Declared unset variables. Fixed console output based on VERBOSE state.

This commit is contained in:
Leora
2025-11-19 11:54:54 -06:00
parent 33c4d58bb7
commit f89ba12361

View File

@@ -3652,6 +3652,7 @@ configure_fail2ban() {
# --- Collect User IPs to Ignore --- # --- Collect User IPs to Ignore ---
local -a IGNORE_IPS=("127.0.0.1/8" "::1") # Array for easier dedup. local -a IGNORE_IPS=("127.0.0.1/8" "::1") # Array for easier dedup.
local -a INVALID_IPS=()
local prompt_change="" local prompt_change=""
# NEW: Auto-detect and offer to whitelist current SSH connection # NEW: Auto-detect and offer to whitelist current SSH connection
@@ -3671,7 +3672,8 @@ configure_fail2ban() {
prompt_change=" additional" # Modifies following prompt based on presence of SSH connection. prompt_change=" additional" # Modifies following prompt based on presence of SSH connection.
fi fi
if confirm "Add$prompt_change IP addresses or CIDR ranges to Fail2Ban ignore list (e.g., Tailscale)?"; then if [[ $VERBOSE != false ]] && \
confirm "Add$prompt_change IP addresses or CIDR ranges to Fail2Ban ignore list (e.g., Tailscale)?"; then
while true; do while true; do
local -a WHITELIST_IPS=() local -a WHITELIST_IPS=()
log "Prompting user for IP addresses or CIDR ranges to whitelist via Fail2Ban ignore list..." log "Prompting user for IP addresses or CIDR ranges to whitelist via Fail2Ban ignore list..."
@@ -3686,7 +3688,7 @@ configure_fail2ban() {
break break
fi fi
local valid=true local valid=true
local -a INVALID_IPS=() INVALID_IPS=()
for ip in "${WHITELIST_IPS[@]}"; do for ip in "${WHITELIST_IPS[@]}"; do
if ! validate_ip_or_cidr "$ip"; then if ! validate_ip_or_cidr "$ip"; then
valid=false valid=false
@@ -3697,10 +3699,10 @@ configure_fail2ban() {
IGNORE_IPS+=( "${WHITELIST_IPS[@]}" ) IGNORE_IPS+=( "${WHITELIST_IPS[@]}" )
break break
else else
local s local s=""
(( ${#INVALID_IPS[@]} > 1 )) && s="s" # Plural if > 1 (( ${#INVALID_IPS[@]} > 1 )) && s="s" # Plural if > 1
print_error "Invalid IP$s: ${INVALID_IPS[*]}" print_error "Invalid IP$s: ${INVALID_IPS[*]}"
printf '%s\n' "Please try again. Leave blank to skip." printf '%s\n\n' "Please try again. Leave blank to skip."
fi fi
done done
fi fi
@@ -3709,19 +3711,21 @@ configure_fail2ban() {
local -A seen=() local -A seen=()
local -a unique=() local -a unique=()
for ip in "${IGNORE_IPS[@]}"; do for ip in "${IGNORE_IPS[@]}"; do
[[ -z ${seen[$ip]} ]] && { if [[ ! -v seen[$ip] ]]; then
seen[$ip]=1 seen[$ip]=1
unique+=( "$ip" ) unique+=( "$ip" )
} fi
done done
IGNORE_IPS=( "${unique[@]}" ) IGNORE_IPS=( "${unique[@]}" )
fi fi
local WHITELIST_STR if (( ${#IGNORE_IPS[@]} > 2 )); then
printf -v WHITELIST_STR "Whitelisting:\n" local WHITELIST_STR
for ip in "${IGNORE_IPS[@]:2}"; do # Skip first two entries in console output ("127.0.0.1/8" "::1"). printf -v WHITELIST_STR "Whitelisting:\n"
printf -v WHITELIST_STR "%s %s\n" "$WHITELIST_STR" "$ip" for ip in "${IGNORE_IPS[@]:2}"; do # Skip first two entries in console output ("127.0.0.1/8" "::1").
done printf -v WHITELIST_STR "%s %s\n" "$WHITELIST_STR" "$ip"
print_info "$WHITELIST_STR" done
print_info "$WHITELIST_STR"
fi
# --- Define Desired Configurations --- # --- Define Desired Configurations ---
local UFW_PROBES_CONFIG local UFW_PROBES_CONFIG
@@ -3793,6 +3797,9 @@ EOF
# Show how to add IPs later # Show how to add IPs later
if (( ${#INVALID_IPS[@]} > 0 )) || confirm "Show instructions for adding IPs later?" "n"; then if (( ${#INVALID_IPS[@]} > 0 )) || confirm "Show instructions for adding IPs later?" "n"; then
printf "\n" printf "\n"
if [[ $VERBOSE == false ]]; then
printf '%s\n' "${PURPLE} Fail2Ban ignore list modification:${NC}"
fi
print_info "To add more IP addresses to Fail2Ban ignore list later:" print_info "To add more IP addresses to Fail2Ban ignore list later:"
printf "%s1. Edit the configuration file:%s\n" "$CYAN" "$NC" printf "%s1. Edit the configuration file:%s\n" "$CYAN" "$NC"
printf " %ssudo nano /etc/fail2ban/jail.local%s\n" "$BOLD" "$NC" printf " %ssudo nano /etc/fail2ban/jail.local%s\n" "$BOLD" "$NC"