Skip to content

Commit ed8ea87

Browse files
author
Kristan Kenney
committed
Separate logging context for system entries from 'admin' account
1 parent e3ae954 commit ed8ea87

File tree

6 files changed

+47
-28
lines changed

6 files changed

+47
-28
lines changed

bin/v-delete-user-log

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,31 @@ check_hestia_demo_mode
2929

3030
check_args '1' "$#" 'USER'
3131
is_format_valid 'user'
32-
is_object_valid 'user' 'USER' "$user"
32+
if [ "$user" != "system" ]; then
33+
is_object_valid 'user' 'USER' "$user"
34+
fi
3335

3436
#----------------------------------------------------------#
3537
# Action #
3638
#----------------------------------------------------------#
3739

38-
# Remove log file and log event
39-
if [ -f "$HESTIA/data/users/$user/history.log" ]; then
40-
rm -f $HESTIA/data/users/$user/history.log
41-
$BIN/v-log-action "system" "Warning" "Security" "User history log deleted (User: $user)."
42-
$BIN/v-log-action "$user" "Info" "Security" "User history log deleted."
40+
# Set correct path for log file (system or user)
41+
if [ "$user" = "system" ]; then
42+
log_file="$HESTIA/data/users/admin/system.log"
43+
else
44+
log_file="$HESTIA/data/users/$user/history.log"
45+
fi
46+
47+
# Verify log file exists before deleting to prevent errors
48+
if [ -f "$log_file" ]; then
49+
rm -f "$log_file"
50+
# Add event to user and system logs specifying that the log history was cleared
51+
if [ "$user" = "system" ]; then
52+
$BIN/v-log-action "system" "Info" "Security" "System log history deleted."
53+
else
54+
$BIN/v-log-action "system" "Warning" "Security" "User action log deleted (User: $user)."
55+
$BIN/v-log-action "$user" "Info" "Security" "Log entries deleted."
56+
fi
4357
log_event "$OK" "$ARGUMENTS"
4458
fi
4559

bin/v-list-user-log

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,21 @@ csv_list() {
101101

102102
check_args '1' "$#" 'USER [FORMAT]'
103103
is_format_valid 'user'
104-
is_object_valid 'user' 'USER' "$user"
105-
104+
if [ "$user" != "system" ]; then
105+
is_object_valid 'user' 'USER' "$user"
106+
fi
106107

107108
#----------------------------------------------------------#
108109
# Action #
109110
#----------------------------------------------------------#
110111

111112
# Parsing history log
112-
logs=$(tail -n 300 $USER_DATA/history.log 2>/dev/null)
113+
if [ "$user" = "system" ]; then
114+
log_file="$HESTIA/data/users/admin/system.log"
115+
else
116+
log_file="$USER_DATA/history.log"
117+
fi
118+
logs=$(tail -n 300 $log_file 2>/dev/null)
113119

114120
case $format in
115121
json) json_list ;;

bin/v-log-action

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,12 @@ fi
4141
#----------------------------------------------------------#
4242

4343
if [ "$user" = "system" ] || [ "$user" = "System" ]; then
44-
user="admin"
44+
user="system"
4545
fi
4646

4747
check_args '4' "$#" 'USER TYPE CATEGORY DETAILS'
48-
is_object_valid 'user' 'USER' "$user"
49-
50-
# Future hooks for login/logout events, currently housed in v-log-user-login and v-log-user-logout
51-
if [ "$event_category" = "login" ] || [ "$event_category" = "Login" ]; then
52-
echo "login hook used"
53-
fi
54-
55-
if [ "$event_category" = "logout" ] || [ "$event_category" = "Logout" ]; then
56-
echo "logout hook used"
48+
if [ "$user" != "system" ]; then
49+
is_object_valid 'user' 'USER' "$user"
5750
fi
5851

5952
log_history "$event_details" '' "$user"

func/main.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ log_history() {
106106
event_category="System"
107107
fi
108108

109-
if ! $BIN/v-list-user "$log_user" >/dev/null; then
110-
return $E_NOTEXIST
109+
# Log system events to system log file
110+
if [ "$log_user" = "system" ]; then
111+
log=$HESTIA/data/users/admin/system.log
112+
else
113+
if ! $BIN/v-list-user "$log_user" >/dev/null; then
114+
return $E_NOTEXIST
115+
fi
116+
log=$HESTIA/data/users/$log_user/history.log
111117
fi
112-
113-
log=$HESTIA/data/users/$log_user/history.log
114118
touch $log
115119

116120
# TODO: Improve log pruning and pagination

web/templates/admin/list_log.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="l-unit-toolbar__buttonstrip">
44
<? if (($_SESSION['userContext'] === 'admin') && ($_SESSION['look'] === 'admin')) {?>
55
<a href="/list/user/" id="btn-back" class="ui-button cancel" dir="ltr"><i class="fas fa-arrow-left status-icon blue"></i><?=_('Back')?></a>
6-
<? } else if (($_SESSION['userContext'] === 'admin') && ($_GET['user'] === 'admin')) { ?>
6+
<? } else if (($_SESSION['userContext'] === 'admin') && ($_GET['user'] === 'system')) { ?>
77
<a href="/list/server/" id="btn-back" class="ui-button cancel" dir="ltr"><i class="fas fa-arrow-left status-icon blue"></i><?=_('Back')?></a>
88
<? } else {?>
99
<? if (($_SESSION['userContext'] === 'admin') && (isset($_GET['user'])) && ($_GET['user'] !== 'admin')) { ?>
@@ -14,10 +14,12 @@
1414
<? } ?>
1515
<? if (($_SESSION['userContext'] === 'admin') && ($_GET['user'] !== 'admin')) { ?>
1616
<? if (($_SESSION['userContext'] === 'admin') && (isset($_GET['user'])) && ($_GET['user'] !== 'admin')) { ?>
17-
<a href="/list/log/auth/?user=<?php echo $_GET['user']; ?>&token=<?=$_SESSION['token']?>" id="btn-back" class="ui-button cancel" dir="ltr" title="<?=_('Login history');?>"><i class="fas fa-binoculars status-icon green"></i><?=_('Login history')?></a>
18-
<? } else { ?>
19-
<a href="/list/log/auth/" id="btn-back" class="ui-button cancel" dir="ltr" title="<?=_('Login history');?>"><i class="fas fa-binoculars status-icon green"></i><?=_('Login history')?></a>
17+
<? if ($_GET['user'] !== 'system') {?>
18+
<a href="/list/log/auth/?user=<?php echo $_GET['user']; ?>&token=<?=$_SESSION['token']?>" id="btn-back" class="ui-button cancel" dir="ltr" title="<?=_('Login history');?>"><i class="fas fa-binoculars status-icon green"></i><?=_('Login history')?></a>
2019
<? } ?>
20+
<? } else { ?>
21+
<a href="/list/log/auth/" id="btn-back" class="ui-button cancel" dir="ltr" title="<?=_('Login history');?>"><i class="fas fa-binoculars status-icon green"></i><?=_('Login history')?></a>
22+
<? } ?>
2123
<? } ?>
2224
</div>
2325
<div class="l-unit-toolbar__buttonstrip float-right">

web/templates/admin/list_services.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- Disable Updates Button
88
<a href="/list/updates/" class="ui-button cancel" dir="ltr"><i class="fas fa-sync status-icon green"></i><?=_('Updates')?></a>
99
-->
10-
<a href="/list/log/?user=admin&token=<?=$_SESSION['token']?>" class="ui-button cancel" dir="ltr"><i class="fas fa-binoculars status-icon lightblue"></i><?=_('Logs')?></a>
10+
<a href="/list/log/?user=system&token=<?=$_SESSION['token']?>" class="ui-button cancel" dir="ltr"><i class="fas fa-binoculars status-icon lightblue"></i><?=_('Logs')?></a>
1111
<div class="actions-panel display-inline-block" key-action="js">
1212
<a class="data-controls do_servicerestart ui-button danger cancel">
1313
<i class="do_servicerestart fas fa-undo status-icon red"></i><?=_('Restart')?>

0 commit comments

Comments
 (0)