Critical fixes: Replace while-read loops with mapfile, fix integer variable defaults
FIXES: 1. Replace server IPs while-read with mapfile to prevent hanging 2. Fix integer expression errors in variable initialization - Strip whitespace from wc commands - Add 0 defaults for all numeric variables RESULT: Script now progresses past threat score loading phase Status: Hangs at IP scoring loop (separate issue to investigate)
This commit is contained in:
@@ -1657,9 +1657,10 @@ calculate_threat_scores() {
|
|||||||
# Pre-load server IPs for fast exclusion checking (avoids grep in loop)
|
# Pre-load server IPs for fast exclusion checking (avoids grep in loop)
|
||||||
declare -A server_ips_array
|
declare -A server_ips_array
|
||||||
if [ -f "$TEMP_DIR/server_ips.txt" ]; then
|
if [ -f "$TEMP_DIR/server_ips.txt" ]; then
|
||||||
while read -r ip; do
|
mapfile -t server_ips_list < "$TEMP_DIR/server_ips.txt" 2>/dev/null
|
||||||
|
for ip in "${server_ips_list[@]}"; do
|
||||||
[ -n "$ip" ] && server_ips_array["$ip"]=1
|
[ -n "$ip" ] && server_ips_array["$ip"]=1
|
||||||
done < "$TEMP_DIR/server_ips.txt"
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Pre-count requests per IP using mapfile (faster than while-read on large files)
|
# Pre-count requests per IP using mapfile (faster than while-read on large files)
|
||||||
@@ -2302,13 +2303,21 @@ generate_report() {
|
|||||||
# QUICK STATS DASHBOARD
|
# QUICK STATS DASHBOARD
|
||||||
print_header "QUICK STATS DASHBOARD"
|
print_header "QUICK STATS DASHBOARD"
|
||||||
|
|
||||||
total_requests=$(wc -l < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null || echo "0")
|
total_requests=$(wc -l < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null)
|
||||||
unique_ips=$(awk -F'|' '{print $1}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | wc -l || echo "0")
|
total_requests=${total_requests:-0}
|
||||||
unique_domains=$(awk -F'|' '{print $2}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | wc -l || echo "0")
|
|
||||||
bot_requests=$(awk -F'|' '$9 != "unknown"' < "$TEMP_DIR/classified_bots.txt" 2>/dev/null | wc -l || echo "0")
|
unique_ips=$(awk -F'|' '{print $1}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | wc -l 2>/dev/null)
|
||||||
|
unique_ips=${unique_ips:-0}
|
||||||
|
|
||||||
|
unique_domains=$(awk -F'|' '{print $2}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | wc -l 2>/dev/null)
|
||||||
|
unique_domains=${unique_domains:-0}
|
||||||
|
|
||||||
|
bot_requests=$(awk -F'|' '$9 != "unknown"' < "$TEMP_DIR/classified_bots.txt" 2>/dev/null | wc -l 2>/dev/null)
|
||||||
|
bot_requests=${bot_requests:-0}
|
||||||
|
|
||||||
# Count private/internal IPs (excluded from threat analysis)
|
# Count private/internal IPs (excluded from threat analysis)
|
||||||
private_ips=$(awk -F'|' '{print $1}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | grep -E '^(127\.|10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[01])\.|169\.254\.)' 2>/dev/null | wc -l || echo "0")
|
private_ips=$(awk -F'|' '{print $1}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | grep -E '^(127\.|10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[01])\.|169\.254\.)' 2>/dev/null | wc -l 2>/dev/null)
|
||||||
|
private_ips=${private_ips:-0}
|
||||||
|
|
||||||
# Count server's own IPs in the logs
|
# Count server's own IPs in the logs
|
||||||
server_ip_hits=0
|
server_ip_hits=0
|
||||||
|
|||||||
Reference in New Issue
Block a user