You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Gary C. New" <ga...@yahoo.com> on 2004/02/06 01:17:50 UTC

Section ENV Variables?

mod_perl = 1.27

I am trying to setup a <Perl> section in my httpd.conf file that will 
retrieve the web server's environment variables.  I've tried several 
methods and all lead me back to the same problem.

I first tried using PerlPassEnv but could never get any environment 
variables from it.  I also understand there is a great deal more 
overhead using this method.

I then tried using $r->subprocess_env but always received an error 
regarding Can't call method "subprocess_env"on an undefined value.  I 
believe this routine is a part of the Apache module.  I verified that it 
was in the perl lib path and then attempted to "use" it in the <Perl> 
section.

I finally tried using $r->parsed_uri but, again, continue to receive an 
error regarding Can't call method "parsed_uri" on an undefined value. 
The routine is part of the Apache::URI module, which I verified was in 
the path and then attempted to "use" in the <Perl> section.

I am having a heck of a time trying to get the web server environment 
variables via the <Perl> section.  I could really use some assistance 
trying to hammer this out.

I was able to get routines from the CGI module to work in the <Perl> 
section within my httpd.conf file.

I would appreciate it if someone could confirm that it is possible to 
read environment variables within a <Perl> section with sample code.

Thank you for your assistance.

Respectfully,


Gary



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by "Gary C. New" <ga...@yahoo.com>.
Geoffrey,

I want to thank you again for pointing me in the right direction!

With the sample code, I've been able to put together a semi-working 
module that allows me to regex the incoming uri and rewrite the 
DocumentRoot on the fly.  This is some cool stuff.

I've run into a minor problem with php_value include_path for some of my 
php sites.  I need to find out if there are any modules in existence 
that will allow me to update php_value include_path on the fly like I 
did with document_root.  I'll start a separate thread in this group with 
that question.

Thanks again for the great pointers.

Respectfully,


Gary


Geoffrey Young wrote:
> 
> Gary C. New wrote:
> 
>>Definitely looks like the code I'm after.
>>
>>I guess what is unclear to me is how to implement it.
> 
> 
> it's a PerlTransHandler, so you'd use it from your httpd.conf like this
> 
> PerlModule My::TransHandler
> PerlTransHandler My::TransHandler
> 
> and put your code, My/TransHandler.pm, someplace where mod_perl can see it,
> such as in ServerRoot/lib/perl/My/TransHandler.pm.  see recipe 7.1
> 
> http://www.modperlcookbook.org/chapters/ch07.pdf
> 
> for more details - it might help clear things up a bit.
> 
> 
>>suburbanantihero states that the <Perl> sections are only configurable
>>on load time.  
> 
> 
> typically, yes (as I also said :)  but they will execute in .htaccess files
> as well (but don't worry about that, it's not what you are after).
> 
> 
>>So I would need to bind it as a handler to the ssl
>>virtualhost section.  Is this correct?
> 
> 
> translation handlers run for every request and can be scoped on a virtual
> host basis.  so, once it's installed it will do the mapping you require.
> 
> 
>>I am not sure how this would then be invoked.  Would it require further
>>extension to my URI?
> 
> 
> the job of a translation handler is to map a URI to a filename on disk.  in
> this case, you would be envoking a bit of trickery - altering the URI so
> that the default Apache translation engine thinks the URI is different than
> it really is.
> 
> but as I just said, it will be run on every request - it is invoked by
> virtue of its nature, as a product of how Apache handles requests and allows
> you to plug into them.
> 
> anyway, looks like you need to settle down with some mod_perl documentation
> and understand the Apache request cycle a bit :)  http://perl.apache.org/ is
> the place to start.  you also might find the general request cycle overview here
> 
> http://www.modperlcookbook.org/chapters/part3.pdf
> 
> helpful
> 
> HTH
> 
> --Geoff
> 
> 



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Gary C. New wrote:
> Definitely looks like the code I'm after.
> 
> I guess what is unclear to me is how to implement it.

it's a PerlTransHandler, so you'd use it from your httpd.conf like this

PerlModule My::TransHandler
PerlTransHandler My::TransHandler

and put your code, My/TransHandler.pm, someplace where mod_perl can see it,
such as in ServerRoot/lib/perl/My/TransHandler.pm.  see recipe 7.1

http://www.modperlcookbook.org/chapters/ch07.pdf

for more details - it might help clear things up a bit.

> 
> suburbanantihero states that the <Perl> sections are only configurable
> on load time.  

typically, yes (as I also said :)  but they will execute in .htaccess files
as well (but don't worry about that, it's not what you are after).

> So I would need to bind it as a handler to the ssl
> virtualhost section.  Is this correct?

translation handlers run for every request and can be scoped on a virtual
host basis.  so, once it's installed it will do the mapping you require.

> 
> I am not sure how this would then be invoked.  Would it require further
> extension to my URI?

the job of a translation handler is to map a URI to a filename on disk.  in
this case, you would be envoking a bit of trickery - altering the URI so
that the default Apache translation engine thinks the URI is different than
it really is.

but as I just said, it will be run on every request - it is invoked by
virtue of its nature, as a product of how Apache handles requests and allows
you to plug into them.

anyway, looks like you need to settle down with some mod_perl documentation
and understand the Apache request cycle a bit :)  http://perl.apache.org/ is
the place to start.  you also might find the general request cycle overview here

http://www.modperlcookbook.org/chapters/part3.pdf

helpful

HTH

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by "Gary C. New" <ga...@yahoo.com>.
Definitely looks like the code I'm after.

I guess what is unclear to me is how to implement it.

suburbanantihero states that the <Perl> sections are only configurable 
on load time.  So I would need to bind it as a handler to the ssl 
virtualhost section.  Is this correct?

I am not sure how this would then be invoked.  Would it require further 
extension to my URI?

I appreciate the help.

Respectfully,


Gary


Geoffrey Young wrote:
>>http://domain.tld = DocumentRoot /home/domain.tld/htdocs
>>
>>https://secure.provider.tld/secure/domain.tld/
>>
>>URI is parsed for ^/secure/([.]*[\.]+[.]*)/(.*)
>>
>><Perl>
>>DocumentRoot is then dynamically replaced with $1
>></Perl>
>>
>>I was trying to use mod_rewrite and mod_vhost_alias to do this, but I
>>just could not get the environment variables into DocumentRoot.
> 
> 
> see recipe 4.3 in the mod_perl developer's cookbook, which is available for
> free from here
> 
> http://www.webreference.com/programming/perl/cookbook/chap4/2.html
> 
> and the code is here
> 
> http://www.modperlcookbook.org/code/ch04/Cookbook/Userdir.pm
> 
> but you'll also want to read up on translation handlers and the request
> cycle in general
> 
> http://www.modperlcookbook.org/
> 
> HTH
> 
> --Geoff
> 
> 



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> http://domain.tld = DocumentRoot /home/domain.tld/htdocs
> 
> https://secure.provider.tld/secure/domain.tld/
> 
> URI is parsed for ^/secure/([.]*[\.]+[.]*)/(.*)
> 
> <Perl>
> DocumentRoot is then dynamically replaced with $1
> </Perl>
> 
> I was trying to use mod_rewrite and mod_vhost_alias to do this, but I
> just could not get the environment variables into DocumentRoot.

see recipe 4.3 in the mod_perl developer's cookbook, which is available for
free from here

http://www.webreference.com/programming/perl/cookbook/chap4/2.html

and the code is here

http://www.modperlcookbook.org/code/ch04/Cookbook/Userdir.pm

but you'll also want to read up on translation handlers and the request
cycle in general

http://www.modperlcookbook.org/

HTH

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by su...@sbcglobal.net.
The <perl> sections are just for load time
configurations.  You want to write a mod_perl handler
and bind it only to the <location /> under the https
virtual host.

You can use the handler to parse the uri and then use
the $r->sendfile("/newdocumentroot/$file");


--- "Gary C. New" <ga...@yahoo.com> wrote:
> Geoffrey,
> 
> My intention is to capture HTTPS requests as they
> come in, break the URI 
> down, and then dynamically change DocumentRoot,
> Logs, etc based on 
> whether a given URI meets my set of criteria.
> 
> Example:
> 
> http://domain.tld = DocumentRoot
> /home/domain.tld/htdocs
> 
> https://secure.provider.tld/secure/domain.tld/
> 
> URI is parsed for ^/secure/([.]*[\.]+[.]*)/(.*)
> 
> <Perl>
> DocumentRoot is then dynamically replaced with $1
> </Perl>
> 
> I was trying to use mod_rewrite and mod_vhost_alias
> to do this, but I 
> just could not get the environment variables into
> DocumentRoot.
> 
> I thought this might be possible with <Perl>
> sections?
> 
> Thank you for your assistance.
> 
> Respectfully,
> 
> 
> Gary
> 
> 
> Geoffrey Young wrote:
> > 
> > Gary C. New wrote:
> > 
> >>mod_perl = 1.27
> >>
> >>I am trying to setup a <Perl> section in my
> httpd.conf file that will
> >>retrieve the web server's environment variables. 
> I've tried several
> >>methods and all lead me back to the same problem.
> >>
> >>I first tried using PerlPassEnv but could never
> get any environment
> >>variables from it.  I also understand there is a
> great deal more
> >>overhead using this method.
> >>
> >>I then tried using $r->subprocess_env but always
> received an error
> >>regarding Can't call method "subprocess_env"on an
> undefined value.  I
> >>believe this routine is a part of the Apache
> module.  I verified that it
> >>was in the perl lib path and then attempted to
> "use" it in the <Perl>
> >>section.
> >>
> >>I finally tried using $r->parsed_uri but, again,
> continue to receive an
> >>error regarding Can't call method "parsed_uri" on
> an undefined value.
> >>The routine is part of the Apache::URI module,
> which I verified was in
> >>the path and then attempted to "use" in the <Perl>
> section.
> > 
> > 
> > all of this makes me think that you're after
> things like $ENV{REMOTE_USER}
> > and other CGI environment variables?
> > 
> > in general, <Perl> sections within a httpd.conf
> are executed when Apache is
> > started.  that means that there is no request to
> associate with a client, so
> > no $ENV{REMOTE_USER} or other things make any
> sense.  that's also why you
> > couldn't call $r->subprocess_env or $r->parsed_uri
> - there is no $r at
> > config time.
> > 
> > so, if it's these environment variables you're
> looking for, you'll need to
> > take a step back and assess what you're really
> trying to do.
> > 
> > if you're after other things - such as variables
> from /etc/profile - but
> > can't access them in <Perl> sections that's a
> different issue, and something
> > that I'd need to try and recall, as I thought they
> should be visible at that
> > point.
> > 
> > --Geoff
> > 
> > 
> 
> 
> 
> -- 
> Reporting bugs: http://perl.apache.org/bugs/
> Mail list info:
> http://perl.apache.org/maillist/modperl.html
> List etiquette:
> http://perl.apache.org/maillist/email-etiquette.html
> 


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by "Gary C. New" <ga...@yahoo.com>.
Geoffrey,

My intention is to capture HTTPS requests as they come in, break the URI 
down, and then dynamically change DocumentRoot, Logs, etc based on 
whether a given URI meets my set of criteria.

Example:

http://domain.tld = DocumentRoot /home/domain.tld/htdocs

https://secure.provider.tld/secure/domain.tld/

URI is parsed for ^/secure/([.]*[\.]+[.]*)/(.*)

<Perl>
DocumentRoot is then dynamically replaced with $1
</Perl>

I was trying to use mod_rewrite and mod_vhost_alias to do this, but I 
just could not get the environment variables into DocumentRoot.

I thought this might be possible with <Perl> sections?

Thank you for your assistance.

Respectfully,


Gary


Geoffrey Young wrote:
> 
> Gary C. New wrote:
> 
>>mod_perl = 1.27
>>
>>I am trying to setup a <Perl> section in my httpd.conf file that will
>>retrieve the web server's environment variables.  I've tried several
>>methods and all lead me back to the same problem.
>>
>>I first tried using PerlPassEnv but could never get any environment
>>variables from it.  I also understand there is a great deal more
>>overhead using this method.
>>
>>I then tried using $r->subprocess_env but always received an error
>>regarding Can't call method "subprocess_env"on an undefined value.  I
>>believe this routine is a part of the Apache module.  I verified that it
>>was in the perl lib path and then attempted to "use" it in the <Perl>
>>section.
>>
>>I finally tried using $r->parsed_uri but, again, continue to receive an
>>error regarding Can't call method "parsed_uri" on an undefined value.
>>The routine is part of the Apache::URI module, which I verified was in
>>the path and then attempted to "use" in the <Perl> section.
> 
> 
> all of this makes me think that you're after things like $ENV{REMOTE_USER}
> and other CGI environment variables?
> 
> in general, <Perl> sections within a httpd.conf are executed when Apache is
> started.  that means that there is no request to associate with a client, so
> no $ENV{REMOTE_USER} or other things make any sense.  that's also why you
> couldn't call $r->subprocess_env or $r->parsed_uri - there is no $r at
> config time.
> 
> so, if it's these environment variables you're looking for, you'll need to
> take a step back and assess what you're really trying to do.
> 
> if you're after other things - such as variables from /etc/profile - but
> can't access them in <Perl> sections that's a different issue, and something
> that I'd need to try and recall, as I thought they should be visible at that
> point.
> 
> --Geoff
> 
> 



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Section ENV Variables?

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Gary C. New wrote:
> mod_perl = 1.27
> 
> I am trying to setup a <Perl> section in my httpd.conf file that will
> retrieve the web server's environment variables.  I've tried several
> methods and all lead me back to the same problem.
> 
> I first tried using PerlPassEnv but could never get any environment
> variables from it.  I also understand there is a great deal more
> overhead using this method.
> 
> I then tried using $r->subprocess_env but always received an error
> regarding Can't call method "subprocess_env"on an undefined value.  I
> believe this routine is a part of the Apache module.  I verified that it
> was in the perl lib path and then attempted to "use" it in the <Perl>
> section.
> 
> I finally tried using $r->parsed_uri but, again, continue to receive an
> error regarding Can't call method "parsed_uri" on an undefined value.
> The routine is part of the Apache::URI module, which I verified was in
> the path and then attempted to "use" in the <Perl> section.

all of this makes me think that you're after things like $ENV{REMOTE_USER}
and other CGI environment variables?

in general, <Perl> sections within a httpd.conf are executed when Apache is
started.  that means that there is no request to associate with a client, so
no $ENV{REMOTE_USER} or other things make any sense.  that's also why you
couldn't call $r->subprocess_env or $r->parsed_uri - there is no $r at
config time.

so, if it's these environment variables you're looking for, you'll need to
take a step back and assess what you're really trying to do.

if you're after other things - such as variables from /etc/profile - but
can't access them in <Perl> sections that's a different issue, and something
that I'd need to try and recall, as I thought they should be visible at that
point.

--Geoff


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html