Authentication-Driven ContentA simple authentication handler either accepts or rejects users. If you instead want to give them different output if authentication fails, you could use a pair of Perl handlers, one on the authentication hook and one on content generation. The content handler then checks whether the note is present, and prints one page or the other depending on the result of that check.
package AuthContent;
use strict;
use Zeus::ModPerl;
use Zeus::ModPerl::Constants qw( :common );
sub authen ($$)
{
my( $pkg, $r ) = @_;
my( $ret, $password ) = $r->get_basic_auth_pw();
if( $ret != OK ) { return $ret }
my $errmsg = '';
my $user = $r->connection()->user();
if( defined($user) )
{
my @pw = getpwnam( $user );
if( @pw && (crypt($password,$pw[1]) ne $pw[1]) )
{
$r->note_basic_auth_failure();
$r->log_reason( $errmsg, $r->filename() );
return AUTH_REQUIRED;
}
$r->pnotes( authenticated => 1 );
}
return OK;
}
sub content ($$)
{
my( $pkg, $r ) = @_;
if( $r->pnotes( 'authenticated' ) )
{
my $user = $r->connection()->user();
print( <<EOF );
<html>
<head><title>Authenticated page</title></head>
<body>You are authenticated as user '$user'.</body>
</html>
EOF
}
else
{
print( <<EOF );
<html>
<head><title>Anonymous page</title></head>
<body>You are not authenticated.</body>
</html>
EOF
}
return OK;
};
1;
To install this example using the Administration Server user interface, put the above code in You will also need to enable the htaccess support, and create an htaccess file with an 'authname' entry, and a global htaccess file with 'passenvauthorization on' in a suitable 'Directory' tag.
Content Manager
[Administrator] 16 December 2005
|
Recent Articles
Other Resources
|


