#!/usr/bin/perl #バージョン番号。いじらないでネ。改造した場合は適当にどうぞ。 $version="Version 0.1"; #このスクリプトのなまえ。ファイル名を変更したときはここも変更してください。 $script="nae.cgi"; $topic="萎え $version"; $tfile="tukkomi.txt"; $hfile="history.txt"; #日本語らいぶらり require './jcode.pl'; # # MAIN ROUTINEs # $table_default=" \n \n \n \n \n \n \n \n \n
1st\2ndなし
なしn_nn_fn_wn_en_an_in_tn_ln_d
f_nf_ff_wf_ef_af_if_tf_lf_d
w_nw_fw_ww_ew_aw_iw_tw_lw_d
e_ne_fe_we_ee_ae_ie_te_le_d
a_na_fa_wa_ea_aa_ia_ta_la_d
i_ni_fi_wi_ei_ai_ii_ti_li_d
t_nt_ft_wt_et_at_it_tt_lt_d
l_nl_fl_wl_el_al_il_tl_ll_d
d_nd_fd_wd_ed_ad_id_td_ld_d
"; @c_code=('n','f','w','e','a','i','t','l','d'); @crname=('無','炎','水','土','風','氷','雷','光','闇'); &make_salt; &form_read; if($function eq "regist"){ &set_cookie; ®ist; } if($function eq "resultregist"){ &set_cookie; &result_regist; } if($function eq "edit"){ &set_cookie; &edit; } if($function eq "delete"){ &set_cookie; &delete; } if($function eq "tukkomi"){ &set_cookie; &tukkomi; } &header; &get_cookie; if($regmes ne ""){ print "登録:$regmes
"; } if($function eq "check"){ ✓ } &list_put; &show_tukkomi; &show_form; &show_history; &footer; # # SUB ROUTINE # sub tukkomi{ if($body ne ""){ if(!open(OUT,">>$tfile")){&error_message('filesystem error','開けないノ');} print OUT "$name > $body ($today2)\n"; close OUT; $reg="ツッコミ完了"; } } sub show_tukkomi{ if(!open(IN,$tfile)){&error_message('filesystem error','開けないノ');} @all=; close IN; print ""; print "一番上鉢登録結果登録
"; print "
ツッコミコーナー
"; print "最近のツッコミ10件
"; $count=0; @all=reverse(@all); foreach $i(@all){ if($count<10){ print "$i
\n"; $count++; } } print <<"EOM";
なまえ

EOM } sub edit{ $filename_prg="$code.prg"; if(open(IN,$filename_prg)){ @all=; close IN; @out=(); foreach $i(@all){ ($t_name,$t_number,$t_body,$t_time,$t_pass)=split(/\t/,$i); if($t_name eq $name && $t_pass eq $pass){ $regmes="データを修正しました。"; push (@out,"$name\t$number\t$body\t$time\t$pass\t\n"); if(!open(OUT,">>$hfile")){&error_message('filesystem error','開けないノ');} print OUT "EDIT\t$name\t$number\t$body\t$time\t$code\t\n"; close OUT; } else { push (@out,$i); } } open(OUT,">$filename_prg"); print OUT @out; close OUT; } } sub delete{ $filename_prg="$code.prg"; if(open(IN,$filename_prg)){ @all=; close IN; @out=(); foreach $i(@all){ ($t_name,$t_number,$t_body,$t_time,$t_pass)=split(/\t/,$i); if($t_name eq $name && $t_pass eq $pass){ if(!open(OUT,">>$hfile")){&error_message('filesystem error','開けないノ');} print OUT "DEL\t$t_name\t$t_number\t$t_body\t$t_time\t$code\t\n"; close OUT; $regmes="データを削除しました。"; } else { push (@out,$i); } } open(OUT,">$filename_prg"); print OUT @out; close OUT; } } sub regist{ $code="$cr1"."_"."$cr2"; $filename_prg="$code.prg"; if(open(IN,$filename_prg)){ @all=; close IN; foreach $i(@all){ ($t_name,$t_number,$t_body,$t_time,$t_pass)=split(/\t/,$i); if($t_name eq $name){ $regmes="すでにデータが存在します。修正フォームから修正してください"; return; } } } if(!open(OUT,">>$filename_prg")){&error_message('filesystem error','開けないノ');} print OUT "$name\t$number\t$body\t$time\t$pass\t\n"; close OUT; if(!open(OUT,">>$hfile")){&error_message('filesystem error','開けないノ');} print OUT "NEW\t$name\t$number\t$body\t$time\t$code\t\n"; close OUT; $regmes="データを追加しました。"; } sub result_regist{ $code="$cr1"."_"."$cr2"; $filename_prg="$code.res"; if(!open(OUT,">>$filename_prg")){&error_message('filesystem error','開けないノ');} print OUT "$name\t$number\t$body\t$time\t$pass\t\n"; close OUT; if(!open(OUT,">>$hfile")){&error_message('filesystem error','開けないノ');} print OUT "RES\t$name\t$number\t$body\t$time\t$code\t\n"; close OUT; $regmes="結果データを追加しました。"; } sub show_history{ if(!open(IN,"$hfile")){&error_message('filesystem error','開けないノ');} @all=; close IN; print "History
"; print "最近の履歴10件
"; $count=0; @all=reverse(@all); foreach $i(@all){ ($mode,$name,$number,$body,$time,$code)=split(/\t/,$i); $code =~ s/n/なし/g; $code =~ s/f/炎/g; $code =~ s/w/水/g; $code =~ s/e/土/g; $code =~ s/a/風/g; $code =~ s/i/氷/g; $code =~ s/t/雷/g; $code =~ s/l/光/g; $code =~ s/d/闇/g; $code =~ s/_/・/g; if($mode eq "NEW"){ $mode ='新規育成データ入力しました。';} if($mode eq "DEL"){ $mode ='育成データを削除しました。';} if($mode eq "EDIT"){ $mode ='育成データを修正しました。';} if($mode eq "RES"){ $mode ="結果データ「$body」を入力しました。";} if($count<10){ print "($time) $name さんが 「$code」 の $mode \n
"; } $count++; } } sub show_form{ print ""; print "一番上ツッコミコーナー結果登録
"; print "登録はこちらからですヨ
"; print "
"; print "Name
"; print "Pass
"; print ""; print "第1クリ"; print "第2クリ"; print "鉢数
"; print "状況詳細欄↓
"; print ""; print "
"; print ""; print "一番上ツッコミコーナー鉢登録
"; print "
結果入力
"; print "
"; print "Name
"; print "Pass
"; print ""; print "第1クリ"; print "第2クリ"; print "
とれたもの(書いた内容がそのまま表\示されるヨ!)
"; print ""; print "
"; } sub check{ print "$name さんの育成中データクポ
"; $d_code=$code; $d_code =~ s/n/なし/g; $d_code =~ s/f/炎/g; $d_code =~ s/w/水/g; $d_code =~ s/e/土/g; $d_code =~ s/a/風/g; $d_code =~ s/i/氷/g; $d_code =~ s/t/雷/g; $d_code =~ s/l/光/g; $d_code =~ s/d/闇/g; ($cr1,$cr2)=split(/_/,$d_code); print "第1クリ :$cr1 第2クリ :$cr2
"; $filename_prg="$code.prg"; if(open(IN,$filename_prg)){ @all=; close IN; foreach $i(@all){ ($t_name,$t_number,$t_body,$t_time,$t_pass)=split(/\t/,$i); if($t_name eq $name){ $t_body =~ s/
/\n/g; print <<"EOM";

修正用パスワード:
鉢数:

削除パスワード:
確認なしでざっくり消えるヽ(・∀・)ノ
EOM } } } } sub list_put{ for($i=0;$i<9;$i++){ for($j=0;$j<9;$j++){ @prg=(); @res=(); $code="$c_code[$i]"."_"."$c_code[$j]"; $filename_prg="$code.prg"; $filename_res="$code.res"; if(open(IN,$filename_prg)){ @all=; close IN; foreach $i(@all){ ($name,$body,$time,$pass)=split(/\t/,$i); push(@prg,"$name : $body
\n"); } } if(open(IN,$filename_res)){ @all=; close IN; foreach $i(@all){ ($name,$number,$body,$time,$pass)=split(/\t/,$i); push(@res,"$body
\n"); } } $table_default =~ s/$code/@prg
@res/g; } } print "$table_default"; } # #汎用サブルーチン。使いまわし&パクり。そしてだんだんと汎用でなくなってくるという様子 # sub form_read { if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); } else { $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; &jcode'convert(*value,'sjis'); $value =~ s//>/g; $value =~ s/\n//g; $value =~ s/\t//g; $value =~ s/\r/
/g; $FORM{$name} = $value; } $code=$FORM{'code'}; $function=$FORM{'function'}; $name=$FORM{'name'}; $number=$FORM{'number'}; $body=$FORM{'body'}; $pass=$FORM{'pass'}; $cr1=$FORM{'cr1'}; $cr2=$FORM{'cr2'}; $rh = $ENV{'REMOTE_HOST'}; $addr = $ENV{'REMOTE_ADDR'}; if ($rh eq $addr) { $rh = gethostbyaddr(pack('C4',split(/\./,$rh)),2) || $addr; } $ENV{'TZ'} = "JST-9"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @wday_array = ('日','月','火','水','木','金','土'); $mon++; $year=$year-100; if($year<10){ $year="0$year"; } if($mon<10){ $mon="0$mon"; } if($mday<10){ $mday="0$mday"; } if($hour<10){ $hour="0$hour"; } if($min<10){ $min="0$min"; } $timenow="$year/$mon/$mday/$hour$min"; $time="$year/$mon/$mday/$hour$min"; $today = "$mon/$mday"; $today2= "$mon/$mday $hour:$min"; } sub header { print "Content-type: text/html\n\n"; print "$topic\n"; print ''; print '\n"; print "\n\n"; print ""; print "リロード
"; print "ツッコミコーナー鉢登録結果登録
"; } sub reload_header { print "Content-type: text/html\n\n"; print "$topic\n"; print ''; print ""; print '"; print "\n\n"; } sub footer { print "
"; print "
Script by senobeya.com
\n"; print "
萎え $version
\n"; print ""; } sub error_message { print "

$_[0]

\n"; print "

$_[1]

\n"; print "ブラウザの[戻る]ボタンを押して前の画面に移動してください.

\n"; &footer; exit; } sub get_cookie { @pairs = split(/\;/,$ENV{'HTTP_COOKIE'}); foreach $pair (@pairs) { local($name, $value) = split(/\=/, $pair); $name =~ s/ //g; $DUMMY{$name} = $value; } @pairs = split(/\,/,$DUMMY{'NAEE'}); foreach $pair (@pairs) { local($name, $value) = split(/\:/, $pair); $COOKIE{$name} = $value; } $c_name = $COOKIE{'name'}; $c_pass = $COOKIE{'pass'}; } sub set_cookie { ($secg,$ming,$hourg,$mdayg,$mong,$yearg,$wdayg,$ydayg,$isdstg) = gmtime(time + 60*24*60*60); $yearg += 1900; if ($secg < 10) { $secg = "0$secg"; } if ($ming < 10) { $ming = "0$ming"; } if ($hourg < 10) { $hourg = "0$hourg"; } if ($mdayg < 10) { $mdayg = "0$mdayg"; } $mong = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep', 'Oct','Nov','Dec') [$mong]; $youbi = ('Sunday','Monday','Tuesday','Wednesday','Thursday', 'Friday','Saturday') [$wdayg]; $date_gmt = "$youbi, $mdayg\-$mong\-$yearg $hourg:$ming:$secg GMT"; $ENV{'TZ'} = "JST-9"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @wday_array = ('日','月','火','水','木','金','土'); $mon++; $year=$year-100; if($year<10){ $year="0$year"; } if($mon<10){ $mon="0$mon"; } if($mday<10){ $mday="0$mday"; } if($hour<10){ $hour="0$hour"; } if($min<10){ $min="0$min"; } $timenow="$year/$mon/$mday/$hour$min"; $cook="name\:$name\,pass\:$pass"; print "Set-Cookie: NAEE=$cook; expires=$date_gmt\n"; } sub make_salt{ srand(); $xx = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" . "abcdefghijklmnopqrstuvwxyz" . "0123456789."; $salt = substr($xx, int(rand(63)), 1); $salt .= substr($xx, int(rand(63)), 1); $salt .= substr($xx, int(rand(63)), 1); $salt .= substr($xx, int(rand(63)), 1); }