Handler: remove useless call to defaultValuesInit at server startup, move
remaining methods of LocalInit into SharedConf and remove LocalInit.pm (#630)
This commit is contained in:
parent
7cfff88ac5
commit
6aa06d2d40
|
@ -12,7 +12,6 @@ lib/Lemonldap/NG/Handler/API/CGI.pm
|
||||||
lib/Lemonldap/NG/Handler/API/Nginx.pm
|
lib/Lemonldap/NG/Handler/API/Nginx.pm
|
||||||
lib/Lemonldap/NG/Handler/CGI.pm
|
lib/Lemonldap/NG/Handler/CGI.pm
|
||||||
lib/Lemonldap/NG/Handler/Initialization/GlobalInit.pm
|
lib/Lemonldap/NG/Handler/Initialization/GlobalInit.pm
|
||||||
lib/Lemonldap/NG/Handler/Initialization/LocalInit.pm
|
|
||||||
lib/Lemonldap/NG/Handler/Main.pm
|
lib/Lemonldap/NG/Handler/Main.pm
|
||||||
lib/Lemonldap/NG/Handler/Main/Headers.pm
|
lib/Lemonldap/NG/Handler/Main/Headers.pm
|
||||||
lib/Lemonldap/NG/Handler/Main/Jail.pm
|
lib/Lemonldap/NG/Handler/Main/Jail.pm
|
||||||
|
@ -33,7 +32,6 @@ META.yml
|
||||||
README
|
README
|
||||||
t/01-Lemonldap-NG-Handler-Main.t
|
t/01-Lemonldap-NG-Handler-Main.t
|
||||||
t/02-Lemonldap-NG-Handler-Main-Portal.t
|
t/02-Lemonldap-NG-Handler-Main-Portal.t
|
||||||
t/04-Lemonldap-NG-Handler-Initialization-LocalInit.t
|
|
||||||
t/05-Lemonldap-NG-Handler-Initialization-GlobalInit.t
|
t/05-Lemonldap-NG-Handler-Initialization-GlobalInit.t
|
||||||
t/10-Lemonldap-NG-Handler-SharedConf.t
|
t/10-Lemonldap-NG-Handler-SharedConf.t
|
||||||
t/12-Lemonldap-NG-Handler-Jail.t
|
t/12-Lemonldap-NG-Handler-Jail.t
|
||||||
|
|
|
@ -222,7 +222,7 @@ sub localSessionStorageInit {
|
||||||
my $params = "";
|
my $params = "";
|
||||||
if ($localSessionStorage) {
|
if ($localSessionStorage) {
|
||||||
require Data::Dumper;
|
require Data::Dumper;
|
||||||
$params = " $self->{localStorage},"
|
$params = " $self->{localSessionStorage},"
|
||||||
. Data::Dumper->new( [ $localSessionStorageOptions ] )->Terse(1)->Indent(0)->Dump; # To send cache params on one line
|
. Data::Dumper->new( [ $localSessionStorageOptions ] )->Terse(1)->Indent(0)->Dump; # To send cache params on one line
|
||||||
}
|
}
|
||||||
#print { $tsv->{statusPipe} } "RELOADCACHE$params";
|
#print { $tsv->{statusPipe} } "RELOADCACHE$params";
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
# Methods run at server startup / reload
|
|
||||||
|
|
||||||
package Lemonldap::NG::Handler::Initialization::LocalInit;
|
|
||||||
|
|
||||||
use Lemonldap::NG::Handler::SharedConf; # Needed to get VERSION
|
|
||||||
use Lemonldap::NG::Handler::Main::Logger;
|
|
||||||
use Lemonldap::NG::Handler::API qw(:httpCodes);
|
|
||||||
|
|
||||||
our $VERSION = '1.4.0';
|
|
||||||
my ( $statusPipe, $statusOut );
|
|
||||||
|
|
||||||
## @imethod void localInit(hashRef args)
|
|
||||||
# Launch the status process (statusProcess()) if wanted
|
|
||||||
# @param $args reference to the initialization hash
|
|
||||||
sub localInit($$) {
|
|
||||||
my ( $class, $args ) = splice @_;
|
|
||||||
|
|
||||||
$class->statusInit if ($args->{status});
|
|
||||||
$class->serverSignatureInit unless ($args->{hideSignature});
|
|
||||||
|
|
||||||
return ( $statusPipe, $statusOut );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub serverSignatureInit {
|
|
||||||
my $class = shift;
|
|
||||||
Lemonldap::NG::Handler::API->setServerSignature(
|
|
||||||
"Lemonldap::NG::Handler/" . $Lemonldap::NG::Handler::VERSION
|
|
||||||
) if ( $Lemonldap::NG::Handler::VERSION );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## @ifn protected void statusInit()
|
|
||||||
# Launch the status process
|
|
||||||
sub statusInit {
|
|
||||||
my $class = shift;
|
|
||||||
require IO::Pipe;
|
|
||||||
$statusPipe = IO::Pipe->new;
|
|
||||||
$statusOut = IO::Pipe->new;
|
|
||||||
if ( my $pid = fork() ) {
|
|
||||||
$statusPipe->writer();
|
|
||||||
$statusOut->reader();
|
|
||||||
$statusPipe->autoflush(1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$statusPipe->reader();
|
|
||||||
$statusOut->writer();
|
|
||||||
my $fdin = $statusPipe->fileno;
|
|
||||||
my $fdout = $statusOut->fileno;
|
|
||||||
open STDIN, "<&$fdin";
|
|
||||||
open STDOUT, ">&$fdout";
|
|
||||||
my @tmp = ();
|
|
||||||
push @tmp, "-I$_" foreach (@INC);
|
|
||||||
exec 'perl', '-MLemonldap::NG::Handler::Status',
|
|
||||||
@tmp,
|
|
||||||
'-e',
|
|
||||||
"&Lemonldap::NG::Handler::Status::run()";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
|
|
@ -1,24 +1,9 @@
|
||||||
## @file
|
# Methods run at request serving
|
||||||
# Base file for Lemonldap::NG handlers
|
|
||||||
|
|
||||||
## @class
|
|
||||||
# Base class for Lemonldap::NG handlers.
|
|
||||||
# All methods in handler are class methods: in ModPerl environment, handlers
|
|
||||||
# are always launched without object created.
|
|
||||||
#
|
|
||||||
# The main method is run() who is called by Apache for each requests (using
|
|
||||||
# handler() wrapper).
|
|
||||||
#
|
|
||||||
# The main initialization subroutine is init() who launch localInit() and
|
|
||||||
# globalInit().
|
|
||||||
package Lemonldap::NG::Handler::Main;
|
package Lemonldap::NG::Handler::Main;
|
||||||
|
|
||||||
#use strict;
|
|
||||||
|
|
||||||
use MIME::Base64;
|
use MIME::Base64;
|
||||||
use Exporter 'import';
|
use Exporter 'import';
|
||||||
|
|
||||||
#use AutoLoader 'AUTOLOAD';
|
|
||||||
use Lemonldap::NG::Common::Crypto;
|
use Lemonldap::NG::Common::Crypto;
|
||||||
use Lemonldap::NG::Common::Session;
|
use Lemonldap::NG::Common::Session;
|
||||||
require POSIX;
|
require POSIX;
|
||||||
|
@ -79,7 +64,6 @@ BEGIN {
|
||||||
Lemonldap::NG::Handler::API->thread_share($tsv);
|
Lemonldap::NG::Handler::API->thread_share($tsv);
|
||||||
}
|
}
|
||||||
|
|
||||||
use Lemonldap::NG::Handler::Initialization::LocalInit;
|
|
||||||
use Lemonldap::NG::Handler::Initialization::GlobalInit;
|
use Lemonldap::NG::Handler::Initialization::GlobalInit;
|
||||||
use Lemonldap::NG::Handler::Main::Jail;
|
use Lemonldap::NG::Handler::Main::Jail;
|
||||||
use Lemonldap::NG::Handler::Main::Headers;
|
use Lemonldap::NG::Handler::Main::Headers;
|
||||||
|
@ -482,14 +466,6 @@ sub initLocalStorage {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
## @imethod void localInit(hashRef args)
|
|
||||||
# launch localInit method which launch the status process
|
|
||||||
# @param $args reference to the initialization hash
|
|
||||||
sub localInit($$) {
|
|
||||||
my ( $class, $args ) = splice @_;
|
|
||||||
( $tsv->{statusPipe}, $tsv->{statusOut} ) = Lemonldap::NG::Handler::Initialization::LocalInit->localInit($args);
|
|
||||||
}
|
|
||||||
|
|
||||||
## @imethod void globalInit(hashRef args)
|
## @imethod void globalInit(hashRef args)
|
||||||
# instanciate a GlobalInit object with variables:
|
# instanciate a GlobalInit object with variables:
|
||||||
# customFunctions, useSafeJail, and safe
|
# customFunctions, useSafeJail, and safe
|
||||||
|
@ -670,7 +646,6 @@ sub status($$) {
|
||||||
'debug', $r );
|
'debug', $r );
|
||||||
return $class->abort( $r, "$class: status page can not be displayed" )
|
return $class->abort( $r, "$class: status page can not be displayed" )
|
||||||
unless ( $tsv->{statusPipe} and $tsv->{statusOut} );
|
unless ( $tsv->{statusPipe} and $tsv->{statusOut} );
|
||||||
$r->handler("perl-script");
|
|
||||||
print { $tsv->{statusPipe} } "STATUS"
|
print { $tsv->{statusPipe} } "STATUS"
|
||||||
. (
|
. (
|
||||||
Lemonldap::NG::Handler::API->args($r)
|
Lemonldap::NG::Handler::API->args($r)
|
||||||
|
|
|
@ -23,7 +23,6 @@ use Lemonldap::NG::Handler::API qw(:httpCodes);
|
||||||
use Lemonldap::NG::Handler::Initialization::GlobalInit;
|
use Lemonldap::NG::Handler::Initialization::GlobalInit;
|
||||||
use Lemonldap::NG::Common::Conf; #link protected lmConf
|
use Lemonldap::NG::Common::Conf; #link protected lmConf
|
||||||
use Lemonldap::NG::Common::Conf::Constants; #inherits
|
use Lemonldap::NG::Common::Conf::Constants; #inherits
|
||||||
use Cache::Cache qw($EXPIRES_NEVER);
|
|
||||||
use Lemonldap::NG::Handler::Main::Logger;
|
use Lemonldap::NG::Handler::Main::Logger;
|
||||||
|
|
||||||
use base qw(Lemonldap::NG::Handler::Main);
|
use base qw(Lemonldap::NG::Handler::Main);
|
||||||
|
@ -55,74 +54,74 @@ BEGIN {
|
||||||
# INIT PROCESS
|
# INIT PROCESS
|
||||||
|
|
||||||
## @imethod void init(hashRef args)
|
## @imethod void init(hashRef args)
|
||||||
# Load parameters and build the Lemonldap::NG::Common::Conf object.
|
# Read parameters and build the Lemonldap::NG::Common::Conf object.
|
||||||
# @param $args hash containing parameters
|
# @param $args hash containing parameters
|
||||||
sub init($$) {
|
sub init($$) {
|
||||||
my ( $class, $args ) = splice @_;
|
my ( $class, $args ) = @_;
|
||||||
|
|
||||||
|
# According to doc, localStorage can be declared in $args root,
|
||||||
|
# but it must be in $args->{configStorage}
|
||||||
|
foreach (qw(localStorage localStorageOptions)) {
|
||||||
|
$args->{configStorage}->{$_} ||= $args->{$_};
|
||||||
|
}
|
||||||
|
|
||||||
$lmConf = Lemonldap::NG::Common::Conf->new($args->{configStorage});
|
$lmConf = Lemonldap::NG::Common::Conf->new($args->{configStorage});
|
||||||
die( "$class : unable to build configuration: "
|
die( "$class : unable to build configuration: "
|
||||||
. "$Lemonldap::NG::Common::Conf::msg" ) unless ($lmConf);
|
. "$Lemonldap::NG::Common::Conf::msg" ) unless ($lmConf);
|
||||||
|
|
||||||
# Get local configuration parameters
|
# Merge local configuration parameters so that params defined in
|
||||||
my $localconf = $lmConf->getLocalConf(HANDLERSECTION);
|
# startup parameters have precedence over lemonldap-ng.ini params
|
||||||
if ($localconf) {
|
$localConfig = {
|
||||||
$args->{$_} ||= $localconf->{$_} foreach ( keys %$localconf );
|
%{ $lmConf->getLocalConf(HANDLERSECTION) },
|
||||||
}
|
%{ $args }
|
||||||
|
};
|
||||||
|
|
||||||
# Store in localConfig global variable
|
$checkTime = $localConfig->{checkTime} || $checkTime;
|
||||||
$localConfig = $args;
|
|
||||||
|
|
||||||
# localStorage can be declared in configStorage or at the root or both
|
# Few actions that must be done at server startup:
|
||||||
foreach (qw(localStorage localStorageOptions)) {
|
# * set server signature
|
||||||
$args->{$_} ||= $args->{configStorage}->{$_} || $lmConf->{$_};
|
$class->serverSignatureInit unless ($localConfig->{hideSignature});
|
||||||
$args->{configStorage}->{$_} ||= $args->{$_};
|
# * launch status process
|
||||||
}
|
( $tsv->{statusPipe}, $tsv->{statusOut} ) = $class->statusInit
|
||||||
|
if ($localConfig->{status});
|
||||||
$checkTime = $args->{checkTime} || $checkTime;
|
|
||||||
|
|
||||||
$class->defaultValuesInit($args);
|
|
||||||
$class->localInit($args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## @imethod protected void defaultValuesInit(hashRef args)
|
# @method void serverSignatureInit
|
||||||
# Set default values for non-customized variables
|
# adapt server signature
|
||||||
# @param $args hash containing parameters
|
sub serverSignatureInit {
|
||||||
# @return boolean
|
my $class = shift;
|
||||||
sub defaultValuesInit {
|
Lemonldap::NG::Handler::API->setServerSignature(
|
||||||
my ( $class, $args ) = splice @_;
|
"Lemonldap::NG::Handler/" . $Lemonldap::NG::Handler::VERSION
|
||||||
|
) if ( $Lemonldap::NG::Handler::VERSION );
|
||||||
# Local configuration overrides global configuration
|
}
|
||||||
my %h = ( %$args, %$localConfig );
|
|
||||||
|
|
||||||
#return $class->SUPER::defaultValuesInit( \%h );
|
|
||||||
|
|
||||||
my $globalinit = Lemonldap::NG::Handler::Initialization::GlobalInit->new(
|
|
||||||
customFunctions => $tsv->{customFunctions},
|
|
||||||
useSafeJail => $tsv->{useSafeJail},
|
|
||||||
);
|
|
||||||
|
|
||||||
(
|
|
||||||
@$tsv{
|
|
||||||
qw( cookieName securedCookie whatToTrace
|
|
||||||
https port customFunctions
|
|
||||||
timeoutActivity useRedirectOnError useRedirectOnForbidden
|
|
||||||
useSafeJail key maintenance
|
|
||||||
cda httpOnly cookieExpiration
|
|
||||||
cipher )
|
|
||||||
}
|
|
||||||
)
|
|
||||||
= $globalinit->defaultValuesInit(
|
|
||||||
@$tsv{
|
|
||||||
qw( cookieName securedCookie whatToTrace
|
|
||||||
https port customFunctions
|
|
||||||
timeoutActivity useRedirectOnError useRedirectOnForbidden
|
|
||||||
useSafeJail key maintenance
|
|
||||||
cda httpOnly cookieExpiration
|
|
||||||
cipher )
|
|
||||||
},
|
|
||||||
\%h
|
|
||||||
);
|
|
||||||
|
|
||||||
|
## @ifn protected void statusInit()
|
||||||
|
# Launch the status process
|
||||||
|
sub statusInit {
|
||||||
|
my $class = shift;
|
||||||
|
require IO::Pipe;
|
||||||
|
$statusPipe = IO::Pipe->new;
|
||||||
|
$statusOut = IO::Pipe->new;
|
||||||
|
if ( my $pid = fork() ) {
|
||||||
|
$statusPipe->writer();
|
||||||
|
$statusOut->reader();
|
||||||
|
$statusPipe->autoflush(1);
|
||||||
|
return ( $statusPipe, $statusOut );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$statusPipe->reader();
|
||||||
|
$statusOut->writer();
|
||||||
|
my $fdin = $statusPipe->fileno;
|
||||||
|
my $fdout = $statusOut->fileno;
|
||||||
|
open STDIN, "<&$fdin";
|
||||||
|
open STDOUT, ">&$fdout";
|
||||||
|
my @tmp = ();
|
||||||
|
push @tmp, "-I$_" foreach (@INC);
|
||||||
|
exec 'perl', '-MLemonldap::NG::Handler::Status',
|
||||||
|
@tmp,
|
||||||
|
'-e',
|
||||||
|
"&Lemonldap::NG::Handler::Status::run()";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# MAIN
|
# MAIN
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
# Before `make install' is performed this script should be runnable with
|
|
||||||
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Handler-Vhost.t'
|
|
||||||
|
|
||||||
#########################
|
|
||||||
|
|
||||||
# change 'tests => 1' to 'tests => last_test_to_print';
|
|
||||||
|
|
||||||
package My::Package;
|
|
||||||
|
|
||||||
use Test::More tests => 2;
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
use_ok('Lemonldap::NG::Handler::Initialization::LocalInit');
|
|
||||||
}
|
|
||||||
|
|
||||||
#########################
|
|
||||||
|
|
||||||
# Insert your test code below, the Test::More module is use()ed here so read
|
|
||||||
# its man page ( perldoc Test::More ) for help writing this test script.
|
|
||||||
|
|
||||||
ok(
|
|
||||||
Lemonldap::NG::Handler::Initialization::LocalInit->localInit({
|
|
||||||
status => 1,
|
|
||||||
hideSignature => 0,
|
|
||||||
}),
|
|
||||||
'localInit method'
|
|
||||||
);
|
|
||||||
|
|
||||||
__END__
|
|
||||||
ok(
|
|
||||||
my (
|
|
||||||
$localStorage, $localStorageOptions,
|
|
||||||
$statusPipe, $statusOut
|
|
||||||
)
|
|
||||||
= $localinit->localInit(
|
|
||||||
{
|
|
||||||
localStorage => 'Cache::FileCache',
|
|
||||||
localStorageOptions => { 'namespace' => 'lemonldap-ng-sessions', },
|
|
||||||
status => 1,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'LocalInit methods: localInit'
|
|
||||||
);
|
|
||||||
|
|
||||||
ok(
|
|
||||||
(
|
|
||||||
$localStorage eq 'Cache::FileCache'
|
|
||||||
and $localStorageOptions->{'namespace'} eq 'lemonldap-ng-sessions'
|
|
||||||
),
|
|
||||||
'LocalInit methods: localInit values'
|
|
||||||
);
|
|
||||||
|
|
||||||
ok( $localinit->statusProcess == 0, 'LocalInit methods: statusProcess' );
|
|
||||||
|
|
||||||
ok( $statusPipe->isa('IO::Pipe::End'), 'status pipe: In pipe' );
|
|
||||||
|
|
||||||
ok( $statusOut->isa('IO::Pipe::End'), 'status pipe: Out pipe' );
|
|
||||||
|
|
||||||
ok( print( $statusPipe "uid => / OK\nuid => / OK\nuid => /no REJECT\n" ),
|
|
||||||
'status pipe: New requests' );
|
|
||||||
|
|
||||||
ok( print( $statusPipe "STATUS\n" ), 'status pipe: Status request' );
|
|
||||||
|
|
||||||
ok( &read, 'status pipe: Status result' );
|
|
||||||
|
|
||||||
ok( close($statusOut), 'status pipe: close out pipe' );
|
|
||||||
|
|
||||||
ok( close($statusPipe), 'status pipe: close in pipe' );
|
|
||||||
|
|
||||||
sub read {
|
|
||||||
my $ok = 0;
|
|
||||||
|
|
||||||
#open LOG, '>/tmp/log';
|
|
||||||
while (<$statusOut>) {
|
|
||||||
|
|
||||||
#print LOG $_;
|
|
||||||
$ok++ if (/^OK\s+:\s*2\s*\(2\.00\s*\/\s*mn\)$/);
|
|
||||||
$ok++ if (/^REJECT\s+:\s*1\s*\(1\.00\s*\/\s*mn\)$/);
|
|
||||||
if (/^END$/) {
|
|
||||||
$ok++;
|
|
||||||
last;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#print LOG "$ok\n";
|
|
||||||
#close LOG;
|
|
||||||
return ( $ok == 3 );
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user