You can get a gnu ziped tar archive from here.
#!/usr/local/bin/perl
#
# xbmp_count_log.cgi
# -- Increment a counter and log the access for WWW --
#
# Written by Tadashi Kawaguchi <ojin@erehwon.org>
# Created on: Apr 03, 1996 Last Modified on: Dec 26, 1999
#
# Usage: <IMG SRC="xbmp_count_log.cgi"> or
# <IMG SRC="xbmp_count_log.cgi" WIDTH=1 HEIGHT=1>
# for loging only purpose
#
#################################################################
# Set file path
$counterfile = "/path/to/xbmp_count_log.txt";
$logfile = "/path/to/access.log";
$errfile = "/path/to/error.log";
## Permissions of these three files must be 666 or 606 ##
$badrefimg = "http://www.your.dom.ain/somedir/badreffer.gif";
# Set allowed hosts and/or URLs that can access this CGI
@allowhost = ('www.your.dom.ain', 'your.dom.ain/some.html', '123.456.789.01');
## Can be defined by domain name and/or IP num ##
# Set count on/off 1 = on, 0 = off
$cntonoff = 1;
# Set loging on/off 1 = on, 0 = off
$logonoff = 1;
# Set length of the counter digits
$countlength = 7;
# Set x-bmp image color 1 = white, 0 = black
$digit = 0;
#########################################################
# Set date & time
if ($logonoff == 1) {
@month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
$year = $year + 1900;
$date = "$hour\:$min\:$sec $mday/$month[$mon]/$year";
}
# Check host
if ($ENV{'HTTP_REFERER'}) {
foreach $i (0 .. $#allowhost)
{
if ($ENV{'HTTP_REFERER'} =~ /$allowhost[$i]/i) {
$goodhost = 1;
last;
}
}
}
else {
$goodhost = 1;
}
if ($goodhost != 1) {
print "Location: $badrefimg\n\n";
if ($logonoff == 1) {
open(LOG,">>$errfile") || die "Can't open error Log: $!\n";
flock(LOG,2);
print LOG "$!: $ENV{'REMOTE_HOST'} [$date] $ENV{'HTTP_REFERER'} - $ENV{'HTTP_USER_AGENT'}\n";
flock(LOG,8);
close(LOG);
}
exit 1;
}
# Log the access
if ($logonoff == 1) {
&log_access;
}
# Increment the counter
if ($cntonoff == 1) {
&xbmp_counter;
}
else {
print "Content-type: image/x-xbitmap\n\n";
print "#define xbm_width 8\n#define xbm_height 1\n";
print 'static char xbm_bits[] = {0x00};';
print "\n";
}
exit 0;
#########################################################
sub xbmp_counter {
# Set x-bmp for each digit
@white = (0xff,0xff,0xff,0xc3,0x99,0x99,0x99,0x99,
0x99,0x99,0x99,0x99,0xc3,0xff,0xff,0xff,
0xff,0xff,0xff,0xcf,0xc7,0xcf,0xcf,0xcf,
0xcf,0xcf,0xcf,0xcf,0xcf,0xff,0xff,0xff,
0xff,0xff,0xff,0xc3,0x99,0x9f,0x9f,0xcf,
0xe7,0xf3,0xf9,0xf9,0x81,0xff,0xff,0xff,
0xff,0xff,0xff,0xc3,0x99,0x9f,0x9f,0xc7,
0x9f,0x9f,0x9f,0x99,0xc3,0xff,0xff,0xff,
0xff,0xff,0xff,0xcf,0xcf,0xc7,0xc7,0xcb,
0xcb,0xcd,0x81,0xcf,0x87,0xff,0xff,0xff,
0xff,0xff,0xff,0x81,0xf9,0xf9,0xf9,0xc1,
0x9f,0x9f,0x9f,0x99,0xc3,0xff,0xff,0xff,
0xff,0xff,0xff,0xc7,0xf3,0xf9,0xf9,0xc1,
0x99,0x99,0x99,0x99,0xc3,0xff,0xff,0xff,
0xff,0xff,0xff,0x81,0x99,0x9f,0x9f,0xcf,
0xcf,0xe7,0xe7,0xf3,0xf3,0xff,0xff,0xff,
0xff,0xff,0xff,0xc3,0x99,0x99,0x99,0xc3,
0x99,0x99,0x99,0x99,0xc3,0xff,0xff,0xff,
0xff,0xff,0xff,0xc3,0x99,0x99,0x99,0x99,
0x83,0x9f,0x9f,0xcf,0xe3,0xff,0xff,0xff
);
@black = (0x00,0x00,0x00,0x3c,0x66,0x66,0x66,0x66,
0x66,0x66,0x66,0x66,0x3c,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x38,0x30,0x30,0x30,
0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,
0x00,0x00,0x00,0x3c,0x66,0x60,0x60,0x30,
0x18,0x0c,0x06,0x06,0x7e,0x00,0x00,0x00,
0x00,0x00,0x00,0x3c,0x66,0x60,0x60,0x38,
0x60,0x60,0x60,0x66,0x3c,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x30,0x38,0x38,0x34,
0x34,0x32,0x7e,0x30,0x78,0x00,0x00,0x00,
0x00,0x00,0x00,0x7e,0x06,0x06,0x06,0x3e,
0x60,0x60,0x60,0x66,0x3c,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x0c,0x06,0x06,0x3e,
0x66,0x66,0x66,0x66,0x3c,0x00,0x00,0x00,
0x00,0x00,0x00,0x7e,0x66,0x60,0x60,0x30,
0x30,0x18,0x18,0x0c,0x0c,0x00,0x00,0x00,
0x00,0x00,0x00,0x3c,0x66,0x66,0x66,0x3c,
0x66,0x66,0x66,0x66,0x3c,0x00,0x00,0x00,
0x00,0x00,0x00,0x3c,0x66,0x66,0x66,0x66,
0x7c,0x60,0x60,0x30,0x1c,0x00,0x00,0x00
);
# Increment the counter
$cntlockfile = "/tmp/${counterfile}.lock";
&f_lock ($counterfile, $cntlockfile, 6, 5);
if (open COUNTER, "+<$counterfile") {
chomp($num = <COUNTER>);
seek COUNTER, 0, 0;
$num++;
$len = length($num) > $countlength ? length($num) : $countlength;
printf COUNTER "%0${len}u\n", $num;
close COUNTER;
unlink $cntlockfile;
$num = sprintf("%0${len}u", $num);
} else {
unlink $cntlockfile;
die "Can\'t open $counterfile: $!\n";
}
# Generate x-bmp image
print "Content-type: image/x-xbitmap\n\n";
printf "#define xbm_width %d\n#define xbm_height 16\n", $len * 8;
print "static char count_bits[] = {\n";
for ($y=0; $y < 16; $y++) {
for ($x=0; $x < $len; $x++) {
$d = substr($num, $x ,1) - '0';
print '0x';
if ($digit == 1) {
printf "%1x",($white[($d * 16) + $y] >> 4) & 0xf;
printf "%1x",$white[($d * 16) + $y] & 0xf;
} else {
printf "%1x",($black[($d * 16) + $y] >> 4) & 0xf;
printf "%1x",$black[($d * 16) + $y] & 0xf;
}
if ($x < $len - 1) {
print ',';
}
}
if ($y == 15) {
print '};';
} else {
print ',';
}
print "\n";
}
}
#########################################################
sub log_access {
open(LOG,">>$logfile") || die "Can\'t open $logfile: $!\n";
flock(LOG,2);
print LOG "[$date] $ENV{'HTTP_REFERER'} - $ENV{'REMOTE_HOST'} - $ENV{'HTTP_USER_AGENT'}\n";
flock(LOG,8);
close(LOG);
}
#########################################################
sub f_lock {
local ($file, $lockfile, $retry, $wait) = @_;
while (!symlink($file, $lockfile)) {
if ( --$retry <= 0 ) {
die "Can\'t lock $file: $!\n";
}
sleep($wait);
}
}
You can get a gnu ziped tar archive from here.
#!/usr/local/bin/perl
#
# gif_count_log.pl
# -- Increment a counter and log the access for WWW --
#
# Written by Tadashi Kawaguchi <ojin@erehwon.org>
# Created on: Apr 3, 1996 Last Modified on: Dec 26, 1999
#
# Usage: <!--#exec cmd="gif_count_log.pl" -->
#
#################################################################
# Global variables -- change these to fit you environment.
$counterfile = "/path/to/count.txt"; # path to the counter text file
$logfile = "/path/to/access.log"; # path to the access log file
### the permission of these files must be 666 or 606 ####
$countlength = 7; # length of the counter digits
$gifdir = "/~foo/counter.gif"; # URL path to the gif files directory
$logonoff = 1; # 1 = loging on, 0 = off
# Set date & time
if ($logonoff == 1) {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
$year = $year + 1900;
$date = "$hour\:$min\:$sec $mon/$mday/$year";
}
# Read and increment the counter then return HTML tags
&count_access;
# Log the Counter Access
if ($logonoff == 1) {
&log_access;
}
exit 0;
################
sub count_access {
open(COUNT, "<$counterfile") || die "Can\'t open $counterfile: $!\n";
flock(COUNT, 2);
$num = <COUNT>;
close(COUNT);
$num++;
$len = length($num) > $countlength ? length($num) : $countlength;
open(COUNT, ">$counterfile") || die "Can\'t open $counterfile: $!\n";
flock(COUNT, 2);
printf COUNT "%0${len}u\n", $num;
$counttext = sprintf("%0${len}u\n", $num);
flock(COUNT, 8);
close(COUNT);
%gif = ('0',"0.gif",
'1',"1.gif",
'2',"2.gif",
'3',"3.gif",
'4',"4.gif",
'5',"5.gif",
'6',"6.gif",
'7',"7.gif",
'8',"8.gif",
'9',"9.gif");
$_ = $counttext;
while(s/^.//) {
print qq(<img src="$gifdir/$gif{$&}" alt="$&">);
}
}
################
sub log_access {
open(LOG,">>$logfile") || die "Can\'t open $logfile: $!\n";
flock(LOG,2);
print LOG "[$date] $ENV{'HTTP_REFERER'} - $ENV{'REMOTE_HOST'} - $ENV{'HTTP_USER_AGENT'}\n";
flock(LOG,8);
close(LOG);
}
You can get a gnu ziped tar archive from here.
#!/usr/local/bin/perl
#
#################################################################
# #
# Email gateway - Send Form Response via e-mail #
# #
# Written by Tadashi Kawaguchi <tk@kawaguchi.k-inet.com> #
# http://www.k-inet.com/ #
# http://www.erehwon.org/ #
# http://macware.erehwon.org/ #
# #
# Created on: Apr 01, 1996 Last Modified on: Jun 28, 1997 #
# #
#################################################################
#### Set static variables ####
# Email headers
$emailto = "youid\@foo.bar.com";
$emailfrom = "sender\@foo.bar.com";
$emailfromname = "Your Name";
$emailsubj = "Form Response";
# Sendmail program
$send_mail = "/usr/lib/sendmail -t";
# Server addresses and/or URLs
@allowhost = ('www.foo.bar.com', 'bar.foo.com/form.html', '123.456.789.01');
# ip num
# Set "0" when generate "Thanks" HTML
$usehtml = 1;
#### Get environment variables ####
$conttype = $ENV{'CONTENT_TYPE'};
$contlength = $ENV{'CONTENT_LENGTH'};
$pathinfo = $ENV{'PATH_INFO'};
$httpreferer = $ENV{'HTTP_REFERER'};
$browser = $ENV{'HTTP_USER_AGENT'};
#### Define Location of HTML files ####
# Document root
$docroot = "http://www.foo.bar.com/~foo";
# Form html
$formhtml = "$docroot/path/to/form.html";
# Thanks html
if ($usehtml == 1) {
if ($pathinfo) {
$thankshtml = "$docroot/$pathinfo";
} else {
$thankshtml = "$docroot/path/to/thanks.html";
}
}
###################################
# Check host
if ($httpreferer) {
foreach $i (0 .. $#allowhost) {
if ($httpreferer =~ /$allowhost[$i]/i) {
$goodhost = 1;
last;
}
}
}
else {
$goodhost = 1;
}
if ($goodhost != 1) {
print "Content-type: text/plain\n";
print "Status: 403 Forbidden\n\n";
print "$httpreferer is not allowed to access this cgi script.\n";
exit 1;
}
# Check content-type
if($conttype ne "application/x-www-form-urlencoded") {
print "Content-type: text/plain\n";
print "Status: 400 Bad Request\n\n";
print "Invalid content-type: $conttype\n";
exit 1;
}
# Put query string into a variable
read(STDIN, $qstring, $contlength);
# Split query string then put into an array
@qstring = split(/&/,$qstring);
foreach $i (0 .. $#qstring) {
# convert "+" to spaces
$qstring[$i] =~ s/\+/ /g;
# convert hex to ascii
$qstring[$i] =~ s/%(..)/pack("c",hex($1))/ge;
# split into name and value
($name, $value) = split(/=/,$qstring[$i],2);
# Remove server side includes
$value =~ s/<!--(.|\n)*-->//g;
# Check missing inputs
if ($value eq '' || $value eq /^\s+$/) {
$fname = $name; $fname =~ s/^[-0-9_]+//;
&errmsg ("Try again", "<b>$fname</b> field is empty.<br>");
exit 0;
}
# Check E-mail addrees
if ($name =~ /E-?mail/i && $value !~ /^[-\.\w]{2,}\@[-\w]+\.[-\.\w]{2,}$/) {
&errmsg ("Invalid email address", "<b>E-mail Address</b> is not valid.<br>");
exit 0;
}
# Put each element into an assosiative array
$qstring{$name} = $value;
}
#### Send Form information via e-mail ####
open(MAIL, "| $send_mail");
print(MAIL "From: $emailfromname <$emailfrom>\r\n");
print(MAIL "To: $emailto\r\n");
print(MAIL "Subject: $emailsubj\r\n\r\n");
print MAIL qq(
Remote Host: $ENV{"REMOTE_HOST"}
Remote Addr: $ENV{"REMOTE_ADDR"}
User Agent: $ENV{"HTTP_USER_AGENT"}
HTML Referred: $ENV{"HTTP_REFERER"}
Form Information:
);
foreach $name (sort keys(%qstring)) {
print MAIL "$name: $qstring{$name}\n";
}
close(MAIL);
#### Return "Thanks" html #####
if ($usehtml == 1) {
print "Location: $thankshtml\n\n";
}
else {
#### Generate "Thanks" html ####
# MIME header
print "Content-type: text/html\n\n";
# HTML code
print qq(
<html><head><title>Thank you</title></head>
<body bgcolor="#00ff00">
<center><h1>Thank you!</h1></center>
<p>The following information has been forwarded by email:
<p>
Host name: <tt>$ENV{"REMOTE_HOST"}</tt><br>
IP address: <tt>$ENV{"REMOTE_ADDR"}</tt><br>
Web browser: <tt>$ENV{"HTTP_USER_AGENT"}</tt><br>
HTML Referred: <tt>$ENV{"HTTP_REFERER"}</tt><br>
<p>
<B>Form Responses:</B>
<p>\n);
foreach $name (sort keys(%qstring)) {
print "$name: <tt>$qstring{$name}</tt><br>\n";
}
print "</html>\n";
}
exit 0;
#### Generate "Try again" html #####
sub errmsg
{
local ($title, $message) = @_;
print "Content-type: text/html\n\n";
print qq(<html>
<head><title>$title</title></head>
$message<br>
Please try again.<p>);
if ($browser =~ /Mozilla/)
{
print qq?<a href="javascript:history.back()">Back</a>?;
} else {
print qq(<a href="$formhtml">Back</a>);
}
print "</html>\n";
}
##-- ------------------------- Sample Form ------------------------- --##
<HTML>
<HEAD>
<TITLE>Email Gateway Form</TITLE>
</HEAD>
<BODY BGCOLOR="#00ff00">
<H3>Please fill in the below form then click "Send" button.</H3>
<FORM METHOD="post" ACTION="form-email.cgi/path/to/thanks.html">
Your name:<BR>
<INPUT TYPE="text" SIZE=50 NAME="01-Name">
<P>
E-mail Address:<BR>
<INPUT TYPE="text" SIZE=50 NAME="02-Email">
<P>
Street Address: <INPUT TYPE="text" SIZE=50 NAME="03-Address"><BR>
City: <INPUT TYPE="text" SIZE=40 NAME="04-City">
State: <INPUT TYPE="text" SIZE=10 NAME="05-State"><BR>
Zip/Postal: <INPUT TYPE="text" SIZE=10 NAME="06-Zip">
Country: <INPUT TYPE="text" SIZE=20 NAME="07-Country"><BR>
<P>
Age: <INPUT TYPE="text" SIZE=6 NAME="08-Age">
<P>
Comments:<BR>
<TEXTAREA NAME="09-Comments" ROWS=5 COLS=70 WRAP="hard"></TEXTAREA>
<P>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Clear">
</FORM>
</BODY>
</HTML>
You can get a gnu ziped archive files from here.
1) Uncompress and extract files in your home directory.
% cd
# if you get "counter.tar.gz"
% gunzip -c counter.tar | tar xf -
or
% gtar zxf counter.tar.gz
or
% gzip -d counter.tar.gz && tar xf counter.tar
# if you get "counter.tar.Z"
% zcat counter.tar.Z | tar xf -
or
% uncompress counter.tar.Z && tar xf counter.tar
2) If you don't have "fly", get it and place a binary into "count" directory
under the "counter" directory.
* You can get a source or a pre-compiled binary from:
http://www.unimelb.edu.au/fly/fly.html
* Binary for Sparc Solaris 2.5.1 is also available at:
ftp://ftp.erehwon.org/pub/unix/
3) Set the variables and file-path on "counter.cgi" and "html_log.cgi"
scripts to fit for your environment.
* If you find suitable lines, uncomment it.
4) Set DocumentRoot of your web to "WEB" variable on "setup-counter" script,
then type:
% sh ~/counter/setup-counter
* This sets proper permission to files and directories then move it
where they should be placed.
#!/bin/sh
#
# script to setup files and directories for the web counter
# written by Tadashi Kawaguchi <ojin@erehwon.org>
#
# usage: sh $HOME/counter/setup-counter
#
PATH=/bin:/usr/bin:/usr/local/bin:/opt/local/bin:/opt/gnu/bin
# Set your Document Root directory
# Uncomment one of the following lines if it's suitable
#WEB="$HOME/public_html"
#WEB="$HOME/htdocs"
#WEB="$HOME/www"
#WEB="$HOME/WWW"
if [ -z "$WEB" ]; then
for dir in public_html htdocs www WWW
do
if [ -d $HOME/$dir ]; then
WEB="$HOME/$dir"
fi
done
fi
if [ -z "$WEB" ]; then
CONF=`ps -ef | grep httpd | grep root | sed 's/^.*-f//'` || \
CONF=`ps aux | grep httpd | grep root | sed 's/^.*-f//'`
fi
if [ $? -ne 0 ]; then
echo "Can not find httpd.conf. Please define UserDir by yourself."
exit 1
elif ([ -n "$CONF" ] && [ -r $CONF ]); then
SRM=`echo "$CONF" | sed 's/httpd\.conf/srm\.conf/'`
WEB=`cat $CONF $SRM | grep '^UserDir' | awk '{print $2}'`
fi
if [ -z "$WEB" ]; then
echo "Can not find UserDir. Please define it by yourself."
exit 1
else
WEB="$HOME/$WEB"
fi
CGI_DIR="$WEB/cgi_bin"
IMG_DIR="$CGI_DIR/images"
COUNT_DIR="$HOME/count"
if [ ! -d $COUNT_DIR ]; then
mv $HOME/counter/count $HOME
chmod 701 $COUNT_DIR
chmod 606 $COUNT_DIR/*.log $COUNT_DIR/*.txt
else
echo "Can not move count directory."
exit 1
fi
if [ -s $COUNT_DIR/fly ]; then
chmod 701 $COUNT_DIR/fly
fi
if [ ! -d $CGI_DIR ]; then
mv $HOME/counter/cgi_bin $WEB
chmod 701 $CGI_DIR
chmod 705 $CGI_DIR/*.cgi
cd $IMG_DIR
chmod 604 *
chmod 701 . counter.gif
chmod 604 japanred/* smallgray/* smallwhite/* tinygray/* tinywhite/*
chmod 701 japanred smallgray smallwhite tinygray tinywhite
else
echo "Can not move cgi_bin directory."
exit 1
fi
# rm -r $HOME/counter
#!/usr/local/bin/perl
#
# Counter Script Version 1.1.1
# Created by Matt Wright mattw@misha.net
# Created on: 10/27/95 Last Modified on: 1/11/96
# Scripts Archive: http://www.worldwidemart.com/scripts/
#
# Consult the file README for more information and Installation Instructions.
#
# This script is provided "as is".
#
# Consult the file README for info on using other counter graphics
#
#######################################################################
# Modified and added image files for counter #
# by Tadashi Kawaguchi <ojin@erehwon.org> #
# Created on: May 18, 1996 Last Modified on: Dec 26, 1999 #
# http://www.erehwon.org/ #
#######################################################################
# There are several styles of counters.
# Choose your style counter by commenting out the others.
$digits = "smallgray";
# $digits = "smallwhite";
# $digits = "tinygray";
# $digits = "tinywhite";
# $digits = "japanred";
# $logname = "your_login_name";
# $home = "/path/to/your_home_directory"; # e.g. /home/your_login_name
$web_dir = "/path/to/document_root";
# $web_dir = "$home/public_html";
$cgi_dir = "$web_dir/cgi_bin";
$gif_dir = "$cgi_dir/images/counter.gif";
if ($digits =~ /japanred/) {
$digit_dir = "$gif_dir/japanred";
$width = "16";
$height = "24";
} elsif ($digits =~ /smallwhite/) {
$digit_dir = "$gif_dir/smallwhite";
$width = "11";
$height = "12";
} elsif ($digits =~ /smallgray/) {
$digit_dir = "$gif_dir/smallgray";
$width = "11";
$height = "12";
} elsif ($digits =~ /tinywhite/) {
$digit_dir = "$gif_dir/tinywhite";
$width = "8";
$height = "16";
} else {
$digit_dir = "$gif_dir/tinygray";
$width = "8";
$height = "16";
}
### FILE AND DIRECTORY LOCATIONS, REFERERS ###
$count_file = "/path/to/count.txt";
# $count_file = "$home/count/count.txt";
$access_log = "/path/to/access.log";
# $access_log = "$home/count/access.log";
$error_log = "/path/to/error.log";
# $error_log = "$home/count/error.log";
$flyprog = "/path/to/fly -q";
# $flyprog = "$home/count/fly -q";
$fly_temp = "/path/to/fly_temp.txt";
# $fly_temp = "$home/count/fly_temp.txt";
# $server = "$ENV{'SERVER_NAME'}";
$bad_referer_img = "http://www.foo.com/images/badreffer.gif";
# $bad_referer_img = "http://$server/cgi_bin/images/badreffer.gif";
# $bad_referer_img = "http://$server/~$logname/cgi_bin/images/badreffer.gif";
@referers = ("www.foo.com", "foo.com", "foo.com/xxx.html", "123.456.789.01");
# ip address
# @referers = ("$server", "$server/xxx.html");
# @referers = ("$server", "$server/~$logname/xxx.html");
### IMAGE SETTINGS ###
$tp = "0,0,0"; # black color to be transparent.
$il = "1"; # interlaced.
$frame_width = "0";
$frame_color = "0,0,0";
$dot = "X"; # Set "1" if you just want a transparent dot
$logo = "X"; # Can be "http://www.foo.com/images/logo.gif"
$countlength = 7; # Length of the counter digits
### OPTIONS ###
$uselog = "1"; # 1 = YES; 0 = NO
# Done
#######################################################################
# Get the Date For Logging Purposes
if ($uselog == 1) {
@month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
$year = $year + 1900;
$date = "$hour\:$min\:$sec $mday/$month[$mon]/$year";
}
# Make Sure People Aren't Messing With the Counter From Other Web Pages
&check_referer;
# If they Just want a transparent dot or a logo, give them that.
if ($dot ne "X" || $logo ne "X") {
&check_dot;
# Log The Access
if ($uselog == 1) {
&log_access;
}
exit 0;
}
# Get the Counter Number And Write New One to File
&get_num;
# Determine Length of Counter Number
$num = $length = length($count);
# Set Individual Counter Numbers Into Associative Array
while ($num > 0) {
$CHAR{$num} = chop($count);
$num--;
}
# Determine the Height and Width of the Image
$img_width = (($width * $length) + ($frame_width * 2));
$img_height = (($frame_width * 2) + $height);
# Open the In-File for Commands
open(FLY,">$fly_temp") || die "Can\'t Open In File For FLY Commands: $!\n";
flock(FLY,2);
# Create New Counter Image
print FLY "new\n";
print FLY "size $img_width,$img_height\n";
# If User Wants Frame, Print Commands to the In-File
&make_frame;
# Copy Individual Counter Images Commands to In-File
$j = 1;
while ($j <= $length) {
print FLY "copy $insert_width,$insert_height,-1,-1,-1,-1,$digit_dir/$CHAR{$j}\.gif\n";
$insert_width = ($insert_width + $width);
$j++;
}
# If they want a color transparent, make it transparent
if ($tp ne "X" && $tp =~ /.*,.*,.*/) {
print FLY "transparent $tp\n";
}
# If they want the image interlaced, make it interlaced
if ($il == 1) {
print FLY "interlace\n";
}
# Close FLY
flock(FLY,8);
close(FLY);
$output = `$flyprog -i $fly_temp`;
print "Content-type: image/gif\n\n";
print "$output";
# Log the Counter Access
if ($uselog == 1) {
&log_access;
}
exit 0;
################
sub check_referer {
if (@referers && $ENV{'HTTP_REFERER'}) {
foreach $referer (@referers) {
if ($ENV{'HTTP_REFERER'} =~ /$referer/) {
$ref = 1;
last;
}
}
}
else {
$ref = 1;
}
if ($ref != 1) {
print "Location: $bad_referer_img\n\n";
if ($uselog == 1) {
open(LOG,">>$error_log") || die "Can\'t open error log: $!\n";
flock(LOG,2);
print LOG "$0 - bad referered: ", $ENV{'REMOTE_HOST'}, " [$date] ",
$ENV{'HTTP_REFERER'}, " - ", $ENV{'HTTP_USER_AGENT'}, "\n";
flock(LOG,8);
close(LOG);
}
exit 1;
}
}
sub get_num {
open(COUNT,"$count_file") || die "Can\'t Open Count Data File: $!\n";
flock(COUNT,2);
$counttext = <COUNT>;
flock(COUNT,8);
close(COUNT);
if ($counttext =~ /\n$/) {
chop($counttext);
}
$counttext++;
$len = length($counttext) > $countlength ? length($counttext) : $countlength;
open(COUNT,">$count_file") || die "Can\'t Open Count Data File For Writing: $!\n";
flock(COUNT,2);
printf COUNT "%0${len}u",$counttext;
$count = sprintf("%0${len}u",$counttext);
flock(COUNT,8);
close(COUNT);
}
sub check_dot {
if ($dot == 1) {
# Open the In-File for Commands
open(FLY,">$fly_temp") || die "Can\'t Open In File For FLY Commands: $!\n";
flock(FLY,2);
# Create New Counter Image
print FLY "new\n";
print FLY "size 1,1\n";
print FLY "fill x,y,0,0,0\n";
print FLY "transparent 0,0,0\n";
flock(FLY,8);
close(FLY);
$output = `$flyprog -i $fly_temp`;
print "Content-type: image/gif\n\n";
print "$output";
}
elsif ($logo =~ /.*tp:\/\//) {
print "Location: $logo\n\n";
}
}
sub make_frame {
$insert_width = $insert_height = $frame_width;
$insert_frame = 0;
while ($insert_frame < $frame_width) {
$current_width = ($img_width - $insert_frame);
$current_height = ($img_height - $insert_frame);
print FLY "line 0,$insert_frame,$img_width,$insert_frame,$frame_color\n";
print FLY "line $insert_frame,0,$insert_frame,$img_height,$frame_color\n";
print FLY "line $current_width,0,$current_width,$img_height,$frame_color\n";
print FLY "line $current_height,0,$current_height,$img_width,$frame_color\n";
$insert_frame++;
}
}
sub log_access {
open(LOG,">>$access_log") || die "Can\'t Open User Access Log: $!\n";
flock(LOG,2);
print LOG "[$date] $ENV{'HTTP_REFERER'} - $ENV{'REMOTE_HOST'} - $ENV{'HTTP_USER_AGENT'}\n";
flock(LOG,8);
close(LOG);
}
#!/usr/local/bin/perl
#
# Access Stat HTML Generator
# Used in conjunction with Counter Script
# Created by Matt Wright mattw@misha.net
# Created on: 10/25/95 Last Modified on: 10/26/95
#
# Version 1.0
#
###################################################################
# #
# Modified and added the bar chart display routine #
# by Tadashi Kawaguchi <ojin@erehwon.org> #
# Created on: Created on: May 18, 1996 #
# Last Modified on: Dec 26, 1999 #
# http://www.erehwon.org/ #
# #
###################################################################
# Define Variables
# $logname = "your_login_name";
# $home = "/path/to/your_home_directory"; # e.g. /home/your_login_name
$log_file = "/path/to/access.log";
# $log_file = "$home/count/access.log";
$cgi_dir = "/cgi_bin";
# $cgi_dir = "/~$logname/cgi_bin";
# $server = "$ENV{'SERVER_NAME'}";
@allowurl = ("www.foo.com", "foo.com", "foo.com/xxx.html", "123.456.789.01");
# ip address
# @allowurl = ("$server", "$server/xxx.html");
# @allowurl = ("$server", "$server/~$logname/xxx.html");
$mkhtmlfile = "0"; # Set "0" if print out to STDOUT
# Set "1" if print out to a html file
$min_refs = "5"; # Set the minimum number to make list
$min_remote = "5";
$min_agent = "5";
$min_domain = "5";
$x_refs = "10"; # Set the ratio of pixels to number
$x_remote = "30";
$x_agent = "10";
$x_domain = "5";
$x_hour = "40";
$x_day = "0.5";
$title = "www.foo.com";
$title_url = "http://www.foo.com/";
$home_url = "$title_url/index.html";
$webmaster = "Your Name";
$mailto = "webmaster\@foo.com"; # Your e-mail address
# Done
###################################################################
###################################################################
# Select Options
$expand_agent = 1; # 0 = NO; 1 = YES
# Done
###################################################################
###################################################################
# Images for bar chart
$h_grf_img_1 = "$cgi_dir/images/h_silver.gif";
$h_grf_img_2 = "$cgi_dir/images/h_greenP.jpg";
$h_grf_img_3 = "$cgi_dir/images/h_violetP.jpg";
$h_grf_img_4 = "$cgi_dir/images/h_purpleP.jpg";
$h_grf_img_5 = "$cgi_dir/images/h_purgray.gif";
$h_grf_img_6 = "$cgi_dir/images/h_red.gif";
#################################################################
######## Check host ########
if ($mkhtmlfile == 0)
{
if ($ENV{'HTTP_REFERER'}) {
foreach $i (0 .. $#allowurl) {
if ($ENV{'HTTP_REFERER'} =~ /$allowurl[$i]/i) {
$goodhost = '1';
last;
}
}
} else {
$goodhost = '1';
}
if ($goodhost != '1') {
print "Content-type: text/html\n";
print "Status: 403 Forbidden\n\n";
print qq(<html>
<head>
<title>Forbidden</title>
</head>
<h2>Forbidden</h2><br>
$ENV{'HTTP_REFERER'} is not allowed to access this cgi script.
<a href="mailto:$mailto">$webmaster <$mailto></a>
</body>
</html>\n);
exit 1;
}
}
#### Get current localtime ####
@month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($hour < 10) { $hour = "0$hour"; }
if ($mday < 10) { $mday = "0$mday"; }
$year = $year + 1900;
$date_now = "$hour\:$min\:$sec $mday/$month[$mon]/$year";
#### Read data from the log file ####
open(DB,"$log_file") || die "Cannot Open Log File $log_file: $!";
@lines = <DB>;
close(DB);
$accesses = @lines;
# Skip broken lines
foreach $n (0 .. 15) {
$first_date = substr($lines[$n], 1, 20);
if ($first_date =~ m!\d{2}/[A-Z][a-z]{2}/\d{4}$!) {
last;
} else {
$first_date = "";
}
}
foreach $n (0 .. 15) {
$last_date = substr($lines[($#lines - $n)], 1, 20);
if ($last_date =~ m!\d{2}/[A-Z][a-z]{2}/\d{4}$!) {
last;
} else {
$last_date = "";
}
}
#### Split each element then put it into assosiative array ####
foreach $line (@lines) {
if ($line =~ /\[(.*)\] (.*) - (.*) - (.*)/) {
$date = $1;
($clock,$day) = split(/ /,$date);
($hour,$minute,$second) = split(/:/,$clock);
($dd,$mm,$yy) = split('/',$day);
if ($mm eq 'Jan') { $mm = '01'; }
if ($mm eq 'Feb') { $mm = '02'; }
if ($mm eq 'Mar') { $mm = '03'; }
if ($mm eq 'Apr') { $mm = '04'; }
if ($mm eq 'May') { $mm = '05'; }
if ($mm eq 'Jun') { $mm = '06'; }
if ($mm eq 'Jul') { $mm = '07'; }
if ($mm eq 'Aug') { $mm = '08'; }
if ($mm eq 'Sep') { $mm = '09'; }
if ($mm eq 'Oct') { $mm = '10'; }
if ($mm eq 'Nov') { $mm = '11'; }
if ($mm eq 'Dec') { $mm = '12'; }
$day = "$yy/$mm/$dd";
$referer = $2;
$remote_host = $3;
$remote_domain = $3;
$user_agent = $4;
$referer = "index.html" if ($referer eq $title_url);
$referer =~ s/$title_url//;
$referer =~ s/\%24/\$/g;
$referer =~ s/\%7E/~/g;
$referer =~ s/\#.*$//;
$referer =~ s/^\.\///;
$remote_domain =~ s/.*\.//g;
$remote_domain = "ip num" if ($remote_domain =~ /[0-9].*/);
$remote_domain =~ tr/[A-Z]/[a-z]/;
$user_agent =~ s/\s\s?via.*$//;
if ($day ne '' && $day ne ' ') {
push(@DAYS, $day);
}
if ($hour ne '' && $hour ne ' ') {
push(@HOURS, $hour);
}
if ($referer ne 'No Referer' && $referer ne ' ' && $referer ne '') {
push(@REFERER, $referer);
}
if ($remote_host ne 'No Remote_Host' && $remote_host ne ' ' && $remote_host ne '') {
push(@REMOTE_HOST, $remote_host);
}
if ($user_agent ne 'No User_Agent' && $user_agent ne ' ' && $user_agent ne '') {
push(@USER_AGENT, $user_agent);
}
if ($remote_domain ne '' && $remote_domain ne ' ') {
push(@DOMAIN, $remote_domain);
}
}
}
foreach (@REFERER) {
$refs{($_)[0]}++;
$i++;
}
foreach (@REMOTE_HOST) {
$remote{($_)[0]}++;
$j++;
}
foreach (@USER_AGENT) {
if ($expand_agent == 1) {
$agent{($_)[0]}++;
}
else {
$agent{(split('/',$_))[0]}++;
}
$k++;
}
foreach (@DAYS) {
$day{($_)[0]}++;
}
foreach (@HOURS) {
$hour{($_)[0]}++;
$l++;
}
foreach (@DOMAIN) {
$domain{($_)[0]}++;
$m++;
}
######## Print HTML ########
if ($mkhtmlfile == 0) {
print "Content-type: text/html\n\n";
}
&html_header;
&html_referer;
&html_remote_host;
&html_remote_domain;
&html_user_agent;
&hours;
&days;
&html_trailer;
exit 0;
#################################################################
################
sub html_header
{
print qq(<html>
<head>
<META HTTP-EQUIV="Content-Typpe" CONTENT="text/html\; charset=iso-8859-1">
<title>Access Stats for $title</title>
</head>
<body bgcolor=#f4fcff text=#000000 link=#0000ff vlink=#009148 alink=ff0000>
<center><h1><font color=#0558FF face="Times">
Access Stats for $title
</h1></font></center>
<center>
Below are the access stats for <a href="$home_url">$title.</a><p>
"A total of $accesses were reviewed for this logging, which occurred at: $date_now<p>
);
unless (($first_date eq "") || ($last_date eq "")) {
print "These statistics reflect accesses from: <i>$first_date</i> to <i>$last_date</i><p>\n";
}
print qq(</center>
<p><hr size=3 width=75%>
<font size=-1><center>
[ <a href="#refs">Referring Pages</a> ] [ <a href="#remote_host">Remote Hosts</a> ]
[ <a href="#remote_domain">Remote Domain</a> ] [ <a href="#browsers">Browsers</a> ]
[ <a href="#hours">Hits by Hour</a> ] [ <a href="#days">Hits by Day</a> ]
</center></font>
<hr size=3 width=75%><p>
<br>);
}
################
sub html_referer
{
print qq(
<center><h2><a name="refs">Referring Pages</a></h2></center>
<b>Referring URLs Searched:</b> <i><u>$i</u></i><br>
<b>Minimum References Required to Make List:</b> <i><u>$min_refs</u></i><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number</th>
<th bgcolor=#30f2ff>Percent</th>
<th bgcolor=#30f2ff>Referring Web Sites</th>
<th bgcolor=#30f2ff></th>
</tr>);
foreach (sort { $refs{$b} <=> $refs{$a} } keys %refs)
{
if ($refs{$_} >= $min_refs)
{
print "<tr>\n";
$total_refs += $refs{$_};
$percent_refs = (int(10000 * ($refs{$_} / $i)) / 100);
$pixel_refs = int($x_refs * $percent_refs);
if ($pixel_refs == 0) {
$pixel_refs = 1;
}
$total_percent_refs += $percent_refs;
$percent_refs = sprintf("%3.1f%%", $percent_refs);
$ref_url = $_;
$ref_url = "$title_url$ref_url" unless ($ref_url =~ /^http.*/);
print "<th align=right>$refs{$_} </th>\n";
print "<td align=right>$percent_refs </td><td><a href=\"$ref_url\">$_</a></td>\n";
print "<td><img src=\"$h_grf_img_2\" width=$pixel_refs height=15 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_refs = sprintf("%3.1f%%", $total_percent_refs);
print qq(<tr>
<th align=right><br>$total_refs </th>
<td align=right><br>$total_percent_refs </td>
<td align=center><br>\*\* Totals For URLS Shown \*\*</td><td></td>
</tr>
</table>
</font>
<p><hr size=7 width=75%>
<br>);
}
################
sub html_remote_host
{
print qq(
<center><h2><a name=\"remote_host\">Remote Hosts</a></h2></center>
<b>Remote Hosts Searched:</b> <u><i>$j</i></u><br>
<b>Minimum Hits Required to Make List:</b> <i><u>$min_remote</u></i><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number</th>
<th bgcolor=#30f2ff>Percent</th><th bgcolor=#30f2ff>Remote Hosts<br></th>
<th></th>
</tr>);
foreach (sort { $remote{$b} <=> $remote{$a} } keys %remote)
{
if ($remote{$_} >= $min_remote)
{
print "<tr>\n";
$total_remote += $remote{$_};
$percent_remote = (int(10000 * ($remote{$_} / $j)) / 100);
$pixel_remote = int($x_remote * $percent_remote);
if ($pixel_remote == 0) {
$pixel_remote = 1;
}
$total_percent_remote += $percent_remote;
$percent_remote = sprintf("%3.1f%%", $percent_remote);
print "<th align=right>$remote{$_} </th>\n";
print "<td align=right>$percent_remote </td><td>$_</td>\n";
print "<td><img src=\"$h_grf_img_3\" width=$pixel_remote height=15 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_remote = sprintf("%3.1f%%", $total_percent_remote);
print qq(<tr>
<th align=right><br>$total_remote </th>
<td align=right><br>$total_percent_remote </td>
<td align=center><br>\*\* Totals For Remote Hosts Shown \*\*</td>
<td></td>
</tr>
</table>
</font>
<P><hr size=7 width=75%>
<br>);
}
################
sub html_remote_domain
{
print qq(
<center><h2><a name="remote_domain">Remote Domain</a></h2></center>
<b>Remote Domain Searched:</b> <u><i>$m</i></u><br>
<b>Minimum Hits Required to Make List:</b> <i><u>$min_domain</u></i><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number</th>
<th bgcolor=#30f2ff>Percent</th>
<th bgcolor=#30f2ff>Domain</th><th></th>
</tr>);
foreach (sort { $domain{$b} <=> $domain{$a} } keys %domain)
{
if ($domain{$_} >= $min_domain)
{
print "<tr>\n";
$total_domain += $domain{$_};
$percent_domain = (int(10000 * ($domain{$_} / $m)) / 100);
$pixel_domain = int($x_domain * $percent_domain);
if ($pixel_domain == 0) {
$pixel_domain = 1;
}
$total_percent_domain += $percent_domain;
$percent_domain = sprintf("%3.1f%%", $percent_domain);
print "<th align=right>$domain{$_} </th>\n";
print "<td align=right>$percent_domain </td><td>$_</td>\n";
print "<td><img src=\"$h_grf_img_6\" width=$pixel_domain height=15 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_domain = sprintf("%3.1f%%", $total_percent_domain);
print qq(<tr>
<th align=right><br>$total_domain </th>
<td align=right><br>$total_percent_domain </td>
<td align=center><br>\*\* Totals For Remote Domain Shown \*\*</td>
<td></td>
</tr>
</table>
</font>
<P><hr size=7 width=75%>
<br>);
}
################
sub html_user_agent
{
print qq(
<a name="browsers"><center><h2>WWW Browsers</h2></center></a>
<b>Browsers Searched:</b> <u><i>$k</i></u><br>
<b>Minimum Hits Required to Make List:</b> <u><i>$min_agent</i></u><p>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Number</th>
<th bgcolor=#30f2ff>Percent</th>
<th bgcolor=#30f2ff>Browser</th>
<th></th>
</tr>);
foreach (sort { $agent{$b} <=> $agent{$a} } keys %agent)
{
if ($agent{$_} >= $min_agent)
{
print "<tr>\n";
$total_agent += $agent{$_};
$percent_agent = (int(10000 * ($agent{$_} / $k)) / 100);
$pixel_agent = int($x_agent * $percent_agent);
if ($pixel_agent == 0) {
$pixel_agent = 1;
}
$total_percent_agent += $percent_agent;
$percent_agent = sprintf("%3.1f%%", $percent_agent);
print "<th align=right>$agent{$_} </th>\n";
print "<td align=right>$percent_agent </td><td>$_</td>\n";
print "<td><img src=\"$h_grf_img_4\" width=$pixel_agent height=15 border=0></td>\n";
print "</tr>\n";
}
}
$total_percent_agent = sprintf("%3.1f%%", $total_percent_agent);
print qq(<tr>
<th align=right><br>$total_agent </th>
<td align=right><br>$total_percent_agent </td>
<td align=center><br>\*\* Totals For WWW Browsers Shown \*\*</td>
<td></td>
</tr>
</table>
</font>
<P><hr size=7 width=75%>
<br>);
}
################
sub hours
{
print qq(
<a name="hours"><center><h2>Hits By Hour</h2></center></a>
<font size=-2>
<table border width=100%>
<tr>
<th bgcolor=#30f2ff>Hour</th>
<th bgcolor=#30f2ff>Number</th>
<th bgcolor=#30f2ff>Percent</th><th></th>
</tr>);
foreach (sort keys %hour)
{
$percent_hour = (int(10000 * ($hour{$_} / $l)) / 100);
$pixel_hour = int($x_hour * $percent_hour);
if ($pixel_hour == 0) {
$pixel_hour = 1;
}
$percent_hour = sprintf("%3.1f%%", $percent_hour);
print "<tr>\n";
print "<th>$_ </th><td align=right>$hour{$_} </td><td align=right>$percent_hour </td>\n";
print "<td><img src=\"$h_grf_img_5\" width=$pixel_hour height=15 border=0></td>\n";
print "</tr>\n";
}
print "</table></font><p><hr size=7 width=75%><br>\n";
}
################
sub days
{
print qq(
<a name="days"><center><h2>Hits By Day</h2></center></a>
<font size=-2>
<table border width=100%>
<tr><th bgcolor=#30f2ff>Day</th><th bgcolor=#30f2ff>Number<th></th>
</tr>);
foreach (sort keys %day)
{
$pixel_day = int($x_day * $day{$_});
if ($pixel_day == 0) {
$pixel_day = 1;
}
print "<tr>\n";
print "<th>$_</th><td align=right>$day{$_}</td>\n";
print "<td><img src=\"$h_grf_img_1\" width=$pixel_day height=10 border=0></td>\n";
print "</tr>\n";
}
print "</table></font><p><br>\n";
}
################
sub html_trailer
{
print qq(
<p><hr size=3 width=75%>
<font size=-1><center>
[ <a href="#refs">Referring Pages</a> ] [ <a href="#remote_host">Remote Hosts</a> ]
[ <a href="#remote_domain">Remote Domain</a> ] [ <a href="#browsers">Browsers</a> ]
[ <a href="#hours">Hits by Hour</a> ] [ <a href="#days">Hits by Day</a> ]
</center></font>
<hr size=3 width=75%><p>
<hr size=5 width=100%>
<center>
<table border=0 width=90%>
<tr>
<td align=left><font size=3 face="Times"><a href="$homeurl">Back to Home</a></font></td>
<td align=right><font size=3 face="Times"><a href="mailto:$mailto">$webmaster <$mailto></a></font></td>
</tr>
</table>
</center>
</body>
</html>
\n);
}
![]() |
Back to Home | ©1995-2000 Erehwon.org, All Rights Reserved. |