new checkDNSBL() function, return true/false, not error

This commit is contained in:
8chan 2015-02-16 16:24:11 -08:00
parent ecdc53522f
commit ee635db05f
2 changed files with 28 additions and 19 deletions

View File

@ -1583,20 +1583,22 @@ function buildJavascript() {
file_write($config['file_script'], $script); file_write($config['file_script'], $script);
} }
function checkDNSBL() { function checkDNSBL($use_ip = false) {
global $config; global $config;
if (!$use_ip && !isset($_SERVER['REMOTE_ADDR']))
if (isIPv6())
return; // No IPv6 support yet.
if (!isset($_SERVER['REMOTE_ADDR']))
return; // Fix your web server configuration return; // Fix your web server configuration
if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions'])) $ip = ($use_ip ? $use_ip : $_SERVER['REMOTE_ADDR']);
if ($ip == '127.0.0.2') return true;
if (isIPv6($ip))
return; // No IPv6 support yet.
if (in_array($ip, $config['dnsbl_exceptions']))
return; return;
$ipaddr = ReverseIPOctets($_SERVER['REMOTE_ADDR']); $ipaddr = ReverseIPOctets($ip);
foreach ($config['dnsbl'] as $blacklist) { foreach ($config['dnsbl'] as $blacklist) {
if (!is_array($blacklist)) if (!is_array($blacklist))
@ -1612,24 +1614,31 @@ function checkDNSBL() {
if (!isset($blacklist[1])) { if (!isset($blacklist[1])) {
// If you're listed at all, you're blocked. // If you're listed at all, you're blocked.
error(sprintf($config['error']['dnsbl'], $blacklist_name)); if ($use_ip) {
} elseif (is_array($blacklist[1])) { return true;
foreach ($blacklist[1] as $octet) { } else {
if ($ip == $octet || $ip == '127.0.0.' . $octet)
error(sprintf($config['error']['dnsbl'], $blacklist_name)); error(sprintf($config['error']['dnsbl'], $blacklist_name));
} }
} elseif (is_array($blacklist[1])) {
foreach ($blacklist[1] as $octet) {
if ($ip == $octet || $ip == '127.0.0.' . $octet) {
return true;
}
}
} elseif (is_callable($blacklist[1])) { } elseif (is_callable($blacklist[1])) {
if ($blacklist[1]($ip)) if ($blacklist[1]($ip)) {
error(sprintf($config['error']['dnsbl'], $blacklist_name)); return true;
}
} else { } else {
if ($ip == $blacklist[1] || $ip == '127.0.0.' . $blacklist[1]) if ($ip == $blacklist[1] || $ip == '127.0.0.' . $blacklist[1]) {
error(sprintf($config['error']['dnsbl'], $blacklist_name)); return true;
}
} }
} }
} }
function isIPv6() { function isIPv6($ip = false) {
return strstr($_SERVER['REMOTE_ADDR'], ':') !== false; return strstr(($ip ? $ip : $_SERVER['REMOTE_ADDR']), ':') !== false;
} }
function ReverseIPOctets($ip) { function ReverseIPOctets($ip) {

View File

@ -38,7 +38,7 @@ if (isset($_POST['delete'])) {
} }
} }
checkDNSBL(); if (checkDNSBL()) error("Tor users may not delete posts.");
// Check if board exists // Check if board exists
if (!openBoard($_POST['board'])) if (!openBoard($_POST['board']))
@ -116,7 +116,7 @@ elseif (isset($_POST['report'])) {
} }
} }
checkDNSBL(); if (checkDNSBL()) error("Tor users may not report posts.");
// Check if board exists // Check if board exists
if (!openBoard($_POST['board'])) if (!openBoard($_POST['board']))