Ïðèãëàøàåì ïîñåòèòü
ßçûêîâ (yazykov.lit-info.ru)

Graffiti Wall

#!/usr/bin/perl
#
# graffiti.pl  v2.1
#	Similar to the Guestbook type scripts
#
# This program uses Steve Brenner's cgi-lib.pl library to handle the input

$GraffitiDir =  "/var/www/docs/graffiti"; # Edit this to show where your graffiti directory is.
$GraffitiURL = "http://www.virtualcenter.com/graffiti"; # Edit this to show the URL of your directory.

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

&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{'name'} eq "") || ($in{'email'} eq "") || ($in{'comments'} eq "")) {
  # something was blank, return the error message
  print "Content-type: text/html

";
  print "<HTML>\n";
  print "<HEAD>\n";
  print "<TITLE>Error Message</TITLE>\n";
  print "</HEAD>\n";
  print "<BODY>\n";
  print "\n";
  print "<H1>An Error has Occurred</H1>\n";
  print "\n";
  print "<P>You did not fill in all the fields.  Please remedy this.</P>\n";
  print "</BODY>\n";
  print "</HTML>\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
  print "Content-type: text/html

";
  print "<HTML>\n";
  print "<HEAD>\n";
  print "<TITLE>Error Message</TITLE>\n";
  print "</HEAD>\n";
  print "<BODY>\n";
  print "\n";
  print "<H1>An Error has Occurred</H1>\n";
  print "\n";
  print "<P>Your email address did not contain an @ sign.  Please remedy
this.</P>\n";
  print "</BODY>\n";
  print "</HTML>\n";

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


$quit = 0;
while ($quit != 1) { 
  if (-e "$GraffitiDir/.lock") {
    # The file existed, time to take a nap
    sleep(1);
    }
  else {

    # Create the lock file, thereby locking the guestbook
    open(LOCK,">$GraffitiDir/.lock");
    close LOCK;

    # open and read in the old graffiti
    open(GW,"$GraffitiDir/index.html");
    @lines = <GW>;
    close GW;

    # Expand the comments for html
    $in{'comments'} =~ s/\n/<BR>\n/go;

    # Empty the old graffiti, and print it out again, adding the new entry
    open(GB,">$GraffitiDir/index.html");
    foreach $line (@lines) {
      $line =~ s/<!--INSERT HERE-->/<!--INSERT HERE-->\n<P><b>Name:<\/b>
$in{'name'} ($in{'email'}) <b>Date:<\/b>
$shortdate<BR>\n<P>\n<b>Comments:<\/b><BR>\n$in{'comments'}<BR>\n<HR>\n/o;
      print GB $line;
      }
    close GB;

    # unlock the file
    unlink("$GraffitiDir/.lock");

    # Return the new graffiti, and set $quit = 1
    print "Location: $GraffitiURL/thanks.html\n\n";
    $quit = 1;
    }
  }
#######################
# 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/<!--(.|\n)*-->//g;

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

      $in{$name} = $value;
   }

}

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