#!/usr/local/bin/perl # # 画像一体型グラフィックカウンタ (c)rescue.ne.jp # # 初期設定 #あなたのホームページを一番短い書き方で記入します $mine = 'http://www.xxx.or.jp/~user/'; #あなたがこのシステムを設置したcounterディレクトリまでのURLを記入します $url = 'http://www.xxx.or.jp/~user/counter/'; # flyの設定 $flyprog = "./fly"; $infile = "/tmp/fly.$$"; #----------------------------------------------------------------------------------- $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($name ne "string") { $value =~ y/A-Z/a-z/; $name =~ y/A-Z/a-z/; } $FORM{$name} = $value; } #----------------------------------------------------------------------------------- $font = $FORM{'font'}; if ($font eq 'image1') { $digit_dir = "./image1"; } elsif ($font eq 'image2') { $digit_dir = "./image2"; } else { $digit_dir = "./image1"; } #----------------------------------------------------------------------------------- if ($FORM{'user'} eq "") { &error(1); } $file = "./user/$FORM{'user'}\.dat"; if (!(-e $file)) { &error(1); } elsif (-z $file) { &error(2); } elsif (!(-T $file)) { &error(2); } if (!open(IN,"$file")) { &error(2); } $line = ; close(IN); ($name,$value) = split(/\:/,$line); if ($name eq "count") { $count = $value; $save = $count; } else { &error(2); } $ref = $ENV{'HTTP_REFERER'}; if (!($ref =~ /$mine/)) { #参考 通常は参照されたURLが$mineで設定されたURLの文字列を含んでいない場合、 #   あなたのページ内から利用されたものではないと判断して、利用できないように #   するのですが、環境によっては誤動作するようです。現在はこの判断をしないように #   してありますが、有効にするには #&error(0); の # を削除してください。 #&error(0); #参考 あなた以外の人が登録利用したらそのファイルを削除してしまう場合は、 #   #unlink("$file"); の # を削除してください。ただし、誰かがあなたの #   使っているカウンタネームでアクセスしてしまっても削除されてしまいます。 #   このままであれば警告画像を表示するだけになります。# を削除して使う # 場合は、#&error(0); の # も削除してください。 #unlink("$file"); } #----------------------------------------------------------------------------------- $size = $FORM{'size'}; if ($size eq "") { if ($digit_dir =~ /image1/) { $width = "15"; $height = "20"; } elsif ($digit_dir =~ /image2/) { $width = "32"; $height = "30"; } else { $width = "15"; $height = "20"; } } else { if ($size =~ /(.*),(.*)/) { $width = $1; $height = $2; } else { $width = "50"; $height = "50"; } } #----------------------------------------------------------------------------------- $tgif = $FORM{'tgif'}; if ($tgif eq 'black') { $tp = "0,0,0"; } elsif ($tgif eq 'white') { $tp = "255,255,255"; } else { $tp = ""; } #----------------------------------------------------------------------------------- $il = "1"; #----------------------------------------------------------------------------------- $fw = $FORM{'fw'}; if ($fw ne '') { $frame_width = $fw; } else { $frame_width = "0"; } #----------------------------------------------------------------------------------- $fc = $FORM{'fc'}; if ($fc =~ /.*,.*,.*/) { $frame_color = $fc; } else { if ($fc eq 'black') { $frame_color = "0,0,0"; } elsif ($fc eq 'white') { $frame_color = "255,255,255"; } elsif ($fc eq 'red') { $frame_color = "255,0,0"; } elsif ($fc eq 'blue') { $frame_color = "0,0,255"; } elsif ($fc eq 'green') { $frame_color = "0,255,0"; } else { $frame_color = "0,0,0"; } } #----------------------------------------------------------------------------------- $string = $FORM{'string'}; $stcolor = $FORM{'stcolor'}; $stpoint = $FORM{'stpoint'}; $stsize = $FORM{'stsize'}; if (!($stcolor =~ /.*,.*,.*/)) { $stcolor = "255,255,255"; } if (!($stpoint =~ /.*,.*/)) { $stpoint = "0,0"; } if ($stsize eq "tiny") { $stsize = "tiny"; } elsif ($stsize eq "small") { $stsize = "small"; } elsif ($stsize eq "medium") { $stsize = "medium"; } elsif ($stsize eq "large") { $stsize = "large"; } elsif ($stsize eq "giant") { $stsize = "giant"; } else { $stsize = "medium"; } #----------------------------------------------------------------------------------- chop($count) if $count =~ /\n$/; $wd = $FORM{'width'}; if ($wd =~ /\D/ || $wd eq "") { ; } else { $cl = length($count); if ($cl < $wd) { $zero = '0' x ($wd - $cl); $count = "$zero$count"; } } $num = $length = length($count); while ($num > 0) { $CHAR{$num} = chop($count); $num--; } #----------------------------------------------------------------------------------- $img_width = (($width * $length) + ($frame_width * 2)); $img_height = (($frame_width * 2) + $height); #----------------------------------------------------------------------------------- print "Content-type: image/gif\n\n"; open(FLY,"> $infile"); print FLY "new\n"; print FLY "size $img_width,$img_height\n"; &make_frame; $j = 1; while ($j <= $length) { print FLY "copy $insert_width,$insert_height,-1,-1,-1,-1,$digit_dir/$CHAR{$j}\.gif\n"; $insert_width = ($insert_width + $width); $j++; } if ($tp ne "") { print FLY "transparent $tp\n"; } if ($FORM{'interlace'} eq "on") { print FLY "interlace\n"; } if ($string ne "") { print FLY "string $stcolor,$stpoint,$stsize,$string\n"; } close(FLY); open(FOO,"$flyprog -q -i $infile |"); while( ) { print;} close(FOO); unlink($infile); #----------------------------------------------------------------------------------- $increase = $FORM{'increase'}; if ($increase eq 'off') { exit; } $save++; if (!open(OUT,">$file")) { &error; } print OUT "count\:$save\n"; foreach (1..3) { chop($lines[($_)]) if $lines[($_)] =~ /\n$/; print OUT "$lines[($_)]\n"; } close(OUT); chmod(0700,$file); exit; #----------------------------------------------------------------------------------- sub make_frame { $insert_width = $insert_height = $frame_width; $insert_frame = 0; while ($insert_frame < $frame_width) { $current_width = ($img_width - $insert_frame); $current_height = ($img_height - $insert_frame); print FLY "line 0,$insert_frame,$img_width,$insert_frame,$frame_color\n"; print FLY "line $insert_frame,0,$insert_frame,$img_height,$frame_color\n"; print FLY "line $current_width,0,$current_width,$img_height,$frame_color\n"; print FLY "line $current_height,0,$current_height,$img_width,$frame_color\n"; $insert_frame++; } } #----------------------------------------------------------------------------------- sub error { $error = $_[0]; if ($error eq "0") { $error_gif = $url . "bad_user.gif"; } elsif ($error eq "1") { $error_gif = $url . "bad_name.gif"; } elsif ($error eq "2") { $error_gif = $url . "hason.gif"; } else { $error_gif = $url . "error.gif"; } print "Location: $error_gif\n\n"; exit; }