You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					62 lines
				
				1.8 KiB
			
		
		
			
		
	
	
					62 lines
				
				1.8 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								#!/bin/bash
							 | 
						||
| 
								 | 
							
								# info: Delete log file for user
							 | 
						||
| 
								 | 
							
								# options: USER
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# example: v-delete-user-log user
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# This function for deleting a users log file
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								#                Variables & Functions                     #
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Argument definition
							 | 
						||
| 
								 | 
							
								user=$1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Includes
							 | 
						||
| 
								 | 
							
								# shellcheck source=/etc/hestiacp/hestia.conf
							 | 
						||
| 
								 | 
							
								source /etc/hestiacp/hestia.conf
							 | 
						||
| 
								 | 
							
								# shellcheck source=/usr/local/hestia/func/main.sh
							 | 
						||
| 
								 | 
							
								source $HESTIA/func/main.sh
							 | 
						||
| 
								 | 
							
								# load config file
							 | 
						||
| 
								 | 
							
								source_conf "$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'
							 | 
						||
| 
								 | 
							
								if [ "$user" != "system" ]; then
							 | 
						||
| 
								 | 
							
									is_object_valid 'user' 'USER' "$user"
							 | 
						||
| 
								 | 
							
								fi
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								#                       Action                             #
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# 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" "Warning" "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
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								exit
							 |