URL for use in emails should use HTTP hostname if available

https://forum.virtualmin.com/t/webmin-virtualmin-password-recovery/132914/82
This commit is contained in:
Jamie Cameron
2025-07-17 01:46:46 -07:00
parent cd51f76062
commit f5305eb065

View File

@ -13106,9 +13106,23 @@ my ($mod, $cgi, $def, $forcehost) = @_;
# Work out the base URL
my $url;
if (!$def && $gconfig{'webmin_email_url'}) {
# From a config option
$url = $gconfig{'webmin_email_url'};
}
elsif ($ENV{'HTTP_HOST'}) {
# From this HTTP request
my $host = $ENV{'HTTP_HOST'};
my $port = $ENV{'SERVER_PORT'} || 80;
if ($host =~ s/:(\d+)$//) {
$port = $1;
}
my $proto = lc($ENV{'HTTPS'}) eq 'on' ? 'https' : 'http';
my $defport = $proto eq 'https' ? 443 : 80;
$url = $proto."://".$host.($port == $defport ? "" : ":".$port);
$url .= $gconfig{'webprefix'} if ($gconfig{'webprefix'});
}
else {
# Work out from miniserv config
my %miniserv;
&get_miniserv_config(\%miniserv);
my $proto = $miniserv{'ssl'} ? 'https' : 'http';