#!/usr/bin/perl
##############################################################################
# Guestbook                     Version 2.3.1                                #
# Copyright 1996 Matt Wright    mattw@worldwidemart.com                      #
# Created 4/21/95               Last Modified 10/29/95                       #
# Scripts Archive at:           http://www.worldwidemart.com/scripts/        #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 1996 Matthew M. Wright  All Rights Reserved.                     #
#                                                                            #
# Guestbook may be used and modified free of charge by anyone so long as     #
# this copyright notice and the comments above remain intact.  By using this #
# code you agree to indemnify Matthew M. Wright from any liability that      #
# might arise from it's use.                                                 #
#                                                                            #
# Selling the code for this program without prior written consent is         #
# expressly forbidden.  In other words, please ask first before you try and  #
# make money off of my program.                                              #
#                                                                            #
# Obtain permission before redistributing this software over the Internet or #
# in any other medium.	In all cases copyright and header must remain intact.#
##############################################################################
# Set Variables

$guestbookurl = "http://localhost/~tony/mirage/d4kaklst.htm";
$guestbookreal = "../mirage/d4kaklst.htm";
$date_command = "/bin/date";

# Done
##############################################################################

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

# 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;
   $value =~ s/<([^>]|\n)*>//g;
   $FORM{$name} = $value;
   }


# Begin the Editing of the Guestbook File
open (FILE,"$guestbookreal") || die "Can't Open $guestbookreal: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

# Open Link File to Output
open (GUEST,">$guestbookreal") || die "Can't Open $guestbookreal: $!\n";

for ($i=0;$i<=$SIZE;$i++) {
    $_=$LINES[$i];
    if (/<!--begin-->/) {

#
#       print all required fields, then 'BEGIN' string
#

        if ($FORM{'name'}) {print GUEST " $FORM{'name'}\n";}

        if ( $FORM{'email'} ){
            print GUEST " \&lt;<a href=\"MAILTO:$FORM{'email'}\">";
            print GUEST "$FORM{'email'}</A>\&gt;";
            }

        print GUEST "<BR>\n";

        if ($FORM{'town'})    {print GUEST " $FORM{'town'}\n";}
        if ($FORM{'country'}) {print GUEST ": $FORM{'country'}\n";}

        print GUEST "<BR>\n";

        if ($FORM{'pagename'}) {
            print GUEST "<A href=\"$FORM{'homepage'}\">$FORM{'pagename'}</A>";
            print GUEST "<BR>\n";
            }

        print GUEST "Occupation: $FORM{'occupation'}\n";
        print GUEST "<BR>\n";

        if ($FORM{'desc_occ'}) {
            print GUEST " $FORM{'desc_occ'}\n";
            print GUEST "<BR>\n";
            }

            print GUEST "Arrived by: $FORM{'howfind'}\n";
            print GUEST "<BR>\n";

        if ($FORM{'desc_howfind'}) {
            print GUEST " $FORM{'desc_howfind'}\n";
            print GUEST "<BR>\n";
            }

        if ($FORM{'note'}) {
            print GUEST "<PRE> $FORM{'note'} </PRE><BR>\n";
            }

        print GUEST "<PRE> - $date</PRE><HR>\n\n";
        print GUEST "<BR>\n";
        print GUEST "<!--begin-->\n";
        }

    else {
        print GUEST $_;
        }
    }

close (GUEST);
print "Location: $guestbookurl\n\n";



