You are here

private static function Path2ban::shouldBlockUser in path2ban 7.2

Registers the infraction and considers blocking the user.

Return value

bool true if should block the user.

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

File

src/Path2ban.php, line 55
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 shouldBlockUser() {
  global $user;
  if ($user->uid == 1) {
    drupal_set_message(t('Hi User One! Use another account and another IP for testing path2ban module. Your IP not banned.'));
    return FALSE;
  }
  $bypass = user_access('bypass path2ban');
  $window = intval(variable_get('path2ban_threshold_window', 3600));
  $limit = intval(variable_get('path2ban_threshold_limit', 5));
  $limit = $limit < 1 ? 1 : $limit;
  if ($bypass) {
    watchdog('path2ban', 'Permitting IP address %ip as they have the \'bypass path2ban\' role.', array(
      '%ip' => ip_address(),
    ));
    return FALSE;
  }
  flood_register_event('path2ban', $window);

  // When flood_is_allowed returns false, the user has run out of chances.
  if (flood_is_allowed('path2ban', $limit, $window)) {
    if (variable_get('path2ban_warn_user')) {
      drupal_set_message(variable_get('path2ban_warn_user_message'), 'warning');
    }
    return FALSE;
  }

  // We should block the user.
  return TRUE;
}