Standardize email-diagnostics.sh menu formatting and add input validation
IMPROVEMENTS: - Added input validation for check type (1-2) with retry loop - Added input validation for time period (1-5) with retry loop - Added email format validation (user@domain.com pattern) - Added domain format validation (example.com pattern) - Added color codes to menu options (${CYAN}1)${NC} format) - Improved error messages for invalid input VALIDATION DETAILS: - Check type: Only accepts 1 or 2, rejects invalid input with clear error - Time period: Only accepts 1-5, rejects invalid input with clear error - Email format: Validates user@domain.com pattern - Domain format: Validates domain.com pattern (alphanumeric, dots, hyphens) - All inputs with defaults continue to work seamlessly 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: ~60 (input validation + color codes) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,48 +27,97 @@ echo ""
|
|||||||
# Ask what to check
|
# Ask what to check
|
||||||
echo -e "${BOLD}What would you like to check?${NC}"
|
echo -e "${BOLD}What would you like to check?${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
echo " 1) Specific email address (e.g., user@example.com)"
|
echo -e " ${CYAN}1)${NC} Specific email address (e.g., user@example.com)"
|
||||||
echo " 2) Entire domain (e.g., example.com)"
|
echo -e " ${CYAN}2)${NC} Entire domain (e.g., example.com)"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# Validate check_type input
|
||||||
|
while true; do
|
||||||
read -p "Enter choice [1]: " check_type
|
read -p "Enter choice [1]: " check_type
|
||||||
check_type=${check_type:-1}
|
check_type=${check_type:-1}
|
||||||
|
|
||||||
|
if ! [[ "$check_type" =~ ^[1-2]$ ]]; then
|
||||||
|
print_error "Invalid choice. Please enter 1 or 2"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
|
|
||||||
# Get email/domain to check
|
# Get email/domain to check
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
if [ "$check_type" = "2" ]; then
|
if [ "$check_type" = "2" ]; then
|
||||||
|
# Domain input with validation
|
||||||
|
while true; do
|
||||||
read -p "Enter domain to check (e.g., example.com): " target
|
read -p "Enter domain to check (e.g., example.com): " target
|
||||||
search_pattern="@${target}"
|
|
||||||
check_label="domain $target"
|
# Validate domain format (basic check)
|
||||||
else
|
if [ -z "$target" ]; then
|
||||||
read -p "Enter email address to check: " target
|
print_error "Domain cannot be empty"
|
||||||
search_pattern="$target"
|
continue
|
||||||
check_label="email $target"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check for invalid characters (allow alphanumeric, dots, hyphens)
|
||||||
|
if ! [[ "$target" =~ ^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
|
||||||
|
print_error "Invalid domain format. Use format like: example.com"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
search_pattern="@${target}"
|
||||||
|
check_label="domain $target"
|
||||||
|
break
|
||||||
|
done
|
||||||
|
else
|
||||||
|
# Email address input with validation
|
||||||
|
while true; do
|
||||||
|
read -p "Enter email address to check: " target
|
||||||
|
|
||||||
|
# Validate email format (basic check)
|
||||||
if [ -z "$target" ]; then
|
if [ -z "$target" ]; then
|
||||||
print_error "No email/domain provided"
|
print_error "Email address cannot be empty"
|
||||||
exit 1
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for valid email format (user@domain.com)
|
||||||
|
if ! [[ "$target" =~ ^[a-zA-Z0-9._+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
|
||||||
|
print_error "Invalid email format. Use format like: user@example.com"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
search_pattern="$target"
|
||||||
|
check_label="email $target"
|
||||||
|
break
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Time period to check
|
# Time period to check
|
||||||
echo ""
|
echo ""
|
||||||
echo "Check logs from:"
|
echo "Check logs from:"
|
||||||
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 (recommended)"
|
echo -e " ${CYAN}3)${NC} Last 24 hours (recommended)"
|
||||||
echo " 4) Last 48 hours"
|
echo -e " ${CYAN}4)${NC} Last 48 hours"
|
||||||
echo " 5) Last week"
|
echo -e " ${CYAN}5)${NC} Last week"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# Validate time_choice input
|
||||||
|
while true; do
|
||||||
read -p "Enter choice [3]: " time_choice
|
read -p "Enter choice [3]: " time_choice
|
||||||
time_choice=${time_choice:-3}
|
time_choice=${time_choice:-3}
|
||||||
|
|
||||||
|
if ! [[ "$time_choice" =~ ^[1-5]$ ]]; then
|
||||||
|
print_error "Invalid choice. Please enter 1-5"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
done
|
||||||
|
|
||||||
case "$time_choice" in
|
case "$time_choice" in
|
||||||
1) hours=1 ;;
|
1) hours=1 ;;
|
||||||
2) hours=6 ;;
|
2) hours=6 ;;
|
||||||
3) hours=24 ;;
|
3) hours=24 ;;
|
||||||
4) hours=48 ;;
|
4) hours=48 ;;
|
||||||
5) hours=168 ;;
|
5) hours=168 ;;
|
||||||
*) hours=24 ;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user