1<?php if (!defined('BB2_CORE')) die('I said no cheating!'); 2 3// Quick and dirty check for an IPv6 address 4function is_ipv6($address) { 5 return (strpos($address, ":")) ? TRUE : FALSE; 6} 7 8// Look up address on various blackhole lists. 9// These should not be used for GET requests under any circumstances! 10// FIXME: Note that this code is no longer in use 11function bb2_blackhole($package) { 12 // Can't use IPv6 addresses yet 13 if (@is_ipv6($package['ip'])) return false; 14 15 // Workaround for "MySQL server has gone away" 16 bb2_db_query("SET @@session.wait_timeout = 90"); 17 18 // Only conservative lists 19 $bb2_blackhole_lists = array( 20 "sbl-xbl.spamhaus.org", // All around nasties 21// "dnsbl.sorbs.net", // Old useless data. 22// "list.dsbl.org", // Old useless data. 23// "dnsbl.ioerror.us", // Bad Behavior Blackhole 24 ); 25 26 // Things that shouldn't be blocked, from aggregate lists 27 $bb2_blackhole_exceptions = array( 28 "sbl-xbl.spamhaus.org" => array("127.0.0.4"), // CBL is problematic 29 "dnsbl.sorbs.net" => array("127.0.0.10",), // Dynamic IPs only 30 "list.dsbl.org" => array(), 31 "dnsbl.ioerror.us" => array(), 32 ); 33 34 // Check the blackhole lists 35 $ip = $package['ip']; 36 $find = implode('.', array_reverse(explode('.', $ip))); 37 foreach ($bb2_blackhole_lists as $dnsbl) { 38 $result = gethostbynamel($find . "." . $dnsbl . "."); 39 if (!empty($result)) { 40 // Got a match and it isn't on the exception list 41 $result = @array_diff($result, $bb2_blackhole_exceptions[$dnsbl]); 42 if (!empty($result)) { 43 return '136673cd'; 44 } 45 } 46 } 47 return false; 48} 49 50function bb2_httpbl($settings, $package) { 51 // Can't use IPv6 addresses yet 52 if (@is_ipv6($package['ip'])) return false; 53 54 if (@!$settings['httpbl_key']) return false; 55 56 // Workaround for "MySQL server has gone away" 57 bb2_db_query("SET @@session.wait_timeout = 90"); 58 59 $find = implode('.', array_reverse(explode('.', $package['ip']))); 60 $result = gethostbynamel($settings['httpbl_key'].".${find}.dnsbl.httpbl.org."); 61 if (!empty($result)) { 62 $ip = explode('.', $result[0]); 63 // Check if threat 64 if ($ip[0] == 127 && ($ip[3] & 7) && $ip[2] >= $settings['httpbl_threat'] && $ip[1] <= $settings['httpbl_maxage']) { 65 return '2b021b1f'; 66 } 67 // Check if search engine 68 if ($ip[3] == 0) { 69 return 1; 70 } 71 } 72 return false; 73} 74?> 75