#!/usr/local/bin/perl
#########################################################
#                                                       #
#                     RedirectPro                       #
#                                                       #
#########################################################
#                                                       #
#                      redrect.pl                       #
#                                                       #
#   Configure this script by filling in the variables   #
#   below. After that put all three scripts into your   #
#   CGI-BIN and CHMOD them 755. Put the datafile into   #
#   into a non-web accessable directory (if you don't   #
#   have access to one a web accessable directory will  #
#   work but is much less secure) and CHMOD it 777.     #
#                                                       #
#   If you have any further questions, direct them to   #
#   the support forum at http://www.go2cgi.com/         #
#                                                       #
#########################################################
#                                                       #
#         Copyright © 1999 W. Dustin Alligood           #
#                                                       #
#########################################################

# If there is a problem with the countries data file
# this is the URL to the HTML file you want to be in
# the popup
$popup='http://www.go2.com.py/pop.html';

# The path to the datafile
$datafile='data.txt';

# If there is a problem with the countries data file
# this is the path to the file you want to be on the
# delay page
$delayfile='delay.txt';

# URL to the ad-frame (currently this is not in the
# countries file so this is the only one)
$frameurl='http://www.go2.com.py/frame.html';

# The path to the countries data file
$countries='countries.txt';

# Change nothing below this line
#########################################################


@fval=split(/&/,$ENV{'QUERY_STRING'});
foreach $i (0 .. $#fval){
	($name,$val)=split (/=/,$fval[$i],2);
	$val=~tr/+/ /;
	$val=~ s/%(..)/pack("c",hex($1))/ge;
	$name=~tr/+/ /;
	$name=~ s/%(..)/pack("c",hex($1))/ge;
	$fild{$name}=$val;
}
if ($fild{'ad'} eq "popup"){
	$ct=$fild{'ct'};
	open (FILE,"<$countries");
		@cntes=<FILE>;
	close(FILE);
	foreach $cnty (@cntes){
		($c,$p,$d,$h)=split(/\|/,$cnty);
		if($ct eq $c){
			$popup=$p;
		}
	}
	print "Content-type: text/html\n\n";
	print "popup=window.open('$popup','adwin','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,width=500,height=85')\n";
}elsif($fild{'ad'} eq "delay"){
	$ct=$fild{'ct'};
	open (FILE,"<$countries");
		@cntes=<FILE>;
	close(FILE);
	foreach $cnty (@cntes){
		($c,$p,$d,$h)=split(/\|/,$cnty);
		if($ct eq $c){
			$delayfile=$d;
		}
	}
	print "Content-type: text/html\n\n";
	open(DLY,"<$delayfile");
	@dely=<DLY>;
	close(DLY);
	print "@dely\n";
}else{
	print "Content-type: text/html\n\n";
	print "$frameurl";
}