From 2775c36d7b9ca70cd218135d7442f32a95edddf6 Mon Sep 17 00:00:00 2001 From: allan Date: Mon, 3 Nov 2025 09:08:22 +0100 Subject: [PATCH] extended input validation --- dokuwikiinstall | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/dokuwikiinstall b/dokuwikiinstall index a01273a..5e00733 100755 --- a/dokuwikiinstall +++ b/dokuwikiinstall @@ -41,15 +41,33 @@ usage () { # # 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 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 # @@ -57,11 +75,6 @@ fi # clear -# -# Check if input conditions are met -# -inputcheck "$hostname" - # # Ensure curl is available #