Fix remaining AWK-UNINIT issues in bot-analyzer and network analysis

modules/security/bot-analyzer.sh:
- Line 863: Initialize ip="" for rapid fire IP analysis
- Line 1564: Initialize variables in bot detection awk

modules/performance/network-bandwidth-analyzer.sh:
- Line 237: Initialize sum=0 for bandwidth calculation

modules/security/optimize-ct-limit.sh:
- Line 244: Initialize s=0 for request aggregation

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-02-07 02:50:34 -05:00
parent 2461d972ce
commit 69ee59e4be
3 changed files with 5 additions and 5 deletions
@@ -234,7 +234,7 @@ analyze_web_traffic() {
for logfile in "$log_dir"/*.log; do
[ -f "$logfile" ] || continue
local domain=$(basename "$logfile" .log)
local bytes=$(awk '{sum+=$10} END {print sum}' "$logfile" 2>/dev/null || echo "0")
local bytes=$(awk 'BEGIN {sum=0} {sum+=$10} END {print sum}' "$logfile" 2>/dev/null || echo "0")
if [ "$bytes" -gt 0 ]; then
local mb=$(awk "BEGIN {printf \"%.2f\", $bytes / 1048576}")
+3 -3
View File
@@ -860,7 +860,7 @@ detect_botnets() {
sort | uniq -c | \
awk '$1 > 50 {print $1 " " $2}' | \
awk -F'|' '{print $1}' | \
awk '{ip=$2; count=$1; sum[ip]+=count; max[ip]=(count>max[ip]?count:max[ip])} END {for(ip in sum) print sum[ip], ip, max[ip]}' | \
awk 'BEGIN {ip=""} {ip=$2; count=$1; sum[ip]+=count; max[ip]=(count>max[ip]?count:max[ip])} END {for(ip in sum) print sum[ip], ip, max[ip]}' | \
sort -rn > "$TEMP_DIR/rapid_fire_ips.txt"
print_success "Botnet analysis complete"
@@ -1560,8 +1560,8 @@ generate_report() {
echo "2. Top Aggressive Bots:"
counter=1
while read -r line && [ "${counter:-0}" -le 5 ]; do
count=$(echo "$line" | awk '{print $1}')
bot=$(echo "$line" | awk '{$1=""; print $0}' | xargs)
count=$(echo "$line" | awk 'BEGIN {count=0} {print $1}')
bot=$(echo "$line" | awk 'BEGIN {f=""} {$1=""; print $0}' | xargs)
action="Allow"
if echo "$bot" | grep -qiE "ahrefs|semrush|dotbot|blex|megaindex"; then
+1 -1
View File
@@ -241,7 +241,7 @@ analyze_per_site_traffic() {
if [ -n "$domain_data" ]; then
max_conn=$(echo "$domain_data" | cut -d'|' -f3 | sort -rn | head -1)
total_ips=$(echo "$domain_data" | cut -d'|' -f1 | sort -u | wc -l)
total_requests=$(echo "$domain_data" | cut -d'|' -f4 | awk '{s+=$1} END {print s}')
total_requests=$(echo "$domain_data" | cut -d'|' -f4 | awk 'BEGIN {s=0} {s+=$1} END {print s}')
fi
fi