Yo, Master, these CGI programming extensions you coded rock! I wanna tell ya.
----------------
# For Rufus.
package Utils ;
use Secrets ;
sub new
{
my ($class) = @_ ;
my $self = {
ipbanFile => $ipBans,
bannedIPs => []
};
unless(open(IPBAN, $$self{ipbanFile}))
{
$errstr = "Cannot open $file: $!";
return undef;
}
while()
{
chomp ;
push @{$$self{bannedIPs}}, $_ ;
}
close IPBAN ;
bless $self, $class;
return $self;
}
sub ipBanned
{
$self = shift ;
$ip = shift ;
$banned = 0 ;
foreach(@{$$self{bannedIPs}})
{
if( $ip =~ /^$_/) { $banned = 1 ; last ; }
}
return $banned ;
}
sub getIP
{
$self = shift ;
return lc ($ENV{'HTTP_X_FORWARDED_FOR'} || $ENV{'REMOTE_ADDR'});
}
1 ; # Perl mantra.