function fail2ban_whitelist in Fail2ban Firewall Integration 6
Same name and namespace in other branches
- 7 fail2ban.module \fail2ban_whitelist()
Check if a given address is whitelisted.
Shamelessly copied from http://php.net/manual/en/function.ip2long.php
1 call to fail2ban_whitelist()
- fail2ban_syslog in ./
fail2ban.module - The function that does the actual work, writing a log message.
1 string reference to 'fail2ban_whitelist'
File
- ./
fail2ban.module, line 139
Code
function fail2ban_whitelist($address) {
$client_ip = ip2long($address);
// Return true if this is not a valid IP.
//
if ($client_ip === FALSE) {
return TRUE;
}
// Load and split the list.
//
$whitelist = variable_get('fail2ban_whitelist', "127.0.0.0/8\n" . ip_address());
$list = split("\n", $whitelist);
// Iterate.
//
foreach ($list as $entry) {
$network = split('/', trim($entry));
// Check if we're dealing with a single address.
//
if (!$network[1] || empty($network[1])) {
if ($address == $network[0]) {
return TRUE;
}
}
else {
if (fail2ban_ip_in_network($address, $network[0], $network[1]) == TRUE) {
return TRUE;
}
}
}
return FALSE;
}