extended input validation

This commit is contained in:
2025-11-03 09:40:49 +01:00
parent bc06a2a279
commit fe9ea628d8

View File

@@ -91,7 +91,7 @@ while getopts ":n:p:m:a:h" option; do
done
#
# Validate hostname and DB password
# Parse and validate input
#
if [[ -z "$hostname" || -z "$dbpass" ]]; then
usage
@@ -115,14 +115,14 @@ if [[ "$hostname" =~ [[:space:]/_] ]]; then
exit 1
fi
# RFC 1123 validation
# 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: zabbix.example.com\n\n"
exit 1
fi
# DB password sanity check
# Check for spaces in DB credentials
if [[ "$dbpass" =~ [[:space:]] ]]; then
printf "\nERROR: Database password cannot contain spaces.\n\n"
exit 1