#!/usr/bin/perl
###################################################################
# analyse.cgi Version 1.01
###################################################################
#
# Written by Jonathan Cogley
# Copyright 1998. THYCOTIC WEBDESIGN
# http://www.thycotic.com
# E-Mail : info@thycotic.com
#
# This script may not be sold or distributed in any other form
# without the permission of Thycotic WebDesign.
# I think the popular expression is :
# 'don't try to make money off of my work'
#
###################################################################
#
# This script uses log files from HitMatic and displays them graphically.
# It adds the ability to isolate viewing based on groups
#
# Hitmatic is a logging system written by Joe DePasquale
# Hitmatic E-Mail: crypt@getcruising.com
# Hitmatic Website: http://www.GetCruising.com
#
###################################################################
#
# If you find the Analyse script useful then please register it!
# Registration is only $10 (US dollars) or £10 (UK pounds)
# http://www.thycotic.com/scripts
# Thanks!
#
###################################################################
#
# Revisions :
# 1.1 * Added ability to view todays and yesterdays hits
# * Added ability to view agent.log and visitor.log, if they
# exist (they are available by using the add-on version of hitcfg.pl
# also written by Thycotic WebDesign)
#
###################################################################
#
# Installation:
#
# 1) Put 'analyse.cgi' in the directory with your hitmatic log
# files. (hit1.dat -> hit12.dat and hit.cfg should all be in the hitmatic directory)
#
# 2) Ensure the first line in analyse.cgi points to Perl on your server
# i.e. #!/usr/bin/perl
# Use 'whereis perl' to find location of Perl.
#
# 3) Set the permissions on analyse.cgi to 755 (chmod 755 - makes it executable)
#
# 4) Try it out! Point your browser at the script ...
# Don't forget to include the Hitmatic group after the script to return only
# a single group or use 'ALL' to bring back everything in the logs
#
# e.g. http://www.whatever.com/hitmatic/analyse.cgi?A
# OR
# e.g. http://www.whatever.com/hitmatic/analyse.cgi?d
# OR
# e.g. http://www.whatever.com/hitmatic/analyse.cgi?ALL
#
###################################################################
#####################
### Configuration ###
#####################
### The URL to the script itself i.e. http://whatever.com/hitmatic/analyse.cgi
$SCRIPTURL = "/hitmatic/analyse.cgi";
### The E-mail address to show when errors occur i.e. yourname\@yourcompany.com
### Dont forget the \ before the @ symbol
$SCRIPTOWNER = "you\@whatever.com";
###Customise body tag and title of pages (optional)
$bodytag = "
";
$title = "Hits to your website!";
###################################################################
# Thats it!!
# DON'T CHANGE ANYTHING BELOW THIS LINE!
###################################################################
print "Content-type: text/html\n\n";
print $bodytag;
@labels = ('Foo','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
@daysinMonth = (0,31,28,31,30,31,30,31,31,30,31,30,31);
$htmltag = chr(85).chr(110).chr(114).chr(101).chr(103).chr(105).chr(115).chr(116).chr(101).chr(114).chr(101);
$htmltag = $htmltag.chr(100).chr(32).chr(118).chr(101).chr(114).chr(115).chr(105).chr(111).chr(110);
$incoming = $ENV{'QUERY_STRING'}; #read in argument
&parse_form;
&get_month;
if ($Form{'group'}) { $incoming = $Form{'group'} }
#find out how long incoming is
$_ = $incoming;
$countincoming = tr/!-z//;
if ($countincoming != 1 && $incoming ne "ALL") {
print "There has been an error
";
print "Please contact $SCRIPTOWNER to report the fault, describing the situation in which it happened.";
&tagline;
exit;
}
print "";
print "$title\n";
print "
";
if (-e "agent.log") {
$AGENT = 1;
}
if (-e "visitor.log") {
$VISITOR = 1;
}
if (-e "analyse.key"){
open (KEY,";
close (KEY);
chomp($key);
$string = "Analyse";
$length = length $string;
if ($key eq crypt ($string, $length)) {
$htmltag = substr($htmltag, 3, (length $htmltag) -3);
$htmltag = chr(82).$htmltag;
}
}
if ($Form{'year'}) {
&show_year;
} elsif ($Form{'month'}) {
&show_month;
} elsif ($Form{'showmain'}) {
$incoming = $Form{'group'};
&show_main_count;
} elsif ($Form{'showtoday'}) {
&show_today;
} elsif ($Form{'yesterday'}) {
&show_yesterday;
} elsif ($Form{'agent'}) {
&show_agent;
} elsif ($Form{'visitor'}) {
&show_visitor;
} else {
&show_today;
}
&show_options;
&tagline;
###################################################################
sub show_agent {
open (FILE, "agent.log"); #load today's file into an array
@file = ;
close (FILE);
@file = sort by_number @file;
print "Agents used
";
print "\n";
print "| Agent | \n";
print "Last used | \n";
print "Hits | \n";
print "
";
foreach $line (@file) {
($hits, $group, $agent, $lastused) = split (/\|/,$line);
if ($agent ne "") {
if ($incoming eq $group || $incoming eq "ALL") {
print "\n";
print "| $agent | \n";
print "$lastused | \n";
print "$hits | \n";
print "
\n";
}
}
}
print "
";
}
###################################################################
sub show_visitor {
open (FILE, "visitor.log"); #load today's file into an array
@file = ;
close (FILE);
@file = sort by_number @file;
print "Visitors
";
print "\n";
print "| Visitor | \n";
print "Last visited | \n";
print "Hits | \n";
print "
";
foreach $line (@file) {
($hits, $group, $visitor, $lastvisit) = split (/\|/,$line);
if ($visitor ne "") {
if ($incoming eq $group || $incoming eq "ALL") {
print "\n";
print "| $visitor | \n";
print "$lastvisit | \n";
print "$hits | \n";
print "
\n";
}
}
}
print "
";
}
###################################################################
sub show_today {
open (TODAYFILE, "hit1.log"); #load today's file into an array
@todayfile = ;
close (TODAYFILE);
print "Today\'s Hits
";
print "\n";
print "| Time | \n";
print "Page | \n";
print "Visitor | \n";
print "Browser | \n";
print "
";
foreach $todayline (@todayfile) {
@todayline = split (/\|/,$todayline);
$pageline = $todayline[1];
$hostname = $todayline[4];
$agent = $todayline[5];
if ($pageline eq "") {
$_ = $todayline;
$countline = tr/!-z//;
$time = substr($todayline, $countline - 5, 4);
} else {
$group = substr($pageline, 0, 1);
$_ = $pageline;
$countpage = tr/!-z//;
$page = substr($pageline, 2, $countpage - 2);
if ($incoming eq $group || $incoming eq "ALL") {
print "\n";
print "| $time | \n";
print "$page | \n";
print "$hostname | \n";
print "$agent | \n";
print "
\n";
}
}
}
print "
";
}
###################################################################
sub show_yesterday {
open (TODAYFILE, "hit2.log"); #load today's file into an array
@todayfile = ;
close (TODAYFILE);
print "Yesterday\'s Hits
";
print "\n";
print "| Time | \n";
print "Page | \n";
print "Visitor | \n";
print "Browser | \n";
print "
";
foreach $todayline (@todayfile) {
@todayline = split (/\|/,$todayline);
$pageline = $todayline[1];
$hostname = $todayline[4];
$agent = $todayline[5];
if ($pageline eq "") {
$_ = $todayline;
$countline = tr/!-z//;
$time = substr($todayline, $countline - 5, 4);
} else {
$group = substr($pageline, 0, 1);
$_ = $pageline;
$countpage = tr/!-z//;
$page = substr($pageline, 2, $countpage - 2);
if ($incoming eq $group || $incoming eq "ALL") {
print "\n";
print "| $time | \n";
print "$page | \n";
print "$hostname | \n";
print "$agent | \n";
print "
\n";
}
}
}
print "
";
}
###################################################################
sub get_month {
open (CFGFILE, "hit.cfg"); #load main count file into an array
@cfgentries = ;
close (CFGFILE);
foreach $cfgline (@cfgentries) {
@cfglines = split(/\|/,$cfgline);
}
$currentmonth = $cfglines[1];
}
###################################################################
sub show_month {
$k = $Form{'monthvalue'};
print "| ";
if ($k != ($currentmonth + 1)) {
if ($k == 1) {
$temp = 12;
} else {
$temp = $k - 1;
}
print " | \n";
print "\n";
}
print "Month : $labels[$k] | ";
print "";
if ($k != $currentmonth) {
if ($k == 12) {
$temp = 1;
} else {
$temp = $k + 1;
}
print " | \n";
print "\n";
}
print "
";
$dataload[1][1] = 0;
$pagecount = 1;
$monthfile = "hit$k.dat";
open (LOGFILE, "$monthfile"); #load main count file into an array
@monthentries = ;
close (LOGFILE);
#######print "opening $monthfile
\n";
$firstline = 1;
foreach $pageline (@monthentries) { #cycle thru each line in current months log
@pageline = split(/\|/,$pageline);
if ($firstline != 1) {
#####refining group and page identifier
$group = substr($pageline[0], 0, 1);
$_ = $pageline[0];
$countpage = tr/!-z//;
$page = substr($pageline[0], 2, $countpage - 2);
if ($incoming eq $group || $incoming eq "ALL") {
##### loading daily hits into dataset
$dataload[$pagecount][0] = $page;
for ($n = 1; $n <= $daysinMonth[$k]; $n++) {
$dataload[$pagecount][$n] = $pageline[$n];
}
$pagecount++;
}# End grouping if
}
$firstline = 0;
}
print "";
print "| Page | ";
for ($n = 1; $n <= $daysinMonth[$k]; $n++) {
print "$n | \n";
}
print "Hits |
";
##### Populate the table with the dataset
for ($j = 1; $j < $pagecount; $j++) {
print "| $dataload[$j][0] | ";
$totalpage = 0;
for ($n = 1; $n <= $daysinMonth[$k]; $n++) {
print "$dataload[$j][$n] | ";
if ($dataload[$j][$n] ne "") {
$totalpage += $dataload[$j][$n];
$totalday[$n] += $dataload[$j][$n];
}
}
print "$totalpage |
";
$grandtotal += $totalpage;
}
#### Do the table totals
print "| Totals | ";
for ($n = 1; $n <= $daysinMonth[$k]; $n++) {
print "$totalday[$n] | ";
}
print "$grandtotal |
";
print "
";
}
###################################################################
sub show_year {
print "Hits for past year
";
$dataload[1][1] = 0;
$pagecount = 1;
for ($k = 1; $k < 13; $k++) { #cycle thru all the months
$monthfile = "hit$k.dat";
open (LOGFILE, "$monthfile"); #load main count file into an array
@monthentries = ;
close (LOGFILE);
#######print "opening $monthfile
\n";
$firstline = 1;
foreach $pageline (@monthentries) { #cycle thru each line in current months log
@pageline = split(/\|/,$pageline);
if ($firstline != 1) {
#####refining group and page identifier
$group = substr($pageline[0], 0, 1);
$_ = $pageline[0];
$countpage = tr/!-z//;
$page = substr($pageline[0], 2, $countpage - 2);
if ($incoming eq $group || $incoming eq "ALL") {
#####determining months hits for this page
$monthtotal = 0;
for ($n = 1; $n < $daysinMonth[$k]; $n++) {
$monthtotal += $pageline[$n];
}
$found = 0;
$loop = 1;
##test to see if page is already in dataset
for ($loop = 1; $loop < $pagecount; $loop++) {
if ($page eq $dataload[$loop][1]) {
$found = 1;
$dataload[$loop][$k+1] += $monthtotal; #if it is add current month total
}
}
##if it isnt - add it
if ($found == 0) {
$dataload[$pagecount][1] = $page;
$dataload[$pagecount][$k+1] = $monthtotal;
#######print "$pagecount $dataload[$pagecount][1] $dataload[$pagecount][$k+1]
";
$pagecount++;
}
}# End grouping if
}
$firstline = 0;
}
}
print "";
print "| Page | ";
$i = $currentmonth + 1;
$doneonce = 0;
while (($i != $currentmonth + 1) || $doneonce == 0) {
print "";
print " | \n";
if ($i == 12) { $i = 0 }
$i++;
$doneonce = 1;
}
print "Hits |
";
##### Populate the table with the dataset
for ($j = 1; $j < $pagecount; $j++) {
print "| $dataload[$j][1] | ";
$totalyear = 0;
$k = $currentmonth + 1;
$doneonce = 0;
while (($k != $currentmonth + 1) || $doneonce == 0) {
print "$dataload[$j][$k+1] | ";
if ($dataload[$j][$k+1] ne "") {
$totalyear += $dataload[$j][$k+1];
$totalmonth[$k+1] += $dataload[$j][$k+1];
}
if ($k == 12) { $k = 0 }
$k++;
$doneonce = 1;
}
print "$totalyear |
";
$grandtotal += $totalyear;
}
#### Do the table totals
print "| Totals | ";
$k = $currentmonth + 1;
$doneonce = 0;
while (($k != $currentmonth + 1) || $doneonce == 0) {
print "$totalmonth[$k+1] | ";
if ($k == 12) { $k = 0 }
$k++;
$doneonce = 1;
}
print "$grandtotal |
";
print "
";
}
sub tagline {
print "© 1998. Analyse Script by Thycotic WebDesign";
print "
$htmltag