Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Setup problem

by dvdj (Initiate)
on Sep 05, 2004 at 12:56 UTC ( [id://388599]=perlquestion: print w/replies, xml ) Need Help??

dvdj has asked for the wisdom of the Perl Monks concerning the following question:

Can somebody please help me!!

I am looking for Monk guidance for the first time so apologies in advance if I haven't followed protocall with the following submission.

I'm having an addressing issue with a PERL script i'm trying to use on my site. I'm new to learning PERL, so don't have the expertise to write a script that directs the content of a form to my email address and sends an automated reply to the submitter, with a thank you page. So I found a script online and am trying to get it to work on my server. I know I have included alot here! But i do so in the hope that a thorough look can be given, as I am at a real loss as to what I may have configured wrong. Many thanks in advance for any help.

Stuart

Visit http://www.truevitality.co.uk to view the contact page and the error messages that are coming up.

The set up on the server is as follows:

folder / >>>>>folder mail
>>>>>folder public_ftp
>>>>>folder public_html
>>>>>>>>>>>>>>>>>folder _private
>>>>>>>>>>>>>>>>>folder _vti_bin
>>>>>>>>>>>>>>>>>folder _vti_log
>>>>>>>>>>>>>>>>>folder _vti_cnf
>>>>>>>>>>>>>>>>>folder _vti_pvt
>>>>>>>>>>>>>>>>>folder _vti_txt
>>>>>>>>>>>>>>>>>folder cgi-bin
>>>>>>>>>>>>>>>>>>>>>>>>>>file AlphaMail.pl
>>>>>>>>>>>>>>>>>>>>>>>>>>file AlphaMail.txt
>>>>>>>>>>>>>>>>>folder images
>>>>>file a_fail.htm
>>>>>file a_thanks.htm
>>>>>file contact.htm
The PERL script that I am using is as follows: (My notes in Bold)
#!/usr/local/bin/perl <strong>(this address has been confirmed as accu +rate with my server provider)</strong> ############################################################# # Instructions: # # - Use WordPad.exe or any plain text editor to edit # - Set your path to Perl as needed (first line at top) # - Set ALL variables appropriately (below, see notes) # - Take special care with the path to your sendmail (below) # - Send the script to the server in ascii (I assume that using notepa +d, saving the file as .pl and ftp the file up to the server, IS sendi +ng the script in ascii??) # - Set script permissions - check your doc or ask admin (apparently t +here aren't any) # - See a_faq.html for HTML set-ups in alphamail.zip file # - Required html pages are also provided in alphamail.zip # ############################################################# ##### SETTABLE VARIABLES #################################### # URL to go to if there is a problem with form input $ErrorPage = "http://www.truevitality.co.uk/public_html/a_fail.htm"; ( +this i believe to be the address to the a_fail.htm page that i did) # URL to go to when form has been successfully submitted $ThankPage = "http://www.truevitality.co.uk/public_html/a_thanks.htm"; + (again I believe this address to be correct. I have tried it without + the /public_html as well) # URL to go to if a 'foreign' referer calls the script $EvilReferer = "http://www.dvdj.co.uk"; (I just used another web addre +ss that i have for this) # E-mail address to send intake form to (your address) # If not using PERL 5, escape the @ thus: \@ instead of @ $YourEmail = 'sackland@blueyonder.co.uk'; (This is my personal email t +hat i was using to test. The actual email would be info@truevitality. +co.uk But didn't think this would effect anything) # Script works only on your server(s) - ('URL1','URL2') @referers = ('www.truevitality.co.uk','truevitality.co.uk'); # Location of mail program - check your doc or ask admin $MailProgram = '/usr/sbin/sendmail'; (again this address has been conf +irmed by my host support team) # Subject of the e-mail autoreply to the submitter $Subject = "Thank you for Your Enquiry!"; # Header line in the auto-reply message $Header = "True Vitality"; # Brief tail message for body of e-mail autoreply $TailMessage = "If your message requires a reply, then please be assur +ed that we'll get back to you as soon as possible."; # Your signature lines the end of the autoreply e-mail $Signature1 = "Laura Wilenius"; $Signature2 = "www.truevitality.co.uk"; ##### END OF SETTABLE VARIABLES ############################ ##### MAIN PROGRAM ######################################### # ___ Do not edit below this line __________________________ &CheckReferingURL; &ReadParse; $Name = $in{'Name'}; $Email = $in{'Email'}; $Message = $in{'Message'}; &CheckEmailAddressFormat; &CheckFields; &GetDate; &SendSubmission; &SendAutoReply; print "Location: $ThankPage\n\n"; exit; # _________________________________________________________ sub SendSubmission { open (MAIL,"|$MailProgram -t"); print MAIL "To: $YourEmail\n"; print MAIL "From: $Email\n"; print MAIL "Subject: $Subject\n"; print MAIL "$Date\n\n"; print MAIL "E-Mail Message\n\n"; print MAIL "From: $Name\n"; print MAIL "Email: $Email\n\n"; print MAIL "Message:\n\n"; print MAIL "$Message\n\n"; close (MAIL); } # _________________________________________________________ sub SendAutoReply { open (MAIL,"|$MailProgram -t"); print MAIL "To: $Email\n"; print MAIL "From: $YourEmail\n"; print MAIL "Subject: $Subject\n"; print MAIL "$Header\n"; print MAIL "$Date\n\n"; print MAIL "$Subject\n\n"; print MAIL "You sent the following:\n\n"; print MAIL "==============================\n\n"; print MAIL "Name: $Name\n"; print MAIL "Email: $Email\n\n"; print MAIL "Message:\n\n"; print MAIL "$Message\n\n"; print MAIL "==============================\n\n"; print MAIL "$TailMessage\n\n"; print MAIL "Best regards,\n\n\n"; print MAIL "$Signature1\n"; print MAIL "$Signature2\n\n"; close (MAIL); } # _________________________________________________________ sub GetDate { @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday',' +Saturday'); @months = ('01','02','03','04','05','06','07','08','09','10','11','12' +); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); $year = $year+1900; $Date = "$days[$wday] $months[$mon]/$mday/$year"; } # _________________________________________________________ sub ReadParse { local (*in) = @_ if @_; local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" ) {$in = $ENV{'QUERY_STRING'};} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} else { $in = ( grep( !/^-/, @ARGV )) [0]; $in =~ s/\\&/&/g; } @in = split(/&/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2); $key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $in{$key} .= "\0" if (defined($in{$key})); $in{$key} .= $val; } return length($in); } # _________________________________________________________ sub CheckEmailAddressFormat { if (index($Email, "@") < 1) {&DoEmailError;} if (index($Email, ".") < 1) {&DoEmailError;} if (index($Email, " ") > -1) {&DoEmailError;} } sub CheckFields { if (!$Name || $Name eq ' ') {&DoEmailError;} if (!$Email || $Email eq ' ') {&DoEmailError;} if (!$Message || $Message eq ' ') {&DoEmailError;} } sub DoEmailError { print "Location: $ErrorPage\n\n"; exit; } # _________________________________________________________ sub CheckReferingURL { if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ /$referer/i) { $check_referer = '1'; last; }}} else {$check_referer = '1';} if ($check_referer != 1) { print "Location: $EvilReferer\n\n"; exit; }} # _________________________________________________________ exit; ##### End of Script ########################################
The contact page contains the following form code. Please note i'am aware that i have additional fields that are not included in the PERL script which i intend to address once it's working. I hope I'm right in thinking that this wouldn't stop this script from working. But i have renamed the appropriate fields to match the scalars listed in the script.
<form action="/cgi-bin/AlphaMail.pl" method="POST"> <table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td>NAME</td> <td><input type="text" name="Name" class="formAreas"></td> </tr> <tr> <td>PHONE NUMBER</td> <td><input type="text" name="telephone" class="formAreas"></td> </tr> <tr> <td>EMAIL</td> <td><input type="text" name="Email" class="formAreas"></td> </tr> <tr> <td>COMMENT/ENQUIRY</td> <td><textarea name="Message" cols="15" rows="4" class="formAreas"></te +xtarea></td> </tr> <tr> <td>PLACE OF EXERCISE</td> <td><input type="text" name="plcOfExercise" class="formAreas"></td> </tr> <tr> <td>HOW DID YOU HEAR ABOUT TRUE VITALITY</td> <td><input type="text" name="howDidUHear" class="formAreas"></td> </tr> <tr> <td><br> <input name="resetVitality" type="reset" class="formAreas"></td> <td><br> <input type="submit" class="formAreas"></td> </tr> </table> </form>

Replies are listed 'Best First'.
Re: Setup problem
by Zaxo (Archbishop) on Sep 05, 2004 at 14:29 UTC

    PodMaster is right to steer you away from this script, but he doesn't say why. I'll describe several of the warts on that thing.

    On its coding standard, this script is very primitive. It uses subroutines as a kind of simple substitution macro, taking no arguments and acting only through global variables. The subroutines occasionally return some useful value, but the caller never makes any use of the retrun values. Error handling is done with exit, which is mighty presumptious of a subroutine. It is uncatchable and prevents any more gracious message to the user.

    The ReadParse routine attempts to do what CGI.pm actually does for you automatically. Not taking advantage of that core module is a red flag. As it is, ReadParse does not appear to work. It seems to try to parse both raw posts and query strings in the same way -- and wrong for either.

    CheckReferingURL is easily spoofed and some browsers don't accomodate it well. It is well-known that HTTP_REFERER is not useful for security or use restriction.

    CheckEmailAddressFormat fails for legal addresses (like dvdj@localhost). This is a notoriously difficult function to implement, and you're usually just as well off without it.

    Follow PodMaster's advice and try the nms archive.

    P.S. we spell it "Perl" or "perl".

    After Compline,
    Zaxo

      Thanks to all of you, the problem is finally now resolved. Thanks Podmaster for your link to the nms archive the script there was fantastic. As it turned out in the end, It wasn't a script or addressing issue. It was the chmod execution permissions that ihadn't set correctly. Many thanks again to all of you for your speedy and helpful responses.
Re: Setup problem
by PodMaster (Abbot) on Sep 05, 2004 at 13:13 UTC
      TFmail is definitely higher quality code. But are you sure it has the auto-reply feature the poster wants? I couldn't find that feature just now.
        *Yawn* I said After that you gotta read/configure TFmail and it will do what you want. Do I have to be sure? Could you have made sure?
        confirmation_template - If this field is set then it must be the name of an email template that will be u +sed to send a mail back to the user confirmi +ng their submission. CAUTION: since the us +er could give any email address (not just t +heir own) and submit repeatedly, there is a r +isk that some nasty person will use this to mailb +omb a third party. Only switch this on if y +ou really need it. Template directives tha +t depend on user input will be disabled fo +r this template, so that this feature can't be +used to send SPAM. Default: no confirmation ema +il.

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Setup problem
by Rhys (Pilgrim) on Sep 05, 2004 at 13:36 UTC
    Okay, I see several possible problems here. First, though, some protocol issues:

    1) protocol, not protocall
    2) Perl, not PERL
    3) a lot, not 'alot'. (You wouldn't write 'alittle', would you?)
    4) You did include an awful lot of stuff from the script, but no information about the system, nor about where you got the script. Those would have been helpful. You also didn't say what the script is doing. I assume it isn't working, but are there any error messages? Does it send mail, but it's empty? What exactly is the problem?

    We really need the answer to 4) before we can help you. What happens when the form is submitted? Also, if you log on to the Web server via command line, what happens if you do:

    perl -wc ./AlphaMail.pl

    Lastly, let's confirm a few things for you:

    1) /usr/sbin/sendmail is correct for $MailProgram.

    2) As long as you used only WordPad or Notepad to edit the file, your mailer should not have done anything strange with it. If you're worried about newlines, log on to the Web server via SSH (or - egad! - Telnet) and run pico -w AlphaMail.pl or, if they don't have pico, try nano -w AlphaMail.pl. Once you have the file open, press Ctrl-O, Enter, Ctrl-X. If you had any newline/carriage return weirdness, it'll be gone.

    3) All of the other variables in the 'configurable' part of the script are just strings used to construct the messages, so it doesn't really matter if they're correct or not.

    So the only thing that comes to mind is, if you log on to the Web server and run /usr/sbin/sendmail -t, what does it do? If nothing appears to happen, but you don't get your prompt back, that's probably good. (Press Ctrl-C to abort sendmail.) If not, what happens instead?

    Also, what did you use to FTP the file up to the server? Windows' command-line FTP util? Did you remember to use binary mode (type 'bin')? If not, you should send the file again (just overwrite the previous copy), making sure to use binary mode.

    --J

    Update: Added suggestion re: binary mode FTP.

      Your advice about ftp binary mode is wrong. When you transfer a win32-ish text file in binary mode, the splatline is seen as "#!/usr/bin/perl\r". There is no such executable file, resulting in a "File not found" error. ASCII mode does line end translation and prevents such errors.

      After Compline,
      Zaxo

        This is only true if the file was originally created on a Win32 system. Wordpad (and maybe Notepad) can correctly edit a UNIX-style text file (sans \r) without mangling it, as the original script itself suggests, and the author says she did.

        I've have no end of trouble transferring things in ASCII mode. The only time I've used any mode other than binary was when I sent a text file to a VAX using EBCDIC mode (bleh!). If I have to do some file cleanup - whether by using the 'pico cheat' or a cleanup Perl script - that's fine, but I'd rather do it myself than have my file transfer program doing things for me.

        Which is why I use Linux and write my own Perl code. :-) I don't do everything myself, but I want the option.

        NOTE: I sent e-mail to the author of the original post shortly after she posted it. No reply yet, and AFAIK, she only came back to the site once or twice to see if there were any answers.

      You wouldn't write 'alittle', would you?

      You'd be surprised how many people do.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://388599]
Approved by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-23 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found