Skip to content

Commit

Permalink
Fix redirects when using Servers Index module
Browse files Browse the repository at this point in the history
This fix requires associated patch webmin/webmin@7dfa97c
  • Loading branch information
Ilia Rostovtsev committed Dec 20, 2017
1 parent f2907f6 commit e1f0db9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
28 changes: 24 additions & 4 deletions authentic-init.pm
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ sub init_vars
our $t_uri___i;
our $t_uri____i;

my ($server_prefix) = parse_servers_path();
our $global_prefix = ($server_prefix ? $server_prefix : $gconfig{'webprefix'});

our $xnav = "xnavigation=1";

our %gaccess = &get_module_acl();
Expand Down Expand Up @@ -927,8 +930,8 @@ sub theme_git_version
sub theme_version
{
my ($switch) = @_;
my $sh__ln__p___version = '19.03';
my $sh__ln__c___version = '19.04';
my $sh__ln__p___version = '19.04';
my $sh__ln__c___version = '19.05';
my $sh__ln__g___version = theme_git_version('uncond');
((!$switch && $sh__ln__g___version) &&
($sh__ln__c___version = $sh__ln__g___version, ($sh__ln__c___version =~ s/\.|-|git//ig)));
Expand Down Expand Up @@ -972,7 +975,7 @@ sub theme_post_update
sub header_html_data
{
my ($module, $skip, @args) = @_;
return 'data-hostname="' .
return 'data-host="' . get_env('http_host') . '" data-hostname="' .
get_display_hostname() . '" data-title-initial="' . $args[0] . '" data-debug="' . theme_mode() . '" data-session="' .
($remote_user ? '1' : '0') . '" data-script-name="' . ($module ? "/$module/" : get_env('script_name')) .
'"' . ($skip ? '' : ' data-background-style="' . (theme_night_mode() ? 'nightRider' : 'gainsboro') . '"') .
Expand All @@ -990,7 +993,7 @@ sub header_html_data
dashboard_switch() . '" data-language="' . get_current_user_language() . '" data-language-full="' .
get_current_user_language(1) . '" data-charset="' . get_charset() . '" data-notice="' . theme_post_update() .
'" data-redirect="' . get_tmp_var('redirected') . '" data-initial-wizard="' . get_initial_wizard() .
'" data-webprefix="' . $gconfig{'webprefix'} . '" data-current-product="' . get_product_name() . '" data-module="' .
'" data-webprefix="' . $global_prefix . '" data-current-product="' . get_product_name() . '" data-module="' .
($module ? "$module" : get_module_name()) . '" data-uri="' . ($module ? "/$module/" : get_env('request_uri')) .
'" data-progress="' . ($__settings{'settings_hide_top_loader'} ne 'true' ? '1' : '0') .
'" data-product="' . get_product_name() . '" data-access-level="' . $get_user_level . '"';
Expand Down Expand Up @@ -1064,6 +1067,23 @@ sub get_tmp_var
return $tmp_var{$key};
}

sub parse_servers_path
{
my ($parent) = $ENV{'HTTP_WEBMIN_PATH'};

if ($parent) {
my ($parent_link) = $parent =~ /\/(\d+)\//;
my $parent_split = '/servers/link.cgi/';
my @parent_host = split(/\Q$parent_split/, $parent);
my $parent_prefix = $gconfig{'webprefix'} . $parent_split . $parent_link;

return ($parent_prefix, $parent, $parent_link, $parent_host[0]);

} else {
return (undef, undef, undef, undef);
}
}

sub get_user_home
{
my @my_user_info = $remote_user ? getpwnam($remote_user) : getpwuid($<);
Expand Down
11 changes: 8 additions & 3 deletions authentic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1041,12 +1041,12 @@ sub theme_ui_radio_table
sub theme_redirect
{
use File::Basename;
my ($link, $protocol, $proxy, $nonproxy, $dirname, $prefix) = (
my ($link, $protocol, $proxy, $nonproxy, $dirname, $prefix, $port) = (
$_[1],
(get_env('https') ? 'https://' : 'http://'),
get_env('http_x_forwarded_host'),
get_env('http_host'), (!get_env('http_referer') || dirname(get_env('http_referer'))),
$gconfig{'webprefix'});
$gconfig{'webprefix'}, get_env('server_port'));

my $redirect;
if (!$proxy || $link =~ /\Q$nonproxy/) {
Expand All @@ -1056,13 +1056,18 @@ sub theme_redirect
}

my $location = replace(($protocol . $redirect), undef, $_[1]);
my $location_use = (($location && $location ne '/' && $location !~ /\Q$xnav/ && $link !~ /fetch.cgi/ && !get_env('http_webmin_servers')) ? 1 : 0);
my $location_use = (($location && $location ne '/' && $location !~ /\Q$xnav/ && $link !~ /fetch.cgi/) ? 1 : 0);

if ($location_use) {
if ($gconfig{'webprefixnoredir'} && $dirname ne ($protocol . $redirect . $prefix) && $location !~ /:\/\//) {
$location = ($prefix . $location);
}

my ($parent_prefix, $parent, $parent_link, $parent_host) = parse_servers_path();
if ($parent) {
$location = replace((':' . $port), $parent_host . "/servers/link.cgi/$parent_link", $location);
}

set_tmp_var('redirected', $location);
print "Location: $location\n\n";
} else {
Expand Down
2 changes: 1 addition & 1 deletion unauthenticated/css/bundle.min.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions unauthenticated/js/bundle.min.js

Large diffs are not rendered by default.

0 comments on commit e1f0db9

Please sign in to comment.