diff options
| author | Savetheinternet <savetheinternet@tinyboard.org> | 2011-12-03 11:52:31 +1100 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@tinyboard.org> | 2011-12-03 11:52:31 +1100 |
| commit | dbe330298729cdaa9c07e72e8778daad0a87e1c3 (patch) | |
| tree | fffb87c4c36dd1052d361d2bda25e32d88aa4d41 /inc/functions.php | |
| parent | 3979d9a7406976c0492cdc4c04dca06bfcde73aa (diff) | |
Avoid DNS timeouts by using `host` and cache if available
Diffstat (limited to 'inc/functions.php')
| -rw-r--r-- | inc/functions.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/inc/functions.php b/inc/functions.php index c79e3a68..db1b930a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -487,6 +487,7 @@ $query->bindValue(':board', $board); $query->execute() or error(db_error($query)); } + if($query->rowCount() < 1 && $config['ban_cidr'] && !isIPv6()) { // my most insane SQL query yet $query = prepare("SELECT `set`, `expires`, `reason`, `board`, `uri`, `bans`.`id` FROM `bans` LEFT JOIN `boards` ON `boards`.`id` = `board` WHERE (`board` IS NULL OR `uri` = :board) @@ -1472,4 +1473,27 @@ } } + 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('host -W 1 ' . $ip_addr); + if(preg_match('/domain name pointer ([^\s]+)$/', $resp, $m)) + $host = $m[1]; + else + $host = $ip_addr; + } + + if($config['cache']['enabled']) + cache::set('rdns_' . $ip_addr, $host, 3600); + + return $host; + } + ?> |
