#!/usr/bin/perl -- ######################################################################### # # My Linktracker V1.0 (Main Script) # Copyright 1998, Jim Melanson, Jim Melanson Web Design. # # Usage of and modification of this script is subject to the terms # and conditions in the Readme file that accompanies this script # package. Use of or modification of this or any of the other # scripts in this package shall constitute acceptance of all the # terms and conditions. If you do not meet or do not accept all the # terms and conditions in the Readme file, then you do not have my # permission to use or modify this script. # ######################################################################### $ScriptURL = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}"; require 'ml_attack.cgi'; &Parse; &Date; if($ENV{'QUERY_STRING'} =~ /^admin/i) {&Admin} else {&Link} exit; ########################################################################### sub Link { $Link = "$Data/links/$ENV{'QUERY_STRING'}"; if(open(LINK, "<$Link/link.txt")) { @LinkURL = ; close(LINK); chop($LinkURL[0]); print "Location: $LinkURL[0]\n\n"; open(COUNT, "<$Link/count.txt"); @Counter = ; close(COUNT); chop($Counter[0]); $NewCount = $Counter[0] + 1; open(COUNT, ">$Link/count.txt"); print COUNT "$NewCount\n"; close(COUNT); $daycheck = 0; open(DATE, "<$Link/$ThisYear|$ThisMonth.list"); @Contents = ; close(DATE); open(DATE, ">$Link/$ThisYear|$ThisMonth.list"); foreach $day_count (@Contents) { chop($day_count); ($day, $count) = split(/\t/, $day_count); if($day ne $ThisDay) { print DATE "$day_count\n"; } else { $count++; print DATE "$day\t$count\n"; $daycheck = 1; } } if(!$daycheck) { print DATE "$ThisDay\t1\n"; } close(DATE); } else { if($SHOW_LIST) { &PrintHead; print "

Error -

The link specified on\n"; print "the page that you came from, no longer exists. Here is\n"; print "a table showing the links that are currently registered\n"; print "with \n"; print "My Linktracker program:

\n"; if(open(LINKS, "<$Data/admin/links.list")) { $checkshow = 0; print "

    \n"; @ShowContents = ; close(LINKS); foreach $showlink (@ShowContents) { chop($showlink); @ShowList = split(/\t/, $showlink); if($ShowList[4]) { print "
  1. $ShowList[2]\n"; $checkshow = 1 } } print "

\n"; } else { print "Currently, there are no active links available.

\n"; } if(!$checkshow) { print "Currently, there are no active links available.

\n"; } &PrintFoot; } else { $Problem = "the link specified no longer exists."; &Error($Problem); } open (MAIL, "|$MailProgram -t") || die "Can't start mail program"; print MAIL "To: $AdminEmail\n"; print MAIL "From: $AdminEmail\n"; print MAIL "Subject: Inactive Link Warning\n\n"; print MAIL "On $date at $time, someone tried to access link #$ENV{'QUERY_STRING'}\n\n"; print MAIL "Here are some environment variable to try and figure\n"; print MAIL "out on what page the link is still in place.\n\n"; @AllKeys = keys(%ENV); foreach $key (@AllKeys) { print MAIL "$key: $ENV{$key}\n"; } print MAIL "\n\nThank You\n\n"; print MAIL "My Linktracker V1.0\n"; print MAIL "Copyright 1998, Jim Melanson Web Design\n"; print MAIL "www.thebeaches.to/jmwd/index.html\n\n"; close(MAIL); } } sub Admin { if($FORM{'action'} eq 'addlink') { if(&CheckPass($FORM{'user'}, $FORM{'pass'})) { if($FORM{'newlinkurl'}) { if($FORM{'newlinktoname'}) { if(!$FORM{'newlinkfromname'}){ $FORM{'newlinkfromname'} = "Multi-Page Origin"; } if(open(NUM, "<$Data/admin/links.list")) { @NumContents = ; close(NUM); $totalnum = @NumContents; $totalnum--; chop($NumContents[$totalnum]); @NumList = split(/\t/, $NumContents[$totalnum]); $NewLinkNum = $NumList[0]; $NewLinkNum++; } else { $NewLinkNum = 101; } open(NUM, ">>$Data/admin/links.list"); print NUM "$NewLinkNum\t$FORM{'newlinkurl'}\t$FORM{'newlinktoname'}\t$FORM{'newlinkfromname'}\tactive\n"; close(NUM); mkdir("$Data/links/$NewLinkNum", 0766); open(LINK, ">$Data/links/$NewLinkNum/link.txt"); print LINK "$FORM{'newlinkurl'}\n"; close(LINK); open(COUNT, ">$Data/links/$NewLinkNum/count.txt"); print COUNT "1\n"; close(COUNT); open(DATE, ">$Data/links/$NewLinkNum/$ThisYear|$ThisMonth.list"); print DATE "$ThisDay\t1\n"; close(DATE); &PrintHead; print "

Link Added -


\n"; print "The link for $FORM{'newlinktoname'} has\n"; print "been set-up. The link you must now use is:

\n"; print "<A HREF=\"$ScriptURL?$NewLinkNum\">Test or Image Link</A>\n"; print "

Use the back button on your browser to\n"; print "return to the previous page and add another link.\n"; print "





\n"; &PrintFoot; } else { $Problem = "you forgot to include the name of the page " . "that you are linking to"; &Error($Problem); } } else { $Problem = "you forgot to include the new links URL."; &Error($Problem); } } else { $Problem = "the UserID or Password you entered does not match " . "the database."; &Error($Problem); } } elsif($FORM{'action'} eq 'removelink') { if(&CheckPass($FORM{'user'}, $FORM{'pass'})) { open(CHANGE, "<$Data/admin/links.list"); @ChangeContents = ; close(CHANGE); $changenum = @ChangeContents; open(CHANGE, ">$Data/admin/links.list"); for($a = 0; $a < $changenum; $a++) { chop($ChangeContents[$a]); if($ChangeContents[$a] =~ /^$FORM{'removelinknum'}/) { @LinkList = split(/\t/, $ChangeContents[$a]); print CHANGE "$LinkList[0]\t$LinkList[1]\t$LinkList[2]\t$LinkList[3]\tinactive\n"; } else { print CHANGE "$ChangeContents[$a]\n"; } } opendir(READ, "$Data/links/$FORM{'removelinknum'}"); @RemoveFiles = readdir(READ); foreach $file (@RemoveFiles) { unless(($file eq '.') || ($file eq '..')) { unlink("$Data/links/$FORM{'removelinknum'}/$file"); } } rmdir("$Data/links/$FORM{'removelinknum'}"); &PrintHead; print "

Link Deactivated -


\n"; print "The link for $LinkList[2] has been deactivated.\n"; print "If anyone attempts to access this link, they will\n"; if($SHOW_LIST) { print "be re-directed to a list of available links within\n"; print "this program.

\n"; } else { print "receive an error message.

\n"; } print "The link information still remains in the database,\n"; print "however, and if anyone attempts to access it, you will\n"; print "be sent an e-mail notification as well as a listing of\n"; print "the access details to help you track down which page\n"; print "the link came from.

The next major release of this\n"; print "program will allow you to re-instate a link from the\n"; print "admin page. This is not yet available for this\n"; print "version of the program.

\n"; &PrintFoot; } else { $Problem = "the UserID or Password you entered does not match " . "the database."; &Error($Problem); } } elsif($ENV{'QUERY_STRING'} =~ /^adminsummary/i) { $ENV{'QUERY_STRING'} =~ /^adminsummary(\d+)/i; $LinkNum = $1; open(SUM, "<$Data/admin/links.list"); @SumContents = ; close(SUM); $sumcheck = 0; foreach $content (@SumContents) { chop($content); if($content =~ /^$LinkNum\t/) { @SumList = split(/\t/, $content); $SUM{'linkurl'} = $SumList[1]; $SUM{'topagename'} = $SumList[2]; $SUM{'frompagename'} = $SumList[3]; $SUM{'status'} = $SumList[4]; $sumcheck = 1; last; } } if($sumcheck) { if($SUM{'status'} eq 'inactive') { &PrintHead; print "

Inactive Status -


\n"; print "You requested a summary for link number \"$LinkNum\".\n"; print "
This link is inactive and can not,\n"; print "therefore, be summarized.



\n"; &PrintFoot; } else { &PrintHead; print "

Link Summary -


\n"; print "
  • Link Number: $LinkNum\n"; print "
  • Links To: $SUM{'topagename'}\n"; print "
  • Link is From: $SUM{'frompagename'}\n"; print "
  • Status is: ACTIVE

\n"; open(COUNT, "<$Data/links/$LinkNum/count.txt"); $Count = ; close(COUNT); chop($Count); print "

Total Number of Hits: $Count

\n"; opendir(READ, "$Data/links/$LinkNum"); @CountMonths = readdir(READ); foreach $month (@CountMonths) { if($month =~ /list$/) { ($month1, $waste) = split(/\./, $month); push(@OrderMonths, $month1); } } @ListMonths = sort {$b cmp $a} @OrderMonths; $Total_Hits = 0; foreach $fullmonth (@ListMonths) { open(MONTH, "<$Data/links/$LinkNum/$fullmonth.list"); @Total_Count = ; close(MONTH); $totaldays = @Total_Count; for($a = 0; $a < $totaldays; $a++) { chop($Total_Count[$a]); ($day_num, $next_count) = split(/\t/, $Total_Count[$a]); $Total_Hits += $next_count; } } foreach $fullmonth (@ListMonths) { ($ShowYear, $ShowMonth) = split(/\|/, $fullmonth); $ShowMonth--; $ShowMonth = $MonthNames[$ShowMonth]; open(MONTH, "<$Data/links/$LinkNum/$fullmonth.list"); @Each_Month = ; close(MONTH); $each_month_total = @Each_Month; $Month_Total = 0; $Biggest_Day = 0; for ($c = 0; $c < $each_month_total; $c++) { ($day_num, $next_count) = split(/\t/, $Each_Month[$c]); $Month_Total += $next_count; if($next_count > $Biggest_Day) { $Biggest_Day = $next_count; } } print "$ShowMonth, $ShowYear
\n"; print "There were $Month_Total hits for the month of $ShowMonth
\n"; print "\n"; print "\n"; print "\n"; print "\n"; @Each_Day = sort {$a <=> $b} @Each_Month; for($d = 0; $d < $each_month_total; $d++) { chop($Each_Day[$d]); ($day_num, $next_count) = split(/\t/, $Each_Day[$d]); $percentage = $next_count/$Biggest_Day; $day_percent = int(($next_count / $Month_Total) * 100); if($day_percent < 1) { $day_percent = 1; } $width = int($percentage * 480); print "\n"; print "\n"; } print "
DayHits\% 
$day_num$next_count$day_percent\%

\n"; } #close foreach full month &PrintFoot; }#close else }#close if sumcheck else { $Problem = "the link number you requested a summary for " . "does not exist."; &Error($Problem); } } #close elsif else { &PrintHead; print "

Admin Panel -


\n"; if(open(SUM, "<$Data/admin/links.list")) { @TotLinks = ; close(SUM); $totlinks = @TotLinks; print "

Total Links: $totlinks

\n"; $Total_Count = 0; foreach $link (@TotLinks) { chop($link); @Each_Month = split(/\t/, $link); open(LINK, "<$Data/links/$Each_Month[0]/count.txt"); $Count = ; close(LINK); chop($Count); $Total_Count += $Count; @Each_Month = (); } print "

Total Number of Hits: $Total_Count

\n"; print "
Here is a breakdown of each link and\n"; print "what it represents. To see a full summary of each link,\n"; print "click on that links number. To see what page it leads to\n"; print "then click on the \"To Page\" page name. To see what page\n"; print "it comes from, click on the \"From Page\" name.\n"; print "

\n"; print "\n"; print "\n"; print "\n"; print "\n"; foreach $link (@TotLinks) { @Each_Month = split(/\t/, $link); open(LINK, "<$Data/links/$Each_Month[0]/count.txt"); $Count = ; close(LINK); chop($Count); if($Each_Month[4] eq 'active') { print "\n"; } else { print "\n"; } if($Each_Month[4] eq 'active') { print "\n"; } else { print "\n"; } print "\n"; print "\n"; @Each_Month = (); } print "
Link #HitsDestinationOrigin
$Each_Month[0]$Each_Month[0]$CountInactive$Each_Month[2]$Each_Month[3]

\n"; } else { print "

There are no links established

\n"; } print "

Add A Link

\n"; print "
\n"; print "\n"; print "
Linking To Page Name:\n"; print "

\n"; print "This is the NAME of the page that the new link will\n"; print "present when people click on it.\n"; if($SHOW_LIST) { print "The name you enter here is for your reference but\n"; print "will also be visible to people who enter an incorrect\n"; print "link number.

\n"; } else { print "The name you enter here is for your own reference and\n"; print "will not be visible to anyone else.

\n"; } print "

The URL\n"; print "

\n"; print "This is the actual URL that the link will follow. Type it\n"; print "carefully to ensure that it is correct and leave in\n"; print "the \"http://\".

\n"; print "

Linking From Page Name\n"; print "

\n"; print "This is the name of the page that the link comes from. It will\n"; print "only be visible to yourself and no one else. If this link\n"; print "will be coming from more than one page or you do not wish to\n"; print "track by referencing page, then leave this field untouched.\n"; print "

\n"; print "\n"; print "\n"; print "
User:
Pass:

\n"; print "


Deactivate a Link

\n"; print "
\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "
Link #:
UserID:
Pass :

\n"; &PrintFoot; } } sub Error { local($cause) = @_[0]; &PrintHead; print "

Error -


An error has occured.

The error\n"; print "occured because $cause

Thank You.

\n"; &PrintFoot; return(0); } sub PrintHead { print "Content-type: text/html\n\n"; print "Link Tracker Administration\n"; print "\n"; } sub PrintFoot { print "



\n"; print "\n"; print "© 1998, Jim Melanson Web Design
\n"; print "Tracking by My Linktracker V1.0
\n"; print "
Script Protection by
Attack Guard V1.1(Modified)\n"; print "
\n"; } sub CheckPass { $User = @_[0]; $Pass = @_[1]; $UserCheck = crypt($User, NB); $PassCheck = crypt($Pass, NB); open(PASS, "<$Data/admin/pass.list"); @PassContents = ; close(PASS); chop($PassContents[0]); ($fileuser, $filepass) = split(/\t/, $PassContents[0]); if(($filepass eq $PassCheck) && ($fileuser eq $UserCheck)) { return(1); } else {return(0)} }