Standardize malware-scanner.sh menu validation, colors, and yes/no prompts

IMPROVEMENTS:
- Added input validation for menu choice (0-10) with retry loop
- Added color codes to menu options (${CYAN}1.${NC} and ${RED}0.${NC})
- Removed wildcard case that accepted invalid input silently
- Added explicit break statements for all valid selections
- Standardized yes/no prompt to use confirm() library function
- Improved user prompt to show valid range (0-10)

VALIDATION DETAILS:
- Menu choice: Only accepts 0-10, rejects invalid with error message
- Retry loop: User stays in menu until valid choice is entered
- Regex validation: ^([0-9]|10)$ to allow single digits and 10
- Cleanup prompt: Now uses confirm() function for consistency

MENU STANDARDS COMPLIANCE:
✓ Input validation (CRITICAL)
✓ Color codes (IMPORTANT - standardized to CYAN)
✓ Error messages on invalid input (IMPORTANT)
✓ Retry logic for failed validation (IMPORTANT)
✓ Standardized yes/no prompts (IMPORTANT)

Lines modified: ~40 (validation, colors, confirm() function)

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
cschantz
2026-02-17 18:42:50 -05:00
parent 8a4d70c37c
commit 83d1ffaf30
+34 -27
View File
@@ -1559,9 +1559,8 @@ echo " cat $RESULTS_DIR/client_report.txt"
echo ""
# Prompt for cleanup (RKHunter cleanup handled by trap)
read -p "Delete scan script? (Logs and results will be preserved) (yes/no): " cleanup_choice
if [ "$cleanup_choice" = "yes" ]; then
echo ""
if confirm "Delete scan script? (Logs and results will be preserved)"; then
log_message "User requested cleanup - deleting scan script"
echo ""
echo "Removing scan script..."
@@ -1572,10 +1571,10 @@ if [ "$cleanup_choice" = "yes" ]; then
echo ""
else
log_message "User chose to keep scan script"
echo ""
fi
echo "Scan script and results preserved at: $SCAN_DIR"
echo ""
fi
echo "You can:"
echo " • Review logs: ls $LOG_DIR"
@@ -2172,41 +2171,49 @@ show_scan_menu() {
echo ""
echo -e "${CYAN}Create New Scan:${NC}"
echo " 1. Scan entire server (ClamAV, Maldet, RKHunter)"
echo " 2. Scan all user accounts (All scanners - recommended)"
echo " 3. Scan specific user account (All scanners)"
echo " 4. Scan specific domain (All scanners)"
echo " 5. Scan custom path (All scanners)"
echo -e " ${CYAN}1.${NC} Scan entire server (ClamAV, Maldet, RKHunter)"
echo -e " ${CYAN}2.${NC} Scan all user accounts (All scanners - recommended)"
echo -e " ${CYAN}3.${NC} Scan specific user account (All scanners)"
echo -e " ${CYAN}4.${NC} Scan specific domain (All scanners)"
echo -e " ${CYAN}5.${NC} Scan custom path (All scanners)"
echo ""
echo -e "${CYAN}Monitor & Manage:${NC}"
echo " 6. Check scan status"
echo " 7. View scan results"
echo " 8. Delete scan sessions"
echo -e " ${CYAN}6.${NC} Check scan status"
echo -e " ${CYAN}7.${NC} View scan results"
echo -e " ${CYAN}8.${NC} Delete scan sessions"
echo ""
echo -e "${CYAN}Configuration:${NC}"
echo " 9. Install all scanners"
echo " 10. Scanner settings"
echo -e " ${CYAN}9.${NC} Install all scanners"
echo -e " ${CYAN}10.${NC} Scanner settings"
echo ""
echo -e " ${RED}0.${NC} Back"
echo ""
read -p "Select option: " choice
# Validate choice input with retry loop
while true; do
read -p "Select option (0-10): " choice
if ! [[ "$choice" =~ ^([0-9]|10)$ ]]; then
echo -e "${RED}Invalid option${NC}"
sleep 1
continue
fi
case $choice in
1) launch_standalone_scanner_menu "server" ;;
2) launch_standalone_scanner_menu "all_users" ;;
3) launch_standalone_scanner_menu "user" ;;
4) launch_standalone_scanner_menu "domain" ;;
5) launch_standalone_scanner_menu "custom" ;;
6) check_standalone_status ;;
7) view_scan_results ;;
8) delete_standalone_sessions ;;
9) install_all_scanners ;;
10) scanner_settings ;;
1) launch_standalone_scanner_menu "server"; break ;;
2) launch_standalone_scanner_menu "all_users"; break ;;
3) launch_standalone_scanner_menu "user"; break ;;
4) launch_standalone_scanner_menu "domain"; break ;;
5) launch_standalone_scanner_menu "custom"; break ;;
6) check_standalone_status; break ;;
7) view_scan_results; break ;;
8) delete_standalone_sessions; break ;;
9) install_all_scanners; break ;;
10) scanner_settings; break ;;
0) return 0 ;;
*) echo -e "${RED}Invalid option${NC}"; sleep 1 ;;
esac
done
done
}
# View scan results