View | Details | Raw Unified | Return to bug 14994
Collapse All | Expand All

(-)a/opac/opac-proxy.pl (-1 / +70 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2015 Halland County Library
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Koha;
22
use C4::Context;
23
use LWP::UserAgent;
24
use CGI  qw( -utf8 );
25
26
# Basic DoS protection (see perldoc CGI)
27
$CGI::POST_MAX = 1024;
28
$CGI::DISABLE_UPLOADS = 1;
29
30
# These should be moved to configuration
31
my $status_text = '503 Service Unavailable';
32
my $src_valid = '127.0.0.1';
33
34
my $cgi = CGI->new;
35
my $id = $cgi->param('id') || 0;
36
37
my @urls = split("\n", C4::Context->preference('RequestProxyURL'));
38
39
if ( C4::Context->preference('RequestProxyEnabled') &&
40
        $cgi->request_method eq 'GET' &&
41
        ($id > 0 && $id <= scalar @urls)) {
42
43
    my $url = $urls[$id - 1];
44
45
    my $agent = new LWP::UserAgent;
46
    my $req = HTTP::Request->new('GET');
47
    $req->url($url);
48
    my $resp = $agent->request($req);
49
50
    my $cgi = CGI->new;
51
52
    my $headers = $resp->headers;
53
54
    my @fields = $headers->header_field_names;
55
    my %newheaders;
56
    foreach my $field (@fields) {
57
        $newheaders{ $field } = $headers->header($field);
58
    }
59
60
    print $cgi->header(\%newheaders);
61
    print $resp->content;
62
63
} else {
64
    print $cgi->header(
65
            -type => 'text/html',
66
            -status => $status_text),
67
        $cgi->start_html,
68
        $cgi->h1($status_text),
69
        $cgi->end_html;
70
}

Return to bug 14994