Lowest Rates
|
![]() |
long distance
| ...and other Worldwide Telecommunications Services -- Full details via that link; or use this Rate Search Engine to compare carriers and select the best one based on your phone usage. |
Yours is the
#!/usr/bin/perl
use lib '/web/cgi';
#use GD;
# cgi-bin access counter program
# Version 4.0.7
#
# Copyright (C) 1995 George Burgyan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# A full copy of the GNU General Public License can be retrieved from
# http://www.webtools.org/counter/copying.html
#
# gburgyan@webtools.org
#
# George Burgyan
# 1380 Dill Road
# South Euclid, OH 44121
#
# For more information look at http://www.webtools.org/counter/
########################################################################
#
# CHANGE THESE TO SUIT YOUR SITE
#
# The default language option (english, french, swedish)
$default_lang = "english";
# The name of the file to use. You should probably give this an absolute path
$FileName = "../counters/access_count";
#
# Replace with a list of regular expression IP addresses that we
# are supposed to ignore. If you don't know what this means, just use
# "\." instead of periods. Comment out entirely to ignore nothing.
#@IgnoreIP = ("199\.18\.203\..*",
# "199\.18\.159\.1",
# );
# Aliases: Set this up so that diffent pages will all yield the same
# count. For instance, if you have a link like "index.html -> home.html"
# set it up like ("/index.html", "/home.html"). Make sure you give a full
# path to it. This will treat "/index.html" as if it were "/home.html".
%Aliases = ("/netscout.html","/scout/netscout.html",
"/nowscout.html","/scout/nowscout.html",
"/millenscout.html","/scout/millenscout.html",
"/wisdom.html","/scout/wisdom.html",
"/applied.html","/scout/applied.html",
"/orsa.html","/scout/orsa.html");
# AUTOMATICALLY SET BY INSTALL!! Modify only if necessary!!!
#
# BaseName: set to whatever you have counter installed as. This is
# used to derive the arguments. No not touch the next comment.
### AUTOMAGIC ###
$BaseName = "counter4";
# counter or counterbanner or counterfiglet
#
# Outputs the number of times a specific page has been accessed.
# The output depends on which page 'called' it, and what the program
# is named:
#
# The counter can "take arguments" via its name. That is, if you tack
# -arg to the end of the program name, -arg is taken to be an argument.
# For example, if you call the counter 'counter-ord', '-ord' is considered
# an argument, and an ordinal count (1st, 2nd, 3rd, ...) will be printed
# instead of (1, 2, 3, ...). Note that counterord does the same thing as
# counter-ord for backward compatibility.
#
# Currently recognized arguments:
#
# -f=font sets "font" to be the font for figlet
# -lang=lang sets the language used to ordinalize to "lang"
# -nc no count; don't to write the incremented count back to the file
# -nl no link; don't automatically generate a link
# -nd no display; don't display anything, just count
# -ord make an ordinal count instead of regular
# -doc=document override the DOCUMENT_URI environment variable
#
# Example: counterfiglet-ord-f=bigfont-nc
#
# This will cause the counter to call figlet as the output routine, printing
# in a big font an ordinal count, without updating the access count file.
# Note that the order of arguments is irrelevant so long as you spell the
# file name correctly. It is generally assumed that the ability to take
# different arguments/use different output routines is done with symlinks:
# i.e. ln -s counter counterfiglet-ord-f=bigfont-nc
#
# More complete documentation can be found at
# http://www.webtools.org/counter/
#
########################################################################
#
# Thing that shouldn't really need changing, but are configurable anyway.
#
# Maximum number of times to try to lock the file.
# Each try is .1 second. Try for 1 second.
$MaxTries = 10;
# Set this to point to something, or comment it out, and it
# won't be a link at all.
#$Link = "http://www.webtools.org/counter/";
# Whether or not to use locking. If perl complains that flock is not
# defined, change this to 0. Not *really* necessary because we check
# to make sure it works properly.
$UseLocking = 0;
# What version of the counter file format are we using?
$FileVersion = "02.000";
# Common names of the counter to install...
@CommonExtensions = ("-ord", # Ordinam
"figlet", # Figlet'ed
"figlet-ord",# Ordinal figlet
"banner", # Bannered
"banner-ord",# Ordinal banner
);
#
#########################################################################
#
# Misc documents to refer people to in case of errors.
#
$CreateFile = "[Error Creating Counter File -- Click for more info]";
$AccessRights = "[Error Opening Counter File -- Click for more info]";
$TimeoutLock = "[Timeout locking counter file]";
$BadVersion = "[Version access_count newer than this program. Please upgrade.]";
#########################################################################
#
# The actual program!
### Stage 1
###
### Parse the arguments... (just ignore this part)
# Get arguments from program name. Argh...what a horrible way to do it!
$prog = $0;
$prog =~ s/(\.cgi|\.pl)//; #strip .cgi|.pl name extension
$prog =~ s!^(.*/)!!; # separate program name
$prog =~ s/\\(.)/sprintf("%%%02x", ord($1))/ge; # quote \c to %xx
($printer, @args) = split(/-/, $prog); # args are separated by dashes
$printer =~ s/%(..)/pack("c", hex($1))/ge; # unquote printer function name
$printer =~ s/$BaseName/counter4/; # Make it cannonical.
# This gets path info, which is only applicable if you are using our
# ssis script (see above). This makes counter/ord the same as counter-ord
push(@args, split("/", $ENV{"PATH_INFO"})) if $ENV{"PATH_INFO"};
# put them in assoc array %arg
foreach (@args) # means do this for each element in the array
{
s/%(..)/pack("c", hex($1))/ge; # unquote %xx
/^([^=]*)=?(.*)$/; # extract "=" part, if any
$arg{$1} = $2 ? $2 : 1;
}
if ($ARGV[0] eq '-install') {
&CheckPerl;
&SetBaseName;
&MakeCommon(0);
exit(0);
}
if ($ARGV[0] eq '-installforce') {
&CheckPerl;
&SetBaseName;
&MakeCommon(1);
exit(0);
}
if ($ARGV[0] eq '-unlock') {
open(FILE,"$FileName");
&UnlockFile(FILE);
exit(0);
}
undef $Link if $arg{'nl'}; # make link?
### Stage 2
###
### Print out the header
# Print out the header
print "Content-type: text/html\n\n";
#print "Debug 1: $ConfName
Debug 2: $FileName";
### Stage 3
###
### Open the access_count file for read-write taking all the precautions
# Make sure the file exists:
if (!(-f $FileName)) {
if (!open (COUNT,">$FileName")) {
# Can't create the file
print $CreateFile;
exit 1;
} else {
# We got the file, print out the version number
print COUNT "$FileVersion\n";
$version = 2;
}
} else {
if (!((-r $FileName) && (-w $FileName))) {
# Make sure that we can in fact read and write to the file in
# question. If not, direct them to the FAQ.
print $AccessRights;
exit 1;
}
if (!open (COUNT,"+<$FileName")) { # Now make sure it *really* opens
print $AccessRights; # ...just in case...
exit 1;
}
# Try to read in a version number
$version = ";
};
}
sub comment1 {
# create a new image
print "Content-type: image/gif\n\n";
$im = new GD::Image(100,100);
# allocate some colors
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);
$red = $im->colorAllocate(255,0,0);
$blue = $im->colorAllocate(0,0,255);
# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');
# Put a black frame around the picture
$im->rectangle(0,0,99,99,$black);
# Draw a blue oval
$im->arc(50,50,95,75,0,360,$blue);
# And fill it with red
$im->fill(50,50,$red);
# Convert the image to GIF and print it on standard output
print $im->gif;
}
### Stage 11
###
### Check if we are supposed to update the count in the file. (ie. we're
### not ignoring the host that just accessed us)
# Make sure we are not ignoring the host:
$ignore = 0;
$ignore = grep($ENV{"REMOTE_ADDR"} =~ /$_/, @IgnoreIP) if defined ($ENV{"REMOTE_ADDR"});
$ignore = $ignore || $arg{"nc"};
### Stage 12
###
### Actually write the updated information back to the file
if (!$ignore) # If we aren't ignoring this access
{
# Now update the counter file
seek(COUNT, $location, 0);
$longaccesses = sprintf("%010.10d", $accesses);
$hexflags = sprintf("%04.4x", $flags);
print COUNT "'$doc_uri' $longaccesses $hexflags\n";
}
&UnlockFile(COUNT);
close COUNT;
#######################################################################
#
# Support functions
#
# translate_output
#
# Quote any special characters with HTML quoting.
sub translate_output {
local($string) = @_;
$_ = $string;
s/è/è/g;
return $_;
}
sub LockFile {
local(*FILE) = @_;
local($TrysLeft) = $MaxTries;
if ($UseLocking) {
# Try to get a lock on the file
while ($TrysLeft--) {
# Try to use locking, if it doesn't use locking, the eval would
# die. Catch that, and don't use locking.
# Try to grab the lock with a non-blocking (4) exclusive (2) lock.
# (4 | 2 = 6)
$lockresult = eval("flock(COUNT,6)");
if ($@) {
$UseLocking = 0;
last;
}
if (!$lockresult) {
select(undef,undef,undef,0.1); # Wait for 1/10 sec.
} else {
last; # We have gotten the lock.
}
}
}
if ($TrysLeft >= 0) {
# Success!
return 0;
} else {
return -1;
}
}
sub UnlockFile {
local(*FILE) = @_;
if ($UseLocking) {
flock(FILE,8); # Unlock the file.
}
}
####################################################################
#
# Installation helpers
#
# SetBaseName
#
# Change the counter program itself to set the basename
sub SetBaseName {
local($name) = $0;
$name =~ s/^.*\/([^\/]+)$/$1/; # Strip off any of the path
if ($name eq $BaseName) { # The way we're set up now!!!
return; # Don't need to change a thing.
}
if (!open(COUNTERFILE, "+<$0")) {
print "Can't modify program. Set \$BaseName manually.\n";
return;
}
print "Configuring \$BaseName variable...\n";
local($oldsep) = $/;
undef($/);
local($program) =
$banner
"; # return no link here (it would be annoying)
}
# output_counterfiglet
#
# An even sillier one than counterbanner. :)
sub output_counterfiglet {
local($count) = @_;
$fig = "echo $count | /usr/games/figlet"; # setup command line
$fig .= " -f $arg{'f'}" if $arg{"f"}; # use a different font?
$fig = `$fig`;
$fig =~ s!&!&!g;
$fig =~ s!" . $fig . "
"; # note no link here, either
}
#########################################################################
#
# Conversion functions
#
# UpdateVersion
#
# Convert a version 1file into a version 2 file.
sub UpdateVersion1 {
local ($contents,$dummy);
local ($oldsep) = $/;
$/ = "";
seek(COUNT,0,0); # Go to the beginning of the file
$contents =