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

I recently set up an ftp-like webserver for my intranet and would now like to have Apache default to it rather than mod_autoindex.c. The server is a single perl script called Drall.

I have downloaded and tried to make sense of Apache::AutoIndex 0.08, which is a perl script that replaces mod_autoindex, but to no avail. The httpd.conf mod_dir command
'DirectoryIndex index.html /cgi-bin/drall.pl?left=$1'
is exactly what I need, but $1 is taken literally, unlike in
RedirectMatch ^/(.*) '/cgi-bin/drall.pl?left=$1'
(which redirects everything, not what I want).

Since httpd.conf can't offer me a solution, I turn back to the perl code of Drall. Looking at Apache::AutoIndex, I can't begin to decipher how it hooks in and the documentation for gettting the thing running is horrid. I know only that this has to do (probably?) with PerlTransHandler and PerlHandler. PerlTransHandler links to URI Translation, which is almost completely undocumented over at the mod_perl pages (what little they have is here).

Replies are listed 'Best First'.
Re: setting up a perl module to replace Apache's autoindex
by Chmrr (Vicar) on Jul 31, 2002 at 22:12 UTC

    If this is meant to be run only in a mod_perl environment, your best bet is probably to make Drall into a module, with a handler which looks something like:

    use Apache::Constants qw(:common DIR_MAGIC_TYPE); sub handler { $r = shift; return DECLINED unless $r->content_type eq DIR_MAGIC_TYPE; do_stuff(); }

    Documentation on the stages of an Apache request, and hence the uses of the mod_perl hooks into them, can be found in the excellent mod_perl book, which has some chapters available online. Chapter 7 may help with what you are trying to do.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: setting up a perl module to replace Apache's autoindex
by PodMaster (Abbot) on Aug 01, 2002 at 07:28 UTC
    Like you've been informed already, you'll need mod_perl to run Apache::AutoIndex.

    I did something like this using a simple CGI script, which employs caching via File::Cache.

    You can see it at http://crazyinsomniac.perlmonk.org/perl/index/

    All you need to do is add DirectoryIndes ... whatever you got ... /cgi-bin/scripto.pl, and have that script do pretty much what mine does (get a list of files and dirs in the current directory).

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: setting up a perl module to replace Apache's autoindex
by valdez (Monsignor) on Aug 01, 2002 at 09:41 UTC

    If I understood correctly, you want Drall to be called with the current location whenever a file index.html isn't found. You can do as follow.

    Replace the redirect to Drall with a call to a printenv script:

    DirectoryIndex index.html /cgi-bin/printenv.pl

    This way, whenever you visit a location without index.html, you get redirected to the script. If now you look at what printenv.pl says, you will see many headers prefixed by REDIRECT_, and the uri you were looking for is in REDIRECT_REQUEST_URI.

    So, the solution is to substitute printenv.pl with a script which issues a redirect to Drall with the correct paramaters, something like

    use CGI; $redir = '/cgi-bin/drall.pl?left='. $ENV{REDIRECT_REQUEST_URI}; print CGI::redirect(-uri => $redir);

    Hope this helps! Ciao, Valerio

      (I am original poster, damn cookies screwed up)
      that is EXACTLY what I needed, and thanks for explaining it; there was no REDIRECT_REQUEST_URI, but there is a REDIRECT_URL as well as a REQUEST_URI, both seem to be the same, so I am happy using REDIRECT_URL.
      (perl 5.6.1, apache 1.3.26, solaris 2.6, no mod_perl(?))

      Thanks again,
      -k

        You are welcome :) Assuming you are working under some kind of unix, you can use this command to discover what kind of HTTP server is used:

        lynx -mime_header http://www.perl.com | grep -E "^Server: "

        Ciao, Valerio