Fix integer expression error in variable validation
Properly handle grep output to prevent newlines and invalid values: - Use explicit if/else instead of || fallback operator - Strip all whitespace from grep results - Validate variables match numeric pattern before use - Set to 0 if validation fails Prevents 'integer expression expected' errors when comparing values
This commit is contained in:
@@ -469,11 +469,14 @@ draw_quick_actions() {
|
|||||||
|
|
||||||
# Check for high connection counts
|
# Check for high connection counts
|
||||||
if [ -f "$TEMP_DIR/recent_events" ]; then
|
if [ -f "$TEMP_DIR/recent_events" ]; then
|
||||||
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)
|
||||||
|
else
|
||||||
|
high_conn_count=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure it's a valid number
|
# Ensure it's a valid number (strip whitespace and validate)
|
||||||
high_conn_count=${high_conn_count:-0}
|
high_conn_count=$(echo "$high_conn_count" | tr -d '[:space:]')
|
||||||
|
[[ ! "$high_conn_count" =~ ^[0-9]+$ ]] && high_conn_count=0
|
||||||
|
|
||||||
# IP Blocking Recommendations
|
# IP Blocking Recommendations
|
||||||
if [ "$blockable_count" -gt 0 ]; then
|
if [ "$blockable_count" -gt 0 ]; then
|
||||||
@@ -495,8 +498,12 @@ draw_quick_actions() {
|
|||||||
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=0
|
||||||
ssh_attacks=${ssh_attacks:-0}
|
if [ -f "$TEMP_DIR/recent_events" ]; then
|
||||||
|
ssh_attacks=$(grep -c "SSH_BRUTEFORCE" "$TEMP_DIR/recent_events" 2>/dev/null)
|
||||||
|
fi
|
||||||
|
ssh_attacks=$(echo "$ssh_attacks" | tr -d '[:space:]')
|
||||||
|
[[ ! "$ssh_attacks" =~ ^[0-9]+$ ]] && ssh_attacks=0
|
||||||
if [ "$ssh_attacks" -gt 5 ]; then
|
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}"
|
||||||
|
|||||||
Reference in New Issue
Block a user