200X/00/19
はっきり言って!!!!!!めちゃ完成(*^_^*)
ちょこっとプログラムは長くなったけど・・・
とっても満足(⌒^⌒)bうふっ
まぁ・・・プログラムみてもどうって事無いでしょうが(*^^*ゞ
一応記録の為に下記に記載(改行タグの部分はちゃんと表示されてません)
#!/usr/local/bin/perl
require './jcode.pl';
print "Content-type: text/html\n\n";

#カウンター観覧者ログGETの処理ーーーーーーーーーーーーーーー
if ($ENV{'REQUEST_METHOD'} ne "POST") {
$ip = $ENV{'REMOTE_ADDR'};
$reurl = $ENV{'HTTP_REFERER'};
$host = $ENV{'REMOTE_HOST'};
$bura = $ENV{'HTTP_USER_AGENT'};

( $byou, $hun, $ji, $hi, $tuki, $toshi, $you ) = localtime( time );
$hyouji = sprintf( "%04d年%02d月%02d日",$toshi + 1900, $tuki + 1, $hi );
$youbi = sprintf( "(%s)", ( "日", "月", "火", "水", "木", "金", "土")[$you] );
$jikan = sprintf( "%02d時%02d分%02d秒", $ji, $hun, $byou );

$suuji = "./suuji.txt";

foreach( 1..5) {
if( mkdir($lock, 0755 ) ){
last;
}
else{
sleep( 1 );
}
}
open(SUUJI, "+<$suuji");
@suuji = <SUUJI>;
$kau = $suuji[0] +1;
$suujidata = $kau."\t".$hyouji."\t".$youbi."\t".$jikan."\t".$ip."\t".$reurl."\t".$host."\t".$bura."\n";
unshift( @suuji, $suujidata );
foreach( 300..$#suuji ){
pop @suuji;
}
seek( SUUJI, 0, 0 );
print SUUJI @suuji;
truncate( SUUJI, tell( SUUJI ));
close( SUUJI );
rmdir( $lock );
}
#フォームからのデータ処理--------------------------------------------------
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $naka, $ENV{"CONTENT_LENGTH"});

( $byou, $hun, $ji, $hi, $tuki, $toshi, $you ) = localtime( time );
$hyouji = sprintf( "%04d年%02d月%02d日",$toshi + 1900, $tuki + 1, $hi );
$youbi = sprintf( "(%s)", ( "日", "月", "火", "水", "木", "金", "土")[$you] );
$jikan = sprintf( "%02d時%02d分%02d秒", $ji, $hun, $byou );

$ip = $ENV{'REMOTE_ADDR'};
$reurl = $ENV{'HTTP_REFERER'};
$host = $ENV{'REMOTE_HOST'};
$bura = $ENV{'HTTP_USER_AGENT'};

@nakami = split('&', $naka);

foreach(@nakami) {
($hidari, $migi) = split("=");
$migi =~ tr/+/ /;
$migi =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;

$migi =~ s/\r?\n/
/g;
$migi =~ s/
/
/gi;
&jcode'convert( *migi, 'sjis' );
$kaku{$hidari} = $migi;
}

$name = $kaku{'name'};
$memo = $kaku{'memo'};
$address = $kaku{'address'};
$url = $kaku{'url'};
$dai = $kaku{'dai'};
$resf = $kaku{'resf'};#レスフォームスイッチ
$no = $kaku{'no'};#ログ参照番号
$res = $kaku{'res'};#レスフォームからの送信スイッチ
$rname = $kaku{'rname'};
$rdai = $kaku{'rdai'};
$raddress = $kaku{'raddress'};
$rurl = $kaku{'rurl'};
$rmemo = $kaku{'rmemo'};
$logfile = "./logfile.txt";
$kanrifile = "./kanrifile.txt";
#二重カキコ参照用に管理ファイルのデータを変数メモ1にしておくーーーーーーーーーーーーー
open( NIJYUU, "$kanrifile");
$nijyuu = <NIJYUU>;
( $a1, $b2, $memo1,$d4, $e5, $f6, $g7, $h8, $i9, $j0, ) = split( /\t/, $nijyuu );
close( NIJYUU );
#レスフォームのスイッチが入ったらサブルーチン$resfへーーーーーーーーーーーーーーーーーー
if($resf eq 'resf' ) {
&resf( "$no" );
exit;
}
#レスフォームから送信が有ったらーーーーーーーーーーーーーーーーーーーーーーーーーーーー
$resdata = "<dl><dt><font size='2'><b>$rdai</b> name: <b><a href='mailto:$raddress'>$rname</a> </b>\[ $hyouji$youbi$jikan ] <a href='$rurl'>[HOME]</a></dt><dd>
$rmemo</font></dd></dl>";
if($res eq 'res' ) {
&res( "$no" );
exit;
}
#二重カキコ処理と未記入エラーの処理------------------------------------------------------
if ($name eq "" or $memo eq ""){
$error="名前かカキコが未記入です(*^^*ゞ。";
}
elsif($memo eq $memo1){
$error="エラーで〜す!2重投稿になっちゃいました(*^^*ゞ。";
}
#普通書き込み処理ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
else{
foreach( 1..5) {
if( mkdir($lock, 0755 ) ){
last;
}
else{
sleep( 1 );
}
}
open(LOGFILE, "+<$logfile");
@logs = <LOGFILE>;
$ban = @logs[0]+1;
$memo =~ s/\r?\n/
/g;
$logdata = $ban."\t".$dai."\t".$address."\t".$name."\t".$hyouji."\t".$youbi."\t".$jikan."\t".$url."\t".$memo."\n";
unshift( @logs, $logdata );

foreach( 15..$#logs ){
pop @logs;
}

seek( LOGFILE, 0, 0 );
print LOGFILE @logs;
truncate( LOGFILE, tell( LOGFILE ));
close( LOGFILE );

open(KANRIFILE, "+<$kanrifile");
@kanri = <KANRIFILE>;
$nan = $kanri[0] +1;
$kanridata = $nan."\t".$name."\t".$memo."\t".$hyouji."\t".$youbi."\t".$jikan."\t".$ip."\t".$reurl."\t".$host."\t".$bura."\n";
unshift( @kanri, $kanridata );
foreach( 100..$#kanri ){
pop @kanri;
}
seek( KANRIFILE, 0, 0 );
print KANRIFILE @kanri;
truncate( KANRIFILE, tell( KANRIFILE ));
close( KANRIFILE );

rmdir( $lock );
}
}

#頭の部分表示HTML吐き出し部分ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
print <<MAMA;
<META HTTP-EQUIV="Content-type"CONTENT="text/html"CHARSET="Shift_JIS">
<HTML>
<HEAD>
<TITLE>お気軽掲示板</TITLE>
<STYLE TYPE="text/css">
<!--
A:hover { color: red; }
a {text-decoration:none}
-->
</STYLE>
</HEAD>
MAMA
#カウンター表示ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
$suuji = "./suuji.txt";
open( KAUNTA, "$suuji");
$kaunta = <KAUNTA>;
( $aa, $bb, $dd, $ee, $ff, $gg, $hh, $ii ) = split( /\t/, $kaunta );
close( KAUNTA );
print "<font size='2'><b>$aa</b></font>
";
#フォーム表示ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
print <<MAMA;
<BODY vlink="#000000" link="#000000" >
<hr>
<center><font size="+1"><b>TEST-BBS</b></font></center>
<FORM METHOD="POST" ACTION=\"****.cgi\" \n>
<center><table border="0" align="center" width="400">
<tr><td align="center">
<b>お名前</b><font size="2">(省略不可)</font><INPUT NAME="name" SIZE="45"></td></tr>
<tr><td align="center">
<b>題名.......</b><font size="2">(省略可)</font><INPUT NAME="dai" SIZE="45" value="no title"></td></tr>
<tr><td align="center">
<b>e-mail...</b><font size="2">(省略可)</font><INPUT NAME="address" SIZE="45"></td></tr>
<tr><td align="center">
<b>URL......</b><font size="2">(省略可)</font><INPUT NAME="url" SIZE="45" VALUE="http://"></td></tr></tr>
<tr><td align="center">
<TEXTAREA NAME="memo" ROWS ="5" COLS="54"></TEXTAREA></tr></td>
<tr><td align="center"><font size="2">(タグ有効)無茶なタグは打たないで下さい、壊れやすい掲示板(*^^*ゞ</font>

<INPUT TYPE="submit" VALUE="送信" > <INPUT TYPE="reset" VALUE="取り消し"></tr></td>
</table></center>
</FORM>
MAMA
#エラーメッセの表示個所ーーーーーーーーーーーーーーーーーーーーーーーーーーー
print "<CENTER><font><B>$error</B></font>
</CENTER>";

#カキコ表示部分ログファイルの参照ーーーーーーーーーーーーーーーーーーー
$logfile = "./logfile.txt";
open(LOGFILE, "$logfile");
@logs = <LOGFILE>;
foreach $kakiko ( @logs ){

chomp( $kakiko );
( $ban, $dai, $address, $name, $hyouji, $youbi, $jikan, $url, $memo, ) = split( /\t/, $kakiko, );

if($a > 15 ){
$a = 0;
}
$a += 1;
$b = $a - 1;
print <<MAMA;
<center>
<table width='600' border='2'>
<tr><td width="95%">
<font size='2'>[$ban]</font> <b><font size='2'>$dai</font></b> </font>
<font size='2'>name: <b><a href='mailto:$address'>$name</a> </b>
\[ $hyouji$youbi$jikan ] 
<a href='$url'>[HOME]</a></td>
</font>
<td align='center' width='15%'>
<FORM METHOD="POST" ACTION=\"******.cgi\" \n>
<input type=hidden name=resf value="resf">
<input type=hidden name=no value=$b>
<input type=submit value="返信">
</td></tr>
<td colspan='2'><font color='$color'><blockquote><font size="2">
$memo</font></blockquote></font></td></tr>
</table></form>
</center>
MAMA
}
close( LOGFILE );
#偉そうに著作権の表示(*^^*ゞーーーーーーーーーーーーーーー
print "<center>Copyright(C) tensyu</center>";
print "</html>";
print "</body>";

#返信ボタンが押されたときのサブルーチンーーーーーーーーーーーーーーーーーーーーーーーーー
sub resf {
my( $resmsg ) = @_;

$logfile = "./logfile.txt";
open(LOGFILE, "$logfile");
@logs = <LOGFILE>;
($ban, $dai, $address, $name, $hyouji, $youbi, $jikan, $url, $memo ) = split(/\t/,$logs[$resmsg] );
close (LOGFILE);

print <<MAMA;
<BODY vlink="#000000" link="#000000">
<center>
<table width='600' border='2'>
<tr><td>
<font size="2">[$ban]</font> <b>$dai</b> 
<font size='2'>name: <b><a href='mailto:$address'>$name</a> </b>
\[ $hyouji$youbi$jikan ] 
<a href='$url'>[HOME]</a></td></font>
</tr><td colspan='2'><font color='$color'><blockquote>$memo</blockquote></font></td></tr>
</table></form>
</center>
MAMA

print <<MAMA;

<center><font size="+1"><b>↑返信フォームです。</b></font></center>
<FORM METHOD="POST" ACTION=\"*****.cgi\" \n>
<input type=hidden name=res value="res">
<input type=hidden name=no value=$resmsg>
<center><table border="0" align="center" width="400">
<tr><td align="center">
<b>お名前</b><font size="2">(省略不可)</font><INPUT NAME="rname" SIZE="45"></td></tr>
<tr><td align="center">
<b>題名.......</b><font size="2">(省略可)</font><INPUT NAME="rdai" SIZE="45" value="RE:$dai"></td></tr>
<tr><td align="center">
<b>e-mail...</b><font size="2">(省略可)</font><INPUT NAME="raddress" SIZE="45"></td></tr>
<tr><td align="center">
<b>URL......</b><font size="2">(省略可)</font><INPUT NAME="rurl" SIZE="45" VALUE="http://"></td></tr></tr>
<tr><td align="center">
<TEXTAREA NAME="rmemo" ROWS ="5" COLS="54"></TEXTAREA></tr></td>
<tr><td align="center"><font size="2">(タグ有効)無茶なタグは打たないで下さい、壊れやすい掲示板(*^^*ゞ</font>

<INPUT TYPE="submit" VALUE="送信" > <INPUT TYPE="reset" VALUE="取り消し"></tr></td>
</table></center>

</FORM>
</body></html>
MAMA
}
#返信フォームからのログ書き換えのサブルーチン--------------------------------
sub res {
my( $resmsg ) = @_;

$logfile = "./logfile.txt";
foreach( 1..5) {
if( mkdir($lock, 0755 ) ){
last;
}
else{
sleep( 1 );
}
}
$logfile = "./logfile.txt";
open(LOGFILE, "+<$logfile");
@logs = <LOGFILE>;
chomp( $logs[$resmsg] );
($ban, $dai, $address, $name, $hyouji, $youbi, $jikan, $url, $memo ) = split(/\t/,$logs[$resmsg] );
$logs[$resmsg] =$ban."\t".$dai."\t".$address."\t".$name."\t".$hyouji."\t".$youbi."\t".$jikan."\t".$url."\t".$memo.$resdata."\n";
seek( LOGFILE, 0, 0 );
print LOGFILE @logs;
truncate( LOGFILE, tell( LOGFILE ));
close( LOGFILE );
rmdir( $lock );

print <<MAMA;
<META HTTP-EQUIV="Content-type"CONTENT="text/html"CHARSET="Shift_JIS">
<HTML>
<HEAD>
<TITLE>お気軽掲示板</TITLE>
<STYLE TYPE="text/css">
<!--
A:hover { color: red; }
a {text-decoration:none}
-->
</STYLE>
</HEAD>
MAMA
$suuji = "./suuji.txt";
open( KAUNTA, "$suuji");
$kaunta = <KAUNTA>;
( $aa, $bb, $dd, $ee, $ff, $gg, $hh, $ii ) = split( /\t/, $kaunta );
close( KAUNTA );
print "<font size='2'><b>$aa</b></font>
";
print <<MAMA;
<BODY vlink="#000000" link="#000000" >
<hr>
<center><font size="+1"><b>TEST-BBS</b></font></center>
<FORM METHOD="POST" ACTION=\"*****.cgi\" \n>
<center><table border="0" align="center" width="400">
<tr><td align="center">
<b>お名前</b><font size="2">(省略不可)</font><INPUT NAME="name" SIZE="45"></td></tr>
<tr><td align="center">
<b>題名.......</b><font size="2">(省略可)</font><INPUT NAME="dai" SIZE="45" value="no title"></td></tr>
<tr><td align="center">
<b>e-mail...</b><font size="2">(省略可)</font><INPUT NAME="address" SIZE="45"></td></tr>
<tr><td align="center">
<b>URL......</b><font size="2">(省略可)</font><INPUT NAME="url" SIZE="45" VALUE="http://"></td></tr></tr>
<tr><td align="center">
<TEXTAREA NAME="memo" ROWS ="5" COLS="54"></TEXTAREA></tr></td>
<tr><td align="center"><font size="2">(タグ有効)無茶なタグは打たないで下さい、壊れやすい掲示板(*^^*ゞ</font>

<INPUT TYPE="submit" VALUE="送信" > <INPUT TYPE="reset" VALUE="取り消し"></tr></td>
</table></center>
</FORM>
MAMA
print "<CENTER><font><B>$error</B></font>
</CENTER>";
$logfile = "./logfile.txt";
open(LOGFILE, "$logfile");
@logs = <LOGFILE>;
foreach $kakiko ( @logs ){

chomp( $kakiko );
( $ban, $dai, $address, $name, $hyouji, $youbi, $jikan, $url, $memo, ) = split( /\t/, $kakiko, );

if($a > 15 ){
$a = 0;
}
$a += 1;
$b = $a - 1;
print <<MAMA;
<center>
<table width='600' border='2'>
<tr><td width="95%">
<font size='2'>[$ban]</font> <b><font size='2'>$dai</font></b> </font>
<font size='2'>name: <b><a href='mailto:$address'>$name</a> </b>
\[ $hyouji$youbi$jikan ] 
<a href='$url'>[HOME]</a></td>
</font>
<td align='center' width='15%'>
<FORM METHOD="POST" ACTION=\"bbss4-2.cgi\" \n>
<input type=hidden name=resf value="resf">
<input type=hidden name=no value=$b>
<input type=submit value="返信">
</td></tr>
<td colspan='2'><font color='$color'><blockquote><font size="2">
$memo</font></blockquote></font></td></tr>
</table></form>
</center>
MAMA
}
close( LOGFILE );
print "<center>Copyright(C) tensyu</center>";
print "</html>";
print "</body>";


}
#以上おしまいーーーーーーーーーーーーーーーーー
exit;