function path2ban_action in path2ban 7
1 call to path2ban_action()
File
- ./
path2ban.module, line 116 - path2ban module.
Code
function path2ban_action() {
$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;
//$testmode = variable_get('path2ban_test_mode', 0);
$ip = ip_address();
flood_register_event('path2ban', $window);
// by default: $window=3600, $identifier=ip
if ($bypass) {
drupal_set_message(t('Your IP address has been logged.'), 'warning');
}
if (!flood_is_allowed('path2ban', $limit, $window)) {
// by default: $window=3600
if (!$bypass) {
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);
$testmode = $bypass ? t('(User has bypass permission. IP address has not been blocked!)') : '';
$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 @testmode\n ", array(
'@ip' => $ip,
'@url' => $url,
'@testmode' => $testmode,
));
//drupal_mail('path2ban', 'blocked-ip', $user1->mail, language_default(), $params);
drupal_mail('path2ban', 'blocked-ip', $user1->mail, user_preferred_language($user1), $params);
}
}
else {
watchdog('path2ban', 'Would have banned IP address %ip but they have the \'bypass path2ban\' role.', array(
'%ip' => $ip,
));
}
}
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.'));
}
}