#!/usr/local/bin/perl #┌───────────────────────────────── #│ [ WebPatio ] #│ regist.cgi - 2006/11/11 #│ Copyright (c) KentWeb #│ webmaster@kent-web.com #│ http://www.kent-web.com/ #└───────────────────────────────── # 外部ファイル取り込み require './init.cgi'; require $jcode; &parse_form; &axscheck; if ($mode eq "todos") { ®ist; } elsif ($mode eq "del") { &delete; } elsif ($mode eq "mente") { &mente; } elsif ($mode eq "edit_log") { require $editlog; &edit_log; } &error("不明な処理です"); #------------------------------------------------- # 記事投稿処理 #------------------------------------------------- sub regist { local($sub,$key,$flg,$i,@top); # 権限チェック if ($authkey && $my_rank < 2) { &error("投稿の権限がありません$my_rank"); } # POST限定 if ($postonly && !$postflag) { &error("不正なアクセスです"); } # チェック if ($no_wd) { &no_wd; } if ($jp_wd) { &jp_wd; } if ($urlnum > 0) { &urlnum; } # コメント文字数チェック if (length($i_com) > $max_msg*2) { &error("文字数オーバーです。全角$max_msg文字以内で記述してください"); } # 汚染チェック $in{'res'} =~ s/\D//g; # 投稿内容チェック if ($i_com eq "") { &error("コメントの内容がありません"); } if ($i_nam eq "") { if ($in_name) { &error("名前は記入必須です"); } else { $i_nam = '名無しのゴンベエ'; } } if ($in_mail && $in{'email'} eq "") { &error("E-mailは記入必須です"); } if ($in{'email'} && $in{'email'} =~ /^[\w\.\-]+\@[\w\.\-]+\.[a-zA-Z]{2,6}$/) { &error("E-mailの入力内容が不正です"); } if ($i_sub eq "") { &error("タイトルは記入必須です"); } if ($i_sub =~ /^(\x81\x40|\s)+$/) { &error("タイトルは正しく記入してください"); } if ($i_nam =~ /^(\x81\x40|\s)+$/) { &error("名前は正しく記入してください"); } if ($i_com =~ /^(\x81\x40|\s|)+$/) { &error("コメントは正しく記入してください"); } if ($in_pwd && $in{'pwd'} eq "") { &error("パスワードは入力必須です"); } if (length($in{'pwd'}) > 8) { &error("パスワードは8文字以内にして下さい"); } if ($in{'url'} eq "http://") { &error("記入できません"); } # トリップ $i_nam2 = &trip($i_nam); # パスワード暗号化 if ($in{'pwd'} eq "") { $pwd = ""; } else { $pwd = &encrypt($in{'pwd'}); } #▼ここから▼ # ファイルアップ local($upl_flg, %ex, %w ,%h); if ($in{'upfile1'} || $in{'upfile2'} || $in{'upfile3'}) { require $upload; ($ex{1},$w{1},$h{1},$ex{2},$w{2},$h{2},$ex{3},$w{3},$h{3}) = &upload($time); # 画像アップのときはフラグを立てる if ($ex{1} || $ex{2} || $ex{3}) { $upl_flg = $time; } } #▲ここまで追加▲ # 新規投稿(新規スレッド作成) if ($in{'res'} eq "") { # indexファイル local($i, $flg, $top, @new, @tmp, @top); open(DAT,"+< $nowfile") || &error("Open Error: $nowfile"); eval "flock(DAT, 2);"; $top = ; # 連続投稿IPチェック local($no,$ho,$t) = split(/<>/, $top); if ($host eq $ho && $wait > time - $t) { close(DAT); &error("連続投稿はもうしばらく時間をおいて下さい"); } $new = $no + 1; # index展開 while() { local($sub,$key) = (split(/<>/))[1,6]; $i++; if ($sub eq $in{'sub'}) { $flg++; last; } elsif ($key == 2) { push(@top,$_); next; } if ($i >= $i_max) { push(@tmp,$_); } else { push(@new,$_); } } # スレッド名重複チェック if ($flg) { close(DAT); &error("「$in{'sub'}」は既存スレッドと重複しています。別のスレッド名を指定してください"); } # ファイルアップ #local($upl_flg, %ex, %w ,%h); #if ($in{'upfile1'} || $in{'upfile2'} || $in{'upfile3'}) { #require $upload; #($ex{1},$w{1},$h{1},$ex{2},$w{2},$h{2},$ex{3},$w{3},$h{3}) = &upload($time); # 画像アップのときはフラグを立てる #if ($ex{1} || $ex{2} || $ex{3}) { $upl_flg = $time; } #} # 現行index更新 unshift(@new,"$new<>$i_sub<>0<>$i_nam2<>$date<>$i_nam2<>1<>$upl_flg<>\n"); unshift(@new,@top) if (@top > 0); unshift(@new,"$new<>$host<>$time<>\n"); seek(DAT, 0, 0); print DAT @new; truncate(DAT, tell(DAT)); close(DAT); # 過去index更新 if (@tmp > 0) { $i = @tmp; open(DAT,"+< $pastfile") || &error("Open Error: $pastfile"); eval "flock(DAT, 2);"; while() { $i++; if ($i > $p_max) { local($delno) = split(/<>/); unlink("$logdir/$delno.cgi"); unlink("$logdir/$delno.dat"); next; } push(@tmp,$_); } seek(DAT, 0, 0); print DAT @tmp; truncate(DAT, tell(DAT)); close(DAT); } # スレッド更新 open(OUT,">$logdir/$new.cgi") || &error("Write Error: $new.cgi"); print OUT "$new<>$i_sub<>0<>1<>\n"; print OUT "0<>$in{'sub'}<>$i_nam2<>$in{'email'}<>$i_com<>$date<>$host<>$pwd<>$in{'url'}<>$in{'mvw'}<>$my_id<>$time<>$ex{1},$w{1},$h{1}<>$ex{2},$w{2},$h{2}<>$ex{3},$w{3},$h{3}<>\n"; close(OUT); # 参照ファイル生成 open(NO,">$logdir/$new.dat") || &error("Write Error: $new.dat"); print NO "0:"; close(NO); # パーミッション変更 chmod(0666, "$logdir/$new.cgi"); chmod(0666, "$logdir/$new.dat"); &sendmail if ($mailing); # 返信投稿 } else { # 参照ファイル local($data); open(IN,"$logdir/$in{'res'}.dat"); $data = ; close(IN); ($count) = split(/:/, $data); # 連続投稿チェック local($top); open(IN,"$nowfile") || &error("Open Error: $nowfile"); $top = ; close(IN); local($no,$hos2,$tim2) = split(/<>/, $top); if ($host eq $hos2 && $wait > time - $tim2) { &error("連続投稿はもうしばらく時間をおいて下さい"); } # スレッド読み込み open(DAT,"+< $logdir/$in{'res'}.cgi") || &error("Open Error: $in{'res'}.cgi"); eval "flock(DAT, 2);"; local(@file) = ; # 先頭ファイルを抽出・分解 $top = shift(@file); local($no,$sub,$res,$key) = split(/<>/, $top); # ロックチェック if ($key eq '0' || $key eq '2') { close(DAT); &error("このスレッドはロック中のため返信できません"); } # 末尾ファイルを分解、重複チェック local($no2,$sb2,$na2,$em2,$co2) = split(/<>/, $file[$#file]); if ($i_nam2 eq $na2 && $i_com eq $co2) { &error("重複投稿は禁止です"); } # 採番 $newno = $no2 + 1; # 記事数チェック if ($m_max < $res+1) { &error("最大記事数をオーバーしたため投稿できません"); } elsif ($m_max == $res+1) { $maxflag = 1; } else { $maxflag = 0; } # ファイルアップ local($upl_flg, %ex, %w ,%h); if ($in{'upfile1'} || $in{'upfile2'} || $in{'upfile3'}) { require $upload; ($ex{1},$w{1},$h{1},$ex{2},$w{2},$h{2},$ex{3},$w{3},$h{3}) = &upload($time); } # スレッド更新 $res++; unshift(@file,"$no<>$sub<>$res<>1<>\n"); push(@file,"$newno<>$in{'sub'}<>$i_nam2<>$in{'email'}<>$i_com<>$date<>$host<>$pwd<>$in{'url'}<>$in{'mvw'}<>$my_id<>$time<>$ex{1},$w{1},$h{1}<>$ex{2},$w{2},$h{2}<>$ex{3},$w{3},$h{3}<>\n"); ## ←修正 seek(DAT, 0, 0); print DAT @file; truncate(DAT, tell(DAT)); close(DAT); ## 規定記事数オーバのとき ## if ($maxflag) { # 過去ログindex読み込み open(BAK,"+< $pastfile") || &error("Open Error: $pastfile"); eval "flock(BAK, 2);"; local(@file) = ; # 現行ログindexから該当スレッド抜き出し local($top, @new); open(DAT,"+< $nowfile") || &error("Open Error: $nowfile"); eval "flock(DAT, 2);"; $top = ; while() { s/\n//; local($no,$sub,$re,$nam,$d,$na2,$key,$upl) = split(/<>/); if ($in{'res'} == $no) { $re++; unshift(@file,"$no<>$sub<>$re<>$nam<>$date<>$na2<>1<>$upl<>\n"); next; } push(@new,"$_\n"); } # 現行ログindex更新 unshift(@new,$top); seek(DAT, 0, 0); print DAT @new; truncate(DAT, tell(DAT)); close(DAT); # 過去ログindex更新 seek(BAK, 0, 0); print BAK @file; truncate(BAK, tell(BAK)); close(BAK); ## ソートあり ## } elsif ($in{'sort'} == 1) { # indexファイル更新 local($flg, $top, @new, @top); open(DAT,"+< $nowfile") || &error("Open Error: $nowfile"); eval "flock(DAT, 2);"; $top = ; while() { s/\n//; local($no,$sub,$re,$nam,$da,$na2,$key,$upl) = split(/<>/); if ($key == 2) { push(@top,"$_\n"); next; } if ($in{'res'} == $no) { $flg = 1; $new = "$in{'res'}<>$sub<>$res<>$nam<>$date<>$i_nam2<>1<>$upl<>\n"; next; } push(@new,"$_\n"); } if (!$flg) { &error("該当のスレッドがindexファイルに見当たりません"); } local($no2,$host2,$time2) = split(/<>/, $top); unshift(@new,$new); unshift(@new,@top) if (@top > 0); unshift(@new,"$no2<>$host<>$time<>\n"); seek(DAT, 0, 0); print DAT @new; truncate(DAT, tell(DAT)); close(DAT); ## ソートなし ## } else { # indexファイル更新 local($flg, $top, @new); open(DAT,"+< $nowfile") || &error("Open Error: $nowfile"); eval "flock(DAT, 2);"; $top = ; while() { s/\n//; local($no,$sub,$re,$nam,$da,$na2,$key,$upl) = split(/<>/); if ($in{'res'} == $no) { $flg = 1; $_ = "$in{'res'}<>$sub<>$res<>$nam<>$date<>$i_nam2<>1<>$upl<>"; } push(@new,"$_\n"); } if (!$flg) { &error("該当のスレッドがindexファイルに見当たりません"); } local($no2,$host2,$time2) = split(/<>/, $top); unshift(@new,"$no2<>$host<>$time<>\n"); seek(DAT, 0, 0); print DAT @new; truncate(DAT, tell(DAT)); close(DAT); } # メール送信 &sendmail if ($mailing == 2); } # クッキーを格納 if ($in{'cook'} eq "on") { &set_cookie($i_nam,$in{'email'},$in{'pwd'},$in{'url'},$in{'mvw'}); } # 完了メッセージ &header; $md = 'view'; if ($in{'res'} eq "") { $no = $new; } else { $no = $in{'res'}; } print < ご投稿ありがとうございました EOM # 過去ログ繰り越しの場合 if ($maxflag) { print "ただし1スレッド当りの最大記事数を超えたため、\n"; print "このスレッドは 過去ログ "; print "へ移動しました。\n"; $md = 'past'; } # 戻りフォーム print <<"EOM";
EOM # 過去ログ繰り越しの場合 if ($maxflag) { print "ただし1スレッド当りの最大記事数を超えたため、\n"; print "このスレッドは 過去ログ "; print "へ移動しました。\n"; $md = 'past'; } # 戻りフォーム print <<"EOM";