Changing apache config with mod_perl, doesnt work!

Changing apache config with mod_perl, doesnt work!

am 22.11.2009 23:42:38 von Devrim Yasar

--Apple-Mail-5--697799423
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=us-ascii;
format=flowed;
delsp=yes

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...


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
# --------------
# AssignUserId fio domain
# --------------

$r->add_config([ "",
"AssignUserId $subdomain $domain",
"
",
]);

if ( $@ ) { warn $@ }


return OK;

} else {
return DECLINED;
}
});



--Apple-Mail-5--697799423
Content-Transfer-Encoding: 7bit
Content-Type: text/html;
charset=us-ascii

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 ,
# this successfully assigns ServerAdmin
# 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>


--Apple-Mail-5--697799423--

Re: Changing apache config with mod_perl, doesnt work!

am 23.11.2009 03:59:47 von gozer

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig611A0D95CD34CF77FB0B2072
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

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.
>=20
> 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 passw=
d.
>=20
> Any ideas though? Thanks...
>=20
> |
> Use Apache2::ServerRec qw//;=20
> use Apache2::ServerUtil qw//;=20
> use Apache2::RequestRec qw//;=20
> use Apache2::RequestUtil qw//;=20
> use Apache2::Const qw/OK DECLINED/;=20
>=20
> my $s =3D Apache2::ServerUtil->server;=20
>=20
> $s->push_handlers(PerlHeaderParserHandler =3D> sub { my($r) =3D @_;=20

=46rom 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 =3D~ m/(.*)\.([^.]+\.\w+)$/ ) {=20
> my($subdomain,$domain) =3D ($1,$2);=20
>=20
> #
> # THIS WORKS!
> # -----------
> # if requested domain is fio.domain.com ,
> # this successfully assigns ServerAdmin fio@domain.com ain.com>
> # so gathering domain parts working
>=20
> $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
> # --------------
> # AssignUserId fio domain
> # --------------
>=20
> $r->add_config([ "",=20
> "AssignUserId $subdomain $domain",=20
> "
",=20
> ]);=20
>=20

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.

--=20
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/


--------------enig611A0D95CD34CF77FB0B2072
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLCfqkyzKhB4jDpaURAnidAKCwfzKYG9pUS4F0jyf/6LifmQJFnACf bWyQ
rpXrhoYL50S7Y88slXsx2B0=
=RjIJ
-----END PGP SIGNATURE-----

--------------enig611A0D95CD34CF77FB0B2072--