Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 49 lines (38 sloc) 1.521 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#!/usr/bin/env perl

use Koha;
use Plack::App::CGIBin;
use Plack::Builder;
use Koha::Plack::Util;

my $root = $ENV{KOHA_BASE} // '.';
my $app = Plack::App::CGIBin->new(root => $root)->to_app;

sub is_staff {
    my $hostname = Koha::Plack::Util::GetCanonicalHostname(shift);
    if ($ENV{KOHA_STAFF}) { return 1 } # for VPN with only IP
    return $hostname =~ /-staff\./;
}

use Koha::Squatting::Reserve 'On::PSGI';
use Koha::Squatting::Z3950 'On::PSGI';
Koha::Squatting::Reserve->init;
Koha::Squatting::Z3950->init;


builder {
    enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' }
        'Plack::Middleware::ReverseProxy';

    enable 'Deflater';
    enable 'HTTPExceptions';
    enable 'MethodOverride';

    enable 'Static', path => qr{^/opac-tmpl/}, root => "$root/koha-tmpl/";
    enable 'Static', path => qr{^/intranet-tmpl/}, root => "$root/koha-tmpl/";

    enable 'Status', path => qr{/C4/|/Koha/|/misc/|/t/|/xt/|/etc/}, status => 404;
    enable 'Rewrite', rules => sub {
        my $env = shift;
        return 302 if (is_staff($env) && s{^/$}{/cgi-bin/koha/mainpage.pl});
        return 302 if (!is_staff($env) && s{^/$}{/cgi-bin/koha/opac-main.pl});
        if (!is_staff($env)) { s{^/cgi-bin/koha/}{/cgi-bin/koha/opac/}}
        return;
    };

    enable 'Header', unset => ['Status'];
    enable '+Koha::Plack::Localize';

    mount '/reserves/' => sub {Koha::Squatting::Reserve->psgi(shift)};
    mount '/z3950/' => sub {Koha::Squatting::Z3950->psgi(shift)};
    mount '/cgi-bin/koha/' => $app;
};
Something went wrong with that request. Please try again.