#!/usr/local/bin/perl
##################################################################
# Advertisement Banner Rotator V2.0
#
# This program is distributed as freeware. We are not
# responsible for any damages that the program causes
# to your system. It may be used and modified free of
# charge, as long as the copyright notice
# in the program that give me credit remain intact.
# If you find any bugs in this program. It would be thankful
# if you can report it to us at cgifactory@cgi-factory.com.
# However, that email address above is only for bugs reporting.
# We will not respond to the messages that are sent to that
# address. If you have any trouble installing this program,
# olease feel free to post a message on our CGI Support Forum.
# Selling this script is absolutely forbidden and illegal.
##################################################################
#
# COPYRIGHT NOTICE:
#
# Copyright 1999-2000 CGI-Factory.com TM
# A subsidiary of SiliconSoup.com LLC
#
#
# Web site: http://www.cgi-factory.com
# E-Mail: cgifactory@cgi-factory.com
#
# Advertisement Banner Rotator V2.0 is protected by the copyright
# laws and international copyright treaties, as well as other
# intellectual property laws and treaties.
###################################################################
#Nothing more needs to be modified below this line, unless you feel
#like doing it.
require "cfg.cgi";
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;
$value =~ s/\n/ /g;
$request{$name} = $value;
}
print "Content-type: text/html\n\n";
############## tell the script what the action is
if ($request{'action'} eq "viewdata") {
&view_data;
exit;
}
if ($request{'action'} eq "view_all") {
&view_all;
exit;
}
if ($request{'action'} eq "addnew") {
&addnew;
exit;
}
if ($request{'action'} eq "preview") {
&preview;
exit;
}
if ($request{'action'} eq "pmodify") {
&preview_modify;
exit;
}
if ($request{'action'} eq "modify") {
&modify;
exit;
}
if ($request{'action'} eq "getid") {
&getid;
exit;
}
if ($request{'action'} eq "pdelete") {
&pdelete;
exit;
}
if ($request{'action'} eq "creset") {
&creset;
exit;
}
if ($request{'action'} eq "erase") {
&erase;
exit;
}
if ($request{'action'} eq "comdelete") {
&comdelete;
exit;
}
if ($request{'action'} eq "deletenow") {
&deletenow;
exit;
}
&exitnow;
########################################################## view an entry
sub view_data {
&vpassword;
$id= $request{'id'};
if ($id=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
open (tid, "<$datalocation/tcount.txt") or &error("Unable to open the count file");
if ($flock eq "y") {
flock tid, 2;
}
$tid=;
close(tid);
$id= $request{'id'};
if ($id > $tid or !$id) {
print "member not in database";
exit;
}
open (data, "<$datalocation/$id.txt") or &exitnow;
if ($flock eq "y") {
flock data, 2;
}
@data=;
close(data);
$percent= @data[10];
$chance= int($percent * 100);
$currenttime=time();
$expire=@data[7];
$newtime=$expire-$currenttime;
if ($newtime < 0) {
$extime="expired!";
}
else {
$extime= $newtime/86400;
}
print "ID:$id
";
print "Name: @data[0]
";
print "Url: @data[1]
";
print "Src: @data[2]
";
print "Name: @data[3]
";
print "Height: @data[4]
";
print "Width: @data[5]
";
print "Alt Text: @data[6]
";
print "Expire after \"$extime\" days
";
print "Total times displayed: @data[8]
";
print "Total times clicked: @data[9]
";
print "Chance been clicked: $chance%
";
exit;
}
########################################################## view all entries
sub view_all {
&vpassword;
open (tid, "<$datalocation/tcount.txt") or &error("Unable to open the count file");
if ($flock eq "y") {
flock tid, 2;
}
$tid=;
close(tid);
$tid++;
$found=0;
$i=1;
if ($i=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
READ: for ($i; $i<$tid; $i++) {
open ($i, "<$datalocation/$i.txt") or next READ;
@$idata=<$i>;
close($i);
$found++;
print "
\n";
}
print "Total result(s) found: $found";
exit;
}
########################################################## preview new entries
sub preview {
&vpassword;
print "The following information will be added:
";
print "Name: $request{'name'}
";
print "Url: $request{'url'}
";
print "Src: $request{'src'}
";
print "Text: $request{'text'}
";
print "Width: $request{'w'}
";
print "Height: $request{'h'}
";
print "Alt text: $request{'alttext'}
";
print "Expire after \"$request{'expire'}\" days
";
print "";
exit;
}
########################################################### preview before modify an entry
sub preview_modify {
&vpassword;
print "The following information will be changed:
";
print "Name: $request{'name'}
";
print "Url: $request{'url'}
";
print "Src: $request{'src'}
";
print "Text: $request{'text'}
";
print "Width: $request{'w'}
";
print "Height: $request{'h'}
";
print "Alt text: $request{'alttext'}
";
print "Expire after \"$request{'expire'}\" days
";
print "";
exit;
}
########################################################### modify
sub modify {
&vpassword;
$id=$request{'id'};
if ($id=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
$currenttime=time();
$expireday= $request{'expire'};
$expiretime= $expireday*86400;
$newtime= $expiretime+$currenttime;
open (data, ">$datalocation/$id.txt") or &error("Unable to open the data file for writing");
if ($flock eq "y") {
flock data, 2;
}
print data "$request{'name'}\n";
print data "$request{'url'}\n";
print data "$request{'src'}\n";
print data "$request{'text'}\n";
print data "$request{'w'}\n";
print data "$request{'h'}\n";
print data "$request{'alttext'}\n";
print data "$newtime\n";
print data "$request{'exposures'}\n";
print data "$request{'hits'}\n";
print data "$request{'percent'}\n";
close(data);
print "The following information had been changed:
\n";
print "Name: $request{'name'}
";
print "Url: $request{'url'}
";
print "Src: $request{'src'}
";
print "Text: $request{'text'}
";
print "Width: $request{'w'}
";
print "Height: $request{'h'}
";
print "Alt text: $request{'alttext'}
";
print "Expire after $request{'expire'} days
";
exit;
}
########################################################### comfirm reseting data
sub creset {
&vpassword;
print "Are you sure you want to do this? The tracking record for banner NO.$request{'id'} will be reset to 0
\n";
print "\n";
exit;
}
########################################################### reset data
sub erase {
&vpassword;
$id=$request{'id'};
if ($id=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
open (bdata, "<$datalocation/$id.txt") or &error("Unable to open the banner data for reading");
if ($flock eq "y") {
flock bdata, 2;
}
@bdata=;
close(bdata);
@reset=("0\n","0\n","0\n");
splice(@bdata, 8,3, @reset);
open (bdata2, ">$datalocation/$id.txt") or &error("Unable to open the banner data for reading");
if ($flock eq "y") {
flock bdata2, 2;
}
print bdata2 @bdata;
close(bdata2);
print "Done\n";
exit;
}
########################################################### add new entries
sub addnew {
&vpassword;
open (id, "<$datalocation/tcount.txt") or &error("Unable to open the count file");
if ($flock eq "y") {
flock id, 2;
}
$id=;
close(id);
$id++;
open (wid, ">$datalocation/tcount.txt") or &error("Unable to write to the count file");
if ($flock eq "y") {
flock wid, 2;
}
print wid"$id";
close(wid);
$currenttime=time();
$expireday= $request{'expire'};
$expiretime= $expireday*86400;
$newtime= $expiretime+$currenttime;
open (data, ">$datalocation/$id.txt") or &error("Unable to open the data file for writing");
if ($flock eq "y") {
flock data, 2;
}
print data "$request{'name'}\n";
print data "$request{'url'}\n";
print data "$request{'src'}\n";
print data "$request{'text'}\n";
print data "$request{'w'}\n";
print data "$request{'h'}\n";
print data "$request{'alttext'}\n";
print data "$newtime\n";
print data "0\n";
print data "0\n";
print data "0\n";
close(data);
print "The following information had been added:
\n";
print "Name: $request{'name'}
";
print "Url: $request{'url'}
";
print "Src: $request{'src'}
";
print "Text: $request{'text'}
";
print "Width: $request{'w'}
";
print "Height: $request{'h'}
";
print "Alt text: $request{'alttext'}
";
print "Expire after \"$request{'expire'}\" days
";
exit;
}
################################################# get entry of an ID
sub getid {
&vpassword;
$id= $request{'id'};
if ($id=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
open (tid, "<$datalocation/tcount.txt") or &error("Unable to open the count file");
if ($flock eq "y") {
flock tid, 2;
}
$tid=;
close(tid);
$id= $request{'id'};
if ($id > $tid or !$id) {
print "member not in database";
exit;
}
open (data, "<$datalocation/$id.txt") or &exitnow;
if ($flock eq "y") {
flock data, 2;
}
@data=;
close(data);
$currenttime=time();
$expire=@data[7];
$newtime=$expire-$currenttime;
if ($newtime < 0) {
$extime="expired!";
}
else {
$extime= $newtime/86400;
}
print "\n";
exit;
}
################################################# delete a member
sub pdelete {
&vpassword;
$id= $request{'id'};
if ($id=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
open (tid, "<$datalocation/tcount.txt") or &error("Unable to open the count file");
if ($flock eq "y") {
flock tid, 2;
}
$tid=;
close(tid);
$id= $request{'id'};
if ($id > $tid or !$id) {
print "member not in database";
exit;
}
open (data, "<$datalocation/$id.txt") or &exitnow;
if ($flock eq "y") {
flock data, 2;
}
@data=;
close(data);
$currenttime=time();
$expire=@data[7];
$newtime=$expire-$currenttime;
if ($newtime < 0) {
$extime="expired!";
}
else {
$extime= $newtime/86400;
}
print "\n";
exit;
}
############################################ comfirm delete
sub comdelete {
&vpassword;
print "\n";
exit;
}
############################################ deletenow
sub deletenow {
&vpassword;
if ($request{'id'}=~ tr/;<>*|`&$!#()[]{}:'"//) {
print "Security Alert! Action canceled.
\n";
print "Please don't use weird symbols\n";
exit;
}
unlink("$datalocation/$request{'id'}.txt");
print "Entry NO. $request{'id'} has been deleted!\n";
exit;
}
############################################ no action
sub exitnow {
print "member not in database";
exit;
}
sub error{
$errors = $_[0] ;
print "An error has occured, the error is $errors
\n";
print "$!\n";
exit;
}
###### password
sub vpassword{
open (PASS,"$datalocation/pass.dat") || &error("Unable to open the password file");
if ($flock eq "y") {
flock PASS, 2;
}
$pass = ;
close(PASS);
$request{'password'}=~ tr/A-Z/a-z/;
$pass2 = crypt($request{'password'}, "MM");
unless ($pass eq "$pass2") {
$timenow=localtime();
print "Incorrect logon. Use your back button to try again.
";
print "The password you entered is incorrect.
";
print "The following information has been sent to the webmaster of the web site
";
print "Your Information: ";
print "Password: $request{'password'}
";
print "";
print "