@@ -, +, @@ Web Services, set RequestProxyEnabled to 'yes' and enter a test URL such as: http://hyltebiblioteken.blogspot.se/feeds/posts/default and: http://bokbastisarna.blogspot.com/feeds/posts/default into RequestProxyURL. http://127.0.1.1/cgi-bin/koha/opac-proxy.pl?id=1 You should get the content of the first URL with 'id' = 1. With 'id' = 2 you should get the second URL. With 'id' = 3 you should get a 503 error. even for valid feed id's AND for invalid ones. --- opac/opac-proxy.pl | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 opac/opac-proxy.pl --- a/opac/opac-proxy.pl +++ a/opac/opac-proxy.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +# Copyright 2015 Halland County Library +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Koha; +use C4::Context; +use LWP::UserAgent; +use CGI qw( -utf8 ); + +# Basic DoS protection (see perldoc CGI) +$CGI::POST_MAX = 1024; +$CGI::DISABLE_UPLOADS = 1; + +# These should be moved to configuration +my $status_text = '503 Service Unavailable'; +my $src_valid = '127.0.0.1'; + +my $cgi = CGI->new; +my $id = $cgi->param('id') || 0; + +my @urls = split("\n", C4::Context->preference('RequestProxyURL')); + +if ( C4::Context->preference('RequestProxyEnabled') && + $cgi->request_method eq 'GET' && + ($id > 0 && $id <= scalar @urls)) { + + my $url = $urls[$id - 1]; + + my $agent = new LWP::UserAgent; + my $req = HTTP::Request->new('GET'); + $req->url($url); + my $resp = $agent->request($req); + + my $cgi = CGI->new; + + my $headers = $resp->headers; + + my @fields = $headers->header_field_names; + my %newheaders; + foreach my $field (@fields) { + $newheaders{ $field } = $headers->header($field); + } + + print $cgi->header(\%newheaders); + print $resp->content; + +} else { + print $cgi->header( + -type => 'text/html', + -status => $status_text), + $cgi->start_html, + $cgi->h1($status_text), + $cgi->end_html; +} --