extended input validation

This commit is contained in:
2025-11-03 12:05:29 +01:00
parent a96245cf2b
commit bfd2d79b0a

View File

@@ -60,15 +60,6 @@ usage() {
printf -- " -h | -help | --help Show this help screen\n\n"
}
#
# Function inputcheck
#
inputcheck () {
[[ -z "$hostname" ]] && { usage; echo "ERROR: DOMAIN CANNOT BE EMPTY!"; exit 1; }
[[ "$hostname" =~ [[:space:]/] ]] && { echo "ERROR: DOMAIN INVALID (no spaces or slashes allowed)"; exit 1; }
[[ -z "$dbpass" ]] && { usage; echo "ERROR: DATABASE PASSWORD CANNOT BE EMPTY!"; exit 1; }
}
#
# Let's go
#
@@ -97,9 +88,42 @@ while getopts "n:p:m:a:h" option; do
done
#
# Check if input conditions are met
# Validate hostname and database password
#
inputcheck "$hostname" "$dbpass"
if [[ -z "$hostname" || -z "$dbpass" ]]; then
usage
printf "\nERROR: Both -n (domain) and -p (database password) are required.\n\n"
exit 1
fi
# Convert to lowercase (domains are case-insensitive)
hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]')
# Disallow leading hyphen
if [[ "$hostname" =~ ^- ]]; then
printf "\nERROR: Domain cannot start with a hyphen.\n"
printf "Example of valid input: git.example.com\n\n"
exit 1
fi
# Disallow spaces, slashes, underscores
if [[ "$hostname" =~ [[:space:]/_] ]]; then
printf "\nERROR: 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
printf "\nERROR: Invalid domain format.\n"
printf "Example of valid input: git.example.com\n\n"
exit 1
fi
# Check for spaces in DB credentials
if [[ "$dbpass" =~ [[:space:]] ]]; then
printf "\nERROR: Database password cannot contain spaces.\n\n"
exit 1
fi
#
# Check for the latest Gitea version