#!/usr/bin/perl use strict; ## Path to DB file my $base_path = "/home/indeshaw/indianadultmovie.com/dbase/ipdb"; ## Path to config file my $config_path = "/home/indeshaw/indianadultmovie.com/dbase/config.txt"; my %ipdb; my $table = {}; eval { dbmopen( %ipdb, $base_path, 0644 ); open( F, $config_path ) || die $!; while ( ) { s/^\s+//s; s/\s+$//s; my ( $id, $gb_url, $non_gb_url ) = split( /\|/ ); if ( ( $id =~ /^\d+$/ ) && $id ) { $table->{$id}->{'gb_url'} = $gb_url; $table->{$id}->{'non_gb_url'} = $non_gb_url; } } close( F ); }; if ( $@ ) { print "Content-type: text/javascript\n\n// $@"; exit; } my $url; if ( ( $ENV{'QUERY_STRING'} =~ /^\d+$/ ) and $table->{$ENV{'QUERY_STRING'}} ){ my @ip = split( /\./, $ENV{'REMOTE_ADDR'} ); $url = ( check_ip( "$ip[0].$ip[1].$ip[2]", "$ip[3]" ) or check_ip( "$ip[0].$ip[1]", "$ip[2].$ip[3]" ) or check_ip( $ip[0], "$ip[1].$ip[2].$ip[3]" ) ) ? $table->{$ENV{'QUERY_STRING'}}->{'gb_url'} : $table->{$ENV{'QUERY_STRING'}}->{'non_gb_url'} ; } print "Content-type: text/javascript\n\n"; print ( ( $url ) ? "self.location='$url';" : "// Thank you for usage this script" ); eval { dbmclose( %ipdb ); }; exit; sub check_ip { my ( $head, $tail ) = @_; if ( my $range_str = $ipdb{$head} ) { my @range = split( /;/, $range_str ); foreach my $range ( @range ) { my ( $from, $to ) = split( /-/, $range ); my $remote_ip = ip2int( "$head.$tail" ); $from = ip2int( "$head.$from" ); $to = ip2int( "$head.$to" ); return 1 if ( ( $from <= $remote_ip ) and ( $remote_ip <= $to ) ); } return 0; } else { return 0; } } sub ip2int { my $ip = shift; my @byte = split /\./, $ip; return $ip = ( $byte[0]<<24 ) | ( $byte[1] << 16 ) | ( $byte[2] << 8 ) | $byte[3]; }