From 530e249b8fb11c3923c90f3f7560bc76bee76502 Mon Sep 17 00:00:00 2001 From: Niek Rabelink Date: Mon, 7 Sep 2026 13:30:55 +0200 Subject: [PATCH 1/2] feat: Implement secure authentication module and integrate session management across multiple files --- auth.php | 90 +++++++++++++++++ index.php | 11 ++- lab.php | 8 +- login.php | 286 +++++++++++++++++++++++++++++++++++++++++++++++++++++ logout.php | 9 ++ tools.php | 6 +- 6 files changed, 404 insertions(+), 6 deletions(-) create mode 100644 auth.php create mode 100644 login.php create mode 100644 logout.php 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 @@ + From 6b827ac1db2d28f8fa7e32f665e67939d9aee9ee Mon Sep 17 00:00:00 2001 From: Niek Rabelink Date: Mon, 7 Sep 2026 13:31:03 +0200 Subject: [PATCH 2/2] chore: Add new line at the end of auth.php, login.php, and logout.php for consistency --- auth.php | 1 + login.php | 1 + logout.php | 1 + 3 files changed, 3 insertions(+) diff --git a/auth.php b/auth.php index b6c649f..2871db7 100644 --- a/auth.php +++ b/auth.php @@ -88,3 +88,4 @@ function logout() { } @session_destroy(); } + diff --git a/login.php b/login.php index 3f33168..d24d20f 100644 --- a/login.php +++ b/login.php @@ -284,3 +284,4 @@ $logoutMessage = isset($_GET['logout']) ? 'U bent succesvol en veilig uitgelogd. + diff --git a/logout.php b/logout.php index a6ee288..5a7b069 100644 --- a/logout.php +++ b/logout.php @@ -7,3 +7,4 @@ require_once __DIR__ . '/auth.php'; logout(); header('Location: login.php?logout=1'); exit; +