/usr/share/php/Net/DNSBL.php is in php-net-dnsbl 1.3.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* PEAR::Net_DNSBL
*
* This class acts as interface to generic Realtime Blocking Lists
* (RBL)
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.01 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_01.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* Net_DNSBL looks up an supplied host if it's listed in 1-n supplied
* Blacklists
*
* @category Net
* @package Net_DNSBL
* @author Sebastian Nohn <sebastian@nohn.net>
* @author Ammar Ibrahim <fixxme@fixme.com>
* @copyright 2004-2009 Sebastian Nohn <sebastian@nohn.net>
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version CVS: $Id: DNSBL.php,v 1.14 2009/06/21 10:32:21 nohn Exp $
* @link http://pear.php.net/package/Net_DNSBL
* @see Net_DNS
* @since File available since Release 1.0.0
*/
require_once 'Net/CheckIP.php';
require_once 'Net/DNS.php';
/**
* PEAR::Net_DNSBL
*
* This class acts as interface to DNSBLs
*
* Net_DNSBL looks up an supplied IP if it's listed in a
* DNS Blacklist.
*
* @category Net
* @package Net_DNSBL
* @author Sebastian Nohn <sebastian@nohn.net>
* @license http://www.php.net/license/3_01.txt PHP License 3.01
* @version Release: 1.3.3
* @link http://pear.php.net/package/net_dnsbl Package Home
*/
class Net_DNSBL
{
/**
* Array of blacklists.
*
* Must have one or more elements.
*
* @var array
* @access protected
*/
var $blacklists = array('sbl-xbl.spamhaus.org',
'bl.spamcop.net');
/**
* Array of Results
*
* @var array
* @access protected
*/
var $results = array();
/**
* Set the blacklist to a desired blacklist.
*
* @param array $blacklists Array of blacklists to use.
*
* @access public
* @return bool true if the operation was successful
*/
function setBlacklists($blacklists)
{
if (is_array($blacklists)) {
$this->blacklists = $blacklists;
return true;
} else {
return false;
} // if
} // function
/**
* Get the blacklists.
*
* @access public
* @return array Currently set blacklists.
*/
function getBlacklists()
{
return $this->blacklists;
}
/**
* Returns Blacklist and Reply from the Blacklist, a host is listed in.
*
* @param string $host Host to check
*
* @access public
* @return array result. $result['dnsbl'] contains DNSBL,
* $result['record'] contains returned DNS record.
*/
function getDetails($host)
{
if (isset($this->results[$host])) {
if (count($this->results[$host])>1) {
return $this->results[$host];
} else {
return $this->results[$host][0];
}
} else {
return false;
}
} // function
/**
* Returns Blacklist, host is listed in.
*
* @param string $host Host to check
*
* @access public
* @return bl, a host is listed in or false
*/
function getListingBl($host)
{
if (isset($this->results[$host]['dnsbl'])) {
return $this->results[$host]['dnsbl'];
} else {
return false;
}
} // function
/**
* Returns Blacklists, host is listed in. isListed() must have
* been called with checkall = true
*
* @param string $host Host to check
*
* @access public
* @return array blacklists, a host is listed in or false
*/
function getListingBls($host)
{
if (is_array($this->results[$host])) {
$result = array_keys($this->results[$host]);
if ($result == null) {
return false;
} else {
return $result;
}
} else {
return false;
}
} // function
/**
* Returns result, when a host is listed.
*
* @param string $host Host to check
*
* @access public
* @return bl, a host is listed in or false
*/
function getListingRecord($host)
{
if (isset($this->results[$host]['record'])) {
return $this->results[$host]['record'];
} else {
return false;
}
} // function
/**
* Returns TXT-Records, when a host is listed.
*
* @param string $host Host to check
*
* @access public
* @return array TXT-Records for this host
*/
function getTxt($host)
{
if (isset($this->results[$host]['txt'])) {
return $this->results[$host]['txt'];
} else {
return false;
}
} // function
/**
* Checks if the supplied Host is listed in one or more of the
* RBLs.
*
* @param string $host Host to check for being listed.
* @param boolean $checkall Iterate through all blacklists and
* return all A records or stop after
* the first hit?
*
* @access public
* @return boolean true if the checked host is listed in a blacklist.
*/
function isListed($host, $checkall = false)
{
$isListed = false;
$resolver = new Net_DNS_Resolver;
if (!is_string($host)) {
return false;
}
foreach ($this->blacklists as $blacklist) {
$response = $resolver->query($this->getHostForLookup($host, $blacklist));
if ($response) {
$isListed = true;
if ($checkall) {
$this->results[$host][$blacklist] = array();
foreach ($response->answer as $answer) {
$this->results[$host][$blacklist]['record'][]
= $answer->address;
}
$response_txt
= $resolver->query(
$this->getHostForLookup(
$host,
$blacklist
),
'TXT'
);
if (isset($response_txt->answer)) {
foreach ($response_txt->answer as $txt) {
$this->results[$host][$blacklist]['txt'][]
= $txt->text[0];
}
}
} else {
$this->results[$host]['dnsbl'] = $blacklist;
$this->results[$host]['record'] = $response->answer[0]->address;
$response_txt
= $resolver->query(
$this->getHostForLookup(
$host,
$blacklist
),
'TXT'
);
if ((isset($response_txt)) && ($response_txt != false)) {
foreach ($response_txt->answer as $txt) {
$this->results[$host]['txt'][] = $txt->text[0];
}
}
// if the Host was listed we don't need to check other RBLs,
break;
}
} // if
} // foreach
return $isListed;
} // function
/**
* Get host to lookup. Lookup a host if neccessary and get the
* complete FQDN to lookup.
*
* @param string $host Host OR IP to use for building the lookup.
* @param string $blacklist Blacklist to use for building the lookup.
*
* @access protected
* @return string Ready to use host to lookup
*/
function getHostForLookup($host, $blacklist)
{
// Currently only works for v4 addresses.
if (!Net_CheckIP::check_ip($host)) {
$resolver = new Net_DNS_Resolver;
$response = $resolver->query($host);
$ip = $response->answer[0]->address;
} else {
$ip = $host;
}
return $this->buildLookUpHost($ip, $blacklist);
} // function
/**
* Build the host to lookup from an IP.
*
* @param string $ip IP to use for building the lookup.
* @param string $blacklist Blacklist to use for building the lookup.
*
* @access protected
* @return string Ready to use host to lookup
*/
function buildLookUpHost($ip, $blacklist)
{
return $this->reverseIp($ip).'.'.$blacklist;
} // function
/**
* Reverse the order of an IP. 127.0.0.1 -> 1.0.0.127. Currently
* only works for v4-adresses
*
* @param string $ip IP address to reverse.
*
* @access protected
* @return string Reversed IP
*/
function reverseIp($ip)
{
return implode('.', array_reverse(explode('.', $ip)));
} // function
} // class
?>
|