#! /usr/local/bin/perl
##########################################
#BooNetTalk,v1.37 / this program is free.#
# (C) BooBooClub 1997-2005 #
##########################################
#set data
$max = '20';
$cgi = "./bnt.cgi";
$dat = "./ntd.dat";
$bnttitle = "BooNetTalk";
$head = '
BooNetTalk
';
$linkname = "Back";
$linkurl = "./link/to/url";
$back = 'bgcolor="#ffffff"';
$linkc = 'text="#000000" link="#0000ff" vlink="880088"';
$noname = '匿名';
#read_lib
require 'jcode.pl';
#time
$ENV{'TZ'}='JST-9';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = ($year + 1900);
$mon++;
if ($sec < 10) { $sec = "0$sec";}
if ($min < 10) { $min = "0$min";}
if ($hour < 10){ $hour = "0$hour";}
if ($mon < 10) { $mon = "0$mon";}
if ($mday < 10){ $mday = "0$mday";}
$time = "$year/$mon/$mday $hour:$min:$sec";
#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;
$value =~ s/\,//g;
$value =~ s/</ig;
$value =~ s/>/>/ig;
$value =~ s/\r\n|[\r\n]//ig;
#prevent chr error
&jcode'convert(*value,'sjis');
$FORM{$name} = $value;
}
#lock
&lock;
#allow
if($FORM{'txt'} ne ''){
&write;
}
&html;
sub write{
open (DAT,"$dat");
@ntdats = ;
close (DAT);
if($FORM{'name'} eq ''){
$FORM{'name'} = "$noname"
}
$wrt = "$FORM{'name'}\,$time\,$FORM{'txt'}\n";
@ndat = @ntdats[0..($max-2)];
unshift(@ndat,$wrt);
open (DAT,">$dat");
print DAT @ndat;
close (DAT);
}
sub html {
open (DAT,"$dat");
@ntdats = ;
close (DAT);
print "Content-type: text/html\n\n";
print "$bnttitle\n";
print "\n";
print "\n";
print "$head\n";
print "
\n";
print "$linkname\n";
print "\n";
print "
\n";
print "\n";
print "\n";
print "
\n";
print "
\n";
foreach $ntdat (@ntdats) {
($name,$time,$txt) = split(/,/,$ntdat);
print "$time [ $name ] $txt
\n";
}
print "\n";
unlink("$lockfile");
exit 0;
}
sub lock{
$retry = 0;
$lockfile = "./lock/lockfile";
until (symlink("$dat", "$lockfile")){
if (++$retry >= 30){
unlink("$lockfile");
exit 0;
}
sleep(1);
}
}