Re: DirectoryIndex ignored when using perl-handler
William McKee wrote: > Hi, > > This message is probably coming at a bad time with the recent release of > RC5. I'm still in the process of migrating from mp1 to mp2-RC4 at the > moment. I have a directory which is setup to be served via > ModPerl::Registry. When I try to open the path with only the directory > name (e.g., http://localhost/), I receive a 404 error in my browser and > get errors in my log like the following: > >Attempt to serve directory: /home/path/to/document/root/ > > If I put a filename in the url (e.g., http://localhost/index) or disable > perl-handler, Apache is correctly serving the index file. Any ideas on > why Apache would appear to be ignoring my DirectoryIndex setting? yup :) > This configuration had been working under mp1. yes, because mp1 is configured to handle requests of type DIR_MAGIC_TYPE whereas mp2 is not. this is a bug or a feature, depending on whether you think mp1 was correct or not :) see http://www.masonhq.com/?HandlingDirectoriesWithDhandlers for a good discussion, and a fixup handler that will likely fix your problem. you can also search the archives for the Apache::Dir discussion that (IIRC) yielded that document. --Geoff
Re: DirectoryIndex ignored when using perl-handler
On Tue, Apr 12, 2005 at 08:33:59PM -0400, Geoffrey Young wrote: > yes, because mp1 is configured to handle requests of type DIR_MAGIC_TYPE > whereas mp2 is not. this is a bug or a feature, depending on whether you > think mp1 was correct or not :) OK, that makes sense. I was beginning to worry about my sanity :). > see > > http://www.masonhq.com/?HandlingDirectoriesWithDhandlers > > for a good discussion, and a fixup handler that will likely fix your > problem. you can also search the archives for the Apache::Dir discussion > that (IIRC) yielded that document. Oddly, the last line of the document (before the comments) says: So none of the above solutions should be necessary in mod_perl 2, but as of this writing, I doubt that Mason handles directories with mod_perl 2 at all. I presume that's in relation to Mason. Do you think that the --permute-module would option work in my case? Any reason to use Apache::Dir in favor of reordering the modules (assuming that one has complete control over the httpd binary)? Thanks, William -- Knowmad Services Inc. http://www.knowmad.com
Re: DirectoryIndex ignored when using perl-handler
On Tue, Apr 12, 2005 at 08:33:59PM -0400, Geoffrey Young wrote: > for a good discussion, and a fixup handler that will likely fix your > problem. you can also search the archives for the Apache::Dir discussion > that (IIRC) yielded that document. Geoff, I tried using Apache::Dir. The current version on CPAN only supports mp1. Adding support for mp2 was easy enough but yielded no beneficial results (i.e., I still get 404 errors and the Apache log error). I wrote to David W. who maintains the module; he had no further suggestions so I did some further debugging. It turns out that I'm not having a problem with appending a trailing slash; Apache seems to be doing this just fine with or without the Apache::Dir module. The problem I'm having is that Apache is not setting the DirectoryIndex to a valid filename. It is instead complaining that it's trying to serve a directory. This is probably because ModPerl::Registry is handling the directory as turning off the SetHandler allows those indexes to be served (albeit I'm getting the script displayed as a text file instead of run as a perl script). I also searched the archives for Apache::Dir as well as the Apache log error but could not find a discussion about this issue. Any more ideas for me? Thanks, William -- Knowmad Services Inc. http://www.knowmad.com
Re: DirectoryIndex ignored when using perl-handler
William McKee wrote: > On Tue, Apr 12, 2005 at 08:33:59PM -0400, Geoffrey Young wrote: > >>for a good discussion, and a fixup handler that will likely fix your >>problem. you can also search the archives for the Apache::Dir discussion >>that (IIRC) yielded that document. > > > Geoff, > > I tried using Apache::Dir. The current version on CPAN only supports > mp1. Adding support for mp2 was easy enough but yielded no beneficial > results (i.e., I still get 404 errors and the Apache log error). > > I wrote to David W. who maintains the module; he had no further > suggestions so I did some further debugging. It turns out that I'm not > having a problem with appending a trailing slash; Apache seems to be > doing this just fine with or without the Apache::Dir module. > > The problem I'm having is that Apache is not setting the DirectoryIndex > to a valid filename. It is instead complaining that it's trying to serve > a directory. This is probably because ModPerl::Registry is handling the > directory as turning off the SetHandler allows those indexes to be > served (albeit I'm getting the script displayed as a text file instead > of run as a perl script). hmm. I'm sorry I didn't get back to you today, but I had something unexpected come up. I'll be rolling rc5 tomorrow, but if you want to create a bug tarball for me I'll look into it with whatever resources I can scrounge up. in the meanwhile here's my preliminary analysis... SetHandler is forcing the handler to be mod_perl, but really mod_dir needs to step in and handle the / -> DirectoryIndex conversion. so... what I would do is alter that fixup handler to do something like this if ($r->handler('perl-script') && -d $r->filename && $r->is_initial_req) { $r->hander(Apache2::Const::DIR_MAGIC_TYPE); } or somesuch. basically, what you want to happen is for mod_dir to apply the directory index and issue it's normal internal_direct to mod_perl. un-doing mod_mime's SetHandler for just the main request ought to do that. however, I am on some severe pain killers at the moment, so who knows... > > I also searched the archives for Apache::Dir as well as the Apache log > error but could not find a discussion about this issue. Any more ideas > for me? http://marc.theaimsgroup.com/?t=10843100422&r=1&w=2 --Geoff
Re: DirectoryIndex ignored when using perl-handler
On Wed, Apr 13, 2005 at 08:21:46PM -0400, Geoffrey Young wrote: > hmm. I'm sorry I didn't get back to you today, but I had something > unexpected come up. I'll be rolling rc5 tomorrow, but if you want to create > a bug tarball for me I'll look into it with whatever resources I can > scrounge up. Hi Geoff, I've finally found a chance to create the bug report tarball[1] for the directory index problems I'm seeing. The important stuff is in t/conf/extra.conf.in where the settings are causing the tests to fail. Perhaps I'm doing something wrong in my settings, but as I've reported before, these used to work under mp1. > SetHandler is forcing the handler to be mod_perl, but really mod_dir needs > to step in and handle the / -> DirectoryIndex conversion. so... what I would > do is alter that fixup handler to do something like this > > if ($r->handler('perl-script') && -d $r->filename && $r->is_initial_req) { > $r->hander(Apache2::Const::DIR_MAGIC_TYPE); > } > > or somesuch. basically, what you want to happen is for mod_dir to apply the > directory index and issue it's normal internal_direct to mod_perl. un-doing > mod_mime's SetHandler for just the main request ought to do that. I tried adding the above code to Apache::Dir (I fixed the $r->hander to $r->handler) and found that I needed to include a 'use Apache::RequestRec' statement (yes, I'm still on RC4 at the moment). Now, the server is returning a 403 error with the following entry in the error log when I try to retrieve the index.html: [Mon Apr 25 09:48:17 2005] [error] file permissions deny server execution /home/william/Apache-Test-skeleton-mp2/t/htdocs/index.html This is followed by the usual error about not being able to serve the directory when I try to GET '/' in t/01basic.t. It looks like the gist is that the suggested patch didn't work or was incorrectly applied. Thanks, William [1] http://66.151.211.202/~william/apache2-directoryindex-error.tgz (let me know if you have any problems retrieving that file; it may be behind a firewall) -- Knowmad Services Inc. http://www.knowmad.com
Re: DirectoryIndex ignored when using perl-handler
>>SetHandler is forcing the handler to be mod_perl, but really mod_dir needs >>to step in and handle the / -> DirectoryIndex conversion. so... what I would >>do is alter that fixup handler to do something like this >> >> if ($r->handler('perl-script') && -d $r->filename && $r->is_initial_req) { >>$r->hander(Apache2::Const::DIR_MAGIC_TYPE); >> } >> >>or somesuch. basically, what you want to happen is for mod_dir to apply the >>directory index and issue it's normal internal_direct to mod_perl. un-doing >>mod_mime's SetHandler for just the main request ought to do that. that code is essentially right. well, except that the above example sets $r->handler instead of comparing it. adding the code at the bottom of this mail essentially makes your tests pass, except that I think your last test is wrong - your DirectoryIndex puts the index script ahead of everything else, so the results should match "Hello" and not "welcome". > I tried adding the above code to Apache::Dir Apache::Dir was just an example. the below code used as the only fixup handler should do the trick. HTH --Geoff package My::Fixup; use strict; use warnings FATAL => qw(all); use Apache2::Const -compile => qw(DIR_MAGIC_TYPE OK DECLINED); use Apache2::RequestRec; sub handler { my $r = shift; if ($r->handler eq 'perl-script' && -d $r->filename && $r->is_initial_req) { $r->handler(Apache2::Const::DIR_MAGIC_TYPE); return Apache2::Const::OK; } return Apache2::Const::DECLINED; } 1;
Re: DirectoryIndex ignored when using perl-handler
On Mon, Apr 25, 2005 at 01:51:23PM -0400, Geoffrey Young wrote: > that code is essentially right. well, except that the above example sets > $r->handler instead of comparing it. adding the code at the bottom of this > mail essentially makes your tests pass, except that I think your last test > is wrong - your DirectoryIndex puts the index script ahead of everything > else, so the results should match "Hello" and not "welcome". Indeed you are correct about the bad test. I've incorporated the new fixup handler into my production config and it's working like a champ. Thanks! William -- Knowmad Services Inc. http://www.knowmad.com
Re: DirectoryIndex ignored when using perl-handler
for the sake of the archives, william reported that the below fixup handler is "working like a champ" so I guess this is a workable solution for anyone in the same situation. and for anyone listening, rolling up a test tarball like william did was outstanding - I was more than happy (ecstatic, actually) to spend the 10 minutes it took me to code the proper handler when all I needed to do was run 'make test' and see _exactly_ what he saw as the problem and what he expected to see when all was working properly. so, thanks william :) --Geoff > the below code used as the only fixup > handler should do the trick. > > HTH > > --Geoff > > package My::Fixup; > > use strict; > use warnings FATAL => qw(all); > > use Apache2::Const -compile => qw(DIR_MAGIC_TYPE OK DECLINED); > use Apache2::RequestRec; > > sub handler { > > my $r = shift; > > if ($r->handler eq 'perl-script' && > -d $r->filename && > $r->is_initial_req) > { > $r->handler(Apache2::Const::DIR_MAGIC_TYPE); > > return Apache2::Const::OK; > } > > return Apache2::Const::DECLINED; > } > > 1;
Re: DirectoryIndex ignored when using perl-handler
I really apologize for resurrecting a thread that was put to rest almost a month ago. I am just running into this problem now, and I don't quite understand what the fix is. I'm very new to writing a MP handler. I am trying to write a (yet another) authentication handler for a directory that is to be indexed. By I am finding that no matter what I try, based on the April thread, I just can't get the normal directory indexing to work. I've stripped out all of the handler's real logic and the usual MP1/MP2 detection below, and it just returns a simple DECLINE. As with the original poster's problem, unless I specify the filename in the URL it fails with the error log "Attempt to Server Directory" Using just the stub code below, I would like to know how to get it to give the directory index. I've tried adding .. $r->handler(Apache::Const::DIR_MAGIC_TYPE); return OK; .. just to see if it gives a directory index, but only an empty file is returned to the browser (but no error). What am I doing wrong? Tom Linux, httpd 2.0.52 httpd.conf snippet: Options Indexes SetHandler perl-script PerlResponseHandler My::Dummy site_perl\My\Dummy.pm file: package My::Dummy ; use Apache::Const -compile => qw(DIR_MAGIC_TYPE OK DECLINED); use Apache::RequestRec; use strict; use warnings; use CGI qw/header path_info redirect path_translated/; sub handler { my $r = shift; # fix to detect blank file and pass to directory index goes here... return DECLINED ; } 1; __END__ __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: DirectoryIndex ignored when using perl-handler
Thomas Hilbig wrote: > I really apologize for resurrecting a thread that was > put to rest almost a month ago. I am just running > into this problem now, and I don't quite understand > what the fix is. I'm very new to writing a MP > handler. since you're new to mod_perl it's probably not obvious from that thread what the solution is. http://marc.theaimsgroup.com/?l=apache-modperl&m=111445150218566&w=2 the code at the bottom of that link (My::Fixup) needs to be enabled from a PerlFixupHandler so that mod_dir can serve the request. in other words, if you put it in the PerlResponseHandler like you are it's too late for mod_dir to take action and DTRT. so PerlFixupHandler My::Fixup PerlResponseHandler My::Dummy ...etc... HTH --Geoff
Re: DirectoryIndex ignored when using perl-handler
--- Geoffrey Young <[EMAIL PROTECTED]> wrote: > since you're new to mod_perl it's probably not > obvious from that thread what > the solution is. > > > http://marc.theaimsgroup.com/?l=apache-modperl&m=111445150218566&w=2 > > the code at the bottom of that link (My::Fixup) > needs to be enabled from a > PerlFixupHandler so that mod_dir can serve the > request. in other words, if > you put it in the PerlResponseHandler like you are > it's too late for mod_dir > to take action and DTRT. so > > PerlFixupHandler My::Fixup > PerlResponseHandler My::Dummy > ...etc... > > HTH > > --Geoff > I have been using Apache::Registry to turbo-charge my CGI scripts for several years, but yes this is the first time writing a handler. Still not working for me. Here are my steps... httpd.conf: Options Indexes SetHandler perl-script PerlFixupHandler My::Fixup PerlResponseHandler My::Dummy My/Dummy.pm package just returns DECLINED (for now) My/Fixup.pm package exactly as http://marc.theaimsgroup.com/?l=apache-modperl&m=111445150218566&w=2 Note 1: - All references to Apache2 changed to Apache (fresh install of Fedora Core 3 & one up2date (httpd is 2.0.52 and mp2 is 1.99_16-3) - no complaints Problem 1: - Error: Bareword "Apache::Const::DIR_MAGIC_TYPE" not allowed while "strict subs" in use .. - Same complaint with Apache::Const::OK and Apache::Const::DECLINED - Bad practice, but I commented out the use strict and use warnings ; Problem 2: - calling URL to location (without file) - error: "Can't locate object method is_initial_req via package Apache::RequestReq - I'm worried. Problem 3: - remove conditional logic from Fixup.pm so it always forces directory index sub handler { my $r = shift; $r->handler(Apache::Const::DIR_MAGIC_TYPE); return Apache::Const::OK; } - call URL with location (no specific file) - error log: "Attempt to Serve directory" Help. I'm stuck. Tom __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: DirectoryIndex ignored when using perl-handler
> My/Fixup.pm package exactly as > http://marc.theaimsgroup.com/?l=apache-modperl&m=111445150218566&w=2 > > Note 1: > - All references to Apache2 changed to Apache (fresh > install of Fedora Core 3 & one up2date > (httpd is 2.0.52 and mp2 is 1.99_16-3) > - no complaints > > Problem 1: > - Error: Bareword "Apache::Const::DIR_MAGIC_TYPE" > not allowed while "strict subs" in use .. > - Same complaint with Apache::Const::OK and > Apache::Const::DECLINED > - Bad practice, but I commented out the use strict > and use warnings ; this needs to be fixed. those constants are explicitly exported in Fixup.pm, so if you're getting those warnings something is wrong. the pragmata you commented out is there for your protection - if you need to comment it out something else is going wrong, which is clearly shown in your next error: > - error: "Can't locate object method is_initial_req > via package Apache::RequestReq so, you need to figure out why the handler doesn't run cleanly before we can diagnose why it's not performing its intended function. for the latter error, you might need to add use Apache::RequestUtil; to Fixup.pm (though I'll need to see why it didn't fail for me). for the constants, something else is amuck. --Geoff
Re: DirectoryIndex ignored when using perl-handler
--- Geoffrey Young <[EMAIL PROTECTED]> wrote: > this needs to be fixed. those constants are explicitly exported in > Fixup.pm, so if you're getting those warnings > something is wrong. the > pragmata you commented out is there for your > protection - if you need to > comment it out something else is going wrong, which > is clearly shown in your > next error: > > > - error: "Can't locate object method > is_initial_req > > via package Apache::RequestReq > > so, you need to figure out why the handler doesn't > run cleanly before we can > diagnose why it's not performing its intended > function. for the latter > error, you might need to add > > use Apache::RequestUtil; > > to Fixup.pm (though I'll need to see why it didn't > fail for me). for the > constants, something else is amuck. Including Apache::RequestUtil solved the is_initial_req problem. However, the directory listing is ignoring the HEADER.html file contents and when called with a filename in the url the Dummy.pm is being picked up properly (I added logging to check) but not outputing the file contents. I agree that the install must be incomplete, but it was straight from the RedHat FC3 install (plus current up2date). I realized that the use of Apache2 is not just convention, but refers to a new API -- which I don't have. Installing Bundle::Apache2 would probably fix everything (.55 probability) but I didn't get this in before releasing the system to production and I fear causing more serious problems (.25 probability). I will try hacking at the handler code to generate the directory listings, as it limits damage to one directory and can easily be reversed, until I test the proper Apache2 modules on another machine. Tom __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com