#!/bin/perl
require "adtracklib.pl";
print "Content-type: text/html\n\n";
# Initialize image file directory here - can make this a variable later
# but it is best to have a single, protected image directory
$image_file_dir = "http://www.glamazon.com/freepix/";
# grab the POST/GET data
&ReadFormInput;
if (! $INPUT{'site'}) {$INPUT{'site'} = "glamazon";}
# DEFAULT this uses a template named "image.html"
# if you want to use a different template, put it in the template directory,
# and pass its name in.
if (! $INPUT{'path'}) {$INPUT{'path'} = "freepix";}
if (! $INPUT{'template'}) {$INPUT{'template'} = "image.html";}
# DEFAULT image here
if (! $INPUT{'image'}) {$INPUT{'image'} = "athome.jpg";}
$image_to_display = '/' . $INPUT{'path'} . '/' . $INPUT{'image'};
#print "$image_to_display";
&InitSiteVars($INPUT{'site'});
$init_template = $INPUT{'template'};
$template = $adref . "templates/$INPUT{'template'}";
$ip_addr = "$ENV{'REMOTE_ADDR'}"; # make into global variable
$ip_logfile = "$logs_dir/$ip_addr.reap";
&InitializeAdArrays;
&PruneAds;
# start the parsing.
# ifh000 = input file handle \
# > dynamic file handles for "recursive" processing
# ofh000 = output file handle /
&Run('ifh000', 'ofh000');
exit;
# End Main ------------------------------------------------------
sub Run
{
my ($in, $out) = @_;
# increment file handles so we don't step on any toes
$in++;
$out++;
# open template
open ($in, "<$template") || &ReturnCGIError(500, "Run" , "Cannot open template $template");
$out = STDOUT;
&ProcessFile($in, $out);
close $in;
}
sub ProcessFile
{
my ($in, $out) = @_;
my ($file) = "";
# This puts our ads in!
while (<$in>) {
#Process each line and throw it into a variable for output
while (//o) { $a = &GetAdByType("stamp"); s//$a/go;}
while (//o) { $a = &GetAdByType("banner"); s//$a/go;}
while (//o) { $a = &GetAdByType("textlink"); s//$a/go;}
while (//o) {s//
/go;}
$file .= $_
}
print $out $file;
}
sub PruneAds {
# if the ip log file exists,
# remove previously clicked ads from rotation.
if (open (LOG, "<" . $ip_logfile)) {
$numdate = time();
$cutoff = $numdate - ($advertHours * 3600);
@loglines = ;
close LOG;
foreach $line ( @loglines ) {
($my_time, $my_referer, $my_ad, $my_sponsor ) = split(/ /,$line);
if ($my_time > $cutoff) {
chop($my_sponsor);
foreach $type (@types) {
foreach $key (keys %{$show_banners{$type}}) {
if ($show_banners{$type}{$key} eq $my_sponsor)
{ delete $show_banners{$type}{$key}; }
}
}
}
}
}
}
sub GetAdByType {
# returns a string containing the type of ad requested
$type = $_[0];
@available = keys %{$show_banners{$type}};
if (@available) {
# Pick a random ad_name from the ones available.
srand;
$displayad = splice(@available, rand(@available), 1);
# Delete the ad_name you have picked.
delete $show_banners{$type}{$displayad};
return &GetAdvertString($displayad,$init_template);
}
else {return &GetThanksString;}
}
sub GetThanksString {
#Say "Thank you, nice surfer!"
#print "";
$sOutput = "Thank You For Clicking My Sponsors!
";
$sOutput .= "Type Control-D to Bookmark My Site
";
$sOutput .= "Please Visit Me Again Later!";
#print "\n";
return $sOutput;
}