Browse Source

Merge branch 'fix/2021-03-logfiles' into main

Kristan Kenney 5 years ago
parent
commit
55799c866a
2 changed files with 22 additions and 19 deletions
  1. 10 9
      bin/v-delete-user-auth-log
  2. 12 10
      bin/v-delete-user-log

+ 10 - 9
bin/v-delete-user-auth-log

@@ -3,9 +3,12 @@
 #
 # The function for deleting a users auth log file
 
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
 # Argument definition
 user=$1
-date=$(date "+%F %T")
 
 # Includes
 source $HESTIA/func/main.sh
@@ -22,17 +25,15 @@ check_args '1' "$#" 'USER'
 is_format_valid 'user'
 is_object_valid 'user' 'USER' "$user"
 
-if [ ! -f $USER_DATA/auth.log ]; then
-    touch  $USER_DATA/auth.log
-fi
-
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-rm $USER_DATA/auth.log
-
-log_history "Authentication log for $user was cleared on $date."
-log_event "$OK" "$ARGUMENTS"
+# Remove log file and log event
+if [ -f $USER_DATA/auth.log ]; then
+    rm -f $USER_DATA/auth.log
+    log_history "login history for $user was cleared."
+    log_event "$OK" "$ARGUMENTS"
+fi
 
 exit

+ 12 - 10
bin/v-delete-user-log

@@ -13,7 +13,6 @@
 
 # Argument definition
 user=$1
-date=$(date "+%F %T")
 
 # Includes
 source $HESTIA/func/main.sh
@@ -22,20 +21,23 @@ source $HESTIA/conf/hestia.conf
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '1' "$#" 'USER'
+is_format_valid 'user'
+is_object_valid 'user' 'USER' "$user"
+
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Remove log file
-if [ -z $user ]; then
-    echo "Error: no user specified."
-elif [ ! -f "$HESTIA/data/users/$user/history.log" ]; then
-    echo "Error: no history log found for $user."
-else
+# Remove log file and log event
+if [ -f "$HESTIA/data/users/$user/history.log" ]; then
     rm -f $HESTIA/data/users/$user/history.log
+    log_history "user action log for $user was cleared."
+    log_event "$OK" "$ARGUMENTS"
 fi
 
-log_history "Log for $user was cleared on $date."
-log_event "$OK" "$ARGUMENTS"
-
 exit