You are here

function _httpbl_check in http:BL 5

The actual checking function.

1 call to _httpbl_check()
httpbl_menu in ./httpbl.module
Implementation of hook_menu().

File

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

Code

function _httpbl_check() {
  global $user;
  if (variable_get('httpbl_check', 0) < 2 || variable_get('httpbl_check', 0) == 2 && $user->uid) {

    // Only check when 'for all users' or 'for all anonymous users' is set
    return;
  }

  // Testcases at http://www.projecthoneypot.org/httpbl_api.php
  // $ip = '127.1.40.1';
  $ip = _httpbl_ip_address();
  $blacklisted = httpbl_blacklisted($ip, TRUE, variable_get('httpbl_stats', TRUE));
  if ($blacklisted && !_httpbl_whitelisted($ip) && !($blacklisted == 2 && $_GET['q'] == 'httpbl/whitelist')) {
    if ($blacklisted == 2) {

      // Greylisted
      $message = variable_get('httpbl_message_grey', "Sorry, %ip has been greylisted by <a href=\"%ipurl\">http:BL</a>.\nYou may try whitelisting on <a href=\"%whitelisturl\">%whitelisturl</a>.\n%honeypot");
      $_SESSION['httpbl_status'] = 'grey';
    }
    else {
      if ($blacklisted == 1) {

        // blacklisted
        $message = variable_get('httpbl_message_black', "Sorry, %ip has been blacklisted by <a href=\"%ipurl\">http:BL</a>.\n%honeypot");
      }
    }
    if ($link = variable_get('httpbl_link', NULL)) {
      $word = variable_get('httpbl_word', 'randomness');
      $link = httpbl_honeylink($link, $word);
    }
    $message = strtr($message, array(
      '%ip' => $ip,
      '%ipurl' => _httpbl_iplink($ip, FALSE),
      '%honeypot' => $link,
      '%whitelisturl' => url('httpbl/whitelist'),
    ));
    header('HTTP/1.1 403 Forbidden');
    print "<html>\n<body>\n";
    print $message . "\n";
    print "</body>\n</html>";
    exit;
  }
}