diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 52 |
1 files changed, 35 insertions, 17 deletions
@@ -19,6 +19,33 @@ require_once('inc/user.inc.php'); $global_start = microtime(true); +// Set variable if this is an ajax request +if ((isset($_REQUEST['async'])) || (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')) { + define('AJAX', true); +} else { + define('AJAX', false); +} +define('API', false); + +// Autoload classes from ./inc which adhere to naming scheme <lowercasename>.inc.php +spl_autoload_register(function ($class) { + $file = 'inc/' . preg_replace('/[^a-z0-9]/', '', mb_strtolower($class)) . '.inc.php'; + if (!file_exists($file)) + return; + require_once $file; +}); + +if (($_GET['do'] ?? '') === '_https_magic') { + Header('Access-Control-Allow-Origin: *'); + Header('Content-Type: application/json'); + $ut = floor(Util::osUptime() / 3); + $str = Property::getServerIp() . serialize(Property::getVmStoreConfig()); + die(json_encode([ + 'a' => md5($ut . $str), + 'b' => md5(($ut - 1) . $str), + ])); +} + /** * Page class which all module's pages must be extending from */ @@ -90,23 +117,6 @@ abstract class Page } -// Set variable if this is an ajax request -if ((isset($_REQUEST['async'])) || (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')) { - define('AJAX', true); -} else { - define('AJAX', false); -} -define('API', false); - -// Autoload classes from ./inc which adhere to naming scheme <lowercasename>.inc.php -spl_autoload_register(function ($class) { - $file = 'inc/' . preg_replace('/[^a-z0-9]/', '', mb_strtolower($class)) . '.inc.php'; - if (!file_exists($file)) - return; - require_once $file; -}); - - if (defined('CONFIG_DEBUG') && CONFIG_DEBUG) { set_error_handler(function ($errno, $errstr, $errfile, $errline) { if (preg_match('/^\[skip:\s*(\d+)\]\s*(.*)/is', $errstr, $out)) { @@ -237,5 +247,13 @@ if (CONFIG_DEBUG) { ), 'main'); } +// Redirect if not accessed via proper domain +if ($_SERVER['REQUEST_METHOD'] === 'GET' && ($host = Util::shouldRedirectDomain()) !== null) { + Render::addTemplate('domain-redirect-check', [ + 'magic' => md5((string)floor(Util::osUptime() / 3) . Property::getServerIp() . serialize(Property::getVmStoreConfig())), + 'host' => $host, + ], 'main'); +} + // Send page to client. Render::output(); |