You are here

public static function AutobanBatch::ipBan in Automatic IP ban (Autoban) 8

IP ban.

1 call to AutobanBatch::ipBan()
autoban_cron in ./autoban.module
Implements hook_cron().

File

src/AutobanBatch.php, line 22
Contains \Drupal\autoban\AutobanBatch.

Class

AutobanBatch
Class AutobanBatch.

Namespace

Drupal\autoban

Code

public static function ipBan($rule, &$context) {
  $controller = \Drupal::service('autoban');
  $banned_ip = $controller
    ->getBannedIp($rule);
  $banned = $controller
    ->banIpList($banned_ip, $rule);
  $context['message'] = t('rule %rule banned @banned', [
    '%rule' => $rule,
    '@banned' => $banned,
  ]);

  // Calculate total banned IPs for all autoban rules.
  $total_banned = $banned;
  if (isset($context['results'])) {
    $total_banned += intval($context['results']);
  }
  $context['results'] = $total_banned;
}