#!/bin/perl -w require "adtracklib.pl"; print "Content-type: text/html\n\n"; print "Adtrack Admin Program\n"; &ReadFormInput; $site = $INPUT{'site'}; if ($INPUT{'site'}) { &InitSiteVars($INPUT{'site'}); } else { print "You need to set the site variable."; exit; } $admincgi = $gsAdminCgiUrl ."?site=$site"; #print $admincgi; $bannerLocation = "$gsInstallDir/sites/$site/banner.loc"; open (BANNERLOC,$bannerLocation) || &ReturnCGIError("500","Banner File Error","Could not open banner location file $bannerLocation"); ($banner_local,$banner_url) = ; chop($banner_local); chop($banner_url); close BANNERLOC; $adfile = "$ads_dir/adinfo.txt"; if (-e $adfile) {&InitializeAdArrays;} if ($INPUT{'edit'}) { &edit; } elsif ($INPUT{'del'}) { &del; } elsif ($INPUT{'editfinal'}) { &editfinal; } elsif ($INPUT{'delfinal'}) { &delfinal; } elsif ($INPUT{'printoptions'}) { &printoptions; } else {&printoptions;} exit; sub printoptions { print "

Administering site: $site

"; print "

The following options are available:\n"; print "

\n"; print "\n"; print ""; print " "; print " "; print "
"; print "
\n"; print "\n"; print "

"; print "\n"; print "

"; print "
\n"; print "\n "; print "

"; #List advertisements print ""; foreach $advertiser (sort (keys %display_vars)) { &ReadDisplayVars($advertiser); print "\n"; } print "
NameTypeIn Rotation?
$advertiser$type$rotating
"; &Footer; exit; } ################################### EDIT ADS sub edit { $name = $INPUT{'adselected'}; print "

$name advert should appear here:

\n"; if ($display_vars{$name}) { &ReadDisplayVars($name); &PrintAdvert($name); } else { $rotating = "on"; $type = "banner"; } print "\n"; print "

Info for $name advert:

\n"; print "

Name:
Change the name to copy these settings to a new ad name
\n"; print "

\n"; print "\n"; print "\n"; print "\n"; $cents = $cents *100; print "\n"; print "\n"; print "\n"; print "\n"; $image =~ s/^$banner_url\///o; #strip banner url from image (will put it back it editfinal) print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Rotating?
Ad Type:"; print "
Sponsor:
Cents Per Click:
Adjustment:
Advert URL:
Text:
Image Name:
User ID:
Password:
Stats Page:
Banner Farm:

\n"; print "\n"; print "\n"; print "

\n"; &Footer; exit; } sub editfinal { $name = $INPUT{'editad'}; $rotating = $INPUT{'rotating'}; $sponsor = $INPUT{'sponsor'}; $type = $INPUT{'type'}; $cents = ($INPUT{'cents'}/100); $adjustment = $INPUT{'adjustment'}; $url = $INPUT{'url'}; $text = $INPUT{'text'}; $image = $INPUT{'image'}; $userid = $INPUT{'userid'}; $password = $INPUT{'password'}; $stats = $INPUT{'stats'}; $banners = $INPUT{'banners'}; #$text =~ s/\s//g; # strip carriage returns from textlink $text =~ s/\n//g; # strip newlines from textlink $text =~ s/\cM//g; # strip newlines from textlink open(GRAPHIC, "$banner_local/$image") || &ReturnCGIError(300,"getHeight", "Can't open graphic $banner_local/$image $!"); binmode(GRAPHIC); # necessary for non UNIX perl. just leave it. if ($image =~ /\.gif$/i) { $height = &gifHeight(GRAPHIC); $width= &gifWidth(GRAPHIC); } elsif ($image =~ /\.jpg$|.jpeg$/i) { $height = &jpegHeight(GRAPHIC); $width = &jpegWidth(GRAPHIC); } close (GRAPHIC); $image = "$banner_url/$image"; #some idiotproofing needs to be added here. #but I am yanking this in order to try out the textlinks code #unless ( $url && $cents ) { # print "

You didn't provide all of the necessary information to allow "; # print "addition of the $editad advert!

\n"; # &Footer; # exit; #} $display_vars{$name} = "$name|$rotating|$sponsor|$type|$cents|$adjustment|$url|" . "$text|$image|$height|$width|$userid|$password|$stats|$banners"; &write_display_vars(); &ReadDisplayVars($name); print "

Advert Updated

\n"; print "

The $name advert will appear as shown below:

\n"; &PrintAdvert($name); print "

\n"; print" \n"; print "\n"; print "

\n"; &Footer; exit; } ########################## DELETE ADS sub del { $name = $INPUT{'adselected'}; unless ($display_vars{$name}) { print "Invalid Advert Name"; print "\n"; print "

There is no advert with the name $INPUT{'delad'} "; print " on the list!

\n"; &Footer; exit; } print "Advert Delete Page"; print "\n"; &PrintAdvert($name); print "
\n"; print "

Are you sure you want to delete the "; print "$name advert from $site?\n"; print "\n"; print "\n"; print "\n"; print "

\n"; &Footer; exit; } sub delfinal { print "Deleting..."; print "\n"; $delad = $INPUT{'delad'}; $savedString = $display_vars{$delad}; delete $display_vars{$delad}; &write_display_vars(); # Move the advert info to the oldads file, # so you can still get info about it later if you need to. open (OLDADS, ">>$ads_dir/oldads.txt") || &ReturnCGIError(500, "Ad Log Error", "Could not open ad file $ads_dir/oldads.txt in delfinal."); print OLDADS "$savedString\n"; close (OLDADS); print "
\n"; print "\n"; print" \n"; print "

\n"; &Footer; } sub Footer { print "\n"; } sub write_display_vars { #delete the old file unlink "$ads_dir/adinfo.txt"; open (DISPLAY, ">$ads_dir/adinfo.txt") || &ReturnCGIError(500, "Ad Log Error", "Could not open ad file $ads_dir/adinfo.txt in write_display_vars ."); foreach $key (sort keys(%display_vars)) { print DISPLAY "$display_vars{$key}\n"; } close (DISPLAY); } sub LockFile { local(*FILE) = @_; local($TrysLeft) = 10; if ($UseLocking) { while ($TrysLeft--) { $lockresult = eval("flock(FILE,$exclusive_lock)"); if ($@) { $UseLocking = 0; last; } if (!$lockresult) { select(undef,undef,undef,0.1); } else { last; } } } if ($TrysLeft >= 0) { return 0; } else { return -1; } } sub UnlockFile { local(*FILE) = @_; if ($UseLocking) { flock(FILE,$unlock_lock); } } sub commas { local($_)=@_; 1 while s/(.*\d)(\d\d\d)/$1,$2/; $_; } #- Size Gifs ----------------------------------------------------------------# sub gifHeight { # return a string of height and width tags for a gif. # this code "adapted" from: # http://rajiv.org/programming/gifsize.txt my ($GIF) = @_; my ($w, $w2, $h, $h2, $gifwidth, $gifsize, $type) = () ; read ($GIF, $type, 3); seek ($GIF, 6, 0); read ($GIF, $w, 1); read ($GIF, $w2, 1); read ($GIF, $h, 1); read ($GIF, $h2, 1); $height = ord ($h) + ord ($h2) * 256; return $height; } sub gifWidth { # return a string of height and width tags for a gif. # this code "adapted" from: # http://rajiv.org/programming/gifsize.txt my ($GIF) = @_; my ($w, $w2, $h, $h2, $gifwidth, $gifsize, $type) = () ; read ($GIF, $type, 3); seek ($GIF, 6, 0); read ($GIF, $w, 1); read ($GIF, $w2, 1); read ($GIF, $h, 1); read ($GIF, $h2, 1); $width = ord ($w) + ord ($w2) * 256; return $width; } #----------------------------------------------------------------------------# #----------------------------------------------------------------------------# # jpegsize : gets the width and height (in pixels) of a jpeg file # Andrew Tong, werdna@ugcs.caltech.edu February 14, 1995 # modified slightly by alex@ed.ac.uk sub jpegHeight { my ($JPEG) = @_; my ($done) = 0; my ($size) = ""; read($JPEG, $c1, 1); read($JPEG, $c2, 1); if( !((ord($c1) == 0xFF) && (ord($c2) == 0xD8))){ print "This is not a JPEG!"; $done=1; } while (ord($ch) != 0xDA && !$done) { # Find next marker (JPEG markers begin with 0xFF) # This can hang the program!! while (ord($ch) != 0xFF) { read($JPEG, $ch, 1); } # JPEG markers can be padded with unlimited 0xFF's while (ord($ch) == 0xFF) { read($JPEG, $ch, 1); } # Now, $ch contains the value of the marker. if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) { read ($JPEG, $junk, 3); read($JPEG, $s, 4); ($a,$b,$c,$d)=unpack("C"x4,$s); $height=$a<<8|$b; $done=1; } else { # We **MUST** skip variables, since FF's within variable names are # NOT valid JPEG markers read ($JPEG, $s, 2); ($c1, $c2) = unpack("C"x2,$s); $length = $c1<<8|$c2; if( ($length < 2) ){ print "Erroneous JPEG marker length"; $done=1; } else { read($JPEG, $junk, $length-2); } } } return $height; } sub jpegWidth { my ($JPEG) = @_; my ($done) = 0; my ($size) = ""; read($JPEG, $c1, 1); read($JPEG, $c2, 1); if( !((ord($c1) == 0xFF) && (ord($c2) == 0xD8))){ # print "This is not a JPEG!"; $done=1; } while (ord($ch) != 0xDA && !$done) { # Find next marker (JPEG markers begin with 0xFF) # This can hang the program!! while (ord($ch) != 0xFF) { read($JPEG, $ch, 1); } # JPEG markers can be padded with unlimited 0xFF's while (ord($ch) == 0xFF) { read($JPEG, $ch, 1); } # Now, $ch contains the value of the marker. if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) { read ($JPEG, $junk, 3); read($JPEG, $s, 4); ($a,$b,$c,$d)=unpack("C"x4,$s); $width= $c<<8|$d; $done=1; } else { # We **MUST** skip variables, since FF's within variable names are # NOT valid JPEG markers read ($JPEG, $s, 2); ($c1, $c2) = unpack("C"x2,$s); $length = $c1<<8|$c2; if( ($length < 2) ){ print "Erroneous JPEG marker length"; $done=1; } else { read($JPEG, $junk, $length-2); } } } return $width; } #----------------------------------------------------------------------------#