#!/usr/bin/perl
#
# Please read the e-mail you received
# with logit for installation instructions.
# (or readme.txt in the logit.zip file)
#
# This script is coupled with logitpro.cgi
# 
# If you did not download this from logitpro.com, please do so
#
########

#Edit this if LogIT Fails to respond, exchange $ENV{'SCRIPT_NAME'} with the name of this script (ie: logitpro.cgi)
$script = $ENV{'SCRIPT_NAME'};

#set this to 1 if you forget your password... then set it back to 0 after you recover!!! IMPORTANT!!!!
$resetpass = 0;

#if you get a 500 error after installing, uncomment the next line (remove the # before "use CGI..."),
#and then submit a technical support request at http://helpdesk.logitpro.com

#use CGI::Carp qw(fatalsToBrowser);

#!!!!!DO NOT EDIT BELOW THIS LINE!!!!!
#I am sure that these translations are not perfect, please let me know if you know a better way of saying it
############################################
# copyright notice:  This program is copyright 1999-2000 BCS (LogIT PRO)
# You may not edit, configure, or misconfigure anything under this copyright
# notice without written consent from the maker.  Any altering will be
# defined as direct defiance of International copyright laws, and subject
# to fines and or punishment to the maximum of their degree in your country.
# Any plagiarism of this script without written consent from the maker will be
# defined as a direct defiance of International copyright laws, and subject
# to maximum fines and/or punishment as the laws are stated in your country.
#
# This copyright holds to the International Software Piracy Act
############################################
# la copie écrivent la notification: Ce programme est copie écrivent BCS 1999-2000 (LogIT PRO)
# vous peut ne pas éditer, configurent, ou le misconfigure quelque chose sous cette copie écrivent
# notification sans consentement écrit du générateur. modifier
# définir comme direct défit international copie écrire loi, et sujet
# amende et ou punition maximum leur degré dans votre pays
# tout plagiarism ce séquence type sans écrire consentement générateur
# définir tel que un direct défit international copie écrire loi, et sujet
# maximum amende et/ou punition tel que loi énoncer dans votre pays
#
# ce copie écrire prise international logiciel piraterie acte 
############################################
# la copie écrivent la notification: Ce programme est copie écrivent BCS 1999-2000 (LogIT PRO) 
# vous peut ne pas éditer, configurent, ou le misconfigure quelque chose sous cette copie écrivent 
# notification sans consentement écrit du générateur. modifier 
# définir comme direct défit international copie écrire loi, et sujet 
# fine et ou punition maximum leur degré dans votre pays
# tout plagiarism ce séquence type sans écrire consentement générateur 
# définir tel que un direct défit international copie écrire loi, et sujet
# maximum amende et/ou punition tel que loi énoncer dans votre pays
#
# ce copie écrire prise international logiciel piraterie acte 
############################################ 
# la copia escriben el aviso: Este programa es copia escribe BCS 1999-2000 (LogIT PRO) 
# usted puede no corregir, configura, o el misconfigure cualquier cosa bajo esta copia escribe 
# aviso sin consentimiento escrito del fabricante. alterar ser 
# definir como directo desafío internacional copia escribir ley, y tema 
# multa y o castigo máximo su grado en su país 
# cualquier plagiarism este escritura sin escribir consentimiento fabricante ser 
# definir a medida que uno directo desafío internacional copia escribir ley, y tema 
# máximo multa y/o castigo a medida que ley ser indicar en su país 
# 
# este copia escribir asimiento internacional software piratería acto 
############################################
########### DO NOT EDIT BELOW ##############
############################################
$noupdat=0;$HeaderPrinted=0;
$cookieExpLength = 7776000;
$verinfo = "2.2.6";
&ginput;
&GetCookies;

if ($INPUT{'llogin'} ne "") {&llogin;}
elsif ($INPUT{'logout'} ne "") {&logout;}
elsif (!($ENV{'QUERY_STRING'} =~ /img/)) {print "Content-type: text/html\n\n";}
else {&img;exit;}
&chk;
&ReadConfig;
if ($p1 eq $p2) {$INPUT{'pword'} = $LPConfig{'password'};}

if ($resetpass) {&NewConfig(1,1,1,1,1);}
elsif ($INPUT{'NewConfig'} ne "") {&NewConfig();}
elsif ($INPUT{'UpdateDataFile'} ne "") {&UpdateDataFile;}
elsif ($INPUT{'tref'} ne "") {&logcheck; &tref($INPUT{'tref'});}
elsif ($INPUT{'tpag'} ne "") {&logcheck; &tpag($INPUT{'tpag'});}
elsif ($INPUT{'tsrh'} ne "") {&logcheck; &tsrh($INPUT{'tsrh'});}
elsif ($INPUT{'fixips'} ne "") {&logcheck; &fixips;}
elsif ($INPUT{'ggdate'} ne "") {&ggdate;}
elsif ($INPUT{'fixwbak'} ne "") {&logcheck; &fixwbak;}
elsif ($INPUT{'autoupdate'} ne "") {&autoupdate;}
elsif ($INPUT{'updatedata'} ne "") {&updatedata;}
elsif ($INPUT{'makebak'} ne "") {&logcheck; &makebak;}
elsif ($INPUT{'fixblank'} ne "") {&logcheck; &fixblank;}
elsif ($INPUT{'fixtitle'} ne "") {&logcheck; &fixtitle;}
elsif ($INPUT{'delete'} eq "on") {&del;}
elsif ($INPUT{'login'} ne "") {&logcheck; &login;}
elsif ($INPUT{'llogin'} ne "") {&llogin;}
elsif ($INPUT{'logout'} ne "") {&logout;}
elsif ($INPUT{'gencode'} ne "") {&logcheck; &gencode;}
elsif ($INPUT{'hourb'} ne "") {&logcheck; &hourb;}
elsif ($INPUT{'dalyb'} ne "") {&logcheck; &dalyb;}
elsif ($INPUT{'weekb'} ne "") {&logcheck; &weekb;}
elsif ($INPUT{'montb'} ne "") {&logcheck; &montb;}
elsif ($INPUT{'lastvisits'} ne "") {&logcheck; &lastvisits;}
elsif ($INPUT{'lastrefers'} ne "") {&logcheck; &lastrefers;}
elsif ($INPUT{'lastsearch'} ne "") {&logcheck; &lastsearch;}
elsif ($INPUT{'toprefers'} ne "") {&logcheck; &toprefers;}
elsif ($INPUT{'topsearch'} ne "") {&logcheck; &topsearch;}
elsif ($INPUT{'topsearcheg'} ne "") {&logcheck; &topsearcheg;}
elsif ($INPUT{'toppages'} ne "") {&logcheck; &toppages;}
elsif ($INPUT{'topips'} ne "") {&logcheck; &topips;}
elsif ($INPUT{'topclr'} ne "") {&logcheck; &topclr;}#LogitPRO VIP Service
elsif ($INPUT{'topjva'} ne "") {&logcheck; &topjva;}#LogitPRO VIP Service
elsif ($INPUT{'dele'} ne "") {&dele($INPUT{'dele'});}
elsif ($INPUT{'tophosts'} ne "") {&logcheck; &tophosts;}
elsif ($INPUT{'topdomains'} ne "") {&logcheck; &topdomains;}
elsif ($INPUT{'topcountries'} ne "") {&logcheck; &topcountries;}
elsif ($INPUT{'topplatform'} ne "") {&logcheck; &topplatform;}
elsif ($INPUT{'topbrowser'} ne "") {&logcheck; &topbrowser;}
elsif ($INPUT{'frame'} ne "") {&frame($INPUT{'frame'});}
elsif ($INPUT{'track'} ne "") {&logcheck; &track($INPUT{'track'});}
elsif ($INPUT{'img'} ne "") {&img;}
elsif ($ENV{'QUERY_STRING'} =~ /closed/) {&closed;}
else {print "[<b>ERROR:</b> no action specified]";}
sub ReadConfig {
	$onoff = 0;
	unless (-e "data/d.dat") {$onoff = 1;}
	
	if ($onoff) {return;exit;}
	readit('DATA','data/d.dat',1);
	close (DATA);
	foreach $data (@tmp) {
		chomp($data);
		($varname, $varvalue) = split(/\|/, $data);
		$varvalue =~ s/^\s+//;
		$varvalue =~ s/\s+$//;
		$varvalue =~ s/\n//g;
		$LPConfig{$varname} = $varvalue;
	}
	&gimgs;
	if ($INPUT{'pword'} eq $guest) {$LPConfig{'ServerPath'} = "Not Shown to GUESTs";$LPConfig{'IPBlocked'} = "Not Shown to GUESTs";$LPConfig{'DomainBlocked'} = "Not Shown to GUESTs";$LPConfig{'mailprog'} = "Not Shown to GUESTs";$LPConfig{'yourmail'} = "Not Shown to GUESTs";$LPConfig{'password'} = "Not Shown to GUESTs";}
}
sub logcheck {
	if ($LPConfig{'passprt'} && !($Cookies{'login'} eq "yes")) {$noupdat=1;&login;}
	elsif ($LPConfig{'passprt'}) {print qq~<a href="$script?logout">logout</a><br>~;}
	else {}
	return;
}

sub fixips {
	open (TMP,"data/i.dat");@info=split(/\r/,<TMP>);close (TMP);
	open (BAK,">i.bak");foreach $line (@info){print BAK "$line\r";}close (BAK);
	open (TMP,">data/i.dat");
	flock (TMP,2);
	foreach $line (@info) {	
		@line=split(/\|/,$line);
		$host=$line[4];use Socket;
		@a=split(/\./,$host);$addr=pack('C4',@a);($name,$alias,$adrtype,$length,@address)=gethostbyaddr($addr,AF_INET);$host2=$name;
		$host = substr($host2, 0, 80);if ($host2 ne $host){$host .= qq~...~;}
		$line[5]=$host;
		print TMP (join("|",@line),"\r");print "$line[4] = $host<br>\r";
	}
	close (TMP);print "$name,$alias,$adrtype,$length,";print @address;
}
sub fixtitle {
	open (TMP,">data/i.dat");
	flock (TMP,2);
	foreach $line (@info) {	
		@line=split(/\|/,$line);
		if (!($line[10] && $line[10] ne "") && ($line[3] ne "" && $line[3])){$domain="$line[3]";$line[10]=&gettitle();$line[10]=~s/\'/\`/g;$line[10]=~s/\"/\`\`/g;$line[10]=~s/\|/\`/g;$line[10]=~s/\~/\`\`/g;}
		print TMP (join("|",@line),"\r");print "$line[3] = $line[10]<br>\r";
	}
	close (TMP);
}
sub fixwbak {
	&header('Using THE Backup files');
	@bak = ("data/i|info","data/c|count","data/o|overall","data/h|href","data/m|month and week","data/ip|daily ips");
	foreach $line (@bak) {
		@a = split(/\|/,$line);
		@b = ("$a[0].dat","$a[0].bak");
		$yesno = rename $b[1],$b[0];
		if ($yesno) {$pt = qq~$IMG[3]> $a[1] backup has been used.....<br>~;
			open (FILE,"$b[0]");
			($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat(FILE);
			close (FILE);
			if  ($size > 1) {$pt .= qq~$IMG[10] width=5 height=1>$IMG[3]> $a[1] backup has STUCK!<br>~;}
			else {$pt .= qq~$IMG[10] width=5 height=1>$IMG[2]> ERROR: $a[1] backup has been lost...<br>~;}
		}
		else {$pt = qq~$IMG[2]>ERROR: $a[1] backup could not be used.....<br>~;}
		open (TMP,"$b[0]");
		@tmp = <TMP>;
		close (TMP);
		open (TMP,">$b[1]");
		print TMP @tmp;
		close (TMP);
		$onoff = 1;unless (-e $b[1]) {$onoff = 0;}
		if ($onoff) {
			$pt .= qq~$IMG[10] width=15 height=1>$IMG[3]> $a[1] backup has been created.....<br>~;
			open (FILE,"$b[1]");
			($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat(FILE);
			close (FILE);
			if  ($size > 1) {$pt .= qq~$IMG[10] width=15 height=1>$IMG[3]> $a[1] backup has been finished<br><Br>~;}
			else {$pt .= qq~$IMG[10] width=15 height=1>$IMG[2]>ERROR: data could not put into $a[1] backup file<br><BR>~;}
		}
		else {$pt .= qq~$IMG[10] width=15 height=1>$IMG[2]>ERROR: $a[1] backup has NOT been created..... <br><br>~;}
		print $pt;
	}
	print qq~$IMG[0]>Finished doing backup routine... if errors occured, please try again~;
	&footer;
	print qq~<script>
	alert('All Data files have (hopefully) been restored through the backup,  Please read the text behind this box, and then click ok');
	</script>~;
}
sub fixblank {
	&makebak;open (TMP,"data/i.dat");@info2=split(/\r/,<TMP>);close (TMP);
	open (TMP,">data/i.dat");
	foreach $line (@info2) {
		@line=split(/\|/,$line);
		if (($line[0] ne "") && ($line[1] ne "") && ($line[2] ne "")) {
			print TMP "$line[0]|$line[1]|$line[2]|$line[3]|$line[4]|$line[5]|$line[6]|$line[7]|$line[8]|$line[9]|$line[10]|\r";
		}
		else {print @line;print "<font color=red><-- this line was not updated</font><br>";}
	}
	close (TMP);
}
sub makebak {
	&header('Creating THE Backup files');
	@bak = ("data/i|info","data/c|count","data/o|overall","data/h|href","data/m|month and week","data/ip|daily ips");
	foreach $line (@bak) {
		@a = split(/\|/,$line);
		@b = ("$a[0].dat","$a[0].bak");
		open (TMP,"$b[0]");
		@tmp = <TMP>;
		close (TMP);
		open (TMP,">$b[1]");
		print TMP @tmp;
		close (TMP);
		$onoff = 1;unless (-e $b[1]) {$onoff = 0;}
		if ($onoff) {
			$pt = qq~$IMG[3]> $a[1] backup has been created.....<br>~;
			open (FILE,"$b[1]");
			($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat(FILE);
			close (FILE);
			if  ($size > 1) {$pt .= qq~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$IMG[3]> $a[1] backup has been finished<br><Br>~;}
			else {$pt .= qq~&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$IMG[2]>ERROR: data could not put into $a[1] backup file<br><BR>~;}
		}
		else {$pt = qq~$IMG[2]>ERROR: $a[1] backup has NOT been created..... <br><br>~;}
		print $pt;
	}
	print qq~$IMG[0]>Finished doing backup routine... if errors occured, please try again~;
	&footer;
	print qq~<script>
	alert('A Backup of all your logitpro files has been made');
	</script>~;
}

sub del {
	if ($INPUT{'pword'} ne $LPConfig{'password'}) {&ErroR('Problem.... WRONG PASSWORD!!!');}
	open (TMP,"data/i.dat");@info = split(/\r/,<TMP>);close (TMP);$b=0;
	$del=~s/[^\w]/_/g;
	foreach $line (@info) {
		@line=split(/\|/,$line);$lline="$line\r";
		$line[0] =~ s/[^\w]/_/g;
		if (!($del =~ /$line[0]/)) {if ($b) {push @ino,$lline;} else {@ino=$lline;}}
		$b++;
	}
	open (LOCK,">lock.test");flock (LOCK,2);print LOCK "1234567890";close (LOCK);
	open (LOCK,"lock.test");@lock = <LOCK>;if ($lock[0] eq "1234567890") {$ynprint = 1;} else {$ynprint = 0;}
	open (LOCK,">lock.test");close(LOCK);
	if ($ynprint) {open (TMP,">data/i.dat");flock (TMP,2);print TMP @ino;close (TMP);}
	else {print qq~
	<H1>ERROR - READ/WRITE</h1>
	<br><Br>There was a problem writing to the files on your server.  Possible problems include: no space on disk, files are currently locked and/or being writtian to
	~;}
	print "Settings updated/deleted...<br><Br>";$INPUT{'pword'} = "";&login;
}

#Login
sub login {
	$frames= "login";
	print shift;
	print "<br>";
	&header("LogIT PRO LOGIN AREA");
	if ($LPConfig{'passprt'} && !($Cookies{'login'} eq "yes")) {
		print qq~<br> $Cookies{'login'} <br><Br>
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center  class="dark">In order
		to edit your configurations, you must enter your admin password here and press enter
		</td></tr><tr><Td  class="light">
		<form action=$script method=post><input type=hidden name="NewConfig" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble" >
		<tr><td valign=center align=center  class="dark">You must login
		to view your statistics.</td></tr><tr><Td class="light">
		<form action=$script method=post><input type=hidden name="llogin" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center  class="dark">Reset files
		</td></tr><tr><Td  class="light">
		<form action=$script method=post>
		Password: <input type=password name=pword value="">
		<select name=dele>
		<option>-Please select one-</option>
		<option value="i.dat">Info File</option>
		<option value="c.dat">Today's Count file</option>
		<option value="o.dat">Overall Count file</option>
		<option value="h.dat">Day by day hit file</option>
		<option value="m.dat">Week and Month hit file</option>
		<option value="ip.dat">Today's Unique ips</option>
		<option value="r.dat">Old/New Referral Database</option>
		<option value="all">All of the data files</option>
		<option value="revert">Revert to Setup (del data dir)</option>
		</select>
		<input type=submit value="DELETE!">
		</form>
		</td></tr>\r</table>
		~;
	}
	elsif ($LPConfig{'passprt'}) {
		print qq~<br>
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade  class="tble">
		<tr><td valign=center align=center  class="dark">In order
		to edit your configurations, you must enter your admin password here and press enter
		</td></tr><tr><Td  class="light">You are logged in, but for security reasons, you must still type your password to view configurations:<br><Br>
		<form action=$script method=post><input type=hidden name="NewConfig" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center  class="dark">You are Logged In
		</td></tr><tr><Td class="light">
		<form action="$script" method=post><input type=hidden name="logout" value=1>
		<input type="submit" value="LogOUT!"></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade  class="tble">
		<tr><td valign=center align=center class="dark">Reset files
		</td></tr><tr><Td  class="light">You are logged in, but for security reasons, you must still type your password to view configurations:<br><Br>
		<form action=$script method=post>
		Password: <input type=password name=pword value="">
		<select name=dele>
		<option>-Please select one-</option>
		<option value="i.dat">Info File</option>
		<option value="c.dat">Today's Count file</option>
		<option value="o.dat">Overall Count file</option>
		<option value="h.dat">Day by day hit file</option>
		<option value="m.dat">Week and Month hit file</option>
		<option value="ip.dat">Today's Unique ips</option>
		<option value="r.dat">Old/New Referral Database</option>
		<option value="all">All of the data files</option>
		<option value="revert">Revert to Setup (del data dir)</option>
		</select>
		<input type=submit value="DELETE!">
		</form>
		</td></tr>\r</table>
		~;
		}
	else {
	print qq~<br>
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade  class="tble">
		<tr><td valign=center align=center class="dark">In order
		to edit your configurations, you must enter your admin password here and press enter
		</td></tr><tr><Td class="light">
		<form action=$script method=post><input type=hidden name="NewConfig" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">Reset files
		</td></tr><tr><Td class="light">
		<form action=$script method=post>
		Password: <input type=password name=pword value="">
		<select name=dele>
		<option>-Please select one-</option>
		<option value="i.dat">Info File</option>
		<option value="c.dat">Today's Count file</option>
		<option value="o.dat">Overall Count file</option>
		<option value="h.dat">Day by day hit file</option>
		<option value="m.dat">Week and Month hit file</option>
		<option value="ip.dat">Today's Unique ips</option>
		<option value="r.dat">Old/New Referral Database</option>
		<option value="all">All of the data files</option>
		<option value="revert">Revert to Setup (del data dir)</option>
		</select>
		<input type=submit value="DELETE!">
		</form>
		</td></tr>\r</table>
	~;
	}
	&footer;
	exit;
}
sub llogin {
	$frames= "llogin";
	open (DATA,'data/d.dat');
	$tmp = <DATA>;
	@tmp = split(/\r/,$tmp);
	close (DATA);
	foreach $data (@tmp) {
		chomp($data);
		($varname, $varvalue) = split(/\|/, $data);
		$varvalue =~ s/^\s+//;
		$varvalue =~ s/\s+$//;
		$varvalue =~ s/\n//g;
		$LPConfig{$varname} = $varvalue;
	}
	if ($p1 eq $p2) {$INPUT{'pword'} = $LPConfig{'password'};}
	if (!($INPUT{'pword'} eq $LPConfig{'password'})) {&ErroR('Password is wrong... Please re-enter');}
	else {
		SetCookies('login','yes','login','yes');
		&header("LogIT PRO LOGIN AREA");
		print "LOGGED IN!";
		
		print qq~<br>
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">In order
		to edit your configurations, you must enter your admin password here and press enter
		</td></tr><tr><Td class="light">You are logged in, but for security reasons, you must still type your password to view configurations:<br><Br>
		<form action=$script method=post><input type=hidden name="NewConfig" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">You are Logged In
		</td></tr><tr><Td class="light">
		<form action="$script" method=post><input type=hidden name="logout" value=1>
		<input type="submit" value="LogOUT!"></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">Reset files
		</td></tr><tr><Td class="light">You are logged in, but for security reasons, you must still type your password to view configurations:<br><Br>
		<form action=$script method=post>
		Password: <input type=password name=pword value="">
		<select name=dele>
		<option>-Please select one-</option>
		<option value="i.dat">Info File</option>
		<option value="c.dat">Today's Count file</option>
		<option value="o.dat">Overall Count file</option>
		<option value="h.dat">Day by day hit file</option>
		<option value="m.dat">Week and Month hit file</option>
		<option value="ip.dat">Today's Unique ips</option>
		<option value="r.dat">Old/New Referral Database</option>
		<option value="all">All of the data files</option>
		<option value="revert">Revert to Setup (del data dir)</option>
		</select>
		<input type=submit value="DELETE!">
		</form>
		</td></tr>\r</table>
		~;
		&footer;
		exit;
	}
}
sub logout {
	$frames= "logout";
	&ClearCookies;
	&header("Logged Out of LogIT PRO");
	print qq~successful logout!~;
	
	
	print qq~<br>
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">In order
		to edit your configurations, you must enter your admin password here and press enter
		</td></tr><tr><Td class="light">
		<form action=$script method=post><input type=hidden name="NewConfig" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">You must login
		to view your statistics.</td></tr><tr><Td class="light">
		<form action=$script method=post><input type=hidden name="llogin" value=1>
		Password: <input type=password name=pword value=""></form>
		</td></tr>\r</table>
		
		<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
		<tr><td valign=center align=center class="dark">Reset files
		</td></tr><tr><Td class="light">
		<form action=$script method=post>
		Password: <input type=password name=pword value="">
		<select name=dele>
		<option>-Please select one-</option>
		<option value="i.dat">Info File</option>
		<option value="c.dat">Today's Count file</option>
		<option value="o.dat">Overall Count file</option>
		<option value="h.dat">Day by day hit file</option>
		<option value="m.dat">Week and Month hit file</option>
		<option value="ip.dat">Today's Unique ips</option>
		<option value="r.dat">Old/New Referral Database</option>
		<option value="all">All of the data files</option>
		<option value="revert">Revert to Setup (del data dir)</option>
		</select>
		<input type=submit value="DELETE!">
		</form>
		</td></tr>\r</table>
        <br><br>The footer will not be displayed for security reasons
		~;
	exit;	
}

#Hourly Breakdown
sub hourb {
	$frames= "hourb";
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat for reading');
	@info = split(/\r/,<INFO>);
	close (INFO);
	&header("LogIT PRO HOURLY BREAKDOWN AREA");
	$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Time Span  $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd </tr>";
	&ghour;$table.=qq~</table></center>~;
	print qq~<center></center><br>~;
	print $table;
	&footer;
}
sub ghour {
	$c=0;
	print "<table>";
	foreach $line (@info) {
		@line = split(/\|/,$line);
		($p,$z) = split (/\:/,$line[2]);
		if (($z =~ /p/) && ($p ne 12)) {$p = ($p+12);}
		elsif (($p == 12) && (($z =~ /a/oi) || ($z =~ /A/oi))) {$p=0;}
		elsif ($p == 24) {$p=0;}
		if ($p > 23) {$p=$p-12;}
		if ($hc[$p] ne "") {$hc[$p] = ($hc[$p] + 1);} else {$hc[$p]=1;}
		$c++;
	}
	$tmp="";
	if ($LPConfig{'TimeHourFormat'} eq "12") {@hours = ("12:00 - 12:59 AM","1:00 - 1:59 AM","2:00 - 2:59 AM",
	"3:00 - 3:59 AM","4:00 - 4:59 AM","5:00 - 5:59 AM","6:00 - 6:59 AM","7:00 - 7:59 AM",
	"8:00 - 8:59 AM","9:00 - 9:59 AM","10:00 - 10:59 AM","11:00 - 11:59 AM","12:00 - 12:59 PM",
	"1:00 - 1:59 PM","2:00 - 2:59 PM","3:00 - 3:59 PM","4:00 - 4:59 PM","5:00 - 5:59 PM",
	"6:00 - 6:59 PM","7:00 - 7:59 PM","8:00 - 8:59 PM","9:00 - 9:59 PM","10:00 - 10:59 PM",
	"11:00 - 11:59 PM","12:00 - 12:59 AM");}
	else {@hours = ("2400 - 0059","0100 - 0159","0200 - 0259","0300 - 0359","0400 - 0459","0500 - 0559",
	"0600 - 0659","0700 - 0759","0800 - 0859","0900 - 0959","1000 - 1059","1100 - 1159","1200 - 1259",
	"1300 - 1359","1400 - 1459","1500 - 1559","1600 - 1659","1700 - 1759","1800 - 1859","1900 - 1959",
	"2000 - 2059","2100 - 2159","2200 - 2259","2300 - 2359","2400 - 0059");}
	$max=0;foreach $line (@hc) {if ($line > $max) {$max = $line;}}
	$wid=(300/$max);
	$b = 1;foreach $line (@hc) {
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		$width=($line*$wid);
		$prct = (($line/$c)*300);
		$prct1 = substr((($line/$c)*100),0,4);$prct1.="%";
		$prctt = (($max/$c)*300);
		$prcttt = (($prct/$prctt)*100);
		if ($width > 300) {$width =300;}
		if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
		$table .= "<tr class=$color><th class=tble class=tble width=10><font size=2>$line</font></th><td class=tble nowrap><font size=2>$hours[$b]</font></td><td class=tble align=left valign=center ><font size=1>$IMG[$ii] width=$width height=8> &nbsp; $prct1</font></td></tr>\r";
		$b++;
	}
}

#Daily Breakdown
sub dalyb {
	$frames= "dalyb";
	&header("LogIT PRO DAILY BREAKDOWN AREA");
	open (HIST,"data/h.dat");
	@hist = split(/\r/,<HIST>);@hista="";@histb="";@histc="";
	open (TMP,"data/c.dat");@count = split(/\|/,<TMP>);close (TMP);
	open (TMP,"data/t.overall");$tmp=length <TMP>;close (TMP);$overall[1] = ($overall[1] + $tmp);
	open (TMP,"data/u.overall");$tmmp=length <TMP>;close (TMP);$overall[2] = ($overall[2] + $tmmp);
	open (TMP,"data/t.count");$tmpz=length <TMP>;close (TMP);$count[0] = ($count[0] + $tmpz);
	open (TMP,"data/u.count");$tmmpz=length <TMP>;close (TMP);$count[1] = ($count[1] + $tmmpz);
	
	push @hista,"Today";push @histb,$count[0];push @histc,$count[1];
	foreach $line (@hist) {
		@l=split(/\|/,$line);
		push @hista,$l[0];push @histb,$l[1];push @histc,$l[2];
	}
	$tt=0;$maxt=0;$b=0;foreach $line (@hista) {if ($maxt<$histb[$b] && $histb[$b] ne "") {$maxt=$histb[$b];}if ($maxt<$histc[$b] && $histc[$b] ne "") {$maxt=$histc[$b];}$tt=$tt+$histb[$b]+$histc[$b];$b++;}
	$widt=(400/$maxt);$table0="";
	$b=1;foreach $line (@hista) {
		if ($hista[$b] ne "") {
			if (($b / 2) =~ /\./) {$color="tddark"}
			else {$color="tdlight"}
			$width=($histb[$b]*$widt);
			$prct=substr((($histb[$b]/$tt)*100),0,4);$prct1="$prct%";
			$prcttt=(($histb[$b]/$maxt)*100);
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table0.=qq~<tr class="tddark"><td rowspan=2 class=$color><font size=2>$hista[$b]</font></td><th class=tble class=tble><font size=2>$histb[$b]</font></th><td class=tble><font size=1>$prct1</font></td><td class=tble>$IMG[$ii] width=$width height=8 border=1></td></tr>\r~;
			$width=($histc[$b]*$widt);
			if ($width > 400) {$width = 400;}
			$prct=substr((($histc[$b]/$tt)*100),0,4);$prct1="$prct%";
			$prcttt=(($histc[$b]/$maxt)*100);
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table0.=qq~<tr class="tdlight"><th class=tble class=tble><font size=2>$histc[$b]</font></th><td class=tble><font size=1>$prct1</font></td><td class=tble>$IMG[$ii] width=$width height=8 border=1></td></tr>\r~;
			$table0.=qq~<tr class="dark"><td class=tble colspan=4>&nbsp;</td></tr>~;
			}
		$b++;
	}	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	print qq~<br><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr><th class=tble class=tble colspan=4>Daily Hits (total/unique)</th></tr><tr class="dark">$ttd Day $tdd $ttd hits total/unique $tdd$ttd percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more]$tdd </tr>\r$table0</table>~;
	&footer;
}



#Weekly Breakdown
sub weekb {
	$frames= "weekb";
	&header("LogIT PRO WEEKLY BREAKDOWN AREA");
	open (TMP,"data/m.dat");($weekdays,$months) = split(/\r/,<TMP>);close (TMP);
	@weekdays = split(/\|/,$weekdays);
	$weekday = "";
	foreach $line (@weekdays) {
		@l = split(/\:/,$line);
		($l[1],$l[2]) = split(/\~/,$l[1]);
		push @weeka,$l[0];push @weekb,$l[1];push @weekc,$l[2];
	}
	$tt=0;$maxt=0;$b=0;foreach $line (@weeka) {if ($maxt<$weekb[$b] && $weekb[$b] ne "") {$maxt=$weekb[$b];}if ($maxt<$weekc[$b] && $weekc[$b] ne "") {$maxt=$weekc[$b];}$tt=$tt+$weekb[$b]+$weekc[$b];$b++;}
	$widt=(400/$maxt);$table0="";
	$b=0;foreach $line (@weeka) {
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		$width=($weekb[$b]*$widt);
		if ($width > 400) {$width = 400;}
		$prct=substr((($weekb[$b]/$tt)*100),0,4);$prct1="$prct%";
		$prcttt=(($weekb[$b]/$maxt)*100);
		if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
		$table0.=qq~<tr class="tddark"><td class=$color rowspan=2><font size=2>$weeka[$b]</font></td><th class=tble class=tble><font size=2>$weekb[$b]</font></th><td class=tble><font size=1>$prct1</font></td><td class=tble>$IMG[$ii] width=$width height=8 border=1></td></tr>\r~;
		$width=($weekc[$b]*$widt);
		if ($width > 400) {$width = 400;}
		$prct=substr((($weekc[$b]/$tt)*100),0,4);$prct1="$prct%";
		$prcttt=(($weekc[$b]/$maxt)*100);
		if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
		$table0.=qq~<tr class="tdlight"><th class=tble class=tble><font size=2>$weekc[$b]</font></th><td class=tble><font size=1>$prct1</font></td><td class=tble>$IMG[$ii] width=$width height=8 border=1></td></tr>\r~;
		$table0.=qq~<tr class="dark"><td class=tble colspan=4>&nbsp;</td></tr>~;
		$b++;
	}$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	
	print qq~<br><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr><th class=tble class=tble colspan=4>Days of the Week</th></tr>\r<tr class="dark">$ttd Weekday $tdd$ttd Hits (total/unique) $tdd$ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd </tr>$table0</table>~;
	&footer;
}
#Monthly Breakdown
sub montb {
	$frames= "montb";
	open (TMP,"data/m.dat");($months,$weekdays) = split(/\r/,<TMP>);close (TMP);
	&header("LogIT PRO MONTHLY BREAKDOWN AREA");
	@weekdays = split(/\|/,$weekdays);
	$weekday = "";
	foreach $line (@weekdays) {
		@l = split(/\:/,$line);
		($l[1],$l[2]) = split(/\~/,$l[1]);
		push @weeka,$l[0];push @weekb,$l[1];push @weekc,$l[2];
	}
	$tt=0;$maxt=0;$b=0;foreach $line (@weeka) {if ($maxt<$weekb[$b] && $weekb[$b] ne "") {$maxt=$weekb[$b];}if ($maxt<$weekc[$b] && $weekc[$b] ne "") {$maxt=$weekc[$b];}$tt=$tt+$weekb[$b]+$weekc[$b];$b++;}
	$widt=(400/$maxt);$table0="";
	$b=0;foreach $line (@weeka) {
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		$width=($weekb[$b]*$widt);
		if ($width > 400) {$width = 400;}
		$prct=substr((($weekb[$b]/$tt)*100),0,4);$prct1="$prct%";
		$prcttt=(($weekb[$b]/$maxt)*100);
		if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
		$table0.=qq~<tr class="tddark"><td class=$color rowspan=2><font size=2>$weeka[$b]</font></td><th class=tble class=tble><font size=2>$weekb[$b]</font></th><td class=tble><font size=1>$prct1</font></td><td class=tble>$IMG[$ii] width=$width height=8 border=1></td></tr>\r~;
		$width=($weekc[$b]*$widt);
		if ($width > 400) {$width = 400;}
		$prct=substr((($weekc[$b]/$tt)*100),0,4);$prct1="$prct%";
		$prcttt=(($weekc[$b]/$maxt)*100);
		if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
		$table0.=qq~<tr class="tdlight"><th class=tble class=tble><font size=2>$weekc[$b]</font></th><td class=tble><font size=1>$prct1</font></td><td class=tble>$IMG[$ii] width=$width height=8 border=1></td></tr>\r~;
		$table0.=qq~<tr class="dark"><td class=tble colspan=4>&nbsp;</td></tr>~;
		$b++;
	}$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	print qq~<br><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr><th class=tble colspan=4>Month by Month</th></tr>\r<tr class="dark">$ttd Month  $tdd$ttd Hits $tdd$ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd </tr>$table0</table>~;
	&footer;
}
#last $LPConfig{'LastVisits'} visitors
sub lastvisits {
	$frames= "lastvisits";
	&header("LogIT PRO LAST VISITS AREA");
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'LastVisits'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<form method=post action="$script"><input type=hidden name=delete value=on>
	$IMG[4]>=track local page (click)&nbsp; &nbsp; &nbsp; $IMG[0]>=track domain (click)&nbsp; &nbsp; &nbsp; $IMG[1]>=track ip (click)&nbsp; &nbsp; &nbsp; $IMG[2]>=Error (hold mouse over or click)&nbsp; &nbsp; &nbsp; $IMG[3]>=referral (hold mouse over or click)<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	&glstvis;$table .= qq~</table><input type=password name=pword><input type=submit value="Delete selected items"></form></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=lastvisits>Change the amount listed:<br>
		<select name="list">~;print gopts($list);print qq~</select>
		<input type=submit value="List IT!"></form></center>~;
	print $table;
	&footer;
}
sub dele {
	if ($INPUT{'pword'} && ($INPUT{'pword'} eq $LPConfig{'password'})) {
	$dele = shift;
	if ($dele eq "m.dat") {unlink "data/m.dat";open (TMP,">data/m.dat") || ErroR("Error creating monthly-daily data file 'm.dat'");print TMP "Sun:|Mon:|Tue:|Wed:|Thu:|Fri:|Sat:|\rJan:|Feb:|Mar:|Apr:|May:|Jun:|Jul:|Aug:|Sep:|Oct:|Nov:|Dec:|";close (TMP);&header('deleted the month/week file');print "finished...";&footer;}
	elsif ($dele eq "h.dat") {unlink "data/h.dat";open (TMP,">data/h.dat") || ErroR("Error creating history data file 'h.dat'");close (TMP);&header('deleted the daily file');print "finished...";&footer;} #history
	elsif ($dele eq "ip.dat") {unlink "data/ip.dat";open (TMP,">data/ip.dat") || ErroR("Error creating daily ip data file 'ip.dat'");close (TMP);&header('deleted today`s unique ip file');print "finished...";&footer;} #ip
	elsif ($dele eq "r.dat") {unlink "data/r.dat";open (TMP,">data/r.dat") || ErroR("Error creating referer newlink data file 'r.dat'");close (TMP);&header('deleted the new/old referrer file');print "finished...";&footer;} #href
	elsif ($dele eq "c.dat") {
		unlink "data/u.overall";open (TMP,">data/u.overall") || ErroR("Error creating the count data file 'c.dat'");close (TMP);
		unlink "data/t.overall";open (TMP,">data/t.overall") || ErroR("Error creating the count data file 'c.dat'");close (TMP);
		unlink "data/u.count";open (TMP,">data/u.count") || ErroR("Error creating the count data file 'c.dat'");close (TMP);
		unlink "data/t.count";open (TMP,">data/t.count") || ErroR("Error creating the count data file 'c.dat'");close (TMP);
		unlink "data/c.dat";open (TMP,">data/c.dat") || ErroR("Error creating the count data file 'c.dat'");close (TMP);
		&header('deleted today`s hit count file');print "finished...";&footer;
	} #count
	elsif ($dele eq "i.dat") {unlink "data/i.dat";open (TMP,">data/i.dat") || ErroR("Error creating info data file 'i.dat'");close (TMP);&header('deleted the info file');print "finished...";&footer;} #info
	elsif ($dele eq "o.dat") {&gdate;unlink "data/o.dat";open (TMP,">data/o.dat") || ErroR("Error creating overall data file 'o.dat'");print TMP "$date\, $clock|0|0|";close (TMP);&header('deleted the overall file');print "finished...";&footer;} #overall	
	elsif ($dele eq "all") {unlink "data/m.dat";unlink "data/o.dat";unlink "data/i.dat";unlink "data/c.dat";unlink "data/r.dat";unlink "data/ip.dat";unlink "data/h.dat";&chk;&header('deleted all of the files');print "finished...";&footer;}
	elsif ($dele eq "revert") {
		opendir(TMP,"data");
		@a = readdir(TMP);closedir(TMP);
		foreach $del (@a) {
			if ($del ne "." && $del ne "..") {
				$del = "data/$del";
				$deel = unlink $del;
				if ($deel) {print " &nbsp; &nbsp; $del - deleted!<br>\r";}
				else {print " &nbsp; &nbsp; $del - NOT DELETED!<br>\r";}
			}
		}
		rmdir "data";print " &nbsp; &nbsp; data/ - deleted!<br>\r";
		unlink "search.dat";print " &nbsp; &nbsp; search.dat - deleted!<br>\r";
		print "<br><Br>Everything has been deleted/removed from the logit directory except for logitpro.cgi and extras.bin (and any other file that you uploaded, and wasn't created by logitpro)";
		print "<br><Br>once you run $script?login , everything will be recreated fresh just like you are using it for the first time";
	}
	elsif (!($dele eq "d.dat")) {unlink "$dele";}}
}
sub chk {	
	unless (-e "data") {mkdir "data",755;$mode = 0700;   chmod $mode, 'data';  }    
	unless (-e "data/h.dat") {open (TMP,">data/h.dat") || ErroR("Error creating history data file 'h.dat'");close (TMP);} #history
	unless (-e "data/ip.dat") {open (TMP,">data/ip.dat") || ErroR("Error creating daily ip data file 'ip.dat'");close (TMP);} #ip
	unless (-e "data/r.dat") {open (TMP,">data/r.dat") || ErroR("Error creating referer newlink data file 'r.dat'");close (TMP);} #href
	unless (-e "data/m.dat") {open (TMP,">data/m.dat") || ErroR("Error creating monthly-daily data file 'm.dat'");print TMP "Sun:|Mon:|Tue:|Wed:|Thu:|Fri:|Sat:|\rJan:|Feb:|Mar:|Apr:|May:|Jun:|Jul:|Aug:|Sep:|Oct:|Nov:|Dec:|";close (TMP);} #monthly
	unless (-e "data/c.dat") {open (TMP,">data/c.dat") || ErroR("Error creating the count data file 'c.dat'");close (TMP);} #count
	unless (-e "data/i.dat") {open (TMP,">data/i.dat") || ErroR("Error creating info data file 'i.dat'");close (TMP);} #info
	unless (-e "data/o.dat") {&gdate;open (TMP,">data/o.dat") || ErroR("Error creating overall data file 'o.dat'");print TMP "$date\, $clock|0|0|";close (TMP);} #overall
	if ($INPUT{'UpdateDataFile'} ne "") {&UpdateDataFile;exit;}
	unless (-e "data/d.dat") {&gimgs;&NewConfig("Configurations have either not been set, or have been deleted",1);}#data
}
sub glstvis {
	$b=1;
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		$lisst[2] =~ s/ //g;
		if ($dte ne $lisst[1]) {
			$dte = $lisst[1];
			$dayy = gday($lisst[0]);
			$table .= "<tr><td colspan=5 class=light><center><b>$dayy, $dte</b></center></td></tr>\r";
			$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
			$table .= "<tr class=dark>$ttd Extra $tdd $ttd Time $tdd$ttd IP Address  $tdd$ttd Host name  $tdd$ttd Accessed Page $tdd </tr>";
		}
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if ($lisst[4] ne "" && $lisst[4]) {
			$lisst[4] = substr($lisst[4],0,15);
			$imagg3 = qq~<a href="$script?track=$lisst[4]">$IMG[1] alt="Click here to track the ip: $lisst[4]" border=0></a>~;
		}
		else {$imagg3 = qq~$IMG[11]>~;}
		if ($lisst[5] ne "" && $lisst[5]) {
			$lisst[5] = substr($lisst[5],0,35);
			@tmp = split (/\./,$lisst[5]);$tmp1=$tmp[$#tmp];$tmp0=$tmp[($#tmp-1)];$tmp2=$tmp[($#tmp-2)];if ($tmp0 eq "com") {$tmp0="$tmp2.$tmp0";}$domain = "$tmp0.$tmp1";
			$imagg4 = qq~<A href="$script?track=$domain">$IMG[0] alt="Click here to track the domain: $domain" border=0></a>~;
		} 
		else {$imagg4 = qq~$IMG[11]>~;}
		if ($lisst[10] ne "") {$lisst[10]="($lisst[10])";}else{$lisst[10]=""}
		if ($lisst[9] ne "" && $lisst[9]) {
			$lisst[10] =~ s/\'//g;$imagg1 = qq~<a href="$script?tsrh=$lisst[9]:$lisst[3]">$IMG[3] alt="Referred by Search: $lisst[9]" border=0></a>~;
		}
		elsif ($lisst[3] ne "" && $lisst[3]) {
			$lisst[10] =~ s/\'//g;$imagg1 = qq~<a href="$script?tref=$lisst[3]">$IMG[3] alt="Referred by: $lisst[10] $lisst[3]" border=0></a>~;
		} 
		else {$imagg1 = qq~$IMG[11]>~;}
		$check = 0;
		
		($lisst[8],$check) = split(/~x~/,$lisst[8]);
		if ($check =~ /\*/) {
			$lisst[8] =~ s/\'//g;
			$imagg2 = qq~$IMG[2] alt="Accessed page: $lisst[8] was not found on your server at $lisst[2], $lisst[1]">~;$imagg5 = qq~$IMG[11]>~;
		} 
		else {$imagg2 = qq~$IMG[11]>~;$imagg5 = qq~<a href="$script?tpag=$lisst[8]">$IMG[4] alt="track local page: $lisst[8]" border=0></a>~;}
		$shortl8 = substr($lisst[8],-20,20);
		if ($shortl8 ne $lisst[8]) {$lisst[8]=qq~...<A href="$lisst[8]" TARGET="_blank">$shortl8</a>~;}
		else {$lisst[8]=qq~<A href="$lisst[8]" TARGET="_blank">$shortl8</a>~;}
		$table .= qq~<tr class=$color><td class=tble nowrap><input type=checkbox name="$lisst[0]"> $imagg1$imagg2$imagg3$imagg4$imagg5 </td><td class=tble nowrap><font size=2>$lisst[2]</font></td><td class=tble nowrap><font size=2><a href="$script?track=$lisst[4]">$lisst[4]</a></font></td><td class=tble nowrap><font size=2><a href="$script?track=$lisst[5]">$lisst[5]</a></font></td><td class=tble nowrap><font size=2>$lisst[8]</font></td></tr>\r~;
		$b++;
		if ($b > $list) {return;exit;}
	}
}

#Last $LPConfig{'LastVisits'} Referrers
sub lastrefers {
	$frames= "lastrefers";
	&header("LogIT PRO LAST REFERRERS AREA");
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'LastVisits'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><form method=post action="$script"><input type=hidden name=delete value=on><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	&glstref;$table .= qq~</table><input type=password name=pword><input type=submit value="Delete selected items"></form></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=lastrefers>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print $table;
	&footer;
}
sub glstref {$b=1;
	foreach $line (@info) {
		$newimg = "";
		@lisst = split(/\|/,$line);
		if ($dte ne $lisst[1]) {
			$dte = $lisst[1];
			$dayy = gday($lisst[0]);
			$table .= "<tr><td colspan=4 class=light><center><b>$dayy, $dte</b></center></td></tr>\r";$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
			$table .= "<tr class=dark>$ttd Extra $tdd $ttd Time $tdd$ttd Referrer $tdd$ttd Accessed Page $tdd </tr>";
		}
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if ((($lisst[3]) && ($lisst[3] ne "")) && (!($lisst[9] =~ /\:/))) {
			if ($lisst[10] && $lisst[10] ne "") {$lisst3 = substr($lisst[10],0,23);if ($lisst3 ne $lisst[10]) {$lisst3 = substr($lisst[10],0,10);$lisst3 .= "<b>...</b>";$lisst3 .= substr($lisst[10],-10,10);}}
			else {$lisst3 = substr($lisst[3],0,63);if ($lisst3 ne $lisst[3]) {$lisst3 = substr($lisst[3],7,20);$lisst3 .= "<b>...</b>";$lisst3 .= substr($lisst[3],-20,20);}}
			($lisst[8],$check) = split(/~x~/,$lisst[8]);
			if ($check =~ /\*/) {
				$lisst[8] =~ s/\'//g;
				$imagg2 = qq~$IMG[2] alt="Accessed page: $lisst[8] was not found on your server at $lisst[2], $lisst[1]" onClick="alert('Accessed page: $lisst[8] was not found on your server at $lisst[2], $lisst[1]');">~;
			} 
			else {$imagg2 = qq~$IMG[11]>~;}
			$shortl8 = substr($lisst[8],-20,20);
			if ($shortl8 ne $lisst[8]) {$lisst[8]=qq~...<A href="$lisst[8]" TARGET="_blank">$shortl8</a>~;}
			else {$lisst[8]=qq~<A href="$lisst[8]" TARGET="_blank">$shortl8</a>~;}
			open (TMP,"data/r.dat");
			$r=<TMP>;
			close (TMP);
			$r = "$r";$ll = "$lisst[3]";
			$r =~ s/[^\w]/_/g;$ll =~ s/[^\w]/_/g;
			$lisst[2] =~ s/ //g;
			if (!($r =~ /$ll/)) {$newimg = "$IMG[12]>";}
			$table .= qq~<tr class=$color><td class=tble nowrap><input type=checkbox name="$lisst[0]">$imagg2 $newimg</td><td class=tble nowrap><font size=2>$lisst[2]</font></td><td class=tble nowrap><font size=2><a href="$lisst[3]" TARGET="_blank" onClick="direct('$lisst[3]');">$lisst3</a></font></td><td class=tble nowrap><font size=2>$lisst[8]</font></td></tr>\r~;
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
sub track {
	$track = shift;
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split (/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	@tracked = "";
	foreach $line (@info) {if ($line =~ /$track/) {push (@tracked,$line);}}
	&header("Who is $track?");
	@tracked = sort {$a <=> $b} @tracked;
	$table = qq~Who is $track?<br>
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	&gtracked;
	$table .= "</table>";
	print "$table";
	&footer;
}
sub tref {
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopHosts'};}
	$track = $ENV{'QUERY_STRING'}; $track =~ s/tref\=//g;
	print "(($track))<br>";
	$track =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split (/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	@tracked = "";
	foreach $line (@info) {if ($line =~ /$track/) {push (@tracked,$line);}}
	$ttrr = $#tracked;
	&header("Tracking Referrer $track");
	$table = qq~Tracking Referrer <a href="$track" TARGET="_blank">$track</a><br>
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr><td class=tble>$track has generated $ttrr hits</td></tr></table>~;
	$table .= qq~<br>
	<center>[<A href="#pags">List of Local Pages</A>] | [<a href="#ips">List of IPS</A>]</center>
	<br><Br>
	<a name="pags">The</a> following is a list of the top $list Referral Pages which created these hits, if nothing shows, it means there was an insignificant number of referrals:
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	~;
	&trkpgs;
	$table .= "</table>";
	
	
	$table .= qq~<br>
	<a name="ips">The</a> following is a list of the top $list IP addresses which created these hits (clicking on an IP will perform a HOST lookup):
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	~;
	&trkips;
	$table .= "</table>";
	#$table .= "</table>";
	print "$table";
	&footer;
}
sub tpag {
	$track = shift;
	$track =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopRefers'};}
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split (/\r/,<INFO>);
	close (INFO);
	
	
	@info = sort {uc($b) cmp uc($a)} @info;
	@tracked = "";
	foreach $line (@info) {
		@ba = split(/\|/,$line);
		$aba = $ba[8] . "-";
		$bab = $track . "-";
		if ($aba eq $bab) {push (@tracked,$line);}
		$aba = "";$bab = "";
		}
	$ttrr = $#tracked;
	&header("Tracking Local Page $track");
	$table = qq~Tracking local Page <a href="$track" TARGET="_blank">$track</a><br>
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr><td class=tble>$track has generated $ttrr hits</td></tr></table>~;
	$table .= qq~<br>
	<center>[<A href="#refs">List of Referral Pages</A>] | [<a href="#ips">List of IPS</A>]</center>
	<br><Br>
	<a name="refs">The</a> following is a list of the top $list Referral Pages which created these hits, if nothing shows, it means there was an insignificant number of referrals:
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	~;
	&trkrefs;
	$table .= "</table>";
	$table .= qq~<br>
	<a name="ips">The</a> following is a list of the top $list IP addresses which created these hits (clicking on an IP will perform a HOST lookup):
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	~;
	&trkips;
	$table .= "</table>";
	print "$table";
	&footer;
}

sub tsrh {
	$track = shift;
	if ($track =~ /\?/) { $track = $ENV{'QUERY_STRING'}; $track =~ s/tsrh\=//g;}
	$track =~ tr/+/ /;$track =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	@trak = split(/\:/,$track);
	$track = "$trak[0]:$trak[1]";
	$lnkk = $trak[2];
	if ($trak[3] ne "") {$lnkk .= ":$trak[3]";}
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopHosts'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split (/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	@tracked = "";
	foreach $line (@info) {if ($line =~ /$track/) {push (@tracked,$line);}}
	$ttrr = $#tracked;
	&header("Tracking Referrer $track");
	@tracked = sort {$a <=> $b} @tracked;
	$table = qq~Tracking Referrer <a href="$lnkk" TARGET="_blank">$track</a><br>
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr><td class=tble>$track has generated $ttrr hits</td></tr></table>~;
	$table .= qq~<br>
	<center>[<A href="#pags">List of Local Pages</A>] | [<a href="#ips">List of IPS</A>]</center>
	<br><Br>
	<a name="pags">The</a> following is a list of the top $list Referral Pages which created these hits, if nothing shows, it means there was an insignificant number of referrals:
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	~;
	&trkpgs;
	$table .= "</table>";
	
	$table .= qq~<br>
	<a name="ips">The</a> following is a list of the top $list IP addresses which created these hits (clicking on an IP will perform a HOST lookup):
	<table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	~;
	&trkips;
	$table .= "</table>";
	print "$table";
	&footer;
}
sub trkpgs {
	@refs = "";
	
	foreach $ttmp (@tracked) {
		print "\n<!-- // $ttmp // -->\n";
		@ab = split(/\|/,$ttmp);
		push (@refs,$ab[8]);
	}
	@refs = sort {uc($a) cmp uc($b)} @refs;
	$tmp = "";
	@topsorted = "";
	$max=1;
	$total = --$#topref;
	foreach $llne (@refs) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne";}
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		print "\n\n\n\n\n\n\n\n<!-- $line -->\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($lisst[1],0,43);if ($lisst1 ne $lisst[1]) {$lisst1 = substr($lisst[1],7,20);$lisst1 .= "<b>...</b>";$lisst1 .= substr($lisst[1],-20,20);}
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$lisst[1]' TARGET='_blank'>$lisst1</a></font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
sub trkrefs {
	@refs = "";
	
	foreach $ttmp (@tracked) {
		print "\n<!-- // $ttmp // -->\n";
		@ab = split(/\|/,$ttmp);
		push (@refs,$ab[3]);
	}
	@refs = sort {uc($a) cmp uc($b)} @refs;
	$tmp = "";
	@topsorted = "";
	$max=1;
	$total = --$#topref;
	foreach $llne (@refs) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne";}
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($lisst[1],0,43);if ($lisst1 ne $lisst[1]) {$lisst1 = substr($lisst[1],7,20);$lisst1 .= "<b>...</b>";$lisst1 .= substr($lisst[1],-20,20);}
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$lisst[1]' TARGET='_blank'>$lisst1</a></font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
sub trkips {
	@ips = "";
	
	foreach $ttmp (@tracked) {
		print "\n<!-- // $ttmp // -->\n";
		@ab = split(/\|/,$ttmp);
		push (@ips,$ab[4]);
	}
	@ips = sort {uc($a) cmp uc($b)} @ips;
	$tmp = "";
	@topsorted = "";
	$max=1;
	$total = --$#topref;
	foreach $llne (@ips) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($lisst[1],0,63);if ($lisst1 ne $lisst[1]) {$lisst1 = substr($lisst[1],0,30);$lisst1 .= "<b>...</b>";$lisst1 .= substr($lisst[1],-30,30);}
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$script?track=$lisst[1]' TARGET='_blank'>$lisst1</a></font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}

#0=domain ||||| 1=IP ||||| 2=error ||||| 3=referral ||||| 4=blue exclamation ||||| 5=bluedot ||||| 6=greendot ||||| 7=yellowdot ||||| 8=orangedot ||||| 9=reddot ||||| 10=cleardot ||||| 11=blank dot ||||| 12=new!
sub img {print "Content-type: image/gif\n\n";open (IMAGE,"extras.bin");$image=<IMAGE>;@images = split(/\|\|\|\|\|/,$image);close(IMAGE);print $images[$INPUT{'img'}];exit;}
sub gtracked {
	$b=1;
	foreach $line (@tracked) {
		@lisst = split(/\|/,$line);
		if (($lisst[3] ne "") && $lisst[3]) {
			$ttable .= qq~<tr><th class=tble colspan=3 class="dark">$lisst[1], $lisst[2] - ENTER FROM <a href="$script?tref=$lisst[3]">$lisst[3]</A></th></tr>\r~;
			$enter = $lisst[0];$ent++;
		}
		elsif ((($lisst[0] - 3600) > $enter))  {
			$ttable .= qq~<tr><th class=tble colspan=3 class="dark">$lisst[1], $lisst[2] - ENTER (NO REFERRAL)</th></tr>\r~;
			$enter = $lisst[0];$ent++;
		}
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		($lisst[8],$check) = split(/~x~/,$lisst[8]);
		if ($check =~ /\*/) {
			$lisst[8] =~ s/\'//g;
			$imagg2 = qq~$IMG[2] alt="Accessed page: $lisst[8] was not found on your server at $lisst[2], $lisst[1]" onClick="alert('Accessed page: $lisst[8] was not found on your server at $lisst[2], $lisst[1]');">~;
		} 
		else {$imagg2 = qq~$IMG[11]>~;}
		$ttable .= qq~<tr class=$color><td class=tble>$imagg2 $lisst[1]</td><td class=tble>$lisst[2]</td><td class=tble><a href="$script?tpag=$lisst[8]">$lisst[8]</a></td></tr>\r~;
		$b++;$view++;
		if ($lisst[4]) {$iip=$lisst[4];}if ($lisst[5]) {$hst=$lisst[5];}if ($lisst[6]) {$brw=$lisst[6];}if ($lisst[7]) {$plt=$lisst[7];}
	}
	open (BIN,"extras.bin") || &ErroR('unable to open the extras file for data output');
	@bin = <BIN>;$bin="@bin";
	($junk,$tmp) = split(/~~\|~~/,$bin);@countries=split(/\|\|\|/,$tmp);close (BIN);
	$county = gctry(substr($hst,-3,3));
	@tmp = split (/\./,$hst);
	$tmp1=$tmp[$#tmp];
	$tmp0=$tmp[($#tmp-1)];
	$tmp2=$tmp[($#tmp-2)];
	if ($tmp0 eq "com") {$tmp0="$tmp2.$tmp0";}
	$domain = "$tmp0.$tmp1";@ip=split(/\./,$iip);
	if (!($hst && $hst ne "")) {$domain = "[no host to grab domain from]";$hst = "[no host]";}
	
	$table .= qq~<tr class="dark"><th class=tble colspan=3>User Info:</th></tr>
			<tr class="tdlight"><td class=tble><b>Domain</b></td><td class=tble colspan=2><a href="http://www.$domain" target="_blank">$domain</a> <a href="$script?track=$domain"><span class="hover">?</span></a></td></tr>
			<tr class="tddark><td class=tble><b>Recent Host</b></td><td class=tble colspan=2>$hst</td></tr>
			<tr class="tdlight"><td class=tble><b>Recent IP</b></td><td class=tble colspan=2><a href="$script?track=$ip[0].$ip[1].$ip[2]">$ip[0].$ip[1].$ip[2]</a>.$ip[3]</td></tr>
			<tr class="tddark"><td class=tble><b>Country</b></td><td class=tble colspan=2>$county</td></tr>
			<tr class="tdlight"><td class=tble><b>Recent Browser</b></td><td class=tble colspan=2>$brw</td></tr>
			<tr class="tddark"><td class=tble><b>Recent Platform</b></td><td class=tble colspan=2>$plt</td></tr>
			<tr class="tdlight"><td class=tble><b>Visits</b></td><td class=tble colspan=2>$ent</td></tr>
			<tr class="tddark"><td class=tble><b>Page views</b></td><td class=tble colspan=2>$view</td></tr>
			$ttable~;
}

#Last $LPConfig{'LastVisits'} Searches
sub lastsearch {
	$frames= "lastsearch";
	&header("LogIT PRO LAST SEARCH AREA");
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'LastVisits'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><form method=post action="$script"><input type=hidden name=delete value=on><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	&glstsrh;$table .= qq~</table><input type=password name=pword><input type=submit value="Delete selected items"></form></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=lastsearch>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print $table;
	&footer;
}
sub glstsrh {
	$b=1;
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		if ($dte ne $lisst[1]) {
			$dte = $lisst[1];
			$dayy = gday($lisst[0]);
			$table .= "<tr class=light><td class=tble colspan=5><center><b>$dayy, $dte</b></td></tr>\r";$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
			$table .= "<tr class=dark>$ttd Extra $tdd $ttd Time $tdd$ttd Search Engine $tdd$ttd Queried Terms  $tdd$ttd Accessed Page $tdd </tr>";
		}
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if ((($lisst[3]) && ($lisst[3] ne "")) && (($lisst[9]) && ($lisst[9] ne ""))) {
			$srhlnk="";
			($serch,$lisst[9]) = split (/\:/,$lisst[9]);
			open (SG,"search.dat");@sg = <SG>;close (SG);$refi = "$serch";foreach $lne (@sg) {@r = split(/~x~/,$lne);if ($refi eq $r[2]) {$srhlnk = "http://www.$r[0]";}}
			$lisst9 = substr($lisst[9],0,35);
			if ($lisst9 ne $lisst[9]) {$lisst9 .= "...";}
			($lisst[8],$l8) = split(/~x~/,$lisst[8]);
			$lisst8 = substr($lisst[8],0,20);
			if ($lisst8 ne $lisst[8]) {$lisst8 .= "...";}
			$table .= qq~<tr class=$color><td class=tble nowrap><input type=checkbox name="$lisst[0]"></td><td class=tble nowrap><font size=2>$lisst[2]</font></td><td class=tble nowrap><font size=2><a href="$srhlnk">$serch</a></font></td><td class=tble nowrap><font size=2><a href='$lisst[3]' TARGET='_blank'>$lisst9</a></font></td><td class=tble nowrap><font size=2><a href='$lisst[8]' TARGET='_blank'>$lisst8</a></font></td></tr>\r~;
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}

sub gencode {
	if ($INPUT{'genit'} eq "java") {$gen="Javascript Code";$generate = qq~&lt;script src="$LPConfig{'URI'}?java"&gt;&lt;/script&gt;
&lt;!-- // Note, Javascript code adds a hidden 1x1 image to your page, Put this code in the body area, or it will not work. // --&gt;~;}
	elsif ($INPUT{'genit'} eq "ssi") {$gen="SSI Code";$generate = qq~&lt;!--#include virtual="$LPConfig{'URI'}?count"--&gt;~;}
	&header('LOGIT PRO GENERATE CODE AREA');
	print qq~<center>What kind of code would you like generated?<br><br>note: javascript code doesn't work on frame pages, you can only use it on content pages.<br>You can also use a combination of javascript and SSI, but only use one per page.~;
	print qq~<br><Br><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">
	<tr class="light"><td class=tble align=center valign=center>
	<form action="$script" method=post><input type=hidden name=gencode value=1>
	<select name=genit>
	<option>-Please select one-</option>
	<option value=ssi>SSI code</option>
	<option value=java>JavaScript code</option>
	</select>
	<input type=submit value="Generate!"></form></td></tr><tr class="dark"><td class=tble align=center valign=center><b>$gen</B>
<br>&nbsp;<textarea rows=6 cols=80>$generate</textarea>&nbsp;<br>
	</center></td></tr></table>
	~;
	&footer();
}

#Top $LPConfig{'TopRefers'} Referrers
sub toprefers {
	$frames= "toprefers";
	&header("LogIT PRO TOP REFERRER AREA");
	print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopRefers'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Referrer  $tdd</tr>";
	&gtopref;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=toprefers>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtopref {$b=1;
	@topref = "";
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		if ((($lisst[3]) && ($lisst[3] ne "")) && (!($lisst[9] =~ /\:/))) {
			push @topref,$lisst[3];
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @topref;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	foreach $llne (@topref) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($lisst[1],0,63);if ($lisst1 ne $lisst[1]) {$lisst1 = substr($lisst[1],0,30);$lisst1 .= "<b>...</b>";$lisst1 .= substr($lisst[1],-30,30);}
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= qq~<tr class=$color><th class=tble width=10><font size=2><a href="$script?tref=$lisst[1]">$lisst[0]</a></font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$lisst[1]' TARGET='_blank'>$lisst1</a></font></td></tr>\r~;
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
#Top $LPConfig{'TopRefers'} Searches
sub topsearch {
	$frames= "topsearch";
	&header("LogIT PRO TOP SEARCH AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopRefers'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Search Engine $tdd$ttd Queried words $tdd</tr>";
	&gtopsrh;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topsearch>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtopsrh {$b=1;
	$f=0;
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		if ((($lisst[3]) && ($lisst[3] ne "")) && (($lisst[9] =~ /\:/))) {
			$pushed = "$lisst[9]~x~$lisst[3]";
			if ($f) {push @topref,$pushed;} else {@topref=$pushed;}
			$f++;
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @topref;
	$tmp = "";
	@topsorted = "";
	$max=1;
	$total = --$#topref;
	if (!($total)) {$total=1;}
	foreach $llne (@topref) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		($searched,$linked) = split(/~x~/,$lisst[1]);
		@searched = split(/\:/,$searched);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($searched[1],0,60);
			if ($lisst1 ne $searched[1]) {
				$lisst1 .= "...";
			}
			$srhlnk="";
			open (SG,"search.dat");@sg = <SG>;close (SG);$refi = "$searched[0]";foreach $lne (@sg) {@r = split(/~x~/,$lne);if ($refi eq $r[2]) {$srhlnk = "http://www.$r[0]";}}
			$prct = (($lisst[0]/$total)*150);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$total)*150);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= qq~<tr class=$color><th class=tble width=10><font size=2><a href="$script?tsrh=$searched[0]:$lisst1:$linked">$lisst[0]</a></font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center>$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$srhlnk' TARGET='_blank'>$searched[0]</a></font></td><td class=tble nowrap><font size=2><b><a href='$linked' TARGET='_blank'>$lisst1</a></b></font></td></tr>\r~;
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
#Top $LPConfig{'TopRefers'} SearchEng
sub topsearcheg {
	$frames= "topsearcheg";
	&header("LogIT PRO TOP SEARCH AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopRefers'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Search Engine $tdd</tr>";
	&gtopseg;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topsearcheg>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtopseg {$b=1;
	@topref = "";
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		if ($lisst[9] =~ /\:/) {
			@searched = split(/\:/,$lisst[9]);
			$pushed = "$searched[0]";
			push @topref,$pushed;
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @topref;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	if (!($total)) {$total=1;}
	foreach $llne (@topref) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]|";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];}push @topsorted,$tmp;$tmp="1|$llne|";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($lisst[1],0,60);
			if ($lisst1 ne $lisst[1]) {
				$lisst1 .= "...";
			}
			open (SG,"search.dat");@sg = <SG>;close (SG);$refi = "$lisst[1]";foreach $line (@sg) {@r = split(/~x~/,$line);if ($refi eq $r[2]) {$lisst[1] = "http://www.$r[0]";}}
			$prct = (($lisst[0]/$total)*150);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$total)*150);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center>$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$lisst[1]' TARGET='_blank'>$lisst1</a></font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
#Top $LPConfig{'TopRefers'} Local Pages
sub toppages {
	$frames= "toppages";
	&header("LogIT PRO TOP LOCAL PAGE AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopRefers'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Local Page$tdd</tr>";
	&gtoppag;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=toppages>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtoppag {$b=1;
	@topref = "";
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		($lisst[8],@tmp) = split(/~x~/,$lisst[8]);
		if (($lisst[8]) && ($lisst[8] ne "")) {
			push @topref,$lisst[8];
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @topref;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	foreach $llne (@topref) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];}push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$lisst1 = substr($lisst[1],0,60);
			if ($lisst1 ne $lisst[1]) {
				$lisst1 .= "...";
			}
			$prct = (($lisst[0]/$total)*150);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$total)*150);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= qq~<tr class=$color><th class=tble width=10><font size=2><a href="$script?tpag=$lisst[1]">$lisst[0]</A></font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center>$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2><a href='$lisst[1]' TARGET='_blank'>$lisst1</a></font></td></tr>\r~;
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
#Top $LPConfig{'TopHosts'} IPs
sub topips {
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopHosts'};}
	$frames= "topips";
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd IP Address $tdd</tr>";
	
	&header("LogIT PRO TOP IPS AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	&gtopips(4);
	$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topips>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtopips {
	$number=shift;$number="$number";
	open (TMP,"data/i.dat");
	@info = split(/\r/,<TMP>);
	close (TMP);
	@info = sort {uc($b) cmp uc($a)} @info;$b=0;print "<b>$number</b><br>";
	foreach $line (@info) {
		if ($number eq 6) {
			@line = split(/\|/,$line);
			if (($line[5]) && ($line[5] ne "")) {
				@tmp = split (/\./,$line[5]);
				$tmp1=$tmp[$#tmp];
				$tmp0=$tmp[($#tmp-1)];
				$tmp2=$tmp[($#tmp-2)];
				if ($tmp0 eq "com") {$tmp0="$tmp2.$tmp0";}
				$domain = "$tmp0.$tmp1";				
				if ($b) {push @list,$domain;}
				else {@list=$domain}
				$b++;
			}
		}
		else {@line = split(/\|/,$line);if (($line[$number]) && ($line[$number] ne "")) {if ($b) {push @list,$line[$number];} else {@list=$line[$number]}$b++;}}
	}
	@list = sort {uc($a) cmp uc($b)} @list;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	foreach $llne (@list) {
		
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];}push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			if ($number eq 4) {$lisst1 = substr($lisst[1],0,16);$lisst1=qq~<a href="$script?track=$lisst[1]">$lisst1</a>~;}
			elsif ($number eq 5) {$lisst1 = substr($lisst[1],0,35);if ($lisst1 ne $lisst[1]) {$lisst1 = "$lisst1...";}$lisst1=qq~<a href="$script?track=$lisst[1]">$lisst1</a>~;}
			elsif ($number eq 6) {$lisst1=qq~<a href="http://www.$lisst[1]" target="_blank">$lisst[1]</a> <a href="$script?track=$lisst[1]"><span class="hover">?</span></a>~;}
			
			$prct = (($lisst[0]/$total)*150);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$total)*150);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= qq~<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center>$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2>$lisst1</font></td></tr>\r~;
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
#Top $LPConfig{'TopHosts'} Hosts
sub tophosts {
	$frames= "tophosts";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopHosts'};}
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Host Address $tdd</tr>";
	
	&header("LogIT PRO TOP HOSTS AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	&gtopips(5);
	$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=tophosts>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
#Top $LPConfig{'TopHosts'} Domains
sub topdomains {
	$frames= "topdomains";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopHosts'};}
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Domain Address $tdd</tr>";
	
	&header("LogIT PRO TOP DOMAINS AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	&gtopips(6);
	$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topdomains>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
#Top $LPConfig{'TopPlat'} Countries
sub topcountries {
	open (BIN,"extras.bin") || &ErroR('unable to open the extras file for data output');
	@bin = <BIN>;$bin="@bin";
	($junk,$tmp) = split(/~~\|~~/,$bin);@countries=split(/\|\|\|/,$tmp);close (BIN);
	$frames= "topcountries";
	&header("LogIT PRO TOP COUNTRY AREA");
		print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopPlat'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@tmp = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Country [domain] $tdd</tr>";
	&gcountry;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topcountries>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;

}

sub gcountry {
	foreach $line (@tmp) {
		@dat=split(/\|/,$line);
		if ($dat[5] ne "") {
			$dat[5] = lc $dat[5];
			$data=substr($dat[5],-3,3);
			if ($b) {push @info,$data;$b++;}
			else {@info = $data;$b++;}
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @info;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	foreach $llne (@topref) {
		
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if ($lisst[1] ne "") {
			$lisst[1] = gctry($lisst[1]);
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2>$lisst[1]</font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
	}
sub gctry {
	$data="";
	$ctry="";
	$dat=shift;
	if (!($dat && $dat ne "")) {return "[no host to check country with]";exit;}
	foreach $line (@countries) {
		($data,$ctry) = split(/\|/,$line);
		if ($data =~ /$dat/) {return "$ctry [$dat]";exit;}
	}
	return "not found ($dat)";
}

#Top $LPConfig{'TopPlat'} Platforms
sub topplatform {#7
	$frames= "topplatform";
	&header("LogIT PRO TOP PLATFORM AREA");
	print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopPlat'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Platform $tdd</tr>";
	&gtopplt;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topplatform>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtopplt {$b=1;
	@topref = "";
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		if (($lisst[7]) && ($lisst[7] ne "")) {
			push @topref,$lisst[7];
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @topref;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	foreach $llne (@topref) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2>$lisst[1]</font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}
#Top $LPConfig{'TopPlat'} Browsers
sub topbrowser {
	$frames= "topbrowser";
	&header("LogIT PRO TOP BROWSER AREA");
	print "note, if you see nothing below it is because an insufficient amount of hits have been generated.  If this is the case, please stop back later<br><Br>";
	if ($INPUT{'list'}) {$list = $INPUT{'list'};}
	else {$list = $LPConfig{'TopPlat'};}
	
	open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
	@info = split(/\r/,<INFO>);
	close (INFO);
	@info = sort {uc($b) cmp uc($a)} @info;
	$dte = "";$n=0;$table = qq~<center><table border="1" margin height="0" margin width="0" cellspacing="1" cellpadding="1" noshade class="tble">~;
	$ttd="<td class=tble nowrap><font size=2><b>";$tdd="</b></font></td>";
	$table .= "<tr class=dark>$ttd Hits $tdd $ttd Percent $tdd$ttd Color-Coded Graph [less$IMG[5] height=8 width=20>$IMG[6] height=8 width=20>$IMG[7] height=8 width=20>$IMG[8] height=8 width=20>$IMG[9] height=8 width=20>more] $tdd$ttd Browser $tdd</tr>";
	&gtopbrw;$table .= qq~</table></center>~;
	print qq~<center><form action="$script" method=GET><input type=hidden name=topbrowser>Change the amount listed:<br>
	<select name="list">~;print gopts($list);print qq~</select>
	<input type=submit value="List IT!"></form></center>~;
	print qq~<br><center></center><br>~;
	print $table;
	&footer;
}
sub gtopbrw {$b=1;
	@topref = "";
	foreach $line (@info) {
		@lisst = split(/\|/,$line);
		if (($lisst[6]) && ($lisst[6] ne "")) {
			push @topref,$lisst[6];
		}
	}
	@topref = sort {uc($a) cmp uc($b)} @topref;
	$tmp = "";
	@topsorted = "";
	$max=0;
	$total = --$#topref;
	foreach $llne (@topref) {
		#if ($c > $list) {print "$c<br><Br>";continue;}
		@st = split (/\|/,$tmp);if (($llne) && ($llne ne "")) {
		if ($tmp ne "") {
			if ($st[1] eq $llne) {
				$st[0] = $st[0] + 1;
				$tmp = "$st[0]|$st[1]";
				if($st[0]>$max) {$max=$st[0];};
			}
			else {if($st[0]>$max) {$max=$st[0];};push @topsorted,$tmp;$tmp="1|$llne";}
		}
		else {$tmp="1|$llne"; }
	}}
	push @topsorted,$tmp;
	@topsorted = sort {$b <=> $a} @topsorted;
	$c=0;$b=0;foreach $line (@topsorted) {if ($b > $list) {}else{@lisst = split(/\|/,$line);$c=$c+$lisst[0];}$b++;}
	if (!($max)) {$max = 1;}
	$wid=(200/$max);
	$b = 1;foreach $line (@topsorted) {
		@lisst = split(/\|/,$line);
		if (($b / 2) =~ /\./) {$color="tddark"}
		else {$color="tdlight"}
		if (($lisst[1]) && ($lisst[1] ne "")) {
			$prct = (($lisst[0]/$c)*300);$width=($line*$wid);
			$prct1 = substr((($lisst[0]/$c)*100),0,4);$prct1.="%";
			$prctt = (($max/$c)*300);
			$prcttt = (($prct/$prctt)*100);
			if ($width > 200) {$width = 200;}
			if ($prcttt < 20) {$ii=5} elsif ($prcttt < 40) {$ii=6} elsif ($prcttt < 60) {$ii=7} elsif ($prcttt < 80) {$ii=8} else {$ii=9}
			$table .= "<tr class=$color><th class=tble width=10><font size=2>$lisst[0]</font></th><td class=tble nowrap><font size=2>$prct1</font></td><td class=tble align=left valign=center >$IMG[$ii] width=$width height=8 border=1></td><td class=tble nowrap><font size=2>$lisst[1]</font></td></tr>\r";
			$b++;
			if ($b > $list) {return;exit;}
		}
	}
}


#LogitPRO VIP Service
sub topjva {
	$frames="topjva";
	&header("LogIT PRO JavaScript Enabled? AREA");
	print qq~This section is only available in the <A href="http://www.logitpro.com/vip.shtml" target="_blank">VIP VERSION</a>~;
	&footer;
	exit;
}


#LogitPRO VIP Service
sub topclr {
	$frames="topclr";
	&header("LogIT PRO TOP Screen/Color AREA");
	print  qq~This section is only available in the <A href="http://www.logitpro.com/vip.shtml" target="_blank">VIP VERSION</a>~;
	&footer;
	exit;
}
#LogitPRO VIP Service
sub gtopclr {return;exit;}



sub UpdateDataFile {
	if (!($INPUT{'npassword'})) {&ReadConfig;}
	if ($INPUT{'npassword'}) {$pass = crypt($INPUT{'npassword'},AD);$INPUT{'password'} = "$pass";}
	elsif ($LPConfig{'password'} ne "") {$INPUT{'password'} = "$LPConfig{'password'}";}
	else {$INPUT{'password'} = "0";}
	if ($INPUT{'ServerPath'} && $INPUT{'TimeHourFormat'} && $INPUT{'inex'} && $INPUT{'MaxLogSize'}) {
	foreach $k (keys %INPUT) {
		unless ($k eq "npassword") {$tdmp .= "$k|$INPUT{$k}\r";}
	}
	&writeit('DATA','data/d.dat',$tdmp,1,0);
	}
	else {$INPUT{'UpdateDataFile'} = 0;&NewConfig("you need to enter all of the variables");exit; }
	&ReadConfig;
	if ($LPConfig{'password'}) {$INPUT{'hword'} = "";$INPUT{'pword'} = "";print "Finished...<br>";&login;}
	else {&NewConfig("You didn't specify a password");}
	
}

sub gpath {
	eval '$home = (getpwuid($< ))[7];';
	if (!-e "C:/") {$pwd = `pwd`; chop $pwd;}
	if (!eval 'use Cwd;') {eval '$cwd = cwd();';} else {$cwd = "";}
	if ($pwd eq "") {$dirname = $cwd;} else {$dirname = $pwd;}
	return $dirname;
}

sub NewConfig {
	$noupdat=1;
	$frames= "NewConfig";
	if ($INPUT{'frame'} ne "") {&frame($INPUT{'frame'});}
	$err = shift;
	$nconf = shift;
	$path = gpath();
	$bott = qq~</font></td>
	<td class=tble>$IMG[10] width=1 height=0></td>	
	</tr>\r~;
	$topp = qq~<tr><td class=tble colspan=3><hr class="hrcolor" size=1 width=80%></td></tr>\r<tr>
	<td class=tble>$IMG[10] width=1 height=0></td>
		<td class=tble valign=top align=left>
		<font >~;
	if ($nconf || !($LPConfig{'password'})) { }
	elsif ($INPUT{'pword'} eq $guest) { }
	elsif (!($INPUT{'pword'} eq $LPConfig{'password'})) {
			
			&ErroR('Wrong Password');
			exit;
		}
	&header("LogIT PRO CONFIGURATION AREA");
	if (!($INPUT{'pword'} eq $guest)) {print qq~<form action=$script method=post>~;}
	if (!($LPConfig{'ServerPath'} && $LPConfig{'ServerPath'} ne "")) {$LPConfig{'ServerPath'} = $ENV{'DOCUMENT_ROOT'};}
	if ($ENV{'DOCUMENT_ROOT'} && $ENV{'DOCUMENT_ROOT'} ne "") {$docr = "(might be $ENV{'DOCUMENT_ROOT'})";}
	print qq~
	<table width=100% height=100% border=0 cellspacing=5 cellpadding=20 margin width=0 margin height=0>
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><font size=3>$err</font><br><br><hr class="hrcolor" size=2 width=100%><font size=3><b>General Settings</b> - </font>These settings
	apply to the way LogIT PRO Runs on your server.  All of these settings are required.</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
	$topp
	<p><b>ServerPath</b> - Specify the unix path to your web directory.  
		It is very important that you set this correctly.  if you are unsure, please check with your
		system admin, and ask them what the path is to your web directory.  if you do not set this
		correctly, the logger will fail in many areas!<br><br>for example, $path is the directory that
		LogIT Pro is in... for this setting you should only have where the index page to your site is. $docr
		<br><br><b><font color="#FF0000">no trailing slash!</font></b><br>
		<center><input type=text size=60 name="ServerPath" value="$LPConfig{'ServerPath'}"></center></p>
		$bott
	$topp
	<p><b>LogIT PRO URL</b> - Specify the http path to logitpro.cgi.  
		It is very important that you set this correctly.  If you do not set this
		correctly, the logger will fail in many areas!<br><br>If you use http://www.yoursite.com/cgi-bin/logitpro/lpview.cgi to login,
		then you should put /cgi-bin/logitpro/logitpro.cgi in this area.  Remember to put the "/" before the directory location.<br><Br>
		Another good example is that this function for the logitpro site is set at "/cgi-bin/logitpro/logitpro.cgi"
		This is what most users will have it set at, and what the instructions ask for you
		to install it as.</b>
		<br><br><b><font color="#FF0000">PUT logitpro.cgi HERE, <u>NOT</u> lpview!!!!!!</font></b><br>
		<center><input type=text size=60 name="URI" value="$LPConfig{'URI'}"></center></p>
		$bott
	$topp
	<p><b>IndexPages</b> - List the name(s) of your index pages here.  If all of your index pages are,
		for example, index.html, all you need to list is index.html.  However, if you have other index
		pages that you use in different directories (like index.htm, index.shtml, default.html, etc...)
		you should list all of them seperated by a comma (ex: index.shtml,index.html,default.html) <br>
		<center><input type=text size=60 name="inex" value="$LPConfig{'inex'}"></center></p>
		$bott~;
	@s = "";
	if ($LPConfig{'MaxLogSize'} == 500) { @s[0] = selected; }
	elsif ($LPConfig{'MaxLogSize'} == 1000) { @s[1] = "selected"; }
	elsif ($LPConfig{'MaxLogSize'} == 1500) { @s[2] = "selected"; }
	elsif ($LPConfig{'MaxLogSize'} == 2000) { @s[3] = "selected"; }
	elsif ($LPConfig{'MaxLogSize'} == 2500) { @s[4] = "selected"; }
	elsif ($LPConfig{'MaxLogSize'} == 3000) { @s[5] = "selected"; }
	elsif ($LPConfig{'MaxLogSize'} == 3500) { @s[6] = "selected"; }
	elsif ($LPConfig{'MaxLogSize'} == 4000) { @s[7] = "selected"; }
	else { @s[1] = "selected"; }
	print qq~$topp
		<p><b>Max LogFile Size</b> - Set this variable to the Maximum size for the logfile (in kB).
		A usual setting for this is 1mb because anything over a MB could take a while to process.
		if you feel you need a larger file, I suggest you <u>do not</u> go over 2.5mb.<br>
		<select name="MaxLogSize">
		<option value="500" $s[0]>0.5 mb</option>
		<option value="1000" $s[1]>1.0 mb</option>
		<option value="1500" $s[2]>1.5 mb</option>
		<option value="2000" $s[3]>2.0 mb</option>
		<option value="2500" $s[4]>2.5 mb</option>
		<option value="3000" $s[5]>3.0 mb !EXCESSIVE SIZE</option>
		<option value="3500" $s[6]>3.5 mb !OVER-EXCESSIVE SIZE</option>
		<option value="4000" $s[7]>4.0 mb !INSANE SIZE</option></select></p>
		$bott~;
	@s = "";
	if ($LPConfig{'gettitle'} eq "1") { @s[1] = "selected"; }
	else { @s[0] = "selected"; }
	print qq~$topp
		<p><b>Get Referral Title on LOG</b> - Turning this on will enable LogIT PRO to retrieve the title of
		a page that generates a referral hit. 
		<br><br>
		Note: This function creates a major server punch if you get a reasonable amount of hits.  It is suggested
		that you D0 N0T TURN THIS ON!  It was originally created for demonstration purposes only.  LogIT PRO Staff
		is not responsible for any damage this function causes if it is left on.
		<br><select name="gettitle" onChange="if (this.options[this.selectedIndex].value == 1) alert('Note:\\r\\rThis option, If left on, will cause a server SPIKE, meaning that it will use up A LOT of the server resources, and make your site load a lot slower.\\r\\rIt may also anger your server admin, and cause them to turn this script off, rendering it useless.  Please leave this off for your own good!!!')">
		<option value="1" $s[1]>ON - log Titles [do not TURN THIS ON!]</option>
		<option value="0" $s[0]>OFF - Manual Title Log</option></select></p>
		$bott~;
	if ($LPConfig{'DisplayCounter'} eq "1") { @s[1] = "selected"; }
	elsif ($LPConfig{'DisplayCounter'} eq "2") { @s[2] = "selected"; }
	elsif ($LPConfig{'DisplayCounter'} eq "3") { @s[3] = "selected"; }
	elsif ($LPConfig{'DisplayCounter'} eq "4") { @s[4] = "selected"; }
	else { @s[0] = "selected"; }
	print qq~$topp
		<p><b>Display Counter</b> - Simply put, this function specifies whether you want to display
		a counter on the pages you are logging or not.  if this is set to yes, the number of unique
		or total hits since the installation of logitPro, or since the last reset will be displayed
		wherever you have put the SSI call, or JavaScript call in your pages.<br>
		<select name="DisplayCounter">
		<option value="1" $s[1]>Yes, Display Unique Hits</option>
		<option value="2" $s[2]>Yes, Display Total Hits</option>
		<option value="3" $s[3]>Yes, Display Unique Hits (+ number below)</option>
		<option value="4" $s[4]>Yes, Display Total Hits (+ number below)</option>
		<option value="0" $s[0]>No, Don`t Display</option></select></p>
		<p>set this to the number you want added onto your count to be displayed (if that option is selected)<br>
		<input type=text size=20 name="AddCount" value="$LPConfig{'AddCount'}"><br>
		<br>
		<p><b>Block Count Display</B> - Put the name(s) of the page(s) that you DO_NOT want to display the counter on
		(if you selected to display the counter above).  Seperate names with a comma. 
		Example is: "index.html,purchase.html,nocount.html"<br><br>note: this will only
		block pages that are using SSI to call logitpro.cgi ...</p>
		<input type=text size=20 name="DontCount" value="$LPConfig{'DontCount'}">
		$bott~;
	print qq~
	$topp
		<p><b>IP Blocking</b> - Here you can specify ip addresses, or parts of ip addresses which you do not
		want to be logged.  This function is useful if you want to keep yourself and other admins from being
		logged.  It is suggested that you at least put the first 3 sections of your ip address here.  An example
		is: 555.555.555  You should seperate different ip addresses with a comma ","<br>
		<center><input type=text size=60 name="IPBlocked" value="$LPConfig{'IPBlocked'}"></center></p>
		$bott
	~;
	print qq~
	$topp
		<p><b>Domain (referral) Blocking</b> - This is one of the most important fields in logitPro.  You should
		put your domain here so that it is not logged as a referral (hits from these domains will be logged, but
		the referral will turn up as null).  Do not put in a www, or http.  Instead just put in the domain.  Seperate
		different domains with a comma.  Example: logitpro.com,bennyland.com<br>
		<center><input size=60 type=text name="DomainBlocked" value="$LPConfig{'DomainBlocked'}"><center></p>
		$bott
	~;
	print qq~
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><br><hr class="hrcolor" size=2 width=100%><font size=3><b>Listing Settings</b> - </font>These settings
	apply to the way LogIT PRO`s log pages feel.  All of these settings are required.</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
	~;
	
	print qq~
	$topp
		<p>Set these to the maximum number of hits to display on logit Pro`s pages respectively<br>
		<select name="LastVisits">~;print gopts($LPConfig{'LastVisits'});print qq~</select> LastVisits, LastRefers, LastSearches<br>
		<select name="TopRefers">~;print gopts($LPConfig{'TopRefers'});print qq~</select> TopRefers, TopPages, TopSearches, TopSearchEngines<br>
		<select name="TopHosts">~;print gopts($LPConfig{'TopHosts'});print qq~</select> TopHosts, TopIps, TopDomains<br>
		<select name="TopPlat">~;print gopts($LPConfig{'TopPlat'});print qq~</select> Countries, Platorms, Browsers </p>
		$bott
	~;
	print qq~
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><br><hr class="hrcolor" size=2 width=100%><font size=3><b>Time Settings</b> - </font>These settings
	help LogIT PRO configure the logging files right...  All of these settings are required.</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
		~;
	&gdate(time);
	$hhour = $Hour;
	@hur = "";
	&hourarray;
	print qq~
	$topp
		<p><b>Time Zone Change</b> - It is currently <b>$Weekday, $Month_Name $Day $hhtime</b> on your server.
		for LogIT Pro to work correctly, we need to know what time it is on your computer (not the server)
		Please specify approximently what time it was at your computer when you first entered this page.<br>
		<br><select name="TimeZoneChange">~;print @hur;print qq~</select>
		<script language="JavaScript">
<!--
todays_date=new Date ();
document.write("It was:<b>")
document.write(todays_date)
document.write("</b> on your computer when you loaded this")
//-->
</script>
		</p>
		$bott
		~;
	@s = "";
	if ($LPConfig{'TimeHourFormat'} eq "12") { @s[1] = "selected"; }
	else { @s[0] = "selected"; }
	print qq~
	$topp
		<p><b>time Hour Format</b> - Set this to either 12 or 24 hour time format<br>
		<select name="TimeHourFormat">
		<option value="12" $s[1]>12 Hour</option>
		<option value="24" $s[0]>24 Hour</option></select></p>
		$bott
		~;
	print qq~
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><br><hr class="hrcolor" size=2 width=100%><font size=3><b>E-Mail Settings</b> - </font>These settings
	set up LogIT Pro`s daily statistic e-mails</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
	~;	
	@s = "";
	if ($LPConfig{'email'} eq "Yes") { @s[1] = "selected"; }
	else { @s[0] = "selected"; }
	print qq~
	$topp
		<p><b>E-mail stats?</b> - Set this to Yes if you would like logit Pro to e-mail you daily
		stats. (you must have the sendmail and e-mail forms filled out below)<br>
		<select name="email">
		<option value="Yes" $s[1]>Yes</option>
		<option value="No" $s[0]>No</option></select></p>
		$bott
		~;
	print qq~
	$topp
		<p><b>Location of sendmail</b> - Set this to the absolute location of sendmail on your server.
		(usually /usr/sbin/sendmail)  do not include anything after "sendmail"<br>
		<input type=text name="mailprog" value="$LPConfig{'mailprog'}"></p>
		$bott
		~;
	print qq~
	$topp
		<p><b>Your e-mail</b> - Set this to the e-mail address you wish logit Pro to send daily stats
		to.<br>
		<input type=text name="yourmail" value="$LPConfig{'yourmail'}"></p>
		$bott
		~;
	
	print qq~
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><br><hr class="hrcolor" size=2 width=100%><font size=3><b>Color/Font Configuration</b> - </font>These settings
	help you adjust the way LogIT PRO looks and feels.  Color/Font settings are only available in LogIT PRO VIP</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
	~;
	print qq~
	$topp
		This configuration is only available on
		<a href="http://www.logitpro.com/vip.shtml" target="_blank">LogIT PRO VIP</a>
		$bott
		~;
		
	print qq~
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><br><hr class="hrcolor" size=2 width=100%><font size=3><b>Image Configuration</b> - </font>These settings
	help you customize the images that are displayed.</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
	~;
	if ($LPConfig{'Images'} eq "custom") {@s = ("selected","");}
	else  {@s = ("","selected");}
	print qq~
	$topp
		Images: <select name="Images">
		<option value="classic" $s[1]>Classic</option>
		<option value="custom" $s[0]>Custom</option>
		$bott
		~;
	print qq~
	$topp
		If you selected "custom" above, please enter the HTTP location of the logitpro image directory<br>
		<input type="text" name="LPImgDir" value="$LPConfig{'LPImgDir'}">
		<br><font size=-1><A href="http://www.logitpro.com/images.shtml" target="_blank">download images, and learn how to make an image directory</a></font>
		$bott
		~;
	
	print qq~
	<tr><td class=tble>$IMG[10] width=1 height=0></td>
	<td class=tble align=left>$IMG[10] width=0 height=20><br><hr class="hrcolor" size=2 width=100%><font size=3><b>Password Settings</b> - </font>These settings
	help protect your LogIT PRO configurations and logs</td>
	<td class=tble>$IMG[10] width=1 height=0></td>
	</tr>\r
		~;
	
		
	print qq~
	$topp
		<p><b>Password</b> - Enter your password here, whatever you enter here will be your password <font color="#FF0000"><b>if you leave this blank, your old password will be used, or if you have never set a password, you will have a blank password</b></font><br>
		<input type=password name="npassword" value=""></p>
		$bott
		~;
		
	@s = "";
	if ($LPConfig{'passprt'}) { @s[1] = "selected"; }
	else { @s[0] = "selected"; }
	print qq~
	$topp
		<p><b>Password Protect All Logs?</b> - Set this to Yes if you want to enter your password
		to be able to view any of your logs.  if you use this, you can avoid putting the password in
		if you have already entered it once in that session by using the pulldown "quick access" menu
		instead of the individual links in the header (you must have entered your password at a log screen
		durring this session for it to work).<br>
		<select name="passprt">
		<option value="1" $s[1]>Yes</option>
		<option value="0" $s[0]>No</option></select></p>
		$bott
		<input type="hidden" name="hword" value="$INPUT{'pword'}">
		<input type="hidden" name="UpdateDataFile" value="1">
		</table>
		~;
	if (!($INPUT{'pword'} eq $guest)) {
		print qq~<br><Br><center>
		<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('\@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\\n'; }
  } if (errors) alert('The following error(s) occurred:\\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
		<input type=submit value="Save Changes" name="submit" onClick="MM_validateForm('ServerPath','','R','URI','','R','inex','','R','yourmail','','NisEmail');return document.MM_returnValue">
		</center><br><Br><br><br><br></form>~;
		}
	&footer;
}
sub hourarray {
	$b = $hhour;
	$a = 0;
	if ($hhour < 12) {$ap = "am";} else {$ap = "pm";}
	$ty = $hhour;if ($hhour > 12) {$ty = $hhour - 12;}
	$hhtime = "$ty".":"."$Minute"." "."$ap";
	until ($a == 48) {
		$ff = $a - 24;
		if ($b < 12 && $b > 0) {$ap = "am";} else {$ap = "pm";}
		$ty = $b;if ($b > 12) {$ty = $b - 12;};if ($b < 0) {$ty = "-" . $b + 12;}
		if ($b == 24 || $b == 0) {$b = 0;$ap = "am";$ty = 12;}
		if ($a < 24) {$ty = "\-$ty";}
		elsif ($a == 24) {$ty = "\=$ty";}
		else {$ty = "\+$ty";}
		$h = "";if ($ff == $LPConfig{'TimeZoneChange'}) {$h = "selected"}
		@hur[$a] = "<option value=\"$ff\" $h>"."$ty".":"."$Minute"." "."$ap"." (servertime + $ff)</option>\r";
		$b++;$a++;
	}
}
sub gettitle {use English;use CGI;use integer;require LWP::UserAgent;$q = new CGI;$ua = new LWP::UserAgent;$the_cgi = CGI->new;if ($INPUT{'fixtitle'}){print "domain=$domain<br>";}$data = $domain;$lookup = new HTTP::Request 'GET', "$data";$response = $ua->request($lookup);@lines = split (/\n/, $response->content);foreach $line (@lines){if ($line =~ /\<title\>/i){($junk,$line,$junk2) = split(/itle\>/,$line);$line =~ s/\<t//gi;$line =~ s/\<\/t//gi;return $line;}}}

sub gopts {
	my $opt = shift;@s = "";$zz = ($opt / 10);@s[$zz] = "selected";
	$options = qq~<option value="10" $s[1]>10</option><option value="20" $s[2]>20</option><option value="30" $s[3]>30</option><option value="40" $s[4]>40</option>
	<option value="50" $s[5]>50</option><option value="100" $s[10]>100</option><option value="150" $s[15]>150</option>
	<option value="200" $s[20]>200</option><option value="250" $s[25]>250</option><option value="300" $s[30]>300</option>
	<option value="350" $s[35]>350</option><option value="400" $s[40]>400</option><option value="450" $s[45]>450</option>
	<option value="500" $s[50]>500</option><option value="550" $s[55]>550</option><option value="600" $s[60]>600</option>
	<option value="650" $s[65]>650</option><option value="700" $s[70]>700</option><option value="750" $s[75]>750</option>
	<option value="800" $s[80]>800</option><option value="850" $s[85]>850</option><option value="900" $s[90]>900</option>
	<option value="950" $s[95]>950</option><option value="1000" $s[100]>1000</option>~;
	return $options;
}
sub ginput {$del="";
	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{'delete'} ne "" && ($name ne "pword")) {$del.="$name,";}
		elsif ($name eq "frames") {$INPUT{$value} = 1;}
		elsif ($value ne '') { $INPUT{$name} = $value; }
		elsif ($name eq "count") {$INPUT{$name} = 1;}
		else { $INPUT{$name} = 0; }
		if ($name eq "pword") {$p1 = crypt($value,AD);}
	}
	@pairs = split(/&/, $ENV{'QUERY_STRING'});
	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{'del'}) {$del.="$name,";}
		elsif ($name eq "frames") {$INPUT{$value} = 1;}
		elsif ($value ne '') { $INPUT{$name} = $value; }
		elsif ($name eq "count") {$INPUT{$name} = 1;}
		else { $INPUT{$name} = 0; }
	}
	$p2 = "AD7o2p3Qa/RHA";
	$guest = "notaguestpasswordalallalalalallalaal";
	if ($INPUT{'pword'} =~ /guest/) { $guest = crypt($INPUT{'pword'}, AD);$INPUT{'pword'} = crypt($INPUT{'pword'}, AD); }
	elsif ($INPUT{'pword'}) {$INPUT{'pword'} = crypt($INPUT{'pword'},AD);}
	if ($INPUT{'hword'}) { } else {$INPUT{'hword'} = 0;}
}

sub closed {
	($j,$k) = split(/~~~/,$ENV{'QUERY_STRING'});
	open (TMP,"data/r.dat");
	$l = <TMP>;
	close (TMP);
	if (!($l =~ /$k/)) {&writeit("TMP","data/r.dat","$k",0,1);}
	print qq~<script>self.close();</script>~;
}
sub autoupdate {
	$noupdat=1;
	&header('Updating Search Data file');print qq~
	<script src="http://www.logitpro.com/cgi-bin/auto.cgi?$script"></script>
	
	<br><Br>
	when you see the button appear above, click on it to update your search.dat file.
	~;
	&footer;
	exit;
	
}
sub updatedata {
	@tmp = split(/\|~~/,$INPUT{'updatedata'});
	open (TMP,">search.dat") || &ErroR('</script>unable to update search file');
	foreach $tmp (@tmp) {
		print TMP "$tmp\n";
	}
	
	close (TMP);
	open (FILE,"search.dat");
	($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat(FILE);
	close (FILE);
	if ($size < 100) {&ErroR('</script>Data in search.dat file has been lost due to a server error... Please update immediately! (contact searchdaterror@logitpro.com and tell them your problem)');}
	else {&login('Search.dat has been updated!');}
}

sub header {
	$title = shift;
	open (TMP,"data/c.dat");@count = split(/\|/,<TMP>);close (TMP);
	open (TMP,"data/o.dat");@overall = split(/\|/,<TMP>);close (TMP);
	open (TMP,"search.dat");
	@logit=<TMP>;
	close (TMP);
	$sinfo = $logit[0];
	print qq~
<!--// ERROR! DOCUMENT CONTAINS NO DATA // -->\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
<html>
<head>
<script><!-- //
function dsrc(dirt) {
	document.location = dirt;
}
function direct(uri) {
windowIMA=window.open("$script?closed\~\~\~"+uri+"",'Anim2','toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,status=no,resizable=0, width=1, height=1,titlebar=no');
}
propt=0;
function listprompt() {
	if (propt == 0){ propt=1; } else { prompt=0; }
}
function listgo(loc) {
	if (propt == 0){document.location=loc;}
	else {
	var list = prompt("LogIT PRO:  Please enter the number of items you want to be listed:", "");
	document.location=loc+"&list="+list;
	}
}
// -->
</script>
	<title>$title</title>
	<style>
	body {
		font-family: Verdana, Helvetica, sans-serif;
		color: \#FFFFFF;
		background-color: \#011234;
	}
	A {color: \#FFFFFF;}
	A:VISITED {color: \#DDDDCC;}
	A:ACTIVE {color: \#FFFF00;}
	A:HOVER {color: \#FFFF00;}
	.hover {color: \#FFFF00 !IMPORTANT;}
	.sidebar {background-color: \#011234; font-size: 8pt; text-decoration: none;}
	.shadow {background-color: \#000000;color: \#000000;}
	.mainsection {background-color: \#566789; font-size:12pt;}
	.hrcolor {color: \#011234;}
	.tddark {background-color: \#344567;border-color: \#000000;color: \#FFFFFF;}
	.tdlight {background-color: \#566789;border-color: \#000000;color: \#FFFFFF;}
	.tble {border-color: \#000000;}
	.light {background-color: \#7889AB;border-color: \#000000;color: \#000000;}
	.dark {background-color: \#011234;border-color: \#000000;color: \#FFFFFF;}
	</style>
</head>

<body leftmargin=0 topmargin=0>
<font  size=4><b><center>$title</center></b></font>
<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
	<td width="150" valign="top" nowrap class="sidebar">
	<DIV id="waterMark" style="position:absolute">	
	<form name="entryform" onSubmit="return false;">
	<table border="0" cellspacing="0" cellpadding="8" class="sidebar">
	<tr>
	<td nowrap class="sidebar">
	<input type="CHECKBOX" name="distype" onClick="markYou();">auto scroll?
	<br><a href="$script?login">Administration</A><br>
	<a href="$script?gencode">Generate Your Code</A><br><BR>
	<a href="$script?topclr">Screen Color/Res</a><br>
	<a href="$script?topjva">Java Enabled?</a><br><br>
	<a href="$script?hourb">Hourly Breakdown</A><br>
	<a href="$script?dalyb">Daily Breakdown</A><br>
	<a href="$script?weekb">Weekly Breakdown</A><br>
	<a href="$script?montb">Monthly Breakdown</A><br><BR>
	<input type="CHECKBOX" name="lispromp" onClick="listprompt();">prompt list#?<br>
	<a href="javascript:listgo('$script?lastvisits');">Last $LPConfig{'LastVisits'} visitors</A><br>
	<a href="javascript:listgo('$script?lastrefers');">Last $LPConfig{'LastVisits'} Referrers</A><br>
	<a href="javascript:listgo('$script?lastsearch');">Last $LPConfig{'LastVisits'} Searches</A><br><br>
	<a href="javascript:listgo('$script?toprefers');">Top $LPConfig{'TopRefers'} Referrers</A><br>
	<a href="javascript:listgo('$script?topsearch');">Top $LPConfig{'TopRefers'} Searches</A><br>
	<a href="javascript:listgo('$script?topsearcheg');">Top $LPConfig{'TopRefers'} SearchEng</A><br>
	<a href="javascript:listgo('$script?toppages');">Top $LPConfig{'TopRefers'} Local Pages</A><br><br>
	<a href="javascript:listgo('$script?topips');">Top $LPConfig{'TopHosts'} IPs</A><br>
	<a href="javascript:listgo('$script?tophosts');">Top $LPConfig{'TopHosts'} Hosts</A><br>
	<a href="javascript:listgo('$script?topdomains');">Top $LPConfig{'TopHosts'} Domains</A><br><BR>
	<a href="javascript:listgo('$script?topcountries');">Top $LPConfig{'TopPlat'} Countries</A><br>
	<a href="javascript:listgo('$script?topplatform');">Top $LPConfig{'TopPlat'} Platforms</A><br>
	<a href="javascript:listgo('$script?topbrowser');">Top $LPConfig{'TopPlat'} Browsers</A><br>
	<br>
	<a href="$script?makebak">Create Backup</A></b><br>
	<a href="$script?fixwbak">Restore w/ BkUP</A></b><br>
	<br><br><br>
	<br><script src=" "></script>~;
	if (!($noupdat)) {print qq~<br><script src=" "></script>~;}
	open (TMP,"data/t.overall");$tmp=length <TMP>;close (TMP);$overall[1] = ($overall[1] + $tmp);
	open (TMP,"data/u.overall");$tmmp=length <TMP>;close (TMP);$overall[2] = ($overall[2] + $tmmp);
	open (TMP,"data/t.count");$tmpz=length <TMP>;close (TMP);$count[0] = ($count[0] + $tmpz);
	open (TMP,"data/u.count");$tmmpz=length <TMP>;close (TMP);$count[1] = ($count[1] + $tmmpz);
		
	print qq~
	<br><Br><table border=0 cellspacing=0 cellpadding=0 margin width=0 margin height=0  class="sidebar"><tr><td colspan=2><font size="-2"><center><b>Today's Hits</b></center></font></td></tr>\r
	<tr><td>Total:</td><td><span class="hover">$count[0]</span></td></tr>\r
	<tr><td>Unique:</td><td><span class="hover">$count[1]</span></td></tr>\r</table>
	<Br><table border=0 cellspacing=0 cellpadding=0 margin width=0 margin height=0  class="sidebar"><tr><td colspan=2><font size="-2"><center><b>Overall Hits</b></center></font></td></tr>\r
	<tr><td>Total:</td><td><span class="hover">$overall[1]</span></td></tr>\r
	<tr><td>Unique:</td><td><span class="hover">$overall[2]</span></td></tr>\r
	<tr><td>From:</td><td><span class="hover">$overall[0]</span></td></tr>\r</table>
	
	</td>
	</tr>
	</table></form>
	</div>

	</td>
	
	<td width="0" class="shadow">|</td>
	
	<td width="100%" class="mainsection">	<table width="100%" border="0" cellspacing="0" cellpadding="10">
	
	<tr>
	<td valign=top>~;#DO NOT EDIT THIS OUT -- CONTACT webmaster\@logitpro.com
	print qq~
	<center><font size=2>

</html>
~;
}
sub footer {
	print qq~</font>
	
	</td>
	</tr>
	</table>

	</td>
</tr>\r
<tr>
	<td colspan="3" valign="top"><div align="center"><font face="Arial" size="-2"></font></div></td>

</tr>\r
</table></font>
<script language="JavaScript1.2">
<!--

markW = 120;       // pixels wide
markH = 400;       // pixels high
markRefresh = 20; // milliseconds

// set common object reference
if (!document.all) document.all = document;
if (!document.all.waterMark.style) document.all.waterMark.style = document.all.waterMark;

wMark = document.all.waterMark.style;
wMark.width = markW;
wMark.height = markH;
navDOM = window.innerHeight; // Nav DOM flag
 
function setVals() {
 barW = 0; // scrollbar compensation for PC Nav
 barH = 0;
 if (navDOM) {
  if (document.height > innerHeight) barW = 20;
  if (document.width > innerWidth) barw = 20;
  } else {
  innerWidth = document.body.clientWidth;
  innerHeight = document.body.clientHeight;
  }

   posX = 0;
   posY = 0;
   
 }


function wRefresh() {
	 if (markIF == 1) { 
 wMark.left = posX; /*+ (navDOM?pageXOffset:document.body.scrollLeft);*/
 wMark.top = posY + (navDOM?pageYOffset:document.body.scrollTop);
 }
 }
markIF = 0;
function markMe() {
    	if (screen.width > 640 ) {

             
    setVals();
    window.onresize=setVals;
   markID = setInterval ("wRefresh()",markRefresh); }
       
 }

function markYou() {
	if (markIF == 0){
	markIF = 1;
	markMe();
 } else { markIF = 0; }
}
if (markIF == 1){
markMe();
}
//-->
</script>


</body>
</html>
			
<BR><BR><BR>$IMG[10] align='left' width=150 height=200><B>$ENV{'QUERY_STRING'}~;
open (INFO,"data/i.dat") || &ErroR('unable to open the info file i.dat');
@info = split(/\r/,<INFO>);
close (INFO);
@info = sort {uc($b) cmp uc($a)} @info;
$tmp="";
foreach $line (@info) {
$tmp .= "$line\r";	
}
$xam=($LPConfig{'MaxLogSize'}*1000);
$ttmp = length $tmp;
if ($ttmp > $xam) {
	print "ttmp=$ttmp , xam=$xam";
	$tmp = substr ($tmp,0,$xam);
	@tmp=split(/\r/,$tmp);
	pop @tmp;
	$tmp=join("\r",@tmp);$ttmp = length $tmp;
	open (TMP,">data/i.dat") || print "UNABLE TO OPEN I.DAT FILE";print TMP $tmp;close (TMP);
	print "<br>$IMG[10] width=150 height=1><b>Reduced the size of the INFO File to: $ttmp bytes</b>";
}
else {
if (!($xam)){$xam=1;}
$pcct=($ttmp/$xam)*100;$pcct=substr($pcct,0,4);$pcct.="%";
print "<br><br>info file is $pcct maximum size... clipping will occur at 100%";
}

print "<br><br>Initializing the Today/Overall Count System :::...";
	open (TMP,"data/c.dat");@count = split(/\|/,<TMP>);close (TMP);
	open (TMP,"data/o.dat");@overall = split(/\|/,<TMP>);close (TMP);
	open (TMP,"data/t.overall");$tmp=length <TMP>;close (TMP);$overall[1] = ($overall[1] + $tmp);
	open (TMP,"data/u.overall");$tmmp=length <TMP>;close (TMP);$overall[2] = ($overall[2] + $tmmp);
	open (TMP,"data/t.count");$tmpz=length <TMP>;close (TMP);$count[0] = ($count[0] + $tmpz);
	open (TMP,"data/u.count");$tmmpz=length <TMP>;close (TMP);$count[1] = ($count[1] + $tmmpz);
	open (TMP,">data/c.dat") || print "<br><b>Major Error:</b> Unable to Increment count data file";print TMP "$count[0]|$count[1]";close (TMP);
	open (TMP,">data/o.dat") || print "<br><b>Major Error:</b> Unable to Increment overall data file";print TMP "$overall[0]|$overall[1]|$overall[2]";close (TMP);
	open (TMP,">data/t.overall");close (TMP);
	open (TMP,">data/u.overall");close (TMP);
	open (TMP,">data/t.count");close (TMP);
	open (TMP,">data/u.count");close (TMP);
	print "<br><b>ALL COUNT FILES INCREMENTED!</b><br>";
}
sub readit {my $fn = shift;my $fh = shift;my $ck = shift;$fh =~ s/([\&;\`'\|\"*\?\~\^\(\)\[\]\{\}\$\n\r])//g;open ($fn, $fh) || ErroR("Error opening $fh for reading");@tmp = split(/\r/,<$fn>);if ($ck) {return;}else {foreach $tmp (@tmp) {print "$tmp<br>";}close ($fn);@tmp = "";}}
sub writeit {my $fn = shift;my $fh = shift;my $tmp = shift;my @c = (shift,shift,shift);$fh =~ s/([\&;\`'\|\"*\?\~\^\(\)\[\]\{\}\$\n\r])//g;if ($c[1] && $c[0]) {open ($fn, "$fh") || ErroR("Error opening $fh for reading");@tmp = <$fn>;close ($fn);open ($fn, ">$fh") || ErroR("Error opening $fh for input");}elsif ($c[0]) {open ($fn, ">$fh") || ErroR("Error opening $fh for overwrite");}elsif ($c[1]) {open ($fn, ">>$fh") || ErroR("Error opening $fh for append");}print $fn $tmp;if ($c[1] && $c[0]) {print $fn @tmp;}close ($fn);}

sub gdate {
	@Abbrev_Week_Days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	@Abbrev_Months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
	$SEC  = 1;
	$MIN  = 60 * $SEC;
	$HR   = 60 * $MIN;
	$DAY  = 24 * $HR;
	$epoch = (localtime(2*$DAY))[5];	# Allow for bugs near localtime == 0.
	$YearFix = ((gmtime(946684800))[5] == 100) ? 100 : 0;
	my $thetime = shift;unless ($thetime) { $thetime = time;if ($LPConfig{'TimeZoneChange'}) { $thetime = $thetime + ($LPConfig{'TimeZoneChange'} * 3600); }}
	($Second,$Minute,$Hour,$Month_Day, $Month,$Year,$Week_Day,$IsDST) = (localtime($thetime))[0,1,2,3,4,5,6,8]; 
	$ActualMonth = $Month + 1;
	$Year = $Year + 1900;
	$hhour = $Hour;
	if ($Second < 10) { $Second = "0$Second"; }
	if ($Minute < 10) { $Minute = "0$Minute"; }
	if ($Hour == 0) { 
		if ($LPConfig{'TimeHourFormat'} == "12") {$Hour = "12";}
		$AMPM = "a";
	}
	elsif ($Hour < 12) {
		$AMPM = "a";
	}
	elsif ($Hour == 12) {
		$AMPM = "p";
	}
	else {
		if ($LPConfig{'TimeHourFormat'} == "12") {$Hour = $Hour - 12;}
		$AMPM = "p";
	}
	$Month_Name = $Abbrev_Months[$Month];
	$Weekday = $Abbrev_Week_Days[$Week_Day];
	$Day = $Month_Day;
	$clock = "$Hour".":"."$Minute"." $AMPM";
	$date = "$Month_Name $Day";
	$today = ($Year*365)+($Month*30)+$Month_Day;
	(@dates) = (localtime($thetime - 86400))[0,1,2,3,4,5,6,8]; 
	$yesterday = "$Abbrev_Months[$dates[4]] $dates[3]";
}
sub gday {
	@Abbrev_Week_Days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
	$SEC  = 1;
	$MIN  = 60 * $SEC;
	$HR   = 60 * $MIN;
	$DAY  = 24 * $HR;
	$epoch = (localtime(2*$DAY))[5];	# Allow for bugs near localtime == 0.
	$YearFix = ((gmtime(946684800))[5] == 100) ? 100 : 0;
	my $thetime = shift;unless ($thetime) { $thetime = time;if ($LPConfig{'TimeZoneChange'}) { $thetime = $thetime + ($LPConfig{'TimeZoneChange'} * 3600); }}
	($Second,$Minute,$Hour,$Month_Day, $Month,$Year,$Week_Day,$IsDST) = (localtime($thetime))[0,1,2,3,4,5,6,8]; 
	return $Abbrev_Week_Days[$Week_Day];
}
sub ggdate {
	open (TMP,"data/d.log");$ctime=<TMP>;close (TMP);
	#($Second,$Minute,$Hour,$Month_Day, $Month,$Year,$Week_Day,$IsDST) = (localtime($thetime))[0,1,2,3,4,5,6,8]; 
	$thetime = (time + ($LPConfig{'TimeZoneChange'} * 3600));
	$ctime = ($ctime + ($LPConfig{'TimeZoneChange'} * 3600));
	@ta = (localtime($thetime))[0,1,2,3,4,5,6,8];
	@tb = (localtime($ctime))[0,1,2,3,4,5,6,8];
	if ($ta[3] ne $tb[3]) {return 1;}
	else {return 0;}
	
}
sub GetCookies {
	@Cookie_Encode_Chars = ('\%', '\+', '\;', '\,', '\=', '\&', '\:\:', '\s');
	
	%Cookie_Encode_Chars = ('\%',   '%25',
	                        '\+',   '%2B',
	                        '\;',   '%3B',
	                        '\,',   '%2C',
	                        '\=',   '%3D',
	                        '\&',   '%26',
	                        '\:\:', '%3A%3A',
	                        '\s',   '+');
	
	@Cookie_Decode_Chars = ('\+', '\%3A\%3A', '\%26', '\%3D', '\%2C', '\%3B', '\%2B', '\%25');
	
	%Cookie_Decode_Chars = ('\+',       ' ',
	                        '\%3A\%3A', '::',
	                        '\%26',     '&',
	                        '\%3D',     '=',
	                        '\%2C',     ',',
	                        '\%3B',     ';',
	                        '\%2B',     '+',
	                        '\%25',     '%');
	local($cookie,$value);
	if ($ENV{'HTTP_COOKIE'}) {
	foreach (split(/; /,$ENV{'HTTP_COOKIE'})) {
		($cookie,$value) = split(/=/);
		foreach $char (@Cookie_Decode_Chars) {
			$cookie =~ s/$char/$Cookie_Decode_Chars{$char}/g;
			$value =~ s/$char/$Cookie_Decode_Chars{$char}/g;
		}
		$Cookies{$cookie} = $value;
	}
	}	
}
sub gimgs {
	if (($LPConfig{'Images'} eq "custom") && ($LPConfig{'LPImgDir'} && $LPConfig{'LPImgDir'} ne "")) {
		$test = substr($LPConfig{'LPImgDir'},-1,1);
		if ($test ne "/") {$LPConfig{'LPImgDir'} .= "/" }
		$IMG[0] = qq~<img src="$LPConfig{'LPImgDir'}0.gif" ~;
		$IMG[1] = qq~<img src="$LPConfig{'LPImgDir'}1.gif" ~;
		$IMG[2] = qq~<img src="$LPConfig{'LPImgDir'}2.gif" ~;
		$IMG[3] = qq~<img src="$LPConfig{'LPImgDir'}3.gif" ~;
		$IMG[4] = qq~<img src="$LPConfig{'LPImgDir'}4.gif" ~;
		$IMG[5] = qq~<img src="$LPConfig{'LPImgDir'}5.gif" ~;
		$IMG[6] = qq~<img src="$LPConfig{'LPImgDir'}6.gif" ~;
		$IMG[7] = qq~<img src="$LPConfig{'LPImgDir'}7.gif" ~;
		$IMG[8] = qq~<img src="$LPConfig{'LPImgDir'}8.gif" ~;
		$IMG[9] = qq~<img src="$LPConfig{'LPImgDir'}9.gif" ~;
		$IMG[10] = qq~<img src="$LPConfig{'LPImgDir'}10.gif" ~;
		$IMG[11] = qq~<img src="$LPConfig{'LPImgDir'}11.gif" ~;
		$IMG[12] = qq~<img src="$LPConfig{'LPImgDir'}12.gif" ~;
		}
	else {
		$IMG[0] = qq~<img src="$script?img=0" height=9 width=9 ~;
		$IMG[1] = qq~<img src="$script?img=1" height=9 width=9 ~;
		$IMG[2] = qq~<img src="$script?img=2" height=9 width=9 ~;
		$IMG[3] = qq~<img src="$script?img=3" height=9 width=9 ~;
		$IMG[4] = qq~<img src="$script?img=4" height=9 width=9 ~;
		$IMG[5] = qq~<img src="$script?img=5" ~;
		$IMG[6] = qq~<img src="$script?img=6" ~;
		$IMG[7] = qq~<img src="$script?img=7" ~;
		$IMG[8] = qq~<img src="$script?img=8" ~;
		$IMG[9] = qq~<img src="$script?img=9" ~;
		$IMG[10] = qq~<img src="$script?img=10" ~;
		$IMG[11] = qq~<img src="$script?img=11" height=9 width=9 ~;
		$IMG[12] = qq~<img src="$script?img=12" ~;
	}
	if (!($IMG[0] ne "") || !($IMG[0])) {
		$IMG[0] = qq~<img src="$script?img=0" height=9 width=9 ~;
		$IMG[1] = qq~<img src="$script?img=1" height=9 width=9 ~;
		$IMG[2] = qq~<img src="$script?img=2" height=9 width=9 ~;
		$IMG[3] = qq~<img src="$script?img=3" height=9 width=9 ~;
		$IMG[4] = qq~<img src="$script?img=4" height=9 width=9 ~;
		$IMG[5] = qq~<img src="$script?img=5" ~;
		$IMG[6] = qq~<img src="$script?img=6" ~;
		$IMG[7] = qq~<img src="$script?img=7" ~;
		$IMG[8] = qq~<img src="$script?img=8" ~;
		$IMG[9] = qq~<img src="$script?img=9" ~;
		$IMG[10] = qq~<img src="$script?img=10" ~;
		$IMG[11] = qq~<img src="$script?img=11" height=9 width=9 ~;
		$IMG[12] = qq~<img src="$script?img=12" ~;
	}
}

sub SetCookies {
	local(@cookies) = @_;
	local($cookie,$value,$char);
	while ( ($cookie,$value) = @cookies ) {
		foreach $char (@Cookie_Encode_Chars) {
			$cookie =~ s/$char/$Cookie_Encode_Chars{$char}/g;
			$value =~ s/$char/$Cookie_Encode_Chars{$char}/g;
		}
	
		print 'Set-Cookie: ' . $cookie . '=' . $value . ';';
		$exptime = time + $cookieExpLength;
		$CookieExpires = DoGMTTime($exptime);
		print ' expires=' . $CookieExpires . ';';
		print "\n";
		shift(@cookies); shift(@cookies);
	}
	print "Content-type: text/html\n";
	print "\n";
	$HeaderPrinted = 1;
	&gdate;
}

sub DoGMTTime {
	my $thetime = shift;
	my $thedate;
	my ($Second,$Minute,$Hour,$Month_Day, $Month,$Year,$Week_Day,$IsDST) = (localtime($thetime))[0,1,2,3,4,5,6,8];	
	if ($Month_Day < 10) {
		$Month_Day = "0$Month_Day";
	}
	$Year = $Year + 1900;
	$thedate = "$Abbrev_Week_Days[$Week_Day], $Month_Day-$Abbrev_Months[$Month]-$Year 00:00:00 GMT";
	return $thedate;
}
sub ClearCookies {
	print "Set-Cookie: login=x; expires=Thu, 03-Feb-2000 00:00:00 GMT;\n";
	print "Content-type: text/html\n\n";
	$HeaderPrinted = 1;
}
sub ErroR {$a = shift;&header("$a");print $a;&footer;exit;}