Skip to content

Commit 7864d2f

Browse files
committed
Web UI for login history
1 parent c67eb07 commit 7864d2f

File tree

9 files changed

+315
-9
lines changed

9 files changed

+315
-9
lines changed

bin/v-delete-user-auth-log

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# info: Delete auth log file for user
3+
#
4+
# The function for deleting a users auth log file
5+
6+
# Argument definition
7+
user=$1
8+
date=$(date "+%F %T")
9+
10+
# Includes
11+
source $HESTIA/func/main.sh
12+
source $HESTIA/conf/hestia.conf
13+
14+
# Perform verification if read-only mode is enabled
15+
check_hestia_demo_mode
16+
17+
#----------------------------------------------------------#
18+
# Verifications #
19+
#----------------------------------------------------------#
20+
21+
check_args '1' "$#" 'USER'
22+
is_format_valid 'user'
23+
is_object_valid 'user' 'USER' "$user"
24+
25+
if [ ! -f $USER_DATA/auth.log ]; then
26+
touch $USER_DATA/auth.log
27+
fi
28+
29+
#----------------------------------------------------------#
30+
# Action #
31+
#----------------------------------------------------------#
32+
33+
rm $USER_DATA/auth.log
34+
35+
log_history "Authentication log for $user was cleared on $date."
36+
log_event "$OK" "$ARGUMENTS"
37+
38+
exit

bin/v-list-sys-config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ json_list() {
5555
"DB_PGA_ALIAS": "'$DB_PGA_ALIAS'",
5656
"SOFTACULOUS": "'$SOFTACULOUS'",
5757
"INACTIVE_SESSION_TIMEOUT": "'$INACTIVE_SESSION_TIMEOUT'",
58-
"TWOFA_VALID_LENGTH": "'$TWOFA_VALID_LENGTH'",
58+
"TWOFA_VALID_LENGTH": "'$TWOFA_VALID_LENGTH'"
5959
}
6060
}'
6161
}

bin/v-list-user-auth-log

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/bin/bash
2+
# info: list user log
3+
# options: USER [FORMAT]
4+
#
5+
# The function of obtaining the list of 10 last users commands.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
format=${2-shell}
15+
16+
# Includes
17+
source $HESTIA/func/main.sh
18+
19+
# JSON list function
20+
json_list() {
21+
IFS=$'\n'
22+
i=1
23+
objects=$(echo "$logs" |wc -l)
24+
echo "{"
25+
for str in $logs; do
26+
IP=$(echo "$str" |cut -f 2 -d \')
27+
FINGERPRINT=$(echo "$str" |cut -f 4 -d \')
28+
DATE=$(echo "$str" |cut -f 6 -d \')
29+
TIME=$(echo "$str" |cut -f 8 -d \')
30+
ACTIVE=$(echo "$str" |cut -f 10 -d \')
31+
CMD=${CMD//\"/\\\"}
32+
echo -n ' {
33+
"DATE": "'$DATE'",
34+
"TIME": "'$TIME'",
35+
"IP": "'$IP'",
36+
"FINGERPRINT": "'$FINGERPRINT'",
37+
"ACTIVE": "'$ACTIVE'",
38+
39+
}'
40+
if [ "$i" -lt "$objects" ]; then
41+
echo ','
42+
else
43+
echo
44+
fi
45+
((i++))
46+
done
47+
echo '}'
48+
}
49+
50+
shell_list() {
51+
IFS=$'\n'
52+
echo "DATE~TIME~IP~FINGERPRINT~ACTIVE"
53+
echo "----~----~--~-----------~------"
54+
for str in $logs; do
55+
IP=$(echo "$str" |cut -f 2 -d \')
56+
FINGERPRINT=$(echo "$str" |cut -f 4 -d \')
57+
DATE=$(echo "$str" |cut -f 6 -d \')
58+
TIME=$(echo "$str" |cut -f 8 -d \')
59+
ACTIVE=$(echo "$str" |cut -f 10 -d \')
60+
echo "$DATE~$TIME~$IP~$FINGERPRINT~$ACTIVE"
61+
done
62+
}
63+
64+
# PLAIN list function
65+
plain_list() {
66+
IFS=$'\n'
67+
for str in $logs; do
68+
IP=$(echo "$str" |cut -f 2 -d \')
69+
FINGERPRINT=$(echo "$str" |cut -f 4 -d \')
70+
DATE=$(echo "$str" |cut -f 6 -d \')
71+
TIME=$(echo "$str" |cut -f 8 -d \')
72+
ACTIVE=$(echo "$str" |cut -f 10 -d \')
73+
echo -e "$DATE\t$TIME\t$IP\t$FINGERPRINT\t$ACTIVE"
74+
done
75+
}
76+
77+
# CSV list function
78+
csv_list() {
79+
IFS=$'\n'
80+
echo "ID,CMD,UNDO,TIME,DATE"
81+
for str in $logs; do
82+
IP=$(echo "$str" |cut -f 2 -d \')
83+
FINGERPRINT=$(echo "$str" |cut -f 4 -d \')
84+
DATE=$(echo "$str" |cut -f 6 -d \')
85+
TIME=$(echo "$str" |cut -f 8 -d \')
86+
ACTIVE=$(echo "$str" |cut -f 10 -d \')
87+
echo "$DATE,$TIME,$IP,$FINGERPRINT,$ACTIVE"
88+
89+
done
90+
}
91+
92+
#----------------------------------------------------------#
93+
# Verifications #
94+
#----------------------------------------------------------#
95+
96+
check_args '1' "$#" 'USER [FORMAT]'
97+
is_format_valid 'user'
98+
is_object_valid 'user' 'USER' "$user"
99+
100+
101+
#----------------------------------------------------------#
102+
# Action #
103+
#----------------------------------------------------------#
104+
105+
# Parsing history log
106+
logs=$(tail -n 10 $USER_DATA/auth.log 2>/dev/null)
107+
108+
case $format in
109+
json) json_list ;;
110+
plain) plain_list ;;
111+
csv) csv_list ;;
112+
shell) shell_list |column -t -s '~';;
113+
esac
114+
115+
116+
#----------------------------------------------------------#
117+
# Hestia #
118+
#----------------------------------------------------------#
119+
120+
exit

bin/v-log-user-login

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ time_n_date=$(date +'%T %F')
2626
time=$(echo "$time_n_date" |cut -f 1 -d \ )
2727
date=$(echo "$time_n_date" |cut -f 2 -d \ )
2828

29-
if [ ! -f $HESTIA/data/users/$user/auth.log ]; then
30-
touch $HESTIA/data/users/$user/auth.log
29+
if [ ! -f $USER_DATA/auth.log ]; then
30+
touch $USER_DATA/auth.log
3131
fi
3232

3333
#----------------------------------------------------------#
3434
# Action #
3535
#----------------------------------------------------------#
3636

37-
awk -i inplace -v finger="FINGERPRINT='$fingerprint'" -v active="active='no'" '$2 == finger {$5=active}1' $HESTIA/data/users/$user/auth.log
37+
awk -i inplace -v finger="FINGERPRINT='$fingerprint'" -v active="active='no'" '$2 == finger {$5=active}1' $USER_DATA/auth.log
3838

39-
echo "IP='$ip' FINGERPRINT='$fingerprint' DATE='$date' TIME='$time' active='yes'" >> $HESTIA/data/users/$user/auth.log
39+
echo "IP='$ip' FINGERPRINT='$fingerprint' DATE='$date' TIME='$time' active='yes'" >> $USER_DATA/auth.log
4040

4141
#----------------------------------------------------------#
4242
# Hestia #

bin/v-log-user-logout

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ check_args '2' "$#" 'USER FINGERPRINT'
1818
is_format_valid 'user'
1919
is_object_valid 'user' 'USER' "$user"
2020

21-
if [ ! -f $HESTIA/data/users/$user/auth.log ]; then
22-
touch $HESTIA/data/users/$user/auth.log
21+
if [ ! -f $USER_DATA/auth.log ]; then
22+
touch $USER_DATA/auth.log
2323
fi
2424

2525
#----------------------------------------------------------#
2626
# Action #
2727
#----------------------------------------------------------#
2828

29-
awk -i inplace -v finger="FINGERPRINT='$fingerprint'" -v active="active='no'" '$2 == finger {$5=active}1' $HESTIA/data/users/$user/auth.log
29+
awk -i inplace -v finger="FINGERPRINT='$fingerprint'" -v active="active='no'" '$2 == finger {$5=active}1' $USER_DATA/auth.log
3030

3131
#----------------------------------------------------------#
3232
# Hestia #

web/delete/user/log/index.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// Init
3+
error_reporting(NULL);
4+
session_start();
5+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
6+
7+
// Check token
8+
if ((!isset($_GET['token'])) || ($_SESSION['token'] != $_GET['token'])) {
9+
header('location: /login/');
10+
exit();
11+
}
12+
13+
// Clear log
14+
$v_username = escapeshellarg($user);
15+
exec (HESTIA_CMD."v-delete-user-auth-log ".$v_username, $output, $return_var);
16+
//check_return_code($return_var,$output);
17+
//unset($output);
18+
19+
20+
$ip = $_SERVER['REMOTE_ADDR'];
21+
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
22+
if(!empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
23+
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
24+
}
25+
}
26+
$v_ip = escapeshellarg($ip);
27+
28+
$v_murmur = escapeshellarg($_SESSION['MURMUR']);
29+
exec(HESTIA_CMD."v-log-user-login ".$v_username." ".$v_ip." ".$v_murmur, $output, $return_var);
30+
31+
// Render page
32+
//render_page($user, $TAB, 'list_auth');
33+
34+
// Flush session messages
35+
unset($_SESSION['error_msg']);
36+
unset($_SESSION['ok_msg']);
37+
38+
header("Location: /edit/user/log/?user=".$_SESSION['user']);
39+
40+
exit;

web/edit/user/log/index.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
error_reporting(NULL);
3+
ob_start();
4+
$TAB = 'USER';
5+
6+
// Main include
7+
include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
8+
9+
10+
// Check user argument
11+
if (empty($_GET['user'])) {
12+
header("Location: /list/user/");
13+
exit;
14+
}
15+
16+
// Edit as someone else?
17+
if (($_SESSION['user'] == 'admin') && (!empty($_GET['user']))) {
18+
$user=$_GET['user'];
19+
$v_username=$_GET['user'];
20+
} else {
21+
$user=$_SESSION['user'];
22+
$v_username=$_SESSION['user'];
23+
}
24+
exec(HESTIA_CMD."v-list-user-auth-log ".escapeshellarg($v_username)." json", $output, $return_var);
25+
check_return_code($return_var,$output);
26+
$data = json_decode(implode('', $output), true);
27+
array_reverse($data);
28+
unset($output);
29+
30+
// Render page
31+
render_page($user, $TAB, 'list_auth');
32+
33+
// Flush session messages
34+
unset($_SESSION['error_msg']);
35+
unset($_SESSION['ok_msg']);

web/templates/admin/edit_user.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="l-sort clearfix">
33
<div class="l-unit-toolbar__buttonstrip">
44
<a class="ui-button cancel" id="btn-back" href="/list/user/"><i class="fas fa-arrow-left status-icon blue"></i> <?=__('Back')?></a>
5-
<a href="/list/key/" id="btn-create" class="ui-button cancel" title="<?=__('Manage SSH keys');?>"><i class="fas fa-key status-icon orange"></i><?=__('Manage SSH keys')?></a>
5+
<a href="/list/key/" id="btn-create" class="ui-button cancel" title="<?=__('Manage SSH keys');?>"><i class="fas fa-key status-icon orange"></i><?=__('Manage SSH keys')?></a> <a href="/edit/user/log/?user=<?php echo $_SESSION['user'];?>" id="btn-list" class="ui-button cancel" title="<?=__('Login history');?>"><i class="fas fa-key status-icon orange"></i><?=__('Login history')?></a>
66
</div>
77
<div class="l-unit-toolbar__buttonstrip float-right">
88
<a href="#" class="ui-button" title="<?=__('Save')?>" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=__('Save')?></a>

web/templates/admin/list_auth.html

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<div class="l-center">
2+
<div class="l-sort clearfix noselect">
3+
<div class="l-unit-toolbar__buttonstrip">
4+
<a href="javascript:location.reload();" class="ui-button cancel" title="<?=__('Refresh')?>"><i class="fas fa-redo status-icon green"></i> <?=__('Refresh')?></a>
5+
<div class="actions-panel display-inline-block" key-action="js">
6+
<a class="data-controls do_delete ui-button danger cancel" title="<?=__('Delete')?>">
7+
<i class="do_delete fas fa-times-circle status-icon red"></i>
8+
<?=__('Delete')?>
9+
<input type="hidden" name="delete_url" value="/delete/user/log/?token=<?=$_SESSION['token']?>" />
10+
<div class="confirmation-text-delete hidden" title="<?=__('Confirmation')?>">
11+
<p class="confirmation"><?=__('Delete authentication logs?')?></p>
12+
</div>
13+
</a>
14+
</div>
15+
</div>
16+
<div class="l-sort-toolbar clearfix">
17+
</div>
18+
</div>
19+
</div>
20+
21+
<div class="l-separator"></div>
22+
23+
<div class="l-center units animated fadeIn">
24+
25+
<div class="header table-header">
26+
<div class="l-unit__col l-unit__col--right">
27+
<div class="clearfix l-unit__stat-col--left super-compact">
28+
&nbsp;
29+
</div>
30+
<div class="clearfix l-unit__stat-col--left"><b><?php print __('Date');?></b></div>
31+
<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 __('Ip adress');?></b></div>
33+
<div class="clearfix l-unit__stat-col--left "><b><?php print __('Active');?></b></div>
34+
<div class="clearfix l-unit__stat-col--left "><b><?php print __('Browser Fingerprint');?></b></div>
35+
</div>
36+
</div>
37+
38+
<?php
39+
foreach ($data as $key => $value) {
40+
++$i;
41+
?>
42+
<div class="l-unit header">
43+
<div class="l-unit__col l-unit__col--right">
44+
<div class="clearfix l-unit__stat-col--left super-compact">
45+
<i class="fas fa-info-circle status-icon dim"></i>
46+
</div>
47+
<div class="clearfix l-unit__stat-col--left "><b><?=translate_date($data[$key]['DATE'])?></b></div>
48+
<div class="clearfix l-unit__stat-col--left "><b><?=$data[$key]['TIME']?></b></div>
49+
<div class="clearfix l-unit__stat-col--left "><?=$data[$key]['IP']?></div>
50+
<div class="clearfix l-unit__stat-col--left small"><?=$data[$key]['ACTIVE']?></div>
51+
<div class="clearfix l-unit__stat-col--left "><?=$data[$key]['FINGERPRINT']?></div>
52+
</div>
53+
</div>
54+
<?}?>
55+
</div>
56+
57+
<div id="vstobjects">
58+
<div class="l-separator"></div>
59+
<div class="l-center">
60+
<div class="l-unit-ft">
61+
<table class='data'></table>
62+
<div class="data-count l-unit__col l-unit__col--right clearfix">
63+
<?
64+
if ( $i == 1) {
65+
echo __('1 log record');
66+
} else {
67+
echo __('%s log records',$i);
68+
}
69+
?>
70+
</div>
71+
</div>
72+
</div>
73+
</div>

0 commit comments

Comments
 (0)