Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

A CGI script to list the files on my external harddrive

by Anonymous Monk
on Nov 14, 2006 at 02:33 UTC ( #583882=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks!

I am trying to write cgi script that will list the contents of my external harddrive.

Here's what I got so far and it works from the command line.

#!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $EX_DIR = "/media/EXTERNAL"; sub displayHardDriveFiles () { opendir( DIR, $EX_DIR ) || die "<H3>Cannot open $EX_DIR: $!</ +H3>\n"; print <<HTML; <table border=1> <tr><th>Files on this harddrive</th></tr> HTML foreach my $d (sort readdir(DIR)) { print "<tr><td>$d</td></tr>\n"; } print <<HTML; </table> HTML } print header; print start_html ("Welcome"); displayHardDriveFiles(); print end_html;
But when I run it in the browser I get ...
Software error: <H3>Cannot open /media/EXTERNAL: Permission denied</H3> For help, please send mail to the webmaster (root@localhost), giving t +his error message and the time and date of the error.
What am I doing wrong? Is there some change I need to make to my httpd.conf and if what would that be? Thanks!

Edit: g0n - replaced pre tags with code tags

Replies are listed 'Best First'.
Re: A CGI script to list the files on my external harddrive
by grep (Monsignor) on Nov 14, 2006 at 02:42 UTC

    Cannot open /media/EXTERNAL: Permission denied

    The difference is the user that is running the script. When you run the script, it's running under your permissions. When the web server server runs it, it's using the web server's permissions.

    Check your httpd.conf (assuming Apache) for the User and Group directive, then adjust your FS permissions accordingly.

    grep
    XP matters not. Look at me. Judge me by my XP, do you?

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: A CGI script to list the files on my external harddrive
by j3 (Friar) on Nov 14, 2006 at 02:45 UTC

    Try putting this in your script:

    print `whoami`;
    Look at the ouput in your browser, then see if that user has permission to look around in /media/EXTERNAL.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: A CGI script to list the files on my external harddrive
by osunderdog (Deacon) on Nov 14, 2006 at 03:12 UTC

    Is it possible that /media/EXTERNAL is a link? If it is, you may need to configure apache to FollowSymLinks

    This really isn't a perl issue, it's a 'can't run a script as another user.' issue.

    Hazah! I'm Employed!

      I can run th script as any user from the command line. So it is not a user issue as far as I can tell. Even if I change the User and Group in my httpd.conf to somethings like ...
      User me
      Group root
      
      The script still fails with permission errors when run a a cgi.
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-10-20 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (210 votes). Check out past polls.

    Notices?