#!/usr/bin/perl #------------------------------- # pad.cgi (ShiftJIS) # 2008. 8.18 MIYAMORI Yoshimasa # 1999. 2.13 MIYAMORI Yoshimasa #------------------------------- require 'padres.pl'; require $myReqPadlib; require $myReqJcode; $myTitle = $padresMyTitle; $myUrl = $padresMyUrl . 'pad.cgi'; &main; exit; sub main { local($i, $s, $text); if ($ENV{'REQUEST_METHOD'} eq 'HEAD') { &dispMsg('Request method: HEAD.'); return; } if (&chkBusy) { &dispMsg($myMsgBusy); return; } &setBusy(1); if (&chkEnv) { &dispMsg($myMsgDeny); &setBusy(0); return; } &parseQry(*in); if (&chkBody($in{'body'})) { &dispMsg($myMsgSpam); &setBusy(0); return; } $in{'hp'} = '' if ($in{'hp'} eq 'http://'); if ($in{'log'}) { local($n); $n = $in{'log'}; if ($n eq 'pad') { &dispPad; } else { if ($n eq 'z') { $n = 0; } else { $n = $in{'log'}; } unless (-f $logFile[$n]) { &dispMsg($myMsgLogNotFound); } else { &dispLog($n); } } &setBusy(0); return; } if ($ENV{'QUERY_STRING'} =~ /^ref/) { local($dummy, $n); ($dummy, $n) = split(/=/, $ENV{'QUERY_STRING'}, 2); &dispRefForm($n, "

$myMsgRef

"); &setBusy(0); return; } if (!$in{'name'}) { if (!$in{'body'}) { if ((!$in{'ml'}) && (!$in{'hp'}) && (!$in{'subj'})) { &dispPad; } else { &dispMsg($myMsgNameBody); } } else { &dispForm("

$myMsgName

", $in{'body'}); } &setBusy(0); return; } elsif (!$in{'body'}) { &dispMsg($myMsgBody); &setBusy(0); return; } $text = join('', $in{'name'}, $in{'ml'}, $in{'hp'}, $in{'subj'}, $in{'body'}); $i = &chkHtml($text); if ($i) { &dispMsg($myMsgTagBad) if ($i == 1); &dispMsg($myMsgTagOpen) if ($i == 2); &setBusy(0); return; } $text = &setText; if ($in{'preview'}) { $s = sprintf("

%s


\n%s", $myMsgPost, $text); &dispForm($s, $in{'body'}); } else { $s = join(',', $in{'name'}, $in{'ml'}, $in{'hp'}, $in{'subj'}, $in{'body'}); if (&chkQry(time, $s)) { &dispMsg($myMsgSame); &setBusy(0); return; } &putText($text); &dispPad; } &setBusy(0); return; } # 書き出す文字列を作る. sub setText { local($cnt, $name, $ml, $hp, $subj, $body); local($s1, $s2, $s3, $s4, $s5, $s6, $s7, $s8, $s9); $name = $in{'name'}; $ml = $in{'ml'}; $hp = $in{'hp'}; $subj = $in{'subj'}; $body = $in{'body'}; $subj = $in{'ref_subj'} unless ($subj); $ml = &getName($name, 1) unless ($ml); $hp = &getName($name, 2) unless ($hp); $cnt = &getCount; $s1 = sprintf("\n%03d: ", $cnt, $cnt, $cnt); if ($subj) { $s2 = sprintf("%s -- ", $subj); } else { $s2 = ''; } if ($hp) { $s3 = sprintf("\n%s", $hp, $name); } else { $s3 = sprintf("\n%s", $name); } $s4 = sprintf(" -- %s --\n\n\n", &getDate(0), $name, $subj); $s5 = sprintf("%s
\n", $PAD_TEXT);
  $s6 = sprintf("%s
\n
", $PAD_TEXT_END); if ($ml) { $s7 = sprintf("%s ", $ml, $ml); } $s8 = sprintf("\n%s
\n", $myUrl, $cnt, $myMsgReply); $s9 = sprintf("%s\n
\n\n", $PAD_REPLY, $cnt); return(join('', $s1,$s2,$s3,$s4,$s5,$body,"\n",$s6,$s7,$s8,$s9)); } # $PAD_TOP の位置に 新しく発言内容を書く. # $myPadLimit(50か100) ごとにファイルを分割する. sub putText { local($text) = @_; local($padLimit, $s, $c, $i); $c = &getCount; if (($c % $myPadLimit) == 1) { $i = &getLogNum($c); if ($i) { &clearPad($i - 1); } else { if ($myPadLimit == 100) { &clearPad(9); } else { &clearPad(19); } } } open(TMP, "|$myOut >$tmpFile") || &exitPadCgi('error: putText().'); open(FILE, "$myIn <$padFile |") || &exitPadCgi('error: putText().'); while () { if (/^$PAD_TOP/io) { print TMP $PAD_TOP, "\n", $text; last; } else { print TMP $_; } } while () { print TMP $_; } close TMP; close FILE; $s = "mv $tmpFile $padFile"; system($s); chmod $myChmod, $padFile; $c++; $c = 0 if ($c > 999); &putCount($c); } # コメント用のフォームを表示. sub dispRefForm { local($ref, $msg) = @_; local($line, $name, $subj, $text); # $nameは現在使っていない. local($num, $s, $flg, $flg2); if (&isInPad($ref)) { open(FILE, "$myIn <$padFile |") || &exitPadCgi('error: dispRefForm().'); if ((&getCount % $myPadLimit) == 1) { # 改ページのタイミング. $num = &getLogNum($ref); } else { $num = -1; } } else { $num = &getLogNum($ref); open(FILE, "$myIn <$logFile[$num] |") || &exitPadCgi('error: dispRefForm().'); } $flg = 0; # 0:引用前. 1:引用中. 2:reply部分引用中. 3:引用後. $name = ''; $subj = ''; $text = ''; $s = sprintf("", $ref); while () { last if ($flg == 3); $line = $_; if ($flg == 0) { if (/^$s/) { $flg = 1; $flg2 = 0; } } elsif ($flg == 1) { if (/^$PAD_TEXT/io) { $flg2 = 1; } elsif (/^$PAD_TEXT_END/io) { $flg2 = 0; } elsif (/^$PAD_TEXT_REPLY/io) { $flg2 = 1; $text .= "\n"; } elsif (/^$PAD_TEXT_REPLY_END/io) { $flg2 = 0; $flg = 3; } elsif (/^$PAD_REPLY/io) { $flg = 3; } elsif (/^/) { $flg = 3; } elsif (/^\n//; $name = $line; $name = &toNum($name); } elsif (/^\n//; $subj = $line; $subj = &toNum($subj); } else { if ($flg2) { $text = $text . ' >' . $line; } } } } close FILE; $in{'ref_name'} = $name; if ($subj) { $in{'ref_subj'} = 'Re:' . $subj; $in{'ref_subj'} =~ s/^Re:Re:/Re:/; } else { $in{'ref_subj'} = ''; } if ($num >= 0) { $s = $urlLogFile[$num]; } else { $s = ''; } $text = "#$ref" . "\n" . $text; &dispForm($msg, $text); } # フォームを表示する関数. # $msg1 をフォームの上に, # $msg2をフォームの TEXTAREA に表示する. sub dispForm { local($msg1, $msg2) = @_; local($ref_name, $ref_subj); local($name, $ml, $hp, $subj); $ref_name = $in{'ref_name'}; # この2つは 隠しフィールド用. $ref_subj = $in{'ref_subj'}; $name = $in{'name'}; $ml = $in{'ml'}; $hp = $in{'hp'}; $hp = 'http://' unless ($hp); $subj = $in{'subj'}; $ref_name = &toNum($ref_name); $ref_subj = &toNum($ref_subj); $name = &toNum($name); $ml = &toNum($ml); $hp = &toNum($hp); $subj = &toNum($subj); $msg2 = &toNum($msg2); print <<"EndOfFile"; Content-type: text/html\n $myHead $myTitle $myBody $msg1
名前:
メール:
ホームページ:
タイトル:
本文:



コメント動作で元発言にタイトルが付いていた場合, タイトル空欄で「Re:元タイトル」となります.

$myMsgBack EndOfFile } # $n 番目の過去ログを作る. 書き込みの無い状態に戻す. # $PAD_BOTTOM の位置に 前のページへのリンクを書く. sub clearPad { local($n) = @_; local($s); $s = "cp $padFile $logFile[$n]"; system($s); chmod $myChmod, $logFile[$n]; open(LOG, "$myIn <$logFile[$n] |") || &exitPadCgi('error: clearPad().'); open(FILE, "|$myOut >$padFile") || &exitPadCgi('error: clearPad().'); while () { print FILE $_; last if (/^$PAD_TOP/io); } while () { if (/^$PAD_BOTTOM/io) { print FILE $PAD_BOTTOM, "$myMsgPrev\n"; last; } } while () { print FILE $_; } close LOG; close FILE; chmod $myChmod, $padFile; } # $qryFile を読んで その内容を返す. # 無ければ '' を返す. sub getQryFile { local($text); local($s); $text = ''; if (-f $qryFile) { open(FILE, "$myIn <$qryFile |") || &exitPadCgi('error: getQryFile().'); $text = ; ($s, $text) = split(',', $text, 2); while () { $s = $_; last if ($s =~ /^$PAD_LAST/io); $text .= $s; } chop($text); close FILE; } return($text); } # $qryFile の最新の内容と $s を比較する. # 同じとき 1 を返す. # 異なるとき $qryFile を更新して 0 を返す. sub chkQry { local($time, $s) = @_; local($t); $t = &getQryFile; return(1) if ($s eq $t); &putQryFile($time, $s); return(0); } # $time と $text を $qryFile に書き出す. # $qryFile は 400行まで. sub putQryFile { local($time, $text) = @_; local($i, $s); open(TMP, "|$myOut >$tmpFile") || &exitPadCgi('error: putQryFile().'); if (-f $qryFile) { open(FILE, "$myIn <$qryFile |") || &exitPadCgi('error: putQryFile().'); print TMP $time, ',', $text, "\n", $PAD_LAST, "\n"; $i = 0; while () { last if (/^$PAD_LAST/io); print TMP $_; $i++; last if ($i >= 400); } while () { print TMP $_; $i++; last if ($i >= 400); } close FILE; } else { print TMP $text, "\n", $PAD_LAST, "\n"; } close TMP; $s = "mv $tmpFile $qryFile"; system($s); chmod $myChmod, $qryFile; }