replaced tor detection with DNSBL

This commit is contained in:
Savetheinternet 2011-05-19 17:37:23 +10:00
parent 99ed879e17
commit db1f0e9446
3 changed files with 26 additions and 29 deletions

View File

@ -23,7 +23,8 @@
'spam' => Array(), 'spam' => Array(),
'flood_filters' => Array(), 'flood_filters' => Array(),
'wordfilters' => Array(), 'wordfilters' => Array(),
'custom_capcode' => Array() 'custom_capcode' => Array(),
'dnsbl' => Array()
); );
// Database stuff // Database stuff
@ -124,7 +125,7 @@
$config['error']['unoriginal'] = 'Unoriginal content!'; $config['error']['unoriginal'] = 'Unoriginal content!';
$config['error']['muted'] = 'Unoriginal content! You have been muted for %d seconds.'; $config['error']['muted'] = 'Unoriginal content! You have been muted for %d seconds.';
$config['error']['youaremuted'] = 'You are muted! Expires in %d seconds.'; $config['error']['youaremuted'] = 'You are muted! Expires in %d seconds.';
$config['error']['tor'] = 'Hmm… That looks like a Tor exit node.'; $config['error']['dnsbl'] = 'Your IP address is listed in %s.';
$config['error']['toomanylinks'] = 'Too many links; flood detected.'; $config['error']['toomanylinks'] = 'Too many links; flood detected.';
$config['error']['toomanycites'] = 'Too many cites; post discarded.'; $config['error']['toomanycites'] = 'Too many cites; post discarded.';
$config['error']['toomanycross'] = 'Too many cross-board links; post discarded.'; $config['error']['toomanycross'] = 'Too many cross-board links; post discarded.';
@ -187,7 +188,9 @@
// sha1_file, md5_file, etc. // sha1_file, md5_file, etc.
$config['file_hash'] = 'sha1_file'; $config['file_hash'] = 'sha1_file';
$config['block_tor'] = true; // DNS blacklists (DNSBL) http://www.dnsbl.info/dnsbl-list.php
$config['dnsbl'][] = 'tor.dnsbl.sectoor.de'; // Tor exit nodes
// Typically spambots try to post a lot of links. Refuse a post with X standalone links? // Typically spambots try to post a lot of links. Refuse a post with X standalone links?
$config['max_links'] = 20; $config['max_links'] = 20;
// Maximum number of cites per post (protects against abuse) // Maximum number of cites per post (protects against abuse)

View File

@ -991,34 +991,31 @@
))); )));
} }
function isDNSBL() { function checkDNSBL() {
$dns_black_lists = file('./dnsbl.txt', FILE_IGNORE_NEW_LINES); global $config;
// Reverse the IP if(isIPv6())
$rev_ip = implode(array_reverse(explode('.', $_SERVER['REMOTE_ADDR'])), '.'); return; // No IPv6 support yet.
$response = array();
foreach ($dns_black_lists as $dns_black_list) { if(!isset($_SERVER['REMOTE_ADDR']))
$response = (gethostbynamel($rev_ip . '.' . $dns_black_list)); return; // Fix your web server configuration
if(!empty($response))
return true; // Reverse IP
$ip = ReverseIPOctets($_SERVER['REMOTE_ADDR']);
foreach($config['dnsbl'] as &$blacklist) {
$lookup = $ip . '.' . $blacklist;
if(gethostbyname($lookup) != $lookup) {
// On NXDOMAIN (meaning it's not in the blacklist), gethostbyname() returns the host unchanged.
error(sprintf($config['error']['dnsbl'], $blacklist));
}
} }
return false;
} }
function isIPv6() { function isIPv6() {
return strstr($_SERVER['REMOTE_ADDR'], ':') !== false; return strstr($_SERVER['REMOTE_ADDR'], ':') !== false;
} }
function isTor() {
if(isIPv6())
return false; // Tor does not support IPv6
return gethostbyname(
ReverseIPOctets($_SERVER['REMOTE_ADDR']) . '.' . $_SERVER['SERVER_PORT'] . '.' . ReverseIPOctets($_SERVER['SERVER_ADDR']) . '.ip-port.exitlist.torproject.org'
) == '127.0.0.2';
}
function ReverseIPOctets($ip) { function ReverseIPOctets($ip) {
$ipoc = explode('.', $ip); $ipoc = explode('.', $ip);
return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0]; return $ipoc[3] . '.' . $ipoc[2] . '.' . $ipoc[1] . '.' . $ipoc[0];

View File

@ -41,8 +41,7 @@
// Check if banned // Check if banned
checkBan(); checkBan();
if($config['block_tor'] && isTor()) checkDNSBL();
error($config['error']['tor']);
// Check if board exists // Check if board exists
if(!openBoard($_POST['board'])) if(!openBoard($_POST['board']))
@ -102,8 +101,7 @@
// Check if banned // Check if banned
checkBan(); checkBan();
if($config['block_tor'] && isTor()) checkDNSBL();
error($config['error']['tor']);
// Check if board exists // Check if board exists
if(!openBoard($_POST['board'])) if(!openBoard($_POST['board']))
@ -179,8 +177,7 @@
// Check if banned // Check if banned
checkBan(); checkBan();
if($config['block_tor'] && isTor()) checkDNSBL();
error($config['error']['tor']);
// Check if board exists // Check if board exists
if(!openBoard($post['board'])) if(!openBoard($post['board']))