From 8c09d72ec1a6a4bfe9f548c7eebf23e77fa3ed12 Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 11 Feb 2026 22:44:34 -0500 Subject: [PATCH] Standardize 500-error-tracker.sh menu formatting and add input validation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IMPROVEMENTS: - Added input validation for time range choice (0-3) with retry loop - Added color codes to menu options (${CYAN}1)${NC} format) - Removed wildcard case fallback that silently accepted invalid input - Added explicit break statements for valid selections VALIDATION DETAILS: - Time range: Only accepts 0-3, rejects invalid input with clear error - Option 0: Cancel and exit (no silent fallback) - Options 1-3: Valid time ranges for scanning MENU STANDARDS COMPLIANCE: ✓ Input validation (CRITICAL) ✓ Default values (already had) ✓ Color codes (CRITICAL) ✓ Error messages on invalid input (IMPORTANT) ✓ Retry logic for failed validation (IMPORTANT) Lines modified: ~25 (input validation + color codes) Co-Authored-By: Claude Haiku 4.5 --- modules/website/500-error-tracker.sh | 44 ++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/modules/website/500-error-tracker.sh b/modules/website/500-error-tracker.sh index d15eded..6002e43 100755 --- a/modules/website/500-error-tracker.sh +++ b/modules/website/500-error-tracker.sh @@ -25,26 +25,34 @@ echo "" # Ask for time range echo -e "${CYAN}How far back to scan?${NC}" -echo " 1) Last 24 hours (default)" -echo " 2) Last 7 days" -echo " 3) Last 30 days" -echo " 0) Cancel and return to menu" +echo -e " ${CYAN}1)${NC} Last 24 hours (default)" +echo -e " ${CYAN}2)${NC} Last 7 days" +echo -e " ${CYAN}3)${NC} Last 30 days" +echo -e " ${CYAN}0)${NC} Cancel and return to menu" echo "" -read -p "Select option [1]: " time_choice -time_choice=${time_choice:-1} -case $time_choice in - 0) - echo "" - echo "Scan cancelled." - echo "" - exit 0 - ;; - 1) HOURS_TO_SCAN=24 ;; - 2) HOURS_TO_SCAN=168 ;; - 3) HOURS_TO_SCAN=720 ;; - *) HOURS_TO_SCAN=24 ;; -esac +# Validate time_choice input +while true; do + read -p "Select option [1]: " time_choice + time_choice=${time_choice:-1} + + if ! [[ "$time_choice" =~ ^[0-3]$ ]]; then + print_error "Invalid choice. Please enter 0, 1, 2, or 3" + continue + fi + + case $time_choice in + 0) + echo "" + echo "Scan cancelled." + echo "" + exit 0 + ;; + 1) HOURS_TO_SCAN=24; break ;; + 2) HOURS_TO_SCAN=168; break ;; + 3) HOURS_TO_SCAN=720; break ;; + esac +done echo "" echo "→ Scanning last $HOURS_TO_SCAN hours of access logs..."