Browse Source

Add IPv6 support for DNSBL

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

31
inc/functions.php

@ -2217,9 +2217,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
@ -2229,7 +2226,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))
@ -2265,10 +2266,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