From 18f58123e8c83672ac97e16e5fe24876d0720947 Mon Sep 17 00:00:00 2001 From: Christoph Heiss Date: Fri, 20 Oct 2023 11:46:44 +0200 Subject: [PATCH] net: move hostname/fqdn regexes into common code Such that they can be re-used by other parts. No functional changes. Signed-off-by: Christoph Heiss --- Proxmox/Sys/Net.pm | 3 +++ proxinstall | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Proxmox/Sys/Net.pm b/Proxmox/Sys/Net.pm index ba368c1..f5a9885 100644 --- a/Proxmox/Sys/Net.pm +++ b/Proxmox/Sys/Net.pm @@ -6,6 +6,9 @@ use warnings; use base qw(Exporter); our @EXPORT_OK = qw(parse_ip_address parse_ip_mask); +our $HOSTNAME_RE = "(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)"; +our $FQDN_RE = "(?:${HOSTNAME_RE}\.)*${HOSTNAME_RE}"; + my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])"; my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)"; my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})"; diff --git a/proxinstall b/proxinstall index 11e537b..fef2870 100755 --- a/proxinstall +++ b/proxinstall @@ -444,8 +444,6 @@ sub create_ipconf_view { $text =~ s/^\s+//; $text =~ s/\s+$//; - my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)"; - # Debian does not support purely numeric hostnames if ($text && $text =~ /^[0-9]+(?:\.|$)/) { Proxmox::UI::message("Purely numeric hostnames are not allowed."); @@ -453,8 +451,11 @@ sub create_ipconf_view { return; } - if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ && - $text =~ m/^([^\.]+)\.(\S+)$/) { + if ($text + && $text =~ m/^${Proxmox::Sys::Net::FQDN_RE}$/ + && $text !~ m/.example.invalid$/ + && $text =~ m/^([^\.]+)\.(\S+)$/ + ) { Proxmox::Install::Config::set_hostname($1); Proxmox::Install::Config::set_domain($2); } else { -- 2.39.2