|
Lines 1-113
Link Here
|
| 1 |
#!/usr/bin/perl |
|
|
| 2 |
use Plack::Builder; |
| 3 |
use Plack::App::CGIBin; |
| 4 |
use lib qw( ./lib ); |
| 5 |
use Plack::Middleware::Debug; |
| 6 |
use Plack::App::Directory; |
| 7 |
|
| 8 |
#BZ 16357, add timestamps to warnings |
| 9 |
use Log::Log4perl qw(:easy); |
| 10 |
Log::Log4perl->easy_init({ level => $WARN, utf8 => 1 }); |
| 11 |
my $logger = Log::Log4perl->get_logger(); # use the default logger style |
| 12 |
$SIG{__WARN__} = sub { |
| 13 |
my $message = shift; |
| 14 |
$logger->warn($message); |
| 15 |
}; |
| 16 |
|
| 17 |
use CGI qw(-utf8 ); # we will lose -utf8 under plack |
| 18 |
{ |
| 19 |
no warnings 'redefine'; |
| 20 |
my $old_new = \&CGI::new; |
| 21 |
*CGI::new = sub { |
| 22 |
my $q = $old_new->( @_ ); |
| 23 |
$CGI::PARAM_UTF8 = 1; |
| 24 |
Koha::Caches->flush_L1_caches(); |
| 25 |
Koha::Cache::Memory::Lite->flush(); |
| 26 |
return $q; |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
BEGIN { |
| 31 |
|
| 32 |
# override configuration from startup script below: |
| 33 |
# (requires --reload option) |
| 34 |
|
| 35 |
$ENV{PLACK_DEBUG} = 1; # toggle debugging |
| 36 |
|
| 37 |
# memcache change requires restart |
| 38 |
$ENV{MEMCACHED_SERVERS} = "localhost:11211"; |
| 39 |
#$ENV{MEMCACHED_DEBUG} = 0; |
| 40 |
|
| 41 |
$ENV{PROFILE_PER_PAGE} = 1; # reset persistent and profile counters after each page, like CGI |
| 42 |
#$ENV{INTRANET} = 1; # usually passed from script |
| 43 |
|
| 44 |
#$ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=null;cache=DBI::Util::CacheMemory' |
| 45 |
|
| 46 |
} # BEGIN |
| 47 |
|
| 48 |
use C4::Context; |
| 49 |
use C4::Languages; |
| 50 |
use C4::Members; |
| 51 |
use C4::Boolean; |
| 52 |
use C4::Letters; |
| 53 |
use C4::Koha; |
| 54 |
use C4::XSLT; |
| 55 |
use Koha::DateUtils; |
| 56 |
use Koha::Caches; |
| 57 |
use Koha::Cache::Memory::Lite; |
| 58 |
use Koha::Patron::Categories; |
| 59 |
|
| 60 |
=for preload |
| 61 |
use C4::Tags; # FIXME |
| 62 |
=cut |
| 63 |
|
| 64 |
use Devel::Size 0.77; # 0.71 doesn't work for Koha |
| 65 |
my $watch_capture_regex = '(C4|Koha)'; |
| 66 |
|
| 67 |
sub watch_for_size { |
| 68 |
my @watch = |
| 69 |
map { s/^.*$watch_capture_regex/$1/; s/\//::/g; s/\.pm$//; $_ } # fix paths |
| 70 |
grep { /$watch_capture_regex/ } |
| 71 |
keys %INC |
| 72 |
; |
| 73 |
warn "# watch_for_size ",join(' ',@watch); |
| 74 |
return @watch; |
| 75 |
}; |
| 76 |
|
| 77 |
my $CGI_ROOT = $ENV{INTRANET} ? $ENV{INTRANETDIR} : $ENV{OPACDIR}; |
| 78 |
warn "# using Koha ", $ENV{INTRANET} ? 'intranet' : 'OPAC', " CGI from $CGI_ROOT\n"; |
| 79 |
my $app=Plack::App::CGIBin->new(root => $CGI_ROOT)->to_app; |
| 80 |
my $home = sub { |
| 81 |
return [ 302, [ Location => '/cgi-bin/koha/' . ( $ENV{INTRANET} ? 'mainpage.pl' : 'opac-main.pl' ) ] ]; |
| 82 |
}; |
| 83 |
|
| 84 |
builder { |
| 85 |
|
| 86 |
# please don't use plugins which are under enable_if $ENV{PLACK_DEBUG} in production! |
| 87 |
# they are known to leek memory |
| 88 |
enable_if { $ENV{PLACK_DEBUG} } 'Debug', panels => [ |
| 89 |
qw(Environment Response Timer Memory), |
| 90 |
# optional plugins (uncomment to enable) are sorted according to performance implact |
| 91 |
# [ 'Devel::Size', for => \&watch_for_size ], # https://github.com/dpavlin/p5-plack-devel-debug-devel-size |
| 92 |
# [ 'DBIProfile', profile => 2 ], |
| 93 |
# [ 'DBITrace', level => 1 ], # a LOT of fine-graded SQL trace |
| 94 |
# [ 'Profiler::NYTProf', exclude => [qw(.*\.css .*\.png .*\.ico .*\.js .*\.gif)] ], |
| 95 |
]; |
| 96 |
|
| 97 |
# don't enable this plugin in production, since stack traces reveal too much information |
| 98 |
# about system to potential attackers! |
| 99 |
enable_if { $ENV{PLACK_DEBUG} } 'StackTrace'; |
| 100 |
|
| 101 |
# this enables plackup or starman to serve static files and provide working plack |
| 102 |
# setup without need for front-end web server to serve static files |
| 103 |
enable_if { $ENV{INTRANETDIR} } "Plack::Middleware::Static", |
| 104 |
path => qr{^/(intranet|opac)-tmpl/}, |
| 105 |
root => "$ENV{INTRANETDIR}/koha-tmpl/"; |
| 106 |
|
| 107 |
# + is required so Plack doesn't try to prefix Plack::Middleware:: |
| 108 |
enable "+Koha::Middleware::SetEnv"; |
| 109 |
|
| 110 |
mount "/cgi-bin/koha" => $app; |
| 111 |
mount "/" => $home; |
| 112 |
|
| 113 |
}; |