]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Reporter/Proxy.pm
added ws_ou for getting perm org
[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 NOT_FOUND 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         my $ws_ou = $cgi->cookie('ws_ou') || 1;
34
35         my $user = verify_login($auth_ses);
36         return Apache2::Const::NOT_FOUND unless ($user);
37
38         my $failures = OpenSRF::AppSession
39                 ->create('open-ils.actor')
40                 ->request('open-ils.actor.user.perm.check', $auth_ses, $user->id, $ws_ou, ['RUN_REPORTS'])
41                 ->gather(1);
42
43         return Apache2::Const::NOT_FOUND if (@$failures > 0);
44
45         # they're good, let 'em through
46         return Apache2::Const::DECLINED if (-e $apache->filename);
47
48         # oops, file not found
49         return Apache2::Const::NOT_FOUND;
50 }
51
52 # returns the user object if the session is valid, 0 otherwise
53 sub verify_login {
54         my $auth_token = shift;
55         return 0 unless $auth_token;
56
57         my $user = OpenSRF::AppSession
58                 ->create("open-ils.auth")
59                 ->request( "open-ils.auth.session.retrieve", $auth_token )
60                 ->gather(1);
61
62         if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
63                 return undef;
64         }
65
66         return $user if ref($user);
67         return undef;
68 }
69
70
71
72 1;