![]() |
Very Frustrating
Hi everyone, the following code works from my linux shell as root or
the 'nobody' accounts: ----------------------------- #!/usr/bin/perl #use strict; #use LWP::Simple; use LWP::UserAgent; #use URI::URL; print "Content-type: text/html\n\n"; print <<HTML; <html> <head> <title>TEST</title> </head> <body> HTML my $url_variable = $input{'URL'}; my $ua = new LWP::UserAgent; $ua->timeout(120); my $request = new HTTP::Request('GET', 'http://www.yahoo.com'); my $response = $ua->request($request); my $content = $response->content(); print "$content"; print <<HTML; </body> </html> </head> HTML --------------------------------- BUT when I hit that same .pl file with my browser I get the following error: 500 Can't connect to www.yahoo.com:80 (Bad hostname 'www.yahoo.com') Can someone help me please? I'm doing something idiotic, I know, and anything you could do to help would be appreciated. -G |
Re: Very Frustrating
On 29 July, 18:48, Tad J McClellan <ta...@seesig.invalid> wrote:
> schnibitz <schnib...@gmail.com> wrote: > > #use strict; > > You lose all of the benfits of that pragma when you comment > it out like that. > > -- > Tad McClellan > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/" Thank you, I've tried both ways BTW, and it doesn't give me any more helpful messages. I checked DNS on my server. I can ping the address, and it resolves to an IP just fine. I've checked the perl resolver by issuing a special perl command, and it too resolves just fine. I can wget the site without issue, my /etc/hosts file has two measly entries, so I don't think that a corrupt hosts file has anything to do with it. Why would it work command-line, but not when invoked through the browser? |
Re: Very Frustrating
On 29 July, 19:59, Tony Curtis <tony_curti...@yahoo.com> wrote:
> > Thank you, I've tried both ways BTW, and it doesn't give me any more > > helpful messages. *I checked DNS on my server. *I can ping the > > address, and it resolves to an IP just fine. *I've checked the perl > > resolver by issuing a special perl command, and it too resolves just > > fine. *I can wget the site without issue, my /etc/hosts file has two > > measly entries, so I don't think that a corrupt hosts file has > > anything to do with it. *Why would it work command-line, but not when > > invoked through the browser? > > maybe there's something restricted about the web server? > > if it works from the command-line then there's nothing > obviously wrong with the perl logic: maybe there's > something to do with the web server config that breaks > things? > > hth > t Hi there, great suggestion, and I'll be doing that from now on. I added all of that in, and I'm still not getting any helpful errors. I don't understand why it works in the shell, but not when invoked from a browser. I know that the browser hits that file from a different user (nobody I think) and I've tried invoking it from the "nobody" acct BTW. Here is the updated code with your suggested additions, and minor clarifications: _______________________________________ #!/usr/bin/perl use strict; use warnings; use diagnostics; #use LWP::Simple; use LWP::UserAgent; #use URI::URL; my $content = 0; my $error = 0; print "Content-type: text/html\n\n"; print <<HTML; <html> <head> <title>TEST</title> </head> <body> HTML &getpage; print "$content"; print "$error"; print <<HTML; </body> </html> </head> HTML sub getpage { my $ua = new LWP::UserAgent; $ua->timeout(120); my $request = new HTTP::Request('GET', 'http://www.yahoo.com'); my $response = $ua->request($request); if ($response->is_success) { $content = $response->content; } else { $error = $response->status_line, "\n"; } } _____________________________________ Any other things I can try? |
Re: Very Frustrating
On 29 July, 19:59, Tony Curtis <tony_curti...@yahoo.com> wrote:
> > Thank you, I've tried both ways BTW, and it doesn't give me any more > > helpful messages. *I checked DNS on my server. *I can ping the > > address, and it resolves to an IP just fine. *I've checked the perl > > resolver by issuing a special perl command, and it too resolves just > > fine. *I can wget the site without issue, my /etc/hosts file has two > > measly entries, so I don't think that a corrupt hosts file has > > anything to do with it. *Why would it work command-line, but not when > > invoked through the browser? > > maybe there's something restricted about the web server? > > if it works from the command-line then there's nothing > obviously wrong with the perl logic: maybe there's > something to do with the web server config that breaks > things? > > hth > t Hadn't thought of that, I'll check into that possibility. Thank you! |
Re: Very Frustrating
On 29 July, 21:13, Tad J McClellan <ta...@seesig.invalid> wrote:
> schnibitz <schnib...@gmail.com> wrote: > > I > > don't understand why it works in the shell, but not when invoked from > > a browser. *I know that the browser hits that file from a different > > user (nobody I think) and I've tried invoking it from the "nobody" > > acct BTW. > > If you "think" wrong, then the fact that it runs as nobody is irrelevant. > > What is relevant is if it runs from the command line as the same use > that your CGI program runs as. > > So the first step is to determine what user your CGI programs run as. > > * * #!/usr/bin/perl > * * print "Content-Type: text/plain\n\n"; > * * system 'whoami'; > > > print "$content"; > > * * perldoc -q vars > > -- > Tad McClellan > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/" Hi Tad, fair enough, I removed the quotes. I normally don't use them, but I started just trying anything (yeah I'm that desperate). Anyway, I added the "system 'whoami';" command, and it shows "apache" instead of "nobody". So I su to "apache" and ran the script again. Flawless. Not a single error or anything thrown that I can see. Still getting "bad hostname" error when accessed from the browser. |
Re: Very Frustrating
On 29 July, 22:01, schnibitz <schnib...@gmail.com> wrote:
> On 29 July, 21:13, Tad J McClellan <ta...@seesig.invalid> wrote: > > > > > schnibitz <schnib...@gmail.com> wrote: > > > I > > > don't understand why it works in the shell, but not when invoked from > > > a browser. *I know that the browser hits that file from a different > > > user (nobody I think) and I've tried invoking it from the "nobody" > > > acct BTW. > > > If you "think" wrong, then the fact that it runs as nobody is irrelevant. > > > What is relevant is if it runs from the command line as the same use > > that your CGI program runs as. > > > So the first step is to determine what user your CGI programs run as. > > > * * #!/usr/bin/perl > > * * print "Content-Type: text/plain\n\n"; > > * * system 'whoami'; > > > > print "$content"; > > > * * perldoc -q vars > > > -- > > Tad McClellan > > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/" > > Hi Tad, fair enough, I removed the quotes. *I normally don't use them, > but I started just trying anything (yeah I'm that desperate). *Anyway, > I added the "system 'whoami';" command, and it shows "apache" instead > of "nobody". *So I su to "apache" and ran the script again. > Flawless. *Not a single error or anything thrown that I can see. > Still getting "bad hostname" error when accessed from the browser. Okay, one other quick thing . . . So when I add the IP for www.yahoo.com into the /etc/hosts file, here's what I get when I run it from my browser now: 0500 Can't connect to www.yahoo.com:80 (Permission denied) Different message. Anyone make anything of that? |
Re: Very Frustrating
On 29 July, 22:01, schnibitz <schnib...@gmail.com> wrote:
> On 29 July, 21:13, Tad J McClellan <ta...@seesig.invalid> wrote: > > > > > schnibitz <schnib...@gmail.com> wrote: > > > I > > > don't understand why it works in the shell, but not when invoked from > > > a browser. *I know that the browser hits that file from a different > > > user (nobody I think) and I've tried invoking it from the "nobody" > > > acct BTW. > > > If you "think" wrong, then the fact that it runs as nobody is irrelevant. > > > What is relevant is if it runs from the command line as the same use > > that your CGI program runs as. > > > So the first step is to determine what user your CGI programs run as. > > > * * #!/usr/bin/perl > > * * print "Content-Type: text/plain\n\n"; > > * * system 'whoami'; > > > > print "$content"; > > > * * perldoc -q vars > > > -- > > Tad McClellan > > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/" > > Hi Tad, fair enough, I removed the quotes. *I normally don't use them, > but I started just trying anything (yeah I'm that desperate). *Anyway, > I added the "system 'whoami';" command, and it shows "apache" instead > of "nobody". *So I su to "apache" and ran the script again. > Flawless. *Not a single error or anything thrown that I can see. > Still getting "bad hostname" error when accessed from the browser. Okay, last post I swear. That last error got me to realize that selinux was hurting me. It would not allow my script to open up a port. Thank you to everyone for bearing with me, and hopefully this will help some poor soul out there. |
| All times are GMT. The time now is 09:04 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.