#!/usr/bin/perl ############################################ ######Yet Another Counter Twisted Edition### ############################################ # Version 0.9.2 # # Beta Released 27/06/2000 # # Rewritten 09/Feb/2002 # # WWW: home.datacomm.ch/atair/yac/ # # Email: atair@datacomm.ch # # Copyright © 2000 A. Schnyder # # All Rights Reserved # # # # See readme.txt for important information # ############################################ sub myError { $errtmp=$_[0]; open(handle1,'>yac/yac_logfile.txt'); print handle1 "###This is the error logfile of###\n"; print handle1 "#####YET ANOTHER COUNTER (YAC)####\n"; print handle1 "\n$errtmp\n"; close(handle1); open(handle1,'yac/count_error.gif'); while(){ print; } close(handle1); exit; } ###Predefined variables $crop=5; $min_width=0; $no=0; $t1=0; %data=(); my $QueryString=0; $tmp_cmd=""; $face=""; $gformat="jpeg"; ###Getting http-DATA. @QueryArray=(); %Query=(); $QueryString=$ENV{'QUERY_STRING'}; @QueryArray=split '&',$QueryString; foreach(@QueryArray){ ($key, $val) = split ('=',$_); $Query{$key} = $val; } $crop=$Query{width}; ###Printing headers print "Content-type: image\n\n"; $sender = $ENV{'HTTP_REFERER'}; if (($sender !~ m'^http:\/\/www.qm.kag.org') && ($sender !~ m'^http:\/\/qm.kag.org')) { if ($sender eq ""){$sender = "Nowhere (A non-browser origin)";} myError( "Khest! Why are you calling me from $sender?!?!
\n"); } ###Reading data file if(!open(handle1,'yac/yac.txt')) {myError("Error reading 'yac.txt'. Maybe wrong access rights?");} ; while(){ ($key, $val) = split ('\t',$_); $val=~s/\n//g; $key=~s/\n//g; if (($key ne '') && ($val ne '')) {$data{$key} = $val;} } close(handle1); if (exists($data{$Query{name}})) { $data{$Query{name}}++; $no=$data{$Query{name}}; } else {myError("No entry for this name in data file. Please add the name to data file.");} if ($no >= 10000000000) {myError("Error! Overflow. This counter cannot deal with numbers greater than 9999999999.");} if ($Query{face} ne "") {$face = "/" . $Query{face};} if ($Query{format} ne "") {$gformat = $Query{format};} ###Writing data file if(!open(handle1,'>yac/yac.txt')) {myError("Error writing 'yac.txt'. Maybe wrong access rights?");} print handle1 "###This is the data file of yac.pl"; @tmp=(); @tmp = each(%data); while ( $tmp[0] ne ''){ print handle1 "\n$tmp[0]\t$tmp[1]"; @tmp = each(%data); } close(handle1); ###Image processing $tz=$no - 5*int($no/5); $tmp_gif= "yac/tmp_" .+ $Query{name} .+ "_" .+ $tz .+ ".$gformat"; for ($i=9;$i>=0;$i--){ $t1=int($no/(10**$i)); if (($t1 != 0) && ($min_width == 0)) {$min_width=$i+1;} if (($min_width > 0) && ($min_width >= $i + 1)) {$tmp_cmd .= " yac$face/$t1.gif";} $no=$no-$t1*10**$i; } $min_width .= "x1 "; system("montage -mode concatenate -tile $min_width $tmp_cmd $gformat:$tmp_gif"); if (!open(handle1,"$tmp_gif")) {myError("Error loading '$tmp_gif'.");} while(){ print; } system("rm $tmp_gif");