[open-ils-commits] r20023 - in trunk/Open-ILS/src: extras perlmods/lib/OpenILS/WWW (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Apr 8 12:30:08 EDT 2011


Author: erickson
Date: 2011-04-08 12:30:04 -0400 (Fri, 08 Apr 2011)
New Revision: 20023

Modified:
   trunk/Open-ILS/src/extras/Makefile.install
   trunk/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm
Log:
patch from Ben Ostrowsky (w/ input) to add support to the Apache redirect module to also optionally read redirect skin and domain from the library IP's configuration file.

Modified: trunk/Open-ILS/src/extras/Makefile.install
===================================================================
--- trunk/Open-ILS/src/extras/Makefile.install	2011-04-07 19:46:23 UTC (rev 20022)
+++ trunk/Open-ILS/src/extras/Makefile.install	2011-04-08 16:30:04 UTC (rev 20023)
@@ -104,6 +104,7 @@
 	libtext-aspell-perl\
 	libtext-csv-perl\
 	libuniversal-require-perl\
+	libnet-ip-perl\
 	libunix-syslog-perl
 
 # Debian Lenny and Ubuntu Intrepid bundle recent versions of yaz

Modified: trunk/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm	2011-04-07 19:46:23 UTC (rev 20022)
+++ trunk/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm	2011-04-08 16:30:04 UTC (rev 20023)
@@ -12,6 +12,7 @@
 use OpenSRF::AppSession;
 use OpenSRF::System;
 use OpenSRF::Utils::Logger qw/$logger/;
+use Net::IP;
 
 use vars '$lib_ips_hash';
 my $lib_ips_hash;
@@ -35,11 +36,11 @@
        while( my $data = <F> ) {
          chomp($data);
 
-         my( $shortname, $ip1, $ip2 ) = split(/\s+/, $data);
+         my ($shortname, $ip1, $ip2, $skin, $domain) = 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 ] );
+         push( @{$lib_ips_hash->{$shortname}}, [ $ip1, $ip2, $skin, $domain ] );
        }
 
        close(F);
@@ -68,16 +69,21 @@
 	if($cgi->https) { $proto = "https"; }
 
 	my $url = "$proto://$hostname:$port/opac/$locale/skin/$skin/xml/index.xml";
-
 	my $path = $apache_obj->path_info();
 
 	$logger->debug("Apache client connecting from $user_ip");
 
-	if(my $shortname = redirect_libs($user_ip)) {
+	my ($shortname, $nskin, $nhostname) = redirect_libs($user_ip);
+	if ($shortname) {
 
-		$logger->info("Apache redirecting $user_ip to $shortname");
+		if ($nskin =~ m/[^\s]/) { $skin = $nskin; }
+		if ($nhostname =~ m/[^\s]/) { $hostname = $nhostname; }
+
+		$logger->info("Apache redirecting $user_ip to $shortname with skin $skin and host $hostname");
 		my $session = OpenSRF::AppSession->create("open-ils.actor");
 
+		$url = "$proto://$hostname:$port/opac/$locale/skin/$skin/xml/index.xml";
+
 		my $org = $session->request(
             'open-ils.actor.org_unit.retrieve_by_shortname',
 			 $shortname)->gather(1);
@@ -95,23 +101,19 @@
 }
 
 sub redirect_libs {
-	my $source_ip = shift;
-	my $aton_binary = inet_aton( $source_ip );
+	my $source_ip = new Net::IP (shift) or return 0;
 
-    return 0 unless $aton_binary;
-
 	# do this the linear way for now...
 	for my $shortname (keys %$lib_ips_hash) {
 
         for my $block (@{$lib_ips_hash->{$shortname}}) {
 
+            $logger->debug("Checking whether " . $source_ip->ip() . " is in the range " . $block->[0] . " to " . $block->[1]);
             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;
+                my $range = new Net::IP( $block->[0] . ' - ' . $block->[1] );
+                if( $source_ip->overlaps($range)==$IP_A_IN_B_OVERLAP ||
+                    $source_ip->overlaps($range)==$IP_IDENTICAL ) {
+                    return ($shortname, $block->[2], $block->[3]);
                 }
             }
         }



More information about the open-ils-commits mailing list