From 6f1c34f28d0168d8ea6647ef3e459b11078e4dc7 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 20 Jan 2025 00:51:00 -0800 Subject: [PATCH 01/23] Initial commit --- ajax/session/do_check_session.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ajax/session/do_check_session.php diff --git a/ajax/session/do_check_session.php b/ajax/session/do_check_session.php new file mode 100644 index 00000000..401ea30c --- /dev/null +++ b/ajax/session/do_check_session.php @@ -0,0 +1,28 @@ += RASPI_SESSION_TIMEOUT ? 'session_expired' : 'active'; + +// send response +header('Content-Type: application/json'); +header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); +header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); +header('Pragma: no-cache'); + +$response = [ + 'status' => $status, + 'last_activity' => $lastActivity, + 'session_lifetime' => $sessionLifetime, + 'timeout_duration' => RASPI_SESSION_TIMEOUT +]; + +echo json_encode($response); +exit(); + From 3cf22a9cbbaea8bafd9b1784cc9ecaac4fd8569c Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 20 Jan 2025 00:52:28 -0800 Subject: [PATCH 02/23] Define RASPI_SESSION_TIMEOUT --- config/config.php | 1 + includes/defaults.php | 1 + 2 files changed, 2 insertions(+) diff --git a/config/config.php b/config/config.php index 2950632d..feaeecea 100755 --- a/config/config.php +++ b/config/config.php @@ -11,6 +11,7 @@ define('RASPI_CACHE_PATH', sys_get_temp_dir() . '/raspap'); define('RASPI_ERROR_LOG', sys_get_temp_dir() . '/raspap_error.log'); define('RASPI_DEBUG_LOG', 'raspap_debug.log'); define('RASPI_LOG_SIZE_LIMIT', 64); +define('RASPI_SESSION_TIMEOUT', 1440); // Constants for configuration file paths. // These are typical for default RPi installs. Modify if needed. diff --git a/includes/defaults.php b/includes/defaults.php index 3b918b58..e7c42cbd 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -16,6 +16,7 @@ $defaults = [ 'RASPI_ERROR_LOG' => sys_get_temp_dir() . '/raspap_error.log', 'RASPI_DEBUG_LOG' => 'raspap_debug.log', 'RASPI_LOG_SIZE_LIMIT' => 64, + 'RASPI_SESSION_TIMEOUT' => 1440, // Constants for configuration file paths. // These are typical for default RPi installs. Modify if needed. From 866d8eb5b02b132f9332d8dea3e655d6b480f0c2 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 20 Jan 2025 00:53:26 -0800 Subject: [PATCH 03/23] Update w/ sessionTimeoutModal, lastActivity --- includes/footer.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/footer.php b/includes/footer.php index 38965fc6..c35a2fc2 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -1,3 +1,5 @@ + +
v | @@ -8,3 +10,19 @@
+ + From c51b520b8dec840c059f2bc20f1b682fc0f0a12a Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 20 Jan 2025 00:55:21 -0800 Subject: [PATCH 04/23] Decouple session from csrf handler, set initial lastActivity --- includes/csrf.php | 1 - includes/session.php | 5 +++++ index.php | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/csrf.php b/includes/csrf.php index bca935df..4e098e5b 100755 --- a/includes/csrf.php +++ b/includes/csrf.php @@ -1,7 +1,6 @@ Date: Mon, 20 Jan 2025 00:58:18 -0800 Subject: [PATCH 05/23] Add checkSession(), showSessionExpiredModal() --- app/js/custom.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/js/custom.js b/app/js/custom.js index c33a5d5a..d63daa05 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -671,6 +671,28 @@ window.addEventListener('load', function() { }); }, false); +let sessionCheckInterval = setInterval(checkSession, 5000); + +function checkSession() { + $.get('ajax/session/do_check_session.php', function (data) { + if (data.status === 'session_expired') { + clearInterval(sessionCheckInterval); + showSessionExpiredModal(); + } + }).fail(function (jqXHR, status, err) { + console.error("Error checking session status:", status, err); + }); +} + +function showSessionExpiredModal() { + $('#sessionTimeoutModal').modal('show'); +} + +$(document).on("click", "#js-session-expired-login", function(e) { + console.log('clicked!'); + window.location.href = '/login'; +}); + // DHCP or Static IP option group $('#chkstatic').on('change', function() { if (this.checked) { From 3f883a70de2757a56d23b3cf40206af0b5d938e7 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 21 Jan 2025 00:29:14 -0800 Subject: [PATCH 06/23] Initial commit --- includes/login.php | 38 ++++++++++++++++++++++++++++++++++++++ templates/login.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 includes/login.php create mode 100644 templates/login.php diff --git a/includes/login.php b/includes/login.php new file mode 100644 index 00000000..89374894 --- /dev/null +++ b/includes/login.php @@ -0,0 +1,38 @@ +login($username, $password)) { + $config = $auth->getAuthConfig(); + header('Location: ' . $redirectUrl); + die(); + } else { + $status = "Login failed"; + } + } + } + + echo renderTemplate( + "login", compact( + "status", + "redirectUrl" + ) + ); +} + diff --git a/templates/login.php b/templates/login.php new file mode 100644 index 00000000..41d1f3f1 --- /dev/null +++ b/templates/login.php @@ -0,0 +1,42 @@ + + + From 792ce0c956a4c21fd1f88f35f3f66933f655dfc4 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 21 Jan 2025 00:29:59 -0800 Subject: [PATCH 07/23] Include login.php, buffer page output --- index.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.php b/index.php index badd2762..3e060dc0 100755 --- a/index.php +++ b/index.php @@ -36,6 +36,7 @@ require_once 'includes/functions.php'; // Default page actions require_once 'includes/dashboard.php'; +require_once 'includes/login.php'; require_once 'includes/authenticate.php'; require_once 'includes/admin.php'; require_once 'includes/dhcp.php'; @@ -97,6 +98,7 @@ initializeApp(); +
@@ -124,6 +126,7 @@ initializeApp();
+ From 6dbdf89760718a6205a13568405b47904ca3a666 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 21 Jan 2025 00:30:40 -0800 Subject: [PATCH 08/23] Add DisplayLogin() page handler --- includes/page_actions.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/page_actions.php b/includes/page_actions.php index 2e406bf8..c9649792 100755 --- a/includes/page_actions.php +++ b/includes/page_actions.php @@ -70,6 +70,9 @@ function handleCorePageAction(string $page, array &$extraFooterScripts): void case "/about": DisplayAbout(); break; + case "/login": + DisplayLogin(); + break; default: DisplayDashboard($extraFooterScripts); } From 6cb0be96b461a78ac24c64bbdadace8fff69f6c9 Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 21 Jan 2025 00:31:49 -0800 Subject: [PATCH 09/23] Set data-bs-backdrop + data-bs-keyboard attributes --- includes/footer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/footer.php b/includes/footer.php index c35a2fc2..b12c0f1c 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -1,6 +1,6 @@ -
+
v | Created by the RaspAP Team @@ -10,7 +10,7 @@
-