Help with PERL guestbook (newbie)

J

John ©

Okay, I don't know how this newsgroup works, but I will try to post as much
as I can and hopefully someone can help me. (I don't know much about PERL).

So I have a script that is to write a guestbook... I have the sign page and
I have the view page ...

the sign page is at: http://www.sigmachi-iotadelta.com/sign.html
the view page is at: http://www.sigmachi-iotadelta.com/view.html
the script is at: http://www.sigmachi-iotadelta.com/cgi-bin/guestbook.cgi
(uploaded in ascii, I think all the chmod's are correct)

Most times, after I try to post from the sign.html page, I get either page
cannot be displayed, internal error, access denied, or some other mistake.
A few times I did get the view.html page, but nothing was written to it.
Also the 'error' message from the .cgi script does work, if I don't fill out
comments or name, it will say they are blank.

Any and all help is appreciated... you can direct email me if you like.

Here is a copy/past of the script...
----------------------------------------------------------------------------
---------

#!/usr/local/bin/perl5

require "actualtime.pl";

# Set Variables

$guestbookurl = "http://www.sigmachi-iotadelta.com/view.html";
$guestbookreal = "view.html";
$cgiurl = "/export/home/johncarb/www/cgi-bin/guestbook.cgi";

# Set Your Options:

$ENV{TZ}="EDT";
$allow_html = 1; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No

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


# The following are arrays for the hour, month, and day of the week
$date = localtime(time+60*60*5);

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

$FORM{$name} = $value;
}

# Print the Blank Response Subroutines
&no_comments unless $FORM{'comments'};
&no_name unless $FORM{'realname'};

# 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 GUEST "<!--begin-->\n";

print GUEST "<b>$FORM{'realname'}</b>\n";

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

print GUEST "<br>\n";

if ( $FORM{'username'} ){
print GUEST " <a href=\"mailto:$FORM{'username'}\">";
print GUEST "$FORM{'username'}</a>";
}

print GUEST "<br>\n";

if ( $FORM{'location'} ){
print GUEST "$FORM{'location'}";
}

print GUEST "<br>\n";

print GUEST "<br>\n";

print GUEST "Comments:";

print GUEST "<br>\n";

if ($line_breaks == 1) {
$FORM{'comments'} =~ s/\cM\n/<br>\n/g;
}

print GUEST "<b>$FORM{'comments'}</b><br>\n";

&getnewstamp;

print GUEST "$wdaybac $mdaypbac-$monptbac-$year2bac
$hourpbac:$minbac$hourabac $ACTZONE\n";

print GUEST "<br>\n";
print GUEST "<br>\n";

print GUEST "<img src=/spacer.gif width=300 height=1>\n\n";

print GUEST "<br>\n";

}
else {
print GUEST $_;
}
}

close (GUEST);

# Print Out Initial Output Location Heading

print "Location: $guestbookurl\n\n";


#######################
# Subroutines

sub no_comments {
print "Content-type: text/html\n\n";
print "<html><LINK HREF=http://www.sigmachi-iotadelta.com/style.css
Type=text/css REL=stylesheet>\n";
print "<head><title>Sigma Chi: Iota Delta Alumni //no
comments//</title></head>\n";
print "<BODY bgcolor=#FFFFFF MARGINHEIGHT=0 MARGINWIDTH=0 LEFTMARGIN=0
TOPMARGIN=0>\n";

print <<ENDHTML;
<img src="/top_gfx.jpg"><BR>
<TABLE WIDTH=725 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD><A HREF="/home.html" target="_top"
onMouseOver="document.home.src='/home_on.gif'; window.status='Alumni Home';
return true" onMouseOut="document.home.src='/home_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="home" SRC="/home_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/undergrad.html" target="_top"
onMouseOver="document.undergrad.src='/undergrad_on.gif'; window.status='Sigm
Chi Iota Delta'; return true"
onMouseOut="document.undergrad.src='/undergrad_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="undergrad" src="/undergrad_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/national.html" target="_top"
onMouseOver="document.national.src='/national_on.gif';
window.status='SigmChi.org'; return true"
onMouseOut="document.national.src='/national_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="national" src="/national_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/news.html" target="_top"
onMouseOver="document.news.src='/news_on.gif'; window.status='News'; return
true" onMouseOut="document.news.src='/news_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="news" src="/news_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/events.html" target="_top"
onMouseOver="document.events.src='/events_on.gif'; window.status='Events';
return true" onMouseOut="document.events.src='/events_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="events" src="/events_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/brothers.html" target="_top"
onMouseOver="document.brothers.src='/brothers_on.gif';
window.status='Brothers'; return true"
onMouseOut="document.brothers.src='/brothers_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="brothers" src="/brothers_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/pictures.html" target="_top"
onMouseOver="document.pictures.src='/pictures_on.gif';
window.status='Pictures'; return true"
onMouseOut="document.pictures.src='/pictures_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="pictures" src="/pictures_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><img src="/mb.gif"></TD>
<TD><IMG NAME="sign" src="/sign_page.gif" BORDER=0></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/view.html" target="_top"
onMouseOver="document.view.src='/view_on.gif'; window.status='View the
Message Board'; return true" onMouseOut="document.view.src='/view_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="view" src="/view_off.gif" BORDER=0></a></TD>

</TR>
</TABLE>

<TABLE WIDTH=725 BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD
HEIGHT="1"></TD></TR></TABLE>

ENDHTML

print "<TABLE class=bodytext bgcolor=#FFFFFF WIDTH=725 BORDER=0
CELLPADDING=0 CELLSPACING=0><TR>\n";
print "<TD class=side valign=top HEIGHT=300 WIDTH=160
BGCOLOR=#FF9900></TD>\n";
print "<TD valign=top WIDTH=50 BGCOLOR=#FFFFFF></TD>\n";
print "<TD valign=middle WIDTH=390>\n";
print GUEST "<br>\n";
print GUEST "<br>\n";
print GUEST "<br>\n";
print "<B>Your comments section appears to be blank.<br>\n";
print "Please click the back button on your browser.<br>\n";
print GUEST "</b>\n";
print GUEST "<br>\n";
print GUEST "<br>\n";
print "</TD>\n";
print "<TD BGCOLOR=#150185 WIDTH=2><img
src=http://www.sigmachi-iotadelta.com/bd.gif></TD>\n";
print "<TD BGCOLOR=#FF9900 WIDTH=171></TD>\n";
print "<TD BGCOLOR=#150185 WIDTH=2><img
src=http://www.sigmachi-iotadelta.com/bd.gif></TD>\n";
print "\n</TR>\n";
print "<TR><TD BGCOLOR=#150185 COLSPAN=6 HEIGHT=5><img
src=http://www.sigmachi-iotadelta.com/bd.gif></TD>\n";
print "\n</TR></TABLE>\n";
print "\n</body></html>\n";

exit;
}

sub no_name {
print "Content-type: text/html\n\n";
print "<html><LINK HREF=http://www.sigmachi-iotadelta.com/style.css
Type=text/css REL=stylesheet>\n";
print "<head><title>Sigma Chi: Iota Delta Alumni //no
name//</title></head>\n";
print "<BODY bgcolor=#FFFFFF MARGINHEIGHT=0 MARGINWIDTH=0 LEFTMARGIN=0
TOPMARGIN=0>\n";

print <<ENDHTML;
<img src="/top_gfx.jpg"><BR>
<TABLE WIDTH=725 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD><A href="/home.html" target="_top"
onMouseOver="document.home.src='/home_on.gif'; window.status='Alumni Home';
return true" onMouseOut="document.home.src='/home_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="home" src="/home_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/undergrad.html" target="_top"
onMouseOver="document.undergrad.src='/undergrad_on.gif'; window.status='Sigm
Chi Iota Delta'; return true"
onMouseOut="document.undergrad.src='/undergrad_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="undergrad" src="/undergrad_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/national.html" target="_top"
onMouseOver="document.national.src='/national_on.gif';
window.status='SigmChi.org'; return true"
onMouseOut="document.national.src='/national_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="national" src="/national_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/news.html" target="_top"
onMouseOver="document.news.src='/news_on.gif'; window.status='News'; return
true" onMouseOut="document.news.src='/news_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="news" src="/news_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/events.html" target="_top"
onMouseOver="document.events.src='/events_on.gif'; window.status='Events';
return true" onMouseOut="document.events.src='/events_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="events" src="/events_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/brothers.html" target="_top"
onMouseOver="document.brothers.src='/brothers_on.gif';
window.status='Brothers'; return true"
onMouseOut="document.brothers.src='/brothers_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="brothers" src="/brothers_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/pictures.html" target="_top"
onMouseOver="document.pictures.src='/pictures_on.gif';
window.status='Pictures'; return true"
onMouseOut="document.pictures.src='/pictures_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="pictures" src="/pictures_off.gif" BORDER=0></a></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><img src="/mb.gif"></TD>
<TD><IMG NAME="sign" src="/sign_page.gif" BORDER=0></TD>
<TD WIDTH=1><img src="/div.gif"></TD>
<TD><A href="/view.html" target="_top"
onMouseOver="document.view.src='/view_on.gif'; window.status='View the
Message Board'; return true" onMouseOut="document.view.src='/view_off.gif'"
onFocus="if(this.blur)this.blur()">
<IMG NAME="view" src="/view_off.gif" BORDER=0></a></TD>

</TR>
</TABLE>

<TABLE WIDTH=725 BORDER=0 CELLPADDING=1 CELLSPACING=1><TR><TD
HEIGHT="1"></TD></TR></TABLE>

ENDHTML

print "<TABLE class=bodytext bgcolor=#FFFFFF WIDTH=725 BORDER=0
CELLPADDING=0 CELLSPACING=0><TR>\n";
print "<TD class=side valign=top HEIGHT=300 WIDTH=160
BGCOLOR=#FF9900></TD>\n";
print "<TD valign=top WIDTH=50 BGCOLOR=#FFFFFF></TD>\n";
print "<TD valign=middle WIDTH=390>\n";
print GUEST "<br>\n";
print GUEST "<br>\n";
print GUEST "<br>\n";
print "<B>Your name appears to be blank.<br>\n";
print "Please click the back button on your browser.<br>\n";
print GUEST "</b>\n";
print GUEST "<br>\n";
print GUEST "<br>\n";
print "</TD>\n";
print "<TD BGCOLOR=#150185 WIDTH=2><img
src=http://www.sigmachi-iotadelta.com/bd.gif></TD>\n";
print "<TD BGCOLOR=#FF9900 WIDTH=171></TD>\n";
print "<TD BGCOLOR=#150185 WIDTH=2><img
src=http://www.sigmachi-iotadelta.com/bd.gif></TD>\n";
print "\n</TR>\n";
print "<TR><TD BGCOLOR=#150185 COLSPAN=6 HEIGHT=5><img
src=http://www.sigmachi-iotadelta.com/bd.gif></TD>\n";
print "\n</TR></TABLE>\n";
print "\n</body></html>\n";

exit;
}



----------------------------------------------------------------------------
 
N

nobull

Okay, I don't know how this newsgroup works,

It doesn't. It does not exist (see FAQ). It is merely an artifact of
your misconfigured news server.
Subject: Help with PERL guestbook (newbie)

"Help with" and "Perl" in subject lines just waste space. Space in
subject lines is valuable. Wasting it will predispose people to view
you in a negative way.

"newbie" in subject lines will be read as "person too lazy to read the
documentation" because experience has shown us that 99% of question
with "newbie" in the subject are either listed in the FAQ or could
have been answered by simply reading the obvious bit of the
documentation. If you are too lazy to read documentation then don't
post asking for help. If you are not too lazy then you should avoid
doing things that are likely to predispose people to suspect that you
are.

For help on composing subject lines see the posting guidelines in
newsgroup that replaced this one when this one ceasesd to exist.
but I will try to post as much as I can and hopefully someone can help me.

You should try to post as much _information_ as possible but as little
volume as possible. For help on composing messages see the posting
guidelines in newsgroup that replaced this one when this one ceasesd
to exist.
(I don't know much about PERL).

Not even the name (see FAQ).
So I have a script that is to write a guestbook...
I get either page
cannot be displayed, internal error, access denied, or some other mistake.

Exact error messages are often important. In the case of errors that
just say "internal error" the actual error is usually to be found in
an error log somewhere.
Any and all help is appreciated... you can direct email me if you like.

Here is a copy/past of the script...

[ snip example of really really bad Perl programming ]

If you wrote it then that's OK (you're a beginner) and I could go
though it line by line telling you all the things that are wrong with
it and maybe that would help you. But somehow I don't think you wrote
it in which case that would be a complete waste of time. If you
didn't write this script throw it away and get a sensible starting
point.

Note: a sensible Perl CGI script will almost certainly contain the
lines:

use strict;
use warnings;
use CGI;

So, did you write this script?
 
J

Jim Gibson

John © said:
Okay, I don't know how this newsgroup works, but I will try to post as much
as I can and hopefully someone can help me. (I don't know much about PERL).

Actually, this newsgroup is defunct. Active Perl newsgroups include
comp.lang.perl.misc, comp.lang.perl.moderated, comp.lang.perl.modules,
comp.lang.perl.tk, and comp.lang.perl.announce, with topics as
indicated.
So I have a script that is to write a guestbook... I have the sign page and
I have the view page ...

I am guessing that you didn't write this script. You should know that
there is a Perl module to assist with CGI tasks (CGI.pm), including
parsing input data and generating HTML. Try executing 'perldoc CGI' at
a command line prompt to get more info.

Your script doesn't do any file locking. It will run into trouble if
two people try to post a message at the same time. If your script
encounters an error, it will die without writing the proper HTML, and
you will see nothing in your browser.

You might look into a different script for guestbooks. There is one
available at http://nms-cgi.sourceforge.net/scripts.shtml that includes
locking the data file to prevent simultaneous access by two users.
the sign page is at: http://www.sigmachi-iotadelta.com/sign.html
the view page is at: http://www.sigmachi-iotadelta.com/view.html
the script is at: http://www.sigmachi-iotadelta.com/cgi-bin/guestbook.cgi
(uploaded in ascii, I think all the chmod's are correct)

Most times, after I try to post from the sign.html page, I get either page
cannot be displayed, internal error, access denied, or some other mistake.
A few times I did get the view.html page, but nothing was written to it.
Also the 'error' message from the .cgi script does work, if I don't fill out
comments or name, it will say they are blank.

Any and all help is appreciated... you can direct email me if you like.

Here is a copy/past of the script...

[ long CGI guestbook script snipped ]
 
J

John ©

Hi,

It doesn't. It does not exist (see FAQ). It is merely an artifact of
your misconfigured news server.

Didn't know there was a FAQ, didn't know I should know that ...
"Help with" and "Perl" in subject lines just waste space.

Now I know...
"newbie" in subject lines will be read as ... ... ... ... ... ... ...

Now I know...
For help on composing subject lines see the posting guidelines in
newsgroup that replaced this one when this one ceasesd to exist.

I didn't know this was replaced.
You should try to post as much _information_ as possible but as little
volume as possible. For help on composing messages see the posting
guidelines in newsgroup that replaced this one when this one ceasesd
to exist.

I don't know what's important yet.
Not even the name (see FAQ).

Thanks for calling me out on that one... it's not like I said I know it all.
What is it Perl (no capitals)?

[ snip example of really really bad Perl programming ]

thankfully it's not mine or the "really really bad" comment would be
considered unnecessary.
So, did you write this script?

Nope, I would have said I wrote the script, I just said I have a script.
Okay, so obviously CGI/Perl is complex, so complex to the point that people
get bothered by people that are brand new to everything. I'll get a book
and go at my own pace, start from scratch so that maybe I can actually learn
something.


Thanks for your help though.

-John
 
R

Rene

My, that bully guy really told you off, didn't he? Please don't take it too
bad. He was right about a couple of things:
It is useless to point out all errors in a bad script. Try to find a
guestbook script that looks well-written and ducumented, and works right
'out of the box'. There are a few around, google is your friend, do a bit of
research. A good script will most probably contain the following lines:
use strict;
use warnings;
use CGI;

CGI is a module, written by people more clever than you and I, that will do
most of the dirty http-parsing for you.
Don't waste your time with a badly written script...
Good luck!

--
{groeten|regards}, René van Leeuwen
___ _ __
/ _ \___ ___ ___// __/ /
/ , _/ -_) _ \/ -_) |/ / /__
/_/|_|\__/_//_/\__/|___/____/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top