From 1d34c1f03e973cf95f8490a3456ed53c94a8e0ed Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 28 Jul 2021 20:52:46 +0000 Subject: [PATCH] Added maintenance mode. --- cron.php | 4 ++++ public/assets/style.css | 7 +++++++ public/index.php | 30 +++++++++++++++++++++++------- src/Config.php | 2 +- templates/header.html | 1 + templates/maintenance.html | 3 +++ 6 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 templates/maintenance.html diff --git a/cron.php b/cron.php index 2a398d3..683f605 100644 --- a/cron.php +++ b/cron.php @@ -1,6 +1,10 @@ '; } -if(!empty($_COOKIE['ytkns_login']) && is_string($_COOKIE['ytkns_login'])) { +if(!YTKNS_MAINTENANCE && !empty($_COOKIE['ytkns_login']) && is_string($_COOKIE['ytkns_login'])) { try { $session = UserSession::byToken($_COOKIE['ytkns_login']); $session->update(); @@ -152,13 +154,15 @@ if(!empty($zoneName)) { return; } - if(!empty($_GET['_refresh_screenshot'])) { - header('Location: /'); - $zoneInfo->takeScreenshot(); - return; - } + if(!YTKNS_MAINTENANCE) { + if(!empty($_GET['_refresh_screenshot'])) { + header('Location: /'); + $zoneInfo->takeScreenshot(); + return; + } - ZoneView::increment($zoneInfo, $_SERVER['REMOTE_ADDR']); + ZoneView::increment($zoneInfo, $_SERVER['REMOTE_ADDR']); + } echo (string)$zoneInfo->getPageBuilder(true); return; @@ -924,6 +928,12 @@ if($reqPath === '/settings/invites') { } if($reqPath === '/auth/login') { + if(YTKNS_MAINTENANCE) { + http_response_code(503); + echo html_information('You cannot log in during maintenance.'); + return; + } + if(UserSession::hasInstance()) { http_response_code(404); echo html_information('You are logged in already.'); @@ -985,6 +995,12 @@ if($reqPath === '/auth/login') { } if($reqPath === '/auth/register') { + if(YTKNS_MAINTENANCE) { + http_response_code(503); + echo html_information('You cannot register during maintenance.'); + return; + } + if(UserSession::hasInstance()) { http_response_code(404); echo html_information('You are logged in already.'); diff --git a/src/Config.php b/src/Config.php index 4cb0216..313a117 100644 --- a/src/Config.php +++ b/src/Config.php @@ -39,7 +39,7 @@ final class Config { public static function set(string $key, $value, bool $soft = false): void { self::$config[$key] = $value; - if(!$soft) { + if(!YTKNS_MAINTENANCE && !$soft) { $value = serialize($value); $save = DB::prepare('REPLACE INTO `ytkns_config` (`config_key`, `config_value`) VALUES (:key, :value)'); diff --git a/templates/header.html b/templates/header.html index e3c31e8..4d917dd 100644 --- a/templates/header.html +++ b/templates/header.html @@ -22,6 +22,7 @@
+ :maintenance
:menu_user diff --git a/templates/maintenance.html b/templates/maintenance.html new file mode 100644 index 0000000..bb66733 --- /dev/null +++ b/templates/maintenance.html @@ -0,0 +1,3 @@ +
+ YTKNS is currently in read-only maintenance mode. +
\ No newline at end of file