You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by stevethames <st...@softlife.com> on 2006/09/20 15:25:40 UTC

Retrieve server environment vars before response handler.

Can anyone tell me how to retrieve the environment variables set by the
Apache server in the PerlAuthenHandler or the PerlHeaderParserHandler? 
Basically any handler that is called before the PerlResponseHandler. 

I am using virtual hosts and want to set a variable for each one.  This
variable is needed in the authentication handler.  I can create a database
and store values by the host name but setting them in the environment would
be easier. 

Thanks.
-- 
View this message in context: http://www.nabble.com/Retrieve-server-environment-vars-before-response-handler.-tf2305332.html#a6407760
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: LOG: Re: Retrieve server environment vars before response handler.

Posted by ro...@elastica.com.
Can anybody tell me why that doesn't work when you want to access environment
variables set from the process that launches Apache and that you want to access
those variables in your <Perl> stanza in your httpd.conf?

I recently had to do this because from what I could see PerlPassEnv doesn't work
when you want to access the vars within the hander that's used in perl stanza's
in httpd.conf.

<Perl>

  # repopulate %ENV
  
  for (`env`) {
	 next unless /^VAR_/;
	 /(.*)=(.*)/;
	 $ENV{$1} = $2;
	 push @PassEnv, $1;
	 #print "$_\n";
	}
	
	my $hostname = $ENV{'VAR_HOSTNAME'};
</Perl>

Quoting Fred Moyer <fr...@redhotpenguin.com>:

>     Accepting to folder lists/perl/mod_perl
> 




----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


Re: Retrieve server environment vars before response handler.

Posted by stevethames <st...@softlife.com>.
Sure.  Here's the bottom of httpd.conf.  Nothing significant here.

#*******************************************************************************
# Load Remaining Config Files
#*******************************************************************************
Include conf.d/*.conf
-----------------------------------------------------------------------------

Here's the vhost section of ssl.conf.  Nothing here, either:

#*******************************************************************************
# Virtual Hosts
#*******************************************************************************
NameVirtualHost              *:443

<VirtualHost                 *:443>
  SSLEngine on
  SSLCertificateFile         /etc/pki/tls/certs/webscriber.crt
  SSLCertificateKeyFile      /etc/pki/tls/private/webscriber.key
  SSLCipherSuite            
ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
  ErrorLog                   logs/ssl_error_log
  TransferLog                logs/ssl_access_log
  LogLevel                   notice
  
  <Files                     ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions               +StdEnvVars
  </Files>
  
  <Directory                 "/var/www/cgi-bin">
    SSLOptions               +StdEnvVars
  </Directory>
  
  SetEnvIf                   User-Agent ".*MSIE.*" \
                             nokeepalive ssl-unclean-shutdown \
                             downgrade-1.0 force-response-1.0

  CustomLog                  logs/ssl_request_log \
                             "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\"
%b"
</VirtualHost>                                  
-----------------------------------------------------------------------

Here are the relevant portions of perl.conf:
LoadModule                   perl_module modules/mod_perl.so
PerlWarn                     on
PerlTaintCheck               on
PerlInitHandler              Apache2::Reload

#-----------------------------------*
# Add timezone aliases to DateTime. *
#-----------------------------------*
PerlModule                   DateTime::TimeZone::Alias
<Perl>
  DateTime::TimeZone::Alias->set( 'US/Arizona-Navajo' => 'US/Mountain' );
</Perl>
  
#----------------------------------------*
# Load debug options if debug turned on. *
#----------------------------------------*
<IfDefine PERLDB>
  <Perl>
    use APR::Pool;
    use Apache::DB ();
    Apache::DB->init;
  </Perl>

  <Location /pa>
    PerlFixupHandler Apache::DB
  </Location>
</IfDefine>

#------------------*
# Script Directory *
#------------------*
Alias                        /perl /var/www/perl
<Directory                   /var/www/perl>
  SetHandler                 perl-script
  PerlResponseHandler        ModPerl::Registry
  PerlOptions                +ParseHeaders
  Options                    +ExecCGI
</Directory>

#---------------------*
# Perl Status Handler *
#---------------------*
<Location                    /perl-status>
  SetHandler                 perl-script
  PerlResponseHandler        Apache2::Status
  Order                      deny,allow
  Deny from                  all
  Allow from                 all
</Location>

#*******************************************************************************
# Webscriber Handlers
#*******************************************************************************

PerlPassEnv                  SERVER_NAME
<Location /pa>
  SetHandler               perl-script                                                                                     
  PerlHeaderParserhandler +Apache2::SessionMgr                                                                          
  PerlSetVar               Apache2SessionMgr_IdleTimeout  300
  PerlSetVar               Apache2SessionMgr_ClassName    WS::Session
  PerlSetVar               Apache2SessionMgr_ClassArgs    'DataSource =>
dbi:Pg:dbname=wscontrol, UserName => apache, Commit => 1'
  PerlSetVar               Apache2SessionMgr_TraceLevel   notice
                          
  PerlAuthenHandler       +WS::Handler::Authenticate                                                 
  PerlSetVar               WSHandlerAuthenticate_username  ets
  PerlSetVar               WSHandlerAuthenticate_statement "SELECT password
FROM users WHERE sid = ?" 
  AuthType                 Basic                                                             
  AuthName                 "Protected Area"                                                  
  Require                  valid-user                                                        
</Location>               
-----------------------------------------------------------------------------

You can see the PerlPassEnv SERVER_HOME above the header parser and
authentication handlers.  Right now, I'm just testing the feature.  Also, I
get an error if I put PerlPassEnv inside the <Location> tags.  Practical
Mod_Perl says I can do this but the server won't start in this case.



Fred Moyer wrote:
> 
> On Wed, 20 Sep 2006, stevethames wrote:
>> I tried PerlPassEnv and found no change.  In fact, I can't verify
>> PerlPassEnv does anything at all.  I'm using perl-script as my handler so
>> SetupEnv is turned on and I get all the environment variables in the
>> response phase.
>>
>> In the header parser and authentication phases, I only get MOD_PERL,
>> MOD_PERL_API_VERSION, and PATH.  PerlPassEnv does not appear to do
>> anything.
>>
>> One wierd thing, though.  In the authentication handler, I set the
>> variable
>> WS_ENTITY to a piece of $r->hostname.  If I reboot the server, on the
>> first
>> request, this variable does not appear before the response phase. 
>> However,
>> in subsequent requests to the server, WS_ENTITY is found in the earlier
>> phases but no other variables are, other than the Mod_Perl variables
>> listed
>> above.  The wierd thing is, I set three other variables at the same time
>> as
>> WS_ENTTY but they don't show up--go figure.
>>
>> BTW, I was testing PerlPassEnv with SERVER_HOME, not WS_ENTITY.  I can
>> only
>> conclude that PerlPassEnv is buggy.
>>
>> i have the same server running several virtual hosts and want to set the
>> database name for the host in the apache config and I need this value
>> available in the authentication handler.
>>
>> Any other ideas?
> 
> If you can post some relevant snippets from your conf file, shell env 
> setup, and handler, we might be able to spot something that's causing the 
> problem.  If it really is a problem with PerlPassEnv I'd like to get it 
> into a reproducible test case.
> 
> 
>> Fred Moyer wrote:
>>>
>>> stevethames wrote:
>>>> Can anyone tell me how to retrieve the environment variables set by the
>>>> Apache server in the PerlAuthenHandler or the PerlHeaderParserHandler?
>>>> Basically any handler that is called before the PerlResponseHandler.
>>>>
>>>> I am using virtual hosts and want to set a variable for each one.  This
>>>> variable is needed in the authentication handler.  I can create a
>>>> database
>>>> and store values by the host name but setting them in the environment
>>>> would
>>>> be easier.
>>>
>>> It sounds like you are looking for PerlPassEnv
>>>
>>> http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Retrieve-server-environment-vars-before-response-handler.-tf2305332.html#a6413194
>> Sent from the mod_perl - General mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Retrieve-server-environment-vars-before-response-handler.-tf2305332.html#a6416513
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: Retrieve server environment vars before response handler.

Posted by Fred Moyer <fr...@redhotpenguin.com>.
On Wed, 20 Sep 2006, stevethames wrote:
> I tried PerlPassEnv and found no change.  In fact, I can't verify
> PerlPassEnv does anything at all.  I'm using perl-script as my handler so
> SetupEnv is turned on and I get all the environment variables in the
> response phase.
>
> In the header parser and authentication phases, I only get MOD_PERL,
> MOD_PERL_API_VERSION, and PATH.  PerlPassEnv does not appear to do anything.
>
> One wierd thing, though.  In the authentication handler, I set the variable
> WS_ENTITY to a piece of $r->hostname.  If I reboot the server, on the first
> request, this variable does not appear before the response phase.  However,
> in subsequent requests to the server, WS_ENTITY is found in the earlier
> phases but no other variables are, other than the Mod_Perl variables listed
> above.  The wierd thing is, I set three other variables at the same time as
> WS_ENTTY but they don't show up--go figure.
>
> BTW, I was testing PerlPassEnv with SERVER_HOME, not WS_ENTITY.  I can only
> conclude that PerlPassEnv is buggy.
>
> i have the same server running several virtual hosts and want to set the
> database name for the host in the apache config and I need this value
> available in the authentication handler.
>
> Any other ideas?

If you can post some relevant snippets from your conf file, shell env 
setup, and handler, we might be able to spot something that's causing the 
problem.  If it really is a problem with PerlPassEnv I'd like to get it 
into a reproducible test case.


> Fred Moyer wrote:
>>
>> stevethames wrote:
>>> Can anyone tell me how to retrieve the environment variables set by the
>>> Apache server in the PerlAuthenHandler or the PerlHeaderParserHandler?
>>> Basically any handler that is called before the PerlResponseHandler.
>>>
>>> I am using virtual hosts and want to set a variable for each one.  This
>>> variable is needed in the authentication handler.  I can create a
>>> database
>>> and store values by the host name but setting them in the environment
>>> would
>>> be easier.
>>
>> It sounds like you are looking for PerlPassEnv
>>
>> http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Retrieve-server-environment-vars-before-response-handler.-tf2305332.html#a6413194
> Sent from the mod_perl - General mailing list archive at Nabble.com.
>
>

Re: Retrieve server environment vars before response handler.

Posted by stevethames <st...@softlife.com>.
Thanks for the input.

I tried PerlPassEnv and found no change.  In fact, I can't verify
PerlPassEnv does anything at all.  I'm using perl-script as my handler so
SetupEnv is turned on and I get all the environment variables in the
response phase.

In the header parser and authentication phases, I only get MOD_PERL,
MOD_PERL_API_VERSION, and PATH.  PerlPassEnv does not appear to do anything.

One wierd thing, though.  In the authentication handler, I set the variable
WS_ENTITY to a piece of $r->hostname.  If I reboot the server, on the first
request, this variable does not appear before the response phase.  However,
in subsequent requests to the server, WS_ENTITY is found in the earlier
phases but no other variables are, other than the Mod_Perl variables listed
above.  The wierd thing is, I set three other variables at the same time as
WS_ENTTY but they don't show up--go figure.

BTW, I was testing PerlPassEnv with SERVER_HOME, not WS_ENTITY.  I can only
conclude that PerlPassEnv is buggy.

i have the same server running several virtual hosts and want to set the
database name for the host in the apache config and I need this value
available in the authentication handler.

Any other ideas?


Fred Moyer wrote:
> 
> stevethames wrote:
>> Can anyone tell me how to retrieve the environment variables set by the
>> Apache server in the PerlAuthenHandler or the PerlHeaderParserHandler? 
>> Basically any handler that is called before the PerlResponseHandler. 
>> 
>> I am using virtual hosts and want to set a variable for each one.  This
>> variable is needed in the authentication handler.  I can create a
>> database
>> and store values by the host name but setting them in the environment
>> would
>> be easier. 
> 
> It sounds like you are looking for PerlPassEnv
> 
> http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_
> 
> 

-- 
View this message in context: http://www.nabble.com/Retrieve-server-environment-vars-before-response-handler.-tf2305332.html#a6413194
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: Retrieve server environment vars before response handler.

Posted by Fred Moyer <fr...@redhotpenguin.com>.
stevethames wrote:
> Can anyone tell me how to retrieve the environment variables set by the
> Apache server in the PerlAuthenHandler or the PerlHeaderParserHandler? 
> Basically any handler that is called before the PerlResponseHandler. 
> 
> I am using virtual hosts and want to set a variable for each one.  This
> variable is needed in the authentication handler.  I can create a database
> and store values by the host name but setting them in the environment would
> be easier. 

It sounds like you are looking for PerlPassEnv

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_