Просмотр исходного кода

Separate logging context for system entries from 'admin' account

Kristan Kenney 5 лет назад
Родитель
Сommit
ed8ea87d98

+ 20 - 6
bin/v-delete-user-log

@@ -29,17 +29,31 @@ check_hestia_demo_mode
 
 check_args '1' "$#" 'USER'
 is_format_valid 'user'
-is_object_valid 'user' 'USER' "$user"
+if [ "$user" != "system" ]; then
+    is_object_valid 'user' 'USER' "$user"
+fi
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Remove log file and log event
-if [ -f "$HESTIA/data/users/$user/history.log" ]; then
-    rm -f $HESTIA/data/users/$user/history.log
-    $BIN/v-log-action "system" "Warning" "Security" "User history log deleted (User: $user)."
-    $BIN/v-log-action "$user" "Info" "Security" "User history log deleted."
+# Set correct path for log file (system or user)
+if [ "$user" = "system" ]; then
+    log_file="$HESTIA/data/users/admin/system.log"
+else
+    log_file="$HESTIA/data/users/$user/history.log"
+fi
+
+# Verify log file exists before deleting to prevent errors
+if [ -f "$log_file" ]; then
+    rm -f "$log_file"
+    # Add event to user and system logs specifying that the log history was cleared
+    if [ "$user" = "system" ]; then
+        $BIN/v-log-action "system" "Info" "Security" "System log history deleted."
+    else
+        $BIN/v-log-action "system" "Warning" "Security" "User action log deleted (User: $user)."
+        $BIN/v-log-action "$user" "Info" "Security" "Log entries deleted."
+    fi
     log_event "$OK" "$ARGUMENTS"
 fi
 

+ 9 - 3
bin/v-list-user-log

@@ -101,15 +101,21 @@ csv_list() {
 
 check_args '1' "$#" 'USER [FORMAT]'
 is_format_valid 'user'
-is_object_valid 'user' 'USER' "$user"
-
+if [ "$user" != "system" ]; then
+    is_object_valid 'user' 'USER' "$user"
+fi
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
 # Parsing history log
-logs=$(tail -n 300 $USER_DATA/history.log 2>/dev/null)
+if [ "$user" = "system" ]; then
+    log_file="$HESTIA/data/users/admin/system.log"
+else
+    log_file="$USER_DATA/history.log"
+fi
+logs=$(tail -n 300 $log_file 2>/dev/null)
 
 case $format in
     json)   json_list ;;

+ 3 - 10
bin/v-log-action

@@ -41,19 +41,12 @@ fi
 #----------------------------------------------------------#
 
 if [ "$user" = "system" ] || [ "$user" = "System" ]; then
-    user="admin"
+    user="system"
 fi
 
 check_args '4' "$#" 'USER TYPE CATEGORY DETAILS'
-is_object_valid 'user' 'USER' "$user"
-
-# Future hooks for login/logout events, currently housed in v-log-user-login and v-log-user-logout
-if [ "$event_category" = "login" ] || [ "$event_category" = "Login" ]; then
-echo "login hook used"
-fi
-
-if [ "$event_category" = "logout" ] || [ "$event_category" = "Logout" ]; then
-echo "logout hook used"
+if [ "$user" != "system" ]; then
+    is_object_valid 'user' 'USER' "$user"
 fi
 
 log_history "$event_details" '' "$user"

+ 8 - 4
func/main.sh

@@ -106,11 +106,15 @@ log_history() {
         event_category="System"
     fi
 
-    if ! $BIN/v-list-user "$log_user" >/dev/null; then
-        return $E_NOTEXIST
+    # Log system events to system log file
+    if [ "$log_user" = "system" ]; then
+        log=$HESTIA/data/users/admin/system.log
+    else 
+        if ! $BIN/v-list-user "$log_user" >/dev/null; then
+            return $E_NOTEXIST
+        fi
+        log=$HESTIA/data/users/$log_user/history.log
     fi
-
-    log=$HESTIA/data/users/$log_user/history.log
     touch $log
 
     # TODO: Improve log pruning and pagination

+ 6 - 4
web/templates/admin/list_log.html

@@ -3,7 +3,7 @@
     <div class="l-unit-toolbar__buttonstrip">
       <? if (($_SESSION['userContext'] === 'admin') && ($_SESSION['look'] === 'admin')) {?>
         <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>
-      <? } else if (($_SESSION['userContext'] === 'admin') && ($_GET['user'] === 'admin')) { ?>
+      <? } else if (($_SESSION['userContext'] === 'admin') && ($_GET['user'] === 'system')) { ?>
         <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>
       <? } else {?>
         <? if (($_SESSION['userContext'] === 'admin') && (isset($_GET['user'])) && ($_GET['user'] !== 'admin')) { ?>
@@ -14,10 +14,12 @@
       <? } ?>
       <? if (($_SESSION['userContext'] === 'admin') && ($_GET['user'] !== 'admin')) { ?>
         <? if (($_SESSION['userContext'] === 'admin') && (isset($_GET['user'])) && ($_GET['user'] !== 'admin')) { ?>
-          <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>
-          <? } else { ?>
-          <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>
+          <? if ($_GET['user'] !== 'system') {?>
+            <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>
           <? } ?>
+        <? } else { ?>
+          <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>
+        <? } ?>
       <? } ?>
     </div>
     <div class="l-unit-toolbar__buttonstrip float-right">

+ 1 - 1
web/templates/admin/list_services.html

@@ -7,7 +7,7 @@
           <!-- Disable Updates Button 
           <a href="/list/updates/" class="ui-button cancel" dir="ltr"><i class="fas fa-sync status-icon green"></i><?=_('Updates')?></a>
           -->
-          <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>
+          <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>
           <div class="actions-panel display-inline-block" key-action="js">
               <a class="data-controls do_servicerestart ui-button danger cancel">
                 <i class="do_servicerestart fas fa-undo status-icon red"></i><?=_('Restart')?>