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);
9 use Template qw(:template);
10 use Apache2::RequestRec ();
11 use Apache2::RequestIO ();
14 use OpenSRF::AppSession;
16 use OpenILS::Utils::Fieldmapper;
18 use vars '$lib_ips_hash';
20 my $bootstrap_config_file;
22 my( $self, $config ) = @_;
23 $bootstrap_config_file = $config;
27 OpenSRF::System->bootstrap_client( config_file => $bootstrap_config_file );
33 my $user_ip = $ENV{REMOTE_ADDR};
34 my $apache_obj = shift;
35 my $cgi = CGI->new( $apache_obj );
37 my $hostname = $cgi->server_name();
38 my $port = $cgi->server_port();
41 if($cgi->https) { $proto = "https"; }
43 my $url = "$proto://$hostname:$port/opac/skin/en-US/default/xml/index.xml";
45 my $path = $apache_obj->path_info();
47 warn "Client connecting from $user_ip\n";
49 if( my $lib_data = redirect_libs( $user_ip ) ) {
50 my $region = $lib_data->[0];
51 my $library = $lib_data->[1];
53 warn "Will redirect to $region / $library\n";
54 my $session = OpenSRF::AppSession->create("open-ils.storage");
55 my $shortname = "$region-$library";
57 my $org = $session->request(
58 "open-ils.storage.direct.actor.org_unit.search.shortname",
59 $shortname)->gather(1);
61 if($org) { $url .= "?location=" . $org->id; }
65 print "Location: $url\n\n";
66 return Apache2::Const::REDIRECT;
68 return print_page($url);
72 my $source_ip = shift;
73 my $aton_binary = inet_aton( $source_ip );
75 if( ! $aton_binary ) { return 0; }
77 # do this the linear way for now...
78 for my $reg (keys %$lib_ips_hash) {
80 for my $lib( keys %{$lib_ips_hash->{$reg}} ) {
82 for my $block (@{$lib_ips_hash->{$reg}->{$lib}}) {
84 if(defined($block->[0]) && defined($block->[1]) ) {
85 my $start_binary = inet_aton( $block->[0] );
86 my $end_binary = inet_aton( $block->[1] );
87 unless( $start_binary and $end_binary ) { next; }
88 if( $start_binary le $aton_binary and
89 $end_binary ge $aton_binary ) {
90 return [ $reg, $lib ];
104 print "Content-type: text/html; charset=utf-8\n\n";
108 <meta HTTP-EQUIV='Refresh' CONTENT="0; URL=$url"/>
109 <style TYPE="text/css">
114 background: lightgrey;
122 <div class="loading_div">
126 <center><img src='/opac/images/main_logo.jpg'/></center>
131 return Apache2::Const::OK;