From 3aa2e0e97c9fde733fc95271dbdb451e71cee46b Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 17 Feb 2026 18:43:50 -0500 Subject: [PATCH] Standardize website-error-analyzer.sh menu validation and colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IMPROVEMENTS: - Added input validation for scope choice (0-3) with retry loop - Added input validation for time choice (0-5) with retry loop - Added color codes to menu options (${CYAN}1)${NC} and ${RED}0)${NC}) - Removed wildcard case that silently accepted invalid input - Added explicit break statements for valid selections - Improved error messages for invalid choices VALIDATION DETAILS: - Scope choice: Only accepts 0-5, rejects invalid with error message - Time choice: Only accepts 0-5, rejects invalid with error message - Both menus have retry logic for failed validation - Cancel options (0) exit immediately MENU STANDARDS COMPLIANCE: ✓ Input validation (CRITICAL) ✓ Default values (already had defaults) ✓ Color codes (IMPORTANT - standardized to CYAN/RED) ✓ Error messages on invalid input (IMPORTANT) ✓ Retry logic for failed validation (IMPORTANT) Lines modified: ~50 (two menus with validation + colors) Co-Authored-By: Claude Haiku 4.5 --- modules/website/website-error-analyzer.sh | 140 ++++++++++++---------- 1 file changed, 80 insertions(+), 60 deletions(-) diff --git a/modules/website/website-error-analyzer.sh b/modules/website/website-error-analyzer.sh index 382bfe8..1102ed3 100755 --- a/modules/website/website-error-analyzer.sh +++ b/modules/website/website-error-analyzer.sh @@ -48,79 +48,99 @@ echo "" # Ask for filtering scope echo -e "${CYAN}Analysis Scope:${NC}" -echo " 1) All users/domains (default)" -echo " 2) Specific cPanel user" -echo " 3) Specific domain" -echo " 0) Cancel and return to menu" +echo -e " ${CYAN}1)${NC} All users/domains (default)" +echo -e " ${CYAN}2)${NC} Specific cPanel user" +echo -e " ${CYAN}3)${NC} Specific domain" +echo -e " ${RED}0)${NC} Cancel and return to menu" echo "" -read -p "Select option [1]: " scope_choice -scope_choice=${scope_choice:-1} -case $scope_choice in - 0) - echo "" - echo "Analysis cancelled." - echo "" - exit 0 - ;; - 2) - # Select specific user - select_user_interactive "Select cPanel user to analyze" - if [ -n "$SELECTED_USER" ]; then - FILTER_USER="$SELECTED_USER" - echo "→ Filtering for user: $FILTER_USER" - else - echo "" - echo "No user selected. Analysis cancelled." - echo "" - exit 0 - fi - ;; - 3) - # Enter specific domain - echo "" - read -p "Enter domain name (e.g., example.com) or 0 to cancel: " FILTER_DOMAIN - if [ "$FILTER_DOMAIN" = "0" ] || [ -z "$FILTER_DOMAIN" ]; then +# Validate scope_choice input with retry loop +while true; do + read -p "Select option [1]: " scope_choice + scope_choice=${scope_choice:-1} + + if ! [[ "$scope_choice" =~ ^[0-3]$ ]]; then + print_error "Invalid choice. Please enter 0-3" + continue + fi + + case $scope_choice in + 0) echo "" echo "Analysis cancelled." echo "" exit 0 - fi - echo "→ Filtering for domain: $FILTER_DOMAIN" - ;; - *) - echo "→ Analyzing all users/domains" - ;; -esac + ;; + 2) + # Select specific user + select_user_interactive "Select cPanel user to analyze" + if [ -n "$SELECTED_USER" ]; then + FILTER_USER="$SELECTED_USER" + echo "→ Filtering for user: $FILTER_USER" + else + echo "" + echo "No user selected. Analysis cancelled." + echo "" + exit 0 + fi + break + ;; + 3) + # Enter specific domain + echo "" + read -p "Enter domain name (e.g., example.com) or 0 to cancel: " FILTER_DOMAIN + if [ "$FILTER_DOMAIN" = "0" ] || [ -z "$FILTER_DOMAIN" ]; then + echo "" + echo "Analysis cancelled." + echo "" + exit 0 + fi + echo "→ Filtering for domain: $FILTER_DOMAIN" + break + ;; + 1) + echo "→ Analyzing all users/domains" + break + ;; + esac +done echo "" # Ask for time range echo -e "${CYAN}How far back should we analyze?${NC}" -echo " 1) Last 1 hour" -echo " 2) Last 6 hours" -echo " 3) Last 24 hours (default)" -echo " 4) Last 7 days" -echo " 5) Last 30 days" -echo " 0) Cancel and return to menu" +echo -e " ${CYAN}1)${NC} Last 1 hour" +echo -e " ${CYAN}2)${NC} Last 6 hours" +echo -e " ${CYAN}3)${NC} Last 24 hours (default)" +echo -e " ${CYAN}4)${NC} Last 7 days" +echo -e " ${CYAN}5)${NC} Last 30 days" +echo -e " ${RED}0)${NC} Cancel and return to menu" echo "" -read -p "Select option [3]: " time_choice -time_choice=${time_choice:-3} -case $time_choice in - 0) - echo "" - echo "Analysis cancelled." - echo "" - exit 0 - ;; - 1) HOURS_TO_ANALYZE=1 ;; - 2) HOURS_TO_ANALYZE=6 ;; - 3) HOURS_TO_ANALYZE=24 ;; - 4) HOURS_TO_ANALYZE=168 ;; - 5) HOURS_TO_ANALYZE=720 ;; - *) HOURS_TO_ANALYZE=24 ;; -esac +# Validate time_choice input with retry loop +while true; do + read -p "Select option [3]: " time_choice + time_choice=${time_choice:-3} + + if ! [[ "$time_choice" =~ ^[0-5]$ ]]; then + print_error "Invalid choice. Please enter 0-5" + continue + fi + + case $time_choice in + 0) + echo "" + echo "Analysis cancelled." + echo "" + exit 0 + ;; + 1) HOURS_TO_ANALYZE=1; break ;; + 2) HOURS_TO_ANALYZE=6; break ;; + 3) HOURS_TO_ANALYZE=24; break ;; + 4) HOURS_TO_ANALYZE=168; break ;; + 5) HOURS_TO_ANALYZE=720; break ;; + esac +done echo "" echo "→ Analyzing last $HOURS_TO_ANALYZE hours..."