function rDNS($ip_addr) { global $config; if ($config['cache']['enabled'] && ($host = cache::get('rdns_' . $ip_addr))) { return $host; } if (!$config['dns_system']) { $host = gethostbyaddr($ip_addr); } else { $resp = shell_exec_error('host -W 1 ' . $ip_addr); if (preg_match('/domain name pointer ([^\\s]+)$/', $resp, $m)) { $host = $m[1]; } else { $host = $ip_addr; } } $isip = filter_var($host, FILTER_VALIDATE_IP); if ($config['fcrdns'] && !$isip && DNS($host) != $ip_addr) { $host = $ip_addr; } if ($config['cache']['enabled']) { cache::set('rdns_' . $ip_addr, $host); } return $host; }
function checkDNSBL() { global $config; if (isIPv6()) { return; } // No IPv6 support yet. if (!isset($_SERVER['REMOTE_ADDR'])) { return; } // Fix your web server configuration if (in_array($_SERVER['REMOTE_ADDR'], $config['dnsbl_exceptions'])) { return; } $ipaddr = ReverseIPOctets($_SERVER['REMOTE_ADDR']); foreach ($config['dnsbl'] as $blacklist) { if (!is_array($blacklist)) { $blacklist = array($blacklist); } if (($lookup = str_replace('%', $ipaddr, $blacklist[0])) == $blacklist[0]) { $lookup = $ipaddr . '.' . $blacklist[0]; } if (!($ip = DNS($lookup))) { continue; } // not in list $blacklist_name = isset($blacklist[2]) ? $blacklist[2] : $blacklist[0]; if (!isset($blacklist[1])) { // If you're listed at all, you're blocked. 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) { error(sprintf($config['error']['dnsbl'], $blacklist_name)); } } } elseif (is_callable($blacklist[1])) { if ($blacklist[1]($ip)) { error(sprintf($config['error']['dnsbl'], $blacklist_name)); } } else { if ($ip == $blacklist[1] || $ip == '127.0.0.' . $blacklist[1]) { error(sprintf($config['error']['dnsbl'], $blacklist_name)); } } } }