Skip to content

Commit 1a5e1d5

Browse files
committed
hestiacp#1002 Limit session length
INACTIVE_SESSION_TIMEOUT is set 60 min by default need to be modifiable via UI
1 parent f0eaa05 commit 1a5e1d5

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

install/hst-install-debian.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,11 @@ if [ "$mysql" = 'yes' ]; then
16601660
source $HESTIA_INSTALL_DIR/phpmyadmin/pma.sh > /dev/null 2>&1
16611661
fi
16621662

1663+
#----------------------------------------------------------#
1664+
# Limit PHP SESSIONS #
1665+
#----------------------------------------------------------#
1666+
1667+
echo "INACTIVE_SESSION_TIMEOUT='60'" >> $HESTIA/conf/hestia.conf
16631668

16641669
#----------------------------------------------------------#
16651670
# Configure Admin User #

install/hst-install-ubuntu.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,11 @@ else
16831683
echo "API='no'" >> $HESTIA/conf/hestia.conf
16841684
fi
16851685

1686+
#----------------------------------------------------------#
1687+
# Limit PHP SESSIONS #
1688+
#----------------------------------------------------------#
1689+
1690+
echo "INACTIVE_SESSION_TIMEOUT='60'" >> $HESTIA/conf/hestia.conf
16861691

16871692
#----------------------------------------------------------#
16881693
# Fix phpmyadmin #

install/upgrade/versions/latest.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ if [ -f "$apt/postgresql.list" ]; then
5656
sed -i "s/http\:\/\/apt.postgresql.org/https\:\/\/apt.postgresql.org/g" $apt/postgresql.list
5757
fi
5858
fi
59+
60+
# Limit PHP Session Live time
61+
echo "INACTIVE_SESSION_TIMEOUT='60'" >> $HESTIA/conf/hestia.conf

web/inc/main.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@
7272
}
7373
}
7474

75+
if( NO_AUTH_REQUIRED !== true){
76+
if(empty($_SESSION['LAST_ACTIVITY']) || empty($_SESSION['INACTIVE_SESSION_TIMEOUT'])){
77+
session_destroy();
78+
header("Location: /login/");
79+
}else if ($_SESSION['INACTIVE_SESSION_TIMEOUT'] * 60 + $_SESSION['LAST_ACTIVITY'] < time()) {
80+
session_destroy();
81+
header("Location: /login/");
82+
}else{
83+
$_SESSION['LAST_ACTIVITY'] = time();
84+
}
85+
}
86+
7587
if (isset($_SESSION['language'])) {
7688
switch ($_SESSION['language']) {
7789
case 'ro':

web/login/index.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
define('NO_AUTH_REQUIRED',true);
4-
54
// Main include
65
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
76

@@ -12,8 +11,6 @@
1211
session_destroy();
1312
}
1413

15-
16-
1714
// Login as someone else
1815
if (isset($_SESSION['user'])) {
1916
if ($_SESSION['user'] == 'admin' && !empty($_GET['loginas'])) {
@@ -116,7 +113,7 @@ function authenticate_user(){
116113
// Define session user
117114
$_SESSION['user'] = key($data);
118115
$v_user = $_SESSION['user'];
119-
116+
$_SESSION['LAST_ACTIVITY'] = time();
120117
// Define language
121118
$output = '';
122119
exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);

0 commit comments

Comments
 (0)