perl cgi problem

P

pfancy

Ok. since this is perl and it deals with cgi i was hoping someone can help
me out. I am working on a guest book and I get to the addguest part. and
when i click on the submit button to add it to the cgi part it says it can
not find my guestbook.cgi file. i have that file in my cgi-bin folder what
is up
It may because i don't have a sendmail thing. what can you tell me and am i
not adding something that needs to be there?



#!/usr/local/bin/perl
############################################################################
##
# Guestbook Version 2.3.1
#
# Copyright 1996 Matt Wright (e-mail address removed)
#
# Created 4/21/95 Last Modified 10/29/95
#
# Scripts Archive at: http://www.scriptarchive.com/
#
############################################################################
##
# 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://www.yourhost.com/guestbook/guestbook.html";
$guestbookreal = "/home/yourhostt/guestbook/guestbook.html";
$guestlog = "http://www.yourhost.com/guestbook/guestlog.html";
$cgiurl = "http://www.yourhost.com/guestbook/cgi-bin/guestbook.pl";
$date_command = "/usr/bin/date";

# Set Your Options:
$mail = 0; # 1 = Yes; 0 = No
$uselog = 1; # 1 = Yes; 0 = No
$linkmail = 1; # 1 = Yes; 0 = No
$separator = 1; # 1 = <hr>; 0 = <p>
$redirection = 0; # 1 = Yes; 0 = No
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$remote_mail = 0; # 1 = Yes; 0 = No
$allow_html = 1; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No

# If you answered 1 to $mail or $remote_mail you will need to fill out
# these variables below:
$mailprog = '/usr/lib/sendmail';
$recipient = '(e-mail address removed)';

# 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;

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-->/) {

if ($entry_order eq '1') {
print GUEST "<!--begin-->\n";
}

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

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

if ($FORM{'url'}) {
print GUEST "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
}
else {
print GUEST "$FORM{'realname'}";
}

if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print GUEST " \&lt;<a href=\"mailto:$FORM{'username'}\">";
print GUEST "$FORM{'username'}</a>\&gt;";
}
else {
print GUEST " &lt;$FORM{'username'}&gt;";
}
}

print GUEST "<br>\n";

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

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

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

if ($separator eq '1') {
print GUEST " - $date<hr>\n\n";
}
else {
print GUEST " - $date<p>\n\n";
}

if ($entry_order eq '0') {
print GUEST "<!--begin-->\n";
}

}
else {
print GUEST $_;
}
}

close (GUEST);

# Log The Entry

if ($uselog eq '1') {
&log('entry');
}


#########
# Options

# Mail Option
if ($mail eq '1') {
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";

print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "From: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "Subject: Entry to Guestbook\n\n";
print MAIL "You have a new entry in your guestbook:\n\n";
print MAIL "------------------------------------------------------\n";
print MAIL "$FORM{'comments'}\n";
print MAIL "$FORM{'realname'}";

if ( $FORM{'username'} ){
print MAIL " <$FORM{'username'}>";
}

print MAIL "\n";

if ( $FORM{'city'} ){
print MAIL "$FORM{'city'},";
}

if ( $FORM{'state'} ){
print MAIL " $FORM{'state'}";
}

if ( $FORM{'country'} ){
print MAIL " $FORM{'country'}";
}

print MAIL " - $date\n";
print MAIL "------------------------------------------------------\n";

close (MAIL);
}

if ($remote_mail eq '1' && $FORM{'username'}) {
open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";

print MAIL "To: $FORM{'username'}\n";
print MAIL "From: $recipient\n";
print MAIL "Subject: Entry to Guestbook\n\n";
print MAIL "Thank you for adding to my guestbook.\n\n";
print MAIL "------------------------------------------------------\n";
print MAIL "$FORM{'comments'}\n";
print MAIL "$FORM{'realname'}";

if ( $FORM{'username'} ){
print MAIL " <$FORM{'username'}>";
}

print MAIL "\n";

if ( $FORM{'city'} ){
print MAIL "$FORM{'city'},";
}

if ( $FORM{'state'} ){
print MAIL " $FORM{'state'}";
}

if ( $FORM{'country'} ){
print MAIL " $FORM{'country'}";
}

print MAIL " - $date\n";
print MAIL "------------------------------------------------------\n";

close (MAIL);
}

# Print Out Initial Output Location Heading
if ($redirection eq '1') {
print "Location: $guestbookurl\n\n";
}
else {
&no_redirection;
}

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

sub no_comments {
print "Content-type: text/html\n\n";
print "<html><head><title>No Comments</title></head>\n";
print "<body><h1>Your Comments appear to be blank</h1>\n";
print "The comment section in the guestbook fillout form appears\n";
print "to be blank and therefore the Guestbook Addition was not\n";
print "added. Please enter your comments below.<p>\n";
print "<form method=POST action=\"$cgiurl\">\n";
print "Your Name:<input type=text name=\"realname\" size=30 ";
print "value=\"$FORM{'realname'}\"><br>\n";
print "E-Mail: <input type=text name=\"username\"";
print "value=\"$FORM{'username'}\" size=40><br>\n";
print "City: <input type=text name=\"city\" value=\"$FORM{'city'}\" ";
print "size=15>, State: <input type=text name=\"state\" ";
print "value=\"$FORM{'state'}\" size=15> Country: <input type=text ";
print "name=\"country\" value=\"$FORM{'country'}\" size=15><p>\n";
print "Comments:<br>\n";
print "<textarea name=\"comments\" COLS=60 ROWS=4></textarea><p>\n";
print "<input type=submit> * <input type=reset></form><hr>\n";
print "Return to the <a href=\"$guestbookurl\">Guestbook</a>.";
print "\n</body></html>\n";

# Log The Error
if ($uselog eq '1') {
&log('no_comments');
}

exit;
}

sub no_name {
print "Content-type: text/html\n\n";
print "<html><head><title>No Name</title></head>\n";
print "<body><h1>Your Name appears to be blank</h1>\n";
print "The Name Section in the guestbook fillout form appears to\n";
print "be blank and therefore your entry to the guestbook was not\n";
print "added. Please add your name in the blank below.<p>\n";
print "<form method=POST action=\"$cgiurl\">\n";
print "Your Name:<input type=text name=\"realname\" size=30><br>\n";
print "E-Mail: <input type=text name=\"username\"";
print " value=\"$FORM{'username'}\" size=40><br>\n";
print "City: <input type=text name=\"city\" value=\"$FORM{'city'}\" ";
print "size=15>, State: <input type=text name=\"state\" ";
print "value=\"$FORM{'state'}\" size=2> Country: <input type=text ";
print "value=USA name=\"country\" value=\"$FORM{'country'}\" ";
print "size=15><p>\n";
print "Comments have been retained.<p>\n";
print "<input type=hidden name=\"comments\" ";
print "value=\"$FORM{'comments'}\">\n";
print "<input type=submit> * <input type=reset><hr>\n";
print "Return to the <a href=\"$guestbookurl\">Guestbook</a>.";
print "\n</body></html>\n";

# Log The Error
if ($uselog eq '1') {
&log('no_name');
}

exit;
}

# Log the Entry or Error
sub log {
$log_type = $_[0];
open (LOG, ">>$guestlog");
if ($log_type eq 'entry') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate]<br>\n";
}
elsif ($log_type eq 'no_name') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No Name<br>\n";
}
elsif ($log_type eq 'no_comments') {
print LOG "$ENV{'REMOTE_HOST'} - [$shortdate] - ERR: No ";
print LOG "Comments<br>\n";
}
}

# Redirection Option
sub no_redirection {

# Print Beginning of HTML
print "Content-Type: text/html\n\n";
print "<html><head><title>Thank You</title></head>\n";
print "<body><h1>Thank You For Signing The Guestbook</h1>\n";

# Print Response
print "Thank you for filling in the guestbook. Your entry has\n";
print "been added to the guestbook.<hr>\n";
print "Here is what you submitted:<p>\n";
print "<b>$FORM{'comments'}</b><br>\n";

if ($FORM{'url'}) {
print "<a href=\"$FORM{'url'}\">$FORM{'realname'}</a>";
}
else {
print "$FORM{'realname'}";
}

if ( $FORM{'username'} ){
if ($linkmail eq '1') {
print " &lt;<a href=\"mailto:$FORM{'username'}\">";
print "$FORM{'username'}</a>&gt;";
}
else {
print " &lt;$FORM{'username'}&gt;";
}
}

print "<br>\n";

if ( $FORM{'city'} ){
print "$FORM{'city'},";
}

if ( $FORM{'state'} ){
print " $FORM{'state'}";
}

if ( $FORM{'country'} ){
print " $FORM{'country'}";
}

print " - $date<p>\n";

# Print End of HTML
print "<hr>\n";
print "<a href=\"$guestbookurl\">Back to the Guestbook</a>\n";
print "- You may need to reload it when you get there to see your\n";
print "entry.\n";
print "</body></html>\n";

exit;
}
 
P

Paul Lalli

Ok. since this is perl and it deals with cgi i was hoping someone can help
me out. I am working on a guest book and I get to the addguest part. and
when i click on the submit button to add it to the cgi part it says it can
not find my guestbook.cgi file. i have that file in my cgi-bin folder what
is up
It may because i don't have a sendmail thing. what can you tell me and am i
not adding something that needs to be there?

There's no way I'm going to look through this massive amounts of code to
find a possible error. However . . . .
$guestbookurl = "http://www.yourhost.com/guestbook/guestbook.html";
$guestbookreal = "/home/yourhostt/guestbook/guestbook.html";
^^^^^
Is that intentional? everywhere else, it says 'yourhost', but here it's
'yourhostt'. Is it possible that's the file it can't find?
^^^^

You said it can't find your guestbook.cgi file, but you're posting to
a guestbook.pl file. Is this possibly the cause of your error?

Paul Lalli

<snipped a LOT of lines>
 
P

pfancy

Paul Lalli said:
There's no way I'm going to look through this massive amounts of code to
find a possible error. However . . . .

^^^^^
Is that intentional? everywhere else, it says 'yourhost', but here it's
'yourhostt'. Is it possible that's the file it can't find?

^^^^

You said it can't find your guestbook.cgi file, but you're posting to
a guestbook.pl file. Is this possibly the cause of your error?

Paul Lalli


^^^^^

No typo. thanks for noticing. that could be it. i going to look at that.
that could be it. Thanks a million.
 
G

Gunnar Hjalmarsson

pfancy said:
I am working on a guest book ...

Are you? To me it appears as if you are just configuring Matt's
guestbook script. Even if it makes me nostalgic (modifying that script
was my first acquaintance with Perl), you'd better pick another
script, such as the guestbook script here, instead:

http://nms-cgi.sourceforge.net/scripts.shtml
It may because i don't have a sendmail thing.

What would the "sendmail thing" have to do with a guestbook script?
 
P

pfancy

Paul Lalli said:
There's no way I'm going to look through this massive amounts of code to
find a possible error. However . . . .

^^^^^
Is that intentional? everywhere else, it says 'yourhost', but here it's
'yourhostt'. Is it possible that's the file it can't find?

^^^^

You said it can't find your guestbook.cgi file, but you're posting to
a guestbook.pl file. Is this possibly the cause of your error?

Paul Lalli
<snipped a LOT of lines>

I did look into that. i did notice i wrote guestbook.cgi i have been so
frustrated in trying to get it figured out. I'm sorry. i wrote the wrong
one done. i looked in to. i did mean .pl though. instead of .cgi. I'm sorr
for such a long code. but i did not know what else to do. but it gives me
the 404 error. I'm beginning to think that i have some code typed wrong
because it looks for the guestbook.pl file and says it can't find it, it
told me to set the chmod for 755 and i did. but it claims it can't find the
file but i have placed the guestbook.pl into the cgi bin.
 
P

pfancy

I did look into that. i did notice i wrote guestbook.cgi i have been so
frustrated in trying to get it figured out. I'm sorry. i wrote the wrong
one done. i looked in to. i did mean .pl though. instead of .cgi. I'm sorr
for such a long code. but i did not know what else to do. but it gives me
the 404 error. I'm beginning to think that i have some code typed wrong
because it looks for the guestbook.pl file and says it can't find it, it
told me to set the chmod for 755 and i did. but it claims it can't find the
file but i have placed the guestbook.pl into the cgi bin.


here is the link from where i found that guestbook at
http://www.scriptarchive.com/
 
E

Eric Schwartz

pfancy said:
I'm sorr for such a long code. but i did not know what else to do.
but it gives me the 404 error.

What gives you which 404 error?
I'm beginning to think that i have
some code typed wrong because it looks for the guestbook.pl file and
says it can't find it,

You have such a confusion of pronouns here, I can't even begin to
figure out what you're talking about. 'it' seems to mean at least
three things in that one sentence alone.
it told me to set the chmod for 755 and i did. but it claims it
can't find the file but i have placed the guestbook.pl into the cgi
bin.

Fundamentally, you have three problems:

1) You're using Matt Wright's scripts, instead of the superior
replacements at http://nms-cgi.sourceforge.net/.

2) You're not good at partitioning problems-- that's not a crime, and
I'm not insulting you by saying it, but it's a skill you'll need to
develop. Partitioning a problem is where you figure out if the
problem is caused by the web server's set up, the script's logic,
or the script's configuration. In your case, I imagine it's a
mixture of the three, but because you don't seem to understand the
distinctions yourself, it's hard to say for sure.

3) You are either unfamiliar with your web host's configuration, or
your script's setup. If it's the first, then you need to talk to
your web hosting provider. If the second, you need to talk to
whoever supports your scripts.

This is another advantage of using the NMS scripts-- Matt no longer
supports his code, if he ever did, and there is a mailing list to
help you with problems running the NMS code.

-=Eric
 
P

pfancy

Eric Schwartz said:
What gives you which 404 error?


You have such a confusion of pronouns here, I can't even begin to
figure out what you're talking about. 'it' seems to mean at least
three things in that one sentence alone.


Fundamentally, you have three problems:

1) You're using Matt Wright's scripts, instead of the superior
replacements at http://nms-cgi.sourceforge.net/.

2) You're not good at partitioning problems-- that's not a crime, and
I'm not insulting you by saying it, but it's a skill you'll need to
develop. Partitioning a problem is where you figure out if the
problem is caused by the web server's set up, the script's logic,
or the script's configuration. In your case, I imagine it's a
mixture of the three, but because you don't seem to understand the
distinctions yourself, it's hard to say for sure.

3) You are either unfamiliar with your web host's configuration, or
your script's setup. If it's the first, then you need to talk to
your web hosting provider. If the second, you need to talk to
whoever supports your scripts.

This is another advantage of using the NMS scripts-- Matt no longer
supports his code, if he ever did, and there is a mailing list to
help you with problems running the NMS code.

-=Eric

Thats cool. I agree with you. I know there is a lot that i need to learn.
I have downloaded the script from the nms site. The guest book is the same
as the one i got but better right.
 
J

Jonathan Stowe

Gunnar Hjalmarsson said:
What would the "sendmail thing" have to do with a guestbook script?

The 'guestbook' script (both the NMS and the original MSA one) have a
facility to send a message to someone when something was added to the
guestbook. I seem to recall the MSA one had the additional feature of
acting as an anonymous mail proxy for spammers.

/J\
 
G

Gunnar Hjalmarsson

Jonathan said:
The 'guestbook' script (both the NMS and the original MSA one) have
a facility to send a message to someone when something was added to
the guestbook.

Aha, thanks, should have realized that.
I seem to recall the MSA one had the additional feature of acting
as an anonymous mail proxy for spammers.

Sounds plausible. Maybe an imported feature from Matt's formmail? :)
 
J

Joe Smith

Purl said:
NMS scripts are truly no more secure, no less buggy, than
are Matt Wright's scripts.

The NMS scripts do more checking of user input, and avoid the
blatant security holes found in many of Matt Wright's scripts.

Back in 1994, when everybody was just starting to learn how
to use perl for CGI, Matt's scripts looked pretty nifty.
During the last 10 years, webmaster's have learned to be
justifiably paranoid about possible exploits. Matt's scripts
have not been updated properly.

-Joe
 
P

pfancy

Joe Smith said:
The NMS scripts do more checking of user input, and avoid the
blatant security holes found in many of Matt Wright's scripts.

Back in 1994, when everybody was just starting to learn how
to use perl for CGI, Matt's scripts looked pretty nifty.
During the last 10 years, webmaster's have learned to be
justifiably paranoid about possible exploits. Matt's scripts
have not been updated properly.

-Joe


that is interesting. Nobody is perfect. but i find anyone to come up with a
program or cool stuff for the web pretty smart. I've yet to get that far.
but will try to learn what i can. thanks for your support.
 
D

Dave Cross

You might enjoy testing the "Not Matt's Scripts" for date printing.
Those NMS scripts I have tested, a few only, cannot correctly
produce a date / time stamp on some platforms because of use
of buggy POSIX. Major mistake, that.

I presented this to NMS years back. They promptly denied any
problem. Their denial, however, did not cause their scripts to
suddenly start printing a date / time stamps.

Actually I said something along the lines of "that's interesting, please
tell me more about the platform that you are running it on and we'll
investigate further". You have never responded to that request. The offer
still stands tho'.

You are, however, the only person to have ever reported that bug and we've
not been able to reproduce it.
NMS scripts are truly no more secure, no less buggy, than
are Matt Wright's scripts.

If you care to explain what you mean by this claim then we can discuss it.
You are the only person who makes this claim.
They are less efficient, though.

I assume this is based on our use of CGI.pm in preference to Matt's buggy
CGI parameter parsing code.
A reader should be cautioned I do hold a bad attitude about
Not Matt's Scripts because when they first came online they
spammed newsgroups with advertisements which contained
personal insults directed at Matt Wright. My opinions and
comments are inherently biased no matter how hard I try to
be fair and open minded.

I posted announcements in two relevant newsgroups. This is a matter of
public record. Anyone can check the posts in Google. I don't know why you
persist in exaggerating the incident.
Questioned about their former name, "Not Matts Scripts," and
their use of personal insults directed at Matt, again adamant
denial. However, their homepage was suddenly edited to change
their name and to remove insults directed at Matt. Their use
of insults in advertisements, and spamming of newsgroups,
also came to an abrupt halt, leading to a historical event,
an event of the one and only time Alan Flavell agreed with me.

Well I don't remember ever denying it, but I do remember toning down the
text on our web site. Again this is all a matter of public record and I'm
happy to supply references if anyone is interested.
I am sure there are some good scripts at NMS. Chances are
those boys corrected mistakes I highlighted, although they
denied the very existence of those mistakes.

I don't think we've ever fixed a bug that you have pointed out, because we
have never got a sensible bug report from you.
Personally, I would not rate NMS scripts as being any better
nor any worse than Matt's scripts. Only change I found was
coding techniques sans any change in quality.

And another claim that is made by no-one but you :)
Matt, however, is a gracious gentleman.

He certainly seems to like us more than you do.

http://scriptarchive.com/nms.html

Dave...
 
P

pfancy

Actually I said something along the lines of "that's interesting, please
tell me more about the platform that you are running it on and we'll
investigate further". You have never responded to that request. The offer
still stands tho'.


I'm sorry. I must have missed that. I'm running windows xp home edition.
thanks for your patients.
 
J

Joe Smith

Purl said:
You might enjoy testing the "Not Matt's Scripts" for date printing.
Those NMS scripts I have tested, a few only, cannot correctly
produce a date / time stamp on some platforms because of use
of buggy POSIX. Major mistake, that.

Which platforms have buggy POSIX?
-Joe
 
D

Dave Cross

Pffttt... you change your story with each response.

Nope. That's the same thing that I've always said. If you send us a proper
report about the problems that you have with POSIX then we'll investigate
it. We'd prefer the report to go to (e-mail address removed), but
posting it here will do just fine too.

The thread we are discussing is at
http://www.google.com/groups?th=5608ee6ce3a61aa2

[ snip ]
Say, didn't Alan RFC Flavell chastise you for spamming newsgroups
with advertisements which contain personal insults directed
at Matt Wright?

Yep, he sho nuff did, Bubba.

Well, he didn't accuse us of spamming (that was just you) but with a few
other folks he expressed some distaste for the content of the site. It was
his comments and those of a handful of other people that persuaded me to
change the wording on the site. If anyone is interested in reading the
whole thread instead of mine and Kira's interpretation of it, then it's at
http://www.google.com/groups?th=1ebc6c2875e80d3b

Dave...
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top