From a424f5b88bd7387a3f15bd79be7728ff6117681b Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 7 Jul 2025 21:22:47 +0100 Subject: [PATCH] enhanced fail2ban jail.local --- du_setup.sh | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/du_setup.sh b/du_setup.sh index 24a647b..752ee7b 100644 --- a/du_setup.sh +++ b/du_setup.sh @@ -1037,29 +1037,24 @@ configure_firewall() { configure_fail2ban() { print_section "Fail2Ban Configuration" - # --- Create UFW Probes Filter for Fail2ban --- - # This custom filter tells Fail2ban what to look for in UFW's log file. - print_info "Creating Fail2ban filter for UFW probes..." - mkdir -p /etc/fail2ban/filter.d - tee /etc/fail2ban/filter.d/ufw-probes.conf > /dev/null <<'EOF' + # --- Define Desired Configurations --- + # Define content of config file. + local UFW_PROBES_CONFIG + UFW_PROBES_CONFIG=$(cat <<'EOF' [Definition] # This regex looks for the standard "[UFW BLOCK]" message in /var/log/ufw.log failregex = \[UFW BLOCK\] IN=.* OUT=.* SRC= ignoreregex = EOF +) - # --- Create Enhanced jail.local Configuration --- - # This new configuration sets more robust defaults and adds the UFW monitoring jail. - print_info "Creating enhanced Fail2ban local jail configuration..." - tee /etc/fail2ban/jail.local > /dev/null < "$UFW_FILTER_PATH" + echo "$JAIL_LOCAL_CONFIG" > "$JAIL_LOCAL_PATH" # --- Restart and Verify Fail2ban --- print_info "Enabling and restarting Fail2Ban to apply new rules..." @@ -1087,7 +1103,6 @@ EOF fail2ban-client status | tee -a "$LOG_FILE" else print_error "Fail2Ban service failed to start. Check 'journalctl -u fail2ban' for errors." - # No longer exits the script, just reports the failure. FAILED_SERVICES+=("fail2ban") fi log "Fail2Ban configuration completed."