***** infoCopter.com/perl *****
mod_perl Basic Authmod_perl Recipe[ mod_perl ] - [ mod_perl Basic Auth Challenge ] Challenge
RecipeEdit your httpd.conf (or ssl.conf) <VirtualHost> ... # --- CGI replacement: Alias /my/x/ /usr/local/apache2/ssl.pgate.net/my/x/ <Location /my/x/> SetHandler perl-script PerlHandler ModPerl::Registry PerlSendHeader On Options +ExecCGI </Location> <Location /my/> AuthType Basic AuthName "The GATE" Require valid-user # mod_perl Basic Auth: PerlAuthenHandler Custom::Login ErrorDocument 401 /nok.htm </Location> ... </VirtualHost> Login.pmFollowing Perl Modul has to be located within on of Perl's search path, typically /usr/lib/perl5/site_perl/.
package Custom::Login;
use strict;
use warnings;
# ---------------------------------------------------
# Basic Auth Sample
# (c) retoh :)
# ---------------------------------------------------
use Apache::Access ();
use Apache::RequestUtil ();
use Apache::RequestRec (); # Always needed
use Apache::RequestIO (); # Needed by Apache::RequestRec!
use Apache::Const -compile => qw(OK DECLINED AUTH_REQUIRED);
sub handler {
my $r = shift;
my ($status, $password) = $r->get_basic_auth_pw;
return $status unless $status == Apache::OK;
my $user = $r->user;
if ($user) {
my $auth_name = $r->auth_name;
if ($user eq 'foo') {
# -- We don't allow foo ;-)
$r->note_basic_auth_failure;
return Apache::AUTH_REQUIRED;
}
else {
return Apache::OK;
}
}
else {
$r->note_basic_auth_failure;
return Apache::AUTH_REQUIRED;
}
}
1;
|