#!/usr/bin/perl
###########################################################################
# #
# graffiti3.cgi - Perl Script for Graffiti Wall #
# Available from The Scripts Home - www.scriptshome.com #
# #
# Written by Michael Hall - mhall@scriptshome.com #
# Written for Virtual Marketing Technologies - scripts@scriptshome.com #
# Copyright ©1996 by Virtual Marketing Technologies, All Rights Reserved. #
# #
###########################################################################

$BaseDir = "/var/www/docs/scripts2/free/graffiti_wall"; # Edit this to show where your graffiti directory is.

@BadWords = ('fuck','shit','asshole','damn');
$MaxMsgs = 50;
$CGI_URL = "http://www.virtualcenter.com/scripts2/free/graffiti_wall/graffiti3.cgi"; # Edit this to show the URL of your directory.

$AllowHTML = 0; # Yes = 1, No = 0

$Header = "


Graffiti Page



";

$Footer = "



Copyright © 1997 by Virtual Marketing Technologies. All Rights Reserved.

Graffiti Wall v3.0";

####################################################################
#YOU MAY NOT EDIT ANYTHING BELOW THIS POINT WITHOUT THE EXPRESS
#WRITTEN PERMISSION OF THE AUTHOR OR VIRTUAL MARKETING TECHNOLOGIES.
#DOING SO IS A DIRECT VIOLATION OF THE USER LICENSE AND COPYRIGHT.
####################################################################

&UnWeb;

# Get the Date for Entry
$date = `date +"%A, %B %d, %Y at %T (%Z)"`;
chop($date);
$shortdate = `date +"%D %T %Z"`;
chop($shortdate);

if ($in{'action'} eq "post") {

if (($in{'Name'} eq "") || ($in{'EMail'} eq "") || ($in{'Comments'} eq "")) {
# something was blank, return the error message
&PrintHeader;
print "$Header\n";
print "

An Error has Occurred

\n";
print "\n";
print "

You did not fill in all the fields. Please remedy this.

\n";
print "\n";
print "\n";

# make a call to exit to end the script now, we had an error
exit;
}

if ($in{'EMail'} !~ /\w*@\w*/) {
# It does not equal the regular expression, send an error message
&PrintHeader;
print "$Header\n";
print "

An Error has Occurred

<\CENTER>\n";
print "\n";
print "

Your email address did not contain an @ sign. Please remedy this.

\n";
print "\n";
print "\n";

# make a call to exit to end the script now, we had an error
exit;
}

# Check for vulgarities

foreach $BadWord (@BadWords) {
if ($in{'Comments'} =~ /$BadWord/i) { # It does contain bad words
$BadFlag = 1;
}
}

if ($BadFlag == 1) {
&PrintHeader;
print "$Header\n";
print "

Error: Bad Words!

\n";
print "It appears that you may have entered words that would be considered unacceptable on this web site.

\n";
print "Please go back and edit your comments and try to keep them clean. After all, this is a family site. Thanks.

\n";
print "If you believe you got this message in error, please e-mail us.

\n";
print "\n";
exit;
}

# Now read in all current messages

open (GUESTBOOK, "$BaseDir/Guestbook.dta");
@Listings = ;
close GUESTBOOK;
chop (@Listings);

$in{'Comments'} =~ s/\t/ /go;

# Now rewrite the book with new comments added
open (GUESTBOOK, ">$BaseDir/Guestbook.dta");
&lock (GUESTBOOK);
$Count = 0;
print GUESTBOOK "$shortdate\t$in{'Name'}\t$in{'EMail'}\t$in{'Comments'}\n";
while ($Count != $MaxMsgs) {
if ($Listings[$Count] ne "") {
print GUESTBOOK "$Listings[$Count]\n";
}
$Count++;
}
&unlock (GUESTBOOK);
close GUESTBOOK;

&PrintHeader;
print "$Header\n";
print "Your paint has been added to the wall and can now be viewed.

\n";
print "$Footer\n";
exit;

}

else {
# Show the guestbook

open (GUESTBOOK, "$BaseDir/Guestbook.dta");
@Listings = ;
close GUESTBOOK;
chop (@Listings);

&PrintHeader;
print "$Header\n";
print "

\n";
print "

We'd like to know who is visiting us. So please take a\n";
print "moment and paint your message on our graffiti wall. Feel free to leave us\n";
print "your comments. We'd like to know what you think!

\n";
print "

And feel free to look through some of our other visitors'\n";
print "comments, too!
\n";
print "

\n";
print "Some of our visitors' comments:

\n";
foreach $Listing (@Listings) {
@Temp = split (/\t/, $Listing);
print " $Temp[1] wrote on $Temp[0]:
\n";
print "$Temp[3]



\n";
}
print "

\n";
print "
\n";
print "\n";
print "\n";
print "\n";
print "
\n";
print "\n";
print "\n";
print "\n";
print "

Sign Our Graffiti Wall!

\n";

print "

To sign the wall, please fill out the information in the\n";
print "box on the right.

\n";

print "

If you leave any comments, all we ask is that you keep\n";
print "your comments clean. Thanks.

\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
print "

Your Name:

E-Mail Address:

Comments:
\n";
print "

\n";

print "

\n";
print "
\n";
print "
\n";
print "
\n";
print "
\n";
print "$Footer\n";
print "\n";
print "\n";
}
exit;

#######################
# Parse Form Subroutine

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///g;

if ($AllowHTML != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
else {
unless ($name eq 'Comments') {
$value =~ s/<([^>]|\n)*>//g;
}
}

$in{$name} = $value;
}

}

sub PrintHeader {
print "Content-type: text/html\n\n";
}

sub lock {
local($file)=@_;
$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;
flock($file,$LOCK_EX);
seek($file, 0, 2);
} #lock

sub unlock {
local($file)=@_;
flock($file,$LOCK_UN);
} #unlock