PDA

View Full Version : New to CGI can someone please advise on the attached code


DougieMcN
09-17-2007, 07:49 PM
Hi, I have created a SWF form for my website with the intention of having the information e-mailed to myself. I have uploaded the cgi script to my providers cgi bin and when I check the url to the script in a browser address bar, don't receive any apparent errors in my browser.

The problem is I don't receive the information from the form either, i.e. it doesn't get e-mailed back to myself.

I have attached the actionscript (attached to the send button) for the form text fields as well as the cgi script I have uploaded to the server and would be grateful if someone could have a look at both scripts to see if I am missing the obvious. There is of course far more to the cgi script but as far as I can see I only require the fields at the top of the script for the minimal amount of information I require. I can post the remainder if it helps.

This is my first attempt at using a cgi/perl script so any help would be appreciated, I've also replaced domain names and e-mail addresses but they are correct in the proper cgi script/flash file.

P.S. it's the lines highlighted in red Im not particularly sure about.

Thanks in advance.

<----actionscript attached to send button below------------>

stop();

var gatherForm:LoadVars = new LoadVars();

//--------------------------------------------------------------------------------\\

function sendForm()
{
gatherForm.visitor_name = fullName.text;
gatherForm.visitor_address = fullAddress.text;
gatherForm.visitor_postcode = postcode.text;
gatherForm.visitor_telNumber = telNumber.text;
gatherForm.email_address = emailAddress.text;
gatherForm.sendAndLoad("http://www.mydomain.co.uk/cgi-bin/formmail/iopost.pl", "POST");

}

this.submitButton.onRelease = function()
{
if (fullName.text == "" || fullAddress.text == "" || postcode.text == "" || telNumber.text == "")
{
gotoAndStop("error");
}

else

{
sendForm();
gotoAndStop("correct");
}
}

------------<cgi script below>-------------

#!/usr/bin/perl

# Define Variables #
# Detailed Information Found In README File. #

# $mailprog defines the location of your sendmail program on your unix #
# system. The flags -i and -t should be passed to sendmail in order to #
# have it ignore single dots on a line and to read message for recipients #

$mailprog = /usr/lib/sendmail -i -t';

# @referers allows forms to be located only on servers which are defined #
# in this field. This security fix from the last version which allowed #
# anyone on any server to use your FormMail script on their web site. #

@referers = ('www.mydomain.co.uk');

# @recipients defines the e-mail addresses or domain names that e-mail can #
# be sent to. This must be filled in correctly to prevent SPAM and allow #
# valid addresses to receive e-mail. Read the documentation to find out how #
# this variable works!!! It is EXTREMELY IMPORTANT. #
@recipients = ('myemail@me.co.uk');

# ACCESS CONTROL FIX: Peter D. Thompson Yezek #
# @valid_ENV allows the sysadmin to define what environment variables can #
# be reported via the env_report directive. This was implemented to fix #
# the problem reported at http://www.securityfocus.com/bid/1187 #

@valid_ENV = ('REMOTE_HOST','REMOTE_ADDR','REMOTE_USER','HTTP_U SER_AGENT');

# Done

FishMonger
09-17-2007, 08:14 PM
It appears that you're using Matt Wright's old formmail script. That script is poorly written and has a number of security issues. It's not worth the time/effort to fix that script, especially when Matt himself doesn't want to fix it. You should get the the drop in replacement from the NMS project.
http://nms-cgi.sourceforge.net/scripts.shtml

Here's Matt's recommendation to use the NMS version instead of his own.
http://www.scriptarchive.com/nms.html

DougieMcN
09-17-2007, 08:42 PM
Thanks for the speedy reply FishMonger. With me being new to CGI, and if I can ask the obvious, it seems to be the TMmail.pl file I should use. If that is the case then I only appeared to need to fill in four fields in the old script as a minimum for it to work ?(the one's highlighted in red in my first post).

I've highlighted the two parts in the new script which look familiar but could you point me in the right direction of the other sections I must complete for the form to work.

I don't need to return any HTML as the form will take care of advising the user what is happening so I just need the results to be returned to me via my e-mail address from the SWF file.

Thanks again for your help.

<-----------------new code below------------------->

use constant DEBUGGING => 1;

use constant LIBDIR => '.';

use constant MAILPROG => '/usr/lib/sendmail -oi -t';

use constant POSTMASTER => 'me@myemail address.com';

use constant CONFIG_ROOT => '.';

use constant SESSION_DIR => '.';

use constant MAX_DEPTH => 0;

use constant CONFIG_EXT => '.trc';

use constant TEMPLATE_EXT => '.trt';

use constant ENABLE_UPLOADS => 0;

use constant USE_MIME_LITE => 1;

use constant LOGFILE_ROOT => '';

use constant LOGFILE_EXT => '.log';

use constant HTMLFILE_ROOT => '';

use constant HTMLFILE_EXT => '.html';

use constant CHARSET => 'iso-8859-1';

FishMonger
09-17-2007, 09:00 PM
The TFMail script is setup to return an html page. Since you don't want to return an html page, the script you want is FormMail which is the first 2 download links on that nms page (the section labeled "FormMail" not "Other Scripts". The script includes good documentation, but if you need, post the config section(s) that you don't understand.


I should have clarified that both scripts return html, but it will (or should) be easier to disable that in the FormMail script

DougieMcN
09-17-2007, 09:09 PM
Thanks again for your help FishMonger, I'll have a read through the docs. Thanks for pointing me in the right direction as well.

Cheers.

DougieMcN
09-18-2007, 08:35 PM
Hi, I think this code very nearly works now but I am having one last problem with a "POST" method error. I have looked but I can't figure out in the script where I should place this or indeed turn it of if that is what is required.

It does mention an HTML form failing to specify the POST method but I don't require an HTML page to be returned, just the data from the text fields in my SWF file to be e-mailed back to me (I am specifying the POST method in the URL address in the sendAndLoad variable in the SWF file).

If someone who knows their way around the script could show me how to bypass this I would appreciate it.

P.S. this is the error I get if I paste the URL to the script on my web server in a browser window, I also have tried the form but still get no results.

I've pasted the error below if someone could help please.

<-------------------------- error ------------------------------>

Error: GET request
The HTML form fails to specify the POST method, so it would not be
correct for this script to take any action in response to your
request.

If you are attempting to configure this form to run with FormMail, you
need to set the request method to POST in the opening form tag, like
this: <form action="/cgi-bin/FormMail.pl" method="post">

<-------------------------- /error ------------------------------>


Thanks again in advance for any help.

DougieMcN
09-18-2007, 08:42 PM
Hi, I think this code very nearly works now but I am having one last problem with a "POST" method error. I have looked but I can't figure out in the script where I should place this or indeed turn it of if that is what is required.

It does mention an HTML form failing to specify the POST method but I don't require an HTML page to be returned, just the data from the text fields in my SWF file to be e-mailed back to me (I am specifying the POST method in the URL address in the sendAndLoad variable in the SWF file).

If someone who knows their way around the script could show me how to bypass this I would appreciate it.

P.S. this is the error I get if I paste the URL to the script on my web server in a browser window, I also have tried the form but still get no results.

I've pasted the error below if someone could help please.

<-------------------------- error ------------------------------>

Error: GET request
The HTML form fails to specify the POST method, so it would not be
correct for this script to take any action in response to your
request.

If you are attempting to configure this form to run with FormMail, you
need to set the request method to POST in the opening form tag, like
this: <form action="/cgi-bin/FormMail.pl" method="post">

<-------------------------- /error ------------------------------>


Thanks again in advance for any help.

KevinADC
09-19-2007, 08:14 AM
For some reason the perl script is unable to detect that the POST method was used to send the form data. That would be a problem associated with your action script.

DougieMcN
09-19-2007, 08:28 PM
Thanks Kevin,

I've tried changing the actionscript as per below (the change is highlighted in red) I'm not totally sure I actually need to add method= but I tried it never the less.

I still get the 'specify post' error if I put the CGI file address in a browser window.

I would still welcome any thoughts or recommendations to try.

Is there anything in the newer NMS script that I should look out for with regards to the POST/GET methods.

If anyone could shed some light on the sendAndLoad conditions that would be appreciated as well.

Cheers



function sendForm()
{
gatherForm.visitor_name = fullName.text;
gatherForm.visitor_address = fullAddress.text;
gatherForm.visitor_postcode = postcode.text;
gatherForm.visitor_telNumber = telNumber.text;
gatherForm.email_address = emailAddress.text;
gatherForm.sendAndLoad("http://www.mydomain.co.uk/cgi-bin/formmail/iopost.pl", gatherForm, method="POST");

}

this.submitButton.onRelease = function()
{
if (fullName.text == "" || fullAddress.text == "" || postcode.text == "" || telNumber.text == "")
{
gotoAndStop("error");
}

else

{
sendForm();
gotoAndStop("correct");
}
}

FishMonger
09-19-2007, 09:10 PM
The problem you're having does not appear to be related to Perl, it's your swf/actionscript. Have your tried posting in one of the forums dedicated to actionscript?

DougieMcN
09-19-2007, 09:19 PM
Sorry FishMonger, I'll go over to an AS forum and try their.

Because I'm very new to Perl I'm just not sure I'm missing out the obvious from a beginners point of view or if indeed my Perl script is actually completed properly.

Thanks for your patience.

Cheers again.