From b0c26867fe4bbbe87ab6aec9a3420fed1a0378d8 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 6 Nov 2022 20:45:51 -0800 Subject: [PATCH] Expand hostname from /etc/hosts if needed --- web-lib-funcs.pl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 0725e146c..adfecd288 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -4086,6 +4086,23 @@ if (!$main::get_system_hostname[$m]) { $fromfile .= ".".$dname if ($dname); } + # Append domain name from /etc/hosts if needed + if ($fromfile && $fromfile !~ /\./) { + my $lref = &read_file_lines("/etc/hosts", 1); + HOST: foreach my $l (@$lref) { + next if ($l =~ /^\s*#/); + my ($ip, @names) = split(/\s+/, $l); + next if (&indexof($fromfile, @names) < 0); + foreach my $n (@names) { + if ($n =~ /^\Q$fromfile\E\.(.*)/) { + $dname = $2; + last HOST; + } + } + } + $fromfile .= ".".$dname if ($dname); + } + # If we found a hostname in a file, use it if ($fromfile && ($m || $fromfile =~ /\./)) { if ($m) {