#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
#############################################################
# Set program parameters here #
#############################################################
# List of IP addresses to ignore, add your own IP to the list
@ignore = ("127.0.0.1");
# Time (in minutes) to show the user as online after the last request
$limit_period = 60;
# Time (in minutes) to save the user's IP after the last request. The counter is only increased for unknown IPs.
$keep_in_log_time = 60;
# Set to 0 if your server's operating system doesn't implement flock() (for example Windows 95/98/ME)
$use_flock = 1;
# Directory of the counter templates (counter_xxx.html)
$templ_dir = ".";
# Directory of the counter data (log.txt and count.txt)
$data_dir = "Data";
#############################################################
# Program starts here #
# GTCounter 1.1 by Wladimir Palant ([URL unfurl="true"]http://www.gtchat.de/)[/URL] #
#############################################################
$LOCK_EX = 2;
$LOCK_UN = 8;
$current_time = time;
open(LOG, "+>>$data_dir/log_m.txt");
flock(LOG,$LOCK_EX) if ($use_flock);
seek(LOG,0,0);
@entries = <LOG>;
seek(LOG,0,0);
truncate(LOG,0);
$add=1;
$clicks_this_ip=1;
$ignore=0;
foreach (@ignore)
{
if ($ENV{REMOTE_ADDR} eq $_)
{
$add=0;
$online=0;
$ignore=1;
}
}
print LOG "$ENV{REMOTE_ADDR}|$current_time\n" if (!$ignore);
foreach $curentry (@entries)
{
# Steuercodes löschen
$curentry =~ s/[\n\r]//g;
($ip, $time) = split(/\|/, $curentry);
# Nur solche behalten, welche z.B. innerhalb einer Stunde sind
if ($current_time - $time <= $keep_in_log_time*60)
{
print LOG "$curentry\n";
}
if ($current_time - $time <= $limit_period*60 && $ip eq $ENV{REMOTE_ADDR})
{
$clicks_this_ip++;
}
}
flock(LOG,$LOCK_UN) if ($use_flock);
close(LOG);
if (!defined($no_output))
{
print "Content-type: text/html\n";
print "Pragma: no-cache\n";
print "Expires: now\n\n";
$ENV{QUERY_STRING} =~ s/\W//g;
if ($ENV{QUERY_STRING} eq "")
{
open(FILE,"$templ_dir/counter.html");
}
else
{
open(FILE,"$templ_dir/counter_$ENV{QUERY_STRING}.html");
}
foreach (<FILE>)
{
$_ =~ s/{ONLINE}/$clicks_this_ip/g;
$_ =~ s/{COUNT}/$count/g;
print "$_";
}
close(FILE);
exit;
}
1;