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; } 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; } /* if (defined('SPAMBLOCKLIST_TEST') and SPAMBLOCKLIST_TEST) { BlackListDebug("10.20.30.40"); BlackListDebug("spammer.org"); BlackListDebug("www.ricoruca.com"); BlackListDebug("ricoruca.com"); BlackListDebug("soft-sky.org"); BlackListDebug("lovers.lv"); BlackListDebug("wumort.net"); BlackListDebug("bibleinayear.org"); BlackListDebug("p50927464.dip.t-dialin.net"); } function BlackListDebug($host) { $res = IsBlackListed($host); echo sprintf("%12s", $host), "\tis"; if ($res) echo " listed at $res[0] - $res[1]\n"; else echo " not blacklisted.\n"; } */ // Local Variables: // mode: php // tab-width: 8 // c-basic-offset: 4 // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: