You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Anthony R Fletcher <ar...@mail.nih.gov> on 2009/06/25 23:51:31 UTC

Running CGI scripts after mod_perl.

I have a mod_perl 2 module, running in Apache 2.2,

-------------------------------------------------
package Apache2::NNNN;

use 5;
use strict;

use Apache2::Const -compile => qw(DECLINED);

sub handler
{
        return Apache2::Const::DECLINED;
}


1;
-------------------------------------------------

and this is enabled in a .htaccess file via

	SetHandler modperl
	PerlResponseHandler Apache2::NNNN

Without the .htaccess config above CGI scripts run fine. With the above
the actual script is returned.

How do I get Apache to process the .cgi scripts as CGI scripts and not
as just text files?


			Anthony.





Re: Running CGI scripts after mod_perl.

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 25/06/09 17:51 , Anthony R Fletcher wrote:
> I have a mod_perl 2 module, running in Apache 2.2,
> 
> -------------------------------------------------
> package Apache2::NNNN;
> 
> use 5;
> use strict;
> 
> use Apache2::Const -compile => qw(DECLINED);
> 
> sub handler
> {
>         return Apache2::Const::DECLINED;
> }
> 
> 
> 1;
> -------------------------------------------------
> 
> and this is enabled in a .htaccess file via
> 
> 	SetHandler modperl
> 	PerlResponseHandler Apache2::NNNN
> 
> Without the .htaccess config above CGI scripts run fine. With the above
> the actual script is returned.

That's because of 'SetHandler modperl'

When you use that, you are telling apache definitively that modperl
should be used to handle this request. When you return DECLINED, all
apache is left with is to fallback to the default handler, and that
serves static files.

> How do I get Apache to process the .cgi scripts as CGI scripts and not
> as just text files?

sub handler {
	my $r = shift;
	# Whatever logic to decide if it should be a cgi or not...
	if ($r->filename =~ /\.cgi$/) {
		$r->handler('cgi-script');
	}
	return Apache2::Const::DECLINED;
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFKRScRyzKhB4jDpaURAmyGAJ0bKo9u7cdR1/pDnQTCB7QnL1PLWwCdE6Sf
BPnLzdh3OekzzvKsR/cXWII=
=2RHI
-----END PGP SIGNATURE-----

Re: Running CGI scripts after mod_perl.

Posted by Anthony R Fletcher <ar...@mail.nih.gov>.
On 26 Jun 2009 at 19:57:10, Perrin Harkins wrote:
> On Fri, Jun 26, 2009 at 6:36 PM, Anthony R Fletcher<ar...@mail.nih.gov> wrote:
> > Perrin asks what am I doing. I want to create a custom directory listing
> > and modify the output of various file formats when they match a
> > particular regexp. All the other files (like CGI scripts) should pass
> > through untouched to be dealt with by Apache as if the perl handle
> > wasn't there.
> 
> I'm still not quite getting it.  If you want to do a custom directory
> listing, that's easy enough.  You can match URLs that end in /.  There
> are some examples of directory handlers on CPAN too.  I think they're
> for mod_perl 1, but I think you'll be able to get the idea from them.
> 
> Or, if what you're trying to do is run a CGI or PHP script and do
> something to the output, you should write a filter instead of a
> response handler.
> 
> - Perrin

I actually wanted to do both; a custom directory listing and let the CGI
or PHP scripts run as before.

I did look at the various CPAN offerings and they just load the perl
handler for everything in a particular directory.

You are right, I need to match just against the URLs that end in
/ and only set up the mod_perl stuff for directories. 

Thanks for the help.

		Anthony


Re: Running CGI scripts after mod_perl.

Posted by Perrin Harkins <ph...@gmail.com>.
On Fri, Jun 26, 2009 at 6:36 PM, Anthony R Fletcher<ar...@mail.nih.gov> wrote:
> Perrin asks what am I doing. I want to create a custom directory listing
> and modify the output of various file formats when they match a
> particular regexp. All the other files (like CGI scripts) should pass
> through untouched to be dealt with by Apache as if the perl handle
> wasn't there.

I'm still not quite getting it.  If you want to do a custom directory
listing, that's easy enough.  You can match URLs that end in /.  There
are some examples of directory handlers on CPAN too.  I think they're
for mod_perl 1, but I think you'll be able to get the idea from them.

Or, if what you're trying to do is run a CGI or PHP script and do
something to the output, you should write a filter instead of a
response handler.

- Perrin

Re: Running CGI scripts after mod_perl.

Posted by Anthony R Fletcher <ar...@mail.nih.gov>.
Thanks for the suggestion, Philippe, but Perrin is right and it seems to
be too late to change the handler (I just tried it).

Actually I can 'fix' the issue by putting 
	<FilesMatch \.cgi$>
        	SetHandler cgi-script
	</FilesMatch>
in the .htaccess file along with the 'SetHandler modperl'. This side
steps the issue as it doesn't deal with the other special files like PHP.

Perrin asks what am I doing. I want to create a custom directory listing
and modify the output of various file formats when they match a
particular regexp. All the other files (like CGI scripts) should pass
through untouched to be dealt with by Apache as if the perl handle
wasn't there. I'm guessing that this won't work.

I want to somehow chain the handlers together.

Should I be running this in a different phase?

		Anthony

On 26 Jun 2009 at 16:01:31, Philippe M. Chiasson wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 26/06/09 15:55 , Perrin Harkins wrote:
> > On Thu, Jun 25, 2009 at 5:51 PM, Anthony R Fletcher<ar...@mail.nih.gov> wrote:
> >> I have a mod_perl 2 module, running in Apache 2.2,
> >>
> >> -------------------------------------------------
> >> package Apache2::NNNN;
> >>
> >> use 5;
> >> use strict;
> >>
> >> use Apache2::Const -compile => qw(DECLINED);
> >>
> >> sub handler
> >> {
> >>        return Apache2::Const::DECLINED;
> >> }
> >>
> >>
> >> 1;
> >> -------------------------------------------------
> >>
> >> and this is enabled in a .htaccess file via
> >>
> >>        SetHandler modperl
> >>        PerlResponseHandler Apache2::NNNN
> >>
> >> Without the .htaccess config above CGI scripts run fine. With the above
> >> the actual script is returned.
> > 
> > Hmm.  Why are you doing this?  It's not clear what you're really trying to do.
> > 
> > If you want to change which module does the response handler phase,
> > you can do that, and you should be able to set it to be the
> > cgi-handler module, but I don't think you can do it when you're
> > already in the response handler phase.
> 
> Yes, so my previous suggestion is most likely no good. It's sort of too
> late indeed, once a content handler has been entered.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iD8DBQFKRSkbyzKhB4jDpaURArs/AKCwYDGegAmvQml1MpUaJF2LYQBEtwCfb8ET
> 6OE0366ojElzWlrg/GQPN2M=
> =IZvN
> -----END PGP SIGNATURE-----

-- 
Anthony R Fletcher        
  Room 2033, Building 12A,        http://dcb.cit.nih.gov/~arif
  National Institutes of Health,  arif@mail.nih.gov
  12A South Drive, Bethesda,      Phone: (+1) 301 402 1741.
  MD 20892-5624, USA.

Re: Running CGI scripts after mod_perl.

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 26/06/09 15:55 , Perrin Harkins wrote:
> On Thu, Jun 25, 2009 at 5:51 PM, Anthony R Fletcher<ar...@mail.nih.gov> wrote:
>> I have a mod_perl 2 module, running in Apache 2.2,
>>
>> -------------------------------------------------
>> package Apache2::NNNN;
>>
>> use 5;
>> use strict;
>>
>> use Apache2::Const -compile => qw(DECLINED);
>>
>> sub handler
>> {
>>        return Apache2::Const::DECLINED;
>> }
>>
>>
>> 1;
>> -------------------------------------------------
>>
>> and this is enabled in a .htaccess file via
>>
>>        SetHandler modperl
>>        PerlResponseHandler Apache2::NNNN
>>
>> Without the .htaccess config above CGI scripts run fine. With the above
>> the actual script is returned.
> 
> Hmm.  Why are you doing this?  It's not clear what you're really trying to do.
> 
> If you want to change which module does the response handler phase,
> you can do that, and you should be able to set it to be the
> cgi-handler module, but I don't think you can do it when you're
> already in the response handler phase.

Yes, so my previous suggestion is most likely no good. It's sort of too
late indeed, once a content handler has been entered.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFKRSkbyzKhB4jDpaURArs/AKCwYDGegAmvQml1MpUaJF2LYQBEtwCfb8ET
6OE0366ojElzWlrg/GQPN2M=
=IZvN
-----END PGP SIGNATURE-----

Re: Running CGI scripts after mod_perl.

Posted by Perrin Harkins <ph...@gmail.com>.
On Thu, Jun 25, 2009 at 5:51 PM, Anthony R Fletcher<ar...@mail.nih.gov> wrote:
> I have a mod_perl 2 module, running in Apache 2.2,
>
> -------------------------------------------------
> package Apache2::NNNN;
>
> use 5;
> use strict;
>
> use Apache2::Const -compile => qw(DECLINED);
>
> sub handler
> {
>        return Apache2::Const::DECLINED;
> }
>
>
> 1;
> -------------------------------------------------
>
> and this is enabled in a .htaccess file via
>
>        SetHandler modperl
>        PerlResponseHandler Apache2::NNNN
>
> Without the .htaccess config above CGI scripts run fine. With the above
> the actual script is returned.

Hmm.  Why are you doing this?  It's not clear what you're really trying to do.

If you want to change which module does the response handler phase,
you can do that, and you should be able to set it to be the
cgi-handler module, but I don't think you can do it when you're
already in the response handler phase.  Depending on what you're
really after, a filter might be the answer, or running your perl code
in an earlier phase might be it.

- Perrin