From 882b694e06acd389dd74f7a7d9b70ada0fd218d5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 8 Oct 2024 16:22:17 +0200 Subject: [webinterface] Add support for ACME, add option to redirect to cert domain --- index.php | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 6b5305b2..c8542b80 100644 --- a/index.php +++ b/index.php @@ -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 .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 .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(); -- cgit v1.2.3-55-g7522