#!/usr/bin/perl #!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 # If you are getting Interal server error messages, # use the code below to pipe script errors to the browser use CGI::Carp ( fatalsToBrowser); # Alternatively code like: # uncomment line below to view compiler errors # #BEGIN { #$| = 1; #open (STDERR, ">&STDOUT"); #print "Content-type: text/html\n\n
\n";
#}
#$N is used to store the number in ?guestbook=n
$N="";
#$X is an extension that allows multiple arrays
$X="";
#SERVER_URL=http://127.0.0.1/
if ( $ENV{'SERVER_URL'} eq 'http://127.0.0.1/' ){
$guestbookurl = 'http://127.0.0.1/gbook.htm';
} else {
$guestbookurl = 'http://www.dougrice.webhosts.co.uk/book/gbook.htm';
}
$guestbookreal = $ENV{'DOCUMENT_ROOT'}.'/gbookF.htm';
$guestbookjs = $ENV{'DOCUMENT_ROOT'}.'/gbookF';
# for cgi.dougrice.plus.com
$guestbookreal = $ENV{'C_DOCUMENT_ROOT'}.'/gb/gbookF.htm';
$guestbookjs = $ENV{'C_DOCUMENT_ROOT'}.'/gb/gbookF';
$guestbookjsf = $ENV{'C_DOCUMENT_ROOT'}.'/gb/gbookF';
$date_command = "/usr/bin/date";
# Set Your Options:
$separator = 1; # 1 =
; 0 =
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$allow_html = 1; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No
# Done
##############################################################################
# Get the Date for Entry
#$date = "System Date"; #`$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
#$date = `$date_command +"%A, %B %d, %Y at %T (%Z)"`; chop($date);
#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# 0 1 2 3 4 5 6 7 8
@t = localtime();
@days= ('sun','Mon','Tue','Wed','Thu','Fri','Sat','Sun');
@months=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
$fullYear=1900+$t[5];
$date = " $days[$t[6]] $t[3]/$months[$t[4]]/$fullYear at $t[2]: $t[1]: $t[0] ";
#toUTCString():
#Tue, 25 Jun 2002 05:47:32 UTC
$date = "$days[$t[6]], $t[3] $months[$t[4]] $fullYear ".substr("0".$t[2],-2,2).":".substr("0".$t[1],-2,2).":".substr("0".$t[0],-2,2)." UTC+0100";
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
#Combine the query string and form fields
# Split the name-value pairs
@pairs = split(/&/, $ENV{'QUERY_STRING'}."&".$buffer );
open (LOG,">>$guestbookjs"."Flog.txt") || die "Can't Open $guestbookjs"."Flog.txt: $!\n" ;
print LOG "=== $date = $ENV{'REMOTE_ADDR'} $ENV{'HTTP_X_FORWARDED_FOR'} ===========================================\n" ;
print LOG "//HTTP_USER_AGENT: $ENV{'HTTP_USER_AGENT'} \n";
print LOG "//HTTP_REFERER = $ENV{'HTTP_REFERER'}\n";
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
print LOG $pair . "\n";
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
# Leave the value mostly escaped as JavaScript can unescape easily.
# Javascript escapes for CR and LF
$value =~ s/%0D/
\\\n/g;
$value =~ s/%0A//g;
# Javascript escapes for " and '
$value =~ s/%22/\\"/g;
$value =~ s/%27/\\'/g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORMJS{$name} = $value;
$value =~ s///g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
$FORM{$name} = $value;
#
# split off prefix and store in associative array / hash
#
($prefix, $name1) = split(/_/, $name);
# print LOG $name ." ". $prefix ." ". $name1 . "\n";
if ( $name1 ne "" ) {
$preA{ $prefix } = $name;
}
}
print LOG "----\n";
@prefixKeys = keys ( %preA );
foreach $prefixI ( sort ( @prefixKeys ) ) {
print LOG ": ". $prefixI ." = ". $preA{$prefixI}."\n";
}
print LOG "----\n";
close ( LOG );
# Open Link File to Output
$N = "$FORM{'guestbook'}";
open (GUESTJS,">>$guestbookjs$N.js") || die "Can't Open $guestbookjs$N.js: $!\n";
$X = "$FORMJS{'guestBookArrayName'}";
# Allow Multiple entry updates
$prefix = "";
#for( $prefixIndex = 0 ; $prefixIndex < 51 ; $prefixIndex++ ){
foreach $prefixI ( sort( @prefixKeys ) ) {
$prefix = $prefixI."_";
# only use
if ( ( $prefix eq "" ) || ( $FORMJS{ $prefix.'updated'} ) ) {
print GUESTJS "\n";
# print GUESTJS " GB$N$X[ count$X ] = new GB( \n";
#print GUESTJS "\n";
#print GUESTJS "// new amendement $N:$X: \n";
print GUESTJS "//HTTP_USER_AGENT: $ENV{'HTTP_USER_AGENT'} \n";
#print GUESTJS "//HTTP_ACCEPT: $ENV{'HTTP_ACCEPT'} \n";
#print GUESTJS "\n";
#print GUESTJS "gbA$X\[ count$X \] = new GB( \n";
print GUESTJS "// $prefix\n";
print GUESTJS "gbF( \n";
#print GUESTJS " guestBookFile$N$X\[ count$X \] = new GB( \n";
print GUESTJS " \"$FORMJS{'name'}\",\n";
print GUESTJS " \"$FORMJS{'email'}\",\n";
print GUESTJS " \"$date\",\n";
print GUESTJS " \"$ENV{'REMOTE_ADDR'} $ENV{'HTTP_X_FORWARDED_FOR'}\",\n";
print GUESTJS " \"".$FORMJS{ $prefix.'userfield1'}."\",\n";
print GUESTJS " \"".$FORMJS{ $prefix.'userfield2'}."\",\n";
print GUESTJS " \"".$FORMJS{ $prefix.'userfield3'}."\",\n";
print GUESTJS " \"".$FORMJS{ $prefix.'userfield4'}."\",\n";
print GUESTJS " \"".$FORMJS{ $prefix.'comments' }."\"\n";
print GUESTJS " );\n";
#print GUESTJS " count$X=count$X+1;\n";
$prefix = "p".$prefixIndex."_";
}
}
close (GUESTJS);
if ( $FORM{'loadnextpage'} ){
# Print Out Initial Output Location Heading
print "Location: $FORM{'nextpage'}\n\n";
exit;
}
&no_redirection();
exit;
#######################
# Subroutines
# Redirection Option
sub no_redirection {
# Print Beginning of HTML
print "Content-Type: text/html\n\n";
print "
Thank You \n";
print "Thank You For your submission
\n";
print " return...
";
print '';
exit;
# print "
Some links back to places known by this frame'."\n";
# print "
Webhoster Env Vars\n";
# while (($key,$value) = each %ENV) {
# print "
$key=$value\n";
# }
print '