Revert "Initial break up of functions.php"

This commit is contained in:
Lorenzo Yario
2024-02-04 05:53:06 -08:00
committed by GitHub
parent 4bd3fdb8a9
commit ec515621eb
9 changed files with 636 additions and 671 deletions

View File

@@ -1,71 +0,0 @@
<?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;
}