[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 // +----------------------------------------------------------------------+ 4 // | PEAR::Net_DNSBL_SURBL | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 2004 Sebastian Nohn <sebastian@nohn.net> | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 3.0 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available through the world-wide-web at the following url: | 11 // | http://www.php.net/license/3_0.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Sebastian Nohn <sebastian@nohn.net> | 17 // +----------------------------------------------------------------------+ 18 // 19 // $Id: SURBL.php,v 1.4 2004/12/02 14:23:51 nohn Exp $ 20 21 /** 22 * PEAR::Net_DNSBL_SURBL 23 * 24 * This class acts as interface to the SURBL - Spam URI Realtime Blocklists. 25 * 26 * Services_SURBL looks up an supplied URI if it's listed in a 27 * Spam URI Realtime Blocklists. 28 * 29 * @author Sebastian Nohn <sebastian@nohn.net> 30 * @package Net_DNSBL 31 * @license http://www.php.net/license/3_0.txt 32 * @version 0.5.4 33 */ 34 require_once dirname(__FILE__) . '/../../Cache/Lite.php'; 35 require_once dirname(__FILE__) . '/../../HTTP/Request.php'; 36 require_once dirname(__FILE__) . '/../CheckIP.php'; 37 require_once dirname(__FILE__) . '/../DNSBL.php'; 38 39 class Net_DNSBL_SURBL extends Net_DNSBL { 40 41 /** 42 * Array of blacklists. 43 * 44 * Must have one or more elements. 45 * 46 * @var string[] 47 * @access protected 48 */ 49 var $blacklists = array('multi.surbl.org'); 50 51 /** 52 * File containing whitelisted hosts. 53 * 54 * There are some whitelisted hosts (co.uk for example). This 55 * requires the package to not ask the domain name but the host 56 * name (spammer.co.uk instead of co.uk). 57 * 58 * @var string 59 * @see $twoLevelCcTld 60 * @access protected 61 */ 62 var $doubleCcTldFile = 'http://spamcheck.freeapp.net/two-level-tlds'; 63 64 /** 65 * Array of whitelisted hosts. 66 * 67 * @var array 68 * @see $twoLevelCcTldFile 69 * @access private 70 */ 71 var $twoLevelCcTld = array(); 72 73 /** 74 * Check if the last two parts of the FQDN are whitelisted. 75 * 76 * @param string Host to check if it is whitelisted 77 * @access protected 78 * @return boolean True if the host is whitelisted 79 */ 80 function isDoubleCcTld($fqdn) 81 { 82 // 30 Days should be way enough 83 $options = array( 84 'lifeTime' => '2592000', 85 'automaticSerialization' => true 86 ); 87 $id = md5($this->doubleCcTldFile); 88 89 $cache = new Cache_Lite($options); 90 if ($data = $cache->get($id)) { 91 // Cache hit 92 } else { 93 // Cache miss 94 $http = &new HTTP_Request($this->doubleCcTldFile); 95 if (!PEAR::isError($http->sendRequest())) { 96 $data = $http->getResponseBody(); 97 } 98 $data = explode("\n", $data); 99 $data = array_flip($data); 100 $cache->save($data, $id); 101 } // if 102 if (array_key_exists($fqdn, $data)) { 103 return true; 104 } else { 105 return false; 106 } // if 107 } // function 108 109 /** 110 * Get Hostname to ask for. 111 * 112 * Performs the following steps: 113 * 114 * (1) Extract the hostname from the given URI 115 * (2) Check if the "hostname" is an ip 116 * (3a) IS_IP Reverse the IP (1.2.3.4 -> 4.3.2.1) 117 * (3b) IS_FQDN Check if is in "CC-2-level-TLD" 118 * (3b1) IS_IN_2LEVEL: we want the last three names 119 * (3b2) IS_NOT_2LEVEL: we want the last two names 120 * (4) return the FQDN to query. 121 * 122 * @param string URL to check. 123 * @access protected 124 * @return string Host to lookup 125 */ 126 function getHostForLookup($uri, $blacklist) 127 { 128 $host = ''; 129 // (1) Extract the hostname from the given URI 130 $parsed_uri = parse_url($uri); 131 $host = $parsed_uri['host']; 132 // (2) Check if the "hostname" is an ip 133 if (Net_CheckIP::check_ip($host)) { 134 // (3a) IS_IP Reverse the IP (1.2.3.4 -> 4.3.2.1) 135 $host = $this->reverseIp($host); 136 } else { 137 $host_elements = explode('.', $host); 138 while (count($host_elements) > 3) { 139 array_shift($host_elements); 140 } // while 141 $host_3_elements = implode('.', $host_elements); 142 143 $host_elements = explode('.', $host); 144 while (count($host_elements) > 2) { 145 array_shift($host_elements); 146 } // while 147 $host_2_elements = implode('.', $host_elements); 148 149 // (3b) IS_FQDN Check if is in "CC-2-level-TLD" 150 if ($this->isDoubleCcTld($host_2_elements)) { 151 // (3b1) IS_IN_2LEVEL: we want the last three names 152 $host = $host_3_elements; 153 } else { 154 // (3b2) IS_NOT_2LEVEL: we want the last two names 155 $host = $host_2_elements; 156 } // if 157 } // if 158 // (4) return the FQDN to query 159 $host .= '.'.$blacklist; 160 return $host; 161 } // function 162 163 } // class 164 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |