View source
<?php
use Drupal\Core\Database\Database;
use Drupal\ban\BanIpManager;
use Drupal\Component\Utility\Xss;
function perimeter_honeypot_reject($form_id, $uid, $type) {
$uid = \Drupal::currentUser()
->id();
if ($uid != 1 && ($type == 'honeypot_time' && $form_id != 'user_login_form')) {
$ip = \Drupal::request()
->getClientIp();
$connection = Database::getConnection();
$banManager = new BanIpManager($connection);
$banManager
->banIp($ip);
\Drupal::logger('Perimeter')
->notice('Banned: %ip for failing %type on %form <br />Source: %source <br /> User Agent: %browser', [
'%ip' => $ip,
'%type' => $type,
'%form' => Xss::filter($form_id),
'%source' => isset($_SERVER['HTTP_REFERER']) ? Xss::filter($_SERVER['HTTP_REFERER']) : '',
'%browser' => isset($_SERVER['HTTP_USER_AGENT']) ? Xss::filter($_SERVER['HTTP_USER_AGENT']) : '',
]);
}
}