3 # This CGI script might be useful for providing an easy way for EZproxy to authenticate
4 # users against an Evergreen instance.
6 # For example, if you modify your eg.conf by adding this:
7 # Alias "/cgi-bin/ezproxy/" "/openils/var/cgi-bin/ezproxy/"
8 # <Directory "/openils/var/cgi-bin/ezproxy">
9 # AddHandler cgi-script .pl
15 # and make that directory and copy remoteauth.cgi to it:
16 # mkdir /openils/var/cgi-bin/ezproxy/
17 # cp remoteauth.cgi /openils/var/cgi-bin/ezproxy/
19 # Then you could add a line like this to the users.txt of your EZproxy instance:
21 # ::external=https://hostname/cgi-bin/ezproxy/remoteauth.cgi,post=user=^u&passwd=^p
28 use Digest::MD5 qw(md5_hex);
30 use OpenSRF::EX qw(:try);
32 use OpenSRF::AppSession;
34 my $bootstrap = '/openils/conf/opensrf_core.xml';
36 my $u = $cgi->param('user');
37 my $usrname = $cgi->param('usrname');
38 my $barcode = $cgi->param('barcode');
39 my $agent = $cgi->param('agent'); # optional, but preferred
40 my $p = $cgi->param('passwd');
42 print $cgi->header(-type=>'text/html', -expires=>'-1d');
44 OpenSRF::AppSession->ingress('remoteauth');
45 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
47 if (!($u || $usrname || $barcode) || !$p) {
53 $nametype = 'username';
56 $nametype = 'barcode';
58 $nametype = 'username';
59 my $regex_response = OpenSRF::AppSession
60 ->create('open-ils.actor')
61 ->request('open-ils.actor.ou_setting.ancestor_default', 1, 'opac.barcode_regex')
63 if ($regex_response) {
64 my $regexp = $regex_response->{'value'};
65 $nametype = 'barcode' if ($u =~ qr/$regexp/);
68 my $seed = OpenSRF::AppSession
69 ->create('open-ils.auth')
70 ->request( 'open-ils.auth.authenticate.init', $u )
73 my $response = OpenSRF::AppSession
74 ->create('open-ils.auth')
75 ->request( 'open-ils.auth.authenticate.verify',
76 { $nametype => $u, password => md5_hex($seed . md5_hex($p)), type => 'opac', agent => $agent })
79 if ($response->{ilsevent} == 0) {
85 print '+BACKEND_ERROR';
88 print '+BACKEND_ERROR';