|
|
#!/usr/local/bin/perl# (C) Gigasoft 2000, by Sephiroth2$cgihdr="#!/usr/local/bin/perl\nprint \"Content-type: text/html\\n\\nNot for you to read!\"; exit;\n__END__\n";sub fail { print "Bad error happened.\n$_[0].\n"; exit;}sub loadfile($) { my @ret; open(LF,$_[0]) | | goto emptyfile; LOADF: while(1) { $_=; last LOADF if($_ eq "__END__\n"); if(!$_) { goto emptyfile; } } @ret=; close(LF); emptyfile: @ret;}print "Content-type: text/html\n\n";$bdir=$0;$bdir=~/((([^\/]+)\/)+)/;$bdir=$1;if($ARGV[0]) { $inp=$ARGV[0]; } else { $inp=$ENV{'QUERY_STRING'}; }@all = split('&',$inp);foreach $stuff(@all) { ($n,$v)=split('=',$stuff); $v=~tr/+/ /; $v=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $v=~s/\0//g; $v=~s///g; $form{$n}=$v;}if($form{'action'}==0) { @sh=loadfile($bdir.'hiscore.cgi'); foreach $h(@sh) { @h=split(/\|/,$h); print (($h[0]+0).'|'.$h[1]).'|'.$h[2]; }} elsif($form{'action'}==1) { $sc=$form{'score'}; $nm=$form{'name'}; $em=$form{'email'}; $sc+=0; if($sc>999999999 | | $sc<0) { fail('Score out of range (0-999999999)'); } if($nm=~/\n/ | | $nm=~/\|/) { fail('Bad character in name'); } if(!$nm) { fail('Name is empty'); } @hisc=loadfile($bdir.'hiscore.cgi'); push(@hisc,sprintf("%09d",$sc)."\|$nm\|$em\n"); @hisc=sort {$b<=>$a;} @hisc; if($#hisc>9) { $#hisc=9; } open(HISCORE,'>'.$bdir.'hiscore.cgi'); print HISCORE $cgihdr,@hisc; close(HISCORE);} else { fail('Invalid parameter.');}
|
|