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

############################################
########### DO NOT EDIT BELOW ##############
############################################
&ginput;
if ($INPUT{'login'} ne "") {print "Location: lpview.cgi?login\n\n";exit;}
print "Content-type: text/html\n\n";
&chk;
&ReadConfig;
&gserv;
if ($INPUT{'count'} ne "") {&count;}
elsif ($INPUT{'java'} ne "") {&java;}
elsif ($INPUT{'listit'} ne "") {&listit;}
elsif ($INPUT{'clrs'} ne "") {&clrs;}#LogitPRO VIP Service
elsif ($INPUT{'ctrk'} ne "") {&ctrk;}#LogitPRO VIP Service
elsif ($INPUT{'nojva'} ne "") {&nojva;}#LogitPRO VIP Service
elsif ($INPUT{'bugfix'} ne "") {&bugfix;}#LogitPRO VIP Service
else {print "[<b>ERROR:</b> no action specified]";}
sub count {
	$frames = "count";
	open (TMP,"data/c.dat");@count = split(/\|/,<TMP>);close (TMP);
	open (TMP,"data/o.dat");@overall = split(/\|/,<TMP>);close (TMP);
	open (TMP,"data/h.dat");@history = <TMP>;close (TMP);
	open (TMP,"data/m.dat");($weekdays,$months) = split(/\r/,<TMP>);close (TMP);
	open (TMP,"data/ip.dat");$ppi = <TMP>;close (TMP);
	$ynprint = 0;
	&gdate;
	$tmee = time;$mont=0;$monu=0;
	if ($ip ne "" && $ip) {
		$title="";
		if ($LPConfig{'gettitle'}){
		$domain = "$ref";
		$title = &gettitle();
		$title=~s/\'/\`/g;$title=~s/\"/\`\`/g;$title=~s/\|/\`/g;$title=~s/\~/\`\`/g;
		}
		$uri =~ s/\|//g;$search =~ s/\|//g;$ref =~ s/\|//g;
		$info = "$tmee|$date|$clock|$ref|$ip|$host|$brow|$plat|$uri|$search|$title|\r";
		&tcount;&toverall;$mont=1;
		if (!($ppi =~ /$ip/)) {$ppi .= $ip;&ucount;&uoverall;$monu=1;}
	}
	if (!($weekdays =~ /Sun/) || !($months =~ /Jan/)) {&dele("m.dat");open (TMP,"data/m.dat");($weekdays,$months) = split(/\r/,<TMP>);close (TMP);}
	@weekdays = split(/\|/,$weekdays);
	$weekday = "";
	foreach $line (@weekdays) {@z = split(/\:/,$line);($wektt,$wekuu) = split(/\~/,$z[1]);if ($z[0] eq $Weekday && $mont) {$wektt++;}if ($z[0] eq $Weekday && $monu) {$wekuu++;}if ($wektt eq "") {$wektt=0;}if ($wekuu eq "") {$wekuu=0;}if ($z[0] ne "") {$weekday .= "$z[0]:$wektt~$wekuu|";}}
	@months = split(/\|/,$months);
	$mmonth = "";
	foreach $line (@months) {@z = split(/\:/,$line);($wektt,$wekuu) = split(/\~/,$z[1]);if ($z[0] eq $Month_Name && $mont) {$wektt++;}if ($z[0] eq $Month_Name && $monu) {$wekuu++;}if ($wektt eq "") {$wektt=0;}if ($wekuu eq "") {$wekuu=0;}if ($z[0] ne "") {$mmonth .= "$z[0]:$wektt~$wekuu|";}}
	@monday = "$weekday\r$mmonth";
	$b=0;@tmp="";
	foreach $tmp (@count) {@tmp[$b] = "$tmp";$b++;}$b=0;@count = @tmp;@tmp="";
	foreach $tmp (@overall) {@tmp[$b] = "$tmp";$b++;}$b=0;@overall = @tmp;@tmp="";
	$DDay = ggdate();
	if ($DDay) {
		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);
		unlink "data/t.count";open (TMP,">data/t.count");close (TMP);
		unlink "data/u.count";open (TMP,">data/u.count");close (TMP);
		unlink "data/ip.dat"; $ppi=$ip;
		@history = "$yesterday|$count[0]|$count[1]|\r@history";
		@mail = @count;
		open (TMP,">data/c.dat") || print "<br><b>Major Error:</b> Unable to Increment count data file";print TMP "0|0|";close (TMP);
		$old=1;
		&olddate();
		open (TMP,">data/h.dat") || wknd("0","h");flock (TMP,2) || wknd("1","h");print TMP @history;close (TMP);
		}
	else {$old=0;}
	$jcount = join("|",@count);
	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;}
	close (LOCK);
	unlink "lock.test";
	if (!($overall[0])) {$overall[0] = "\~$date\, $clock";$jover = join("|",@overall);open (TMP,">data/o.dat");flock (TMP,2);print TMP $jover;close (TMP);}
	if ($ynprint) {
		unless (-e "flock.tmp") {open (LOCK,">flock.tmp");close (LOCK);
		open (TMP,">data/m.dat") || wknd("0","m");flock (TMP,2) || wknd("1","m");print TMP @monday;close (TMP);
		open (TMP,">data/ip.dat") || wknd("0","p");flock (TMP,2) || wknd("1","p");print TMP $ppi;close (TMP);
		unlink "flock.tmp";
		}
		open (TMP,">>data/i.dat") || wknd("0","i");flock (TMP,2) || wknd("1","i");print TMP $info;close (TMP);
	}
	unless (-e "data/d.log") {open (DATE,">data/d.log");print DATE "$today";close DATE;}
	if ($LPConfig{'email'} eq "Yes" && $old) {
		$mailprog = $LPConfig{'mailprog'};
			open (MAIL,"|$mailprog -t");
			print MAIL "To: $LPConfig{'yourmail'}\n";
			print MAIL "From: $LPConfig{'yourmail'}\n";
			print MAIL "Subject: Daily Hit Statistics for $yesterday\n";
			print MAIL "Hello, this is your daily e-mail from logitPro\n";
			print MAIL "to let you know about today's stats.\n\n";
			print MAIL " $mail[0] total hits today\n";
			print MAIL " $mail[1] of which are completely unique\n\n\n\n";
			print MAIL "-------------------------------------\n";
			print MAIL "daily stats brought to you by logitPro and the following:\n";
			print MAIL "http://www.bennyland.com/\n";
			print MAIL "http://www.logitpro.com/\n";
			close(MAIL); 
		}
	@dcount = split(/\,/, $LPConfig{'DontCount'});
	$dcc = 1;
	foreach $line (@dcount) {
		if ($uri =~/$line/) { $dcc = 0; }
	}
	if ($dcc) {
	open (TMP,"t.overall");$tmp=length <TMP>;close (TMP);$overall[1] = ($overall[1]+$tmp);
	open (TMP,"u.overall");$tmmp=length <TMP>;close (TMP);$overall[2] = ($overall[2]+$tmmp);
	if ($LPConfig{'DisplayCounter'} eq "1") { print $overall[2]; }
	elsif ($LPConfig{'DisplayCounter'} eq "2") { print $overall[1]; }
	elsif ($LPConfig{'DisplayCounter'} eq "3") { print ($overall[2]+$LPConfig{'AddCount'}); }
	elsif ($LPConfig{'DisplayCounter'} eq "4") { print ($overall[1]+$LPConfig{'AddCount'}); }
	else {print "<!-- // Counter is turned off // -->";}
	}
	if ($INPUT{'res'}) {&clrs;}#LogitPRO VIP Service
}
sub wknd {
my $died = shift;
my $used = shift;
if ($died) {
	return;
}
else {
	return;
}
return;	
}
sub tcount {
	open (TMP,">>data/t.count");flock (TMP,2);print TMP ".";close (TMP);return;
}
sub toverall {
	open (TMP,">>data/t.overall");flock (TMP,2);print TMP ".";close (TMP);return;
}
sub ucount {
	open (TMP,">>data/u.count");flock (TMP,2);print TMP ".";close (TMP);return;
}
sub uoverall {
	open (TMP,">>data/u.overall");flock (TMP,2);print TMP ".";close (TMP);return;
}
sub olddate {open (DATE,">data/d.log") || print "cannot open date log for date switch";flock (DATE,2);print DATE $tmee;close(DATE);return;}
#Delete
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 "d.dat")) {unlink "$dele";}}
}


sub chk {	
	unless (-e "data") {mkdir "data",700;$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
}

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 Identify_Agent {if ($agent =~ m#cherrypicker#oi || $agent =~ m#crescent#oi || $agent =~ m#emailcollector#oi || $agent =~ m#emailsiphon#oi || $agent =~ m#emailwolf#oi || $agent =~ m#extractorpro#oi || $agent =~ m#microsoft url#oi || $agent =~ m#mozilla/3.mozilla/2.01#oi || $agent =~ m#newt#oi || $agent =~ m#nicerspro#oi || $agent =~ m#webbandit#oi) {$longagent = "E-Mail Harvester";$shortagent = "E-Mail Harvester";} elsif ($agent =~ m#opera/(\d)#oi || $agent =~ m#opera (\d)#oi) {$longagent = "Opera v$1";	$shortagent = "Opera";}
  elsif ($agent =~ m#opera#oi) {$longagent = "Opera";$shortagent = "Opera";} elsif ($agent =~ m#mozilla#oi) {$mozillaversion = 0;if ($agent =~ m#mozilla/(\d)#oi) {$mozillaversion = $1;} if ($agent =~ m#compatible#oi) {if ($agent =~ m#webtv#oi) {$longagent = "WebTV";$shortagent = "WebTV";} elsif ($agent =~ m#aol (\d)#oi) {$longagent = "AOL's Browser v$1";$shortagent = "AOL's Browser";} elsif ($agent =~ m#iweng (\d)#oi) {$longagent = "AOL's Browser v$1";$shortagent = "AOL's Browser";}	elsif ($agent =~ m#msie (\d)#oi) {$longagent = "MS Internet Explorer v$1";
  $shortagent = "MS Internet Explorer";} elsif ($agent =~ m#msie#oi) {$longagent = "MS Internet Explorer";$shortagent = "MS Internet Explorer";} elsif ($agent =~ m#bot#oi || $agent =~ m#frontpage#oi || $agent =~ m#powermarks#oi || $agent =~ m#spider#oi || $agent =~ m#webwhacker#oi) {$longagent = "Spider/Robot";$shortagent = "Spider/Robot";} else {$longagent = "Other Agent";$shortagent = "Other Agent";}} elsif ($agent =~ m#msie#oi) {$longagent = "MS Internet Explorer";$shortagent = "MS Internet Explorer";} elsif ($agent =~ m#bot#oi || $agent =~ m#spider#oi) {
  $longagent = "Spider/Robot";$shortagent = "Spider/Robot";} else {if ($mozillaversion) {$longagent = "Netscape Navigator v$mozillaversion";} else {$longagent = "Netscape Navigator";}$shortagent = "Netscape Navigator";}} elsif ($agent =~ m#iweng/(\d)#oi) { $longagent = "AOL's Browser v$1";$shortagent = "AOL's Browser";} elsif ($agent =~ m#aolbrowser/(\d)#oi) {$longagent = "AOL's Browser v$1";$shortagent = "AOL's Browser";} elsif ($agent =~ m#microsoft internet explorer/(\d)#oi) {$longagent = "MS Internet Explorer v$1";$shortagent = "MS Internet Explorer";}
  elsif ($agent =~ m#lynx#oi) {$longagent = "Lynx";$shortagent = "Lynx";} elsif ($agent =~ m#teleport pro#oi) {$longagent = "Teleport Pro Offline Browser";$shortagent = "Teleport Pro Offline Browser";} elsif ($agent =~ m#analyzer#oi || $agent =~ m#batch#oi || $agent =~ m#bot#oi || $agent =~ m#check#oi || $agent =~ m#crawl#oi || $agent =~ m#digout#oi || $agent =~ m#ecatch#oi || $agent =~ m#elitesys#oi || $agent =~ m#enfish#oi || $agent =~ m#frontpage#oi || $agent =~ m#getright#oi || $agent =~ m#gozilla#oi || $agent =~ m#harvest#oi || $agent =~ m#infoseek#oi
  || $agent =~ m#links#oi || $agent =~ m#mata hari#oi || $agent =~ m#netants#oi || $agent =~ m#offline#oi || $agent =~ m#powermarks#oi || $agent =~ m#reader#oi || $agent =~ m#reaper#oi || $agent =~ m#roamer#oi || $agent =~ m#rover#oi || $agent =~ m#scooter#oi || $agent =~ m#slurp#oi || $agent =~ m#spider#oi || $agent =~ m#sweep#oi || $agent =~ m#url#oi || $agent =~ m#validator#oi || $agent =~ m#walker#oi) {$longagent = "Spider/Robot";$shortagent = "Spider/Robot";} else {$longagent = "Other Agent";$shortagent = "Other Agent";} if ($longagent ne "") {$brow = "$longagent";}
  elsif ($shortagent ne "") {$brow = "$shortagent";} else { $brow = "UnKNOWN"; }
}
sub Identify_Platform {if ($agent =~ m#win#oi) {$shortplatform = "Windows";if (($agent =~ m#95/nt#oi) || ($agent =~ m#98/nt#oi)) {$longplatform = "Windows";} elsif (($agent =~ m#win95#oi) || ($agent =~ m#windows 95#oi)) {$longplatform = "Windows 95";} elsif (($agent =~ m#win98#oi) || ($agent =~ m#windows 98#oi)) {$longplatform = "Windows 98";}
 elsif (($agent =~ m#winNT#oi) || ($agent =~ m#windows nt#oi)) {$longplatform = "Windows NT";} elsif ($agent =~ m#windows 3.1#oi) {$longplatform = "Windows 3.1";} elsif (($agent =~ m#win16#oi) || ($agent =~ m#win32#oi) || ($agent =~ m#winweb#oi) || ($agent =~ m#windows#oi)) {$longplatform = "Windows";} elsif ($agent =~ m#window#oi) {$shortplatform = "X Windows";$longplatform = "X Windows";}
 else {$longplatform = "Windows";}} elsif ($agent =~ m#mac#oi) {$shortplatform = "Macintosh";if (($agent =~ m#ppc#oi) || ($agent =~ m#powerpc#oi)) {$longplatform = "Macintosh PowerPC";} else {$longplatform = "Macintosh 68K";}} elsif ($agent =~ m#amiga#oi) {$shortplatform = "Amiga";$longplatform = "Amiga";} elsif ($agent =~ m#os/2#oi) {$shortplatform = "OS/2";$longplatform = "OS/2";}
 elsif ($agent =~ m#x11#oi) {$shortplatform = "UNIX";if ($agent =~ m#hp-ux#oi) {$longplatform = "UNIX (HP-UX)";} elsif ($agent =~ m#linux#oi) {$longplatform = "UNIX (Linux)";} elsif ($agent =~ m#sunos#oi) {$longplatform = "UNIX (SunOS)";} elsif ($agent =~ m#freebsd#oi) {$longplatform = "UNIX (FreeBSD)";} elsif ($agent =~ m#netbsd#oi) {$longplatform = "UNIX (NetBSD)";}
 elsif ($agent =~ m#bsd#oi) {$longplatform = "UNIX (BSD)";} elsif ($agent =~ m#aix#oi) {$longplatform = "UNIX (AIX)";} elsif ($agent =~ m#osf1#oi) {$longplatform = "UNIX (OSF1)";} elsif ($agent =~ m#irix#oi) {$longplatform = "UNIX (IRIX)";} else {$longplatform = "UNIX";}} elsif ($agent =~ m#iweng#oi || $agent =~ m#teleport#oi) {$shortplatform = "Windows";$longplatform = "Windows";}
 elsif ($agent =~ m#lynx#oi) {$shortplatform = "UNIX";$longplatform = "UNIX";} elsif ($agent =~ m#webtv#oi) {$shortplatform = "";$longplatform = "WebTV";} else {$shortplatform = "Unknown Platform";$longplatform = "Unknown Platform";} if ($shortagent eq "E-Mail Harvester") {$shortplatform = "";$longplatform = "E-Mail Harvester";}
 if ($shortagent eq "Spider/Robot") {$shortplatform = "";$longplatform = "Spider/Robot";} if ($longplatform ne "") {$plat = "$longplatform";} elsif ($shortplatform ne "") {$plat = "$shortplatform";} else { $plat = "UnKNOWN"; }
}

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;
	}
}

sub gserv {
	
	if ($ENV{'REMOTE_ADDR'}) {
		$ip = $ENV{'REMOTE_ADDR'};
		$ip = substr($ip,0,15);
		if ($LPConfig{'IPBlocked'}) {
			@ip = split(/,/,$LPConfig{'IPBlocked'});
			foreach $ibl (@ip) {
				if ($ibl ne '' && $ip =~ /$ibl/) {
					$ip = "";
				}
			}
		}
	}
	
	else {$ip = "";}
	
	if ($INPUT{'jref'}) {$ref = $INPUT{'jref'};}
	else {$ref = $ENV{'HTTP_REFERER'};}
	
	@dblock = split(/\,/,$LPConfig{'DomainBlocked'});
	foreach $line (@dblock) {
		if (($ref =~ /$line/) || ($ref =~ /jref/)) {
			$ref = "";
		}
	}
	
	if ($INPUT{'juri'}) {$uri = $INPUT{'juri'};
		if ($uri =~ /juri/) {$uri = "/";}
		else {@uri = split(/\//,$uri);$uri = "";$b = 0;
			foreach $line (@uri) {
				if ($b < 3) { }
				else {$uri .= "\/$line";}
				$b++;
			}
			if ($uri ne "") { }
			else { $uri = "/"; }
	}}
	else {$uri = $ENV{'REQUEST_URI'};}
	$agent = $ENV{'HTTP_USER_AGENT'};($url,@b) = split(/\?/,$uri);($url,@b)=split(/\#/,$url);
	$blah = "$LPConfig{'ServerPath'}$url";
	unless (-e "$blah") { $uri = "$uri~x~<font color=\"#FF0000\"><b>*</b></font>~x~"; }
	if ($LPConfig{'inex'}) {@idex = split(/\,/,$LPConfig{'inex'});foreach $line (@idex) {$uri =~ s/$line//gi;}}
	if ($ENV{'REMOTE_HOST'} && ($ENV{'REMOTE_HOST'} ne $ENV{'REMOTE_ADDR'})) {$host2 = $ENV{'REMOTE_HOST'};}
	else {$host=$ip;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~...~;}
	&Identify_Agent;
	&Identify_Platform;
	&gsearch();
}
sub gsearch {	
	&sgin;
	if (!($cps)) {return 0;}

	($tmp,$string) = split(/\?/,$refi);
	if ($string =~ $cps) { @string = split(/&/,$string); }
	else {return 0;}
	foreach $tmp (@string) {
		@tmp = split(/=/,$tmp);
		$ttm = "$tmp[0]";
		@tmp[0] = "$ttm"."=";
		if ($tmp[0] =~ /$cps/ && $tmp[0] !~ /stq/) { $sterms = $tmp[1]; }
	}
	&csrh;
	if ($sss) {$search = "$sss:$sterms";}
	else {$search = 0;}
}
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 sgin {
	$cps = 0;
	$sss = 0;
	open (SG,"search.dat");
	@sg = <SG>;
	close (SG);
	$refi = "$ref";
	foreach $line (@sg) {
		@r = split(/~x~/,$line);
		if (($refi =~ /$r[0]/) && ($refi =~ /$r[1]/)) {
			$cps = $r[1];
			$sss = $r[2];
			return;
		}
	}
	return;
}
sub csrh {if ($sterms ne "") {$sterms =~ tr/+/ /;$sterms =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;} else { return; }}
sub ginput {$del="";
	@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 ($value ne '') { $INPUT{$name} = $value; }
		elsif ($name eq "count") {$INPUT{$name} = 1;}
		else { $INPUT{$name} = 0; }
	}
}
sub java {
	$ovall = "";
	if ($LPConfig{'DisplayCounter'}) {
		open (TMP,"data/o.dat");@overall = split(/\|/,<TMP>);close (TMP);
		if ($LPConfig{'DisplayCounter'} eq "1") { $ovall = $overall[2]; }
		elsif ($LPConfig{'DisplayCounter'} eq "2") { $ovall = $overall[1]; }
		elsif ($LPConfig{'DisplayCounter'} eq "3") { $ovall = ($overall[2]+$LPConfig{'AddCount'}); }
		elsif ($LPConfig{'DisplayCounter'} eq "4") { $ovall = ($overall[1]+$LPConfig{'AddCount'}); }
		else {$ovall = "";}
	}
	print qq~<!-- //
lok="$LPConfig{'URI'}";
d=document;
document.write('$ovall<img src="'+lok+'?count&',
'jref='+escape(d.referrer)+'&',
'juri='+escape(d.location)+'" ',
'width=1 height=1 border=0 alt="" nosave>');
	// -->
	~;
if ($INPUT{'res'}) {&clrs;}#LogitPRO VIP Service
}

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 ggdate {
	open (TMP,"data/d.log");$ctime=<TMP>;close (TMP);
	$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 listit {
	print qq~
	This is a safe debug mechanisim, please DO NOT remove it,
	it WILL NOT give away any valuable info (your password is
	one way incripted, so even if it gave that away, it would
	be impossible to tell what your password is).  For more info
	on the debug, please e-mail debug\@logitpro.com<br>
	<br>
	<b>gettitle</b> $LPConfig{'gettitle'} <br>
	<b>email</b> $LPConfig{'email'} <br>
	<b>mailprog</b> $LPConfig{'mailprog'} <br>
	<b>yourmail</b> $LPConfig{'yourmail'} <br>
	<b>DisplayCounter</b> $LPConfig{'DisplayCounter'} <br>
	<b>AddCount</b> $LPConfig{'AddCount'} <br>
	<b>ServerPath</b> $LPConfig{'ServerPath'} <br>
	<b>IPBlocked</b> $LPConfig{'IPBlocked'} <br>
	<b>DomainBlocked</b> $LPConfig{'DomainBlocked'} <br>
	<b>ServerPath</b> $LPConfig{'ServerPath'} <br>
	<b>inex</b> $LPConfig{'inex'} <br>
	<b>URI</b> $LPConfig{'URI'} <br>
	<b>TimeZoneChange</b> $LPConfig{'TimeZoneChange'} <br>
	<b>TimeHourFormat</b> $LPConfig{'TimeHourFormat'} <br>~;
}

sub ErroR {$a = shift;print $a;exit;}


#LogitPRO VIP Service
sub clrs {
	print qq~<!-- // LogIT PRO VIP ONLY - Please purchase the VIP version // -->~;
}
#LogitPRO VIP Service
sub ctrk {
	print qq~<!-- // LogIT PRO VIP ONLY - Please purchase the VIP version // -->~;
}
#LogitPRO VIP Service
sub nojva {
	print qq~<!-- // LogIT PRO VIP ONLY - Please purchase the VIP version // -->~;
}


sub bugfix {
	unless (-e "milbugfix.backup") {
	print "<b><font face='verdana, arial, helvetica, sans-serif' size=2>Billionth Second Bug Fix: LogIT PRO</b></font><br><br>\n\n";
	print "<font face='verdana, arial, helvetica, sans-serif' size=2>\n\n";
	open (BAK, ">milbugfix.backup") || &killit("Cannot create the milbugfix backup file.  PATCH cannot proceed");
	open (DAT, "data/i.dat") || &killit("Cannot open the info data file.  PATCH cannot proceed.<br>" . $! . "\n\n\n>done\n");
	print "Creating backup of Info Data file<br>\n &nbsp; &nbsp; &nbsp; Making corrections on each line...<br>\n";
	$lcnt = 0;
	$ccnt = 0;
	@info = split(/\r/,<DAT>);
	close (DAT);
	foreach $line (@info) {
		if (substr($line,0,1) == "9") {
			$line = "0" . $line;
			$lcnt++;
		} else {
			$ccnt++;
		}
		print BAK $line . "\r";
	}
	close (BAK);
	print "\nBackup Created<br>\n &nbsp; &nbsp; &nbsp; <b>" . $lcnt . "</b> corrections have been made<br>\n &nbsp; &nbsp; &nbsp; <b>" . $ccnt . "</b> lines needed no correction\n\n<br><br>\n\n";

	print "Converting Backup to i.dat";
	open (DAT, ">data/i.dat") || &killit("ERROR: CANNOT RE-OPEN DATA FILE!!!!!");
	open (BAK, "milbugfix.backup") || &killit("FATAL ERROR!  BACKUP FILE CANNOT BE RE-OPENED! ALL DATA LOST");
	@info = split(/\r/,<BAK>);
	close (BAK);
	foreach $line (@info) {
		print DAT $line . "\r";
	}
	close (DAT);
	}
	open (BAK, ">milbugfix.backup");
	print BAK "1";
	close (BAK);
	if (-e "milbugfix.backup") {
		print "\n\n<br><br>\n\nFINISHED: \n\n <br>If you see nothing above, then the PATCH did not need to be done, or has already been applied\n\n<br>\n\nYou will now see a file called milbugfix.backup.  DO NOT DELETE THIS FILE"	
	}
	exit;
}


sub killit {
	$death = shift;
	print $death;
	exit;
}


exit;