CRITICAL: Add error handling to stats dashboard calculations
- Line 2290: Added 2>/dev/null fallback to wc for total_requests - Line 2291: Added 2>/dev/null fallback to unique_ips calculation - Line 2292: Added 2>/dev/null fallback to unique_domains calculation - Line 2293: Added 2>/dev/null fallback to bot_requests calculation - Line 2296: Improved error handling for private_ips calculation - Line 2302: Fixed UUOC (cat | grep) pattern - removed useless cat These operations lack proper error handling and would crash with set -e if files are missing or malformed. Also removed inefficient cat pipe.
This commit is contained in:
@@ -2287,19 +2287,19 @@ 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")
|
total_requests=$(wc -l < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null || echo "0")
|
||||||
unique_ips=$(awk -F'|' '{print $1}' < "$TEMP_DIR/parsed_logs.txt" | sort -u | wc -l)
|
unique_ips=$(awk -F'|' '{print $1}' < "$TEMP_DIR/parsed_logs.txt" 2>/dev/null | sort -u | wc -l || echo "0")
|
||||||
unique_domains=$(awk -F'|' '{print $2}' < "$TEMP_DIR/parsed_logs.txt" | sort -u | wc -l)
|
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" | wc -l)
|
bot_requests=$(awk -F'|' '$9 != "unknown"' < "$TEMP_DIR/classified_bots.txt" 2>/dev/null | wc -l || echo "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" | sort -u | grep -E '^(127\.|10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[01])\.|169\.254\.)' || true | wc -l)
|
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")
|
||||||
|
|
||||||
# Count server's own IPs in the logs
|
# Count server's own IPs in the logs
|
||||||
server_ip_hits=0
|
server_ip_hits=0
|
||||||
if [ -f "$TEMP_DIR/server_ips.txt" ] && [ -s "$TEMP_DIR/server_ips.txt" ]; then
|
if [ -f "$TEMP_DIR/server_ips.txt" ] && [ -s "$TEMP_DIR/server_ips.txt" ]; then
|
||||||
while read -r server_ip; do
|
while read -r server_ip; do
|
||||||
if cat "$TEMP_DIR/parsed_logs.txt" | grep -q "^$server_ip|" 2>/dev/null; then
|
if grep -q "^$server_ip|" "$TEMP_DIR/parsed_logs.txt" 2>/dev/null; then
|
||||||
server_ip_hits=$((server_ip_hits + 1))
|
server_ip_hits=$((server_ip_hits + 1))
|
||||||
fi
|
fi
|
||||||
done < "$TEMP_DIR/server_ips.txt"
|
done < "$TEMP_DIR/server_ips.txt"
|
||||||
|
|||||||
Reference in New Issue
Block a user