Apache-NNTPGateway
view release on metacpan or search on metacpan
NNTPGateway.pm view on Meta::CPAN
$r->log->info( "DisabledActions: \"$disabled\"" ) if $DEBUG;
my @disabled = split( /([\s,])/, $disabled );
foreach ( @disabled ) {
my $a = $_;
$Disabled_Actions{$a} = 1 if $Actions_Map{$a};
}
} else {
$r->log->notice( "DisabledActions: none" );
}
# NYI: Get directory where to find HTML::Template files. This
# feature is not yet implemented but hope it will be soon...
my $tmpldir = $r->dir_config( 'NNTPGatewayTemplatesDir' ) || $DEFAULT_TEMPLATES_DIR;
# Append server root to it
$tmpldir = $r->server_root_relative( $tmpldir ) unless File::Spec->file_name_is_absolute( $tmpldir );
# Canonize dir name
$Templates_Dir = File::Spec->canonpath( $tmpldir );
unless ( -d $Templates_Dir ) {
#$r->log_error( "Templates dir $Templates_Dir not found!" );
#return 0;
}
#$r->log->info( "Using templates from dir $Templates_Dir ..." ) if $DEBUG;
return 1;
} # end get_config();
### Sub check_user() ###
# status = &check_user( request ):
# - Description: Check username..., via ident 1st then w/ http loggin...
# This function need still a lot of work.
# - Arguments : the Apache request
# - Return : 1=ok, 0=failure
###
sub check_user ( $ ) {
my $r = shift;
# The_User is a global...
# 1/ Try to check username through indent
# (IdentityCheck) and then with Http authentication.
$The_User = $r->get_remote_logname() || $r->connection->user() || undef;
if ( $The_User &&
&is_true( $r->dir_config( 'NNTPGatewayUsersNamesCaseInsensitive' ))) {
$The_User = lc( $The_User );
}
# The following list should be configurable maybe ?
$The_User = undef if
(
$The_User eq '-' ||
$The_User eq 'unknown' ||
$The_User eq 'anonymous' ||
$The_User eq 'guest' ||
$The_User eq 'admin' ||
$The_User eq 'root'
);
# 2/ Check username validity, by checking if a local (Unix) account
# exists for the user. This check is mainly for posting actions,
# the access protection is not handled in this module.
my $username = (getpwnam($The_User))[6];
# No password entry for this user consider it as anonymous
$The_User = undef if ( !$username && !&is_true( $r->dir_config( 'NNTPGatewayNonLocalPostOk' )));
# 3/ Check if user allowed to use this service ... And build a choice of possible
# From addresses.
if ( $Anonymous_Post_Allowed ) {
# Populate from posters list with some anonymous one...
%From_Posters = %Anonymous_Posters;
# ... and with the real user name too.
$From_Posters{$The_User} = $username if $The_User;
# Here I should undef $r->connection->remote_logname() and
# $r->connection->user() and associated values in subprocess_env,
# so that they will definitively disappear from any log files, to
# be fair. I should ... Should I really ?
} elsif (( not $The_User ) && $Post_Actions_Map{$The_Action} ) {
# The user had not been successfully identified, and the current
# action is to post an article, but anonymous post is not enabled
# ... so bad luck today.
$r->log->warn( "${Base}: From ",
$r->get_remote_host(),
", posting not allowed for unidentified users." );
&print_html_head( $r );
&print_html_error( $r, &message('no_anon' ), undef );
&print_html_foot( $r );
return 0;
} else {
# The user had been identified and seems (...) to be valid, as
# we're not in anonymous posting mode this is the only one poster
# allowed.
$From_Posters{$The_User} = $username;
}
return 1;
} # end check_user();
### Sub message() ###
# string = &message( msgkey [, args] ):
# - Description:
# - Arguments : message_map key, args
# - Return : string
###
sub message ( $\@ ) {
my $k = lc( shift );
my @args = @_;
return undef unless exists $Messages_Map{$k};
my $fmt = $Messages_Map{$k}->{$USR_LANG};
return sprintf( $fmt, @args );
} # end message();
### Sub is_true() ###
# bool = &is_true( string ):
# - Description: Check arg is true.
( run in 0.640 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )