MM-5730 hostname update revised

This commit is contained in:
Mike Steinmetz
2020-04-28 16:17:52 +02:00
parent 203a7f5baa
commit 8ea525cbea

View File

@@ -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));
}