2026-03-04 20:46:11 +00:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../core/bootstrap.php';
|
|
|
|
|
|
2026-04-01 14:12:17 +00:00
|
|
|
if (session_status() !== PHP_SESSION_ACTIVE) {
|
|
|
|
|
session_start();
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 20:46:11 +00:00
|
|
|
$uriPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
|
|
|
|
|
$uriPath = is_string($uriPath) && $uriPath !== '' ? $uriPath : '/';
|
|
|
|
|
$isAdminRoute = str_starts_with($uriPath, '/admin');
|
|
|
|
|
$maintenanceWhitelist = [
|
|
|
|
|
'/support/imap-sync',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
Core\Services\Settings::get('site_maintenance_enabled', '0') === '1'
|
|
|
|
|
&& !Core\Services\Auth::check()
|
|
|
|
|
&& !$isAdminRoute
|
|
|
|
|
&& !in_array($uriPath, $maintenanceWhitelist, true)
|
|
|
|
|
) {
|
2026-04-01 14:12:17 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 20:46:11 +00:00
|
|
|
$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', '');
|
2026-04-01 14:12:17 +00:00
|
|
|
$siteTitle = Core\Services\Settings::get('site_title', 'AudioCore V1.5.1');
|
2026-03-04 20:46:11 +00:00
|
|
|
|
|
|
|
|
$contentHtml = '';
|
|
|
|
|
if ($customHtml !== '') {
|
|
|
|
|
$contentHtml = $customHtml;
|
|
|
|
|
} else {
|
|
|
|
|
$contentHtml = '<div class="ac-maintenance-wrap">'
|
|
|
|
|
. '<div class="ac-maintenance-badge">Maintenance Mode</div>'
|
|
|
|
|
. '<h1>' . htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</h1>'
|
|
|
|
|
. '<p>' . nl2br(htmlspecialchars($message, ENT_QUOTES, 'UTF-8')) . '</p>';
|
|
|
|
|
if ($buttonLabel !== '' && $buttonUrl !== '') {
|
|
|
|
|
$contentHtml .= '<a class="ac-maintenance-btn" href="' . htmlspecialchars($buttonUrl, ENT_QUOTES, 'UTF-8') . '">'
|
|
|
|
|
. htmlspecialchars($buttonLabel, ENT_QUOTES, 'UTF-8')
|
|
|
|
|
. '</a>';
|
|
|
|
|
}
|
2026-04-01 14:12:17 +00:00
|
|
|
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>';
|
|
|
|
|
}
|
2026-03-04 20:46:11 +00:00
|
|
|
$contentHtml .= '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$maintenanceHtml = '<!doctype html><html lang="en"><head><meta charset="utf-8">'
|
|
|
|
|
. '<meta name="viewport" content="width=device-width, initial-scale=1">'
|
|
|
|
|
. '<title>' . htmlspecialchars($siteTitle, ENT_QUOTES, 'UTF-8') . '</title>'
|
|
|
|
|
. '<style>'
|
|
|
|
|
. 'body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px;background:linear-gradient(180deg,#131419,#0f1014);color:#eef2ff;font-family:Syne,system-ui,sans-serif;}'
|
|
|
|
|
. '.ac-maintenance-wrap{max-width:780px;width:100%;padding:36px;border-radius:22px;border:1px solid rgba(255,255,255,.12);background:rgba(21,23,30,.86);box-shadow:0 20px 60px rgba(0,0,0,.35);}'
|
|
|
|
|
. '.ac-maintenance-badge{font-family:IBM Plex Mono,monospace;text-transform:uppercase;font-size:11px;letter-spacing:.24em;color:rgba(255,255,255,.6);}'
|
|
|
|
|
. 'h1{font-size:42px;line-height:1.08;margin:14px 0 0;}'
|
|
|
|
|
. '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);}'
|
2026-04-01 14:12:17 +00:00
|
|
|
. '.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;}'
|
2026-03-04 20:46:11 +00:00
|
|
|
. '</style></head><body>' . $contentHtml . '</body></html>';
|
|
|
|
|
|
|
|
|
|
(new Core\Http\Response($maintenanceHtml, 503, ['Content-Type' => 'text/html; charset=utf-8']))->send();
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 14:12:17 +00:00
|
|
|
maintenance_bypass_complete:
|
|
|
|
|
|
2026-03-04 20:46:11 +00:00
|
|
|
$router = new Core\Http\Router();
|
|
|
|
|
$router->get('/', function (): Core\Http\Response {
|
|
|
|
|
$db = Core\Services\Database::get();
|
|
|
|
|
if ($db instanceof PDO) {
|
|
|
|
|
$stmt = $db->prepare("SELECT title, content_html FROM ac_pages WHERE is_home = 1 AND is_published = 1 LIMIT 1");
|
|
|
|
|
$stmt->execute();
|
|
|
|
|
$page = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
if ($page) {
|
|
|
|
|
$view = new Core\Views\View(__DIR__ . '/../modules/pages/views');
|
|
|
|
|
return new Core\Http\Response($view->render('site/show.php', [
|
|
|
|
|
'title' => (string)$page['title'],
|
|
|
|
|
'content_html' => Core\Services\Shortcodes::render((string)$page['content_html'], [
|
|
|
|
|
'page_slug' => 'home',
|
|
|
|
|
'page_title' => (string)$page['title'],
|
|
|
|
|
]),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$view = new Core\Views\View(__DIR__ . '/../views');
|
|
|
|
|
return new Core\Http\Response($view->render('site/home.php', [
|
2026-04-01 14:12:17 +00:00
|
|
|
'title' => 'AudioCore V1.5.1',
|
2026-03-04 20:46:11 +00:00
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
$router->registerModules(__DIR__ . '/../modules');
|
|
|
|
|
Core\Services\Plugins::register($router);
|
|
|
|
|
|
|
|
|
|
$response = $router->dispatch($_SERVER['REQUEST_URI'] ?? '/', $_SERVER['REQUEST_METHOD'] ?? 'GET');
|
|
|
|
|
$response->send();
|