Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to un-encode an encoded script? 1

Status
Not open for further replies.

CraigHappy

Technical User
Jun 1, 2005
92
GB
Hi

I purchased a perl/cgi script and now the seller is no longer trading and does not provide support for the script anymore.

The code, I have been told from this forum is 'encoded'.
eg. the script mostly works, but there is one bit that doesn't seem to, so I think it needs some tweaking, but it looks like this -

#!/usr/bin/perl --
require "config.pl";
$AXJXSXOXHXJXGXJXYXJXGXDXRXYXZXXYXZDXFXGXBVXAXQX="13l10l36l97Xl103l101l110l116l61l36l69l78l86l+123l39l72l84lZ84l80l95l85l83l69lX82l95l65l71l69l78l84-l39l125l=59Zl13l10l36l114l101l102l117l114l108l61l36l69l78l86=l123l39l72l84l84l80l95lX82l69l70l69l82l69l82l39l125l59l13l10l40l36l-83l101l99l111
l110l100l44l32l36lZ77l105l110l117l116l101l44l32l36l72+l111l117l114l44l32l36l68lZ97l121l44l32l36l77l111l110l116l104l44l32l36=l89l101l97l114l44Xl32l36l87l101l101l107l68l97l121l+44l32l36l68lZ97l121l79l102l89l101lX97l114l44l32l13l10l36-l73l115l=

Is there a way to make the script readable again?

Many thanks, Craig.
 
Is that actually the script?
Is that all of it?
If not, can you post a link to the whole thing so that we can see how it is encrypted??


Trojan.
 
I have pretty much decoded the first.
I have pasted the code below but it appears to have a few corruptions. I'm not sure if I screwed up a bit or if there was something lost in your pasting to a webpage.
Anywayz, this might give you a start.
If you want, I can look at doing the second one too although I'd like to know first if you could create a link to a zip or something to guarantee I have precisely the correct source.

Code:
$agent=$ENV{'HTTP_USER_AGENT'};
$refurl=$ENV{'HTTP_REFERER'};
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear,
$IsDST) = localtime(time);$Year=$Year + 1900;
$Month++;
if (length($Month) == 1){$Month="0$Month"}
if (length($Day) == 1){$Day="0$Day"}
$newdate="$Month/$Day/$Year";
$logfile="$logdir/linklist";
$dailylog="$logdir/$Month\_$Day\_$Year.log";
$randomise="randomlist";
my $random=0;
$link=$ENV{'QUERY_STRING'};
use CGI;
my $q=new CGI;
$link=$q->unescape($link);
$link=~s/\s+$//g;
$link=~s/link=//i;
$link=~tr/A-Z/a-z/;
$link=~s!%3a!:!;
if ($link=~/^multi=/i)
{
$link=~s/multi=//i;
$random=1;
&randomit($link);
}
$refd="$link.log";
$refd=~s![URL unfurl="true"]http://!!ig;[/URL]
$refd=~s!http:/!!ig;
$refd=~s!/!_!g;
$reflog="$refdir/$refd";
if ($link=~/^http:\//i){
$recordlink=$link;
$recordlink=~s!^[URL unfurl="true"]http://!!i;[/URL]
$recordlink=~s!^http:/!!i;
$found=0;
open (FILE,"<$logfile") || print "couldn't open $logfile";
flock(FILE, 2) ;
@lines = <FILE>;
close (FILE);
flock(FILE, 8) ;
open (FILE3,">$logfile") || print "couldn't open $logfile";
flock(FILE3, 2) ;
foreach $line (@lines)
{
chomp $line;
($date,$url,$countit = split/\|/,$line;
if ($url eq $recordlink)
        {
        $found=1;
        $countit++;
        $line="$newdate|$url|$countit";
        }
print FILE3 "$line\n";
}
close (ILE3);
flock(FILE3, 8) ;
if (!$found)
        {
        open (FILE4,">>$logfile") || print "couldn't open $logfile";
        flock(FILE4, 2) ;
        print FILE4 "$newdate|$recordlnk|1\n";
        close (FILE4);
        flock(FILE4, 8) ;
        }
&daily;
&printref;
if($email_site_on_click_dud)
{&emailsite($recordlink)}
if ($link=~/^http:\//i && $link !~/^http:\/\//i)
{$link=~s!^http:/![URL unfurl="true"]http://!i;}[/URL]
print "Location: $link\n\n";
}
else {pr
nt "Location: $forwarderror/\n\n";}
sub daily
{
unless (-e $dailylog)
{
if($emailstats){&mailit}
open (F,">$dailylog");
close (F);
chmod 0666, $dailylog;
}
$found=0;
o
 en (FILE,"<$dailylog") || print "couldn't open $dailylog";
flock(FILE, 2) ;
@lines2 = <FILE>;
close (FILE);
flock(FILE, 8) ;
$recordlink=$link;
$recordlink=~s![URL unfurl="true"]http://!!;[/URL]
open (ILE3,">$dailylog") || print "couldn't open $dailylog";
flock(FILE3, 2) ;
foreach $line (lines2)
{
chomp $line;
($date,$url,$countit) = split/\|/,$line;
if ($url eq $recordlink)
        {
        $found=1;
        $countit++;
        $line="$newdate|$url|$counti
                                    ";
        }
print FILE3 "$line\n";
}
close (FILE3);
flock(FILE3, 8) ;
if (!$found)
       {
        open (FILE4,">>$dailylog") || print "couldn't open $dailylog";
        flockFILE4, 2) ;
        print FILE4 "$newdate|$recordlink|1\n";
        close (FILE4);
        flock(FILE4, 8) ;
        }
}
sub printref
{
if(!$refurl){$refurl="no referrer informaion";}
unless (-e $reflog){open (FILED,">$reflog");
close (FILED);
chmod 0666, $reflog;

$foundref=0;
open (FILE2,"<$reflog") || print "couldn't open $reflog";
flock(FILE2, 2 ;
@refit = <FILE2>;
close (FILE2);
flock(FILE2, 8) ;
open (FILE4,">$reflog") || print "coldn't open $reflog";
flock(FILE4, 2) ;
foreach $line (@refit)
{
chomp $line;
($date,url,$countit) = split/\|/,$line;
if ($url eq $refurl)
        {
        $foundref=1;
        $countit++;
        $line="$newdate|$url|$countit";
        }
print FILE4 "$line\n";
}
close (FILE4);
flock(FILE4, 8) ;
if (!$foundref)
        {
        open (FILE5,">>$reflog") || print "couldn't open $reflog";
        flock(FILE5, 2) ;
        print FILE5 "$newdate|$refurl|1\n";
        close (FILE5);
        flock(FILE5, 8) ;
        }
}
sub randomi
{
my (@random,$lastclicked);
$c="";
open (FILE2,"<$randomise") || print "couldn't open $randomise";
flock(FILE2, 2) ;
@dostuff = <FILE2>;
close (FILE2);
flock(FILE2, 8) ;
forach $dostuff(@dostuff)
{
if ($dostuff=~/lastclicked/)
{
$lastclicked=$dostuff;
$latclicked=~s/lastclicked//;
next;
}
push (@random,$dostuff);
}
$c=@random;
$c=int (rand ($c));
$link=$random[$c];
$link=~s/.*\|(.*)\|.*\|.*/$1/;
chomp $link;
$recordlink=$link;
$recordlink=~s![URL unfurl="true"]http://!!;[/URL]
open (FILE4,">$randomise") || print "couldn't open $rand
                                                        mise";
flock(FILE4, 2);
print FILE4 $lastclicked;
foreach $ran (@random)
{
chomp $ran;
($date,$url,$countit,undef) = split/\|/,$ran;
$url=~s![URL unfurl="true"]http://!!;[/URL]
if ($url eq $recordlink)
        {
        $countit++;
        $ran="$newdate|[URL unfurl="true"]http://$url|$countit|lastclicke[/URL]
";
        }
print FILE4 "$ran\n";
}
close (FILE4);
flock(FILE4, 8) ;
}
sub mailit
{
my @sendit=();
my $bodymessage="";
$totalcount=0;
open (MF, "daterecord");
$logf=<MF>;
close (MF);
open (MFF,">daterecord");
print MFF $dailylog;
close (MFF);
$displaydate=$logf;
$displaydate=~s!logs/!!g;
$displaydate=~s!_!/!g;
$displaydate=~s!\.log!!g;
open FILED,"<$logf" || print "";
flock(FILED, 2) ;
@users2 = <FILED>;
chomp(@users2);
flock(FILE, 8);
close (FILED);
&sortit(@users2);
foreach $line2 (@users2)
{
chomp $line2;
($dae,$url,$countit) = split/\|/,$line2;
$totalcount=($totalcount + $countit);
$bodymessage.= qq[$countit\t$url\n];
}
open (MAIL,"|$mailprog -t") || print "";
print MAIL "To: $memail\n";
print MAIL "From: $myemail\n";
print MAIL "Subject: Tracker Stats - $displaydae\n\n";
print MAIL "Below you will find a summary of the links clicked for $displaydae:\n\n";
print MAIL "$bodymessage\n\n";
close (MAIL);
}
sub sortit
{
my @pre = map { [$_, split /\|/ ] } @users2;
my @post = sort custom @pre;
@users2 = map { $_->[0] } @pot;
@users2=reverse(@users2);
sub custom {
$a->[3] <=> $b->[3];
}
}
sub emailsite
{$checkemail=$_[0];
$checkemail=~s!^[URL unfurl="true"]www\.!!i;[/URL]
open (FILE2,"<email_list") || print "cannot open file";
flock(FILE2, 2) ;
@emails = <FILE2>;
flock(FILE2, 8) ;
close (FILE2);
foreach $emails(@emails)
{
chomp $emails;
($site,$siteemail)=split(/\|/,$emails);
if ($refurl ne "no referrer information")
{$theref = "The link was clicked from: $refurl";}
if ($site eq $checkemail)
        {
        open (MAIL,"|$mailprog -t") || print "";
        print MAIL "To: $siteemail\n";
        print MAIL "From: $myemail\n";
        print MAIL "Su  ject: $subject\n\n";
        print MAIL "$body\n\n";
        print MAIL "Link clicked: htt
                                     ://$checkemail\n";
        print MAIL $theref;
        print MAIL "\n\n";
        close (MAIL);
        }
}
}


Trojan.
 
Hi Trojan

Many thanks again for your help with this.
Here's a zipped file of the two cgi files -

The script basically creates a log for every external web link that is clicked on from my site and then should email the owner of that web link to advise them that it has been clicked on.
But at the moment, no emails are being able to be sent?
Have tested it on two hosting servers with no luck, so that's why I think the problem lies in the script?

Cheers, Happy.
 
Sorry Trojan

Problem with the free hosting for downloading, I'll get it sorted and put up the new web link for downloading.
 
tracker.cgi:
Code:
$agent=$ENV{'HTTP_USER_AGENT'};
$refurl=$ENV{'HTTP_REFERER'};
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear,
$IsDST) = localtime(time);
$Year=$Year + 1900;
$Month++;
if (length($Month) == 1){$Month="0$Month"}
if (length($Day) == 1){$Day="0$Day"}
$newdate="$Month/$Day/$Year";
$logfile="$logdir/linklist";
$dailylog="$logdir/$Month\_$Day\_$Year.log";
$randomise="randomlist";
my $random=0;
$link=$ENV{'QUERY_STRING'};
use CGI;
my $q=new CGI;
$link=$q->unescape($link);
$link=~s/\s+$//g;
$link=~s/link=//i;
$link=~tr/A-Z/a-z/;
$link=~s!%3a!:!;
if ($link=~/^multi=/i)
{
$link=~s/multi=//i;
$random=1;
&randomit($link);
}
$refd="$link.log";
$refd=~s![URL unfurl="true"]http://!!ig;[/URL]
$refd=~s!http:/!!ig;
$refd=~s!/!_!g;
$reflog="$refdir/$refd";
if ($link=~/^http:\//i)
{
$recordlink=$link;
$recordlink=~s!^[URL unfurl="true"]http://!!i;[/URL]
$recordlink=~s!^http:/!!i;
$found=0;
open (FILE,"<$logfile") || print "couldn't open $logfile";
flock(FILE, 2) ;
@lines = <FILE>;
close (FILE);
flock(FILE, 8) ;
open (FILE3,">$logfile") || print "couldn't open $logfile";
flock(FILE3, 2) ;
foreach $line (@lines)
{
chomp $line;
($date,$url,$countit) = split/\|/,$line;
if ($url eq $recordlink)
        {
        $found=1;
        $countit++;
        $line="$newdate|$url|$countit";
        }
print FILE3 "$line\n";
}
close (FILE3);
flock(FILE3, 8) ;
if (!$found)
        {
        open (FILE4,">>$logfile") || print "couldn't open $logfile";
        flock(FILE4, 2) ;
        print FILE4 "$newdate|$recordlink|1\n";
        close (FILE4);
        flock(FILE4, 8) ;
        }
&daily;
&printref;
if ($email_site_on_click_dud)
{&emailsite($recordlink)}
if ($link=~/^http:\//i && $link !~/^http:\/\//i)
{$link=~s!^http:/![URL unfurl="true"]http://!i;}[/URL]
print "Location: $link\n\n";
}
else {print "Location: $forwarderror/\n\n";}
sub daily
{
unless (-e $dailylog)
{
if($emailstats){&mailit}
open (F,">$dailylog");
close (F);
chmod 0666, $dailylog;
}
$found=0;
open (FILE,"<$dailylog") || print "couldn't open $dailylog";
flock(FILE, 2) ;
@lines2 = <FILE>;
close (FILE);
flock(FILE, 8) ;
$recordlink=$link;
$recordlink=~s![URL unfurl="true"]http://!!;[/URL]
open (FILE3,">$dailylog") || print "couldn't open $dailylog";
flock(FILE3, 2) ;
foreach $line (@lines2)
{
chomp $line;
($date,$url,$countit) = split/\|/,$line;
if ($url eq $recordlink)
        {
        $found=1;
        $countit++;
        $line="$newdate|$url|$countit";
        }
print FILE3 "$line\n";
}
close (FILE3);
flock(FILE3, 8) ;
if (!$found)
        {
        open (FILE4,">>$dailylog") || print "couldn't open $dailylog";
        flock(FILE4, 2) ;
        print FILE4 "$newdate|$recordlink|1\n";
        close (FILE4);
        flock(FILE4, 8) ;
        }
}
sub printref
{
if(!$refurl){$refurl="no referrer information";}
unless (-e $reflog){open (FILED,">$reflog");
close (FILED);
chmod 0666, $reflog;}
$foundref=0;
open (FILE2,"<$reflog") || print "couldn't open $reflog";
flock(FILE2, 2) ;
@refit = <FILE2>;
close (FILE2);
flock(FILE2, 8) ;
open (FILE4,">$reflog") || print "couldn't open $reflog";
flock(FILE4, 2) ;
foreach $line (@refit)
{
chomp $line;
($date,$url,$countit) = split/\|/,$line;
if ($url eq $refurl)
        {
        $foundref=1;
        $countit++;
        $line="$newdate|$url|$countit";
        }
print FILE4 "$line\n";
}
close (FILE4);
flock(FILE4, 8) ;
if (!$foundref)
        {
        open (FILE5,">>$reflog") || print "couldn't open $reflog";
        flock(FILE5, 2) ;
        print FILE5 "$newdate|$refurl|1\n";
        close (FILE5);
        flock(FILE5, 8) ;
        }
}
sub randomit
{
my (@random,$lastclicked);
$c="";
open (FILE2,"<$randomise") || print "couldn't open $randomise";
flock(FILE2, 2) ;
@dostuff = <FILE2>;
close (FILE2);
flock(FILE2, 8) ;
foreach $dostuff(@dostuff)
{
if ($dostuff=~/lastclicked/)
{
$lastclicked=$dostuff;
$lastclicked=~s/lastclicked//;
next;
}
push (@random,$dostuff);
}
$c=@random;
$c=int (rand ($c));
$link=$random[$c];
$link=~s/.*\|(.*)\|.*\|.*/$1/;
chomp $link;
$recordlink=$link;
$recordlink=~s![URL unfurl="true"]http://!!;[/URL]
open (FILE4,">$randomise") || print "couldn't open $randomise";
flock(FILE4, 2);
print FILE4 $lastclicked;
foreach $ran (@random)
{
chomp $ran;
($date,$url,$countit,undef) = split/\|/,$ran;
$url=~s![URL unfurl="true"]http://!!;[/URL]
if ($url eq $recordlink)
        {
        $countit++;
        $ran="$newdate|[URL unfurl="true"]http://$url|$countit|lastclicked";[/URL]
        }
print FILE4 "$ran\n";
}
close (FILE4);
flock(FILE4, 8) ;
}
sub mailit
{
my @sendit=();
my $bodymessage="";
$totalcount=0;
open (MF, "daterecord");
$logf=<MF>;
close (MF);
open (MFF,">daterecord");
print MFF $dailylog;
close (MFF);
$displaydate=$logf;
$displaydate=~s!logs/!!g;
$displaydate=~s!_!/!g;
$displaydate=~s!\.log!!g;
open FILED,"<$logf" || print "";
flock(FILED, 2) ;
@users2 = <FILED>;
chomp(@users2);
flock(FILED, 8);
close (FILED);
&sortit(@users2);
foreach $line2 (@users2)
{
chomp $line2;
($date,$url,$countit) = split/\|/,$line2;
$totalcount=($totalcount + $countit);
$bodymessage.= qq[$countit\t$url\n];
}
open (MAIL,"|$mailprog -t") || print "";
print MAIL "To: $myemail\n";
print MAIL "From: $myemail\n";
print MAIL "Subject: Tracker Stats - $displaydate\n\n";
print MAIL "Below you will find a summary of the links clicked for $displaydate:\n\n";
print MAIL "$bodymessage\n\n";
close (MAIL);
}
sub sortit
{
my @pre = map { [$_, split /\|/ ] } @users2;
my @post = sort custom @pre;
@users2 = map { $_->[0] } @post;
@users2=reverse(@users2);
sub custom {
$a->[3] <=> $b->[3];
}
}
sub emailsite
{
$checkemail=$_[0];
$checkemail=~s!^[URL unfurl="true"]www\.!!i;[/URL]
open (FILE2,"<email_list") || print "cannot open file";
flock(FILE2, 2) ;
@emails = <FILE2>;
flock(FILE2, 8) ;
close (FILE2);
foreach $emails(@emails)
{
chomp $emails;
($site,$siteemail)=split(/\|/,$emails);
if ($refurl ne "no referrer information")
{$theref = "The link was clicked from: $refurl";}
if ($site eq $checkemail)
        {
        open (MAIL,"|$mailprog -t") || print "";
        print MAIL "To: $siteemail\n";
        print MAIL "From: $myemail\n";
        print MAIL "Subject: $subject\n\n";
        print MAIL "$body\n\n";
        print MAIL "Link clicked: [URL unfurl="true"]http://$checkemail\n";[/URL]
        print MAIL $theref;
        print MAIL "\n\n";
        close (MAIL);
        }
}
}

admin.cgi
Code:
$totalcount="";
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
if (length($Day) eq "1"){$Day="0$Day"}
if (length($Month) eq "1"){$Month="0$Month"}
my @months=('January','February','March','April','May','June','July','August','September','October','November','December');
$Year=$Year + 1900;
&parse;
my $script=$ENV{'SCRIPT_NAME'};
my $host1=$ENV{'HTTP_HOST'};
my $host2=$ENV{'SCRIPT_NAME'};
$showhost=0;
$showhostlink="";
if ($host1 && $host2){$showhost=1}
if (!$host1){$host1 = "domain.com"}
if (!$host2){$host2 = "/path_to/tracker.cgi"}
my $host="$host1$host2";
$host=~s/admin/tracker/i;
if ($showhost){$showhostlink=qq[<p><a class="headings" href=[URL unfurl="true"]http://$host?multi=rotate[/URL] target="_blank">test rotator</a></p>];}
$action=$input{'action'};
my $time = time;
my $donemessage = "";
&head;
if (!$input{'user'}){$input{'user'}=$input{'username'}}
print qq~<form action=$script method=post><input type=hidden name=user value=$input{'user'}>~;
DIRECT:
{
if ($input{'removeemail'}){&removeemail}
($action eq "settings") && do {&settings};
($action eq "settings2") && do {&settings2};
($action eq "delete") && do {&logs};
($action eq "rotateman") && do {&rotateman};
($action eq "addrotate") && do {&addrotate};
($action eq "removelink") && do {&removelink};
($action eq "searchlogs") && do {&searchlogs};
($action eq "viewlogs") && do {&logs};
($action eq "viewreflogs") && do {&viewreflogs};
($action eq "openreflog") && do {&openreflog($input{'showlog'})};
($action eq "openlog") && do {&openlog($input{'showlog'})};
($action eq "admin") && do {&admin};
($action eq "logon") && do {&checkpass};
($action eq "setpass") && do {&passad};
($action eq "dellog") && do {&delete};
($action eq "addemail") && do {&addemail};
($action eq "addemail2") && do {&addemail2};
($action eq "") && do {&logged};
($action eq "deletelinklist") && do {&deletelinklist};
($input{'user'} eq "") && do {&logged};
}
sub logs
{
PICK:
{
($action eq "delete") && do {$method2="dellog",$text="delete"};
($action eq "viewlogs") && do {$method2="openlog",$text="view"};
}
    opendir(DIR, "$logdir") || print "can't opendir $logdir";
    @dots = readdir(DIR);
    closedir DIR;
print qq~<table cellpadding=2 cellspacing=0 border=0 width=100%><tr><td class="two" colspan=2 width=100%
align=center>Please select a file to $text:</td></tr>
<tr><td width=100% align=center><br><br><table cellpadding=2 cellspacing=0 border=0>~;
$count=0;
foreach $dot(@dots)
        {
        chomp $dot;
        if ($dot !~m/\.log/i){next}
        $dot=~/(.*)_(.*)_(.*)\.log/;
        $mmonth=$1;
        $dday=$2;
        $yyear=$3;
        $mmonth=~s/^0//;
        $mmonth2=$mmonth;
        $mmonth2--;
        $dday=~s/^0//;
if ($action eq "delete"){$port="<input type=checkbox name=delfile value=\"$dot|$method$months[$mmonth2]\_$dday\_$yyear\">"}
if($action eq "viewlogs"){$port="<input type=radio name=showlog value=\"$dot|$method$months[$mmonth2]\_$dday\_$yyear\">"}
if ($count==0)
        {
        print qq~<tr><td class="tablerow">$port$months[$mmonth2] $dday $yyear</td>\n~;
        $count=1;
        }
else
        {
        print qq~<td class="tablerow" style=\"padding-left:40px;\">$port$months[$mmonth2] $dday $yyear</td></tr>\n~;
        $count=0;
        }
        }
if ($count){print "</tr>"}
if($action eq "viewlogs")
{print qq[<tr><td class="tablerow" colspan=2 align=center><br><br><input type=radio name=showlog value=\"linklist|Full_Link_List\"> full list</td></tr>];}
print qq~<tr><td colspan=2 style="padding-top:20px;"><center><input type=hidden name=action value=$method2><input
type=submit value=" $text log file " class="submit"></form></td></tr></table></td></tr></table>~;
&bottom;
exit;
} # end sub logs
sub openlog
{
$file=$_[0];
$file=~/(.*)\|(.*)/;
$displaydate=$2;
$logf=$1;
$logfile="$logdir/$logf";
$displaydate=~s/_/ /g;
open FILED,"<$logfile" || print "there is no data for this day";
flock(FILED, 2) ;
@users2 = <FILED>;
chomp(@users2);
flock(FILED, 8);
close (FILED);
if ($input{'search'}){$users=0}
else {$users=scalar(@users2)}
if ($users == 1)
        {
         $plural="link";
        $plural3="result";
          }
else
{
$plural="links";
$plural3="results";
}
$sortby="";
$sortby2="";
$trs="";
$try="";
$tre="";
if ($trowit){
$trs="<tr>";
$try="</tr>";
}
else{
$tre="</tr>";}
if ($input{'showlog'}=~/linklist/i){
$datelink= qq[&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openlog&sort=date&showlog=$input{'showlog'}>date</a>];
}
if ($input{'linkurl'}){$linkk="&linkurl=on";}
if (!$input{'search'})
{
if ($trowit){
$sortby=qq[<td valign=top align=right><span class="headings"><nobr>sort by:&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openlog$linkk&sort=link&showlog=$input{'showlog'}>link</a>&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openlog$linkk&sort=clicks&showlog=$input{'showlog'}>clicks</a>$datelink</nobr></span></td>];}
else {
$sortby2=qq[<td valign=top align=right><span class="headings"><nobr>sort by:&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openlog$linkk&sort=link&showlog=$input{'showlog'}>link</a>&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openlog$linkk&sort=clicks&showlog=$input{'showlog'}>clicks</a>$datelink</nobr></span></td>];}
}
print qq~
<p>
<table cellpadding=5 cellspacing=0 width=100% border=0><tr><td width=100% height=100% valign=top>
<table cellpadding=5 cellspacing=0 width=100% border=0><tr>
<td>
<table cellpadding=0 cellspacing=0><tr><td><input type=submit class="submit" value=" search this log ">
<input type=hidden name=user value=$input{'user'}>
<input type=hidden name=action value=openlog></td></tr>
<tr><td style="padding-top:5px;">
<input type=hidden name=showlog value="$input{'showlog'}">
<input type=text name=search value="$input{'search'}" class="searchbox" size=21></td></tr></table>
</td>$sortby$try
</form>~;
if ($input{'search'})
{
print qq~$trs<form action=$script method=post><td valign=top>
<input type=hidden name=user value=$input{'user'}>
<input type=hidden name=action value=openlog>
<input type=hidden name=showlog value="$input{'showlog'}">
<input type=submit class="submit" value="show full list"></td></form>~;
$try
}
if ((!$input{'linkurl'}) && (!$input{'search'}))
{
print qq~$trs<form action=$script method=post><input type=hidden name=showlog value="$input{'showlog'}">
<input type=hidden name=action value=openlog>
<input type=hidden name=linkurl value=linkurl>
<td valign=top>
<input type=submit value="show as link" class="submit">
</td></form>~;
$try
}
print qq~$trs<form action=$script method=post><td valign=top>
<input type=hidden name=action value=admin><input type=submit class="submit" value=" admin page ">
<br></td></form>
~;
if ($input{'showlog'}=~/linklist/i)
{
print qq~$trs<form action=$script method=post><td valign=top>
<input type=hidden name=action value=deletelinklist><input type=submit class="submit" value=" delete this list ">
<br></td></form>
~;
$try
}
print $sortby2;
print qq~$tre</table></td></tr>~;
if (!$input{'search'}){print qq~<tr><td class="headings">$users $plural for $displaydate</td></tr>~;}
else
{
print qq~
<tr><td valign=top><p class="headings">Search results for <span
class="misc">$input{'search'}</span></p></td></tr></form>~;
}
print qq~<tr><td valign=top><center><table border=1 bordercolor=$bordercolor cellpadding=$cellpadding cellspacing=$cellspacing>
<tr><td class="two">date</td><td class="two"><nobr>link</td><td class="two">clicks</td></tr>~;
if ($input{'sort'} eq "link")
{
$sortnum=2;
&sortit;}
elsif ($input{'sort'} eq "clicks")
{
$sortnum=3;
&sortit;}
elsif ($input{'sort'} eq "date")
{
$sortnum=1;
&sortit;}
foreach $line2 (@users2)
{
$font="";
chomp $line2;
if ($input{'search'}){if ($line2 !~m/$input{'search'}/ig){next}}
($date,$url,$countit) = split/\|/,$line2;
$totalcount=($totalcount + $countit);
if (($input{'linkurl'}) || ($input{'search'})){$url=qq~<a href=$url target="_blank">$url</a>&nbsp;~;}
print qq~<tr><td class="tablerow" valign=\"top\">$date</td><td
class="tablerow" valign=\"top\">$url</td><td class="tablerow" valign=\"top\">$countit</tr>\n~;
if ($input{'search'}){$users++}
}
print "</table>";
if ($totalcount == 1)
        {
         $plural2="click"
          }
else
{
$plural2="clicks";
}
if ($input{'search'}){print qq~<p class="misc"><b>$users $plural3 found</b></p>~;}
print qq~<p class="misc"><b>$totalcount total $plural2</b></p>
</td></tr></table>
~;
print qq~<br><br><div class ="layer1" align=center>&copy;2002 <a href=[URL unfurl="true"]http://www.usersonline.net[/URL] target="_blank">usersonline.net</a></div>~;
&bottom;
exit;
} # end sub openlog
sub logged
{
print qq~<table border=0 width=100% height=100%>
~;
if (!-e $password_location)
        {
        print qq~<tr><td class="headings" colspan=2 align=center><br><br><b>Please set your admin
username/password:</b><br><br>
        <input type=hidden name="action" value="setpass"></td></tr>~;
        }
else
        {
        print qq~<tr><td class="headings" colspan=2 align=center><br><br><b>Please enter your admin
username/password:</b><br><br>
        <input type=hidden name="action" value="logon"></td></tr>~;
        }
print qq~
<tr><td width=100% align=center valign=top height=100%>
<table cellpadding=2 cellspacing=0 border=0><tr><td colspan=2 class="tablerow"><b>@_</b></td></tr>
<tr><td class="headings"><b>username: </b></td><td>
<input type=text name=username value="admin"></td></tr>
<tr><td class="headings"><b>password: </b></td><td>
<input type=password name=password value="admin"></td></tr>
<tr><td></td><td align=center>
<input type=submit class="submit" name=admin value=" Proceed ">
</form></td></tr></table></td></tr></table>~;
&bottom;
exit;
}
sub searchlogs
{
    opendir(DIR, "$logdir") || print "can't opendir $logdir";
    @dots = readdir(DIR);
    closedir DIR;
@dots = sort ( @dots);
$users=0;
print qq~
<p>
<table cellpadding=5 cellspacing=0 width=100% border=0><tr><td width=100% height=100% valign=top>
<table cellpadding=0 cellspacing=0 border=0>
<tr><td><table><tr><td><input type=submit class="submit" value=" search again "><input type=hidden name=user value=$input{'user'}></td></tr>
<tr><td style="padding-top:5px;">
<input type=hidden name=action value=searchlogs>
<input class="searchbox" type=text name=searchall size=18>
</td></tr></form>
<form action=$script method=post></table></td>$try
$trs<td valign=top><table><tr><td>
<input type=hidden name=action value=admin><input type=submit class="submit" value=" admin page ">
<br></td></tr></table></td></tr></table></td></tr></form>
~;
print qq~
<tr><td valign=top><p class="headings">Search results for <span
class="misc">$input{'searchall'}</span></p></td></tr></form>~;
print qq~<tr><td valign=top><center><table border=1 bordercolor=$bordercolor cellpadding=$cellpadding cellspacing=$cellspacing>
<tr><td class="two">date</td><td class="two"><nobr>link</td><td
class="two">clicks</td></tr>~;
foreach $dot(@dots)
{
$file=$dot;
$file=~/(.*)_(.*)_(.*)\.log/i;
$mmonth=$1;
$dday=$2;
$yyear=$3;
$mmonth=~s/^0//;
$dday=~s/^0//;
$mmonth2=$mmonth;
$mmonth2--;
if ($dot!~/\.log/i){next}
$logfile="$logdir/$dot";
open FILED,"<$logfile" || print "there is no data for this day";
flock(FILED, 2) ;
@users2 = <FILED>;
chomp(@users2);
flock(FILED, 8) ;
close (FILED);
foreach $line2 (@users2)
{
$font="";
chomp $line2;
if ($line2 !~m/$input{'searchall'}/ig){next}
($date,$url,$countit) = split/\|/,$line2;
$totalcount=($totalcount + $countit);
print qq~<tr><td class="tablerow"
valign=\"top\" align=left>$date</td><td class="tablerow" valign=\"top\">$url</td><td class="tablerow"
valign=\"top\">$countit</td></tr>\n~;
$users++;
}
} # end foreach $dot
print "</table>";
if ($users == 1)
        {
         $plural="link";
         $plural3="result";
          }
else
{
$plural="links";
$plural3="results";
}
if ($totalcount == 1)
        {
         $plural2="click";
          }
else
{
$plural2="clicks";
}
print qq~<p class="misc"><b>$users $plural3 found</b></p><p class="misc"><b>$totalcount total $plural2</b></p>~;
print qq~</td></tr></table>~;
print qq~<br><br><div class ="layer1" align=center>&copy;2002 <a href=[URL unfurl="true"]http://www.usersonline.net[/URL]
target="_blank">usersonline.net</a></div>~;
&bottom;
exit;
}
sub admin
{
print qq~<center><table cellpadding=2 cellspacing=0 border=0 width=100%>
<tr><td class="two" width=100% align=center>Please choose:</td></tr>
<tr><td width=100% align=center valign=top style="padding-left:7px;padding-top:7px;" class="tablerow">$donemessage
<table align=center cellpadding=5 border=0>
<tr><td class="tablerow"><input type=radio name=action value=viewlogs checked> <b>view logs</b></td></tr>
<tr><td class="tablerow"><input type=radio name=action value=delete> <b>delete logs</b></td></tr>
<tr><td class="tablerow"><input type=radio name=action value=viewreflogs> <b>view referrer logs</b></td></tr>
<tr><td class="tablerow"><input type=radio name=action value=rotateman> <b>random rotator manager</b></td></tr>
~;
if (($email_site_on_click) || ($input{'email_site_on_click'}))
{
print qq~<tr><td class="tablerow"><input type=radio name=action value=addemail> <b>manage site emails</b></td></tr>
~;
}print qq~
<tr><td class="tablerow"><input type=radio name=action value=settings> <b>change settings</b></td></tr>
</table></td></tr>
<tr><td style="padding-top:20px;" align=center><input type=submit value=" choose action "
class="submit"></form></td></tr>
<tr><td style="padding-top:20px;" align=center class="headings"><b>or</b><br><form action=$script method=post><input
type=text name=searchall class="searchbox"></td></tr>
<tr><td align=center><input type=hidden name=action value=searchlogs><input type=submit value=" search all daily logs"
class="submit"></form></td></tr>
</table>~;
&bottom;
exit;
} # end sub admin
sub checkpass
{
if (!-e $password_location){&setadminpass}
open (PASSWORD, "$password_location") || &error("Unable to open $password_location");
$checkp = <PASSWORD>;
close (PASSWORD);
chomp $checkp;
($input{'username'} eq "") && do {&logged('Please enter a username')};
($input{'password'} eq "") && do {&logged('Please enter a password')};
($user,$pass)=split(/\|/,$checkp);
        $newpassword = crypt($input{'password'}, $pass);
if (($user eq $input{'username'}) && ($pass eq $newpassword))
        {
        $input{'user'}=$input{'username'};
        &admin;
        }
else
        {
        &logged("Wrong admin username/password.");
        }
} # end sub checkpass
sub passad
{
@passset = ('a'..'z');
for ($i = 0; $i < 2; $i++)
        {
        $randum_num = int(rand($#passset + 1));
        $salt .= $passset[$randum_num];
        }
$newpassword = crypt($input{'password'}, $salt);
open (PASSWORD, ">$password_location")|| &error("Error setting Password");
print PASSWORD "$input{'username'}|$newpassword";
close (PASSWORD);
&logged("<br><br>Admin username and password printed<p>Please enter your username/password:<p>");
} # end sub passad
sub delete
{
$file=$input{'delfile'};
@delete = split(/\t/, $file );
print qq~<table width=100% align=center><tr><td width=100%><br><br><table align=center cellpadding=5>~;
foreach $delete(@delete)
        {
        chomp $delete;
        $delete=~/(.*)\|(.*)/;
        $delete1=$1;
        $displayfile=$2;
        unlink "$logdir/$delete1" || print qq[<tr><td class="headings">cannot delete $delete1</td></tr>];
        print qq~<tr><td class="headings">Log file: <span class="misc">$displayfile</span> deleted</b></td></tr>~;
        }
print qq~<tr><td><p align=center><input type=hidden name=action value=admin><input type=submit value=" admin page "
class="submit"></form></p></td></tr></table></td></tr></table>~;
&bottom;
exit;
}
sub bottom
{
if ($action ne "logon" && $action ne "admin"){
print qq[</form>
<center><form method=post>
<input type=hidden name=action value="admin">
<input type=hidden name=user value=$input{'user'}>
<input type=submit class=submit value="admin page">
</form><br>
];
}
print qq~</td></tr></table></body></html>~;
}
sub parse
{
if($ENV{'REQUEST_METHOD'} eq "GET")
{
   $my_data = $ENV{'QUERY_STRING'};
}
else
{
   $data_length = $ENV{'CONTENT_LENGTH'};
   my $bytes_read = read(STDIN, $my_data, $data_length);
}
@name_value_array = split(/&/, $my_data);
foreach $name_value_pair (@name_value_array)
{
   ($name, $value) = split(/=/, $name_value_pair);
   $name =~ tr/+/ /;
   $value =~ tr/+/ /;
   $name =~ s/%(..)/pack("C",hex($1))/eg;
   $value =~ s/%(..)/pack("C",hex($1))/eg;
   if($input{$name})
   {
      $input{$name} .= "\t$value";
   }
   else
   {
      $input{$name} = $value;
   }
}
} # end sub parse
sub head
{
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
<title>Link Tracker</title>
<link rel=stylesheet type="text/css" href="$stylesheet">
</head>
<body marginheight=0 marginwidth=0>~;
open (HEADER,"header");
while (<HEADER>) {
print $_;
}
close (HEADER);
}
sub sortit
{
my @pre = map { [$_, split /\|/ ] } @users2;
my @post = sort custom @pre;
@users2 = map { $_->[0] } @post;
if ($input{'sort'} eq "clicks"){@users2=reverse(@users2);}
sub custom {
if ($input{'sort'} eq "clicks")
{$a->[$sortnum] <=> $b->[$sortnum];}
else
{$a->[$sortnum] cmp $b->[$sortnum];}
}
}
sub viewreflogs
{
    opendir(DIR, "$refdir") || print "can't opendir $refdir";
    @dots = readdir(DIR);
    closedir DIR;
@dots = sort ( @dots);
print qq~<table cellpadding=2 cellspacing=0 border=0 width=100%>
<tr><td class="two" colspan=2 width=100% align=center>Please select a file to view:</td></tr>
<tr><td colspan=2 width=100% align=center><br><table><tr><td><span class="misc">Each link you track has it's own referrer log.<br>This shows: <ul><li>which pages the link was clicked from</li><li>the date of the last click</li><li>total clicks from each page</li></ul></span></td></tr></table></td></tr>
<tr><td width=100% align=center><table cellpadding=2 cellspacing=0 border=0>~;
$count=0;
foreach $dot(@dots)
        {
        chomp $dot;
        if ($dot !~m/\.log/i){next}
        $dot=~s/\.log//;
        $thename=$dot;
        $thename=~s!_!/!g;
if ($count==0)
        {
        print qq~<tr><td class="tablerow"><input type=radio name=showlog value=\"$dot|$thename\">$thename</td>\n~;
        $count=1;
        }
else
        {
        print qq~<td class="tablerow" style=\"padding-left:40px;\"><input type=radio name=showlog value=\"$dot|$thename\">$thename</td></tr>\n~;
        $count=0;
        }
        }
if ($count){print "</tr>"}
print qq~<tr><td colspan=2 style="padding-top:20px;"><center><input type=hidden name=action value=openreflog><input
type=submit value=" view log file " class="submit"></form></td></tr></table></td></tr></table>~;
&bottom;
exit;
} # end sub viewreflogs
sub openreflog
{
$file=$_[0];
$file=~/(.*)\|(.*)/;
$displaydate=$2;
$logf=$1;
$logf=~s/%3D/=/gi;
$logf=~s/%26/&/gi;
$logf=~s/%7E/\~/gi;
$logf=~s/%25/\%/gi;
$logfile="$refdir/$logf.log";
$displaydate=~s!_!/!g;
open FILED,"<$logfile" || print "there is no data for this day";
flock(FILED, 2) ;
@users2 = <FILED>;
chomp(@users2);
flock(FILED, 8);
close (FILED);
if ($input{'search'}){$users=0}
else {$users=scalar(@users2)}
if ($users == 1)
        {
         $plural="page";
        $plural3="result";
          }
else
{
$plural="pages";
$plural3="results";
}
$formlink=$input{'showlog'};
$formlink=~s/\=/%3D/ig;
$formlink=~s/\&/%26/ig;
$formlink=~s/\~/%7E/ig;
$formlink=~s/\%/%25/ig;
if ($input{'linkurl'}){$linkk="&linkurl=on";}
if (!$input{'search'})
{$sortby=qq[<td valign=top align=right><span class="headings">sort by:&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openreflog$linkk&sort=link&showlog=$formlink>link</a>&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openreflog$linkk&sort=clicks&showlog=$formlink>clicks</a>&nbsp;&nbsp;&nbsp;<a class="headings" href=$script?action=openreflog$linkk&sort=date&showlog=$formlink>date</a></span></td>];}
print qq~
<p>
<table cellpadding=5 cellspacing=0 width=100% border=0><tr><td width=100% height=100% valign=top>
<table cellpadding=5 cellspacing=0 width=100% border=0>
<tr><td class="headings">
enter term to search this log:</td>$sortby
</tr><tr><td>
<input type=hidden name=showlog value="$input{'showlog'}">
<input type=text name=search value="$input{'search'}" class="searchbox">
</td></tr><tr><td><input type=submit class="submit" value=" search logs ">
<input type=hidden name=user value=$input{'user'}>
<input type=hidden name=action value=openreflog></td>
</tr></form>~;
if ($input{'search'})
{
print qq~<tr><td valign=top>
<form action=$script method=post>
<input type=hidden name=user value=$input{'user'}>
<input type=hidden name=action value=openreflog>
<input type=hidden name=showlog value="$input{'showlog'}">
<input type=submit class="submit" value="show full list"></td></tr></form>~;
}
if ((!$input{'linkurl'}) && (!$input{'search'}))
{
print qq~<tr><td valign=top>
<form action=$script method=post>
<input type=hidden name=showlog value="$input{'showlog'}">
<input type=hidden name=action value=openreflog>
<input type=hidden name=linkurl value=linkurl>
<input type=submit value="show as link" class="submit">
</td></tr></form>~;
}
print qq~<form action=$script method=post><tr><td valign=top>
<input type=hidden name=action value=admin><input type=submit class="submit" value=" admin page ">
<br><br></td></tr></table></td></tr></form>
~;
$displaydate=~s/%3D/\=/ig;
$displaydate=~s/%26/\&/ig;
$displaydate=~s/%7E/\~/ig;
$displaydate=~s/%25/\%/ig;
if (!$input{'search'}){print qq~<tr><td class="headings">$users referring $plural for $displaydate</td></tr>~;}
else
{
print qq~
<tr><td valign=top><p class="headings">Search results for <span
class="misc">$input{'search'}</span></p></td></tr></form>~;
}
print qq~<tr><td valign=top><center><table border=1 bordercolor=$bordercolor cellpadding=$cellpadding cellspacing=$cellspacing>
<tr><td class="two">date</td><td class="two"><nobr>link</td><td
class="two">clicks</td></tr>~;
if ($input{'sort'} eq "link")
{
$sortnum=2;
&sortit;}
elsif ($input{'sort'} eq "clicks")
{
$sortnum=3;
&sortit;}
elsif ($input{'sort'} eq "date")
{
$sortnum=1;
&sortit;}
foreach $line2 (@users2)
{
$font="";
chomp $line2;
if ($input{'search'}){if ($line2 !~m/$input{'search'}/ig){next}}
($date,$url,$countit) = split/\|/,$line2;
$totalcount=($totalcount + $countit);
if (($input{'linkurl'}) || ($input{'search'})){$url=qq~<a href=$url target="_blank">$url</a>&nbsp;~;}
print qq~<tr><td class="tablerow" valign=\"top\">$date</td><td
class="tablerow" valign=\"top\">$url</td><td class="tablerow" valign=\"top\">$countit</tr>\n~;
if ($input{'search'}){$users++}
}
print "</table>";
if ($totalcount == 1)
        {
         $plural2="click"
          }
else
{
$plural2="clicks";
}
if ($input{'search'}){print qq~<p class="misc"><b>$users $plural3 found</b></p>~;}
print qq~<p class="misc"><b>$totalcount total $plural2</b></p>
</td></tr></table>
~;
print qq~<br><br><div class ="layer1" align=center>&copy;2002 <a href=[URL unfurl="true"]http://www.usersonline.net[/URL] target="_blank">usersonline.net</a></div>~;
&bottom;
exit;
} # end sub openreflog
sub rotateman
{
open (FILE2,"randomlist") || print "couldn't open $randomlist";
flock(FILE2, 2) ;
@dostuff = <FILE2>;
close (FILE2);
flock(FILE2, 8) ;
print qq~
<br><br>
<table width=100% cellpadding=5 cellspacing=0><tr><td align=center valign=top>
<table width=90%><tr><td><p align=center class="tablerow">If you want to distribute one link and have users redirected through to a different website each time the link is clicked, use the random rotator. This allows you to put one link out there and be able to change which links you want users to visit without having to change the url you give out.
<br>You need more than one link for the rotator to work.</p>
</td></tr></table>
<p align=center class="tablerow"><b>Add a link to the random link rotator:</b></p>
<p align=center><table cellpadding=5 cellspacing=0>
<tr><td><form action=$script method=post><input type=hidden name=action value=addrotate><input type=text name=addlink size=50 value="[URL unfurl="true"]http://"[/URL] class="searchbox"></td><td><input type=submit value=" add link " class="submit"></td></tr></table></p></form>
<p align=center class="tablerow">The url to the random rotator is:<br> <b>[URL unfurl="true"]http://$host?multi=rotate</b></p>$showhostlink[/URL]
<form action=$script method=post><input type=hidden name=action value=removelink>
<center><table border=1 bordercolor=$bordercolor cellpadding=$cellpadding cellspacing=$cellspacing>
<tr><td class="two">date</td><td class="two"><nobr>link</td><td
class="two">clicks</td><td class="two"><nobr>&nbsp;</td></tr>~;
foreach $stuff(@dostuff)
        {
        chomp $stuff;
($date,$url,$countit,undef) = split/\|/,$stuff;
print "<tr><td class=\"tablerow\">$date</td><td class=\"tablerow\">$url</td><td class=\"tablerow\">$countit</td><td class=\"tablerow\"><input type=checkbox name=dellink value=$url> remove</td></tr>";
        }
print "</table><p align=center><input type=submit class=\"submit\" value=\" delete links \"></p></form></td></tr></table>";
&bottom;
exit;
}
sub addrotate
{
my $foundurl=0;
my $message;
open (FILE3,"randomlist") || print "couldn't open randomlist";
flock(FILE3, 2) ;
@check=<FILE3>;
close (FILE3);
flock(FILE3, 8) ;
foreach $check(@check)
        {
        chomp $check;
        $remove=~s/\r//;
        ($date,$url,$countit,undef) = split/\|/,$check;
        if ($url eq $input{'addlink'})
        {
        $foundurl=1;
        $message=qq[<br><br><center><span class="tablerow"><font color=red>Url exists - $input{'addlink'}</font></span></center>]
        }
        }
if (!$foundurl)
{
open (FILE2,">>randomlist") || print "couldn't open randomlist";
flock(FILE2, 2) ;
print FILE2 "no date|$input{'addlink'}|0|\n";
close (FILE2);
flock(FILE2, 8) ;
$message=qq[<br><br><center><span class="tablerow"><font color=red>Added - $input{'addlink'}</font></span></center>]
}
print $message;
&rotateman;
}
sub removelink
{
@dellink=split/\t/,$input{'dellink'};
my $done = "<b>not found</b>";
foreach $dellink(@dellink)
{
open (FILE2,"randomlist") || print "couldn't open randomlist";
flock(FILE2, 2) ;
@remove=<FILE2>;
close (FILE2);
open (FILE3,">randomlist") || print "couldn't open randomlist";
flock(FILE3, 2) ;
foreach $remove(@remove)
        {
        chomp $remove;
        $remove=~s/\r//;
        $remove=~s/\n//;
        ($date,$url,$countit,undef) = split/\|/,$remove;
        if (!$url){next}
        if ($url eq $dellink)
        {
        $done="removed";
        next}
        print FILE3 "$remove\n";
        }
close (FILE3);
flock(FILE3, 8) ;
print qq[<br><br><center><font class="tablerow"><font color=red>$dellink $done</font></font></center>];
}
&rotateman;
}
sub addemail
{
open (FILE2,"<email_list") || print "cannot open file";
flock(FILE2, 2) ;
@emails = <FILE2>;
flock(FILE2, 8) ;
close (FILE2);
print qq~<center><table cellpadding=2 cellspacing=0 border=0 width=100%>
<tr><td class="two" width=100% align=center>Please enter details:</td></tr>
<tr><td width=100% align=center valign=top style="padding-left:7px;padding-top:7px;">
<table align=center cellpadding=5 border=0>
$donemessage
<tr><td class="tablerow"><b>Site:</b></td><td><input type=text name=site value="[URL unfurl="true"]http://"[/URL] size=40></td></tr>
<tr><td class="tablerow"><b>Email:</b></td><td><input type=text name=email size=40></td></tr>
<input type=hidden name=action value=addemail2>
<tr><td></td><td align=center><input type=submit value=" add email "
class="submit"></form></td></tr>~;
if ($email_site_on_click && $emails[0])
{print qq[
<form action=$script method=post><input type=hidden name=user value=$input{'user'}>
<tr><td align = center colspan=2><hr color=green><p><table border=0 cellpadding=2 cellspacing=0>
<tr><td class="tablerow" colspan=3><b><u>Current emails entered:</u></b><br><br></td></tr>
<tr><td class="tablerow"><span class="headings">site</span></td><td class="tablerow"><span class="headings">email</span></td><td>&nbsp;</td></tr>];
foreach $emails(@emails)
{
chomp $emails;
($site,$siteemail)=split(/\|/,$emails);
print qq[<tr><td class="tablerow">[URL unfurl="true"]http://$site[/URL] &nbsp;&nbsp;&nbsp;</td><td class="tablerow">$siteemail</td><td class="tablerow"><input type=checkbox name=removeemail value="$site|$siteemail"> remove</td></tr>];
}
print qq[
<tr><td class="tablerow" colspan=3 align=right><br><br><input type="submit" class="submit" name="action" value=" remove "></td></tr></table>
<p><hr color=green></td></tr></form>];
}
print qq~</table></td></tr>
<tr><td class="tablerow">
<center><table width=500><tr><td class="tablerow">
<br><br>You can choose to have each website emailed when someone clicks through from your link. If you have a lot of clicks through to their site, I'd advise you don't enter their email here - otherwise, their mailbox is going to be full of 'your link has been clicked' emails!
<p>Only those sites and emails listed here will be emailed when their link is clicked.</p><p>Emails are sent including the link that was clicked and the page it was clicked from.</p><br><br></td></tr></table></center></td></tr>
</table>~;
&bottom;
exit;
}
sub addemail2
{
$newemail=$input{'email'};
$newsite=$input{'site'};
$newsite=~s![URL unfurl="true"]http://!!i;[/URL]
$newsite=~s![URL unfurl="true"]www\.!!i;[/URL]
open (FILE2,">>email_list") || print "";
flock(FILE2, 2) ;
print FILE2 "$newsite|$newemail\n";
flock(FILE2, 8);
close (FILE2);
$donemessage = qq~
<tr><td></td><td class="tablerow"><b>The following details were added:</td></tr><tr><td></td><td class="tablerow"><ol><b>Site:</b> <font color=red>$input{'site'}</font><br>
<b>Email:</b> <font color=red>$input{'email'}</font></ol></td></tr>
~;
&addemail;
}
sub deletelinklist
{
open (F, ">$logdir/linklist");
close (F);
&admin;
}
sub removeemail
{
my @done="";
@checkemail=split(/\t/,$input{'removeemail'});
foreach $checkemail(@checkemail)
{
($checksite,$checkem)=split(/\|/,$checkemail);
open (FILE2,"<email_list") || print "cannot open file";
flock(FILE2, 2) ;
@emails = <FILE2>;
flock(FILE2, 8) ;
close (FILE2);
open (FILE2,">email_list") || print "cannot open file";
flock(FILE2, 2);
foreach $emails(@emails)
        {
        chomp $emails;
        ($site,$siteemail)=split(/\|/,$emails);
        if ($siteemail eq $checkem && $site eq $checksite)
{
$done .= qq[<tr><td></td><td class="tablerow"><font color=red>[URL unfurl="true"]http://$site[/URL] - $siteemail</font></td></tr>];
next;
}
        print FILE2 "$emails\n";
        }
flock(FILE2, 8) ;
close (FILE2);
}
$donemessage=qq[<tr><td></td><td class="tablerow"><b>The following details were removed:</td></tr>
$done
];
&addemail;
}
sub settings
{
my ($set1,$set2);
$optionon=qq[<option value=1>yes</option><option value=0>no</option>];
$optionoff=qq[<option value=0>no</option><option value=1>yes</option>];
if ($emailstats){$set1=$optionon}else{$set1=$optionoff}
if ($email_site_on_click){$set2=$optionon}else{$set2=$optionoff}
if ($trowit){$set3=qq[<option value="1">vertically</option><option value="0">horizontally</option>];}
else{$set3=qq[<option value="0">horizontally</option><option value="1">vertically</option>];}
print qq~<center><table cellpadding=2 cellspacing=0 border=0 width=100%>
<tr><td class="two" width=100% align=center>Current settings:</td></tr>
<tr><td width=100% align=center valign=top style="padding-left:7px;padding-top:7px;">
<table align=center cellpadding=5 border=0>
<tr><td class="tablerow"><b>Password file location:</b> </td><td><input type=text size=40 name=password_location value="$password_location"></td></tr>
<tr><td class="tablerow"><b>Stylesheet location:</b> </td><td><input type=text size=40 name=stylesheet value="$stylesheet"></td></tr>
<tr><td class="tablerow"><b>Page to forward to on error:</b> </td><td><input type=text size=40 name=forwarderror value="$forwarderror"></td></tr>
<tr><td class="tablerow"><b>Border colour of tables in admin:</b> </td><td><input type=text size=40 name=bordercolor value="$bordercolor"></td></tr>
<tr><td class="tablerow"><b>Cellpadding of tables in admin:</b> </td><td><input type=text size=40 name=cellpadding value="$cellpadding"></td></tr>
<tr><td class="tablerow"><b>Cellspacing of tables in admin:</b> </td><td><input type=text size=40 name=cellspacing value="$cellspacing"></td></tr>
<tr><td class="tablerow"><b>Arrange form buttons at top of logs:</b> </td><td><select name=trowit>$set3</select></td></tr>
<tr><td class="tablerow"><b>Email daily stats to you:</b> </td><td><select name=emailstats>$set1</select></td></tr>
<tr><td class="tablerow"><b>Email each site that their link was clicked:</b> </td><td><select name=email_site_on_click>$set2</select></td></tr>
<tr><td class="tablerow"><b>Subject of email sent:</b> </td><td><input type=text size=40 name=subject value="$subject"></td></tr>
<tr><td class="tablerow"><b>Message in email:</b> </td><td><input type=text size=40 name=body value="$body"></td></tr>
<tr><td class="tablerow"><b>Location of sendmail:</b> </td><td><input type=text size=40 name=mailprog value="$mailprog"></td></tr>
<tr><td class="tablerow"><b>Your email address:</b> </td><td><input type=text size=40 name=myemail value="$myemail"></td></tr>
<tr><td class="tablerow"><b>Logs directory:</b> </td><td><input type=text size=40 name=logdir value="$logdir"></td></tr>
<tr><td class="tablerow"><b>Referrer logs directory:</b> </td><td><input type=text size=40 name=refdir value="$refdir"></td></tr>
<input type=hidden name=action value=settings2>
</table></td></tr>
<tr><td style="padding-top:20px;" align=center><input type=submit value=" save settings " class="submit"></form></td></tr>
</table>~;
&bottom;
exit;
} # end sub settings
sub settings2
{
if (!$input{'cellpadding'}){$input{'cellpadding'} = "0"}
if (!$input{'cellspacing'}){$input{'cellspacing'} = "0"}
$myEmail = $input{'myemail'};
$myEmail =~s/@/\\@/;
open (F,">config.pl") || print "cannot open config file";
flock(F, 2) ;
print F "\$password_location=qq|$input{'password_location'}|\;\n";
print F "\$bordercolor = qq|$input{'bordercolor'}|\;\n";
print F "\$stylesheet = qq|$input{'stylesheet'}|\;\n";
print F "\$forwarderror = qq|$input{'forwarderror'}|\;\n";
print F "\$cellpadding = qq|$input{'cellpadding'}|\;\n";
print F "\$cellspacing=qq|$input{'cellspacing'}|\;\n";
print F "\$email_site_on_click=qq|$input{'email_site_on_click'}|\;\n";
print F "\$emailstats=qq|$input{'emailstats'}|\;\n";
print F "\$mailprog = qq|$input{'mailprog'}|\;\n";
print F "\$myemail = qq|$myEmail|\;\n";
print F "\$logdir=qq|$input{'logdir'}|\;\n";
print F "\$refdir=qq|$input{'refdir'}|\;\n";
print F "\$subject=qq|$input{'subject'}|\;\n";
print F "\$body=qq|$input{'body'}|\;\n";
print F "\$trowit=qq|$input{'trowit'}|\;\n";
print F "\n\n1\;\n";
flock(F, 8) ;
close (F);
$donemessage="<font color=red><b>Your settings have been saved</b></font>";
&admin;
}

I just hope that you are right that the company has collapsed and there is not a copyright issue here!



Trojan.
 
That's fantastic, many thanks Trojan.

Now I've copied the code above into the cgi files to replace the encoded stuff.
The scripts still works ok, as it did, other than the sending email bit, as expected though.

Any ideas what could be wrong with the code to stop emails from being sent. I know very little about Perl coding, hence I brought the script in the first place.

In the admin area it gives two sections where you can enter a web address and a corresponding email address and the servers sendmail address.
So when that web address is clicked on from within the site an email is sent out to the corresponding email address, to advise them that the link has been clicked on.

I think some of the bit for this to happen is in the last bit of the tracker.cgi file?

Any ideas?

Cheers, Craig.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top