#!/usr/local/bin/perl
#
# Name :ad
# Author :Kang SoonLai
# Date :Fri Nov 08 1996, 02:01:43 AM v1.0
# Path :/users/skang/public_html/programs/ad
# Email :skang@tisl.ukans.edu
# WWW :htp://www.tisl.ukans.edu/~skang
#
# This is an ad banner script that randomly displays the banner img and
# correctly(hopefully) routes the ref to the correct URL & img based
# on the REMOTE_ADDR.
# **DOES NOT require server side include! **
# Usage:
# You MUST create a rc file named stat. This file stores the urls, the
# paths to the banner, freq of appearence.
# If you plan to use ad for several other pages, you can then create
# another rc files, and you must append the name of the rc file to the
# cgi call. Here are the examples:
#
# default:
#
#
# rc file, stat2, given:
#
#
# the stat file should have a format like this
# url1%%img_file1%%freq_of_appearence
# url2%%img_file2%%freq_of_appearence
# .
# .
#
# ** remember **
# 1. you also have to create a pics dir in the $dir specified
# below. put all the image files there. default dir is
# /users/skang/public_html/banner
#
# 2. crete a tmp dir in $dir as well, and make the permission to 757
# by using this command: chmod 757 tmp
#
# 3. you might want to get the rmads script as well. this script
# cleans up the tmp dir.
#
# This program will fail if the user clicks to the sponsor page and come
# back, then reclicks the sponsor page again. The second click might
# bring him to somewhere else!
#
###############################################################################
# the base url to the banner images, this is the url where all the banner pics
# located.
#
$homeurl = "www.tisl.ukans.edu/~skang/banner/pics";
# dir to where the banner info located. contains the stat file, pics dir,
# tmp/ip files, etc.
#
$dir = "/users/skang/public_html/banner";
# get the remote IP so that in case the ip file is not created, we can still
# kind of guess the link to go to.
#
$ip = $ENV{'REMOTE_ADDR'} ? "tmp/$ENV{'REMOTE_ADDR'}" : "tmp/129.237.125.68";
# get the action from the env var. two actions are allowed,
# 'url' - point to the "sponsor" page.
# 'img' - returns the img to be displayed.
#
($dum,$action,$file) = split(/\//,$ENV{'PATH_INFO'});
#$action =~ s/\///;
# this file contains the information about the banner to be displayed
# it has the format -> url%%img%%frequency%%showed_frequency
#
$file = "stat" unless $file;
######################
# ACTION!
######################
if ( (-e "$dir/$ip") && $action eq 'url' ) {
open(TMP,"$dir/$ip") || die "Error opening file $dir/$ip: $!\n";
$URL = ;
close(TMP);
unlink("$dir/$ip");
print "Location: http://$URL\n\n";
} else {
open(F,"$dir/$file") || die "Error opening file $dir/$file: $!\n";
while (chop($line = )) {
($url,$img,$freq,$sfreq) = split(/%%/,$line);
push(@imgs,"$img");
push(@urls,"$url");
#push(@freqs,$freq);
#push(@sfreqs,$sfreq);
for ($i=0; $i<$freq; $i++) {
push(@imgs,"$img");
push(@urls,"$url");
}
}
close(F);
# pick a random seed to randomly display banner
srand(time|$ip);
$random = int(rand(@imgs));
#$action = 'url';
if ( $action eq 'img' ) {
$flag = $urls[$random];
$URL = "$homeurl/$imgs[$random]";
} elsif ( $action eq 'url' ) {
$flag = $URL = $urls[$random];
}
#print "Content-type: text/html\n\n";
# make sure that the browser displays the new image, stupid Netscape
# version 2.*,1.* do not do that.
print "Pragma: no-cache\n";
# redirect URL
print "Location: http://$URL\n\n";
# write the URL so that when user click on the link, will bring
# to the exact page!
open(TMP,">$dir/$ip") || die "Error opening file $dir/$ip: $!\n";
print TMP $flag;
close(TMP);
}