Hi,
I'm very new to modperl and I've got a question regarding the usage of tie
() and untie().
I've written a perl-script for authenticating a user's IP-address
against a DBM-database which has stored a certain valid IP-range
for each user.
I put it into a directory where every .perl-file runs under
Apache::Registry.
Now I do a tie() once in the .perl-script. Do I have to untie() in the same
script
or is this not necessary because as I understood the perl-script keeps
"living" as long as the child-process who started it?!
Did I get something wrong here?!
best regards,
Johannes Grumb�ck
PS: Here's the source code - I know it's a little bit weak - but I'm still
beginner :)
======================
#!/usr/local/bin/perl -W
# file: test.perl
use strict;
use Apache::Constants qw(:response);
my $r = Apache->request;
my %params = $r->args;
my $username = $params{'hdl'} || undef;
if (!$username) {
$r->status(BAD_REQUEST);
return;
}
$username = 'hdl' . $username;
my @FirstIP = ();
my @LastIP =();
my @IP = split('\.',$r->connection->remote_ip());
tie(my %DB, "NDBM_File","/www/apache/auth/crossrs.user",'0_RDONLY',0664) ||
die "Kann DB nicht �ffnen.";
my @rest = split(/:/,$DB{$username});
foreach (@rest) {
my ($n,$v) = split('=');
@FirstIP = split('\.',$v) if ($n eq "FirstIP");
@LastIP = split('\.',$v) if ($n eq "LastIP");
}
untie %DB;
my $inrange = "true";
if ($FirstIP[0] > $IP[0] || $IP[0] > $LastIP[0]){ $inrange = "false1";}
elsif ($FirstIP[1] > $IP[1] || $IP[1] > $LastIP[1]){ $inrange = "false2";}
elsif ($FirstIP[2] > $IP[2] || $IP[2] > $LastIP[2]){ $inrange = "false3";}
elsif ($FirstIP[3] > $IP[3] || $IP[3] > $LastIP[3]){ $inrange = "false4";}
# Interne Adresse auch gelten lassen
if ($IP[0] == 10 && $IP[1] == 222) { $inrange = "true";}
if ($inrange eq "true" && @rest) {
$r->status(OK);
return;
} else {
$r->status(FORBIDDEN);
return;
}
================