forked from leftypol/leftypol
Add IPv6 support for DNSBL
Should have used the library but didn't want to experiement and posiibly break the includes
This commit is contained in:
parent
8fe2499e58
commit
132b7ace54
1 changed files with 26 additions and 5 deletions
|
@ -1753,9 +1753,6 @@ function buildJavascript() {
|
||||||
function checkDNSBL() {
|
function checkDNSBL() {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if (isIPv6())
|
|
||||||
return; // No IPv6 support yet.
|
|
||||||
|
|
||||||
if (!isset($_SERVER['REMOTE_ADDR']))
|
if (!isset($_SERVER['REMOTE_ADDR']))
|
||||||
return; // Fix your web server configuration
|
return; // Fix your web server configuration
|
||||||
|
|
||||||
|
@ -1765,7 +1762,11 @@ function checkDNSBL() {
|
||||||
if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions']))
|
if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions']))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$ipaddr = ReverseIPOctets($_SERVER['REMOTE_ADDR']);
|
if (isIPv6()) {
|
||||||
|
$ipaddr = ReverseIPv6Octets($_SERVER['REMOTE_ADDR']);
|
||||||
|
} else {
|
||||||
|
$ipaddr = ReverseIPv4Octets($_SERVER['REMOTE_ADDR']);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($config['dnsbl'] as $blacklist) {
|
foreach ($config['dnsbl'] as $blacklist) {
|
||||||
if (!is_array($blacklist))
|
if (!is_array($blacklist))
|
||||||
|
@ -1801,10 +1802,30 @@ function isIPv6() {
|
||||||
return strstr($_SERVER['REMOTE_ADDR'], ':') !== false;
|
return strstr($_SERVER['REMOTE_ADDR'], ':') !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReverseIPOctets($ip) {
|
function ReverseIPv4Octets($ip) {
|
||||||
return implode('.', array_reverse(explode('.', $ip)));
|
return implode('.', array_reverse(explode('.', $ip)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ReverseIPv6Octets($ip) {
|
||||||
|
return strrev(implode(".", str_split(str_replace(':', '', inet_expand($ip)))));
|
||||||
|
}
|
||||||
|
|
||||||
|
// copypastad from lib/IP/Lifo/IP.php, TODO replace this with a proper include
|
||||||
|
function inet_expand($ip)
|
||||||
|
{
|
||||||
|
// strip possible cidr notation off
|
||||||
|
if (($pos = strpos($ip, '/')) !== false) {
|
||||||
|
$ip = substr($ip, 0, $pos);
|
||||||
|
}
|
||||||
|
$bytes = unpack('n*', inet_pton($ip));
|
||||||
|
if (count($bytes) > 2) {
|
||||||
|
return implode(':', array_map(function ($b) {
|
||||||
|
return sprintf("%04x", $b);
|
||||||
|
}, $bytes));
|
||||||
|
}
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
|
|
||||||
function wordfilters(&$body) {
|
function wordfilters(&$body) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue