Skip to content

Commit 2972a28

Browse files
committed
Keep log of successfull login attempts
- When user logs in create extra line in log - When same finger print is detected set old sessions as inactive - Logout via Session expire / logout will set active to no for login session - Logout via "/logout/" route will clear 2fa cookie only when you logout not switch back to admin account
1 parent f13dea2 commit 2972a28

File tree

5 files changed

+102
-4
lines changed

5 files changed

+102
-4
lines changed

bin/v-log-user-login

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# info: add user login
3+
# options: USER IP [FINGERPRINT]
4+
5+
# Argument definition
6+
user=$1
7+
ip=$2
8+
fingerprint=${3}
9+
10+
# Includes
11+
source $HESTIA/func/main.sh
12+
source $HESTIA/conf/hestia.conf
13+
14+
#----------------------------------------------------------#
15+
# Verifications #
16+
#----------------------------------------------------------#
17+
18+
check_args '2' "$#" 'USER IP [FINGERPRINT]'
19+
is_format_valid 'user' 'ip'
20+
is_object_valid 'user' 'USER' "$user"
21+
22+
browser=$(echo $browser | sed -e "s/\'//g");
23+
24+
# Generating timestamp
25+
time_n_date=$(date +'%T %F')
26+
time=$(echo "$time_n_date" |cut -f 1 -d \ )
27+
date=$(echo "$time_n_date" |cut -f 2 -d \ )
28+
29+
if [ ! -f $HESTIA/data/users/$user/auth.log ]; then
30+
touch $HESTIA/data/users/$user/auth.log
31+
fi
32+
33+
#----------------------------------------------------------#
34+
# Action #
35+
#----------------------------------------------------------#
36+
37+
awk -i inplace -v finger="FINGERPRINT='$fingerprint'" -v active="active='no'" '$2 == finger {$5=active}1' $HESTIA/data/users/$user/auth.log
38+
39+
echo "IP='$ip' FINGERPRINT='$fingerprint' DATE='$date' TIME='$time' active='yes'" >> $HESTIA/data/users/$user/auth.log
40+
41+
#----------------------------------------------------------#
42+
# Hestia #
43+
#----------------------------------------------------------#
44+
45+
exit

bin/v-log-user-logout

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# info: Log User logout event
3+
# options: USER FINGERPRINT
4+
5+
# Argument definition
6+
user=$1
7+
fingerprint=$2
8+
9+
# Includes
10+
source $HESTIA/func/main.sh
11+
source $HESTIA/conf/hestia.conf
12+
13+
#----------------------------------------------------------#
14+
# Verifications #
15+
#----------------------------------------------------------#
16+
17+
check_args '2' "$#" 'USER FINGERPRINT'
18+
is_format_valid 'user'
19+
is_object_valid 'user' 'USER' "$user"
20+
21+
if [ ! -f $HESTIA/data/users/$user/auth.log ]; then
22+
touch $HESTIA/data/users/$user/auth.log
23+
fi
24+
25+
#----------------------------------------------------------#
26+
# Action #
27+
#----------------------------------------------------------#
28+
29+
awk -i inplace -v finger="FINGERPRINT='$fingerprint'" -v active="active='no'" '$2 == finger {$5=active}1' $HESTIA/data/users/$user/auth.log
30+
31+
#----------------------------------------------------------#
32+
# Hestia #
33+
#----------------------------------------------------------#
34+
35+
exit

web/inc/main.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
// Checking user to use session from the same IP he has been logged in
4343
if($_SESSION['user_combined_ip'] != $user_combined_ip && $_SERVER['REMOTE_ADDR'] != '127.0.0.1'){
44+
$v_user = escapeshellarg($_SESSION['user']);
45+
$v_murmur = escapeshellarg($_SESSION['MURMUR']);
46+
exec(HESTIA_CMD."v-log-user-logout ".$v_user." ".$v_murmur, $output, $return_var);
4447
session_destroy();
4548
session_start();
4649
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
@@ -77,6 +80,9 @@
7780
session_destroy();
7881
header("Location: /login/");
7982
}else if ($_SESSION['INACTIVE_SESSION_TIMEOUT'] * 60 + $_SESSION['LAST_ACTIVITY'] < time()) {
83+
$v_user = escapeshellarg($_SESSION['user']);
84+
$v_murmur = escapeshellarg($_SESSION['MURMUR']);
85+
exec(HESTIA_CMD."v-log-user-logout ".$v_user." ".$v_murmur, $output, $return_var);
8086
session_destroy();
8187
header("Location: /login/");
8288
}else{

web/login/index.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,17 @@ function authenticate_user(){
117117
// Define session user
118118
$_SESSION['user'] = key($data);
119119
$v_user = $_SESSION['user'];
120-
120+
//log successfull login attempt
121+
$v_murmur = escapeshellarg($_POST['murmur']);
122+
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." ".$v_murmur, $output, $return_var);
123+
121124
//rename $_SESSION['TWOFA_VALID_LENGTH'] still to be done!
122125
if(empty($_COOKIE['limit2fa'] && $_SESSION['TWOFA_VALID_LENGTH'] == 1 && $data[$user]['TWOFA'] != "")){
123126
setcookie('limit2fa',password_hash($data[$user]['TWOFA'].$ip.$_POST['murmur'],PASSWORD_BCRYPT),time()+60*60*24,"/");
124127
};
125128
$_SESSION['LAST_ACTIVITY'] = time();
126-
129+
$_SESSION['MURMUR'] = $_POST['murmur'];
130+
127131
// Define language
128132
$output = '';
129133
exec (HESTIA_CMD."v-list-sys-languages json", $output, $return_var);

web/logout/index.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<?php
2-
32
session_start();
43

4+
define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
5+
56
if (!empty($_SESSION['look'])) {
67
unset($_SESSION['look']);
78
} else {
9+
if($_SESSION['MURMUR'] && $_SESSION['user']){
10+
$v_user = escapeshellarg($_SESSION['user']);
11+
$v_murmur = escapeshellarg($_SESSION['MURMUR']);
12+
exec(HESTIA_CMD."v-log-user-logout ".$v_user." ".$v_murmur, $output, $return_var);
13+
}
14+
815
session_destroy();
16+
setcookie('limit2fa','',time() - 3600,"/");
917
}
10-
setcookie('limit2fa','',time() - 3600,"/");
18+
1119
header("Location: /login/");
1220
exit;
1321
?>

0 commit comments

Comments
 (0)