1 package OpenILS::Reporter::Proxy;
2 use strict; use warnings;
6 use Apache2::Const -compile => qw(REDIRECT FORBIDDEN OK NOT_FOUND DECLINED :log);
7 use APR::Const -compile => qw(:error SUCCESS);
10 use Digest::MD5 qw/md5_hex/;
12 use OpenSRF::EX qw(:try);
16 # set the bootstrap config and template include directory when
17 # this module is loaded
27 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
33 my $auth_ses = $cgi->cookie('ses');
34 my $ws_ou = $cgi->cookie('ws_ou') || 1;
37 my $u = $cgi->param('user');
38 my $p = $cgi->param('passwd');
43 if ($url =~ /^http:/o) {
44 $url =~ s/^http:/https:/o;
45 print "Location: $url\n\n";
46 return Apache2::Const::OK;
49 print $cgi->header(-type=>'text/html', -expires=>'-1d');
53 <title>Report Output Login</title>
57 <table style='border-collapse: collapse;'>
59 <th colspan='2' align='center'><u>Please log in to view reports</u></th>
62 <th>Username or barcode:</th>
63 <td><input type="text" name="user"/></td>
67 <td><input type="password" name="passwd"/></td>
70 <input type="submit" value="Log in"/>
75 return Apache2::Const::OK;
78 $auth_ses = oils_login($u, $p);
82 -cookie=>$cgi->cookie(
85 -path=>'/',-expires=>'+1h'
88 return Apache2::Const::REDIRECT;
92 my $user = verify_login($auth_ses);
93 return Apache2::Const::FORBIDDEN unless ($user);
95 my $failures = OpenSRF::AppSession
96 ->create('open-ils.actor')
97 ->request('open-ils.actor.user.perm.check', $auth_ses, $user->id, $ws_ou, ['RUN_REPORTS'])
100 return Apache2::Const::FORBIDDEN if (@$failures > 0);
102 # they're good, let 'em through
103 return Apache2::Const::DECLINED if (-e $apache->filename);
105 # oops, file not found
106 return Apache2::Const::NOT_FOUND;
109 # returns the user object if the session is valid, 0 otherwise
111 my $auth_token = shift;
112 return undef unless $auth_token;
114 my $user = OpenSRF::AppSession
115 ->create("open-ils.auth")
116 ->request( "open-ils.auth.session.retrieve", $auth_token )
119 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
123 return $user if ref($user);
128 my( $username, $password, $type ) = @_;
131 my $nametype = 'username';
132 $nametype = 'barcode' if ($username =~ /^\d+$/o);
134 my $seed = OpenSRF::AppSession
135 ->create("open-ils.auth")
136 ->request( 'open-ils.auth.authenticate.init', $username )
139 return undef unless $seed;
141 my $response = OpenSRF::AppSession
142 ->create("open-ils.auth")
143 ->request( 'open-ils.auth.authenticate.complete',
144 { $nametype => $username,
145 password => md5_hex($seed . md5_hex($password)),
149 return undef unless $response;
151 return $response->{payload}->{authtoken};