Standardize website-error-analyzer.sh menu validation and colors

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 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-02-17 18:43:50 -05:00
parent 83d1ffaf30
commit 3aa2e0e97c
+80 -60
View File
@@ -48,79 +48,99 @@ echo ""
# Ask for filtering scope # Ask for filtering scope
echo -e "${CYAN}Analysis Scope:${NC}" echo -e "${CYAN}Analysis Scope:${NC}"
echo " 1) All users/domains (default)" echo -e " ${CYAN}1)${NC} All users/domains (default)"
echo " 2) Specific cPanel user" echo -e " ${CYAN}2)${NC} Specific cPanel user"
echo " 3) Specific domain" echo -e " ${CYAN}3)${NC} Specific domain"
echo " 0) Cancel and return to menu" echo -e " ${RED}0)${NC} Cancel and return to menu"
echo "" echo ""
read -p "Select option [1]: " scope_choice
scope_choice=${scope_choice:-1}
case $scope_choice in # Validate scope_choice input with retry loop
0) while true; do
echo "" read -p "Select option [1]: " scope_choice
echo "Analysis cancelled." scope_choice=${scope_choice:-1}
echo ""
exit 0 if ! [[ "$scope_choice" =~ ^[0-3]$ ]]; then
;; print_error "Invalid choice. Please enter 0-3"
2) continue
# Select specific user fi
select_user_interactive "Select cPanel user to analyze"
if [ -n "$SELECTED_USER" ]; then case $scope_choice in
FILTER_USER="$SELECTED_USER" 0)
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
echo "" echo ""
echo "Analysis cancelled." echo "Analysis cancelled."
echo "" echo ""
exit 0 exit 0
fi ;;
echo "→ Filtering for domain: $FILTER_DOMAIN" 2)
;; # Select specific user
*) select_user_interactive "Select cPanel user to analyze"
echo "→ Analyzing all users/domains" if [ -n "$SELECTED_USER" ]; then
;; FILTER_USER="$SELECTED_USER"
esac 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 "" echo ""
# Ask for time range # Ask for time range
echo -e "${CYAN}How far back should we analyze?${NC}" echo -e "${CYAN}How far back should we analyze?${NC}"
echo " 1) Last 1 hour" echo -e " ${CYAN}1)${NC} Last 1 hour"
echo " 2) Last 6 hours" echo -e " ${CYAN}2)${NC} Last 6 hours"
echo " 3) Last 24 hours (default)" echo -e " ${CYAN}3)${NC} Last 24 hours (default)"
echo " 4) Last 7 days" echo -e " ${CYAN}4)${NC} Last 7 days"
echo " 5) Last 30 days" echo -e " ${CYAN}5)${NC} Last 30 days"
echo " 0) Cancel and return to menu" echo -e " ${RED}0)${NC} Cancel and return to menu"
echo "" echo ""
read -p "Select option [3]: " time_choice
time_choice=${time_choice:-3}
case $time_choice in # Validate time_choice input with retry loop
0) while true; do
echo "" read -p "Select option [3]: " time_choice
echo "Analysis cancelled." time_choice=${time_choice:-3}
echo ""
exit 0 if ! [[ "$time_choice" =~ ^[0-5]$ ]]; then
;; print_error "Invalid choice. Please enter 0-5"
1) HOURS_TO_ANALYZE=1 ;; continue
2) HOURS_TO_ANALYZE=6 ;; fi
3) HOURS_TO_ANALYZE=24 ;;
4) HOURS_TO_ANALYZE=168 ;; case $time_choice in
5) HOURS_TO_ANALYZE=720 ;; 0)
*) HOURS_TO_ANALYZE=24 ;; echo ""
esac 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 ""
echo "→ Analyzing last $HOURS_TO_ANALYZE hours..." echo "→ Analyzing last $HOURS_TO_ANALYZE hours..."