From eaf59fac4c42efe465c7d7448e6221c3e82d6141 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 20 Jan 2014 11:54:26 +1100 Subject: [PATCH] Bug 11575 - OPACBaseURL sometimes set by ENV variable and not system preference This patch changes how the OPACBaseURL parameter gets set in the subroutine get_template_and_user in Auth.pm. Currently, it's being set by the $ENV{'SERVER_NAME'} variable, which is typically filled by the URL that the user uses to access a page. While this works in many cases, this causes a problem when using a proxy server. The SERVER_NAME will instead be the domain of the proxy server (for more info, read the comments already on this bug on Bugzilla). There are ways to compensate for proxy servers. However, such a solution seems a bit convoluted... Elsewhere in Koha, we use the system preference OPACBaseURL, so I think it makes sense to use it here as well. I did leave the $ENV{'SERVER_NAME'} as a full back if OPACBaseURL isn't set, but that's it. _TEST PLAN_ Before applying: 1) Clear your OPACBaseURL preference 2) Perform a search in the OPAC 3) Click on or hover over the orange RSS icon 4) Note that the URL you used to access the site is the URL used for the RSS link 5) Add an OPACBaseURL that isn't the same as the actual OPAC URL 6) Note that the OPACBaseURL system preference has no effect here After applying the patch: 7) Refresh the page 8) Note that the URL you see now is actually the OPACBaseURL system preference that you set 9) Clear your OPACBaseURL system preference 10) Refresh your search page 11) Note that the URL has reverted back to the URL that you used to access the page --- C4/Auth.pm | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 44edf67..de00bad 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -387,6 +387,10 @@ sub get_template_and_user { } elsif (C4::Context->preference("SearchMyLibraryFirst") && C4::Context->userenv && C4::Context->userenv->{'branch'}) { $opac_name = C4::Context->userenv->{'branch'}; } + my $opac_base_url = C4::Context->preference("OPACBaseURL"); + if (!$opac_base_url){ + $opac_base_url = $ENV{'SERVER_NAME'} . ($ENV{'SERVER_PORT'} eq ($in->{'query'}->https() ? "443" : "80") ? '' : ":$ENV{'SERVER_PORT'}"); + } $template->param( opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"), AnonSuggestions => "" . C4::Context->preference("AnonSuggestions"), @@ -407,8 +411,7 @@ sub get_template_and_user { OPACMobileUserCSS => "". C4::Context->preference("OPACMobileUserCSS"), OPACViewOthersSuggestions => "" . C4::Context->preference("OPACViewOthersSuggestions"), OpacAuthorities => C4::Context->preference("OpacAuthorities"), - OPACBaseURL => ($in->{'query'}->https() ? "https://" : "http://") . $ENV{'SERVER_NAME'} . - ($ENV{'SERVER_PORT'} eq ($in->{'query'}->https() ? "443" : "80") ? '' : ":$ENV{'SERVER_PORT'}"), + OPACBaseURL => ($in->{'query'}->https() ? "https://" : "http://") . $opac_base_url, opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'}, opac_search_limit => $opac_search_limit, opac_limit_override => $opac_limit_override, -- 1.7.7.4