summaryrefslogtreecommitdiffstats
path: root/index.php
diff options
context:
space:
mode:
authorSimon Rettberg2024-10-08 16:22:17 +0200
committerSimon Rettberg2024-10-08 16:22:17 +0200
commit882b694e06acd389dd74f7a7d9b70ada0fd218d5 (patch)
tree11c95683e56645c498a08378dadf2422cd2d27fb /index.php
parentUpdate phpdoc (diff)
downloadslx-admin-882b694e06acd389dd74f7a7d9b70ada0fd218d5.tar.gz
slx-admin-882b694e06acd389dd74f7a7d9b70ada0fd218d5.tar.xz
slx-admin-882b694e06acd389dd74f7a7d9b70ada0fd218d5.zip
[webinterface] Add support for ACME, add option to redirect to cert domain
Diffstat (limited to 'index.php')
-rw-r--r--index.php52
1 files changed, 35 insertions, 17 deletions
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 <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();