diff --git a/system/autoload/Admin.php b/system/autoload/Admin.php index c39ee81c..68d84698 100644 --- a/system/autoload/Admin.php +++ b/system/autoload/Admin.php @@ -11,35 +11,54 @@ class Admin public static function getID() { - global $db_password; - if (isset($_SESSION['aid'])) { + global $db_password, $config; + $enable_session_timeout = $config['enable_session_timeout']; + $session_timeout_duration = $config['session_timeout_duration'] * 60; // Convert minutes to seconds + + if (isset($_SESSION['aid']) && isset($_SESSION['aid_expiration']) && $_SESSION['aid_expiration'] > time()) { return $_SESSION['aid']; - } else if (isset($_COOKIE['aid'])) { + } elseif ($enable_session_timeout && isset($_SESSION['aid']) && isset($_SESSION['aid_expiration']) && $_SESSION['aid_expiration'] <= time()) { + self::removeCookie(); + session_destroy(); + _alert(Lang::T('Session has expired. Please log in again.'), 'danger', "admin"); + return 0; + } + // Check if cookie is set and valid + elseif (isset($_COOKIE['aid'])) { // id.time.sha1 $tmp = explode('.', $_COOKIE['aid']); if (sha1($tmp[0] . '.' . $tmp[1] . '.' . $db_password) == $tmp[2]) { if (time() - $tmp[1] < 86400 * 7) { $_SESSION['aid'] = $tmp[0]; + if ($enable_session_timeout) { + $_SESSION['aid_expiration'] = time() + $session_timeout_duration; + } return $tmp[0]; } } } + return 0; } public static function setCookie($aid) { - global $db_password; + global $db_password, $config; + $enable_session_timeout = $config['enable_session_timeout']; + $session_timeout_duration = $config['session_timeout_duration'] * 60; // Convert minutes to seconds if (isset($aid)) { $time = time(); $token = $aid . '.' . $time . '.' . sha1($aid . '.' . $time . '.' . $db_password); setcookie('aid', $token, time() + 86400 * 7); + $_SESSION['aid'] = $aid; + if ($enable_session_timeout) { + $_SESSION['aid_expiration'] = $time + $session_timeout_duration; + } return $token; } return ''; } - public static function removeCookie() { if (isset($_COOKIE['aid'])) { diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 8b3795bd..652c3ca3 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -155,7 +155,9 @@ switch ($action) { die(); } } - // Save all settings including tax system + // Save all settings including tax system + $enable_session_timeout = isset($_POST['enable_session_timeout']) ? 1 : 0; + $_POST['enable_session_timeout'] = $enable_session_timeout; foreach ($_POST as $key => $value) { $d = ORM::for_table('tbl_appconfig')->where('setting', $key)->find_one(); if ($d) { diff --git a/system/devices/Radius.php b/system/devices/Radius.php index 437bc4f7..46cc2f31 100644 --- a/system/devices/Radius.php +++ b/system/devices/Radius.php @@ -150,7 +150,7 @@ class Radius function remove_plan($plan) { // Delete Plan - $this->getTablePackage()->where_equal('plan_id', "plan_" . $plan['id'])->delete_many(); + $this->getTablePackage()->where_equal('plan_id', $plan['id'])->delete_many(); // Reset User Plan $c = $this->getTableUserPackage()->where_equal('groupname', "plan_" . $plan['id'])->findMany(); if ($c) { diff --git a/ui/ui/app-settings.tpl b/ui/ui/app-settings.tpl index eedb9473..baf5fed4 100644 --- a/ui/ui/app-settings.tpl +++ b/ui/ui/app-settings.tpl @@ -586,6 +586,24 @@ {Lang::T('Miscellaneous')}
+
+ +
+ +
+

{Lang::T('Logout Admin if not Available/Online a period of time')}

+
+
@@ -786,6 +804,38 @@ add dst-host=*.{$_domain}
+ + + -{/if} \ No newline at end of file + + {/if} \ No newline at end of file