View source
<?php
function paranoia_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_admin_perm':
$hide_permissions = module_invoke_all('paranoia_revoke');
foreach ($hide_permissions as $hidden) {
unset($form['permission'][$hidden]);
foreach (element_children($form['checkboxes']) as $rid) {
unset($form['checkboxes'][$rid]['#options'][$hidden]);
}
}
break;
case 'system_modules':
$hidden_modules = module_invoke_all('paranoia_hide');
foreach ($hidden_modules as $module) {
_paranoia_hide_module($form, $module);
}
break;
case 'user_profile_form':
if ($form['#uid'] === '1') {
global $user;
if ($user->uid != 1) {
drupal_set_message('You must login as this user (user/1) to modify the email address and password for this account.');
$form['account']['mail']['#access'] = FALSE;
$form['account']['pass']['#access'] = FALSE;
}
}
break;
}
}
function _paranoia_hide_module(&$form, $module) {
unset($form['validation_modules']['#value'][$module], $form['name'][$module], $form['version'][$module], $form['description'][$module], $form['throttle'][$module], $form['throttle']['#options'][$module], $form['status']['#options'][$module]);
}
function paranoia_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
module_load_include('inc', 'user', 'user.admin');
$form = user_admin_perm($form_state);
$hide_permissions = module_invoke_all('paranoia_revoke');
foreach (element_children($form['checkboxes']) as $rid) {
if (count(array_intersect($hide_permissions, $form['checkboxes'][$rid]['#default_value']))) {
$requirements['paranoia'] = array(
'title' => t('Paranoia'),
'description' => t('At least one user role has permission to input PHP. Resubmit your <a href="@admin/user/permissions">user permissions</a> to close this security hole.', array(
'@admin/user/permissions' => url('admin/user/permissions'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
}
if (module_exists('php')) {
$requirements['paranoia_php'] = array(
'title' => t('Paranoia'),
'description' => t('The PHP module is enabled. This module should be disabled (but paranoia module prevents it from showing in the module admin form). It may have been enabled in the database, circumventing the effectiveness of paranoia module.'),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
function paranoia_paranoia_hide() {
return array(
'php',
'paranoia',
);
}
function paranoia_paranoia_revoke() {
return array(
'use PHP for block visibility',
'Use PHP input for field settings (dangerous - grant with care)',
'use PHP for additional processing',
'administer bueditor(execute PHP)',
'use PHP for tracking visibility',
);
}