Merge pull request #225 from Focuslinkstech/master

Add session expiration settings
This commit is contained in:
iBNu Maksum
2024-07-29 08:59:12 +07:00
committed by GitHub
5 changed files with 338 additions and 211 deletions

View File

@ -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'])) {

View File

@ -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) {

View File

@ -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) {