You are here

private static function Path2ban::blockUser in path2ban 7.2

This function bans IP addresses of web scanners and sends a notification email to User One.

1 call to Path2ban::blockUser()
Path2ban::destinationCheck in src/Path2ban.php
This function compare real path and restricted, and takes action if necessary.

File

src/Path2ban.php, line 90
path2ban core functionality file.

Class

Path2ban
@class Path2ban The Path2ban class contains the core functionality to assess and block visitors who violate rules.

Code

private static function blockUser() {

  // Actually ban.
  $ip = ip_address();
  db_insert('blocked_ips')
    ->fields(array(
    'ip' => $ip,
  ))
    ->execute();
  watchdog('path2ban', 'Banned IP address %ip', array(
    '%ip' => $ip,
  ));
  drupal_set_message(t('Sorry, your IP has been banned.'), 'error');

  // Notify user one.
  if (variable_get('path2ban_notify', 0)) {
    $user1 = user_load(1);
    $url = url('admin/config/people/ip-blocking', array(
      'absolute' => TRUE,
    ));
    $params['subject'] = variable_get('site_name') . t(': Blocked IP due to web-scanner attack');
    $params['body'][] = t("Hi User One,\n        There were suspected web-scanner activities.\n        Associated IP (@ip) has been blocked.\n        You can review the list of blocked IPs at @url\n        Thank you.\n        Sent by path2ban module.\n      ", array(
      '@ip' => $ip,
      '@url' => $url,
    ));
    drupal_mail('path2ban', 'blocked-ip', $user1->mail, user_preferred_language($user1), $params);
  }
}