From 663e9d1974292c80b590ae4d006cfe6826689686 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 8 Apr 2011 16:30:04 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/ILS/trunk@20023 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/extras/Makefile.install | 1 + .../src/perlmods/lib/OpenILS/WWW/Redirect.pm | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/extras/Makefile.install b/Open-ILS/src/extras/Makefile.install index 2068d9f543..0ebec6851d 100644 --- a/Open-ILS/src/extras/Makefile.install +++ b/Open-ILS/src/extras/Makefile.install @@ -104,6 +104,7 @@ DEBS = \ 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 diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm index b4854773e6..c76cbf3706 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/Redirect.pm @@ -12,6 +12,7 @@ use CGI (); 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 @@ sub parse_ips_file { while( my $data = ) { 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 @@ sub handler { 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) { + + if ($nskin =~ m/[^\s]/) { $skin = $nskin; } + if ($nhostname =~ m/[^\s]/) { $hostname = $nhostname; } - $logger->info("Apache redirecting $user_ip to $shortname"); + $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 handler { } sub redirect_libs { - my $source_ip = shift; - my $aton_binary = inet_aton( $source_ip ); - - return 0 unless $aton_binary; + my $source_ip = new Net::IP (shift) or return 0; # 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]); } } } -- 2.43.2