#!/usr/bin/perl
# counter nur fuer die Anzeige
require"./read.pl";

&ReadParse;
&SpaceKill;

$link=$in{'link'}|| $ENV{SERVER_NAME};
if(index($link,"adidas-lycra.de.vu") != -1){print "Content-type:text/html\n\n";print "Bitte an netviper wenden";exit;}
$link =~ s/,/\//g;
open(COUNT,"counter.txt");
@counter=<COUNT>;
close(COUNT);

#print "Content-type:text/html\n\n";

for(@counter)
{
if(/\n/){chop($_);}
@teile=split(/=/,$_);
$COUNT{$teile[0]}=$teile[1];
}
$COUNT{$link}++;


# counter neu schreiben

@keyIN=keys(%COUNT);

$gesamt="";
for(@keyIN)
{
if(/\n/){chop($_);}
$gesamt.=$_."=".$COUNT{$_}."\n";
}
open(COUNT,">counter.txt");
print COUNT $gesamt;
close(COUNT);

&statistik($link);

$url="http://$link";

print "Location:$url\n\n";


sub statistik{
local($name)=@_;

open(STAT,"count_statistik.txt");
@STAT=<STAT>;
close(STAT);
for(@STAT)
{
chop($_);
@teile=split(/=/,$_);
$STAT{$teile[0]}=$teile[1];
}
if($STAT{$name} eq "")
{
open(STAT,"count_statistik.txt");
@STAT=<STAT>;
close(STAT);
$count_statistik=@STAT;
$count_statistik++;

open(HTML0,">>count_statistik.txt");
print HTML0 "$name=$count_statistik\n";
close(HTML0);
$STAT{$name}=$count_statistik;
}

$pfad=$ENV{SCRIPT_FILENAME};
$pfad=substr($pfad,0,rindex($pfad,"/"));
$counter_statistik="$pfad/".$STAT{$name}.".txt";


@months = ('Januar','Februar','Maerz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');

@days = ('Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag');

      ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
      if ($sec < 10) { $sec = "0$sec"; }
      if ($min < 10) { $min = "0$min"; }
      if ($hour < 10) { $hour = "0$hour"; }
      if ($mday < 10) { $mday = "0$mday"; }
     	$woche = "$days[$wday]";$year+=1900;
	   $datum = "$mday. $months[$mon] $year";
  	$zeit = "$hour:$min";
#####################################################################

	$agent = "";
	$userURL = " ";
	$host = "";
	$ip = "";
	$arglist = "";
	if( defined($ENV{'HTTP_USER_AGENT'}) ) {
	    $agent = $ENV{'HTTP_USER_AGENT'};
		}
	if( defined($ENV{'HTTP_REFERER'}) ) {
	    $userURL = $ENV{'HTTP_REFERER'};
		$userURL = substr($userURL,0,index($userURL,"?"));
	}
	if( defined($ENV{'REMOTE_HOST'}) ) {
	    $host = $ENV{'REMOTE_HOST'};
	}
	if( defined($ENV{'REMOTE_ADDR'}) ) {
	    $ip = $ENV{'REMOTE_ADDR'};
	}
	if( defined($ENV{'QUERY_STRING'}) ) {
	    $arglist = $ENV{'QUERY_STRING'};
	}

	if(index($userURL,"netviper")== -1)
	{
   open(LOG, ">>$counter_statistik");
   print LOG "$name,$woche,$datum,$zeit,$agent,$userURL,$host,$ip,$arglist\n";
   close(LOG);
	#open(LOG, ">>LC_counter.txt");
   #print LOG "$counter_name,$woche,$datum,$zeit,$agent,$userURL,$host,$ip,$arglist\n";
   #close(LOG);
	}
#############################################

}

