From ba9334250e972b7e5dc0fed144ac948488668bb8 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 18 Dec 2020 15:21:34 -0800 Subject: [PATCH] Add param to force a hostname --- package-updates/update.pl | 5 +---- web-lib-funcs.pl | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package-updates/update.pl b/package-updates/update.pl index 428fecd87..ff4750f4f 100755 --- a/package-updates/update.pl +++ b/package-updates/update.pl @@ -45,10 +45,7 @@ foreach $t (@todo) { if ($tellcount) { # Add link to Webmin - &get_miniserv_config(\%miniserv); - $proto = $miniserv{'ssl'} ? 'https' : 'http'; - $port = $miniserv{'port'}; - $url = $proto."://".&get_system_hostname().":".$port."/$module_name/"; + $url = &get_webmin_email_url($module_name); $body .= "Updates can be installed at $url\n\n"; } diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 77308adb3..580073db8 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -11207,14 +11207,14 @@ $referer =~ s/\/\//\//g; return $referer; } -=head2 get_webmin_email_url([module], [cgi], [force-default]) +=head2 get_webmin_email_url([module], [cgi], [force-default], [force-host]) Returns the base URL for accessing this Webmin system, for use in URLs. =cut sub get_webmin_email_url { -my ($mod, $cgi, $def) = @_; +my ($mod, $cgi, $def, $forcehost) = @_; # Work out the base URL my $url; @@ -11226,7 +11226,7 @@ else { &get_miniserv_config(\%miniserv); my $proto = $miniserv{'ssl'} ? 'https' : 'http'; my $port = $miniserv{'port'}; - my $host = &get_system_hostname(); + my $host = $forcehost || &get_system_hostname(); my $defport = $proto eq 'https' ? 443 : 80; $url = $proto."://".$host.($port == $defport ? "" : ":".$port); $url .= $gconfig{'webprefix'} if ($gconfig{'webprefix'}); @@ -11234,8 +11234,15 @@ else { # Append module if needed $url =~ s/\/$//; -$url .= "/".$mod if ($mod); -$url .= "/".$cgi if ($cgi); +if ($mod && $cgi) { + $url .= "/".$mod."/".$cgi; + } +elsif ($mod) { + $url .= "/".$mod."/"; + } +elsif ($cgi) { + $url .= "/".$cgi; + } return $url; }