#!/usr/bin/perl # TwoCHAT.pl: Simple chat script # ver.1.00 1996/12/09 # Copyright (c)1996 GOMASUKE # Orange Internet Service USERS, Japan require 'jcode.pl'; $dir = "/home/foo/msg/"; # ~~~~~~~~~~~~ update to your environment(1/2) $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "GET") { $dat = $ENV{'QUERY_STRING'}; } else { read(STDIN, $dat, $ENV{'CONTENT_LENGTH'}); } @buf = split('&',$dat); foreach $item (@buf) { ($var,$value) = split('=',$item); $value =~ tr/+/ /; $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg; $value =~ s/\x0d\x0a/\x0a/g; $value =~ s/\x0d/\x0a/g; &jcode'convert(*value,'sjis'); $itm{$var} = $value; } $io = $itm{'io'}; $cnt = $itm{'cnt'}; $msg_len = $itm{'mln'}; $msg_file = "$dir$itm{'fn'}.txt"; unless (-e $msg_file) { print "Content-type: text/html\n\n"; print "Error

Message file not exist

\n"; exit; } $rec_len = 37 + $msg_len; # name+date+msg+*+LF=20+15+msg_len+1+1 if ($io eq "c") { $spc = "*" x ($rec_len - 1); open(OUT,">$msg_file"); for ($p = 0; $p < $cnt*2; $p++) { print OUT "$spc\n"; } close(OUT); chmod(0666, $msg_file); # ~~~ update to your environment(2/2) print "Content-type: text/html\n\n"; print "Completed

Create file

\n"; exit; } $box = $itm{'box'}; if ($box < 1 || $box > 2) { print "Content-type: text/html\n\n"; print "Error

Box number 1 or 2

\n"; exit; } $reftm = $itm{'reftm'}; $reftm = $reftm + 0; if ($io ne "w") { &readmsg; exit; } $msg = $itm{'msg'}; $msln = length($msg); if ($msln > $msg_len) { print "Content-type: text/html\n\n"; print "Error

Your message is too long($msln > $msg_len)

\n"; exit; } @week = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); $spc1 = " " x 20; $spc2 = " " x $msg_len; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdat) = localtime(time); $mon++; $dt = sprintf("%02d/%02d(%3s)%02d:%02d",$mon,$mday,$week[$wday],$hour,$min); $name = $itm{'name'}; $name = substr("$name$spc1",0,20); $msg = substr("$msg$spc2",0,$msg_len); $t = ($box - 1) * $cnt; open(OUT,"+<$msg_file"); seek(OUT,$t*$rec_len,0); read(OUT,$dat,$rec_len*($cnt-1)); seek(OUT,$t*$rec_len,0); print OUT "$name$dt$msg\*\n$dat"; close(OUT); &readmsg; exit; sub readmsg { print "Content-type: text/html\n\n"; print ""; if ($reftm != 0) { print ""; } print "TwoCHAT message\n"; $t = $cnt * 2; open(IN,"<$msg_file"); if ($box == 1) { $p = 0; &outmsg; seek(IN,$cnt*$rec_len,0); for ($p = $cnt; $p < $t; $p++) { &outmsg; } seek(IN,$rec_len,0); for ($p = 1; $p < $cnt; $p++) { &outmsg; } } else { $p = $cnt; seek(IN,$cnt*$rec_len,0); &outmsg; seek(IN,0,0); for ($p = 0; $p < $cnt; $p++) { &outmsg; } seek(IN,($cnt+1)*$rec_len,0); for ($p = $cnt + 1; $p < $t; $p++) { &outmsg; } } print "\n"; } sub outmsg { read(IN,$dat,$rec_len); if ($p < $cnt) {$clr="ff0000";} else {$clr="0000ff";} $name = substr($dat,0,20); $name =~ s/ +$//g; $time = substr($dat,20,15); $dat = substr($dat,35,$msg_len); $dat =~ s/ +$//g; print "$name$time
"; print "
$dat

\n"; }