#!/usr/local/bin/perl # # Name :cronad # Author :Kang SoonLai # Date :Mon Oct 27 17:14:42 CST 1997 v1.0 # Path :/home/skang/public_html/programs/cronad # Email :skang@granax.com # WWW :http://www.granax.com/~skang # # this script is useful when you don't have cgi access but you have cron # access. It can then be used to rotate your banner on your pages. # it looks for a begin tag, , and an end tag, # , and replace all the texts inside with a new # random banner text. it uses the same stat file as cookiead uses. # this makes sure that it compatible with all my ad programs. # # how to use: # 1. Create a dir call it banner in your public_html dir. This is your # $dir var. If your server doesn't use public_html as the default user # html dir, then you have modify the $dir var below. # # 2. Create a dir in banner dir that you have just created, call it pics. # this dir contains all the banner imgs. Then modify the $IMGURL to # where your banners pics are. # # 3. Create 2 stat files. One call it stat, and another one with a .cron # extension, stat.cron. Stat file has a format like this: (if you have # used cookiead or ad, then u can use the same stat file.) # url1%%banner_img_name%% # www.granax.com/~skang%%skang.jpg%%1 # notice that url doesn't include the http:// str, just the domain name. # and banner_img_name is the file name of banner itself. and finally # the weight of the banner. If you want the banner to show up more # often on your pages, then put a higher number there. # stat.cron contains the dirs to where cronad should process. Cronad # opens the file, and go to the dirs specified, and process all .html # files. # # 4. Finally, you need to submit this to a cron job if you decide to. If # don't have access to a cron, then you might have to do it manually. # Here is a simple command edit a cron file: # crontab -e # then put this line if you want to have it do it every hour for u: # 20 * * * * /users/skang/bin/cronad # * Please provide the full patht to your cronad program. # # I hope this will help you to make some profit from banner advertising. # ############################################################################## require "imgsize"; # tag to parse $tag ="banner"; # the base url to the banner images, this is the url where all the banner pics # located. $IMGURL = "http://freenshare.granax.com/pics/ads"; # dir to where the banner info located. contains the stat file, pics dir, # tmp/ip files, etc. # $dir = "$ENV{HOME}/public_html/banner"; $PICSDIR = "$dir/pics"; $default = "freenshare.granax.com"; # this file contains the information about the banner to be displayed # it has the format -> url%%img%%frequency%%showed_frequency # ** currently, the showed_freq is not implemented yet. # $file = "stat" unless $file; # # generate a random img and url to go to, and set cookie no matter the browser # supports cookie or not. if there is no HTTP_COOKIE defined, then create a # file so that the action 'url' will be able to get the url. open(F,"$dir/$file") || die "Error opening file $dir/$file: $!\n"; while (chop($line = )) { my($url,$img,$freq,$sfreq) = split(/%%/,$line); push(@imgs,"$img"); push(@urls,"$url"); for ($i=0; $i<$freq; $i++) { push(@imgs,"$img"); push(@urls,"$url"); } } close(F); srand(time|$$); open(DF,"$dir/$file.cron") || die "Error opening file $dir/$file.cron: $!\n"; # process all dirs specified in $file.cron while ($dir=) { chop $dir; # process all files in dir. opendir(DIR,$dir) || die "Can't open $dir: $!\n"; readdir DIR; readdir DIR; @files = readdir DIR; while ($f = pop @files) { # only process file with html extension. if ($f =~ /html$/) { open(PF,"$dir/$f") || die "Error opening file $dir/$f: $!\n"; open(NF,">$dir/$f.new") || die "Error opening file $dir/$f.new: $!\n"; $changed = 0; print "\nprocessing $dir/$f\n"; # parse file, and insert banner link. while ($l=) { if ( $l eq "\n") { while ( ($l1=) && ($l1 ne "\n") ) {} my $link = &mk_link; print NF <
$link
EOH ; $changed = 1; } else { print NF $l; } } # remove temp file, or mv temp file if ($changed) { system "mv -f $dir/$f.new $dir/$f"; } else { unlink "$dir/$f.new"; } } } } sub mk_link { # pick a random seed to randomly display banner my $random = int(rand(scalar(@imgs))); my $cookie = $urls[$random]; my $pic = "$imgs[$random]"; my $size = &getsize("$PICSDIR/$pic"); #print "\n"; return ""; }