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
28 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
34 my $proxyhtml = $apache->dir_config('OILSProxyHTML');
35 my $title = $apache->dir_config('OILSProxyTitle');
36 my $desc = $apache->dir_config('OILSProxyDescription');
37 my $ltype = $apache->dir_config('OILSProxyLoginType');
38 my $perms = [ split ' ', $apache->dir_config('OILSProxyPermissions') ];
40 return Apache2::Const::NOT_FOUND unless ($title || $proxyhtml);
41 return Apache2::Const::NOT_FOUND unless (@$perms);
44 my $auth_ses = $cgi->cookie('ses') || $cgi->param('ses');
45 my $ws_ou = $cgi->cookie('ws_ou') || $cgi->param('ws_ou');
49 # push everyone to the secure site
50 if (!$ssl_off && $url =~ /^http:/o) {
51 $url =~ s/^http:/https:/o;
52 print "Location: $url\n\n";
53 return Apache2::Const::OK;
57 my $u = $cgi->param('user');
58 my $p = $cgi->param('passwd');
62 print $cgi->header(-type=>'text/html', -expires=>'-1d');
64 $proxyhtml = join '', <DATA>;
65 $proxyhtml =~ s/TITLE/$title/gso;
66 $proxyhtml =~ s/DESCRIPTION/$desc/gso;
68 # XXX template toolkit??
72 return Apache2::Const::OK;
75 $auth_ses = oils_login($u, $p, $ltype);
79 -cookie=>$cgi->cookie(
82 -path=>'/',-expires=>'+1h'
85 return Apache2::Const::REDIRECT;
89 my $user = verify_login($auth_ses);
90 return Apache2::Const::FORBIDDEN unless ($user);
92 $ws_ou ||= $user->home_ou;
94 warn "Checking perms " . join(',', @$perms) . " for user " . $user->id . " at location $ws_ou\n";
96 my $failures = OpenSRF::AppSession
97 ->create('open-ils.actor')
98 ->request('open-ils.actor.user.perm.check', $auth_ses, $user->id, $ws_ou, $perms)
101 return Apache2::Const::FORBIDDEN if (@$failures > 0);
103 # they're good, let 'em through
104 return Apache2::Const::DECLINED;
107 # returns the user object if the session is valid, 0 otherwise
109 my $auth_token = shift;
110 return undef unless $auth_token;
112 my $user = OpenSRF::AppSession
113 ->create("open-ils.auth")
114 ->request( "open-ils.auth.session.retrieve", $auth_token )
117 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
121 return $user if ref($user);
126 my( $username, $password, $type ) = @_;
129 my $nametype = 'username';
130 $nametype = 'barcode' if ($username =~ /^\d+$/o);
132 my $seed = OpenSRF::AppSession
133 ->create("open-ils.auth")
134 ->request( 'open-ils.auth.authenticate.init', $username )
137 return undef unless $seed;
139 my $response = OpenSRF::AppSession
140 ->create("open-ils.auth")
141 ->request( 'open-ils.auth.authenticate.complete',
142 { $nametype => $username,
143 password => md5_hex($seed . md5_hex($password)),
147 return undef unless $response;
149 return $response->{payload}->{authtoken};
165 <table style='border-collapse: collapse; border: 1px solid black;'>
167 <th colspan='2' align='center'><u>DESCRIPTION</u></th>
170 <th align="right">Username or barcode:</th>
171 <td><input type="text" name="user"/></td>
174 <th align="right">Password:</th>
175 <td><input type="password" name="passwd"/></td>
178 <input type="submit" value="Log in"/>