function _ip_ban_set_ban_value in IP Ban 7
Function sets user's ban value (if any).
Load the user's country code based on their IP address, then check if that country is set to complete ban, read-only, or has no access restrictions. We then do the same for any additional read-only or complete ban IP addresses added. If the user matched a country or an IP address entered, then they are shown a message and/or redirected based on complete ban or read-only.
1 call to _ip_ban_set_ban_value()
- ip_ban_block_list_alter in ./
ip_ban.module - Implements hook_block_list_alter().
File
- ./
ip_ban.module, line 105
Code
function _ip_ban_set_ban_value() {
// If code is being run from drush, we don't want to take any action.
if (drupal_is_cli() && function_exists('drush_main')) {
return;
}
$test_ip = variable_get('ip_ban_test_ip', '');
// Grab the test IP address or the user's real address.
$ip = empty($test_ip) ? ip_address() : $test_ip;
$country_code = ip2country_get_country($ip);
// Determine if the current user is banned or read only.
// Individual IP complete ban trumps individual read only IP, both of which
// trump a country setting.
// Load the country-wide setting.
$banvalue =& drupal_static(__FUNCTION__);
if (!isset($banvalue)) {
$banvalue = (int) variable_get('ip_ban_' . $country_code, IP_BAN_NOBAN);
// Check the read-only IP list.
$readonly_ips = variable_get('ip_ban_readonly_ips', '');
if (!empty($readonly_ips)) {
$ip_readonly_array = explode(PHP_EOL, $readonly_ips);
if (in_array($ip, $ip_readonly_array)) {
$banvalue = IP_BAN_READONLY;
}
}
// Check the complete ban list.
$banned_ips = variable_get('ip_ban_additional_ips', '');
if (!empty($banned_ips)) {
$ip_ban_array = explode(PHP_EOL, $banned_ips);
if (in_array($ip, $ip_ban_array)) {
$banvalue = IP_BAN_BANNED;
}
}
}
return $banvalue;
}