2020-02-09 23:02:19 +01:00
|
|
|
<?php
|
|
|
|
|
2022-11-18 18:06:46 +01:00
|
|
|
include_once 'Core/core.php';
|
|
|
|
include_once 'Core/datetime.php';
|
|
|
|
include_once 'Core/constants.php';
|
2021-04-06 23:05:02 +02:00
|
|
|
|
2021-12-08 16:53:43 +01:00
|
|
|
define("WEBROOT", realpath("."));
|
|
|
|
|
|
|
|
if (is_file("MAINTENANCE") && !in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
|
2021-04-06 23:05:02 +02:00
|
|
|
http_response_code(503);
|
2022-11-18 18:06:46 +01:00
|
|
|
\Core\Objects\Router\StaticFileRoute::serveStatic(WEBROOT . "/static/maintenance.html");
|
2021-04-06 23:05:02 +02:00
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2022-11-18 18:06:46 +01:00
|
|
|
use Core\Configuration\Configuration;
|
2023-01-07 15:34:05 +01:00
|
|
|
use Core\Objects\Context;
|
2022-11-18 18:06:46 +01:00
|
|
|
use Core\Objects\Router\Router;
|
2020-04-03 18:09:01 +02:00
|
|
|
|
2020-06-18 15:35:09 +02:00
|
|
|
if (!is_readable(getClassPath(Configuration::class))) {
|
2020-06-18 15:39:38 +02:00
|
|
|
header("Content-Type: application/json");
|
2022-06-01 09:47:31 +02:00
|
|
|
die(json_encode([ "success" => false, "msg" => "Configuration class is not readable, check permissions before proceeding." ]));
|
2020-06-18 15:35:09 +02:00
|
|
|
}
|
|
|
|
|
2023-01-07 15:34:05 +01:00
|
|
|
$context = Context::instance();
|
2022-06-20 19:52:31 +02:00
|
|
|
$sql = $context->initSQL();
|
|
|
|
$settings = $context->getSettings();
|
|
|
|
$context->parseCookies();
|
2020-02-09 23:02:19 +01:00
|
|
|
|
2022-06-20 19:52:31 +02:00
|
|
|
$installation = !$sql || ($sql->isConnected() && !$settings->isInstalled());
|
2022-06-01 09:47:31 +02:00
|
|
|
$requestedUri = $_GET["site"] ?? $_GET["api"] ?? $_SERVER["REQUEST_URI"];
|
|
|
|
|
|
|
|
if ($installation) {
|
2022-06-01 12:28:50 +02:00
|
|
|
$requestedUri = Router::cleanURL($requestedUri);
|
2022-06-01 09:47:31 +02:00
|
|
|
if ($requestedUri !== "" && $requestedUri !== "index.php") {
|
|
|
|
$response = "Redirecting to <a href=\"/\">/</a>";
|
|
|
|
header("Location: /");
|
2020-02-10 00:52:25 +01:00
|
|
|
} else {
|
2022-11-18 18:06:46 +01:00
|
|
|
$document = new \Core\Documents\Install(new Router($context));
|
2022-08-20 22:17:17 +02:00
|
|
|
$response = $document->load();
|
2022-06-01 09:47:31 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-20 20:13:51 +02:00
|
|
|
|
2022-06-01 09:47:31 +02:00
|
|
|
$router = null;
|
2022-12-04 13:21:40 +01:00
|
|
|
$routerCacheClass = '\Site\Cache\RouterCache';
|
2022-06-01 09:47:31 +02:00
|
|
|
$routerCachePath = getClassPath($routerCacheClass);
|
|
|
|
if (is_file($routerCachePath)) {
|
|
|
|
@include_once $routerCachePath;
|
|
|
|
if (class_exists($routerCacheClass)) {
|
2022-06-20 19:52:31 +02:00
|
|
|
$router = new $routerCacheClass($context);
|
2020-02-10 00:52:25 +01:00
|
|
|
}
|
2022-06-01 09:47:31 +02:00
|
|
|
}
|
2022-02-20 16:53:26 +01:00
|
|
|
|
2022-06-01 09:47:31 +02:00
|
|
|
if ($router === null) {
|
2022-11-18 18:06:46 +01:00
|
|
|
$req = new \Core\API\Routes\GenerateCache($context);
|
2022-06-01 09:47:31 +02:00
|
|
|
if ($req->execute()) {
|
|
|
|
$router = $req->getRouter();
|
2022-02-20 16:53:26 +01:00
|
|
|
} else {
|
2022-06-01 09:47:31 +02:00
|
|
|
$message = "Unable to generate router cache: " . $req->getLastError();
|
2022-06-20 19:52:31 +02:00
|
|
|
$response = (new Router($context))->returnStatusCode(500, [ "message" => $message ]);
|
2022-02-20 16:53:26 +01:00
|
|
|
}
|
2020-02-10 00:52:25 +01:00
|
|
|
}
|
2020-06-22 21:39:15 +02:00
|
|
|
|
2022-06-01 09:47:31 +02:00
|
|
|
if ($router !== null) {
|
2022-06-01 12:37:09 +02:00
|
|
|
if ((!isset($_GET["site"]) || $_GET["site"] === "/") && isset($_GET["error"]) &&
|
|
|
|
is_string($_GET["error"]) && preg_match("/^\d+$/", $_GET["error"])) {
|
2022-06-01 09:47:31 +02:00
|
|
|
$response = $router->returnStatusCode(intval($_GET["error"]));
|
2020-04-02 21:19:06 +02:00
|
|
|
} else {
|
2024-03-30 11:22:59 +01:00
|
|
|
try {
|
|
|
|
$response = $router->run($requestedUri);
|
|
|
|
} catch (\Error $e) {
|
|
|
|
http_response_code(500);
|
|
|
|
$router->getLogger()->error($e->getMessage());
|
|
|
|
$router->returnStatusCode(500);
|
|
|
|
}
|
2022-05-31 16:14:49 +02:00
|
|
|
}
|
2020-04-02 22:25:13 +02:00
|
|
|
}
|
2022-06-01 09:47:31 +02:00
|
|
|
|
2022-06-20 19:52:31 +02:00
|
|
|
$context->processVisit();
|
2020-02-09 23:02:19 +01:00
|
|
|
}
|
|
|
|
|
2022-06-20 19:52:31 +02:00
|
|
|
$context->sendCookies();
|
2020-04-03 18:09:01 +02:00
|
|
|
die($response);
|