Added maintenance mode.

This commit is contained in:
flash 2021-07-28 20:52:46 +00:00
parent 2e222021b9
commit 1d34c1f03e
6 changed files with 39 additions and 8 deletions

View file

@ -1,6 +1,10 @@
<?php <?php
namespace YTKNS; namespace YTKNS;
// Prevent running cron script during maintenance
if(YTKNS_MAINTENANCE)
return;
if(!defined('YTKNS_SEM_NAME')) if(!defined('YTKNS_SEM_NAME'))
define('YTKNS_SEM_NAME', 'b'); define('YTKNS_SEM_NAME', 'b');
if(!defined('YTKNS_SFM_PATH')) if(!defined('YTKNS_SFM_PATH'))

View file

@ -45,6 +45,13 @@ body {
box-shadow: 0 1px 4px #000; box-shadow: 0 1px 4px #000;
} }
.maintenance {
background: #c00;
color: #fff;
font-size: .9em;
padding: 5px 10px;
}
@media(min-width: 1000px) { @media(min-width: 1000px) {
body { padding-top: 1px; } body { padding-top: 1px; }
.wrapper { margin: 3px auto 10px; } .wrapper { margin: 3px auto 10px; }

View file

@ -68,6 +68,8 @@ function html_header(array $vars = []): string {
$vars['menu_user'] = Template::renderSet('menu-user-item', $userMenu); $vars['menu_user'] = Template::renderSet('menu-user-item', $userMenu);
$vars['maintenance'] = YTKNS_MAINTENANCE ? Template::renderRaw('maintenance') : '';
return Template::renderRaw('header', $vars); return Template::renderRaw('header', $vars);
} }
@ -117,7 +119,7 @@ function html_pagination(int $pages, int $current, string $urlFormat): string {
return $html . '</div>'; return $html . '</div>';
} }
if(!empty($_COOKIE['ytkns_login']) && is_string($_COOKIE['ytkns_login'])) { if(!YTKNS_MAINTENANCE && !empty($_COOKIE['ytkns_login']) && is_string($_COOKIE['ytkns_login'])) {
try { try {
$session = UserSession::byToken($_COOKIE['ytkns_login']); $session = UserSession::byToken($_COOKIE['ytkns_login']);
$session->update(); $session->update();
@ -152,13 +154,15 @@ if(!empty($zoneName)) {
return; return;
} }
if(!empty($_GET['_refresh_screenshot'])) { if(!YTKNS_MAINTENANCE) {
header('Location: /'); if(!empty($_GET['_refresh_screenshot'])) {
$zoneInfo->takeScreenshot(); header('Location: /');
return; $zoneInfo->takeScreenshot();
} return;
}
ZoneView::increment($zoneInfo, $_SERVER['REMOTE_ADDR']); ZoneView::increment($zoneInfo, $_SERVER['REMOTE_ADDR']);
}
echo (string)$zoneInfo->getPageBuilder(true); echo (string)$zoneInfo->getPageBuilder(true);
return; return;
@ -924,6 +928,12 @@ if($reqPath === '/settings/invites') {
} }
if($reqPath === '/auth/login') { if($reqPath === '/auth/login') {
if(YTKNS_MAINTENANCE) {
http_response_code(503);
echo html_information('You cannot log in during maintenance.');
return;
}
if(UserSession::hasInstance()) { if(UserSession::hasInstance()) {
http_response_code(404); http_response_code(404);
echo html_information('You are logged in already.'); echo html_information('You are logged in already.');
@ -985,6 +995,12 @@ if($reqPath === '/auth/login') {
} }
if($reqPath === '/auth/register') { if($reqPath === '/auth/register') {
if(YTKNS_MAINTENANCE) {
http_response_code(503);
echo html_information('You cannot register during maintenance.');
return;
}
if(UserSession::hasInstance()) { if(UserSession::hasInstance()) {
http_response_code(404); http_response_code(404);
echo html_information('You are logged in already.'); echo html_information('You are logged in already.');

View file

@ -39,7 +39,7 @@ final class Config {
public static function set(string $key, $value, bool $soft = false): void { public static function set(string $key, $value, bool $soft = false): void {
self::$config[$key] = $value; self::$config[$key] = $value;
if(!$soft) { if(!YTKNS_MAINTENANCE && !$soft) {
$value = serialize($value); $value = serialize($value);
$save = DB::prepare('REPLACE INTO `ytkns_config` (`config_key`, `config_value`) VALUES (:key, :value)'); $save = DB::prepare('REPLACE INTO `ytkns_config` (`config_key`, `config_value`) VALUES (:key, :value)');

View file

@ -22,6 +22,7 @@
</head> </head>
<body> <body>
<div class="wrapper"> <div class="wrapper">
:maintenance
<div class="header"> <div class="header">
<div class="header-usermenu"> <div class="header-usermenu">
:menu_user :menu_user

View file

@ -0,0 +1,3 @@
<div class="maintenance">
YTKNS is currently in read-only maintenance mode.
</div>