199 lines
7.1 KiB
PHP
199 lines
7.1 KiB
PHP
<?php
|
|
ob_start();
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'domain' => '',
|
|
'secure' => false,
|
|
'httponly' => true,
|
|
'samesite' => 'Lax'
|
|
]);
|
|
session_start();
|
|
|
|
if (empty($_SESSION['user_logged_in'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/src/MVC/autoloader.php';
|
|
|
|
include_once( __DIR__ . '/config.php');
|
|
include_once( __DIR__ . '/src/classes/getData.php');
|
|
include_once( __DIR__ . '/src/controller/apiController.php');
|
|
include_once( __DIR__ . '/src/controller/cookieController.php');
|
|
include_once( __DIR__ . '/src/controller/rightsController.php');
|
|
include_once( __DIR__ . '/src/controller/userController.php');
|
|
include_once( __DIR__ . '/src/database/databaseConnect.php');
|
|
include_once( __DIR__ . '/src/utils/Debugging/ConsoleLogger.php');
|
|
include_once( __DIR__ . '/src/utils/databaseMethods.php');
|
|
include_once( __DIR__ . '/src/utils/formatter.php');
|
|
include_once( __DIR__ . '/src/utils/mailer.php');
|
|
include_once( __DIR__ . '/src/utils/requestLogger.php');
|
|
include_once( __DIR__ . '/src/utils/router.php');
|
|
|
|
$user_id = DatabaseShow(
|
|
"Benutzer",
|
|
"ID",
|
|
"NAME = ?",
|
|
$_SESSION['username'],
|
|
);
|
|
|
|
$rightsArray = DatabaseShowWithFK(
|
|
"Benutzer_Berechtigungen",
|
|
$Berechtigungen,
|
|
"SEITEN_ID",
|
|
"BENUTZER_ID = ?",
|
|
$user_id[0]['ID'],
|
|
);
|
|
|
|
$userRights = array_map('trim', array_column($rightsArray['rows'], 'SEITEN_ID'));
|
|
|
|
$selectedService = null;
|
|
|
|
if (
|
|
isset($_GET['service']) &&
|
|
isset($services[$_GET['service']]) &&
|
|
$services[$_GET['service']]['active']
|
|
) {
|
|
$selectedService = $_GET['service'];
|
|
}
|
|
|
|
if (!$selectedService &&
|
|
isset($defaultService) &&
|
|
isset($services[$defaultService]) &&
|
|
$services[$defaultService]['active']
|
|
) {
|
|
$selectedService = $defaultService;
|
|
}
|
|
|
|
if (!$selectedService) {
|
|
foreach ($services as $key => $service) {
|
|
if ($service['active']) {
|
|
$selectedService = $key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($selectedService && !in_array($selectedService, $userRights, true)) {
|
|
$selectedService = null;
|
|
}
|
|
|
|
$isAdmin = isset($_SESSION['is_admin']) && $_SESSION['is_admin'] === true;
|
|
|
|
if ((new getSpecificData())->getWebsite() != "backend.blackpi.ipv64.net") {
|
|
$title = "DEV Backend";
|
|
} else {
|
|
$title = "Backend";
|
|
}
|
|
|
|
// MVC Logic
|
|
try {
|
|
$router = new \MVC\Core\Router();
|
|
|
|
// Register Routes
|
|
$router->add('home_info', \MVC\Controller\ServiceController::class, 'home_info', ['auth']);
|
|
$router->add('links', \MVC\Controller\ServiceController::class, 'links', ['auth']);
|
|
$router->add('documentation', \MVC\Controller\DocumentationController::class, 'links', ['auth']);
|
|
$router->add('logout', \MVC\Controller\ServiceController::class, 'logout', ['auth']);
|
|
|
|
$router->add('public_request_logs', \MVC\Controller\LogController::class, 'public_request_logs', ['auth']);
|
|
$router->add('backend_request_logs', \MVC\Controller\LogController::class, 'backend_request_logs', ['auth']);
|
|
$router->add('personal_request_logs', \MVC\Controller\LogController::class, 'personal_request_logs', ['auth', 'admin']);
|
|
$router->add('public_request_chart', \MVC\Controller\LogController::class, 'public_request_chart', ['auth']);
|
|
$router->add('backend_request_chart', \MVC\Controller\LogController::class, 'backend_request_chart', ['auth']);
|
|
|
|
$router->add('user_control', \MVC\Controller\AdminController::class, 'user_control', ['auth', 'admin']);
|
|
$router->add('services_control', \MVC\Controller\AdminController::class, 'services_control', ['auth', 'admin']);
|
|
$router->add('variablen_control', \MVC\Controller\AdminController::class, 'variablen_control', ['auth', 'admin']);
|
|
$router->add('data_info', \MVC\Controller\AdminController::class, 'data_info', ['auth', 'admin']);
|
|
$router->add('tabellen', \MVC\Controller\AdminController::class, 'tabellen', ['auth', 'admin']);
|
|
|
|
$router->add('berichte', \MVC\Controller\ReportController::class, 'berichte', ['auth']);
|
|
$router->add('berichte_arbeit_gen', \MVC\Controller\ReportController::class, 'berichte_arbeit_gen', ['auth']);
|
|
$router->add('zeiterfassung', \MVC\Controller\ReportController::class, 'zeiterfassung', ['auth']);
|
|
$router->add('print_static', \MVC\Controller\ReportController::class, 'print_static', ['auth']);
|
|
|
|
$router->add('api_tester', \MVC\Controller\ApiController::class, 'api_tester', ['auth', 'admin']);
|
|
$router->add('weather_chart', \MVC\Controller\StatsController::class, 'weather_chart', ['auth', 'admin']);
|
|
$router->add('domains', \MVC\Controller\DomainController::class, 'domains', ['auth']);
|
|
$router->add('documentation', \MVC\Controller\DocumentationController::class, 'index', ['auth']);
|
|
|
|
$layout = new \MVC\Layout\Layout('main');
|
|
$layout->setBlock('title', $title);
|
|
|
|
// Header Block
|
|
ob_start();
|
|
?>
|
|
Backend
|
|
<button id="darkModeToggle">Dark Mode</button>
|
|
<button id="logoutButton">Logout</button>
|
|
<?php
|
|
$layout->setBlock('header', ob_get_clean());
|
|
|
|
// Sidebar Block
|
|
ob_start();
|
|
?>
|
|
<?php foreach ($serviceGroups as $groupKey => $group): ?>
|
|
<?php
|
|
$visibleServices = [];
|
|
|
|
foreach ($group['services'] as $serviceKey) {
|
|
if (!isset($services[$serviceKey])) continue;
|
|
if (!$services[$serviceKey]['active']) continue;
|
|
if (!empty($services[$serviceKey]['adminOnly']) && !$isAdmin) continue;
|
|
if (!in_array($serviceKey, $userRights, true)) continue;
|
|
$visibleServices[] = $serviceKey;
|
|
}
|
|
|
|
if (empty($visibleServices)) continue;
|
|
|
|
$isOpen = !empty($group['defaultOpen']) || in_array($selectedService, $visibleServices, true);
|
|
?>
|
|
<div class="service-group <?= $isOpen ? 'open' : '' ?>" data-group="<?= $groupKey ?>">
|
|
|
|
<div class="group-title">
|
|
<?= htmlspecialchars($group['label']) ?>
|
|
<span class="arrow">▸</span>
|
|
</div>
|
|
|
|
<div class="group-services">
|
|
<?php foreach ($visibleServices as $serviceKey): ?>
|
|
<a href="?service=<?= $serviceKey ?>">
|
|
<button class="<?= $selectedService === $serviceKey ? 'active' : '' ?>">
|
|
<?= htmlspecialchars($services[$serviceKey]['name']) ?>
|
|
</button>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php
|
|
$layout->setBlock('sidebar', ob_get_clean());
|
|
|
|
// Content Block
|
|
if ($selectedService) {
|
|
$content = $router->dispatch($selectedService);
|
|
$layout->setBlock('content', $content);
|
|
logging();
|
|
} else {
|
|
$layout->setBlock('content', "<p>Kein aktiver Service verfügbar.</p>");
|
|
}
|
|
|
|
echo $layout->render();
|
|
|
|
} catch (\Exception $e) {
|
|
// Central Error Handling
|
|
error_log($e->getMessage());
|
|
http_response_code(500);
|
|
|
|
if ($isAdmin) {
|
|
echo "<h1>Internal Server Error</h1>";
|
|
echo "<p><strong>Message:</strong> " . $e->getMessage() . "</p>";
|
|
echo "<p><strong>File:</strong> " . $e->getFile() . " on line " . $e->getLine() . "</p>";
|
|
echo "<pre>" . $e->getTraceAsString() . "</pre>";
|
|
} else {
|
|
echo "<h1>Hoppla!</h1>";
|
|
echo "<p>Ein interner Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.</p>";
|
|
}
|
|
}
|