Приглашаем посетить
WWWChat
#!/usr/bin/perl
###########################################################################
# #
# wwwchat.pl - Perl Script for Interactive Chatting #
# #
# Written by Michael Hall - mikeh@isaac.biola.edu #
# Written for Virtual Marketing Technologies - vmt@airmail.net #
# Copyright ©1996 by Virtual Marketing Technologies, All Rights Reserved. #
# #
###########################################################################
# Get the Date for Entry
$date = `date +"%A, %B %d, %Y at %T (%Z)"`;
chop($date);
$shortdate = `date +"%D %T %Z"`;
chop($shortdate);
#############################################
# Set Up Variables
$BaseDir = "/var/www/docs/chat";
$ChatFile = "Chat.html";
$MaxMsgs = "15";
$Count = 0;
@ChatStuff = "";
&UnWeb;
if ($in{'text'} ne "") {
# Read in the current file but lock it first
open (CHATFILE,"$BaseDir/$ChatFile");
@ChatStuff = <CHATFILE>;
chop (@ChatStuff);
close CHATFILE;
# Rewrite the chat file
open (CHATFILE,">$BaseDir/$ChatFile");
print CHATFILE "$ChatStuff[0]\n";
print CHATFILE "$ChatStuff[1]\n";
print CHATFILE "$ChatStuff[2]\n";
print CHATFILE "$ChatStuff[3]\n";
print CHATFILE "$ChatStuff[4]\n";
print CHATFILE "<b>$in{'name'} on <i>$shortdate: </i></b>$in{'text'}</b></i></h1></h2></h3></h4></font><p>\n";
$Count = 5;
while ($Count != "$MaxMsgs" + 4) {
print CHATFILE "$ChatStuff[$Count]\n";
$Count++;
}
close CHATFILE;
&PrintHeader;
print "<html>\n <body bgcolor=#FFFFFF vlink=#979907 text=#000000>\n <table>\n";
print "<tr><td valign=\"top\"></td><td><form method=post
action=\"/cgi-bin/chat.cgi\"><input type=text size=50 maxlength=255
name=\"text\"> <input type=hidden name=\"name\" value=\"$in{'name'}\">
<br><center><input type=submit value=\"Enter\"> <input type=reset
value=\"Clear\"> <a href=\"/chat/Chat.html\" target=\"Window\">View Text
Now!</a></center></td></tr>\n";
print "</table>\n </html>\n";
}
sub UnWeb {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
else {
unless ($name eq 'body') {
$value =~ s/<([^>]|\n)*>//g;
}
}
$in{$name} = $value;
}
}
#######################
# Print HTML Header
sub PrintHeader {
print "Content-type: text/html\n\n";
}