From 8ea525cbeaa454177da932239eb3c39e4ddd2113 Mon Sep 17 00:00:00 2001 From: Mike Steinmetz Date: Tue, 28 Apr 2020 16:17:52 +0200 Subject: [PATCH 1/2] MM-5730 hostname update revised --- net/save_dns.cgi | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/net/save_dns.cgi b/net/save_dns.cgi index c23743e14..fb017c4c1 100755 --- a/net/save_dns.cgi +++ b/net/save_dns.cgi @@ -6,11 +6,17 @@ require './net-lib.pl'; $access{'dns'} == 2 || &error($text{'dns_ecannot'}); &error_setup($text{'dns_err'}); &ReadParse(); -$old_hostname = &get_system_hostname(); +$old_fqdn = &get_system_hostname(); # Fully-Qualified Domain Name +$old_pqdn = &get_system_hostname(1); # Partially Qualified Domain Name (short name) +$old_hostname = &get_hostname(); -$in{'hostname'} =~ /^[A-z0-9\.\-]+$/ || +$in{'hostname'} =~ /^[A-Za-z0-9\.\-]+$/ || &error(&text('dns_ehost', &html_escape($in{'hostname'}))); $dns = { }; + +$new_pqdn = $in{'hostname'}; +$new_pqdn =~ s/\..*$//; + for($i=0; defined($ns = $in{"nameserver_$i"}); $i++) { $ns = $in{"nameserver_$i"}; $ns =~ s/^\s+//; $ns =~ s/\s+$//; @@ -43,8 +49,9 @@ if ($in{'name0'}) { if (!$in{'domain_def'}) { @dlist = split(/\s+/, $in{'domain'}); foreach $d (@dlist) { - $d =~ /^[A-z0-9\.\-]+$/ || + $d =~ /^[A-Za-z0-9\.\-]+$/ || &error(&text('dns_edomain', &html_escape($d))); + $new_fqdn = "$new_pqdn.$d" if !$new_fqdn; push(@{$dns->{'domain'}}, $d); } @dlist || &error($text{'dns_esearch'}); @@ -53,8 +60,8 @@ if (!$in{'domain_def'}) { &save_dns_config($dns); &save_hostname($in{'hostname'}); -if ($in{'hosts'} && $in{'hostname'} ne $old_hostname) { - # Update hostname in /etc/hosts too +if ($in{'hosts'} && ($in{'hostname'} ne $old_hostname || $new_fqdn ne $old_fqdn)) { + # Update hostname/fqdn/pqdn in /etc/hosts too @hosts = &list_hosts(); foreach $h (@hosts) { local $found = 0; @@ -63,6 +70,14 @@ if ($in{'hosts'} && $in{'hostname'} ne $old_hostname) { $n = $in{'hostname'}; $found++; } + elsif (lc($n) eq lc($old_fqdn) && $new_fqdn) { + $n = $new_fqdn; + $found++; + } + elsif (lc($n) eq lc($old_pqdn)) { + $n = $new_pqdn; + $found++; + } } &modify_host($h) if ($found); } @@ -76,6 +91,14 @@ if ($in{'hosts'} && $in{'hostname'} ne $old_hostname) { $n = $in{'hostname'}; $found++; } + elsif (lc($n) eq lc($old_fqdn) && $new_fqdn) { + $n = $new_fqdn; + $found++; + } + elsif (lc($n) eq lc($old_pqdn)) { + $n = $new_pqdn; + $found++; + } } &modify_ipnode($h) if ($found); } @@ -92,13 +115,9 @@ if (&foreign_installed("postfix") && $in{'hostname'} ne $old_hostname) { &postfix::set_current_value("mydestination", join(", ", @mydests)); } - $old_shorthostname = $old_hostname; - $old_shorthostname =~ s/\..*$//; - $shorthostname = $in{'hostname'}; - $shorthostname =~ s/\..*$//; - $idx = &indexoflc($old_shorthostname, @mydests); + $idx = &indexoflc($old_pqdn, @mydests); if ($idx >= 0) { - $mydests[$idx] = $shorthostname; + $mydests[$idx] = $new_pqdn; &postfix::set_current_value("mydestination", join(", ", @mydests)); } From cf1965834cf94d6822af818c070e6cbb054490ce Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 3 May 2020 15:00:36 -0700 Subject: [PATCH 2/2] Don't append domain name if none was found https://virtualmin.com/node/68961 --- web-lib-funcs.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 1d36805f0..840f3ff77 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -3846,7 +3846,7 @@ if (!$main::get_system_hostname[$m]) { last; } } - $fromfile .= ".".$dname; + $fromfile .= ".".$dname if ($dname); } # If we found a hostname in a file, use it