extended input validation

This commit is contained in:
2025-11-03 12:59:07 +01:00
parent e9fb0df269
commit 7eee6a4ec7

View File

@@ -33,6 +33,7 @@ printf -- "sudo ./certbotinstall -p 1234AkkbdceewEFJK\n\n"
#
clear
#
# Check if no arguments were given
#
@@ -52,10 +53,17 @@ while [[ $# -gt 0 ]]; do
fi
apitoken="$1"
# Validate token at least 20 chars alphanum + - _
if [[ ! "$apitoken" =~ ^[A-Za-z0-9_-]{20,}$ ]]; then
echo "ERROR: API token format seems invalid."
echo "Cloudflare API tokens are usually long strings with letters, numbers, - and _."
#
# Validate Cloudflare API token format
#
if [[ "$apitoken" =~ [[:space:]] ]]; then
printf "\nERROR: API token cannot contain spaces or line breaks.\n\n"
exit 1
fi
if [[ ! "$apitoken" =~ ^[A-Za-z0-9_-]{20,120}$ ]]; then
printf "\nERROR: Invalid API token format.\n"
printf "Expected 20120 characters (AZ, az, 09, - or _).\n\n"
exit 1
fi