extended input validation

This commit is contained in:
2025-11-03 09:08:22 +01:00
parent 635f73d052
commit 2775c36d7b

View File

@@ -41,15 +41,33 @@ usage () {
# #
# Parse and validate input # Parse and validate input
# #
if [[ $# -ne 1 ]]; then usage ; printf "ERROR: Exactly one argument (the domain) is required.\n\n" ; exit 1 ; fi if [[ $# -ne 1 ]]; then
usage
printf "ERROR: Exactly one argument (the domain ony).\n\n"
exit 1
fi
hostname="$1" ; hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') # Convert to lowercase (domains are case-insensitive)
hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
if [[ "$hostname" =~ [[:space:]/_] ]]; then printf "ERROR: Domain cannot contain spaces, slashes, or underscores.\n\n" ; exit 1 ; fi # Ensure domain is not empty
if [[ -z "$hostname" ]]; then
printf "ERROR: Domain cannot be empty.\n\n"
usage
exit 1
fi
# Disallow spaces, slashes, or underscores
if [[ "$hostname" =~ [[:space:]/_] ]]; then
printf "ERROR: Domain cannot contain spaces, slashes, or underscores.\n\n"
exit 1
fi
# Validate domain format (RFC 1123)
if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then
printf "ERROR: Invalid domain format.\n" printf "ERROR: Invalid domain format.\n"
printf "Example of valid input: wiki.example.com\n\n" ; exit 1 printf "Example of valid input: wiki.example.com\n\n"
exit 1
fi fi
# #
@@ -57,11 +75,6 @@ fi
# #
clear clear
#
# Check if input conditions are met
#
inputcheck "$hostname"
# #
# Ensure curl is available # Ensure curl is available
# #