0

This script supposedly should take * out of *.domain.com, assign it to $subdomain variable, and $subdomain should be put to AssignUserId.

However, no matter how hard I try, I can't get this to work. I've been working on this for days, and am really desperate. If you think this is a lot of work, please charge me consultancy and come get the root passwd.

Any ideas though? Thanks...

<Perl>
 Use Apache2::ServerRec qw//; 
 use Apache2::ServerUtil qw//; 
 use Apache2::RequestRec qw//; 
 use Apache2::RequestUtil qw//; 
 use Apache2::Const qw/OK DECLINED/; 

 my $s = Apache2::ServerUtil->server; 

 $s->push_handlers(PerlHeaderParserHandler => sub { my($r) = @_; 
 if ( $r->hostname =~ m/(.*)\.([^.]+\.\w+)$/ ) { 
 my($subdomain,$domain) = ($1,$2); 

 #
 # THIS WORKS!
 # -----------
 # if requested domain is fio.domain.com,
 # this successfully assigns ServerAdmin fio@domain.com
 # so gathering domain parts working

 $r->server->server_admin("$subdomain\@$domain");

 #
 # THIS DOESN'T!
 # --------------
 # this is supposed to insert this line inside Virtual host
 # --------------
 # <IfModule mpm_itk_module> AssignUserId fio domain</IfModule>
 # --------------

 $r->add_config([ "<IfModule mpm_itk_module>", 
 "AssignUserId $subdomain $domain", 
 "</IfModule>", 
 ]); 

 if ( $@ ) { warn $@ } 


 return OK; 

 } else { 
 return DECLINED; 
 } 
 }); 
</Perl> 
Devrim
  • 1,187
  • 4
  • 16
  • 29
  • Have you placed this <Perl> block inside the top-level configuration? Inside a virtual server configuration? Inside a `.htaccess` file? – PP. Nov 22 '09 at 23:55

1 Answers1

1

My initial guess here is that you have set up a handler via the hook PerlHeaderParserHandler to which you have been handed $r, or the request object.

From the documentation for AssignUserId (the parameter you want to dynamically configure) the context of configuration must be virtual-host. At a guess I would suspect this to mean you should configure on a per-server basis rather than on a per-request basis.

See $s->add_config documentation as opposed to $r->add_config.

Depend on the processing of directives it is possible that by the time the request hook has been called the processing of AssignUserId has already taken place in which case there's not a lot you can do besides statically configuring each subdomain as a virtual server..

update 1: of course if you try and use $s->add_config for every request you run the danger of having an unwieldy server configuration in memory with the same directive repeated over and over. Making updating the server configuration every request impractical.

Perhaps it is still possible to do this with $r->add_config(), noting from the documentation that "Configuration directives are processed as if given in a <Location> block". Have you tried a non-Perl test of placing the AssignUserId parameter in a <Location> block?

PP.
  • 3,316
  • 6
  • 27
  • 31
  • Hi PP, I placed this inside a virtual host that catches every possible domain *.domain.com. AssignUserId is an internal part of mpm-itk so I don't think placing in Location wouldn't work. If you meant that if I have tried to insert Location just to see if it works, it's a good idea. Notes: I didn't get the danger you mentioned on your update 1. – Devrim Nov 23 '09 at 02:58
  • Apache uses memory pools that simply grow until released. The request object (`$r`) is allocated at the beginning of processing every single web page request, then released after processing that web page request. So you can add as much as you like to it because that memory will be released after the request. The server object (`$s`), however, gets allocated when the server process starts up, and doesn't get released until the process dies. So you want to add to that configuration once, not _every request_. – PP. Nov 23 '09 at 08:01
  • If you believe `AssignUserId` cannot be placed inside a directive then you cannot use `$r->add_config()` according to the documentation. – PP. Nov 23 '09 at 08:03