HTTP Error 502.2 - Bad Gateway - perl

I am trying to learn Perl so I need to be able to test it locally. I have IIS7.5 and I have the pl and cgi mapped. But I am throwing this error when I test it in Chrome.
It works fine when I use the command prompt. So I don't understand what I am missing or how to troubleshoot this. I've searched all over google, can someone help me.
My test code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI;
my $test = new CGI();
print $test->header("text/html"),$test->start_html("PERL Test");
print $test->h1("PERL IS WORKING!");
print $test->end_html;
And the command console spits out a perfectly programmed HTML page:

Related

LAMPP - CGI-Script not working

Hello
I have got a LAMPP Webserver. I tried to open a CGI Script called "Hello.cgi".
It contains:
#!/usr/bin/perl
print "Hello World.\n";
The path is: /opt/lampp/htdocs/dashboard/cgi-bin/hello.cgi
When I open: "127.0.0.1/dashboard/cgi-bin/hello.cgi", I get following:
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: hello.cgi
If you think this is a server error, please contact the webmaster.
The CGI Script is written in Perl.
If you need more informations about my problem, say it, please.
~~runasas
Firstly, you should never write a Perl program without including the lines use strict; and use warnings;.
Secondly, if you have problems with a CGI program, you should check the web server error log for more details of the problem.
Thirdly, the output from a CGI program needs to include a content type header. So you'll want to add the following:
print "Content-Type: text/plain\015\012\015\012";
This becomes easier if you use the CGI module:
use CGI;
print header('text/plain');
But really, in 2016, you shouldn't be writing CGI programs - there are plenty of good alternatives available.

Email script not working on IIS

I have the following test script to send an email:
use strict;
use Net::SMTP;
print "Content-Type: text/plain\n\n";
print "Sending email...\n";
my $smtp = Net::SMTP->new('10.0.0.1', Port => 25, Timeout => 10, Debug => 1);
$smtp->mail("user1\#domain.local");
$smtp->to("user2\#domain.local");
$smtp->data();
$smtp->datasend("From: user1\#domain.local\n");
$smtp->datasend("To: user2\#domain.local\n");
$smtp->datasend("Subject: Test\n\n");
$smtp->datasend("Testing 1 2 3\n");
$smtp->datasend();
$smtp->quit;
It works fine when I run it from the command line, I get the email right away. But when I put it in C:\inetpub\wwwroot and run it from a web browser, I get the Sending email... text but then nothing. No email is sent, no error message is shown. I looked at the mail server log and no connection is even made. I'm not sure why it's working from cmd but not from IIS. Is there some extra configuration needed for the script to do this through IIS?
I also tried with sendmail() and get similar results.
First of all, add the following headers to the file
use strict 'vars';
use warnings;
use diagnostics;
use feature qw/say/;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
... your code...
# Print Warnings
warningsToBrowser(1);
That will give you more information if it's failing or throwing a warning on something.
Secondly, how did you install Net::SMTP? Make sure it, and all it's dependancies have permissions by the IIS worker process.

Why isn't this perl cgi script redirecting?

I have a perl cgi script that is exactly the following:
#!/usr/bin/perl -w
use CGI;
$query = new CGI;
print $query->redirect("http://www.yahoo.com");
At the command line things look OK:
$perl test.pl
Status: 302 Moved
Location: http://www.yahoo.com
When I load it in the browser, http://localhost/cgi-bin/test.pl, the request gets aborted, and depending on the browser I get various messages:
Connection reset by server.
No data received.
The only research I could find on this issue, stated that a common problem is printing some data or header before the redirect call, but I am clearly not doing that here.
I'm hosting it from a QNX box with the default slinger server.
The code works fine on my machine, check the following
Check the error logs, eg: tail /var/log/http/error_log
Do the chmod/chown permissions match other working CGi scripts, compare using ls -l
Does printing the standard hello world work? Change your print statement to
print $query->header(), 'Hello World';
Add the following for better errors
use warnings;
use diagnostics;
use CGI::Carp 'fatalsToBrowser';
at the command line use slinger will return some basic use options. For logging you need both syslogd and -d enabled in slinger. Ie
slinger -d &
Then look to /var/log/syslog for errors

Perl: how to fix SOAP::Lite delcampe-api-client example?

Here http://code.google.com/p/delcampe-api-client/wiki/Info#Perl is code example of delcampe-api-client in Perl. Obviously, there is an syntax error, running the code i got:
syntax error at test.pl line 9, near "-> service"
Bareword "SOAP::Lite" not allowed while "strict subs" in use at test.pl line 8.
Execution of test.pl aborted due to compilation errors.
If i change code to little bit more meaningful for me, like this:
#!/usr/bin/perl
use SOAP::Lite;
use SOAP::WSDL;
use strict;
use warnings;
my $service = new SOAP::Lite;
print $service
->uri('http://api.delcampe.net/soap.php?wsdl')
->getServerTime()
->result;
I got:
A service address has not been specified either by using SOAP::Lite->proxy() or a service description)
What is wrong with this code? What proxy? Service description?
[ If you think, i have no experience with SOAP, you are certainly right. Still, how to get this little example to work. PHP example worked nicely, but not the Perl's one. ]
If I were you, I would give "The Fine Documentation" a try. This should work, however:
#!/usr/bin/perl
use SOAP::Lite;
use SOAP::WSDL;
use strict;
use warnings;
my $service = SOAP::Lite->service('http://api.delcampe.net/soap.php?wsdl');
print $service->getServerTime()->result;
Edit:
Documentation can be found at http://guide.soaplite.com/ - also perldoc SOAP::Lite from the command line.
The example (above) on the web site appears not to work on more than one count: this one, however, is tested and works on my machine:
#!/usr/bin/perl
use SOAP::Lite;
use strict;
use warnings;
my $service = SOAP::Lite->service('http://api.delcampe.net/soap.php?wsdl');
print $service->getServerTime();

PERL file runs only on apache restart on xampp

I am running my perl file on XAMPP. First time I execute it then it works OK, but when I refresh it then it doesn't run. To make it run, I have to restart apachee. Can anybody please let me know the reason and solution?
PERL CODE IS: code
#!"D:\xampp\perl"
print "Content-type:text/html\n\n";
print "<H1>Hello World</H1>\n";
require 'D:\xampp\htdocs\sa\settings.pl';
print "Content-type:text/html\n\n"
Why aren't you using the CGI module with it's header method?
When I remove "require " Then it works fine
Then your error_log file should tell you what is going wrong. You don't check for the files existence before requiring it. You should also be including:
use strict;
use warnings;
use diagnostics;
and test running the file from the command line. You should read up on debugging Perl and CGI programs.