Added maintenance mode.
This commit is contained in:
parent
2e222021b9
commit
1d34c1f03e
6 changed files with 39 additions and 8 deletions
4
cron.php
4
cron.php
|
@ -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'))
|
||||||
|
|
|
@ -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; }
|
||||||
|
|
|
@ -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,6 +154,7 @@ if(!empty($zoneName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!YTKNS_MAINTENANCE) {
|
||||||
if(!empty($_GET['_refresh_screenshot'])) {
|
if(!empty($_GET['_refresh_screenshot'])) {
|
||||||
header('Location: /');
|
header('Location: /');
|
||||||
$zoneInfo->takeScreenshot();
|
$zoneInfo->takeScreenshot();
|
||||||
|
@ -159,6 +162,7 @@ if(!empty($zoneName)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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.');
|
||||||
|
|
|
@ -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)');
|
||||||
|
|
|
@ -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
|
||||||
|
|
3
templates/maintenance.html
Normal file
3
templates/maintenance.html
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="maintenance">
|
||||||
|
YTKNS is currently in read-only maintenance mode.
|
||||||
|
</div>
|
Loading…
Reference in a new issue