function autoban_form in Automatic IP ban (Autoban) 7
Defines the form for autoban rules.
Parameters
int $rid: (optional) Autoban rule id.
See also
2 string references to 'autoban_form'
- autoban_menu in ./
autoban.module - Implements hook_menu().
- autoban_page in ./
autoban.admin.inc - Menu callback. Displays autoban rules list.
File
- ./
autoban.admin.inc, line 206 - Configuration for autoban module.
Code
function autoban_form($form, $form_state, $rid = NULL) {
if ($rid == NULL && current_path() == AUTOBAN_BASE_URL) {
$form['autoban'] = array(
'#type' => 'fieldset',
'#title' => t('Add autoban rule'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
$params = drupal_get_query_parameters();
$all_groups = db_query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type')
->fetchAllKeyed(0, 0);
$form['autoban']['type'] = array(
'#title' => t('Type'),
'#type' => 'textfield',
'#size' => 32,
'#required' => FALSE,
'#maxlength' => 64,
'#default_value' => isset($params['type']) ? filter_xss($params['type']) : '',
'#description' => t('Type of <a href="/admin/reports/dblog">log message</a>: ' . implode(', ', $all_groups)),
);
$form['autoban']['message'] = array(
'#title' => t('Message'),
'#type' => 'textfield',
'#size' => 64,
'#required' => FALSE,
'#maxlength' => 255,
'#default_value' => isset($params['message']) ? filter_xss($params['message']) : '',
'#description' => t('<a href="/admin/reports/dblog">Log message</a> pattern.
Use delimiter "!delimiter" for multiple values. Use regular expression if <a href="@href">Query option</a> set to REGEXP. Use wildcards if <a href="@href">Use wildcards</a> is checked.', array(
'!delimiter' => AUTOBAN_MESSAGE_SEPARATOR,
'@href' => url(AUTOBAN_BASE_URL . '/settings'),
)),
);
$form['autoban']['threshold'] = array(
'#title' => t('Threshold'),
'#type' => 'select',
'#multiple' => FALSE,
'#options' => drupal_map_assoc(_autoban_get_thresholds()),
'#required' => TRUE,
'#description' => t('The threshold number of the <a href="/admin/reports/dblog">log entries</a>.'),
);
$form['autoban']['user_type'] = array(
'#title' => t('User type'),
'#type' => 'select',
'#multiple' => FALSE,
'#options' => _autoban_get_user_type_name(),
'#default_value' => 0,
'#required' => TRUE,
'#description' => t('Choose user type.'),
);
$form['autoban']['referer'] = array(
'#title' => t('Referrer'),
'#type' => 'textfield',
'#size' => 64,
'#required' => FALSE,
'#maxlength' => 255,
'#default_value' => isset($params['referer']) ? filter_xss($params['referer']) : '',
'#description' => t('URL of referring page pattern. Use delimiter "!delimiter" for multiple values.', array(
'!delimiter' => AUTOBAN_MESSAGE_SEPARATOR,
)),
);
$form['autoban']['ip_type'] = array(
'#title' => t('IP type'),
'#type' => 'select',
'#multiple' => FALSE,
'#options' => _autoban_get_ip_type_names_list(),
'#default_value' => 0,
'#required' => TRUE,
'#description' => t('Choose IP type.'),
);
$form['rule_id'] = array(
'#type' => 'value',
'#value' => $rid,
);
$form['autoban']['actions'] = array(
'#type' => 'actions',
);
if ($rid != NULL) {
// Edit rule.
$rule = autoban_get_rules($rid);
$form['autoban']['type']['#default_value'] = filter_xss($rule->type);
$form['autoban']['message']['#default_value'] = filter_xss($rule->message);
$form['autoban']['threshold']['#default_value'] = (int) $rule->threshold;
$form['autoban']['user_type']['#default_value'] = $rule->user_type;
$form['autoban']['referer']['#default_value'] = filter_xss($rule->referer);
$form['autoban']['ip_type']['#default_value'] = $rule->ip_type;
$time_info = t('Created: @created Updated: @updated', array(
'@created' => !empty($rule->created) ? format_date($rule->created) : t('n/a'),
'@updated' => !empty($rule->changed) ? format_date($rule->changed) : t('n/a'),
));
$form['autoban']['time_info'] = array(
'#markup' => $time_info,
);
$form['autoban']['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('Edit'),
);
$form['autoban']['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => isset($_GET['destination']) ? $_GET['destination'] : AUTOBAN_BASE_URL,
);
}
else {
// Add rule.
$form['autoban']['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);
if (current_path() != AUTOBAN_BASE_URL) {
$form['autoban']['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => isset($_GET['destination']) ? $_GET['destination'] : AUTOBAN_BASE_URL,
);
}
}
return $form;
}