Created
May 14, 2016 21:41
-
-
Save visnup/14dcab15ab2ebe44a3faa9dff8ce6434 to your computer and use it in GitHub Desktop.
In 1995, I had a Friends fan site. This is the first code I ever wrote to support a message board on the site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
###################### | |
# guest book script # | |
# Visnu Pitiyanuvath # | |
###################### | |
push(@INC, "/home/h/hello/.html/cgi-bin"); | |
require("cgi-lib.pl"); | |
&ReadParse; | |
#print an error message if there's nothing there.. | |
if ($in{'Name'} eq "") { | |
print &PrintHeader; | |
print "<html>\n"; | |
print "<head><title>Error</title></head>\n"; | |
print "<body>\n"; | |
print "<h2>"; | |
print "<font size=6>E</font>RROR"; | |
print "</h2>\n"; | |
print "<hr>\n"; | |
print "I guess you didn't put in your name or something.\n"; | |
print "</body></html>"; | |
exit; | |
} | |
#check fields for "nonchalantness"... | |
$badwords = "fuck|shit|cunt|penis|suck|lick|bite|asshole|bitch"; | |
if (($in{'Name'} =~ /$badwords/i) || ($in{'EMail'} =~ /$badwords/i) || ($in{'category'} =~ /$badwords/i) || ($in{'something'} =~ /$badwords/i)) { | |
print &PrintHeader; | |
print "<html>\n"; | |
print "<head><title>Error</title></head>\n"; | |
print "<body>\n"; | |
print "Don't do that...\n"; | |
print "</body></html>"; | |
exit; | |
} | |
if ($in{'EMail'} !~ /@/) { | |
print &PrintHeader; | |
print "<html>\n"; | |
print "<head><title>Error</title></head>\n"; | |
print "<body>\n"; | |
print "EMail has no @ sign\n"; | |
print "</body></html>"; | |
exit; | |
} | |
if ($in{'URL'} !~ m\^http://\) { | |
print &PrintHeader; | |
print "<html>\n"; | |
print "<head><title>Error</title></head>\n"; | |
print "<body>\n"; | |
print "URL must start with \"http://\"\n"; | |
print "</body></html>"; | |
exit; | |
} | |
#print out formatted info into @foo | |
@foo = " <td>\n"; | |
$in{'Name'} =~ s/\b(\w)(\w+)/\u$1\L$2/g; | |
if($in{'URL'} =~ /\w+/) { | |
push(@foo, " <a href=\"$in{'URL'}\">$in{'Name'}</a>\n"); | |
} | |
else { | |
push(@foo, " $in{'Name'}\n"); | |
} | |
push(@foo, " - <a href=\"mailto:$in{'EMail'}\"><$in{'EMail'}></a><br>\n"); | |
push(@foo, " Favorite Character: $in{'fav_char'}<br>\n"); | |
push(@foo, " Favorite Episode: $in{'fav_ep'}<br>\n"); | |
if ($in{'color'} =~ /\w+/) { | |
$in{'color'} = ucfirst $in{'color'}; | |
push(@foo, " Favorite Color: $in{'color'}<br>\n"); | |
} | |
if (("$in{'category'}" ne ("[REPLACE ME]" || "")) & ("$in{'something'}" ne ("[REPLACE ME TOO]" || ""))) { | |
$in{'category'} =~ s/\b(\w)(\w+)/\u$1\L$2/g; | |
$in{'something'} =~ s/\b(\w)(\w+)/\u$1\L$2/g; | |
push(@foo, " Favorite $in{'category'}: $in{'something'}\n"); | |
} | |
push(@foo, " </td>"); | |
#set up "Last Updated" string... | |
#get the time | |
($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime; | |
#list of months... | |
@months = (January, February, March, April, May, June, July, August, September, October, November, December); | |
$LastUpdated = "$months[$month] $day, 19$year - $hour:$min GMT(-7)"; | |
if ("$in{'go'}" eq "0") { | |
print &PrintHeader; | |
print "<html>\n"; | |
print "<head><title>Preview</title></head>\n"; | |
print "<body>\n"; | |
print "<h2><font size=6>P</font>REVIEW</h2>\n"; | |
print "<hr>\n"; | |
print "Here's what it will look like in the table:<p>\n"; | |
print "<table border cellpadding=12>\n"; | |
print "@foo\n"; | |
print "</table>\n"; | |
print "<hr>\n"; | |
print "<form method=get action=\"http://www.sky.net/cgi-bin/guest.hello.pl\">\n"; | |
print "<input type=hidden name=\"go\" value=\"1\">"; | |
print "<input type=hidden name=\"Name\" value=\"$in{'Name'}\">"; | |
print "<input type=hidden name=\"EMail\" value=\"$in{'EMail'}\">"; | |
print "<input type=hidden name=\"URL\" value=\"$in{'URL'}\">"; | |
print "<input type=hidden name=\"fav_char\" value=\"$in{'fav_char'}\">"; | |
print "<input type=hidden name=\"fav_ep\" value=\"$in{'fav_ep'}\">"; | |
print "<input type=hidden name=\"color\" value=\"$in{'color'}\">"; | |
print "<input type=hidden name=\"category\" value=\"$in{'category'}\">"; | |
print "<input type=hidden name=\"something\" value=\"$in{'something'}\">\n"; | |
print "<input type=submit value=\"Sign Away!\">\n"; | |
print "</form>\n"; | |
print "Last Updated: $LastUpdated\n"; | |
print "</body></html>"; | |
} | |
elsif ("$in{'go'}" eq "1") { | |
$quit = 0; | |
while ($quit != 1) { | |
#lock/unlock guest book... | |
if (-e "/home/h/hello/.html/.guestlock") { | |
sleep(1); | |
} | |
else { | |
open (LOCK, ">/home/h/hello/.html/.guestlock"); | |
close (LOCK); | |
#open, read in guest.html | |
open (GB,"</home/h/hello/.html/friends/guest.html"); | |
@gb = <GB>; | |
close (GB); | |
#open, read out guest.html | |
open (GB, ">/home/h/hello/.html/friends/guest.html"); | |
foreach $_ (@gb) { | |
if (/<tr><!-- INSERT HERE -->/) { | |
s/<tr><!-- INSERT HERE -->\n/<!-- INSERT HERE -->\n <tr>\n@foo\n/; | |
} | |
elsif (/ <!-- INSERT HERE -->/) { | |
s/<!-- INSERT HERE -->\n/<tr><!-- INSERT HERE -->\n@foo\n <\/tr>\n/; | |
} | |
s/Last Updated:.+<\/address>/Last Updated: $LastUpdated<\/address>/; | |
print GB $_; | |
} | |
close (GB); | |
print "Location: http://www.sky.net/~hello/friends/guest.html#GB\n\n"; | |
# unlock me and quit out! | |
unlink("/home/h/hello/.html/.guestlock"); | |
$quit = 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment