Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Troubles with CGI

by downer (Monk)
on Feb 05, 2008 at 14:14 UTC ( [id://666292]=perlquestion: print w/replies, xml ) Need Help??

downer has asked for the wisdom of the Perl Monks concerning the following question:

Some of you may remember my crazy problems with CGI as discussed in the chatterbox yesterday. I was having problems using any HTTP GET within my CGI scipt, this problem still remains a mystery. Rather than continuing to bang my head on the wall, I have decided to pursue a different architecture.

The gist of the problem is: I have a list of URLs, I wish to display the HTML associated with each of those urls, allowing the user to make some judgments on each page via some radio buttons. Since LWP etc. dont seem to want to work for me, I have pre-fetched each of the pages, storing each as a unique, numbered file stored in a separate directory. here is a toy example code that exhibits the problems I am having

#!/usr/local/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser carpout); $| = 1; print header(-type => 'text/html'), start_html(); my $path = '/var/www/cgi-bin/samples'; print "hi"; undef $/; opendir DIR, $path or die "cant open dir $!"; my @parts = sort(readdir(DIR)); foreach my $x (@parts) { open FILE, $path."/".$x or die "cant open $x $!"; my $data = ''; $data = <FILE>; print $data; close FILE; system("date"); sleep(5); }
the error message I get is as follows:
Software error: cant open dir Permission denied at /var/www/cgi-bin/test3.cgi line 15.
I have given a+rw permission to all the files associated, and a+rwx permission to the directory "samples" and all parent directories in the file system tree. I'm clueless. help me monks, you're my only hope.

Replies are listed 'Best First'.
Re: Troubles with CGI
by moritz (Cardinal) on Feb 05, 2008 at 14:22 UTC
    Just a guess: it could be selinux enabled web server, or one with some other security enhancements.

    selinux provides different security contexts, and a CGI script is run with a "www-server" (don't know the exact name) security context and can't access files with other contexts, even when the file permissions would allow that.

    So go and find out more about your environment - what kind of OS is this? does it use selinux? if yes, can you change the security context of the sample directory?

    (Usually Red Hat servers come with selinux out of the box, don't know about others).

      i am using fedora core 4, and is seems you are exactly right! that helped a lot, thanks.
        Given that, it's entirely possible that selinux may have also been the cause of your problems with not being able to do GETs from your CGI code. Might want to check whether your system's selinux config allows applications in the www-server (or whatever it's called) context to open outbound ports.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://666292]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found