From c2c8f83c491a38c2c428a9a2510030671f538b86 Mon Sep 17 00:00:00 2001 From: IDQDD Date: Thu, 23 Nov 2023 15:07:53 +0300 Subject: [PATCH] hostname validation added --- phpipam-hosts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/phpipam-hosts b/phpipam-hosts index 5c2ef2c..6603e4f 100755 --- a/phpipam-hosts +++ b/phpipam-hosts @@ -274,6 +274,16 @@ def listSubnets(): sys.exit(0) +# check if hostname is a valid DNS hostname (DNS names requirements RFC952+RFC1123) +def is_valid_hostname(hostname): + if len(hostname) > 255: + return False + if hostname[-1] == ".": + hostname = hostname[:-1] # strip exactly one dot from the right, if present + allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?