Not able to convert into cgi script

Discussion in 'Perl Misc' started by HP, Jan 5, 2006.

  1. HP

    HP Guest

    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.
     
    HP, Jan 5, 2006
    #1
    1. Advertising

  2. HP

    HP Guest

    comman please some one help me out
     
    HP, Jan 5, 2006
    #2
    1. Advertising

  3. HP

    HP Guest

    common please some one help me out
     
    HP, Jan 5, 2006
    #3
  4. [ No answer after 2 hours? How rude of us! ]

    HP wrote:
    >
    > #!/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?

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jan 5, 2006
    #4
  5. HP

    HP Guest

    Hi Gunnar

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

    so its not printing the value of $title and $mess.
     
    HP, Jan 5, 2006
    #5
  6. HP

    HP Guest

    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
     
    HP, Jan 5, 2006
    #6
  7. HP

    Samwyse Guest

    HP wrote:
    > 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.
     
    Samwyse, Jan 5, 2006
    #7
  8. HP

    Dr.Ruud Guest

    [OT] quoting (was: Re: Not able to convert into cgi script)

    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

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Jan 5, 2006
    #8
  9. HP

    HP Guest

    Re: quoting (was: Re: Not able to convert into cgi script)

    Hi
    So what should i do , make it right.
    i mean please suggest me some solution.
     
    HP, Jan 5, 2006
    #9
  10. [ 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. ]

    HP wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jan 5, 2006
    #10
  11. HP

    HP Guest

    >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.
     
    HP, Jan 5, 2006
    #11
  12. HP wrote:
    >>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.


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

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jan 5, 2006
    #12
  13. HP

    HP Guest

    Re: quoting (was: Re: Not able to convert into cgi script)

    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.
     
    HP, Jan 5, 2006
    #13
  14. Gunnar Hjalmarsson, Jan 5, 2006
    #14
  15. HP

    HP Guest

    Re: quoting

    i have done some changes thats why i posted the code once again. gunnar
    help me.
    why my browser is not printing anything.
     
    HP, Jan 5, 2006
    #15
  16. HP

    HP Guest

    Re: quoting

    common please help me some one
     
    HP, Jan 5, 2006
    #16
  17. HP

    Paul Lalli Guest

    Re: quoting

    HP wrote:
    > 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
     
    Paul Lalli, Jan 5, 2006
    #17
  18. HP

    Anno Siegel Guest

    Re: quoting

    HP <> wrote in comp.lang.perl.misc:
    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Jan 5, 2006
    #18
  19. Re: quoting (was: Re: Not able to convert into cgi script)

    HP <> wrote:

    > once again i am posting my code here.



    I've had enough.

    Off to the killfile you go!


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jan 5, 2006
    #19
  20. HP

    Joe Smith Guest

    Re: quoting

    HP wrote:
    > 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
     
    Joe Smith, Jan 5, 2006
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Muzammil
    Replies:
    1
    Views:
    1,162
    red floyd
    Aug 28, 2008
  2. K Viltersten

    Not able to put class into namespace

    K Viltersten, Apr 9, 2009, in forum: ASP .Net
    Replies:
    5
    Views:
    319
    bruce barker
    Apr 11, 2009
  3. sed_y
    Replies:
    0
    Views:
    1,030
    sed_y
    Feb 15, 2012
  4. kath
    Replies:
    4
    Views:
    672
    J. Gleixner
    Apr 9, 2007
  5. Yogi
    Replies:
    1
    Views:
    437
    Peter Makholm
    Sep 13, 2012
Loading...

Share This Page