#!/usr/bin/perl $debug_flag=1; #require TripodCGI; require CGI; use CGI; $cgi = new CGI; # # get the digit to display # $f=$cgi->param('f'); $d=$cgi->param('d'); if ($debug_flag) { print "Content-type: text/html", "\n\n"; print "\n"; print "digit=$d
";
}
#
# the digit must be a number
# null digits aint allowed
#
if ($d eq "" ) {
if ($debug_flag) {
print "\$d is null
\n";
}
$image="null_not_allowed.jpg";
goto done;
}
if ($d =~ /^comma$/i ) {
if ($debug_flag) {
print "\$d is comma
\n";
}
$image="comma.jpg";
goto done;
}
if ($d =~ /^dot$/i ) {
if ($debug_flag) {
print "\$d is dot
\n";
}
$image="dot.jpg";
goto done;
}
#
# digit must be a one or more digit number
#
if ($d !~ /^[0-9][0-9]*$/ ) {
if ($debug_flag) {
print "\$d must be numeric it aint '$d'
\n";
}
$image="number_required.jpg";
goto done;
}
#
# digit cant be the number zero
#
if ($d == 0 ) {
if ($debug_flag) {
print "\$d must not be zero '$d'
\n";
}
$image="zero_not_allowed.jpg";
goto done;
}
$digit_out=$d;
#
# get the name of the counter
#
$n=$cgi->param('n');
if ($debug_flag) {
print "counter name='$n'
";
}
#
# if the counter name is not null
# validate the name of the counter name
# counter names can only be a-z, A-Z, and (_) underscores
#
if ($n ne "" ) {
if ($debug_flag) {
print "\$n not NULL='$n'
";
}
if ($n !~ /^[0-9a-zA-Z_][0-9a-zA-Z_]*$/ ) {
if ($debug_flag) {
print "\$n is invalid '$n'
\n";
}
$image="counter_name_bad.jpg";
goto done;
}
}
if ($debug_flag) {
print "valid counter name='$n'
";
}
#
# open the counter file ane read in the counter names
$i=0;
$counter_is_at="";
open(COUNTERS,'counter/counter.txt');
while(
";
print "$kounter[$i]
";
}
if ($n eq "") {
if ($_ =~ /^[0-9][0-9]*$/ ) {
$counter_is_at=$i;
$counter=$_;
$the_counter=$counter;
if ($debug_flag) {
print "COUNTER at $i
";
print "COUNTER=$counter
";
}
}
}
else {
if ($_ =~ /^$n=[0-9][0-9]*$/ ) {
$counter_is_at=$i;
$counter=$_;
$counter=~s/^.*=//;
$the_counter=$counter;
if ($debug_flag) {
print "COUNTER at $i
";
print "COUNTER=$counter
";
}
}
}
$i++;
$max_counters=$i;
}
close(COUNTERS);
#
# counter was not found
if ($counter_is_at eq "" ) {
if ($debug_flag) {
print "\$n counter '$n' not found
\n";
}
$image="counter_not_found_in_file.jpg";
goto done;
}
#
# validate the counter
# it must be a positive number
#
if ($counter eq "" ) {
if ($debug_flag) {
print "\$counter cant be NULL
\n";
}
$image="counter_is_null.jpg";
goto done;
}
if ($counter !~ /^[0-9][0-9]*$/ ) {
if ($debug_flag) {
print "\$counter must be numeric it aint '$counter'
\n";
}
$image="counter_not_numeric.jpg";
goto done;
}
$remainder=0;
if ($debug_flag) {
print "counter=$counter
";
}
while ($d > 0 ) {
$remainder=$counter%10;
$counter=$counter-$remainder;
$counter=$counter/10;
$d--;
}
if ($debug_flag) {
print "remainter=$remainder
";
}
#$image="$remainder".".gif";
$image="$f$remainder".".gif";
#
# all done. get outa here
#
#
# if the digit is the number one (1)
# add 1 to the counter
# and write it back to the file
# later on flock the file so we can handle mutiple users
#
if ( $digit_out== 1) {
if ($debug_flag) {
print "digit == 1
";
print "update the counter file!!!
";
print "old counter=$the_counter
";
}
$the_counter++;
if ($debug_flag) {
print "new counter=$the_counter
";
print "old counter=$kounter[$counter_is_at]
";
}
if ($n eq "") {
$kounter[$counter_is_at]++;
if ($debug_flag) {
print "new counter=$kounter[$counter_is_at]
";
}
}
else {
$kounter[$counter_is_at]=~s/=.*$/=$the_counter/;
if ($debug_flag) {
print "new counter=$kounter[$counter_is_at]
";
}
}
if ($debug_flag) {
print "now write out $max_counters counters
";
}
open(COUNTERS,'>counter/counter.txt');
for ($i=0;$i<$max_counters;$i++) {
if ($debug_flag) {
print "write $kounter[$i]
\n";
}
#prnters
";
}
#
# note we ALWAYS update the counters
# even if we dont log the IP address
#
open(COUNTERS,'>counter/counter.txt');
#flock( COUNTERS , 2);
for ($i=0;$i<$max_counters;$i++) {
if ($debug_flag) {
print "write $kounter[$i]
\n";
}
print COUNTERS "$kounter[$i]\n";
}
close(COUNTERS);
#
# this computer is on the east coast and uses New York time
# f*ck New York time!!! We want Phoenix time!
#
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
#
# 1) subtract 7 hours from GM time to get Phoenix time
# 2) format Phoenix time into yy/mm/dd/ hh/mm/ss
#
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime(time()-(7*60*60));
$mon++;
$mon=($mon<10)?"0$mon":$mon;
$hour=($hour<10)?"0$hour":$hour;
$min=($min<10)?"0$min":$min;
$sec=($sec<10)?"0$sec":$sec;
$mday=($mday<10)?"0$mday":$mday;
$year+=1900;
$zdate="$year/$mon/$mday $hour:$min:$sec";
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
#
# but if it is an IP address I use turn off the logging
#
@my_ip_addresses=('156.42.68.2', # maricopa county law library
'156.42.68.3' # maricopa county law library
};
#
# the default is to write the IP address to the log
#
$do_the_stinking_log=1;
#
# if the current address is one of my IP addresses don't log it
#
foreach (@myNames) {
print $_;
if ( $ENV{REMOTE_ADDR} eq $_) {
#
# turn off logging
#
$do_the_stinking_log=0;
}
}
#
# log this IP address with the URL that took us to it
# if it aint one of the IP addresses i use
#
if ($do_the_stinking_log == 1) {
open(LOGIPADDRESS,'>>counter/ip_log.txt');
flock(LOGIPADDRESS, 2);
print LOGIPADDRESS "$zdate $ENV{REMOTE_ADDR} $ENV{HTTP_REFERER}\n";
close(LOGIPADDRESS);
}
done:;
if ($debug_flag) {
print "image='$image'
";
print "
";
}
else {
print "Content-type: image/jpeg\n\n";
#
# open the image file
#
#$i=open(GIFFILE,$src);
#$i=open(GIFFILE,"counter/$image");
$i=open(GIFFILE,"counter/0.gif");
#
# do i/o in in binary mode as opposed to text
#
$i=binmode(GIFFILE);
#
# read the image
#
$i=read(GIFFILE,$text,10000000);
#
# print the image to the web site
#
print $text;
#
# close the image file
#
close(GIFFILE);
}
exit;