Release v1.5.1
This commit is contained in:
@@ -3,6 +3,10 @@ declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../core/bootstrap.php';
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$uriPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
|
||||
$uriPath = is_string($uriPath) && $uriPath !== '' ? $uriPath : '/';
|
||||
$isAdminRoute = str_starts_with($uriPath, '/admin');
|
||||
@@ -16,12 +20,33 @@ if (
|
||||
&& !$isAdminRoute
|
||||
&& !in_array($uriPath, $maintenanceWhitelist, true)
|
||||
) {
|
||||
$maintenancePasswordHash = (string)Core\Services\Settings::get('site_maintenance_access_password_hash', '');
|
||||
$maintenanceBypassKey = $maintenancePasswordHash !== '' ? hash('sha256', $maintenancePasswordHash) : '';
|
||||
$hasMaintenanceBypass = $maintenanceBypassKey !== ''
|
||||
&& (string)($_SESSION['ac_maintenance_bypass'] ?? '') === $maintenanceBypassKey;
|
||||
$passwordError = '';
|
||||
|
||||
if ($maintenancePasswordHash !== '' && !$hasMaintenanceBypass && ($_SERVER['REQUEST_METHOD'] ?? 'GET') === 'POST') {
|
||||
$submittedPassword = (string)($_POST['ac_maintenance_access_password'] ?? '');
|
||||
if ($submittedPassword !== '' && password_verify($submittedPassword, $maintenancePasswordHash)) {
|
||||
$_SESSION['ac_maintenance_bypass'] = $maintenanceBypassKey;
|
||||
$redirectTo = (string)($_SERVER['REQUEST_URI'] ?? '/');
|
||||
(new Core\Http\Response('', 302, ['Location' => $redirectTo !== '' ? $redirectTo : '/']))->send();
|
||||
exit;
|
||||
}
|
||||
$passwordError = 'Incorrect access password.';
|
||||
}
|
||||
|
||||
if ($hasMaintenanceBypass) {
|
||||
goto maintenance_bypass_complete;
|
||||
}
|
||||
|
||||
$title = Core\Services\Settings::get('site_maintenance_title', 'Coming Soon');
|
||||
$message = Core\Services\Settings::get('site_maintenance_message', 'We are currently updating the site. Please check back soon.');
|
||||
$buttonLabel = Core\Services\Settings::get('site_maintenance_button_label', '');
|
||||
$buttonUrl = Core\Services\Settings::get('site_maintenance_button_url', '');
|
||||
$customHtml = Core\Services\Settings::get('site_maintenance_html', '');
|
||||
$siteTitle = Core\Services\Settings::get('site_title', 'AudioCore V1.5');
|
||||
$siteTitle = Core\Services\Settings::get('site_title', 'AudioCore V1.5.1');
|
||||
|
||||
$contentHtml = '';
|
||||
if ($customHtml !== '') {
|
||||
@@ -36,6 +61,18 @@ if (
|
||||
. htmlspecialchars($buttonLabel, ENT_QUOTES, 'UTF-8')
|
||||
. '</a>';
|
||||
}
|
||||
if ($maintenancePasswordHash !== '') {
|
||||
$contentHtml .= '<form method="post" class="ac-maintenance-form">'
|
||||
. '<label class="ac-maintenance-label" for="acMaintenancePassword">Access Password</label>'
|
||||
. '<div class="ac-maintenance-form-row">'
|
||||
. '<input id="acMaintenancePassword" class="ac-maintenance-input" type="password" name="ac_maintenance_access_password" placeholder="Enter access password" autocomplete="current-password">'
|
||||
. '<button class="ac-maintenance-submit" type="submit">Unlock Site</button>'
|
||||
. '</div>';
|
||||
if ($passwordError !== '') {
|
||||
$contentHtml .= '<div class="ac-maintenance-error">' . htmlspecialchars($passwordError, ENT_QUOTES, 'UTF-8') . '</div>';
|
||||
}
|
||||
$contentHtml .= '</form>';
|
||||
}
|
||||
$contentHtml .= '</div>';
|
||||
}
|
||||
|
||||
@@ -50,12 +87,20 @@ if (
|
||||
. 'p{font-size:18px;line-height:1.7;margin:16px 0 0;color:rgba(235,241,255,.8);}'
|
||||
. '.ac-maintenance-btn{margin-top:20px;display:inline-block;padding:10px 18px;border-radius:999px;border:1px solid rgba(255,255,255,.2);color:#f7f8ff;text-decoration:none;font-size:12px;text-transform:uppercase;letter-spacing:.18em;}'
|
||||
. '.ac-maintenance-btn:hover{background:rgba(255,255,255,.08);}'
|
||||
. '.ac-maintenance-form{margin-top:24px;padding-top:20px;border-top:1px solid rgba(255,255,255,.12);}'
|
||||
. '.ac-maintenance-label{display:block;font-family:IBM Plex Mono,monospace;text-transform:uppercase;font-size:11px;letter-spacing:.24em;color:rgba(255,255,255,.7);margin:0 0 10px;}'
|
||||
. '.ac-maintenance-form-row{display:flex;gap:12px;flex-wrap:wrap;}'
|
||||
. '.ac-maintenance-input{flex:1 1 260px;min-width:220px;padding:14px 16px;border-radius:14px;border:1px solid rgba(255,255,255,.16);background:rgba(9,11,16,.75);color:#eef2ff;font:inherit;}'
|
||||
. '.ac-maintenance-submit{padding:14px 18px;border-radius:14px;border:1px solid rgba(34,242,165,.45);background:rgba(34,242,165,.16);color:#effff8;font-family:IBM Plex Mono,monospace;font-size:12px;text-transform:uppercase;letter-spacing:.18em;cursor:pointer;}'
|
||||
. '.ac-maintenance-error{margin-top:10px;color:#ffb4b4;font-size:14px;}'
|
||||
. '</style></head><body>' . $contentHtml . '</body></html>';
|
||||
|
||||
(new Core\Http\Response($maintenanceHtml, 503, ['Content-Type' => 'text/html; charset=utf-8']))->send();
|
||||
exit;
|
||||
}
|
||||
|
||||
maintenance_bypass_complete:
|
||||
|
||||
$router = new Core\Http\Router();
|
||||
$router->get('/', function (): Core\Http\Response {
|
||||
$db = Core\Services\Database::get();
|
||||
@@ -76,7 +121,7 @@ $router->get('/', function (): Core\Http\Response {
|
||||
}
|
||||
$view = new Core\Views\View(__DIR__ . '/../views');
|
||||
return new Core\Http\Response($view->render('site/home.php', [
|
||||
'title' => 'AudioCore V1.5',
|
||||
'title' => 'AudioCore V1.5.1',
|
||||
]));
|
||||
});
|
||||
$router->registerModules(__DIR__ . '/../modules');
|
||||
|
||||
Reference in New Issue
Block a user