From a3b31e24d52c787b38014bbd7079988c73e09878 Mon Sep 17 00:00:00 2001 From: allan Date: Mon, 3 Nov 2025 17:05:54 +0100 Subject: [PATCH] extended input validation --- giteainstall | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/giteainstall b/giteainstall index 3ea987d..eae0643 100755 --- a/giteainstall +++ b/giteainstall @@ -119,6 +119,20 @@ if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then exit 1 fi +# Prevent accidental overwrite of existing Nginx config +if [[ -f "/etc/nginx/conf.d/${hostname}.conf" ]]; then + printf "\nERROR: A configuration file already exists for %s.\n" "$hostname" + printf "Refusing to overwrite existing site.\n\n" + exit 1 +fi + +# Check for existing references in other Nginx configs +hostcheck=$(grep -r --exclude="README.md" "$hostname" /etc/nginx/ 2>/dev/null || true) +if [[ -n "$hostcheck" ]]; then + printf "\nFound existing configuration mentioning %s — aborting to avoid collision.\n\n" "$hostname" + exit 1 +fi + # Check for spaces in DB credentials if [[ "$dbpass" =~ [[:space:]] ]]; then printf "\nERROR: Database password cannot contain spaces.\n\n"