mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-12-03 19:47:25 +01:00
72 lines
1.4 KiB
PHP
72 lines
1.4 KiB
PHP
<?php // Networking related functions
|
|
|
|
defined('TINYBOARD') or exit;
|
|
|
|
|
|
function isIPv6() {
|
|
return strstr($_SERVER['REMOTE_ADDR'], ':') !== false;
|
|
}
|
|
|
|
function ReverseIPOctets($ip) {
|
|
return implode('.', array_reverse(explode('.', $ip)));
|
|
}
|
|
|
|
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 3 ' . $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 DNS($host) {
|
|
global $config;
|
|
|
|
if ($config['cache']['enabled'] && ($ip_addr = cache::get('dns_' . $host))) {
|
|
return $ip_addr != '?' ? $ip_addr : false;
|
|
}
|
|
|
|
if (!$config['dns_system']) {
|
|
$ip_addr = gethostbyname($host);
|
|
if ($ip_addr == $host) {
|
|
$ip_addr = false;
|
|
}
|
|
} else {
|
|
$resp = shell_exec_error('host -W 1 ' . $host);
|
|
if (preg_match('/has address ([^\s]+)$/', $resp, $m)) {
|
|
$ip_addr = $m[1];
|
|
} else {
|
|
$ip_addr = false;
|
|
}
|
|
}
|
|
|
|
if ($config['cache']['enabled']) {
|
|
cache::set('dns_' . $host, $ip_addr !== false ? $ip_addr : '?');
|
|
}
|
|
|
|
return $ip_addr;
|
|
}
|