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;
38 # push everyone to the secure site
39 if ($url =~ /^http:/o) {
40 $url =~ s/^http:/https:/o;
41 print "Location: $url\n\n";
42 return Apache2::Const::OK;
46 my $u = $cgi->param('user');
47 my $p = $cgi->param('passwd');
51 print $cgi->header(-type=>'text/html', -expires=>'-1d');
56 <title>Report Output Login</title>
62 <table style='border-collapse: collapse; border: 1px solid black;'>
64 <th colspan='2' align='center'><u>Please log in to view reports</u></th>
67 <th align="right">Username or barcode:</th>
68 <td><input type="text" name="user"/></td>
71 <th align="right">Password:</th>
72 <td><input type="password" name="passwd"/></td>
75 <input type="submit" value="Log in"/>
82 return Apache2::Const::OK;
85 $auth_ses = oils_login($u, $p);
89 -cookie=>$cgi->cookie(
92 -path=>'/',-expires=>'+1h'
95 return Apache2::Const::REDIRECT;
99 my $user = verify_login($auth_ses);
100 return Apache2::Const::FORBIDDEN unless ($user);
102 my $failures = OpenSRF::AppSession
103 ->create('open-ils.actor')
104 ->request('open-ils.actor.user.perm.check', $auth_ses, $user->id, $ws_ou, ['RUN_REPORTS'])
107 return Apache2::Const::FORBIDDEN if (@$failures > 0);
109 # they're good, let 'em through
110 return Apache2::Const::DECLINED if (-e $apache->filename);
112 # oops, file not found
113 return Apache2::Const::NOT_FOUND;
116 # returns the user object if the session is valid, 0 otherwise
118 my $auth_token = shift;
119 return undef unless $auth_token;
121 my $user = OpenSRF::AppSession
122 ->create("open-ils.auth")
123 ->request( "open-ils.auth.session.retrieve", $auth_token )
126 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
130 return $user if ref($user);
135 my( $username, $password, $type ) = @_;
138 my $nametype = 'username';
139 $nametype = 'barcode' if ($username =~ /^\d+$/o);
141 my $seed = OpenSRF::AppSession
142 ->create("open-ils.auth")
143 ->request( 'open-ils.auth.authenticate.init', $username )
146 return undef unless $seed;
148 my $response = OpenSRF::AppSession
149 ->create("open-ils.auth")
150 ->request( 'open-ils.auth.authenticate.complete',
151 { $nametype => $username,
152 password => md5_hex($seed . md5_hex($password)),
156 return undef unless $response;
158 return $response->{payload}->{authtoken};