diff --git a/auth.php b/auth.php new file mode 100644 index 0000000..b6c649f --- /dev/null +++ b/auth.php @@ -0,0 +1,90 @@ + 7200)) { + logout(); + return false; + } + $_SESSION['wpc_last_activity'] = time(); + return true; + } + return false; +} + +/** + * Blokkeert ongeautoriseerde toegang en stuurt door naar het inlogscherm. + */ +function require_auth() { + if (!is_logged_in()) { + // Als het een asynchrone AJAX aanroep is, geef HTTP 401 Unauthorized + if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) || isset($_GET['action']) || isset($_GET['api'])) { + header('HTTP/1.1 401 Unauthorized'); + header('Content-Type: application/json; charset=utf-8'); + echo json_encode(['status' => 'unauthorized', 'message' => 'Sessie verlopen of niet ingelogd.']); + exit; + } + + $redirect = urlencode($_SERVER['REQUEST_URI'] ?? 'index.php'); + header("Location: login.php?redirect={$redirect}"); + exit; + } +} + +/** + * Genereert een CSRF token voor formulieren. + */ +function get_csrf_token() { + if (empty($_SESSION['wpc_csrf'])) { + $_SESSION['wpc_csrf'] = bin2hex(random_bytes(32)); + } + return $_SESSION['wpc_csrf']; +} + +/** + * Valideert het ingediende CSRF token. + */ +function verify_csrf_token($token) { + if (empty($_SESSION['wpc_csrf']) || empty($token)) { + return false; + } + return hash_equals($_SESSION['wpc_csrf'], $token); +} + +/** + * Beëindigt de sessie en ruimt cookies op. + */ +function logout() { + $_SESSION = []; + if (ini_get("session.use_cookies")) { + $params = session_get_cookie_params(); + setcookie(session_name(), '', time() - 42000, + $params["path"], $params["domain"], + $params["secure"], $params["httponly"] + ); + } + @session_destroy(); +} diff --git a/index.php b/index.php index be2da71..b0173ee 100644 --- a/index.php +++ b/index.php @@ -4,6 +4,9 @@ * Hoofdpagina voor status, runtime verificatie en Git webhook deployment tests. */ +require_once __DIR__ . '/auth.php'; +require_auth(); + // Snelle API responder voor AJAX pings if (isset($_GET['api']) && $_GET['api'] === 'status') { header('Content-Type: application/json; charset=utf-8'); @@ -23,9 +26,10 @@ date_default_timezone_set('Europe/Amsterdam'); $serverTime = date('d-m-Y H:i:s'); $phpVersion = PHP_VERSION; $serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? 'Apache / Nginx'; -$host = $_SERVER['HTTP_HOST'] ?? 'www.webenpcstudio.nl'; +$host = $_SERVER['HTTP_HOST'] ?? 'server.webenpcstudio.nl'; $clientIp = $_SERVER['REMOTE_ADDR'] ?? 'Onbekend'; $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'HTTPS' : 'HTTP'; +$loggedUser = $_SESSION['wpc_user_email'] ?? 'niek.rabelink@gmail.com'; // Git repository inspectie (met veilige fallback) $activeBranch = 'dev'; @@ -91,9 +95,10 @@ if (empty($commits)) { @@ -102,7 +107,7 @@ if (empty($commits)) {

Systeem Dashboard & Git Status

- Realtime omgevingsstatus, Git webhook deploy-verificatie en server-runtime monitoring voor www.webenpcstudio.nl. + Realtime omgevingsstatus, Git webhook deploy-verificatie en server-runtime monitoring voor server.webenpcstudio.nl.

diff --git a/lab.php b/lab.php index 9658f03..d743d4c 100644 --- a/lab.php +++ b/lab.php @@ -4,6 +4,9 @@ * Diepgaande diagnostische suite voor CPU, NVMe Disk I/O, RAM en HTTP Concurrency. */ +require_once __DIR__ . '/auth.php'; +require_auth(); + // Helper functies voor benchmarks function benchmarkCPU() { $start = microtime(true); @@ -387,6 +390,7 @@ $serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? 'Apache / Nginx'; + 🚪 Uitloggen @@ -403,7 +407,7 @@ $serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? 'Apache / Nginx';

⚡ Volledige Server Benchmark

- Voert in één geautomatiseerde cyclus alle 5 hardware- & softwaretests uit op www.webenpcstudio.nl. + Voert in één geautomatiseerde cyclus alle 5 hardware- & softwaretests uit op server.webenpcstudio.nl.

+
+
+ + + + + + + + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..a6ee288 --- /dev/null +++ b/logout.php @@ -0,0 +1,9 @@ +