[open-ils-commits] r7997 - in branches/rel_1_2/Open-ILS: examples/apache src/perlmods/OpenILS/WWW

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Nov 4 17:51:10 EST 2007


Author: erickson
Date: 2007-11-04 17:35:50 -0500 (Sun, 04 Nov 2007)
New Revision: 7997

Modified:
   branches/rel_1_2/Open-ILS/examples/apache/startup.pl
   branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/WWW/Redirect.pm
Log:
backporting redirect fixes: svn merge -r7995:7996 svn://svn.open-ils.org/ILS/trunk/

Modified: branches/rel_1_2/Open-ILS/examples/apache/startup.pl
===================================================================
--- branches/rel_1_2/Open-ILS/examples/apache/startup.pl	2007-11-04 22:30:00 UTC (rev 7996)
+++ branches/rel_1_2/Open-ILS/examples/apache/startup.pl	2007-11-04 22:35:50 UTC (rev 7997)
@@ -5,6 +5,15 @@
 use OpenILS::Reporter::Proxy ('/openils/conf/opensrf_core.xml');
 
 
+# - Uncoment the following 2 lines to make use of the IP redirection code
+# - The IP file should to contain a map with the following format:
+# - actor.org_unit.shortname <start_ip> <end_ip>
+# - e.g.  LIB123 10.0.0.1 10.0.0.254
 
+#use OpenILS::WWW::Redirect qw(/openils/conf/opensrf_core.xml);
+#OpenILS::WWW::Redirect->parse_ips_file('/openils/conf/lib_ips.txt');
+
+
+
 1;
 

Modified: branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/WWW/Redirect.pm
===================================================================
--- branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/WWW/Redirect.pm	2007-11-04 22:30:00 UTC (rev 7996)
+++ branches/rel_1_2/Open-ILS/src/perlmods/OpenILS/WWW/Redirect.pm	2007-11-04 22:35:50 UTC (rev 7997)
@@ -1,22 +1,21 @@
 package OpenILS::WWW::Redirect;
 use strict; use warnings;
+
 use Socket;
-
 use Apache2 ();
 use Apache2::Log;
 use Apache2::Const -compile => qw(OK REDIRECT :log);
 use APR::Const    -compile => qw(:error SUCCESS);
-use Template;
 use Apache2::RequestRec ();
 use Apache2::RequestIO ();
 use CGI ();
 
 use OpenSRF::AppSession;
 use OpenSRF::System;
-use OpenILS::Utils::Fieldmapper;
 use OpenSRF::Utils::Logger qw/$logger/;
 
 use vars '$lib_ips_hash';
+my $lib_ips_hash;
 
 my $bootstrap_config_file;
 sub import {
@@ -28,7 +27,30 @@
 	OpenSRF::System->bootstrap_client( config_file => $bootstrap_config_file );
 }
 
+sub parse_ips_file {
+    my $class = shift;
+    my $ips_file = shift;
 
+    if( open(F, $ips_file) ) {
+
+       while( my $data = <F> ) {
+         chomp($data);
+
+         my( $shortname, $ip1, $ip2 ) = split(/\s+/, $data);
+         next unless ($shortname and $ip1 and $ip2);
+
+         $lib_ips_hash->{$shortname} = [] unless $lib_ips_hash->{$shortname};
+         push( @{$lib_ips_hash->{$shortname}}, [ $ip1, $ip2 ] );
+       }
+
+       close(F);
+
+    } else {
+        $logger->error("Unable to open lib IP redirector file $ips_file");
+    }
+}
+
+
 sub handler {
 
 	my $user_ip = $ENV{REMOTE_ADDR};
@@ -47,20 +69,16 @@
 
 	$logger->debug("Apache client connecting from $user_ip");
 
-	if( my $lib_data = redirect_libs( $user_ip ) ) {
-		my $region = $lib_data->[0];
-		my $library = $lib_data->[1];
+	if(my $shortname = redirect_libs($user_ip)) {
 
-		$logger->info("Apache redirecting $user_ip to $region / $library");
+		$logger->info("Apache redirecting $user_ip to $shortname");
 		my $session = OpenSRF::AppSession->create("open-ils.storage");
-		my $shortname = "$region-$library";
 
 		my $org = $session->request(
 			"open-ils.storage.direct.actor.org_unit.search.shortname",
 			 $shortname)->gather(1);
 
 		if($org) { $url .= "?ol=" . $org->id; }
-
 	}
 
 	print "Location: $url\n\n"; 
@@ -73,26 +91,23 @@
 	my $source_ip = shift;
 	my $aton_binary = inet_aton( $source_ip );
 
-	if( ! $aton_binary ) { return 0; }
+    return 0 unless $aton_binary;
 
 	# do this the linear way for now...
-	for my $reg (keys %$lib_ips_hash) {
+	for my $shortname (keys %$lib_ips_hash) {
 
-		for my $lib( keys %{$lib_ips_hash->{$reg}} ) {
+        for my $block (@{$lib_ips_hash->{$shortname}}) {
 
-			for my $block (@{$lib_ips_hash->{$reg}->{$lib}}) {
-
-				if(defined($block->[0]) && defined($block->[1]) ) {
-					my $start_binary	= inet_aton( $block->[0] );
-					my $end_binary		= inet_aton( $block->[1] );
-					unless( $start_binary and $end_binary ) { next; }
-					if( $start_binary le $aton_binary and
-							$end_binary ge $aton_binary ) {
-						return [ $reg, $lib ];
-					}
-				}
-			}
-		}
+            if(defined($block->[0]) && defined($block->[1]) ) {
+                my $start_binary	= inet_aton( $block->[0] );
+                my $end_binary		= inet_aton( $block->[1] );
+                next unless( $start_binary and $end_binary );
+                if( $start_binary le $aton_binary and
+                        $end_binary ge $aton_binary ) {
+                    return $shortname;
+                }
+            }
+        }
 	}
 	return 0;
 }



More information about the open-ils-commits mailing list