You are here

public function AutobanController::banIpAction in Automatic IP ban (Autoban) 8

Direct ban controller.

Parameters

string $ips: IP addresses (comma delimited).

string $provider: Ban provider name.

Return value

bool IP banned status.

1 string reference to 'AutobanController::banIpAction'
autoban.routing.yml in ./autoban.routing.yml
autoban.routing.yml

File

src/Controller/AutobanController.php, line 226

Class

AutobanController
Provides an Autoban functional.

Namespace

Drupal\autoban\Controller

Code

public function banIpAction($ips, $provider) {
  $banManagerData = $this
    ->getBanManagerData($provider);
  $ips_arr = explode(',', $ips);
  foreach ($ips_arr as $ip) {
    $banned = $this
      ->banIp($ip, $banManagerData, TRUE);
    if ($banned) {
      $this
        ->messenger()
        ->addMessage($this
        ->t('IP %ip has been banned (@provider).', [
        '%ip' => $ip,
        '@provider' => $banManagerData['ban_name'],
      ]));
    }
    else {
      $this
        ->messenger()
        ->addMessage($this
        ->t('IP %ip has not been banned', [
        '%ip' => $ip,
      ]), 'warning');
    }
  }
  $destination = $this
    ->getDestinationArray();
  if (!empty($destination)) {
    $url = Url::fromUserInput($destination['destination']);
    return new RedirectResponse($url
      ->toString());
  }
}