#!/usr/local/bin/perl

# \i̓p[~bV()͏LҌCGIT[ȍꍇj
#|-- tl10.cgi    755(700)
#|-- jcode.pl    644(600)
#|-- bbs.dat     666(600)
#|-- count.txt   666(600)
#
#₫Cg̓Vvȋ@\̈sfłB
#gpAAĔzzɈ؂̐͂܂B
#08/24 2000 ^ӐT
############################### ݒ ###############################

$title = 'vR펺';     # f̖O

$bbsurl = './tl10.cgi';     # ̃XNvgURLiΎwj

$bbsfile = './bbs.dat';    # L^t@C̃pX

$counterfile = './count.txt';  # JE^t@C̃pX

$jcpl = './jcode.pl';          # {R[hϊCũpX

# oHTML̕Fwii{fB^Oj
$body = '<body text="#000000" bgcolor="#aabbcc" link="#1775a2" vlink="#1775a2" alink="#cc0000">';

$namecolor = '#d53d8e';        # O̐F

$textcolor = '#333333';        # e̐F

$datecolor = '#666666';        # e̐F

$max = 100;                    # \

$maxlength = 3*1024;           # ̓f[^v̍ől(byte)

$time_dif = 9*60*60;           # OjbWWƂ̎i{Ԃ\ꍇ9*60*60j

############################### S̏ ###############################

&get_time;
if ($ENV{'REQUEST_METHOD'} eq "POST") {
	&decode;
	&write if($FORM{'value'});
}
&html;
exit;

############################### Tu[` ###############################

sub get_time{ #--------------------  --------------------#
	$time = time;
	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($time + $time_dif);
	$mon++;
	$wday = ('','','','','','','y')[$wday];
	$date_now = sprintf( "%02d/%02d($wday)%02d:%02d",$mon,$mday,$hour,$min);
}

sub decode{ #-------------------- fR[h --------------------#
	return if($ENV{'CONTENT_LENGTH'} > $maxlength);
	require "$jcpl";
	read(STDIN, $buf, $ENV{'CONTENT_LENGTH'}); 
	foreach (split(/&/,$buf)) {
		($name, $value) = split(/=/,$_);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		&jcode'convert(*value,'sjis');
		$value =~ s/\r|\n//g;
		$value =~ s/&/&amp\;/g;
		$value =~ s/</&lt;/g;
		$value =~ s/>/&gt;/g;
		$value =~ s/\t:/  :/g; 
		$FORM{$name} = $value;
	}
}

sub html{ #-------------------- HTMLo --------------------#
	&counter; # HTML̔Cӂ̏ꏊ$countuƂɃJEg\܂
	print "Content-type: text/html\n\n";
	print <<"_HTML_";
<html><head><title>$title</title></head>
$body
<font size=4><b>$title</b></font>
<small>@@| <a href="http://thor.prohosting.com/~crium/cgi-bin/mchat.cgi">펺</a>
| <a href="http://wacom.virtualave.net/cgi-bin/kakiko.cgi">Q펺</a>
| <a href=""></a>()
| <a href="http://toshiba.hypermart.net/cgi-bin/kanon/bbs.cgi">ލ펺</a>
| <a href="http://kozaetsu.hypermart.net/kozaetsu.cgi">iߎ</a>
| <a href="http://i.am/kakumeigun/">vR</a>
|@@$count
</small>
<form method=post action="$bbsurl">
O <input type=text name="name" size=20 maxlength=50 value="$FORM{'name'}">
N <input type="checkbox" name="auto_link" value="1" checked><br>
e <input type=text name="value" size=80 maxlength=300><br>
 <input type=submit value="e /[h"><input type=reset value="del"></form><p>
_HTML_

	# L̏o
	open(IN,"$bbsfile");
	while (<IN>) {
		($date,$name,$value) = split(/\t:/,$_);
		print "<hr size=1><font color=\"$namecolor\"><b>$name</b> </font>&gt\; ";
		print "<font color=\"$textcolor\"><b>$value</b></font> <font size=1 color=\"$datecolor\">$date</font>\n";
	}
	close(IN);

	print <<"_HTML_";
<hr><div align=right><small>₫Cg1.0 <a href="http://mizuiro.virtualave.net/t_lite/">source</a></small></div>
</body></html>
_HTML_
}

sub write{ #-------------------- ݏ --------------------#
	return if($ENV{'HTTP_REFERER'} !~ /$bbsurl/i);

	open(IN,"$bbsfile");
	chomp(@lines=<IN>);
	close(IN);

	splice(@lines,$max-1) if($max <= @lines);

	open(OUT,">$bbsfile");
	print OUT "$date_now\t:$FORM{'name'}\t:$FORM{'value'}\n";
	foreach(@lines){print OUT "$_\n";}
	close(OUT);
}

sub counter{ #-------------------- ANZXJE^ --------------------#
	open(IN,"$counterfile");
	$count = <IN>;
	close(IN);
	$count++;
	open(OUT,">$counterfile");
	print OUT "$count";
	close(OUT);
}

