1 package OpenILS::WWW::Redirect;
2 use strict; use warnings;
7 use Apache2::Const -compile => qw(OK REDIRECT :log);
8 use APR::Const -compile => qw(:error SUCCESS);
10 use Apache2::RequestRec ();
11 use Apache2::RequestIO ();
14 use OpenSRF::AppSession;
16 use OpenILS::Utils::Fieldmapper;
17 use OpenSRF::Utils::Logger qw/$logger/;
19 use vars '$lib_ips_hash';
21 my $bootstrap_config_file;
23 my( $self, $config ) = @_;
24 $bootstrap_config_file = $config;
28 OpenSRF::System->bootstrap_client( config_file => $bootstrap_config_file );
34 my $user_ip = $ENV{REMOTE_ADDR};
35 my $apache_obj = shift;
36 my $cgi = CGI->new( $apache_obj );
38 my $hostname = $cgi->server_name();
39 my $port = $cgi->server_port();
42 if($cgi->https) { $proto = "https"; }
44 my $url = "$proto://$hostname:$port/opac/en-US/skin/default/xml/index.xml";
46 my $path = $apache_obj->path_info();
48 $logger->debug("Apache client connecting from $user_ip");
50 if( my $lib_data = redirect_libs( $user_ip ) ) {
51 my $region = $lib_data->[0];
52 my $library = $lib_data->[1];
54 $logger->info("Apache redirecting to $region / $library");
55 my $session = OpenSRF::AppSession->create("open-ils.storage");
56 my $shortname = "$region-$library";
58 my $org = $session->request(
59 "open-ils.storage.direct.actor.org_unit.search.shortname",
60 $shortname)->gather(1);
62 if($org) { $url .= "?ol=" . $org->id; }
66 print "Location: $url\n\n";
67 return Apache2::Const::REDIRECT;
69 return print_page($url);
73 my $source_ip = shift;
74 my $aton_binary = inet_aton( $source_ip );
76 if( ! $aton_binary ) { return 0; }
78 # do this the linear way for now...
79 for my $reg (keys %$lib_ips_hash) {
81 for my $lib( keys %{$lib_ips_hash->{$reg}} ) {
83 for my $block (@{$lib_ips_hash->{$reg}->{$lib}}) {
85 if(defined($block->[0]) && defined($block->[1]) ) {
86 my $start_binary = inet_aton( $block->[0] );
87 my $end_binary = inet_aton( $block->[1] );
88 unless( $start_binary and $end_binary ) { next; }
89 if( $start_binary le $aton_binary and
90 $end_binary ge $aton_binary ) {
91 return [ $reg, $lib ];
105 print "Content-type: text/html; charset=utf-8\n\n";
109 <meta HTTP-EQUIV='Refresh' CONTENT="0; URL=$url"/>
110 <style TYPE="text/css">
115 background: lightgrey;
123 <div class="loading_div">
127 <center><img src='/opac/images/main_logo.jpg'/></center>
132 return Apache2::Const::OK;