Not able to convert into cgi script

H

HP

Hi All

i have written prtl script
but when i am converting into the cgi scipt its not printing the value

perl script is-


#!/3rdparty/contrib/bin/perl

use strict;
use warnings;
use HTTP::Request::Common;
use LWP::UserAgent;

my $svUser;
my $svPassword;

print " Number: ";
chomp($svUser = <STDIN>);
print "Password: ";
system "stty -echo";
chomp($svPassword = <STDIN>);
system "stty echo";
print "\n";

my $svRequest = "Login";
my $url = "https://xx.xx.com:1343/fwua.htm";

my $ua = LWP::UserAgent->new;
my $res = $ua->request(POST $url, [svUser => $svUser, svPassword =>
$svPassword, svRequest => $svRequest]);
if ($res->is_success) {
my $resp = $res->as_string;
if($resp =~ /Invalid password/) {
print "Invalid Username/Password\n";
exit 1;
} else {
print "Login successful\n";
exit 0;
}
} else {
print "Failed: ", $res->status_line, "\n";
exit 1;


my cgi script is

#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use LWP::protocol::http;
use HTTP::Request;
use warnings;
#use LWP::Debug '+';
use Getopt::Long;
use Pod::Usage;
use XML::Simple;
use Data::Dumper;
use CGI;
my $cgi =new CGI;

my $svUser = $cgi->param("cnt");
my $svPassword = $cgi->param("passwd");
my $cr = $cgi->param("CR");



my $svRequest = "Login";
my $url = "https://47.152.183.41:3443/fwua.htm";
# exit with an error if the command-line parameters were not specified
#die "Usage: $0 <userid> <password> \n\n";
#unless defined $URL && length $URL

# Create user agent for querying data
my $ua = LWP::UserAgent->new();
# push @{ $ua->requests_redirectable }, 'POST';


# perform the request and obtain the response from the web server;

my $title "";
my $mess = "";
my $res = $ua->request(POST $url, [svUser => $svUser, svPassword =>
$svPassword, svRequest => $svRequest]);
if ($res->is_success) {
my $resp = $res->as_string;
if($resp =~ /Invalid password/) {



$title = "authentication failed";
$mess = "Invalid Username/Password\n";



exit 1;
}
else {

$title = "authentication successful";
$mess = "Login successful";



}
}

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

print "<html><head>\n";
print "<title>$title</title></head>\n";
print "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#FF0000\"
vlink=\"#800000\">\n";
print "<h1>$mess</h1>\n";

print "<a href=\"../perl/tutorial.html\"><b>Back</b></a> to the
Tutorial\n";
print "</body></html>\n";


when i debug the code i found that my program is not going into the
authentication loop.so it s not printing the value of $title and $mess.

please help me out.
 
G

Gunnar Hjalmarsson

[ No answer after 2 hours? How rude of us! ]
#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use LWP::protocol::http;
use HTTP::Request;
use warnings;
#use LWP::Debug '+';
use Getopt::Long;
use Pod::Usage;
use XML::Simple;
use Data::Dumper;

Are you using all those modules?

This is one module you ought to use when debugging a CGI script:

use CGI::Carp 'fatalsToBrowser';
if ($res->is_success) {
my $resp = $res->as_string;
if($resp =~ /Invalid password/) {

$title = "authentication failed";
$mess = "Invalid Username/Password\n";

exit 1;

Do you really want the script to exit there?

Btw, your indenting style is a little odd...
when i debug the code i found that my program is not going into the
authentication loop.

I don't see any loop.
so it s not printing the value of $title and $mess.

What does it do then? Which error messages does it generate?
 
H

HP

Hi Gunnar

hey i mean its falling into
if ($res->is_success)

so its not printing the value of $title and $mess.
 
H

HP

i am getting this error on browser

Failed: 500 Can't load
'/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/HTML/Parser/Parser.so'
for module HTML::parser:
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/HTML/Parser/Parser.so:
failed to map segment from shared object: Permission denied
Content-type: text/htm
 
S

Samwyse

HP said:
i am getting this error on browser

Failed: 500 Can't load
'/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/HTML/Parser/Parser.so'
for module HTML::parser:
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/HTML/Parser/Parser.so:
failed to map segment from shared object: Permission denied
Content-type: text/htm

Your web server is running as some user. The file Parser.so apparently
has its permissions set such that this user can't read the file.
 
D

Dr.Ruud

HP schreef:
so its not printing

For HP and everybody else with "User-Agent: G2/#.#":

"How can I automatically quote the previous message when I post a
reply?"
http://groups.google.co.uk/support/bin/answer.py?answer=14213

See also:
http://www.safalra.com/special/googlegroupsreply/

What's good 'netiquette' when posting to Usenet?
http://groups.google.co.uk/support/bin/answer.py?answer=12348
http://directory.google.com/Top/Computers/Usenet/Etiquette/

But Google needs you to vote for 'Default quoting of previous message in
replies'
http://groups-beta.google.com/support/bin/request.py?contact_type=features
 
G

Gunnar Hjalmarsson

[ You replied to a message in the Usenet group comp.lang.perl.misc. Even
if you posted from an interface provided by Google, most readers use
other tools for reading Usenet groups. Hence it's very important to
provide some context when you reply to a message, or else people who
might be able to help won't have a clue what you are talking about.
Typically that's accomplished by quoting parts of the message you are
replying to. ]
i am getting this error on browser

Failed: 500 Can't load
'/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/HTML/Parser/Parser.so'
for module HTML::parser:
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/HTML/Parser/Parser.so:
failed to map segment from shared object: Permission denied
Content-type: text/htm

Samwyse gave you a plausible explanation.

In addition to that, I'm not sure why your script is trying to load
HTML::parser, so one way to get rid of the error might be to not load a
bunch of modules that you still don't make use of.
 
H

HP

so one way to get rid of the error might be to not load a
bunch of modules that you still don't make use of.

now i am using

#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use LWP::protocol::http;
#use HTTP::Request;
use warnings;
#use LWP::Debug '+';
#use Getopt::Long;
#use Pod::Usage;
#use XML::Simple;
#use Data::Dumper;
use CGI;
use CGI::Carp 'fatalsToBrowser';

but the error is still there.
 
G

Gunnar Hjalmarsson

HP said:
now i am using

#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use LWP::protocol::http;
#use HTTP::Request;
use warnings;
#use LWP::Debug '+';
#use Getopt::Long;
#use Pod::Usage;
#use XML::Simple;
#use Data::Dumper;
use CGI;
use CGI::Carp 'fatalsToBrowser';

but the error is still there.

Then you'd better fix the permission issue that Samwyse called your
attention to.
 
H

HP

once again i am posting my code here.

#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use LWP::protocol::http;
#use HTTP::Request;
use warnings;
#use LWP::Debug '+';
#use Getopt::Long;
#use Pod::Usage;
#use XML::Simple;
#use Data::Dumper;
use CGI;
use CGI::Carp 'fatalsToBrowser';


my $cgi =new CGI;
my $svUser = $cgi->param("cnt");
my $svPassword = $cgi->param("passwd");
my $cr = $cgi->param("CR");





my $svRequest = "Login";
my $url = "https://xx.xx";



# Create user agent for querying data
my $ua = LWP::UserAgent->new();
# push @{ $ua->requests_redirectable }, 'POST';


# perform the request and obtain the response from the web server;

my $title = "";
my $mess = "";



my $res = $ua->request(POST $url, [svUser => $svUser, svPassword =>
$svPassword, svRequest => $svRequest]);

if ($res->is_success) {

my $resp = $res->as_string;
if($resp =~ /Invalid password/) {



$title = "authentication failed";
$mess = "Invalid Username/Password\n";



}
else {

$title = "authentication successful";
$mess = "Login successful";

}

}
else {
print "Failed: ", $res->status_line, "\n";


}

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

print "<html><head>\n";
print "<title>$title</title></head>\n";
print "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#FF0000\"
vlink=\"#800000\">\n";
print "<h4>$mess</h4>\n";
print "</body></html>\n";


i am taking the $cr , $passwd ,$cnt from html webpage.
this script is not printing anything on browser.since $title and $mess
both are empty string(as initialised as empty)
by debugging the code i found that
$title and $mess not getting any value since its not going into if
($res->is_success)
check .
while same perl script without cgi work fine on command line.
 
H

HP

i have done some changes thats why i posted the code once again. gunnar
help me.
why my browser is not printing anything.
 
P

Paul Lalli

HP said:
common please help me some one

1) Stop whining
2) "come on" is not the same as "common"
3) You have been repeatedly asked to follow the standard Usenet
conventions and quote context when posting a reply. One poster was
even nice enough to send you links to relevant information on how to do
that. You continue to be rude by ignoring these requests.
4) No one here is obligated to help you. We do it out of our own
desire to volunteer to help people. You are not encouraging anyone to
help you.


Go read the Posting Guidelines. Go read the links about properly
quoting context in replies. Then, perhaps, try again. If you're very
fortunate, not everyone will have already added you to their killfile.

Paul Lalli
 
A

Anno Siegel

HP said:
common please help me some one

Your whining is slowly but surely getting on everyone's nerves.

Posting version after version of code that nobody can run but you
is not going to help. Read the posting guidelines for this group
(posted here frequently) and put some effort in asking a reasonable
question. Re-reading your posts with some attention, or even using
a spell-checker wouldn't hurt either.

Anno
 
J

Joe Smith

HP said:
common please help me some one

When you post newsgroups like this, don't expect answers immediately.
A two-day response time is typical.
Do _NOT_ complain when no-one has solved your problem within two hours.
That is extremely rude, since USENET does not have real-time propagation.


You need to reduce your program to the simplest form that works
before doing any debugging.

#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
use CGI;
use CGI::Carp 'fatalsToBrowser';
print "Content-type: text/plain\n\n OK so far!\n";

If you can't even get that print() statement to run, then you've
got some serious problems that need to be fixed before doing
anything else.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top