]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Reporter/Proxy.pm
simple auth proxy for the reporter -- we probably just need a generic one the figures...
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Reporter / Proxy.pm
1 package OpenILS::Reporter::Proxy;
2 use strict; use warnings;
3
4 use Apache2 ();
5 use Apache2::Log;
6 use Apache2::Const -compile => qw(OK BAD_REQUEST NOT_FOUNE DECLINED :log);
7 use APR::Const    -compile => qw(:error SUCCESS);
8 use CGI;
9 use Data::Dumper;
10
11 use OpenSRF::EX qw(:try);
12 use OpenSRF::System;
13
14
15 # set the bootstrap config and template include directory when 
16 # this module is loaded
17 my $bootstrap;
18
19 sub import {
20         my $self = shift;
21         $bootstrap = shift;
22 }
23
24
25 sub child_init {
26         OpenSRF::System->bootstrap_client( config_file => $bootstrap );
27 }
28
29 sub handler {
30         my $apache = shift;
31         my $cgi = new CGI;
32         my $auth_ses = $cgi->cookie('ses');
33
34         my $user = verify_user($auth_ses);
35         return Apache2::Const::BAD_REQUEST unless ($user);
36
37         my $failures = OpenSRF::AppSession
38                 ->create('open-ils.actor')
39                 ->request('open-ils.actor.user.perm.check', $token, $user->id, 1, ['RUN_REPORTS'])
40                 ->gather(1);
41
42         return Apache2::Const::BAD_REQUEST if (@$failures > 0);
43
44         # they're good, let 'em through
45         return Apache2::Const::DECLINED if (-e $apache->filename);
46
47         # oops, file not found
48         return Apache2::Const::NOT_FOUND;
49 }
50
51 # returns the user object if the session is valid, 0 otherwise
52 sub verify_login {
53         my $auth_token = shift;
54         return 0 unless $auth_token;
55
56         my $session = OpenSRF::AppSession
57                 ->create("open-ils.auth")
58                 ->request( "open-ils.auth.session.retrieve", $auth_token )
59                 ->gather(1);
60
61         if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
62                 return undef;
63         }
64
65         return $user if ref($user);
66         return undef;
67 }
68
69
70
71 1;