From 8b5c332b968ffe0e0a31247e0b384c8cccec5860 Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 2 Dec 2025 17:16:20 -0500 Subject: [PATCH] Add missing save_snapshot function to prevent startup error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL BUG: Line 2635 called save_snapshot() every 5 minutes in background loop Function didn't exist → "command not found" error ROOT CAUSE: Snapshot functionality was planned but never implemented Background loop: while true; do sleep 300; save_snapshot; done But save_snapshot() function was missing entirely FIX: Added save_snapshot() function (lines 138-159): - Saves IP_DATA associative array to temp file - Saves ATTACK_TYPE_COUNTER for persistence - Saves TOTAL_THREATS, TOTAL_BLOCKS, START_TIME - Writes to $TEMP_DIR/snapshot.dat - Silent errors (2>/dev/null) to prevent spam PURPOSE: Allows monitor to preserve state across sessions Data can be restored if monitor crashes/restarts ERROR BEFORE FIX: /root/server-toolkit/modules/security/live-attack-monitor.sh: line 2635: save_snapshot: command not found AFTER FIX: ✓ Background snapshot saves every 5 minutes without errors ✓ Monitor state preserved for recovery --- modules/security/live-attack-monitor.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/security/live-attack-monitor.sh b/modules/security/live-attack-monitor.sh index 7fcb065..c23ac9d 100755 --- a/modules/security/live-attack-monitor.sh +++ b/modules/security/live-attack-monitor.sh @@ -135,6 +135,29 @@ cleanup() { trap cleanup EXIT INT TERM +# Save current monitoring state to temp files (for persistence across sessions) +save_snapshot() { + # Save IP_DATA associative array to file + local snapshot_file="$TEMP_DIR/snapshot.dat" + + # Write IP data + { + for ip in "${!IP_DATA[@]}"; do + echo "IP_DATA[$ip]=${IP_DATA[$ip]}" + done + + # Write attack type counters + for attack in "${!ATTACK_TYPE_COUNTER[@]}"; do + echo "ATTACK_TYPE_COUNTER[$attack]=${ATTACK_TYPE_COUNTER[$attack]}" + done + + # Write totals + echo "TOTAL_THREATS=$TOTAL_THREATS" + echo "TOTAL_BLOCKS=$TOTAL_BLOCKS" + echo "START_TIME=$START_TIME" + } > "$snapshot_file" 2>/dev/null +} + # Statistics counters declare -A IP_DATA # Stores: IP -> score|hits|bot_type|attacks|ban_count|rep_score declare -A IP_TIMESTAMPS # Stores: IP -> comma-separated attack timestamps (last 100)