You are here

perimeter.module in Drupal Perimeter Defence 2.0.x

Same filename and directory in other branches
  1. 8 perimeter.module

File

perimeter.module
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) {

  // Honeypot might remove the uid param at some point later.
  $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']) : '',
    ]);
  }
}

Functions