1 package OpenILS::Reporter::Proxy;
2 use strict; use warnings;
5 use Apache2::Const -compile => qw(REDIRECT FORBIDDEN OK NOT_FOUND DECLINED :log);
6 use APR::Const -compile => qw(:error SUCCESS);
9 use Digest::MD5 qw/md5_hex/;
11 use OpenSRF::EX qw(:try);
15 # set the bootstrap config and template include directory when
16 # this module is loaded
26 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
32 my $auth_ses = $cgi->cookie('ses');
33 my $ws_ou = $cgi->cookie('ws_ou') || 1;
37 # push everyone to the secure site
38 if ($url =~ /^http:/o) {
39 $url =~ s/^http:/https:/o;
40 print "Location: $url\n\n";
41 return Apache2::Const::OK;
45 my $u = $cgi->param('user');
46 my $p = $cgi->param('passwd');
50 print $cgi->header(-type=>'text/html', -expires=>'-1d');
55 <title>Report Output Login</title>
61 <table style='border-collapse: collapse; border: 1px solid black;'>
63 <th colspan='2' align='center'><u>Please log in to view reports</u></th>
66 <th align="right">Username or barcode:</th>
67 <td><input type="text" name="user"/></td>
70 <th align="right">Password:</th>
71 <td><input type="password" name="passwd"/></td>
74 <input type="submit" value="Log in"/>
81 return Apache2::Const::OK;
84 $auth_ses = oils_login($u, $p);
88 -cookie=>$cgi->cookie(
91 -path=>'/',-expires=>'+1h'
94 return Apache2::Const::REDIRECT;
98 my $user = verify_login($auth_ses);
99 return Apache2::Const::FORBIDDEN unless ($user);
101 my $failures = OpenSRF::AppSession
102 ->create('open-ils.actor')
103 ->request('open-ils.actor.user.perm.check', $auth_ses, $user->id, $ws_ou, ['VIEW_REPORT_OUTPUT'])
106 return Apache2::Const::FORBIDDEN if (@$failures > 0);
108 # they're good, let 'em through
109 return Apache2::Const::DECLINED if (-e $apache->filename);
111 # oops, file not found
112 return Apache2::Const::NOT_FOUND;
115 # returns the user object if the session is valid, 0 otherwise
117 my $auth_token = shift;
118 return undef unless $auth_token;
120 my $user = OpenSRF::AppSession
121 ->create("open-ils.auth")
122 ->request( "open-ils.auth.session.retrieve", $auth_token )
125 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
129 return $user if ref($user);
134 my( $username, $password, $type ) = @_;
137 my $nametype = 'username';
138 $nametype = 'barcode' if ($username =~ /^\d+$/o);
140 my $seed = OpenSRF::AppSession
141 ->create("open-ils.auth")
142 ->request( 'open-ils.auth.authenticate.init', $username )
145 return undef unless $seed;
147 my $response = OpenSRF::AppSession
148 ->create("open-ils.auth")
149 ->request( 'open-ils.auth.authenticate.complete',
150 { $nametype => $username,
151 password => md5_hex($seed . md5_hex($password)),
155 return undef unless $response;
157 return $response->{payload}->{authtoken};