Add reverse_proxy option which hard-codes cgiurl in CGI output

This solves several people's issues with the CGI trying to be
too clever when IkiWiki is placed behind a reverse-proxy.
master
Simon McVittie 2014-10-05 23:06:48 +01:00
parent d712389ae3
commit 3b8da667cc
3 changed files with 16 additions and 8 deletions

View File

@ -108,6 +108,14 @@ sub getsetup () {
safe => 1,
rebuild => 1,
},
reverse_proxy => {
type => "boolean",
default => 0,
description => "do not adjust cgiurl if CGI is accessed via different URL",
advanced => 0,
safe => 1,
rebuild => 0, # only affects CGI requests
},
cgi_wrapper => {
type => "string",
default => '',

View File

@ -59,7 +59,7 @@ sub cgitemplate ($$$;@) {
my $template=template("page.tmpl");
my $topurl = $config{url};
if (defined $cgi && ! $config{w3mmode}) {
if (defined $cgi && ! $config{w3mmode} && ! $config{reverse_proxy}) {
$topurl = $cgi->url;
}
@ -93,7 +93,13 @@ sub cgitemplate ($$$;@) {
sub redirect ($$) {
my $q=shift;
eval q{use URI};
my $url=URI->new(urlabs(shift, $q->url));
my $topurl;
if (defined $q && ! $config{w3mmode} && ! $config{reverse_proxy}) {
$topurl = $q->url;
}
my $url=URI->new(urlabs(shift, $topurl));
if (! $config{w3mmode}) {
print $q->redirect($url);
}

View File

@ -571,11 +571,8 @@ run(["./t/tmp/ikiwiki.cgi"], \undef, \$content, init => sub {
%bits = parse_cgi_content($content);
like($bits{tophref}, qr{^(?:/wiki|\.)/$});
like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$});
TODO: {
local $TODO = "reverse-proxy support needed";
is($bits{basehref}, "https://example.com/wiki/");
like($bits{stylehref}, qr{^(?:(?:https:)?//example.com)?/wiki/style.css$});
}
# previewing a page
$in = 'do=edit&page=a/b/c&Preview';
@ -589,10 +586,7 @@ run(["./t/tmp/ikiwiki.cgi"], \$in, \$content, init => sub {
%bits = parse_cgi_content($content);
like($bits{tophref}, qr{^(?:/wiki|\.\./\.\./\.\.)/$});
like($bits{cgihref}, qr{^(?:(?:https:)?//example.com)?/cgi-bin/ikiwiki.cgi$});
TODO: {
local $TODO = "reverse-proxy support needed";
is($bits{basehref}, "https://example.com/wiki/a/b/c/");
like($bits{stylehref}, qr{^(?:(?:https:)?//example.com)?/wiki/style.css$});
}
done_testing;