[open-ils-commits] r18116 - trunk/Open-ILS/examples (phasefx)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Oct 1 08:19:12 EDT 2010


Author: phasefx
Date: 2010-10-01 08:19:11 -0400 (Fri, 01 Oct 2010)
New Revision: 18116

Modified:
   trunk/Open-ILS/examples/remoteauth.cgi
Log:
tweak remoteauth.cgi to offer usrname and barcode params in addition to user.  user param now looks for the opac.barcode_regex org unit setting to determine whether the value is a usrname or barcode.  change double-quotes to single-quotes if we're not doing string interpolation.  change apache instructions for configuration


Modified: trunk/Open-ILS/examples/remoteauth.cgi
===================================================================
--- trunk/Open-ILS/examples/remoteauth.cgi	2010-10-01 05:31:50 UTC (rev 18115)
+++ trunk/Open-ILS/examples/remoteauth.cgi	2010-10-01 12:19:11 UTC (rev 18116)
@@ -3,7 +3,8 @@
 #    This CGI script might be useful for providing an easy way for EZproxy to authenticate
 #    users against an Evergreen instance.
 #    
-#    For example, if you modify your eg_vhost.conf by adding this:
+#    For example, if you modify your eg.conf by adding this:
+#    Alias "/cgi-bin/ezproxy/" "/openils/var/cgi-bin/ezproxy/"
 #    <Directory "/openils/var/cgi-bin/ezproxy">
 #        AddHandler cgi-script .pl
 #        AllowOverride None
@@ -29,47 +30,63 @@
 use OpenSRF::EX qw(:try);
 use OpenSRF::System;
 
-
 my $bootstrap = '/openils/conf/opensrf_core.xml';
 my $cgi = new CGI;
 my $u = $cgi->param('user');
+my $usrname = $cgi->param('usrname');
+my $barcode = $cgi->param('barcode');
 my $p = $cgi->param('passwd');
 
 print $cgi->header(-type=>'text/html', -expires=>'-1d');
 
 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
 
-if (!$u || !$p) {
-	print "+INCOMPLETE";
+if (!($u || $usrname || $barcode) || !$p) {
+	print '+INCOMPLETE';
 } else {
-	my $nametype = 'username';
-	$nametype = 'barcode' if ($u =~ /^\d+$/o);
+	my $nametype;
+    if ($usrname) {
+        $u = $usrname;
+	    $nametype = 'username';
+    } elsif ($barcode) {
+        $u = $barcode;
+        $nametype = 'barcode';
+    } else {
+	    $nametype = 'username';
+        my $regex_response = OpenSRF::AppSession
+            ->create('open-ils.actor')
+            ->request('open-ils.actor.ou_setting.ancestor_default', 1, 'opac.barcode_regex')
+            ->gather(1);
+        if ($regex_response) {
+            my $regexp = $regex_response->{'value'};
+            $nametype = 'barcode' if ($u =~ qr/$regexp/);
+        }
+    }
 	my $seed = OpenSRF::AppSession
-		->create("open-ils.auth")
+		->create('open-ils.auth')
 		->request( 'open-ils.auth.authenticate.init', $u )
 		->gather(1);
 	if ($seed) {
 		my $response = OpenSRF::AppSession
-			->create("open-ils.auth")
+			->create('open-ils.auth')
 			->request( 'open-ils.auth.authenticate.complete', { $nametype => $u, password => md5_hex($seed . md5_hex($p)), type => 'temp' })
 			->gather(1);
 		if ($response->{payload}->{authtoken}) {
 			my $user = OpenSRF::AppSession
-				->create("open-ils.auth")
-				->request( "open-ils.auth.session.retrieve", $response->{payload}->{authtoken} )
+				->create('open-ils.auth')
+				->request( 'open-ils.auth.session.retrieve', $response->{payload}->{authtoken} )
 				->gather(1);
 			if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
-				print "+NO";
+				print '+NO';
 			} else {
-				print "+VALID";
+				print '+VALID';
 			}
 		} else {
-			print "+NO";
+			print '+NO';
 		}
 	} else {
-		print "+BACKEND_ERROR";
+		print '+BACKEND_ERROR';
 	}
-
 }
 
 1;



More information about the open-ils-commits mailing list