You are here

function fail2ban_whitelist in Fail2ban Firewall Integration 7

Same name and namespace in other branches
  1. 6 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'
fail2ban_update_7100 in ./fail2ban.install
Implementation of hook_update_N()

File

./fail2ban.module, line 146

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.
  //
  $settings = variable_get('fail2ban', fail2ban_defaults());
  $list = preg_split("/[\\s,]+/", $settings['whitelist'] . "\n" . ip_address());

  // Iterate.
  //
  foreach ($list as $entry) {
    $network = preg_split("/\\//", trim($entry));

    // Check if we're dealing with a single address.
    //
    if (count($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;
}