You've already forked wordpress-ubuntu
extended input validation
This commit is contained in:
@@ -65,17 +65,6 @@ usage() {
|
||||
printf -- " -h | -help | --help Show this help screen\n\n"
|
||||
}
|
||||
|
||||
#
|
||||
# Function inputcheck
|
||||
#
|
||||
inputcheck () {
|
||||
[[ -z "$hostname" ]] && { usage; echo ""; echo "Error! Hostname empty."; echo ""; exit 1; }
|
||||
[[ "$hostname" =~ [[:space:]/] ]] && { echo "ERROR: DOMAIN INVALID (no spaces or slashes allowed)"; exit 1; }
|
||||
[[ -z "$dbname" ]] && { usage; echo ""; echo "Error! Database name empty."; echo ""; exit 1; }
|
||||
[[ -z "$dbuser" ]] && { usage; echo ""; echo "Error! Database user empty."; echo ""; exit 1; }
|
||||
[[ -z "$dbpass" ]] && { usage; echo ""; echo "Error! Database password empty."; echo ""; exit 1; }
|
||||
}
|
||||
|
||||
#
|
||||
# Let's go
|
||||
#
|
||||
@@ -109,9 +98,43 @@ while getopts ":n:d:u:p:m:a:h" option; do
|
||||
done
|
||||
|
||||
#
|
||||
# Check if input conditions are met
|
||||
# Parse and validate input
|
||||
#
|
||||
inputcheck "$hostname" "$dbname" "$dbuser" "$dbpass"
|
||||
if [[ -z "$hostname" || -z "$dbname" || -z "$dbuser" || -z "$dbpass" ]]; then
|
||||
usage
|
||||
printf "\nERROR: Missing required arguments.\n"
|
||||
printf "Hostname (-n), Database name (-d), User (-u), and Password (-p) are mandatory.\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: wp.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: wp.example.com\n\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for spaces in DB credentials
|
||||
if [[ "$dbname" =~ [[:space:]] || "$dbuser" =~ [[:space:]] || "$dbpass" =~ [[:space:]] ]]; then
|
||||
printf "\nERROR: Database name, user, and password cannot contain spaces.\n\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#
|
||||
# Download, install, and configure the latest WordPress version
|
||||
|
||||
Reference in New Issue
Block a user