Fix variable comparison error in Quick Actions

Added proper quoting and default values for numeric comparisons to prevent
'too many arguments' error when variables are empty or contain spaces.

Changes:
- Quote all numeric comparisons in conditional statements
- Add fallback default values for grep results (high_conn_count, ssh_attacks)
- Ensures variables always contain valid numbers before comparison
This commit is contained in:
cschantz
2025-11-14 16:23:55 -05:00
parent 3e97dd86d9
commit 64b00774ea
+8 -4
View File
@@ -472,8 +472,11 @@ draw_quick_actions() {
high_conn_count=$(grep -c "HIGH_CONN_COUNT" "$TEMP_DIR/recent_events" 2>/dev/null || echo "0") high_conn_count=$(grep -c "HIGH_CONN_COUNT" "$TEMP_DIR/recent_events" 2>/dev/null || echo "0")
fi fi
# Ensure it's a valid number
high_conn_count=${high_conn_count:-0}
# IP Blocking Recommendations # IP Blocking Recommendations
if [ $blockable_count -gt 0 ]; then if [ "$blockable_count" -gt 0 ]; then
echo -e "${HIGH_COLOR} ⚠️ $blockable_count high-threat IPs ready to block${NC}" echo -e "${HIGH_COLOR} ⚠️ $blockable_count high-threat IPs ready to block${NC}"
echo -e "${MEDIUM_COLOR} → Press 'b' to open blocking menu${NC}" echo -e "${MEDIUM_COLOR} → Press 'b' to open blocking menu${NC}"
else else
@@ -483,7 +486,7 @@ draw_quick_actions() {
# Intelligent Firewall Recommendations # Intelligent Firewall Recommendations
local recommendations=0 local recommendations=0
if [ $has_ddos -eq 1 ] || [ $high_conn_count -gt 0 ]; then if [ "$has_ddos" -eq 1 ] || [ "$high_conn_count" -gt 0 ]; then
echo -e "${HIGH_COLOR} ⚠️ DDoS/SYN Flood Detected - Firewall Protection Recommended${NC}" echo -e "${HIGH_COLOR} ⚠️ DDoS/SYN Flood Detected - Firewall Protection Recommended${NC}"
echo -e "${MEDIUM_COLOR} → Enable SYNFLOOD protection: ${BOLD}csf -e SYNFLOOD${NC}" echo -e "${MEDIUM_COLOR} → Enable SYNFLOOD protection: ${BOLD}csf -e SYNFLOOD${NC}"
echo -e "${MEDIUM_COLOR} → Optimize CT_LIMIT: ${BOLD}Press 'c' to run CT_LIMIT optimizer${NC}" echo -e "${MEDIUM_COLOR} → Optimize CT_LIMIT: ${BOLD}Press 'c' to run CT_LIMIT optimizer${NC}"
@@ -491,9 +494,10 @@ draw_quick_actions() {
recommendations=1 recommendations=1
fi fi
if [ $has_ssh_bruteforce -eq 1 ]; then if [ "$has_ssh_bruteforce" -eq 1 ]; then
local ssh_attacks=$(grep -c "SSH_BRUTEFORCE" "$TEMP_DIR/recent_events" 2>/dev/null || echo "0") local ssh_attacks=$(grep -c "SSH_BRUTEFORCE" "$TEMP_DIR/recent_events" 2>/dev/null || echo "0")
if [ $ssh_attacks -gt 5 ]; then ssh_attacks=${ssh_attacks:-0}
if [ "$ssh_attacks" -gt 5 ]; then
echo -e "${HIGH_COLOR} ⚠️ SSH Bruteforce ($ssh_attacks attempts) - Strengthen SSH Security${NC}" echo -e "${HIGH_COLOR} ⚠️ SSH Bruteforce ($ssh_attacks attempts) - Strengthen SSH Security${NC}"
echo -e "${MEDIUM_COLOR} → Lower LF_SSHD trigger: ${BOLD}Edit /etc/csf/csf.conf → LF_SSHD=\"3\"${NC}" echo -e "${MEDIUM_COLOR} → Lower LF_SSHD trigger: ${BOLD}Edit /etc/csf/csf.conf → LF_SSHD=\"3\"${NC}"
echo -e "${MEDIUM_COLOR} → Enable PortKnocking or change SSH port${NC}" echo -e "${MEDIUM_COLOR} → Enable PortKnocking or change SSH port${NC}"