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:
@@ -1559,9 +1559,8 @@ echo " cat $RESULTS_DIR/client_report.txt"
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Prompt for cleanup (RKHunter cleanup handled by trap)
|
# Prompt for cleanup (RKHunter cleanup handled by trap)
|
||||||
read -p "Delete scan script? (Logs and results will be preserved) (yes/no): " cleanup_choice
|
echo ""
|
||||||
|
if confirm "Delete scan script? (Logs and results will be preserved)"; then
|
||||||
if [ "$cleanup_choice" = "yes" ]; then
|
|
||||||
log_message "User requested cleanup - deleting scan script"
|
log_message "User requested cleanup - deleting scan script"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Removing scan script..."
|
echo "Removing scan script..."
|
||||||
@@ -1572,11 +1571,11 @@ if [ "$cleanup_choice" = "yes" ]; then
|
|||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
log_message "User chose to keep scan script"
|
log_message "User chose to keep scan script"
|
||||||
echo ""
|
|
||||||
echo "Scan script and results preserved at: $SCAN_DIR"
|
|
||||||
echo ""
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Scan script and results preserved at: $SCAN_DIR"
|
||||||
|
echo ""
|
||||||
|
|
||||||
echo "You can:"
|
echo "You can:"
|
||||||
echo " • Review logs: ls $LOG_DIR"
|
echo " • Review logs: ls $LOG_DIR"
|
||||||
echo " • View summary: cat $SUMMARY_FILE"
|
echo " • View summary: cat $SUMMARY_FILE"
|
||||||
@@ -2172,41 +2171,49 @@ show_scan_menu() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo -e "${CYAN}Create New Scan:${NC}"
|
echo -e "${CYAN}Create New Scan:${NC}"
|
||||||
echo " 1. Scan entire server (ClamAV, Maldet, RKHunter)"
|
echo -e " ${CYAN}1.${NC} Scan entire server (ClamAV, Maldet, RKHunter)"
|
||||||
echo " 2. Scan all user accounts (All scanners - recommended)"
|
echo -e " ${CYAN}2.${NC} Scan all user accounts (All scanners - recommended)"
|
||||||
echo " 3. Scan specific user account (All scanners)"
|
echo -e " ${CYAN}3.${NC} Scan specific user account (All scanners)"
|
||||||
echo " 4. Scan specific domain (All scanners)"
|
echo -e " ${CYAN}4.${NC} Scan specific domain (All scanners)"
|
||||||
echo " 5. Scan custom path (All scanners)"
|
echo -e " ${CYAN}5.${NC} Scan custom path (All scanners)"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${CYAN}Monitor & Manage:${NC}"
|
echo -e "${CYAN}Monitor & Manage:${NC}"
|
||||||
echo " 6. Check scan status"
|
echo -e " ${CYAN}6.${NC} Check scan status"
|
||||||
echo " 7. View scan results"
|
echo -e " ${CYAN}7.${NC} View scan results"
|
||||||
echo " 8. Delete scan sessions"
|
echo -e " ${CYAN}8.${NC} Delete scan sessions"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${CYAN}Configuration:${NC}"
|
echo -e "${CYAN}Configuration:${NC}"
|
||||||
echo " 9. Install all scanners"
|
echo -e " ${CYAN}9.${NC} Install all scanners"
|
||||||
echo " 10. Scanner settings"
|
echo -e " ${CYAN}10.${NC} Scanner settings"
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " ${RED}0.${NC} Back"
|
echo -e " ${RED}0.${NC} Back"
|
||||||
echo ""
|
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
|
case $choice in
|
||||||
1) launch_standalone_scanner_menu "server" ;;
|
1) launch_standalone_scanner_menu "server"; break ;;
|
||||||
2) launch_standalone_scanner_menu "all_users" ;;
|
2) launch_standalone_scanner_menu "all_users"; break ;;
|
||||||
3) launch_standalone_scanner_menu "user" ;;
|
3) launch_standalone_scanner_menu "user"; break ;;
|
||||||
4) launch_standalone_scanner_menu "domain" ;;
|
4) launch_standalone_scanner_menu "domain"; break ;;
|
||||||
5) launch_standalone_scanner_menu "custom" ;;
|
5) launch_standalone_scanner_menu "custom"; break ;;
|
||||||
6) check_standalone_status ;;
|
6) check_standalone_status; break ;;
|
||||||
7) view_scan_results ;;
|
7) view_scan_results; break ;;
|
||||||
8) delete_standalone_sessions ;;
|
8) delete_standalone_sessions; break ;;
|
||||||
9) install_all_scanners ;;
|
9) install_all_scanners; break ;;
|
||||||
10) scanner_settings ;;
|
10) scanner_settings; break ;;
|
||||||
0) return 0 ;;
|
0) return 0 ;;
|
||||||
*) echo -e "${RED}Invalid option${NC}"; sleep 1 ;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# View scan results
|
# View scan results
|
||||||
|
|||||||
Reference in New Issue
Block a user