#!/usr/bin/perl # 上のperlのパスはサーバーによって違うことがあるので、 # プロバイダーのCGI設置案内を参照して下さい。 # =================================================================== # EASY 投票アンケート(EASY Tohyo Ver2.2) # File name: eztohyo.cgi # Copyright; Hiroshi Ishikawa (e-mail; laut@tky.3web.ne.jp) # (URL; http://www.net-easy.com) # Last Update: 2000/01/14 # # EASY Tohyo Ver2.2は個人使用に限りフリーウェアです。 # 課金の発生する商用利用などはお問い合わせ下さい。 # また、改造は自由ですが、この欄は削除しないで下さい。 # =================================================================== #このスクリプトは、EASY投票を改造したものです。 # Arranged by K-ji #(E-mail : k-ji@ma5.seikyou.ne.jp) #(URL: http://ha5.seikyou.ne.jp/home/k-ji/) require 'cgi-lib.pl'; #他の場所にあるときは相対パスで指定 require 'jcode.pl'; #他の場所にあるときは相対パスで指定 &ReadParse; # タイトル $title = '2000年CDランキング'; # 見出し $title2 = '
2000年CDランキング
'; # 戻るページのURL $back = 'http://ha5.seikyou.ne.jp/home/k-ji/main2.html'; #相対パスでも可 # この投票の説明文 $kaisetsu = '
2000年シングルCDランキングです。
ぜひ1票入れていってください♪
'; # グラフ用のGIFファイルの設置場所 $gif = "./graph.gif"; #左は同じディレクトリの場合。別の場所に置く時はパスも記入。 # 記録保存ファイル $file = 'eztohyo.txt'; # パスワード(投稿記事の削除の際必要・適宜変更して下さい) $psw = '1234'; # 各コメントの最大保存数、これを越えると古いものから削除される $max = 5; # 各項目の最大文字数(日本語の場合の文字数) $length_max = '15'; # cookieを使用するかしないか # 1を選ぶと,1回の訪問につき1回だけの投票になります。 $cook = '0'; #使用は1、使用しないは0 # cookieの初期設定 # 上の項目で「1」を選んだ場合のみ必要,「0」を選んだときはそのまま。 $cookie = 'easytohyo'; #変更してもしなくても可 # 項目の追加を認めるか $koumoku_add = 'yes'; #認めない時は'no'に変更 # ===================================================================== # 初期設定が必要なのはここまでです # --------------------------------------------------------------------- # これ以下は変更の必要はありませんが、BODYタグなどを変更するだけなら # 変更可能です。ただし、$xxxxのように変数を使っているところを変更すると # エラーの原因となるので注意して下さい。 # ===================================================================== # cookie用に時間を取得 $time = time; $time_last = $time - (60 * 10); # cookieの有無を調べ、あれば取得サブルーチンへ if($cook eq '1'){ if ($ENV{'HTTP_COOKIE'} =~ /$cookie/){ &CookieCutter; } } # 時間の取得 ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime; $mon++; @week = ('日','月','火','水','木','金','土'); $wday = $week[$wday]; $mon = sprintf("%.2d",$mon); $mday = sprintf("%.2d",$mday); $hour = sprintf("%.2d",$hour); $min = sprintf("%.2d",$min); $sec = sprintf("%.2d",$sec); $year = substr($year,1,2); $jikan = "$year/$mon/$mday($wday) $hour:$min:$sec"; # CGIを呼び出された場合分けに応じて条件分岐 if($in{'forked'} eq 'tohyo'){ &tohyo; &html; }elsif($in{'forked'} eq 'add'){ &add; &html; }elsif($in{'forked'} eq 'add_admin'){ &add_admin; &delete_html; }elsif($in{'forked'} eq 'link'){ &comment_link_html; }elsif(($in{'forked'} eq 'admin') && ($in{'psw'} eq "$psw")){ &delete_html; }elsif(($in{'forked'} eq 'delete') && ($in{'psw'} eq "$psw")){ &delete; &delete_html; }elsif($in{'action'} eq 'add_com'){ &add_com; }else{ &html; } # 最初に呼び出されたときのサブルーチン sub html{ if(!open(TXT,"$file")){&error(err_fail);} @DATA = ; close(TXT); if($DATA[0] eq ''){ if(!open(TXT,"$file")){&error(err_fail);} print TXT "0,$jikan\n"; close(TXT); $DATA[0] = "0,$jikan\n"; } @line1 = split(/\,/,$DATA[0]); $total = $line1[0]; $last_time = $line1[1]; print "Content-type: text/html\n"; &SetCookie; print "\n"; print < $title
$title2
$kaisetsu
戻る
20$last_time現在、投票総数$totalです。

下の曲名1つにチェックして、投票ボタンを押してください。 EOM if($koumoku_add eq 'yes'){ print "
投票したい曲が無い場合には、一番下のフォームから曲の追加もできます。\n"; } if($cook eq '1'){ print "
1回のご訪問で1回だけ投票(または項目の追加)ができます。\n"; } print <
EOM $count = @DATA; $count--; $i = 1; $j = 0; $juni = 1; $gr_check = 'yes'; while($count > 0){ @line = split(/\,/,$DATA[$i]); if($line[1] == 0){$per = 0;} if($line[1] != 0){ $per = int(1000 * ($line[1] / $total)) / 10; if($line[1] != $tokuten){ $juni = $i; $tokuten = $line[1]; }else{ $tokuten = $line[1]; } } $rank = $juni; if($line[1] == 0){$rank = 0;} print "\n"; $convert_url = $line[2]; $convert_url =~ s/./sprintf("%%%2X",ord($&))/eg; $koumoku = "$line[2] / $line[7]\n"; print "\n"; print "\n"; #パーセント表示が小数点以下何位も表示されてしまう時は下の行頭の#をとって下さい #$per = substr($per,0,4); #この場合4桁までになります print "\n"; if($gr_check eq 'yes'){ if($per < 40){ $m = 15; }elsif($per >= 40){ if($per > 60){ $m = 5; }else{ $m = 10; } } $gr_check = 'no'; } $r = int($per * $m); if($per != 0){ print "\n"; }else{ print "\n"; } print "\n"; $i++; $j--; $count--; } print <
  項目に*印がついているものはコメントがあります
順位曲名 / アーティスト名票数割合グラフ
$rank$koumoku\n"; if($line[3] ne ''){ print "*\n"; } print "$line[1]$per\%
EOM if($koumoku_add eq 'yes'){ print <

▼項目の追加はこちらから▼
追加する項目を書いて[項目の追加]ボタンを押して下さい
※ 投票の対象は、2000年発売のシングルA面の曲です。
曲名:
アーティスト名:

項目を追加するときは、できればコメントも書いてください(任意)
お名前:
コメント:
 
EOM } # 以下13行は削除しないで下さい。(Copyrightです) print <
EasyTohyo Ver2.1
EDIT by K-ji
EOM } # 投票をするときの加算サブルーチン sub tohyo{ if($in{'choice'} eq ''){ &error(bad_choice); } if(($cook eq '1') && ($check_time > $time_last)){ &html; exit; } if(!open(TXT,"$file")){&error(err_fail);} @DATA = ; close(TXT); @log = split(/\,/,$DATA[0]); $total = $log[0] + 1; $line1 = "$total,$jikan\n"; $choice = $in{'choice'}; &jcode'convert(*choice,"sjis"); $i = 1; $count = @DATA; $count--; while($count > 0){ @line = split(/\,/,$DATA[$i]); if($line[2] eq $choice){ $tokuten = $line[1] + 1; $tokuten_5keta = sprintf("%.5d",$tokuten); $DATA[$i] = "$tokuten_5keta,$tokuten,$line[2],$line[3],$line[4],$line[5],$line[6],$line[7]\="; }else{ $DATA[$i] = "$DATA[$i]\="; } $data_new = "$data_new$DATA[$i]"; $i ++; $count--; } @DATA_new = split(/\=/,$data_new); @DATA_new = sort(@DATA_new); @DATA_new = reverse(@DATA_new); @DATA = ($line1,@DATA_new); if(!open(TXT,">$file")){&error(err_fail);} print TXT @DATA; close(TXT); } # 新たに項目を追加したときのサブルーチン sub add{ if($in{'touroku'} eq ''){ &error(bad_touroku); } if($in{'art'} eq ''){ &error(bad_touroku); } if(($cook eq '1') && ($check_time > $time_last)){ &html; exit; } $length_check = length($in{'touroku'}); $length_max = int($length_max * 2); if($length_check > $length_max){ &error(bad_length); } $touroku = $in{'touroku'}; $art = $in{'art'}; $name = $in{'name'}; $comment = $in{'comment'}; &jcode'convert(*touroku,"sjis"); &jcode'convert(*art,"sjis"); &jcode'convert(*name,"sjis"); &jcode'convert(*comment,"sjis"); $touroku =~ s/&/&/g; $touroku =~ s//>/g; $touroku =~ s/,/./g; $touroku =~ s/ / /g; $art =~ s/&/&/g; $art =~ s//>/g; $art =~ s/,/./g; $art =~ s/ / /g; $name =~ s/&/&/g; $name =~ s//>/g; $name =~ s/,/./g; $name =~ s/ / /g; $comment =~ s/&/&/g; $comment =~ s//>/g; $comment =~ s/,/./g; $comment =~ s/ / /g; if(!open(TXT,"$file")){&error(err_fail);} @DATA = ; close(TXT); $count = @DATA; $count--; $i = 1; $check = 'no'; while($count > 0){ @line = split(/\,/,$DATA[$i]); if($line[2] eq $touroku){ &error(bad_touroku_check); }else{ $check = 'yes'; } $i++; $count--; } if($DATA[1] eq ''){$check = 'yes';} if($check eq 'yes'){ @line1 = split(/\,/,$DATA[0]); $total = $line1[0] + 1; $DATA[0] = "$total,$jikan\n"; if(($comment eq '') && ($name ne '')){ &error(bad_comment); } if(($comment ne '') && ($name eq '')){ $name ='匿名'; } $remote_addr = $ENV{'REMOTE_ADDR'}; $remote_host = ((gethostbyaddr(pack('C4',split(/\./,$remote_addr)),2))[0]); $value = "00001,1,$touroku,$name,$comment,$remote_host,$remote_addr,$art\n"; push(@DATA,$value); $i = 2; $count = @DATA; $count = $count-2; $data_new = $DATA[1]; while($count > 0){ $data_new = "$data_new\=$DATA[$i]"; $i ++; $count--; } @DATA_new = split(/\=/,$data_new); @DATA_new = sort(@DATA_new); @DATA_new = reverse(@DATA_new); @DATA_new = ($DATA[0],@DATA_new); if(!open(TXT,">$file")){&error(err_fail);} print TXT @DATA_new; close(TXT); } } # 削除する行を選ぶHTML画面を出力するサブルーチン sub delete_html{ print "Content-type: text/html\n\n"; print < 管理者画面

管理者画面

戻る

追加する項目を書いて[項目の追加]ボタンを押して下さい
※ ここでの追加は得票になりません。
曲名:
アーティスト名:

項目を追加するときは、できればコメントも書いてください(任意)
お名前:
コメント:
 

削除する記事をチェックして送信して下さい
項目を作った人の、リモートホストが各行最後から2番目の項目、最後がリモートアドレスになっています。


EOM if(!open(OUT,"$file")){&error(err_fail);} @DATA = ; close(OUT); $count = @DATA; $count--; $i = 1; while($count > 0){ @line = split(/\,/,$DATA[$i]); print "$line[1]票 $line[2] $line[3] \- $line[4] $line[5] $line[6]
\n"; $i ++; $count --; } print < EOM } # 削除サブルーチン sub delete{ if(!open(OUT,"$file")){&error(err_fail);} @DATA = ; close(OUT); @line1 = split(/\,/,$DATA[0]); $total_old = $line1[0]; $count = @DATA; @code = split(/\0/,$in{'delete'}); $countcode = @code; $i = 0; $j = 0; while(($count > 0) || ($countcode > $j)){ @line = split(/\,/,$DATA[$i]); if($line[2] eq $code[$j]){ @data_line = split(/\,/,$DATA[$i]); $tokuten = $data_line[1]; $delete_tokuten = $delete_tokuten + $tokuten; $DATA[$i] = ''; $j ++; } $i ++; $count --; } $total_new = $total_old - $delete_tokuten; $DATA[0] = "$total_new,$jikan\n"; $line = $DATA[0]; shift(@DATA); @DATA = sort(@DATA); @DATA = reverse(@DATA); @DATA = ($line,@DATA); if(!open(TXT,">$file")){&error(err_fail);} print TXT @DATA; close(TXT); } # 項目に対するコメントを表示するサブルーチン sub comment_link_html{ if(!open(OUT,"$file")){&error(err_fail);} @DATA = ; close(OUT); $count = @DATA; $count--; $i = 1; while($count > 0){ @line = split(/\,/,$DATA[$i]); if($in{'link'} eq "$line[2]"){ print "Content-type: text/html\n\n"; print < $line[2]コメント

$line[2]」のコメント

EOM if(($line[3] ne '') && ($line[4] ne '')){ @NAME = split(/\//,$line[3]); @COMMENT = split(/\//,$line[4]); $count = @NAME; print < 最新の$max個までが表\示されます(現在コメントは$count個あります) EOM $j = 0; while($count > 0){ print "
\n\n"; print "\n"; print "\n"; print "
$NAME[$j]さん
$COMMENT[$j]
\n
\n
\n"; $j++; $count--; } }else{ print "
コメントは現在ありません
\n
\n"; } print <このウィンドウは右上の×ボタンで閉じてください   
コメントを追加する時は下にお書きください
お名前:

コメント:


 
EOM } $i++; $count--; } } # cookieの取得サブルーチン sub CookieCutter { foreach(split(/; /,$ENV{'HTTP_COOKIE'})){ ($key,$value) = split(/=/); if ($key eq $cookie){ $cookieJar{$cookie} = $value; } } $check_time = $cookieJar{$cookie}; } # cookieセットサブルーチン sub SetCookie{ if($cook eq '1'){ if(($in{'forked'} eq 'tohyo') || ($in{'forked'} eq 'add')){ print "Set-Cookie: "; print "$cookie=$time;\n"; } } } # コメント追加サブルーチン sub add_com{ if($in{'comment'} eq ''){ &error(bad_touroku); } $koumoku = $in{'koumoku'}; $comment = $in{'comment'}; $name = $in{'name'}; &jcode'convert(*comment,"sjis"); &jcode'convert(*name,"sjis"); $name =~ s/&/&/g; $name =~ s//>/g; $name =~ s/,/./g; $comment =~ s/&/&/g; $comment =~ s//>/g; $comment =~ s/,/./g; $comment =~ s/\//\-/g; if(!open(TXT,"$file")){&error(err_fail);} @DATA = ; close(TXT); $count = @DATA; $count--; $i = 1; @NEW_DATA = "$DATA[0]"; while($count > 0){ @line = split(/\,/,$DATA[$i]); if($line[2] eq $koumoku){ if($name eq ''){$name = '匿名';} if($line[3] eq ''){ $line[3] = "$name"; }else{ $line[3] = "$line[3]\/$name"; @check_name = split(/\//,$line[3]); $check_n = @check_name; if($check_n > $max){ shift(@check_name); foreach $write(@check_name){ if($new_line3 eq ""){ $new_line3 = $write; }else{ $new_line3 = "$new_line3\/$write"; } } $line[3] = $new_line3; $flag = 'yes'; } } if($line[4] eq ''){ $line[4] = "$comment"; }else{ $line[4] = "$line[4]\/$comment"; if($flag eq "yes"){ @check_comment = split(/\//,$line[4]); shift(@check_comment); foreach $write_c(@check_comment){ if($new_line4 eq ""){ $new_line4 = $write_c; }else{ $new_line4 = "$new_line4\/$write_c"; } } $line[4] = $new_line4; } } } $value = "$line[0],$line[1],$line[2],$line[3],$line[4],$line[5],$line[6],$line[7]"; push(@NEW_DATA,$value); $i++; $count--; } if(!open(TXT,">$file")){&error(err_fail);} print TXT @NEW_DATA; close(TXT); &comment_link_html; } # 管理者用項目追加サブルーチン # 管理者が項目を追加するときは投票数がゼロで項目追加される sub add_admin{ if($in{'touroku'} eq ''){ &error(bad_touroku); } $touroku = $in{'touroku'}; $name = $in{'name'}; $comment = $in{'comment'}; &jcode'convert(*touroku,"sjis"); &jcode'convert(*name,"sjis"); &jcode'convert(*comment,"sjis"); $touroku =~ s/&/&/g; $touroku =~ s//>/g; $touroku =~ s/,/./g; $name =~ s/&/&/g; $name =~ s//>/g; $name =~ s/,/./g; $comment =~ s/&/&/g; $comment =~ s//>/g; $comment =~ s/,/./g; if(!open(TXT,"$file")){&error(err_fail);} @DATA = ; close(TXT); $count = @DATA; $count--; $i = 1; $check = 'no'; while($count > 0){ @line = split(/\,/,$DATA[$i]); if($line[2] eq $touroku){ &error(bad_touroku_check); }else{ $check = 'yes'; } $i++; $count--; } if($DATA[1] eq ''){$check = 'yes';} if($check eq 'yes'){ if($DATA[0] == ''){ @line1 = split(/\,/,$DATA[0]); $total = 0; $DATA[0] = "$total,$jikan\n"; } if(($comment eq '') && ($name ne '')){ &error(bad_comment); } if(($comment ne '') && ($name eq '')){ $name ='匿名'; } $value = "00000,0,$touroku,$name,$comment,$remote_host,$remote_addr\n"; push(@DATA,$value); if(!open(TXT,">$file")){&error(err_fail);} print TXT @DATA; close(TXT); } } # エラーサブルーチン sub error{ $error = $_[0]; if ($error eq "bad_choice"){ $msge = '項目から1つ選んで「投票ボタン」押してください'; }elsif($error eq "bad_touroku"){ $msge = '項目が記入されていません'; }elsif($error eq "bad_comment"){ $msge = 'コメントを書いてください。
書かない場合は名前もコメントも空欄にして下さい。'; }elsif($error eq "bad_touroku_check"){ $msge = '登録しようとしている項目は既にあります'; }elsif($error eq "err_fail"){ $msge = 'ファイルオープンできません'; }elsif($error eq "bad_length"){ $bad_max_length = int($length_max / 2); $msge = "追加する項目の文字数を$bad_max_length文字以内にしてください"; }else{ $msge = '何らかのエラーです'; } print "Content-type: text/html\n\n"; print "ERROR\n"; print "\n"; print "

$msge


\n"; print "BACK\n"; exit; }