Added maintenance mode.

This commit is contained in:
Pachira 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
namespace YTKNS;
// Prevent running cron script during maintenance
if(YTKNS_MAINTENANCE)
return;
if(!defined('YTKNS_SEM_NAME'))
define('YTKNS_SEM_NAME', 'b');
if(!defined('YTKNS_SFM_PATH'))

View file

@ -45,6 +45,13 @@ body {
box-shadow: 0 1px 4px #000;
}
.maintenance {
background: #c00;
color: #fff;
font-size: .9em;
padding: 5px 10px;
}
@media(min-width: 1000px) {
body { padding-top: 1px; }
.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['maintenance'] = YTKNS_MAINTENANCE ? Template::renderRaw('maintenance') : '';
return Template::renderRaw('header', $vars);
}
@ -117,7 +119,7 @@ function html_pagination(int $pages, int $current, string $urlFormat): string {
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 {
$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.');

View file

@ -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)');

View file

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

View file

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