public function AutobanSettingsForm::buildForm in Automatic IP ban (Autoban) 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- src/
Form/ AutobanSettingsForm.php, line 65
Class
- AutobanSettingsForm
- Configure autoban settings for this site.
Namespace
Drupal\autoban\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('autoban.settings');
// Retrieve Ban manager list.
$providers = [];
$controller = $this->autoban;
$banManagerList = $controller
->getBanProvidersList();
if (!empty($banManagerList)) {
foreach ($banManagerList as $id => $item) {
$providers[$id] = $item['name'];
}
$form['providers'] = [
'#markup' => '<label>' . $this
->t('Ban providers') . '</label> ' . implode(', ', $providers),
'#allowed_tags' => [
'label',
],
];
}
else {
$this
->messenger()
->addMessage($this
->t('List ban providers is empty. You have to enable at least one Autoban providers module.'), 'warning');
}
$thresholds = $config
->get('autoban_thresholds') ?: "1\n2\n3\n5\n10\n20\n50\n100";
$form['autoban_thresholds'] = [
'#type' => 'textarea',
'#title' => $this
->t('Thresholds'),
'#default_value' => $thresholds,
'#required' => TRUE,
'#description' => $this
->t('Thresholds set for Autoban rules threshold field.'),
];
$query_mode = $config
->get('autoban_query_mode') ?: 'like';
$form['autoban_query_mode'] = [
'#type' => 'radios',
'#title' => $this
->t('Query mode'),
'#options' => [
'like' => 'LIKE',
'regexp' => 'REGEXP',
],
'#default_value' => $query_mode,
'#description' => $this
->t('Use REGEXP option if your SQL engine supports REGEXP syntax.'),
];
$use_wildcards = $config
->get('autoban_use_wildcards') ?: FALSE;
$form['autoban_use_wildcards'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use wildcards'),
'#default_value' => $use_wildcards,
'#description' => $this
->t('If not checked, Autoban will add % to begin and end of message patterns.'),
];
$form['autoban_whitelist'] = [
'#type' => 'textarea',
'#title' => $this
->t('Whitelist'),
'#default_value' => $config
->get('autoban_whitelist'),
'#description' => $this
->t('Enter a list of IP addresses or domain. Format: CIDR "aa.bb.cc.dd/ee" or "aa.bb.cc.dd" or "googlebot.com". # symbol use as a comment.
The rows beginning with # are comments and are ignored.
For example: <a href="http://www.iplists.com/google.txt" rel="nofollow" target="_new">robot-whitelist site</a>.'),
'#rows' => 10,
'#cols' => 30,
];
$dblog_type_exclude = $config
->get('autoban_dblog_type_exclude') ?: "autoban\ncron\nphp\nsystem\nuser";
$form['autoban_dblog_type_exclude'] = [
'#type' => 'textarea',
'#title' => $this
->t('Exclude dblog types'),
'#default_value' => $dblog_type_exclude,
'#description' => $this
->t('Exclude dblog types events for log analyze, autoban rules.'),
];
$form['autoban_threshold_analyze'] = [
'#type' => 'number',
'#title' => $this
->t("Analyze's form threshold"),
'#default_value' => $config
->get('autoban_threshold_analyze') ?: 5,
'#description' => $this
->t('Threshold for log analyze.'),
];
$form['autoban_cron'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable cron'),
'#default_value' => $config
->get('autoban_cron') ?: TRUE,
'#description' => $this
->t('If checked, Autoban will enabled IP ban by cron.'),
];
return parent::buildForm($form, $form_state);
}