PDA

View Full Version : Ready to flip my scripting lid!


jaxong
09-12-2007, 09:36 PM
Hello,
I've built a form in Adobe LiveCycles and I want to submitt the data to an email via the post method. I cant get anything from the pdf form I've created to submitt. So I got another script in order to test out the post method on my server. But I cant get that to do anything either. Here is my form and here is the link www.texassaltwaterfishingmagazine.com/form.htm (http://www.texassaltwaterfishingmagazine.com/form.htm)

<form method="post" action="scriptform.cgi">

Your name: <input type="text" name="name"><br>
Your email: <input type="text" name="email"><br>
Your comment: <textarea name="comment"></textarea><br>

<input type="submit">
</form>

Here is the scriptform.cgi file

#!/home/texassal/perl

use CGI::Carp qw(fatalsToBrowser);

# The following accepts the data from the form and splits it into its component parts

if ($ENV{'REQUEST_METHOD'} eq 'POST') {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}



# Then sends the email

open (MESSAGE,"| /usr/sbin/sendmail -t");

print MESSAGE "To: you\@example.com\n"; # Don't forget to escape this @ symbol!
print MESSAGE "From: " . $FORM{name} . ", reader\n";
print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")\n";

print MESSAGE "Subject: Feedback from $FORM{name} \n\n";

print MESSAGE "$FORM{name} wrote:\n\n";
print MESSAGE "Comment: $FORM{comment}\n\n";
print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";

close (MESSAGE);

&thank_you; #method call
}

I have loaded the cgi file into the same directory as the html file containing my form. When I attemp to test the form it doesn't ever submit. The status bar says "waiting on http://www....../scriptform.cgi" Then it finaly times out. I've adjusted the permissions to be 755 on the file. Still nothing does anyone have any advice on this? Also if any one knows about the Adobe LiveCycles coding and can help with that I would really appreciate it. Thanks for your help in advance!

nikkiH
09-12-2007, 10:32 PM
Are you sure that's the path to sendmail, and why are you using -t?

jaxong
09-13-2007, 03:09 PM
Thanks for your response! Well I checked my sendmail path and it wasn't correct so I changed that. I'm not sure why it uses the -t that was the way the script was when I got it from the tutorial site. What does that represent? What would you suggest differently? Thanks again for your assistance.
Jax

FishMonger
09-13-2007, 05:00 PM
Are you sure that's the path to sendmail, and why are you using -t?This is why -t is being used (quoted from man sendmail).
-t Read message for recipients. To:, Cc:, and Bcc: lines will be
scanned for recipient addresses. The Bcc: line will be
deleted before transmission.

I'm not sure why it uses the -t that was the way the script was when I got it from the tutorial site. What does that represent? What would you suggest differently? Thanks again for your assistance.
Jax
I would suggest not using that tutorial site anymore. That's not a very good example of how to do what you want.


It's not using the warnings or strict pragmas, which should be used in EVERY Perl script that you write.

The method that it's using to process the form submission has been depreciated for nearly 10 years. Instead, you should be using the CGI module.

It's not checking the return code of the open call to verify that it was successful. Fixing that would have told you that it was having a problem finding sendmail.

For portability and reliability, it's better to use one of Perl's mail modules instead of manually rolling your own i.e., your pipe to sendmail.

Production level cgi scripts should be running under taint mode.

Here's a rewrite that addresses most, but not all of these issues.
#!/home/texassal/perl

use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use MIME::Lite; # This is one of the more popular mail modules, but there are a number of others.

my $cgi = CGI->new;
my %form = $cgi->Vars;

my $mail_message = <<MESSAGE;
$form{name} wrote:

Comment: $form{comment}

Sent by: $form{name} ($form{email}).

MESSAGE

my $mail = MIME::Lite->new(
From => $form{name},
To => 'me@myhost.com',
Subject => "Feedback from $form{name}",
Data => $mail_message
);

$mail->send;
thank_you();

jaxong
09-13-2007, 07:08 PM
I tried replacing the cgi file with the one you supplied fishmonger but still no luck. The page just times out? Am I still doing something wrong? I changed the sendmail path that you posted because I originally had it wrong. /usr/sbin/sendmail is what is should be. But still nothing. Thanks for all the assistance!

KevinADC
09-13-2007, 09:16 PM
MIME::Lite is not a core module but if it is not installed you sould be getting an error mesage about not finding it in @INC with the code Fsihmonger posted.

Can you check the server error log?

jaxong
09-14-2007, 02:38 PM
Here are the log files I could see related to the submission of my form.
MAIN error_log:
[Fri Sep 14 07:29:03 2007] [error] mod_ssl: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] (System error follows)
[Fri Sep 14 07:29:03 2007] [error] System: Connection reset by peer (errno: 104)
[Fri Sep 14 07:29:07 2007] [error] mod_ssl: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] (System error follows)
[Fri Sep 14 07:29:07 2007] [error] System: Connection reset by peer (errno: 104)
sendmail: No recipients found, aborting...
failed to open log file
fopen: Permission denied
[Fri Sep 14 07:30:27 2007] [error] [client 207.243.120.11] Premature end of script headers: /home/texassal/public_html/cgi-bin/scriptform.cgi
[Fri Sep 14 07:30:31 2007] [error] mod_ssl: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] (System error follows)
[Fri Sep 14 07:30:31 2007] [error] System: Connection reset by peer (errno: 104)
[Fri Sep 14 07:30:33 2007] [error] mod_ssl: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] (System error follows)
[Fri Sep 14 07:30:33 2007] [error] System: Connection reset by peer (errno: 104)
[Fri Sep 14 07:30:33 2007] [error] mod_ssl: SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] (System error follows)
[Fri Sep 14 07:30:33 2007] [error] System: Connection reset by peer (errno: 104)
mail.logisticaytransportehn.com: WEBMAIL BOUNCING TO: http://mail.logisticaytransportehn.com:2095/


SUEXEC error_log:
--------------------------------------------------------------------------------

[2007-09-14 07:35:29]: info: (target/actual) uid: (texassal/texassal) gid: (texassal/texassal) cmd: scriptform.cgi

Thanks again for all your help everyone!

FishMonger
09-14-2007, 06:23 PM
The main problem is the shebang line i.e., #!/home/texassal/perl
My example had it set to that path only because that's what you had posted. I'm sure that Perl is not located in that path, instead it's probably
#!/usr/bin/perl

If the script still doesn't work after fixing the shebang line, then the problem will be that the MIME::Lite module is not installed on your system. You have several options.

Install the MIME::Lite module. (This would be my first choice)

Use the Net::SMTP module instead, which is a core module that is on your system. http://search.cpan.org/~gbarr/libnet-1.22/Net/SMTP.pm

Use the piped open call to sendmail, but clean it up a little and add some error handling.

KevinADC
09-14-2007, 06:35 PM
looks like he has other problems fish, all those "reset" and "handshake interruption" errors are suspicious. Any ideas?

FishMonger
09-14-2007, 07:10 PM
looks like he has other problems fish, all those "reset" and "handshake interruption" errors are suspicious. Any ideas?

It's unclear if those issues are related to this script. Based on the timestamps I'd say they are more likely related to some other script/process that is accessing an https page. But I could be wrong.

KevinADC
09-14-2007, 07:24 PM
On second thought you're probably right fish.

jaxong
09-28-2007, 02:57 PM
Well Thanks for checking it out. I do have another script going which has some errors so thats why you probably see other issues. I went ahead and figured out how to get a php script to work for this process. Thanks again for all your input.