3) { array_shift($host_elements); } $host_3_elements = implode('.', $host_elements); if (count($host_elements) > 2) { array_shift($host_elements); } $host_2_elements = implode('.', $host_elements); if (empty($twoleveltlds)) { $data = @file(dirname(__FILE__) . "/../config/two-level-tlds"); $twoleveltlds = $data ? array_flip($data) : array(); } if (array_key_exists($host_2_elements, $twoleveltlds)) //IS_IN_2LEVEL: we want the last three names $host = $host_3_elements; else // IS_NOT_2LEVEL: we want the last two names $host = $host_2_elements; return $host; } /** * @param string $uri * @return int */ function IsBlackListed($uri) { static $blacklists = array("multi.surbl.org", "bl.spamcop.net"); /* "sbl-xbl.spamhaus.net" */ static $whitelist = array(); if (empty($whitelist)) { // list of domains $data = @file(dirname(__FILE__) . "/../config/whitelist"); $whitelist = $data ? array_flip($data) : array(); } $parsed_uri = parse_url($uri); if (!empty($parsed_uri['host'])) $host = $parsed_uri['host']; else $host = $parsed_uri['path']; if (array_key_exists($host, $whitelist)) return 0; if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $host)) { $host = implode('.', array_reverse(explode('.', $host))); $revip = 1; } else { $revip = 0; } foreach ($blacklists as $bl) { if (!$revip and $bl == "multi.surbl.org") { $host = stripDomainPrefixes($host); // strip domain prefixes if (array_key_exists($host, $whitelist)) return 0; } elseif (!$revip) { // convert to IP addr and revert it. $host = implode('.', array_reverse(explode('.', gethostbyname($host)))); } //echo "($host.$bl)"; $res = gethostbyname($host . "." . $bl); if (preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/", $res)) return array($bl, $res, $host); } return 0; } // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: