#!C:/perl/bin/perl
############################################
## ##
## WebAdverts (Admin) ##
## by Darryl Burgdorf ##
## (e-mail burgdorf@awsd.com) ##
## ##
## version: 1.52 ##
## last modified: 2/13/98 ##
## copyright (c) 1998 ##
## ##
## latest version is available from ##
## http://awsd.com/scripts/ ##
## ##
############################################
# COPYRIGHT NOTICE:
#
# Copyright 1998 Darryl C. Burgdorf. All Rights Reserved.
#
# This program is being distributed as shareware. It may be used and
# modified by anyone, so long as this copyright notice and the header
# above remain intact, but any usage should be registered. (See the
# program documentation for registration information.) By using this
# program you agree to indemnify Darryl C. Burgdorf from any liability.
#
# Selling the code for this program without prior written consent is
# expressly forbidden. Obtain permission before redistributing this
# program over the Internet or in any other medium. In all cases
# copyright and header must remain intact.
# VERSION HISTORY:
#
# 1.52 02/10/98 Fixed handling of "raw mode" entries
# Fixed "daily stats from group display" problem
# Fixed minor new glitch in "show all" code
# Fixed data truncation in "CreditID" subroutine
# Fixed failure of default banner to increment counter
# 1.51 02/09/98 Fixed miscalc in display of exchange credits
# 1.50 02/08/98 Added "expires" header to non-SSI banners
# Eliminated need for separate SSI/non-SSI config files
# Removed referer & agent info from non-SSI log file
# Added "page" designation to non-SSI log file
# Made *all* user updates subject to admin approval
# Made necessity of *any* admin approval optional
# Made banners optional for "display only" exchanges
# Added exchange buttons to SSI-generated output
# Allowed "show all" to display members w/o exposures
# Made groups on admin page, like advert names, links
# Corrected group function password handling
# Fixed occasional "div by zero" bug in daily averages
# Cleaned up ("mod_perlized") code
# Various "appearance" modifications
# 1.44 01/15/98 OK, finally, the last bit of the bug is squashed...
# Also fixed bug that zeroed credits upon admin approval
# And fixed bug in multiple group "split" code
# Set intro screens so that "Enter" key works
# Corrected year refs from 19XX to 1900+XX
# Removed first day from daily average calculation
# 1.43 01/02/98 *Really* finished the bug fix
# 1.42 01/02/98 Finished fixing the create/edit bug
# Added "name already in use" error message
# 1.41 01/02/98 Fixed new bug which prevented editing
# 1.40 01/01/98 Closed glaring access security hole
# Separated admin and user intro screens
# Added $header_file to complement $footer_file
# Fixed minor typo in generated non-SSI HTML
# 1.34 12/15/97 *Really* fixed "admin approval" buttons
# 1.33 12/13/97 Added parentheses around new "sort" commands
# Added "status" print before "location" prints
# (Thanks to Rodger Zeisler for pointing out the need)
# 1.32 12/10/97 Allowed listing of zones in exchange edit form
# Added ability to generate master e-mail list
# Allowed "zone" settings to override advert settings
# Stripped QUERY_STRING info from nonssi.log file
# Reduced nonssi.log maintenance to fifteen minutes
# Corrected remaining file access-related typo
# Fixed bug that disabled "admin approval" buttons
# 1.31 11/16/97 Improved "page" designations
# Put exchange name in page titles and headers
# Revised main entry screen (yet again)
# Corrected a few typos
# 1.30 11/14/97 Removed backup system completely
# Split adcount.txt into adcount.txt and adlist.txt
# Added ability for exchange members to self-update
# Eliminated "drop down" advert list
# Added "default" banner designation
# Allowed for "mailto" banner URLs
# Made start date configurable rather than automatic
# Added dummy "page" designation to non-SSI URLs
# Added advertiser name and e-mail to data file
# Added optional IP address logging
# Added $bodyspec and $footer_file variables
# Added "direct" edit links to main admin page
# Revised page-to-page linkages
# Sorted advert list on main admin page
# Allowed for "LE"-style exchange buttons
# Shortened default daily stats list to one month
# Altered "exps per day" to reflect only past week
# 1.21 09/07/97 Fixed "fall-thru after click-thru" problem
# Fixed problem with displays not giving exposures
# Improved handling of "bad" click-thrus
# Reorganized main advert edit screen
# Removed SSI elements from admin banner displays
# Added zone to info maintained in non-SSI log file
# Squashed "text reverts to bottom" bug
# "Dealt with" extra (blank) adcount.txt lines
# Various minor tweaks
# 1.20 08/31/97 Added non-SSI (banner exchange) option
# Added basing of exposures on banner exchange "ratio"
# Further simplified config files
# Made backups optional
# Added optional flock() control of semaphore files
# Fixed minor typo in banner display
# Fixed lock-related typos in "gotoad" subroutine
# 1.14 08/25/97 Rewrote file locking & backup "from the ground up"
# (Replaced flock() system with semaphore system)
# Abbreviated some table headings
# Closed minor security hole
# 1.13 08/17/97 Fixed bug in initialization of group list
# Revised backup system
# 1.12 08/16/97 Added logging of daily stats
# Allowed for each zone to cycle distinctly
# Added ability to "group" adverts
# Removed link texts from "show all" display
# Changed TARGET def to general link attribute def
# Added auto backups as supplement to file locking
# "Cleaned up" initial password entry
# Revised "look" of admin pages
# Improved parsing of URLs
# Really fixed "BORDER=0" & "WEIGHT=0" bugs
# 1.11 07/26/97 Fixed "exclusive access/read only" lock bug
# Fixed bug causing display script to "lose" extra URLs
# Fixed "BORDER=0" bug
# Fixed minor time display-related bugs
# Changed URL checking to allow commas
# 1.10 07/19/97 FIRST SHAREWARE RELEASE
# Consolidated various display scripts into one
# Added ability to "zone" adverts via separate configs
# Revamped "weighting" system from scratch
# Allowed definition of individual expiration criteria
# Allowed for multiple banners in a single advert
# Made URL, link text, height and width optional
# Added ability to put text above *or* below banner
# Allowed designation of TARGET and BORDER attributes
# Added "raw" HTML banner code option
# Fixed minor bugs in total exposure count
# Trapped for bad characters in new advert names
# Trapped for previously-problematical commas
# Moved "delete" from main page to advert edit page
# Improved handling of administrative password
# Lots of other miscellaneous small improvements
# 1.04 05/27/97 Added new script to display all active banners
# Put variable assignments in configuration script
# Added option to define max click-thrus
# Added ability to "weight" banners
# Added start date to log info for each advert
# Added "exposures per day" to advert info display
# Improved error handling
# Added basic URL format validation
# Numerous "tweaks" and format adjustments
# 1.03 05/22/97 Added configurable link text
# Added new script to put banners in CGI pages
# Fixed bugs introduced by previous file locking "fix"
# Corrected style of main password input box
# Minor bug fixes in display code
# 1.02 04/20/97 Fixed file locking!
# Added actual click-thru ratios to display
# Revised display of percentages
# 1.01 04/03/97 Allowed for automatic creation of necessary text files
# Closed hole that allowed spaces in file names
# 1.00 04/01/97 Initial "public" release
# The following variables should be set to define the locations
# and URLs of various files, as explained in the documentation,
# and to "tailer" the functioning of the script.
$adverts_dir = "c:/Inetpub/data/webadverts";
$admin_cgi = "http://www.fourteenernet.com/cgi-bin/ads/admin.pl";
$nonssi_cgi = "http://www.fourteenernet.com/cgi-bin/ads/ads.pl";
%nonssi_cgis = (
'large','http://www.fourteenernet.com/cgi-bin/ads/largeads.pl',
'small','http://www.fourteenernet.com/cgi-bin/ads/smallads.pl',
'creede','http://www.fourteenernet.com/cgi-bin/ads/creedeads.pl',
);
$UseLocking = 1;
$LogIP = 0;
$AllowUserEdit = 0;
$RequireAdminApproval = 1;
$DefaultDisplayRatio = 2;
$bodyspec = "BGCOLOR=\"#ffffdd\" TEXT=\"#000000\"";
$header_file = "";
$footer_file = "";
$ExchangeName = "";
$ExchangeURL = "";
$ExchangeLogo = "";
$ExchangeLogoHeight = 40;
$ExchangeLogoWidth = 40;
$ExchangeBannerHeight = 130;
$ExchangeBannerWidth = 130;
# NOTHING BELOW THIS LINE NEEDS TO BE ALTERED!
@months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
$version = "1.52";
print "Content-type: text/html\n\n";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}." ".$value; }
else { $INPUT{$name} = $value; }
}
if ((-e "$adverts_dir/adcount.txt")
&& !(-e "$adverts_dir/adlist.txt")) {
&UpdateAdList;
}
$time = time;
if ($ENV{'QUERY_STRING'} =~ /reginfo/) { ®info; }
elsif ($ENV{'QUERY_STRING'} =~ /admin/) { &adminintro; }
elsif ($INPUT{'register'}) { ®ister; }
elsif ($INPUT{'edit'}) { &edit; }
elsif ($INPUT{'UserEdit'}) { &UserEdit; }
elsif ($INPUT{'groupedit'}) { &groupedit; }
elsif ($INPUT{'del'}) { &del; }
elsif ($INPUT{'delgroup'}) { &delgroup; }
elsif ($INPUT{'newpass'}) { &newpass; }
elsif ($INPUT{'resetcount'}) { &resetcount; }
elsif ($INPUT{'editfinal'}) { &editfinal; }
elsif ($INPUT{'editgroupfinal'}) { &editgroupfinal; }
elsif ($INPUT{'delfinal'}) { &delfinal; }
elsif ($INPUT{'delgroupfinal'}) { &delgroupfinal; }
elsif ($INPUT{'reviewone'} eq "Review All Accounts") { &reviewall; }
elsif ($INPUT{'reviewone'}) { &reviewone; }
elsif ($INPUT{'dailystats'}) { &dailystats; }
elsif ($INPUT{'iplog'}) { &iplog; }
elsif ($INPUT{'listemail'}) { &ListEmail; }
else { &userintro; }
sub userintro {
&Header("VistaWorks Ad Administration","VistaWorks Ads Administrative Access");
print "
To view the status of any single account ";
print "or defined group,\n";
print " enter its name and password:
\n";
print "
\n";
if ($AllowUserEdit) {
print "
To add your site ";
print "to the exchange,\n";
print " enter the name and password ";
print "you wish to use:
\n";
print "
\n";
}
&Footer;
}
sub adminintro {
$lockerror = &LockFile("adpassword.txt");
if ($lockerror) {
&Error_File("adpassword.txt");
}
open (PASSWORD, "$adverts_dir/adpassword.txt");
$password = ;
close (PASSWORD);
&UnlockFile("adpassword.txt");
chop ($password) if ($password =~ /\n$/);
if (!$password) {
&InitializePassword;
}
&Header("VistaWorks Ads Admin","VistaWorks Ads Administrative Access");
print "
To view the status of all accounts and ";
print "access Web Ads main administrative functions,\n";
print " input the administrative password:
\n";
print "
\n";
&Footer;
}
sub InitializePassword {
&Header("WebAdverts","Enter an Administrative Password!");
print "
Before you can do anything else, ";
print "you'll need to set your administrative password. ";
print "This will allow you to access the admin functions, ";
print "create and edit accounts, review statistics, etc. ";
print "Please enter your desired password below. ";
print "(Enter it twice.)\n";
print "
\n";
&Footer;
}
sub ConfirmAdminPassword1 {
$lockerror = &LockFile("adpassword.txt");
if ($lockerror) {
&Error_File("adpassword.txt");
}
open (PASSWORD, "$adverts_dir/adpassword.txt");
$password = ;
close (PASSWORD);
&UnlockFile("adpassword.txt");
chop ($password) if ($password =~ /\n$/);
if (!$password) {
&InitializePassword;
}
if ($INPUT{'cryptword'}) {
$newpassword = $INPUT{'cryptword'};
}
elsif ($INPUT{'password'}) {
$newpassword = crypt($INPUT{'password'}, "aa");
}
else {
&Header("WebAdverts Error!","No Password!");
print "
";
($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,$isdst) = localtime($time);
if ($hour < 10) { $hour = "0".$hour; }
if ($min < 10) { $min = "0".$min; }
$year += 1900;
print "(These figures are accurate as of ";
print "$hour:$min on $mday $months[$mon] $year.";
($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,$isdst) = localtime($starttime);
if ($hour < 10) { $hour = "0".$hour; }
if ($min < 10) { $min = "0".$min; }
$year += 1900;
print " Since $hour:$min on $mday $months[$mon] $year, ";
print "there have been a total of ",&commas($exposures);
print " advert exposures";
$time = $time - $starttime + 1;
if ($time > 86400) {
$average = int(($exposures/($time/86400))+.5);
print ", for an average of ",&commas($average);
print " exposures per day";
}
print ".)
\n";
if (-e "$adverts_dir/adnew.txt") {
$lockerror = &LockFile("adnew.txt");
if ($lockerror) {
undef @newlines;
}
else {
open (COUNT, "+<$adverts_dir/adnew.txt");
@newlines = ;
close (COUNT);
&UnlockFile("adnew.txt");
}
}
if (@newlines > 0) {
print "
";
print "The Following Accounts Await ";
print "Administrative Approval:";
print "
\n";
@sortednewlines = sort (@newlines);
foreach $newad (@sortednewlines) {
chop ($newad) if ($newad =~ /\n$/);
next if (length($newad) < 2);
$lockerror = &LockFile("$newad.txt");
if ($lockerror) {
print "
[ File Error: ";
print "$newad.txt ]
\n";
next;
}
open (DISPLAY, "+<$adverts_dir/$newad.txt");
@lines = ;
close (DISPLAY);
&UnlockFile("$newad.txt");
foreach $line (@lines) {
chop ($line) if ($line =~ /\n$/);
}
($max,$shown,$visits,$url,$image,$height,$width,
$alt,$pass,$text,$start,$weight,$zone,
$border,$target,$raw,$displayratio,$username,$email,
$displayzone) = @lines;
print "\n";
}
print "
\n";
}
if (-e "$adverts_dir/groups.txt") {
$lockerror = &LockFile("groups.txt");
if ($lockerror) {
undef @grouplines;
}
else {
open (COUNT, "+<$adverts_dir/groups.txt");
@grouplines = ;
close (COUNT);
&UnlockFile("groups.txt");
}
}
if (@grouplines > 0) {
print "
";
print "The Following Groups Have Been Defined:";
print "\n";
print "
\n";
foreach $group (@grouplines) {
chop ($group) if ($group =~ /\n$/);
next if (length($group) < 2);
$lockerror = &LockFile("$group.grp");
if ($lockerror) {
print "
";
print "
";
print "[ File Error: $group.grp ]";
print "
\n";
}
else {
open (DISPLAY, "+<$adverts_dir/$group.grp");
@members = ;
close (DISPLAY);
&UnlockFile("$group.grp");
$grppassword = $members[0];
print "
Your account currently has no assigned banner.\n";
}
if ($displayratio || $displaycount || !($image || $raw)) {
if ($displaycount<1) { $displaycount = "0"; }
print "
To date, you have displayed ";
print &commas($displaycount)," banners ";
print "on your site";
if ($displayratio > 0) {
$earnings = int($displaycount/$displayratio);
print ", earning ";
print &commas($earnings)," exposures ";
print "for your own advert on other sites. ";
print "(You earn an exposure for each ";
print "$displayratio display";
if ($displayratio > 1) { print "s"; }
print ".)\n";
}
else {
print ".\n";
}
print "
The HTML code on your pages should look similar ";
print "to the following. (It's OK to alter the general ";
print "appearance to match the "look" of your ";
print "site, but don't change the addresses!)\n";
print "
<P ALIGN=CENTER>";
if ($ExchangeLogo) {
if ($ExchangeURL) {
print "<A HREF="$ExchangeURL">";
}
print "<IMG SRC="$ExchangeLogo"";
if ($ExchangeLogoHeight && $ExchangeLogoWidth) {
print " HEIGHT=$ExchangeLogoHeight";
print " WIDTH=$ExchangeLogoWidth";
}
if ($ExchangeName) {
print " ALT="$ExchangeName"";
}
print ">";
if ($ExchangeURL) {
print "</A>";
}
}
if (%nonssi_cgis) {
foreach $setzone (keys %nonssi_cgis) {
if ($displayzone eq $setzone) {
$nonssi_cgi = $nonssi_cgis{$setzone};
}
}
}
print "<A HREF="$nonssi_cgi?";
print "advert=NonSSI&page=XX">";
print "<IMG SRC="$nonssi_cgi?";
print "ID=$name&page=XX"";
if ($ExchangeBannerHeight && $ExchangeBannerWidth) {
print " HEIGHT=$ExchangeBannerHeight";
print " WIDTH=$ExchangeBannerWidth";
}
if ($ExchangeName) {
print " ALT="$ExchangeName"";
}
print "></A>";
if ($ExchangeName) {
print "<BR><SMALL>";
if ($ExchangeURL) {
print "<A HREF="$ExchangeURL">";
}
print "$ExchangeName";
if ($ExchangeURL) {
print "</A>";
}
print "</SMALL>";
}
print "</P>\n";
print "
Note that the "page" designations ";
print "should be different on each page (or at each ";
print "location) from which you call a banner. Simply ";
print "replace the "XX"s with unique numbers, ";
print "as in "page=04". (Both "XX"s ";
print "in the same banner call, of course, should be ";
print "replaced with the same number!) Even if you're ";
print "only calling a single banner on a single page, you ";
print "need to include the "page" designations, ";
print "as without them, the script will not function ";
print "correctly.\n";
}
print "
\n";
&Footer;
}
sub iplog {
&ConfirmUserPassword;
$lockerror = &LockFile("$INPUT{'advert'}.ips");
if ($lockerror || !(-e "$adverts_dir/$INPUT{'advert'}.ips")) {
&Header("WebAdverts Error!","No IP Log!");
print "
";
print "Sorry, but it seems ";
print "there is no IP address log file available ";
print "for the $INPUT{'advert'} account!
\n";
&Footer;
}
open (DISPLAY, "+<$adverts_dir/$INPUT{'advert'}.ips");
@lines = ;
close (DISPLAY);
&UnlockFile("$INPUT{'advert'}.ips");
&Header("VistaWorks","Web Ads Administrative Display");
print "
IP Address Log for the ";
print "$INPUT{'advert'} Account:\n";
print "
The following log file lists ";
print "the IP addresses of those individuals who ";
print "have seen or clicked on this advert's banner ";
print "in the past 24 hours. Each ";
print "line displays the time of the exposure (E) ";
print "or click-thru (C), and the IP ";
print "address of the responsible party. ";
print "If a single IP address shows up in the list ";
print "repeatedly, it is most likely because ";
print "the individual either saw the banner ";
print "on several different pages or ";
print "hit the "reload" button.\n";
print "
(Please note that deleting the group will ";
print "not delete or otherwise affect the adverts ";
print "themselves. Only the ability to view all their stats ";
print "on a single page will be gone!)