H
HP
i am not ablt to convert this perl script into cgi
#!/3rdparty/contrib/bin/perl
use strict;
use warnings;
use HTTP::Request::Common;
use LWP::UserAgent;
my $svUser;
my $svPassword;
print "CNT 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";
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:rotocol::http;
use HTTP::Request;
use warnings;
#use LWP:ebug '+';
use Getopt::Long;
use Pod::Usage;
use XML::Simple;
use Data:umper;
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://xx.xx";
# 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";
}
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 "</body></html>\n";
i am not able to print the value of title and mess.
during the debugging i found out that the cgi script is not going into
authentication loop.
while my perl script is running fine on command line.
#!/3rdparty/contrib/bin/perl
use strict;
use warnings;
use HTTP::Request::Common;
use LWP::UserAgent;
my $svUser;
my $svPassword;
print "CNT 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";
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:rotocol::http;
use HTTP::Request;
use warnings;
#use LWP:ebug '+';
use Getopt::Long;
use Pod::Usage;
use XML::Simple;
use Data:umper;
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://xx.xx";
# 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";
}
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 "</body></html>\n";
i am not able to print the value of title and mess.
during the debugging i found out that the cgi script is not going into
authentication loop.
while my perl script is running fine on command line.