Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Changing apache config with mod_perl, doesnt work!

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


devrim at kodingen

Nov 22, 2009, 2:42 PM

Post #1 of 3 (784 views)
Permalink
Changing apache config with mod_perl, doesnt work!

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 [at] domain
# 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 at kodingen

Nov 22, 2009, 3:01 PM

Post #2 of 3 (745 views)
Permalink
Changing apache config with mod_perl, doesnt work! [In reply to]

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 [at] domain
# 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>


gozer at ectoplasm

Nov 22, 2009, 6:59 PM

Post #3 of 3 (732 views)
Permalink
Re: Changing apache config with mod_perl, doesnt work! [In reply to]

On 09-11-22 17:42 , Devrim Yasar wrote:
> 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) = @_;

From a quick glance at the mpm-itk source-code, it does its magic in at
the headerparsing phase, so your attempt at using that phase to alter
it's behaviour was a good one.

/* set the uid as fast as possible, but not before merging per-dit
config */
ap_hook_header_parser(itk_post_perdir_config, NULL, NULL,
APR_HOOK_REALLY_FIRST);

Unfortunately, it seems to pick APR_HOOK_REALLY_FIRST as precedence,
which makes it run /before/ your code, in the same phase. So, even
though you actually succeed at changing it's run-time configuration, you
do it too late, and it doesn't even look at it.

> if ( $r->hostname =~ m/(.*)\.([^.]+\.\w+)$/ ) {
> my($subdomain,$domain) = ($1,$2);
>
> #
> # THIS WORKS!
> # -----------
> # if requested domain is fio.domain.com <http://fio.domain.com/>,
> # this successfully assigns ServerAdmin fio [at] domain <mailto:fio [at] domain>
> # so gathering domain parts working
>
> $r->server->server_admin("$subdomain\@$domain");

Yes, as expected, and it uses a published API to do that.

> #
> # 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>",
> ]);
>

Except for my above explanation, this would work just fine. I would
however caution about using this kind of mechanism to alter run-time
configuration on a per-request basis. This comes at a non-negligable
performance impact, if that's important to your usage scenario.

Ideally, like in the server_admin() case outlined above, mpm-itk
could/should expose an API to allow for changing the userid/domain.

You could try and use PerlMapToStorageHandler as your phase, since it
happens before the PerlHeaderParserHandler phase.

--
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
Attachments: signature.asc (0.24 KB)

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.