-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
48 lines (39 loc) · 1.87 KB
/
Copy pathindex.php
File metadata and controls
48 lines (39 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
require __DIR__ . '/app/bootstrap.php';
use XuiPanel\Controllers\AuthController;
use XuiPanel\Controllers\BouquetController;
use XuiPanel\Controllers\DashboardController;
use XuiPanel\Controllers\PasswordController;
$page = trim((string)($_GET['page'] ?? ''));
if ($page === '') {
$requestPath = (string)(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
$scriptDir = rtrim(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '')), '/');
if ($scriptDir !== '' && $scriptDir !== '/' && str_starts_with($requestPath, $scriptDir)) {
$requestPath = substr($requestPath, strlen($scriptDir));
}
$candidate = trim($requestPath, '/');
if ($candidate !== '' && !str_contains($candidate, '.')) {
$page = $candidate;
}
}
$page = $page === '' ? (current_user() ? 'dashboard' : 'login') : $page;
$GLOBALS['current_page'] = $page;
$method = strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET');
try {
match ($page) {
'login' => $method === 'POST' ? (new AuthController())->login() : (new AuthController())->showLogin(),
'logout' => (new AuthController())->logout(),
'dashboard' => (new DashboardController())->index(),
'bouquets' => $method === 'POST' ? (new BouquetController())->update() : (new BouquetController())->index(),
'password' => $method === 'POST' ? (new PasswordController())->update() : (new PasswordController())->index(),
default => (function (): void {
http_response_code(404);
view('error', ['title' => 'Page Not Found', 'message' => 'The page you are looking for could not be found.']);
})(),
};
} catch (Throwable $e) {
http_response_code(500);
$message = (bool)config('app.debug', false) ? $e->getMessage() : 'An unexpected error occurred.';
view('error', ['title' => 'Error', 'message' => $message]);
}