diff --git a/modules/security/bot-analyzer.sh b/modules/security/bot-analyzer.sh index 50ae08a..a87c83d 100755 --- a/modules/security/bot-analyzer.sh +++ b/modules/security/bot-analyzer.sh @@ -118,35 +118,47 @@ prompt_time_range() { echo -e " ${GREEN}7)${NC} Custom hours" echo -e " ${GREEN}8)${NC} Custom days" echo "" - read -p "Select time range (1-8): " time_choice - case $time_choice in - 1) ;; # All logs - no filter - 2) HOURS_BACK=1 ;; - 3) HOURS_BACK=6 ;; - 4) HOURS_BACK=24 ;; - 5) DAYS_BACK=7 ;; - 6) DAYS_BACK=30 ;; - 7) - read -p "Enter number of hours: " custom_hours - if [[ "$custom_hours" =~ ^[0-9]+$ ]]; then - HOURS_BACK=$custom_hours - else - print_error "Invalid input, using all logs" - fi - ;; - 8) - read -p "Enter number of days: " custom_days - if [[ "$custom_days" =~ ^[0-9]+$ ]]; then - DAYS_BACK=$custom_days - else - print_error "Invalid input, using all logs" - fi - ;; - *) - print_warning "Invalid choice, using all logs" - ;; - esac + # Validate time_choice input with retry loop + while true; do + read -p "Select time range (1-8): " time_choice + + if ! [[ "$time_choice" =~ ^[1-8]$ ]]; then + print_error "Invalid choice. Please enter 1-8" + continue + fi + + case $time_choice in + 1) break ;; # All logs - no filter + 2) HOURS_BACK=1; break ;; + 3) HOURS_BACK=6; break ;; + 4) HOURS_BACK=24; break ;; + 5) DAYS_BACK=7; break ;; + 6) DAYS_BACK=30; break ;; + 7) + while true; do + read -p "Enter number of hours: " custom_hours + if [[ "$custom_hours" =~ ^[0-9]+$ ]] && [ "$custom_hours" -gt 0 ]; then + HOURS_BACK=$custom_hours + break 2 # Break out of both loops + else + print_error "Invalid input. Please enter a positive number" + fi + done + ;; + 8) + while true; do + read -p "Enter number of days: " custom_days + if [[ "$custom_days" =~ ^[0-9]+$ ]] && [ "$custom_days" -gt 0 ]; then + DAYS_BACK=$custom_days + break 2 # Break out of both loops + else + print_error "Invalid input. Please enter a positive number" + fi + done + ;; + esac + done } prompt_user_scope() { @@ -156,15 +168,25 @@ prompt_user_scope() { echo -e " ${GREEN}1)${NC} All users (system-wide analysis)" echo -e " ${GREEN}2)${NC} Specific user" echo "" - read -p "Select option (1-2): " user_choice - if [ "$user_choice" = "2" ]; then - echo "" - local selected=$(select_user_interactive "Select user to analyze") - if [ $? -eq 0 ] && [ "$selected" != "ALL" ]; then - FILTER_USER="$selected" + # Validate user_choice input with retry loop + while true; do + read -p "Select option (1-2): " user_choice + + if ! [[ "$user_choice" =~ ^[1-2]$ ]]; then + print_error "Invalid choice. Please enter 1 or 2" + continue fi - fi + + if [ "$user_choice" = "2" ]; then + echo "" + local selected=$(select_user_interactive "Select user to analyze") + if [ $? -eq 0 ] && [ "$selected" != "ALL" ]; then + FILTER_USER="$selected" + fi + fi + break + done } # Interactive prompts for missing options