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
+37 -17
View File
@@ -48,14 +48,22 @@ 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 ""
# Validate scope_choice input with retry loop
while true; do
read -p "Select option [1]: " scope_choice read -p "Select option [1]: " scope_choice
scope_choice=${scope_choice:-1} 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 case $scope_choice in
0) 0)
echo "" echo ""
@@ -75,6 +83,7 @@ case $scope_choice in
echo "" echo ""
exit 0 exit 0
fi fi
break
;; ;;
3) 3)
# Enter specific domain # Enter specific domain
@@ -87,26 +96,37 @@ case $scope_choice in
exit 0 exit 0
fi fi
echo "→ Filtering for domain: $FILTER_DOMAIN" echo "→ Filtering for domain: $FILTER_DOMAIN"
break
;; ;;
*) 1)
echo "→ Analyzing all users/domains" echo "→ Analyzing all users/domains"
break
;; ;;
esac 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 ""
# Validate time_choice input with retry loop
while true; do
read -p "Select option [3]: " time_choice read -p "Select option [3]: " time_choice
time_choice=${time_choice:-3} 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 case $time_choice in
0) 0)
echo "" echo ""
@@ -114,13 +134,13 @@ case $time_choice in
echo "" echo ""
exit 0 exit 0
;; ;;
1) HOURS_TO_ANALYZE=1 ;; 1) HOURS_TO_ANALYZE=1; break ;;
2) HOURS_TO_ANALYZE=6 ;; 2) HOURS_TO_ANALYZE=6; break ;;
3) HOURS_TO_ANALYZE=24 ;; 3) HOURS_TO_ANALYZE=24; break ;;
4) HOURS_TO_ANALYZE=168 ;; 4) HOURS_TO_ANALYZE=168; break ;;
5) HOURS_TO_ANALYZE=720 ;; 5) HOURS_TO_ANALYZE=720; break ;;
*) HOURS_TO_ANALYZE=24 ;;
esac esac
done
echo "" echo ""
echo "→ Analyzing last $HOURS_TO_ANALYZE hours..." echo "→ Analyzing last $HOURS_TO_ANALYZE hours..."