1 package OpenILS::WWW::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 $proxyhtml = $apache->dir_config('OILSProxyHTML');
33 my $title = $apache->dir_config('OILSProxyTitle');
34 my $desc = $apache->dir_config('OILSProxyDescription');
35 my $ltype = $apache->dir_config('OILSProxyLoginType');
36 my $perms = [ split ' ', $apache->dir_config('OILSProxyPermissions') ];
38 return Apache2::Const::NOT_FOUND unless ($title || $proxyhtml);
39 return Apache2::Const::NOT_FOUND unless (@$perms);
42 my $auth_ses = $cgi->cookie('ses') || $cgi->param('ses');
43 my $ws_ou = $cgi->cookie('ws_ou') || $cgi->param('ws_ou');
47 # push everyone to the secure site
48 if ($url =~ /^http:/o) {
49 $url =~ s/^http:/https:/o;
50 print "Location: $url\n\n";
51 return Apache2::Const::OK;
55 my $u = $cgi->param('user');
56 my $p = $cgi->param('passwd');
60 print $cgi->header(-type=>'text/html', -expires=>'-1d');
62 $proxyhtml = join '', <DATA>;
63 $proxyhtml =~ s/TITLE/$title/gso;
64 $proxyhtml =~ s/DESCRIPTION/$desc/gso;
66 # XXX template toolkit??
70 return Apache2::Const::OK;
73 $auth_ses = oils_login($u, $p, $ltype);
77 -cookie=>$cgi->cookie(
80 -path=>'/',-expires=>'+1h'
83 return Apache2::Const::REDIRECT;
87 my $user = verify_login($auth_ses);
88 return Apache2::Const::FORBIDDEN unless ($user);
90 $ws_ou ||= $user->home_ou;
92 warn "Checking perms " . join(',', @$perms) . " for user " . $user->id . " at location $ws_ou\n";
94 my $failures = OpenSRF::AppSession
95 ->create('open-ils.actor')
96 ->request('open-ils.actor.user.perm.check', $auth_ses, $user->id, $ws_ou, $perms)
99 return Apache2::Const::FORBIDDEN if (@$failures > 0);
101 # they're good, let 'em through
102 return Apache2::Const::DECLINED;
105 # returns the user object if the session is valid, 0 otherwise
107 my $auth_token = shift;
108 return undef unless $auth_token;
110 my $user = OpenSRF::AppSession
111 ->create("open-ils.auth")
112 ->request( "open-ils.auth.session.retrieve", $auth_token )
115 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
119 return $user if ref($user);
124 my( $username, $password, $type ) = @_;
127 my $nametype = 'username';
128 $nametype = 'barcode' if ($username =~ /^\d+$/o);
130 my $seed = OpenSRF::AppSession
131 ->create("open-ils.auth")
132 ->request( 'open-ils.auth.authenticate.init', $username )
135 return undef unless $seed;
137 my $response = OpenSRF::AppSession
138 ->create("open-ils.auth")
139 ->request( 'open-ils.auth.authenticate.complete',
140 { $nametype => $username,
141 password => md5_hex($seed . md5_hex($password)),
145 return undef unless $response;
147 return $response->{payload}->{authtoken};
163 <table style='border-collapse: collapse; border: 1px solid black;'>
165 <th colspan='2' align='center'><u>DESCRIPTION</u></th>
168 <th align="right">Username or barcode:</th>
169 <td><input type="text" name="user"/></td>
172 <th align="right">Password:</th>
173 <td><input type="password" name="passwd"/></td>
176 <input type="submit" value="Log in"/>