From 3179eef3382a2d8c54f716cf08aa98cb6ebe4ee3 Mon Sep 17 00:00:00 2001 From: Michael Save Date: Thu, 15 Mar 2012 14:00:25 +1100 Subject: [PATCH] use ``host`` if available for standard DNS lookups too --- inc/functions.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index a2861edc..d757c2fe 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -88,7 +88,7 @@ $config['uri_thumb'] = $config['root'] . $board['dir'] . $config['dir']['thumb']; elseif(isset($board['dir'])) $config['uri_thumb'] = sprintf($config['uri_thumb'], $board['dir']); - + if(!isset($config['uri_img'])) $config['uri_img'] = $config['root'] . $board['dir'] . $config['dir']['img']; elseif(isset($board['dir'])) @@ -1302,8 +1302,8 @@ foreach($config['dnsbl'] as &$blacklist) { $lookup = $ip . '.' . $blacklist; - $host = gethostbyname($lookup); - if($host != $lookup) { + $host = DNS($lookup); + if($host !== false) { // On NXDOMAIN (meaning it's not in the blacklist), gethostbyname() returns the host unchanged. if(preg_match('/^127\.0\.0\./', $host) && $host != '127.0.0.10') error(sprintf($config['error']['dnsbl'], $blacklist)); @@ -1672,4 +1672,29 @@ return $host; } -?> + function DNS($host) { + global $config; + + if($config['cache']['enabled'] && ($host = cache::get('dns_' . $host))) { + return $host; + } + + if(!$config['dns_system']) { + $ip_addr = gethostbyname($host); + if($ip_addr == $host) + return false; + } else { + $resp = shell_exec('host -W 1 ' . $host); + if(preg_match('/has address ([^\s]+)$/', $resp, $m)) + $ip_addr = $m[1]; + else + return false; + } + + if($config['cache']['enabled']) + cache::set('dns_' . $ip_addr, $host, 3600); + + return $host; + } + +