You are here

function httpbl_check in http:BL 6

Same name and namespace in other branches
  1. 6.2 httpbl.module \httpbl_check()
  2. 7 httpbl.module \httpbl_check()

Check if an IP should be banned

Return value

constant: HTTP_LIST_*

3 calls to httpbl_check()
httpbl_boot in ./httpbl.module
Implementation of hook_boot().
httpbl_comment in ./httpbl.module
Implementation of hook_comment().
httpbl_whitelist_access in ./httpbl.module
Determine whether a user has access to the session whitelist functionality.
4 string references to 'httpbl_check'
httpbl_admin_settings in ./httpbl.module
Implementation of hook_settings().
httpbl_boot in ./httpbl.module
Implementation of hook_boot().
httpbl_comment in ./httpbl.module
Implementation of hook_comment().
httpbl_requirements in ./httpbl.module
Implementation of hook_requirements().

File

./httpbl.module, line 145
Implementation of http:BL for Drupal. It provides IP-based blacklisting through http:BL and allows linking to a honeypot.

Code

function httpbl_check() {
  static $result;

  // Result was already calculated -- return.
  if (is_int($result)) {
    return $result;
  }
  $ip = ip_address();

  // Check if user is whitelisted in any way
  if (_httpbl_whitelisted($ip)) {
    $result = HTTPBL_LIST_SAFE;
  }
  else {
    if ($cache = variable_get('httpbl_cache', HTTPBL_CACHE_DBDRUPAL)) {
      $result = _httpbl_cache_get($ip);
    }
  }
  if (!is_numeric($result)) {

    // Do a DNS lookup, and continue if lookup was succesful
    if ($response = httpbl_dnslookup($ip)) {
      $stats = variable_get('httpbl_stats', TRUE);

      // Blacklist?
      if ($response['threat'] > HTTPBL_THRESHOLD_BLACK && $response['type']) {
        if (variable_get('httpbl_log', FALSE)) {
          watchdog('httpbl', '%ip was blacklisted (%response)', array(
            '%ip' => $ip,
            '%response' => $response['raw'],
          ), WATCHDOG_WARNING, _httpbl_ipdata($ip));
        }
        if ($stats) {
          variable_set('httpbl_stat_black', variable_get('httpbl_stat_black', 0) + 1);
        }
        $result = HTTPBL_LIST_BLACK;
      }
      else {
        if ($response['threat'] > HTTPBL_THRESHOLD_GREY && $response['type']) {
          if (variable_get('httpbl_log', FALSE)) {
            watchdog('httpbl', '%ip was greylisted (%response)', array(
              '%ip' => $ip,
              '%response' => $response['raw'],
            ), WATCHDOG_WARNING, _httpbl_ipdata($ip));
          }
          if ($stats) {
            variable_set('httpbl_stat_grey', variable_get('httpbl_stat_grey', 0) + 1);
          }
          $result = HTTPBL_LIST_GREY;
        }
        else {
          $result = HTTPBL_LIST_SAFE;
        }
      }

      // Cache results
      if ($cache) {
        _httpbl_cache_set($ip, $result, 7200);
      }
    }
    else {
      if ($cache) {
        _httpbl_cache_set($ip, HTTPBL_LIST_SAFE, 10800);
      }
      $result = HTTPBL_LIST_SAFE;
    }
  }
  return $result;
}