Browse Source

Add IPv6 support for DNSBL

Should have used the library but didn't want to experiement and posiibly break the includes
pull/48/head
discomrade 3 years ago
parent
commit
44dd1ef6f6
  1. 31
      inc/functions.php

31
inc/functions.php

@ -1753,9 +1753,6 @@ function buildJavascript() {
function checkDNSBL() {
global $config;
if (isIPv6())
return; // No IPv6 support yet.
if (!isset($_SERVER['REMOTE_ADDR']))
return; // Fix your web server configuration
@ -1765,7 +1762,11 @@ function checkDNSBL() {
if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions']))
return;
$ipaddr = ReverseIPOctets($_SERVER['REMOTE_ADDR']);
if (isIPv6()) {
$ipaddr = ReverseIPv6Octets($_SERVER['REMOTE_ADDR']);
} else {
$ipaddr = ReverseIPv4Octets($_SERVER['REMOTE_ADDR']);
}
foreach ($config['dnsbl'] as $blacklist) {
if (!is_array($blacklist))
@ -1801,10 +1802,30 @@ function isIPv6() {
return strstr($_SERVER['REMOTE_ADDR'], ':') !== false;
}
function ReverseIPOctets($ip) {
function ReverseIPv4Octets($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) {
global $config;

Loading…
Cancel
Save