diff options
Diffstat (limited to 'inc/util.inc.php')
-rw-r--r-- | inc/util.inc.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/inc/util.inc.php b/inc/util.inc.php index 0ff6fdad..ed0b40ae 100644 --- a/inc/util.inc.php +++ b/inc/util.inc.php @@ -471,4 +471,44 @@ class Util } } + public static function shouldRedirectDomain(): ?string + { + if ($_SERVER['HTTP_HOST'] === 'satellite.bwlehrpool') + return null; + if (!Property::get('webinterface.redirect-domain') || empty(Property::get('webinterface.https-domains'))) + return null; // Disabled, or unknown domain + $curDomain = $_SERVER['HTTP_HOST']; + if ($curDomain[-1] === '.') { + $curDomain = substr($curDomain, 0, -1); + } + $domains = explode(' ', Property::get('webinterface.https-domains')); + foreach ($domains as $domain) { + if ($domain === $curDomain) + return null; // MATCH + if (substr_compare($domain, '*.', 0, 2) === 0) { + if (substr($domain, 2) === $curDomain) + return null; // MATCH + $len = strlen($domain) - 1; + if (substr($curDomain, -$len) === substr($domain, 1)) + return null; // MATCH + } + } + // No match + return $domains[0]; + /* + $str = '//' . $domains[0] . '/' . $_SERVER['REQUEST_URI']; + if (!empty($_SERVER['QUERY_STRING'])) { + $str .= '?' . $_SERVER['QUERY_STRING']; + } + Header('Location: ' . $str); + exit; + */ + } + + public static function osUptime(): int + { + $a = file_get_contents('/proc/uptime'); + return (int)preg_replace('/[^0-9].*$/s', '', $a); + } + } |