Perl script Problem

I'm hosting a website that is using .pl in a form, and when you try to submit the form it doesn't work. It returns a Connect Error. I checked the file association and the connection to the mailserver is open.
kafusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Adam314Commented:
What is the exact error message you see in your browser?
What is in the error log?

Do you have this in your script perl script?
    use CGI::Carp 'fatalsToBrowser';
If not, adding it will cause the perl error message to show up in the browser as well as the error log.
0
kafusAuthor Commented:
How would I exactly add that to the script? I'm new to perl /scripting admin.

0
Adam314Commented:
Edit the perl script, and add that line as the second line in the file.

Try the web form again.  Post here whatever errors you get.
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

kafusAuthor Commented:
All I got was this:

The following error took place:
Connect error - aborted

Click here to return to previous page.

OR, click on your browser's back button to restore your data. Correct any mistakes, then submit again.

0
Adam314Commented:
post the source code for the perl
0
kafusAuthor Commented:
#!/usr/bin/perl5
use CGI::Carp 'fatalsToBrowser';
########################################################################
#On a unix system, make sure the first line has the true path to perl 5
#on your system!
#
#tgmail.pl
#
#Version 1.3, Sept., 1997.
#
#by Tom Germain | cgiguy@reach.net | http://www.cgiware.com
# and http://cgiware.olm.net
#Copyright 1997-1998, Tom Germain
#
#version 1.1: added content-type header that was missing
#version 1.2: Removed redundant socket stuff, gave priority to script
#settings for increased security. Don't need Socket.pm anymore.
#version 1.3: added from and to headers for servers that won't create them
# and added line for Solaris support.
#
#For more recent version of this script, download from sites.
#For customization of this script or other cgi you require, contact
#Tom Germain at the address above. (that's not free!!)
#
#This is freeware. You must not remove this credit. You must not
#sell, redistribute or modify this script (except for the lines that were
#designed to be changed). Each copy of this script must be downloaded from
#cgitricks.com. ISPs and Hosts: If you install this for all users on your
#system, you must always refer to this script as 'Tom Germain's tgmail'.  
#
#Requirements: Perl 5.0 or higher. May not work on some o/s that do not
#support sockets.
#
#Usage: Install in directory that is cgi enabled. Do a chmod 755 (Unix
# only). Depending on server set-up, you may have to rename it
# 'tgmail.cgi'.
#
#NOTES: The current version does not contain a timeout function, so it
# may hang on rare occasions, although I've yet to see it happen.
# If used with a form, it must be submitted with 'post' method.
# Not all smtp servers will accept to forward mail to other machines.
# You should not, out of courtesy, use a server where you aren't a paying
# customer.
#
#IMPORTANT: I offer no warranties with this freeware. Use it at your own
# risk. Tom Germain is not responsible for any damage or injury  
# received through the use of this software. I don't know how you'd injure
# yourself, however - Don't read this and drive at the same time!
#
########################################################################
#The following variables may be handed over by the form
#note: if a default is provided, script will use it instead
#As a rule, it isn't wise to let a form dictate much to a script
# as forms can be tampered with.
#
#stmp_server = your smtp server's name
#from = the letter's sender
#to = the letter's recipient
#subject = the subject of the letter
#message = the body of the letter
#okay_url = the url of the page to redirect to if the send is successful
#error_url = the url of the page to redirect to if the send fails
#note: if you use error_url, the error message will be lost
#
#*****You must define most of the following variables*************
#DEFAULT SETTINGS - will be used even if form provides values. Leave
#these blank if you want to force a form value. See explanations above.
#
$def_smtp_server = 'conan.comsoc.org';
$def_to = '';
$def_subject = '';
$def_ReqDept = '';
$def_ReqBy = '';
$def_AppBy = '';
$def_DateReq = '';
$def_VoluInit = '';
$def_SpecInit = '';
$def_Volunteers = '';
$def_GenProjReq = '';
$def_CritSucFact = '';
$def_CompDate= '';
$def_OtherDates= '';
$def_SingleUser= '';
$def_MultiUser= '';
$def_NoUsers= '';
$def_Website= '';
$def_MiscProjComm= '';
$def_ReqByVol= '';
$def_ReqByVolPos= '';
$def_Budget= '';
$def_BudgetAmt= '';
$def_BudgetApp= '';
$def_okay_url = '';
$def_error_url = '';

&parse_form;

#check if defaults should be used
if(!$def_smtp_server){
(!$TG{smtp_server})&& (&error('No smtp server defined!'));
$def_smtp_server = $TG{smtp_server};
}

if(!$def_to){
 (!$TG{to}) && (&error('No recipient address!'));
$def_to = $TG{to};
}


if(!$def_ReqDept){
# (!$TG{name}) && (&error('Name!'));
 $def_ReqDept = $TG{ReqDept};
 }
 
if(!$def_ReqBy){
# (!$TG{confname}) && (&error('confname!'));
 $def_ReqBy = $TG{ReqBy};
 }

 
 if(!$def_AppBy){
# (!$TG{company}) && (&error('Company!'));
 $def_AppBy = $TG{AppBy};
 }

 if(!$def_DateReq){
# (!$TG{address}) && (&error('Street!'));
 $def_DateReq = $TG{DateReq};
 }

if(!$def_VoluInit){
# (!$TG{address}) && (&error('Street!'));
 $def_VoluInit = $TG{VoluInit};
 }

if(!$def_SpecInit){
# (!$TG{address}) && (&error('Street!'));
 $def_SpecInit = $TG{SpecInit};
 }

if(!$def_Volunteers){
# (!$TG{address}) && (&error('Street!'));
 $def_Volunteers = $TG{Volunteers};
 }

if(!$def_GenProjReq){
# (!$TG{address}) && (&error('Street!'));
 $def_GenProjReq = $TG{GenProjReq};
 }

if(!$def_CritSucFact){
# (!$TG{address}) && (&error('Street!'));
 $def_CritSucFact = $TG{CritSucFact};
 }

if(!$def_CompDate){
# (!$TG{address}) && (&error('Street!'));
 $def_CompDate = $TG{CompDate};
 }

if(!$def_OtherDates){
# (!$TG{address}) && (&error('Street!'));
 $def_OtherDates = $TG{OtherDates};
 }

if(!$def_SingleUser){
# (!$TG{address}) && (&error('Street!'));
 $def_SingleUser = $TG{SingleUser};
 }

if(!$def_MultiUser){
# (!$TG{address}) && (&error('Street!'));
 $def_MultiUser = $TG{MultiUser};
 }

if(!$def_NoUsers){
# (!$TG{address}) && (&error('Street!'));
 $def_NoUsers = $TG{NoUsers};
 }

if(!$def_Website){
# (!$TG{address}) && (&error('Street!'));
 $def_Website = $TG{Website};
 }

if(!$def_MiscProjComm){
# (!$TG{address}) && (&error('Street!'));
 $def_MiscProjComm = $TG{MiscProjComm};
 }

if(!$def_ReqByVol){
# (!$TG{address}) && (&error('Street!'));
 $def_ReqByVol = $TG{ReqByVol};
 }

if(!$def_ReqByVolPos){
# (!$TG{address}) && (&error('Street!'));
 $def_ReqByVolPos = $TG{ReqByVolPos};
 }

if(!$def_Budget){
# (!$TG{address}) && (&error('Street!'));
 $def_Budget = $TG{Budget};
 }

if(!$def_BudgetAmt){
# (!$TG{address}) && (&error('Street!'));
 $def_BudgetAmt = $TG{BudgetAmt};
 }

if(!$def_BudgetApp){
# (!$TG{address}) && (&error('Street!'));
 $def_BudgetApp = $TG{BudgetApp};
 }
if(!$def_subject){
(!$TG{subject}) && (&error('No subject!'));
$def_subject = $TG{subject};
}

(!$def_okay_url) && ($def_okay_url = $TG{okay_url});
(!$def_error_url) && ($def_error_url = $TG{error_url});

if($def_to !~ /^([\w\-\.]+)\@([\w\-\.]+)\.[a-z]([a-z]+)$/i){
&error("$def_to isn't valid recipient address");}

&send_mail;

print "Content-type: text/html\n";

if($def_okay_url){
print "Location: $def_okay_url\n\n";
#send this link, in case browser doesn't automatically redirect:
print "<a href=\"$def_okay_url\">Click here to continue...</a>";
exit(0);
}

print "\n";
print <<EOF;
<body bgcolor="#ffffff" text="#000000">
Thank you for registering.
<p>
Click
 <a href="$ENV{HTTP_REFERER}">here</a>
 to return to previous page.
EOF
exit(0);

######################
sub send_mail
{
($x,$x,$x,$x, $here) = gethostbyname($void);
($x,$x,$x,$x, $there) = gethostbyname($def_smtp_server);
$myserver = pack('S n a4 x8',2,0,$here);
$sendserver = pack('S n a4 x8',2,25,$there);
#NOTE, if Solaris or System V, uncomment the line below and delete the one below it
#(!(socket(S,2,2,6))) && (&error('Connect error!'));
(!(socket(S,2,1,6))) && (&error('Connect error!'));
(!(bind(S,$myserver))) && (&error('Connect error!'));
(!(connect(S,$sendserver))) && (&error("!! connection to $def_smtp_server has failed!"));

select(S);
$| = 1;
select(STDOUT);

$DATA_IN = <S>;      
($DATA_IN !~ /^220/) && (&error('Connect error - aborted'));
#>>>>>>
print S "HELO tg\n";
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error('Connect error - aborted'));
#<<<<<<<<
print S "MAIL FROM:<$def_from>\n";
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error("'From' address not valid"));
#<<<<<<<<<<<<<<<
print S "RCPT TO:<$def_to>\n";
$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error('Recipient address not valid'));
#<<<<<<<<<<<<<<<
print S "DATA\r\n";
$DATA_IN = <S>;
($DATA_IN !~ /^354/) && (&error('Message send failed - try again'));
#<<<<<<<<<<<<<<<
print S <<EOF;
To: $def_to
Subject: $def_subject

REQUESTING DEPARTMENT INFORMATION
Requesting Dept: $def_ReqDept
Requested By: $def_ReqBy
Approved By:$def_AppBy
Date of Request :$def_DateReq

FOR COMSOC VOLUNTEERS ONLY
Requested By:$def_ReqByVol
Position :$def_ReqByVolPos

STAKEHOLDERS
Is this project a volunteer initiative?:$def_VoluInit
If yes, please specify initiative:$def_SpecInit
Specify volunteers and other stakeholders involved:$def_Volunteers

PROJECT SCOPE/GENERAL REQUIREMENTS
General Project Requirements: $def_GenProjReq
Critical Success Factors: $def_CritSucFact

Project Budget
Is there a budget amount for this project?:$def_Budget
How much? $def_BudgetAmt
Has the budget been approved? $def_BudgetApp

Critical Dates
Desired completion date: $def_CompDate
Other Critical Dates: $def_OtherDates

Expected Usage
Single User?: $def_SingleUser
Multi-User?: $def_MultiUser
Multi-User?: $def_NoUsers
Is it going to require a website?: $def_Website

MISCELLANEOUS PROJECT COMMENTS:$def_MiscProjComm



.
EOF

$DATA_IN = <S>;
($DATA_IN !~ /^250/) && (&error('Message send failed - try again'));
#<<<<<<<<<<<<<<<
print S "QUIT\n";
}

######
sub error
{
print S "QUIT\n";
print "Content-type: text/html\n";

if($TG{error_url} ne ""){
print "Location: $def_error_url\n\n";
#send this link, in case browser doesn't automatically redirect:
print "<a href=\"$def_error_url\">Click here to continue...</a>";
exit(0);
}

print "\n";
print <<EOF;
<body bgcolor="#ffffff" text="#000000">
<font color=red>
The following error took place:
</font>
<p>
<b>$_[0]</b>
<p>
Click
 <a href="$ENV{HTTP_REFERER}">here</a>
 to return to previous page.
<p>
OR, click on your browser's back button to restore your data. Correct any mistakes, then submit again.
EOF
exit(0);

}

#########
sub parse_form
{
local($form);
local($item_name);
local($item_value);
local(@sets);
local($set);

read(STDIN, $form, $ENV{'CONTENT_LENGTH'});
@sets = split(/&/,$form);

foreach $set (@sets)
{
($item_name, $item_value) = split(/=/,$set);
$item_value =~ tr/+/ /;
$item_value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$item_value =~ s/^( +)//;
$item_value =~ s/( +)$//;
$TG{$item_name} = $item_value;
}
}

We've been using this script for ages I'm told.


0
Adam314Commented:
Is the goal of the file to send an e-mail with the form data?  If so, there is a more popular version called nms formmail.

Anyways, there are two places in the script that can give that error.  You will get that error if the data from the mail server is not as the script expects.  Did you change your mail server, or any mail server related configs?


Change these lines to the following, and try again.  Post here what you get:

#Line 266:
($DATA_IN !~ /^220/) && (&error('Connect error - aborted' . "Got: $DATA_IN"));
 
#Line 270:
($DATA_IN !~ /^250/) && (&error('Connect error - aborted' . "Got: $DATA_IN")); 

Open in new window

0
kafusAuthor Commented:
Ok. I received this error now:

The following error took place:
Connect error - abortedGot: 220 conan.comsoc.org (NY9491.00.1c184a6e) ready for ESMTP transfer

Click here to return to previous page.

OR, click on your browser's back button to restore your data. Correct any mistakes, then submit again.
0
Adam314Commented:
Should have added what was expected.... try this instead:

#Line 266:
($DATA_IN !~ /^220/) && (&error('Connect error - aborted (expected 220), ' . "Got: $DATA_IN"));
 
#Line 270:
($DATA_IN !~ /^250/) && (&error('Connect error - aborted (expected 250), ' . "Got: $DATA_IN"));  

Open in new window

0
kafusAuthor Commented:
Alright, got this now:

The following error took place:
Connect error - aborted (expected 250), Got: 220 conan.comsoc.org (NY9491.00.1c184a6e) ready for ESMTP transfer

Click here to return to previous page.

OR, click on your browser's back button to restore your data. Correct any mistakes, then submit again.
0
Adam314Commented:
Okay... I'm not real familar with the SMTP protocol, but what looks like is happening is the server is supposed to send a message 220, then the client responsds with a hello message, then the server with a 250 message.  In this case, the server is giving another 220 message.

I'm not sure if this is a problem with the server (is it giving a 220 when it should have given a 250), or with the perl script (is the server allowed to give multiple 220 messages before a 250).

Has anything changed with your mail server?  If not, or if you can't change it back, then I'd suggest a different perl script.  You can check the website given in the script to see if there is an update to this script.  Or the nms formmail is popular for taking form data and sending an e-mail.
0
kafusAuthor Commented:
I just tried to update the Activeperl on my webserver and now the script is timing out. This is developing into a  nightmare.
0
Adam314Commented:
Did you try to update the version of perl, or the version of the script?  I don't think the problem is with your version of perl - it looks like it is either this script, or your mail server.
You could see if there is a new version of this script, or you could use another form-to-email script.  If you want to try a different script, the nms formmail is very popular:
    http://nms-cgi.sourceforge.net/

As to the timeout... are any perl scripts working?  What is in the error log?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kafusAuthor Commented:
I'm sorry for not getting back to you. We are going to go with another script. Thank you for all your help!

Regards.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.