WEB4LIB digest 845

Jonathan Esterhazy jonathan_esterhazy at umanitoba.ca
Thu Oct 30 10:59:18 EST 1997


Ms. Hassett -- 

Try the following:

#!/usr/local/bin/perl -w

# the authfile should be a regular .htaccess type file,
# with 'allow from address' and 'deny from address' lines.

$ip_authfile = 'path/to/authfile';
my ($local) = &check_ip;

if ($local)
{
    print "Location: http://www.whatever.com/first_url/\n\n";
}

else 
{
    print "Location: http://www.whatever.com/first_url/\n\n";
}

exit;


#####################################################################
# this routine reads IP addresses from the main
# ByLocation authfile, and compares that with the
# $ENV{'REMOTE_ADDR'} environment variable.
#
# it returns '1' if user is authorized, '0' if not.
#
sub check_ip
{
 my (@good_ips, @bad_ips);
 my ($authflag) = '0';
 open (AUTHFILE, $ip_authfile) || &error("can't open authfile");
 while (<AUTHFILE>)
 {
  chop;
  if ($_ =~ s/^allow from //)
  {
   push (@good_ips, $_);
  }
  elsif ($_ =~ s/^deny from //)
  {
   push (@bad_ips, $_);
  }
  else
  {
   next;
  }
 }
 close AUTHFILE;
 while (@good_ips)
 {
  my ($ip) = shift (@good_ips);
  if ($ENV{'REMOTE_ADDR'} =~ m/^$ip/)
  {
   $authflag = 1;
   last;
  }
 }
 # no need to check deny addresses if they aren't authorized by now!
 return '0' if (! $authflag);
 while (@bad_ips)
 {
  my ($ip) = shift (@bad_ips);
  if ($ENV{'REMOTE_ADDR'} =~ m/^$ip/)
  {
   $authflag = 0;
   last;
  }
 }
 return $authflag;
}

>Date: Wed, 29 Oct 97 12:51:10 PST
>From: "lHassett" <lHassett at dwebb.llu.edu>
>To: web4lib at library.berkeley.edu
>Subject: need script for redirect based on IP address
>Message-ID: <9709298781.AA878158401 at dwebb.llu.edu>
>
>     
>     I'm hoping one or more of you have a script that you could share 
>     with us that will redirect users based on IP addresses when they 
>     click on a link (button). 
>     
>     
>     Here's the scenario.  We are bringing up a new service of remote 
>     web access to our licensed databases.  We have a "databases" 
>     button on all library web pages that for off campus users we want 
>     to go to a login page for authentication. For on-campus users, 
>     including in-library use, we want them to go to the page (on a 
>     different server) which directly accesses the databases with no 
>     password required.  At this time, the process actually goes on on 
>     three different servers:  our main University server that has all 
>     the library pages, the authentication server, and the server for 
>     the databases.
>     
>     We'd like this process to be transparent to the user.  All users 
>     initially click on the same button, but end up on different 
>     pages, depending on where they are coming from (IP address).
>     
>     All of the servers are unix based.
>     
>     
>     We would very much appreciate anything anyone can share with us.
>     
>     Thank you very much.
>     
>     Leslie Hassett
>     Reference Librarian, Library Web Editor 
>     Loma Linda University
>     lhassett at dwebb.llu.edu
>
>




More information about the Web4lib mailing list