Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

permissions...

by Anonymous Monk
on Dec 21, 2002 at 07:29 UTC ( [id://221598]=perlquestion: print w/replies, xml ) Need Help??

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

Hello! I am asking for your help because my host doesn't know too much about cgi-bin permissions (imagine that...)

The server where my scripts are is running:
RedHat Linux 7.2
Plesk Server Administrator 2.5.5
Apache V1.3.23

When I upload weather.pl to:
http://www.robj.ca/cgi-bin/weather.pl?city=Kingston_ON
using ws ftp (no SSH access) and use the CHMOD function of ws ftp to set weather.pl to 755 and cities.dat to 644, everything works fine. If I put weather.pl and cities.dat into a folder called weather and CHMOD it to 777 or 755 (or anything for that matter) it won't work!!!! :(((((

I have used directories in a cgi-bin in the past and never had any problem... any ideas??

Thanks!!!!

Merry Christmas!!!!
Rob

Replies are listed 'Best First'.
Re: permissions...
by seattlejohn (Deacon) on Dec 21, 2002 at 07:45 UTC

    Since you can run the script in the main /cgi-bin directory, I assume you haven't made mistakes like uploading as binary instead of ASCII, ignoring case-sensitivite filenames, or anything like that.

    Do you have access to your server error logs? That might be the easiest way to get an idea what's going wrong.

    If not, I would start by trying to figure out whether the problem is indeed in your server config/permissions or somewhere in your script. (Seems unlikely that the script would fail simply because you changed directories, but without code I can't be sure what assumptions your program might make.) Anyway, you could write an extremely trivial cgi script -- like "hello, world" -- and see if you can get that to run within a directory under cgi-bin. If so, you could put use CGI::Carp qw(fatalsToBrowser) near the beginning of your script and probably get a better idea where the failure is occurring.

    I suppose it's possible that Apache is configured to execute scripts only within cgi-bin, though if that's the case I'm surprised that you would've been able to use this technique in the past.

            $perlmonks{seattlejohn} = 'John Clyman';

      I suppose it's possible that Apache is configured to execute scripts only within cgi-bin,

      More than just possible - This is the default and is set via the ScriptAlias directive (see below)

      though if that's the case I'm surprised that you would've been able to use this technique in the past.

      Lazy administrators can use AddHandler to make any .cgi .pl .foo .bar .baz file executable regardless of where it is in the dir structure but as you can imagine this is not regarded as a *good* ie secure way of doing business

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Thanks for the quick reply John! I tried running a different script (a basic date and time script). Worked fine in root dir of cgi-bin.

      Then tried running with SSI. Worked fine. Put it into a directory in the bin called "sdf" and tried to access with SSI. Got this error:
      Sat Dec 21 01:56:37 2002 error client 24.226.53.114 unable to include "/cgi-bin/sdf/datetime.pl" in parsed file /home/httpd/vhosts/robj.ca/httpdocs/test/index.shtml

      and this error when I tried to browse to datetime.pl in the sdf directory:
      Sat Dec 21 01:56:53 2002 error client 24.226.53.114 Premature end of script headers: /home/httpd/vhosts/robj.ca/cgi-bin/sdf/datetime.pl

      I think it is probably that scripts can only be run in the root dir of the bin?...

      script works fine: http://www.robj.ca/cgi-bin/datetime.pl
        Can Apache even be configured to do this? If so, why would it be an option to do so? I would hate to have 500+ files in one directory!!

        By the way, here is my dog: http://www.robj.ca/brae/
Re: permissions...
by tachyon (Chancellor) on Dec 21, 2002 at 12:00 UTC

    You look like you have an Apache issue. Specifically the script alias directives in httpd.conf need work. Around line 475 (very roughly but it is a long way into the file) of httpd.conf (/etc/httpd/conf/httpd.conf) you will find (well you can't cause you gotta be root but anyway)

    # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the realname directory are treated as applications and # run by the server when requested rather than as documents sent to th +e client. # The same rules about trailing "/" apply to ScriptAlias directives as + to # Alias. # ScriptAlias /cgi-bin/ "/var/httpd/cgi-bin/" # you need a ScriptAlias for your subdir(s) like this ScriptAlias /cgi-bin/subdir/ "var/httpd/cgi-bin/subdir/"

    There is a workaround using AddHandler but it is very insecure as it will allow anything that ends in .pl or .cgi or whatever you set to be executed - regardless of where it is in the dir structure so I'm not going to show you how.

    As an aside Apache 1.23 has some significant security issues. Your ISP should go to 1.27

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      I agree that this is an apache issue, and the host admin would have to take care of it. But I disagree that this is the default configuration.

      I've always been able to have just one ScriptAlias directive and scripts run fine in subdirectories. There is no line like # you need a ScriptAlias for your subdir(s) like this in the default httpd.conf that came with the 1.3.27 source.

      Also, the location of httpd.conf and the position of any ScriptAlias directives are system dependent. Is your Apache installation by any chance from an RPM or other third party package?

        This is cut directly from a working Redhat 7.3 box's old Apache 1.23 httpd.conf file (dir locations modified but otherwise stock):

        # # ScriptAlias: This controls which directories contain server scri +pts. # ScriptAliases are essentially the same as Aliases, except that # documents in the realname directory are treated as applications +and # run by the server when requested rather than as documents sent t +o the client. # The same rules about trailing "/" apply to ScriptAlias directive +s as to # Alias. # # ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" ScriptAlias /cgi-bin/ "/home/www/cgi-bin/" # # "/var/www/cgi-bin" should be changed to whatever your ScriptAlia +sed # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory>

        Exactly the same stuff is in my current 1.27 conf file (apache built from source). It is also in the 1.27 httpd.conf.default file although it points to the default location (/usr/lib/apache/cgi-bin/)

        The location of httpd.conf in /etc/httpd/conf/httpd.conf is correct for a Redhat 7.2 box. Line number is of course ballpark. In 1.23 it is actually at 750 in my file but I have a couple of hundred module lines....

        With this config I can run cgi's in subdirs of CGI bin proviced that the dir is 755 and script 755 of course. The reason that our respondent has issues will actually probably relate to other directives in the conf file (perhaps CGI is set up via Alias) preventing execution in subdirs but the quickest way to fix the issue should be to specifically allow it in the desired subdir....

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        Wow, thanks for all the input guys. I just got this host yesterday morning. I do not know much about his Apache installation. Everything about his server is here:
        http://pjmco.ca/html/packages.html

        I am going to direct him to this page for a better explaination of what is going on, as I won't be able to explain it very well.

        I don't know if it makes any difference, but his hosting is virtual. I searched through his testimonials page to find someone with a subdirectory in the bin. I found one. I pinged their site and we have same ip, so I am assuming that we are on same server. Their extention was .cgi (mine was .pl), so I tried one of my .cgi scripts in a subfolder and nothing...
Re: permissions...
by mt2k (Hermit) on Dec 22, 2002 at 18:44 UTC

    For starters, there is a reason why scripts are only permitted to run in the cgi-bin... it's what the cgi-bin is meant to be used for. If scripts were just allowed to run anywhere, then you'd find out that plain html files, text files, images, and everything non-script would fail to load because Apache would try to execute them as scripts.

    As for using ScriptAlias for every single directory you want to run scripts in, why? That's what the Options directive is meant for! If your host permits it, stick an htaccess file in the subdirectory you want to execute scripts in, and place the following line(s) in it:

    # .htaccess file # You might need the following line. Maybe, maybe not AddHandler cgi-script .pl # Turn on CGI script handling in this directory # and all subdirectories Options +ExecCGI

    -------------------------------------
    eval reverse@{[lreP
    =>q{ tsuJ\{qq},' rehtonA'
    ,q{\}rekcaH },' tnirp']}[1+1+
    1,1-1,1+1,1*1,(1+1)*(1+1)];
    -------------------------------------
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-20 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found