Skip to content

Commit 5395a9d

Browse files
author
Kristan Kenney
committed
Log browser user agent
1 parent 222898e commit 5395a9d

File tree

6 files changed

+87
-69
lines changed

6 files changed

+87
-69
lines changed

bin/v-list-user-auth-log

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ json_list() {
2828
IP=$(echo "$str" |cut -f 6 -d \')
2929
ACTION=$(echo "$str" |cut -f 8 -d \')
3030
STATUS=$(echo "$str" |cut -f 10 -d \')
31-
SESSION=$(echo "$str" |cut -f 12 -d \')
32-
ACTIVE=$(echo "$str" |cut -f 14 -d \')
31+
USER_AGENT=$(echo "$str" |cut -f 12 -d \')
32+
SESSION=$(echo "$str" |cut -f 14 -d \')
33+
ACTIVE=$(echo "$str" |cut -f 16 -d \')
3334
echo -n ' "'$i'": {
3435
"DATE": "'$DATE'",
3536
"TIME": "'$TIME'",
3637
"IP": "'$IP'",
3738
"ACTION": "'$ACTION'",
3839
"STATUS": "'$STATUS'",
40+
"USER_AGENT": "'$USER_AGENT'",
3941
"SESSION": "'$SESSION'",
4042
"ACTIVE": "'$ACTIVE'"
4143
}'
@@ -59,9 +61,10 @@ shell_list() {
5961
IP=$(echo "$str" |cut -f 6 -d \')
6062
ACTION=$(echo "$str" |cut -f 8 -d \')
6163
STATUS=$(echo "$str" |cut -f 10 -d \')
62-
SESSION=$(echo "$str" |cut -f 12 -d \')
63-
ACTIVE=$(echo "$str" |cut -f 14 -d \')
64-
echo "$DATE~$TIME~$IP~$ACTION~$STATUS~$SESSION~$ACTIVE"
64+
USER_AGENT=$(echo "$str" |cut -f 12 -d \')
65+
SESSION=$(echo "$str" |cut -f 14 -d \')
66+
ACTIVE=$(echo "$str" |cut -f 16 -d \')
67+
echo "$DATE~$TIME~$IP~$ACTION~$STATUS~$USER_AGENT~$SESSION~$ACTIVE"
6568
done
6669
}
6770

@@ -74,25 +77,27 @@ plain_list() {
7477
IP=$(echo "$str" |cut -f 6 -d \')
7578
ACTION=$(echo "$str" |cut -f 8 -d \')
7679
STATUS=$(echo "$str" |cut -f 10 -d \')
77-
SESSION=$(echo "$str" |cut -f 12 -d \')
78-
ACTIVE=$(echo "$str" |cut -f 14 -d \')
79-
echo -e "$DATE\t$TIME\t$IP\t$ACTION\t$STATUS\t$SESSION\t$ACTIVE"
80+
USER_AGENT=$(echo "$str" |cut -f 12 -d \')
81+
SESSION=$(echo "$str" |cut -f 14 -d \')
82+
ACTIVE=$(echo "$str" |cut -f 16 -d \')
83+
echo -e "$DATE\t$TIME\t$IP\t$ACTION\t$STATUS\t$USER_AGENT\t$SESSION\t$ACTIVE"
8084
done
8185
}
8286

8387
# CSV list function
8488
csv_list() {
8589
IFS=$'\n'
86-
echo "DATE,TIME,IP,ACTION,STATUS,SESSION,ACTIVE"
90+
echo "DATE,TIME,IP,ACTION,STATUS,USER_AGENT,SESSION,ACTIVE"
8791
for str in $logs; do
8892
DATE=$(echo "$str" |cut -f 2 -d \')
8993
TIME=$(echo "$str" |cut -f 4 -d \')
9094
IP=$(echo "$str" |cut -f 6 -d \')
9195
ACTION=$(echo "$str" |cut -f 8 -d \')
9296
STATUS=$(echo "$str" |cut -f 10 -d \')
93-
SESSION=$(echo "$str" |cut -f 12 -d \')
94-
ACTIVE=$(echo "$str" |cut -f 14 -d \')
95-
echo "$DATE,$TIME,$IP,$SESSION,$ACTIVE,$STATUS"
97+
USER_AGENT=$(echo "$str" |cut -f 12 -d \')
98+
SESSION=$(echo "$str" |cut -f 14 -d \')
99+
ACTIVE=$(echo "$str" |cut -f 16 -d \')
100+
echo "$DATE,$TIME,$IP,$ACTION,$STATUS,$USER_AGENT,$SESSION,$ACTIVE"
96101

97102
done
98103
}

bin/v-log-user-login

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ user=$1
77
ip=$2
88
status=$3
99
session_id=$4
10+
user_agent=$5
1011

1112
active="yes"
12-
if [ $status = "failed" ]; then
13+
if [ "$status" = "failed" ]; then
1314
active="no"
1415
fi
1516

@@ -21,7 +22,7 @@ source $HESTIA/conf/hestia.conf
2122
# Verifications #
2223
#----------------------------------------------------------#
2324

24-
check_args '2' "$#" 'USER IP SESSION_ID'
25+
check_args '2' "$#" 'USER IP SESSION_ID USER_AGENT'
2526
is_format_valid 'user' 'ip'
2627
is_object_valid 'user' 'USER' "$user"
2728

@@ -38,7 +39,7 @@ fi
3839
# Action #
3940
#----------------------------------------------------------#
4041

41-
echo "DATE='$date' TIME='$time' IP='$ip' ACTION='login' STATUS='$status' SESSION='$session_id' ACTIVE='$active'" >> $USER_DATA/auth.log
42+
echo "DATE='$date' TIME='$time' IP='$ip' ACTION='login' STATUS='$status' USER_AGENT='$user_agent' SESSION='$session_id' ACTIVE='$active'" >> $USER_DATA/auth.log
4243

4344
#----------------------------------------------------------#
4445
# Hestia #

web/delete/log/auth/index.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// Clear log
1414
$v_username = escapeshellarg($user);
1515
exec (HESTIA_CMD."v-delete-user-auth-log ".$v_username, $output, $return_var);
16-
//check_return_code($return_var,$output);
17-
//unset($output);
16+
check_return_code($return_var,$output);
17+
unset($output);
1818

1919

2020
$ip = $_SERVER['REMOTE_ADDR'];
@@ -24,21 +24,17 @@
2424
}
2525
}
2626
$v_ip = escapeshellarg($ip);
27+
$user_agent = $_SERVER['HTTP_USER_AGENT'];
28+
$v_user_agent = escapeshellarg($user_agent);
2729

2830
$v_session_id = escapeshellarg($_SESSION['token']);
29-
exec(HESTIA_CMD."v-log-user-login ".$v_username." ".$v_ip." success ".$v_session_id, $output, $return_var);
30-
31-
// Render page
32-
//render_page($user, $TAB, 'list_auth');
31+
exec(HESTIA_CMD."v-log-user-login ".$v_username." ".$v_ip." success ".$v_session_id." ".$v_user_agent, $output, $return_var);
3332

3433
// Flush session messages
3534
unset($_SESSION['error_msg']);
3635
unset($_SESSION['ok_msg']);
3736

38-
if (($_SESSION['userContext'] === 'admin') && (isset($_SESSION['look']))) {
39-
header("Location: /list/log/auth/?user=".$_SESSION['look']);
40-
} else {
41-
header("Location: /list/log/auth/?user=".$_SESSION['user']);
42-
}
37+
// Return to authentication history
38+
header("Location: /list/log/auth/");
4339

4440
exit;

web/login/index.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,15 @@ function authenticate_user($user, $password, $twofa = ''){
9292
if(isset($_SESSION['token']) && isset($_POST['token']) && $_POST['token'] == $_SESSION['token']) {
9393
$v_user = escapeshellarg($user);
9494
$ip = $_SERVER['REMOTE_ADDR'];
95+
$user_agent = $_SERVER['HTTP_USER_AGENT'];
9596
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
9697
if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
9798
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
9899
}
99100
}
100101
$v_ip = escapeshellarg($ip);
102+
$v_user_agent = escapeshellarg($user_agent);
103+
101104
// Get user's salt
102105
$output = '';
103106
exec (HESTIA_CMD."v-get-user-salt ".$v_user." ".$v_ip." json" , $output, $return_var);
@@ -138,7 +141,7 @@ function authenticate_user($user, $password, $twofa = ''){
138141
sleep(2);
139142
$error = "<a class=\"error\">"._('Invalid username or password')."</a>";
140143
$v_session_id = escapeshellarg($_POST['token']);
141-
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." failed ".$v_session_id, $output, $return_var);
144+
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." failed ".$v_session_id." ".$v_user_agent, $output, $return_var);
142145

143146
return $error;
144147
} else {
@@ -162,7 +165,7 @@ function authenticate_user($user, $password, $twofa = ''){
162165
$_SESSION['login']['username'] = $user;
163166
$_SESSION['login']['password'] = $password;
164167
$v_session_id = escapeshellarg($_POST['token']);
165-
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." failed ".$v_session_id, $output, $return_var);
168+
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." failed ".$v_session_id." ".$v_user_agent, $output, $return_var);
166169
return $error;
167170
unset($_POST['twofa']);
168171
}
@@ -176,7 +179,7 @@ function authenticate_user($user, $password, $twofa = ''){
176179
$v_user = $_SESSION['user'];
177180
//log successfull login attempt
178181
$v_session_id = escapeshellarg($_POST['token']);
179-
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." success ".$v_session_id, $output, $return_var);
182+
exec(HESTIA_CMD."v-log-user-login ".$v_user." ".$v_ip." success ".$v_session_id." ".$v_user_agent, $output, $return_var);
180183

181184
$_SESSION['LAST_ACTIVITY'] = time();
182185
$_SESSION['MURMUR'] = $_POST['murmur'];

web/templates/admin/list_log_auth.html

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,16 @@
2323
<div class="l-center units">
2424
<div class="header table-header">
2525
<div class="l-unit__col l-unit__col--right">
26-
<div class="clearfix l-unit__stat-col--left super-compact">
27-
&nbsp;
26+
<div class="clearfix l-unit__stat-col--left compact text-center">
27+
<b><?php print _('Active');?></b>
2828
</div>
29-
<div class="clearfix l-unit__stat-col--left super-compact">
30-
&nbsp;
29+
<div class="clearfix l-unit__stat-col--left small text-center">
30+
<b><?php print _('Status');?></b>
3131
</div>
32-
<div class="clearfix l-unit__stat-col--left super-compact">
33-
&nbsp;
34-
</div>
35-
<div class="clearfix l-unit__stat-col--left small"><b><?php print _('Date');?></b></div>
36-
<div class="clearfix l-unit__stat-col--left"><b><?php print _('Time');?></b></div>
32+
<div class="clearfix l-unit__stat-col--left"><b><?php print _('Date');?></b></div>
33+
<div class="clearfix l-unit__stat-col--left compact"><b><?php print _('Time');?></b></div>
3734
<div class="clearfix l-unit__stat-col--left"><b><?php print _('IP address');?></b></div>
35+
<div class="clearfix l-unit__stat-col--left wide-6"><b><?php print _('Browser');?></b></div>
3836
</div>
3937
</div>
4038
<?php
@@ -43,34 +41,26 @@
4341
?>
4442
<div class="l-unit header animated fadeIn">
4543
<div class="l-unit__col l-unit__col--right">
46-
<div class="clearfix l-unit__stat-col--left super-compact">
44+
<div class="clearfix l-unit__stat-col--left compact text-center">
4745
<? if ($data[$key]['ACTION'] == 'login') { ?>
48-
<i class="fas fa-sign-in-alt status-icon dim icon-pad-right" title="<?=_('Login')?>"></i>
46+
<? if ($data[$key]['ACTIVE'] === 'yes') {?>
47+
<i class="fas fa-sign-in-alt status-icon maroon icon-pad-right" title="<?=_('Login')?>"></i>
48+
<? } else {?>
49+
<i class="fas fa-sign-in-alt status-icon dim icon-pad-right" title="<?=_('Login')?>"></i>
50+
<? } ?>
4951
<? } ?>
5052
</div>
51-
<div class="clearfix l-unit__stat-col--left super-compact">
53+
<div class="clearfix l-unit__stat-col--left small text-center">
5254
<? if ($data[$key]['STATUS'] == 'success') { ?>
5355
<i class="fas fa-check-circle status-icon green icon-pad-right" title="<?=_('Success')?>"></i>
5456
<? } else {?>
5557
<i class="fas fa-minus-circle status-icon red icon-pad-right" title="<?=_('Failed')?>"></i>
5658
<? } ?>
5759
</div>
58-
<div class="clearfix l-unit__stat-col--left super-compact">
59-
<? if ($data[$key]['STATUS'] === 'failed') {?>
60-
<!-- Do not display session status as login was never active-->
61-
&nbsp;
62-
<? } else {?>
63-
<? if ($data[$key]['ACTIVE'] === 'yes') {?>
64-
<i class="fas fa-user-circle status-icon dim icon-pad-right" title="<?=_('Active Session')?>"></i>
65-
<? } else {?>
66-
<!-- Do not display indicator for non-active sessions -- note: whitespace char required to pad cell at this time -->
67-
&nbsp;
68-
<? } ?>
69-
<? } ?>
70-
</div>
71-
<div class="clearfix l-unit__stat-col--left small"><b><?=translate_date($data[$key]['DATE'])?></b></div>
72-
<div class="clearfix l-unit__stat-col--left"><b><?=$data[$key]['TIME']?></b></div>
60+
<div class="clearfix l-unit__stat-col--left"><b><?=translate_date($data[$key]['DATE'])?></b></div>
61+
<div class="clearfix l-unit__stat-col--left compact"><b><?=$data[$key]['TIME']?></b></div>
7362
<div class="clearfix l-unit__stat-col--left"><?=$data[$key]['IP']?></div>
63+
<div class="clearfix l-unit__stat-col--left wide-6"><?=$data[$key]['USER_AGENT']?></b></div>
7464
</div>
7565
</div>
7666
<?}?>

web/templates/user/list_log_auth.html

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,66 @@
44
<a href="/list/log/" id="btn-back" class="ui-button cancel" dir="ltr"><i class="fas fa-arrow-left status-icon blue"></i><?=_('Back')?></a>
55
</div>
66
<div class="l-unit-toolbar__buttonstrip float-right">
7-
<a href="javascript:location.reload();" class="ui-button cancel" dir="ltr"><i class="fas fa-redo status-icon green"></i> <?=_('Refresh')?></a>
7+
<a href="javascript:location.reload();" class="ui-button cancel" dir="ltr"><i class="fas fa-redo status-icon green"></i><?=_('Refresh')?></a>
88
</div>
99
</div>
1010
</div>
11+
1112
<div class="l-separator"></div>
1213

13-
<div class="l-center units animated fadeIn">
14+
<div class="l-center units">
1415
<div class="header table-header">
1516
<div class="l-unit__col l-unit__col--right">
1617
<div class="clearfix l-unit__stat-col--left super-compact">
1718
&nbsp;
18-
</div>
19+
</div>
20+
<div class="clearfix l-unit__stat-col--left super-compact">
21+
&nbsp;
22+
</div>
23+
<div class="clearfix l-unit__stat-col--left super-compact">
24+
&nbsp;
25+
</div>
1926
<div class="clearfix l-unit__stat-col--left small"><b><?php print _('Date');?></b></div>
2027
<div class="clearfix l-unit__stat-col--left"><b><?php print _('Time');?></b></div>
2128
<div class="clearfix l-unit__stat-col--left"><b><?php print _('IP address');?></b></div>
22-
<div class="clearfix l-unit__stat-col--left"><b><?php print _('Status');?></b></div>
23-
<div class="clearfix l-unit__stat-col--left"><b><?php print _('Active');?></b></div>
24-
<div class="clearfix l-unit__stat-col--left wide-4"><b><?php print _('Browser Fingerprint');?></b></div>
29+
<div class="clearfix l-unit__stat-col--left wide-6"><b><?php print _('Browser');?></b></div>
2530
</div>
2631
</div>
2732
<?php
2833
foreach ($data as $key => $value) {
2934
++$i;
3035
?>
31-
<div class="l-unit header">
36+
<div class="l-unit header animated fadeIn">
3237
<div class="l-unit__col l-unit__col--right">
3338
<div class="clearfix l-unit__stat-col--left super-compact">
34-
<i class="fas fa-info-circle status-icon dim"></i>
39+
<? if ($data[$key]['ACTION'] == 'login') { ?>
40+
<i class="fas fa-sign-in-alt status-icon dim icon-pad-right" title="<?=_('Login')?>"></i>
41+
<? } ?>
42+
</div>
43+
<div class="clearfix l-unit__stat-col--left super-compact">
44+
<? if ($data[$key]['STATUS'] == 'success') { ?>
45+
<i class="fas fa-check-circle status-icon green icon-pad-right" title="<?=_('Success')?>"></i>
46+
<? } else {?>
47+
<i class="fas fa-minus-circle status-icon red icon-pad-right" title="<?=_('Failed')?>"></i>
48+
<? } ?>
49+
</div>
50+
<div class="clearfix l-unit__stat-col--left super-compact">
51+
<? if ($data[$key]['STATUS'] === 'failed') {?>
52+
<!-- Do not display session status as login was never active-->
53+
&nbsp;
54+
<? } else {?>
55+
<? if ($data[$key]['ACTIVE'] === 'yes') {?>
56+
<i class="fas fa-user-circle status-icon dim icon-pad-right" title="<?=_('Active Session')?>"></i>
57+
<? } else {?>
58+
<!-- Do not display indicator for non-active sessions -- note: whitespace char required to pad cell at this time -->
59+
&nbsp;
60+
<? } ?>
61+
<? } ?>
3562
</div>
3663
<div class="clearfix l-unit__stat-col--left small"><b><?=translate_date($data[$key]['DATE'])?></b></div>
3764
<div class="clearfix l-unit__stat-col--left"><b><?=$data[$key]['TIME']?></b></div>
3865
<div class="clearfix l-unit__stat-col--left"><?=$data[$key]['IP']?></div>
39-
<div class="clearfix l-unit__stat-col--left"><?=$data[$key]['STATUS']?></div>
40-
<div class="clearfix l-unit__stat-col--left"><?=$data[$key]['ACTIVE']?></div>
41-
<div class="clearfix l-unit__stat-col--left"><?=$data[$key]['FINGERPRINT']?></div>
42-
43-
66+
<div class="clearfix l-unit__stat-col--left wide-6"><?=$data[$key]['USER_AGENT']?></b></div>
4467
</div>
4568
</div>
4669
<?}?>

0 commit comments

Comments
 (0)