#!/usr/bin/perl
#
# Original code is from steve@vigra.com, particularly the flock commands.
#
# Heavily modified by Eric Klien
#
$LOCK_SH = 1;# Shared
$LOCK_EX = 2;# Exclusive
$LOCK_NB = 4;# Don't block when locking
$LOCK_UN = 8;# Unlock
$count_file=".count";
$source="index.shtml";
print "Content-type: text/html\n\n";
open (IN, "<$source") ||
die "Error retrieving homepage source file!";
if (!open (COUNT, "+< $count_file"))
{print "
No count file?
"; open (COUNT, "> $count_file");}
flock (COUNT, $LOCK_EX);
$count = ;
$count++;
seek (COUNT, 0, 0); # Rewind
print COUNT "$count\n"; # Overwrite
flock (COUNT, $LOCK_UN);
close (COUNT);
$count = &formatnum ($count,"d");
while ($string=) {$string =~ s/\#COUNT/$count/; print $string;}
## Below code adds AXS call to this script.
# AXS Script Set, Logging Module, Version 2.02I Beta
# Copyright 1997, 1998 by Fluid Dynamics. Please adhere to
# the copyright notice and conditions of use which are described
# in the attached help file and hosted at the URL below.
#
# For latest version and help files, visit:
# http://www.xav.com/scripts/axs/
# __________________________________________________________________
# The location of your log file relative to this script. This is path
# and file name, not a web address. Leave this as is for a default
# install.
$LogFile = '/home/sites/www.mencik.com/web/cgi-local/axs/log.txt';
# Set this to 0 to forbid debugging, 1 to allow it. Leave this as is if
# you're installing for the first time.
$AllowDebug = 0;
# The following are examples of Perl debugger errors that come up when
# this script is transferred in binary format. If you get an error
# that looks like this (or a web error regarding "Internal Server Error"),
# then binary/ascii conflicts are probably the problem. Delete the script, and
# re-upload it in ascii format. Then give executable permissions
# (chmod 755 ax.pl) again, and you should be fine. This comes up on
# Unix web servers, not Windows NT ones.
#
# [mu]/usr/www/users/xav/beta> perl -w ax.pl
# EOF in string at ax.pl line 166.
#
# [mu]/usr/www/users/xav/beta> perl5 -w ax.pl
# Illegal character \015 (carriage return) at ax.pl line 2.
# (Maybe you didn't strip carriage returns after a network transfer?)
# __________________________________________________________________
#
# The following shouldn't need to be changed:
$domain = 'http://mencik.com';
# If your webserver doesn't support SERVER_NAME, then set this variable
# as the top-level URL to your server without a trailing slash, e.g.:
# $domain = 'http://www.xav.com';
#$header = "Content-type: text/html\n\n";
# This should be deleted if the content-type header is being echoed out
# to your SSI output, otherwise leave as is.
$Version = '2.02I Beta';
$TimeOffsetInHours = -1;
# The above variable allows you to correct for a different time zone if
# your ISP is somewhere else. This is an integer of +/- a certain number
# of hours. i.e., ISP is in Pennsylvania and owner is in Seattle:
# $TimeOffsetInHours = -3;
# ISP in Australia, owner in London:
# $TimeOffsetInHours = +12;
#
# __________________________________________________________________
$IIS = 1 if ($ENV{'SERVER_SOFTWARE'} =~ m!iis!i);
# These conditionals return output to the browser, and determine which
# URLs go in the $From and $To variables:
$To = $domain."/index.cgi";
$From = $ENV{'HTTP_REFERER'};
#print "$header\n \n";
# [optional:] this was used a few builds back, but doesn't seem necessary with new
# cache-control headers. It should be un-commented if you see a lot of double
# requests for files from the same people at about the same time:
#exit if ($ENV{'REQUEST_METHOD'} =~ m!HEAD!i);
# This code converts un-resolved hostnames to their text versions:
if ($ENV{'REMOTE_HOST'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) {
$Address = pack('C4',$1,$2,$3,$4);
if ($Address = (gethostbyaddr($Address,2))[0]) {
$ENV{'REMOTE_HOST'} = $Address;
}
}
$ENV{'REMOTE_HOST'} =~ tr[A-Z][a-z];
$logline = '|';
for ($ENV{'REMOTE_HOST'},$ENV{'REMOTE_ADDR'},$From,$To,$ENV{'HTTP_USER_AGENT'}) {
s/\||\r|\n//g;
$logline .= $_.'|';
}
foreach ((localtime(time + (3600*$TimeOffsetInHours)))[0..7]) {
$logline .= $_.'|';
}
$logline .= 'export|' if ($Export);
$logline .= "\n";
chdir($1) if (($IIS) && ($0 =~ m!(.*)(\\|\/)!));
if (open(LOG,">>$LogFile")) {
print LOG $logline;
close(LOG);
}
else {print "Log File Open Error\n\n";}
exit;
# Format a number - precision, prefix and commas
# $var = &formatnum(number,format,prefix)
# &formatnum(12345,"d") - 12,345
# &formatnum(12345.678,".2f",$) - $12,345.68
sub formatnum {
local($_,$fmt,$prefix) = @_;
$_ = sprintf("$prefix%$fmt",$_);
@parts = split(/\./,$_);
1 while $parts[0] =~ s/(.*\d)(\d{3})/$1,$2/;
join(".",@parts);
}