#!/usr/local/bin/perl # Simple SSI counter v1.2 (Jan-06-2000) # Copyright (C) 1999-2000 Kan-chan # Web site: http://kan-chan.stbbs.net/download/ # # 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. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # Release note: # v1.2 (Jan-06-2000) # Small bug fixes. # v1.1 (Nov-24-1999) # Added PNG support. # v1.0 (Jan-07-1999) # First release. # Usage: # 1. Modify the perl directory written on the top of this script # if it is required. # 2. Modify the value of $basedir/$imagedir/$countfile/$lockfile if # the directory and/or file name are different. # 3. Upload files to the following directories and change the # permission. If you cannot use 707/705/606, try 777/755/666. # 4. Add to index.html # # public_html/ # | # |-- index.html # |-- .htaccess (most systems require this to run SSI scripts) # | # |-- images/ # | |-- 0.gif # | |-- 1.gif # | | : # | | : # | |-- 8.gif # | |-- 9.gif # | # |-- count/ (permission:707 or 777) # |-- count.pl (permission:705 or 755) # |-- count.txt (permission:606 or 666) # # Where you installed count.pl/count.txt (location from index.html) $basedir = "./count/"; # Where you installed 0.gif~9.gif (location from index.html) $imagedir = "./images/"; # The extension of the digit file (.gif / .jpg / .png etc.) $ext = ".gif"; # The name of count file $countfile = "count.txt"; # The name of temporary file to lock the process $lockfile = "count.loc"; $countfilepath = $basedir.$countfile; $lockfilepath = $basedir.$lockfile; # Error messages $err_busy = "[Server busy!]"; $err_open = "[Cannot open count file! ($countfilepath)]"; # Wait until the lock is released for ($i=1;$i<=6;$i++){ if (!(-e $lockfilepath)) { last; } elsif ($i == 1){ $filetime = (stat($lockfilepath))[9]; if ($filetime < time() - 10 * 60){ &unlock(); } } elsif ($i >= 6){ &error($err_busy); } sleep(1); } # Create a lock file open(OUT, ">$lockfilepath"); close(OUT); # Read/write count file if (!open(IN, "<$countfilepath")) { &unlock(); &error($err_open); } $count = ; close(IN); $count++; if (!open(OUT, ">$countfilepath")) { &unlock(); &error($err_open); } print(OUT $count); close(OUT); # Output a number as HTML tags &disp($count); # Remove the lock file &unlock(); # Exit this program exit; # If a lock file exists, delete the file sub unlock { if (-e $lockfilepath) { unlink($lockfilepath); } } # Output a number as HTML tags sub disp { $count = $_[0]; foreach (0..length($count)-1) { $n = substr($count, $_, 1); print "\"$n\""; } } # Output an error mesasge sub error { print "$_[0]"; exit; }