Is this script OK?

They have: 5,633 posts

Joined: Jan 1970

I have tried everything to get this script to work but to no avail, it was taken from a fairly mainstream site (http://scripts.riffnet.com/) but it offers no direct support. A working demonstration ccan be found there. Many others at the site have reported similar problems on the forum. Can you tell me if there is a problem with the script. Currently it is modified for use with my 'freedom2surf' account and I'm pretty sure the details are correct. Beware it is quite long...

#!/usr/bin/perl

#######################################################################
# FlexBook Version 1.02 #
# Copyright 1998 by Matt Riffle All Rights Reserved. #
# Initial Full Release: 7/4/98 This Release: 2/20/99 #
# Riffnet Scripts Archive http://scripts.riffnet.com/ #
#######################################################################
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. It is included in #
# this distribution in the file "license.txt". #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #
# 02111-1307, USA. #
#######################################################################

#### Variables -- Set Accordingly

# This is the full path to your guestbook html file. Be sure
# that it is writable by the web server. In UNIX, that can
# be done with `chmod 666 gbook.html` where gbook.html is the
# name of your guestbook page.
$gbook = "gbook.html";

# This is the full path to the entry template file. For each
# variable in the form, use [varname] where you want it to
# appear in the template. To add environmental variables add a $,
# as in [$HTTP_USER_AGENT]. Another useful environmental variable
# is [$REMOTE_HOST]. [date] is a special variable that adds a date
# stamp to the entry, and [time] is a timestamp.
$template = "template.txt";

# This is the URL of the page you want displayed after a
# submission is entered. If it is set to "", a generic
# thank-you page is generated.
$success = "http://www.freeplayers.f9.co.uk/guestbook/thanks.html";

# If this variable is set to 1, new entries are added to the top of the
# list. If not, they are added at the bottom.
$add_at_top = 1;

# If you place "bad words" in this array, the guestbook will
# replace occurrences of them with ****. This, to some degree, helps
# keep foul language out of your guestbook. Comment it out if you don't
# want any filtering.
@badwords = ("gosh","heck","shucks","darn");

# This array contains the form fields that must be filled in before the
# entry can be added. Set it to ("") if no particular form field *has*
# to be entered.
@required = ("name");

# This array contains the IP addresses which are banned from using the
# site. To log IP addresses in your entries, use the special tag
# [$REMOTE_ADDR] in your template (See the README file for more info.)
# Set it to () if no one should be banned.
@banned = ();

# If this variable is set to 1, all html tags will be stripped from the
# submissions. This prevents people from including huge images or other
# such things in their entries.
$ban_html = 1;

# If your system can use "flock" for file-locking, set this variable to
# 1. Otherwise, set it to 0.
$filelock = 0;

# If this variable is set to 1, you will receive e-mailed confirmation
# each time someone adds to the guestbook.
$mail_you = 0;

# This is the path to "sendmail" on your system. On most UNIX
# systems, you can use 'which sendmail' or 'whereis sendmail'
# to find out the path. If you didn't set mail_you
# equal to 1, you don't need to set this at all.
$mailer = "/usr/sbin/sendmail";

# This is the e-mail address to send mail to, if you set $mail_you
# equal to one. Be sure to put a \ before the @, as in
# "mattr\@cgiscripts.net"
$adminaddr = "webmaster\@example.com";

###### Do Not Edit Below This Line ######

## Actions

# Check Security
&secure;

# Organize Input
&parse_form;

# Check Required Fields
&check_for_required;

# Add Entry
&add_entry;

# Mail Admin if Needed
if (($mail_you) && ($adminaddr)) {
&mail_admin;
}
# Report Success
&report_success;

## Subroutines

sub secure {

if (@banned) {
my($ban);
foreach $ban (@banned) {
if ($ENV{'REMOTE_HOST'} =~ /^$ban/) { &error("BANNED"); }
}
}
}

sub parse_form {

# Die if method is "GET"
if ($ENV{'QUERY_METHOD'} eq "GET") {
&error("GET");
}

my($ind,$value,$badword);

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@couples = split(/&/, $buffer);

foreach $one (@couples) {
($ind, $value) = split(/=/, $one);
# 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;
# Kill Bad Words
foreach $badword (@badwords) {
$value =~ s/$badword/****/ig;
}
# Strip HTML
if ($ban_html == 1) {
$value =~ s/<([^>]|\n)*>//g;
}

$TAG{$ind} = $value;
}

}

sub check_for_required {

if (@required) {
foreach $req (@required) {
if (!$TAG{$req}) { push (@missing,$req); }
}
}
if (@missing) { &error("MISSING"); }
}
sub add_entry {

# Create Date Stamp
my($date,$min,$hour,$day,$month,$year,$weekday,$ampm,$zero,@weekdays,@months);
(undef, $min, $hour, $day, $month, $year, $weekday) = localtime(time);
@weekdays = ("Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday");
@months = ("January","February","March","April","May","June","July",
"August","September","October","November","December");
# Dates correct through 2097
if ($year > 97) { $year += 1900; } else { $year += 2000; }
# Fix Time
if ($hour > 12) { $hour -= 12; $ampm = "PM"; } else { $ampm = "AM"; }
if ($hour == 0) { $hour = 12; }
if ($min < 10) { $zero = "0"; } else { $zero = ""; }
$time = "$hour:$zero$min $ampm";
$date = "$weekdays[$weekday], $months[$month] $day, $year";

# Parse Template and push data to @out array
open (IN,$template) | | &error("TMPL");
while (<IN> ) {
# Handle special date tag
$_ =~ s/\[date\]/$date/ig;
# Handle special time tag
$_ =~ s/\[time\]/$time/ig;
# Handle Environment Variables
$_ =~ s/\[\$([^\]]*)\]/$ENV{$1}/ig;
# Handle form input tags
$_ =~ s/\[([^\]]*)\]/$TAG{$1}/ig;
push (@out,$_);
}
close(IN);

# Open guestbook and get entries
open (GUEST,$gbook) | | &error("GBR");
# This should be more efficient, really
@lines = <GUEST>;
close (GUEST);
# Write New Guestbook File
open (NEW,">$gbook") | | &error("GBW"

They have: 5,633 posts

Joined: Jan 1970

They have: 334 posts

Joined: Dec 1999

A couple of things to check:

#!/usr/bin/perl

^Make sure that's the correct path to Perl.

$gbook = "gbook.html";

$template = "template.txt";

$success = "http://www.freeplayers.f9.co.uk/guestbook/thanks.html";

Make sure the file paths are okay there. If the thanks.html page and the gbook.html page are in the same directory, the path to one of them is wrong. If you have created a /guestbook/ subdirectory to hold the html files, perhaps $gbook = "gbook.html";
should be $gbook = "/guestbook/gbook.html";

Also, check the file permissions. The gbook.html file should be chmod-ed to 666, the script itself to 755.

They have: 26 posts

Joined: Mar 2000

Ok I finally worked it out, I put relative URLs in and I forgot to CHMOD the cgi-bin directory

Doh...

They have: 334 posts

Joined: Dec 1999

Yes, but you had the bad word filter set perfectly. When oh when will those animals stop saying "shucks" and "darn" on the internet? They're ruining it for everyone!!!

They have: 1,587 posts

Joined: Mar 1999

hehe, yeah might want to upgrade those dirty words to real ones.

------------------
CLICK 4 some tested resources for making money $, hosting, and web promotions.
My Site got hacked, but i'm coming back?

Traffic-Website.com free traffic, affiliate programs, hosting, & domain names.
My Site got hacked, but i'm coming back?

They have: 26 posts

Joined: Mar 2000

Ok ok I've added the serious ones,

Crumbs, Crikey, Blast, and...dare I say it.....By Jingo

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.