perrin, I am forced to bow to your mastery here... with appreciation.
I haven't finished all the bits that I need, but it's definitely turning out to be significantly easier to do this as you suggested than I had originally feared. And, yes, this is mod_perl2, so I can do an output filter.
For anyone else who cares, relevant code (and otherwise) fragments: (Names have been changed to protect the guilty...)
httpd.conf
PerlModule Foo::FooAuth
PerlModule Foo::FooFilter
<Location /foo/cgi-bin/foo.cgi>
PerlOutputFilterHandler Foo::FooFilter
PerlAuthenHandler Foo::FooAuth
require valid-user
</Location>
Foo::FooAuth
package Foo::FooAuth;
use strict;
use Apache2::Const qw(:common);
use Foo::AuthAux; # Provides whoami - uses a cookie set elsewhere
sub handler {
my $r = shift;
my $user = whoami($r);
unless ($user) {
$r->note_basic_auth_failure;
return AUTH_REQUIRED;
}
$r->user($user);
$r->subprocess_env(FOO => "bar+$user");
return OK;
}
1;
Foo::FooFilter
package Foo::FooFilter;
use strict;
use Apache2::Filter;
use Apache2::Const qw(:common);
use Apache2::Request;
use HTML::Template;
use Foo::Config; # Provides $TMPL_PATH below
use Foo::Auth;
use Foo::AuthAux; # Provides whoami below
my $BUFF_LEN = 8192;
sub handler {
my $f = shift;
my $r = $f->r;
my $fullbuf;
while ($f->read(my $buf, $BUFF_LEN)) {
$fullbuf .= $buf;
}
my $tmpl = HTML::Template->new(scalarref => \$fullbuf,
path => $TMPL_PATH,
die_on_bad_params => 0,
);
my $user = whoami($r);
my $userinfo = ISPNET::Auth::userinfo($user);
$tmpl->param(_user => $user,
_logo => $userinfo->{logo},
_logo_alt => $userinfo->{logo_alt},
# Set _home (would be $ENV{SCRIPT_NAME})...
);
$f->print($tmpl->output);
return OK;
}
1;
I'm still debating where to put the .cgi scripts (in the filesystem) and have to figure out how to reference them from elsewhere (which will be used to adjust the $tmpl->param(_home => ...) bits, but otherwise, it seems to be working nicely. |