1 package OpenILS::WWW::Redirect;
2 use strict; use warnings;
6 use Apache2::Const -compile => qw(OK REDIRECT :log);
7 use APR::Const -compile => qw(:error SUCCESS);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
12 use OpenSRF::AppSession;
14 use OpenSRF::Utils::Logger qw/$logger/;
16 use vars '$lib_ips_hash';
19 my $bootstrap_config_file;
21 my( $self, $config ) = @_;
22 $bootstrap_config_file = $config;
26 OpenSRF::System->bootstrap_client( config_file => $bootstrap_config_file );
33 if( open(F, $ips_file) ) {
35 while( my $data = <F> ) {
38 my( $shortname, $ip1, $ip2 ) = split(/\s+/, $data);
39 next unless ($shortname and $ip1 and $ip2);
41 $lib_ips_hash->{$shortname} = [] unless $lib_ips_hash->{$shortname};
42 push( @{$lib_ips_hash->{$shortname}}, [ $ip1, $ip2 ] );
48 $logger->error("Unable to open lib IP redirector file $ips_file");
55 my $user_ip = $ENV{REMOTE_ADDR};
56 my $apache_obj = shift;
57 my $cgi = CGI->new( $apache_obj );
59 my $hostname = $cgi->server_name();
60 my $port = $cgi->server_port();
63 if($cgi->https) { $proto = "https"; }
65 my $url = "$proto://$hostname:$port/opac/en-US/skin/default/xml/index.xml";
67 my $path = $apache_obj->path_info();
69 $logger->debug("Apache client connecting from $user_ip");
71 if(my $shortname = redirect_libs($user_ip)) {
73 $logger->info("Apache redirecting $user_ip to $shortname");
74 my $session = OpenSRF::AppSession->create("open-ils.storage");
76 my $org = $session->request(
77 "open-ils.storage.direct.actor.org_unit.search.shortname",
78 $shortname)->gather(1);
80 if($org) { $url .= "?ol=" . $org->id; }
83 print "Location: $url\n\n";
84 return Apache2::Const::REDIRECT;
86 return print_page($url);
90 my $source_ip = shift;
91 my $aton_binary = inet_aton( $source_ip );
93 return 0 unless $aton_binary;
95 # do this the linear way for now...
96 for my $shortname (keys %$lib_ips_hash) {
98 for my $block (@{$lib_ips_hash->{$shortname}}) {
100 if(defined($block->[0]) && defined($block->[1]) ) {
101 my $start_binary = inet_aton( $block->[0] );
102 my $end_binary = inet_aton( $block->[1] );
103 next unless( $start_binary and $end_binary );
104 if( $start_binary le $aton_binary and
105 $end_binary ge $aton_binary ) {
119 print "Content-type: text/html; charset=utf-8\n\n";
123 <meta HTTP-EQUIV='Refresh' CONTENT="0; URL=$url"/>
124 <style TYPE="text/css">
129 background: lightgrey;
137 <div class="loading_div">
141 <center><img src='/opac/images/main_logo.jpg'/></center>
146 return Apache2::Const::OK;