[pve-devel] [PATCH installer 1/5] net: move hostname/fqdn regexes into common code

Christoph Heiss c.heiss at proxmox.com
Fri Oct 20 11:46:44 CEST 2023


Such that they can be re-used by other parts.
No functional changes.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 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 d5b2565..88f194f 100755
--- a/proxinstall
+++ b/proxinstall
@@ -429,8 +429,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.");
@@ -438,8 +436,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.42.0






More information about the pve-devel mailing list