#!/usr/bin/perl
#
# Grabs input and writes to a new file. If filename is 'gameworms.cpp'
# then the file is given special treatment and a timestamp is added to
# the filename, and the link on the main page is updated to point to the
# latest version.
# 11/1/01 -rjp
require "cgi-lib.pl";
&ReadParse(*input);
$WHO = $input{'who'};
$FILE = $input{'filename'};
$TXT = $input{'rawtext'};
$DATE = `date`;
$DATESTAMP = `date | sed s\/\" \"\/\-\/g`;
#print $DATESTAMP;
chop($DATE);
# -- test for input errors
$formerrors = "";
if ($WHO eq "NONE") {
$formerrors = $formerrors . "Your username is required. Go back and select it.
";
}
if ($FILE eq "") {
$formerrors = $formerrors . "A filename is required. Go back and enter one.
";
}
if ($TXT eq "") {
$formerrors = $formerrors . "A comment is required. Go back and enter one.
";
}
if ($formerrors ne "") {
print &CgiDie("Error(s) ","$formerrors");
}
if ($FILE eq "gameworms.cpp") # revision control for gameworms.cpp
{
$OUT="$FILE-$DATESTAMP";
}
else
{
$OUT=$FILE;
}
open(OUT,">$OUT") || die("Cannot open output file.");
print OUT <
\/\*
File: $FILE
Uploaded by $WHO on $DATE
\*\/
$TXT
ENDBLOCK
close(OUT);
if ($FILE eq "gameworms.cpp")
{
chop($OUT);
system("rm gameworms.cpp"); # remove old link
system("ln -s '$OUT' gameworms.cpp"); # relink to the latest version
}
# log the old files to the old index page
$OLDLOG="index.html";
open(OUTLOG,">>$OLDLOG") || die("Cannot open output file.");
print OUTLOG <$OUT<\/a>
ENDBLOCK2
close(OUTLOG);
# now print out the response to the user
print "Content-type: text/html\n\n";
print "Thanks $WHO for the new file!\n";
print "
Thank you $WHO for the new file!
\n";
print "Returning to the main page...";
print "\n";
print "
\n";
print "
\n";