Commit 70522969 authored by Clément OUDOT's avatar Clément OUDOT
Browse files

Add possibility to use a local configuration file (localconf.ini) to override...

Add possibility to use a local configuration file (localconf.ini) to override configuration parameters
parent ca905f34
......@@ -368,6 +368,7 @@ install_conf_dir: install_sessions_dir
@if [ "$(ERASECONFIG)" -eq "1" ]; then \
cp --remove-destination $(SRCCOMMONDIR)/storage.conf $(RCONFDIR); \
perl -i -pe 's#^dirName = .*#dirName = $(FILECONFIGDIR)#g' $(RCONFDIR)/storage.conf; \
cp --remove-destination $(SRCCOMMONDIR)/localconf.ini $(RCONFDIR); \
fi
@cp _example/conf/lmConf-1 $(RFILECONFIGDIR)
@perl -000 -i -pe "s#^(globalStorageOptions\\n\\s+)'[^\\n]*?'\$$#\$${1}\'\\\$$data1 = {&39;Directory&39; => &39;$(APACHESESSIONFILEDIR)&39;,&39;LockDirectory&39; => &39;$(APACHESESSIONFILELOCKDIR)&39;};'#m" $(RFILECONFIGDIR)/lmConf-1
......
......@@ -20,6 +20,8 @@ requires:
Regexp::Assemble: 0
SOAP::Lite: 0
Storable: 0
File::Basename: 0
Config::IniFiles: 0
no_index:
directory:
- t
......
......@@ -12,15 +12,19 @@ no strict 'refs';
use Lemonldap::NG::Common::Conf::Constants; #inherits
use Lemonldap::NG::Common::Crypto; #link protected cipher Object "cypher" in configuration hash
use Regexp::Assemble;
use File::Basename;
use Config::IniFiles;
#inherits Lemonldap::NG::Common::Conf::File
#inherits Lemonldap::NG::Common::Conf::DBI
#inherits Lemonldap::NG::Common::Conf::SOAP
#inherits Lemonldap::NG::Common::Conf::LDAP
use constant DEFAULTCONFFILE => "/etc/lemonldap-ng/storage.conf";
use constant DEFAULTCONFFILE => "/usr/local/lemonldap-ng/etc/storage.conf";
use constant LOCALCONFFILENAME => "localconf.ini";
use constant DEFAULTINISECTION => "all";
our $VERSION = 0.6;
our $VERSION = 0.70;
our $msg;
our %_confFiles;
......@@ -189,6 +193,59 @@ sub getConf {
}
}
## @method hashRef getLocalConf(string section, string file)
# Get configuration from local file
#
# @param $section Optional section name (default DEFAULTINISECTION)
# @param $file Optional file name (default dirname DEFAULTCONFFILE . LOCALCONFFILENAME)
# @return Lemonldap::NG configuration
sub getLocalConf {
my ( $self, $section, $file ) = @_;
my $r;
$section ||= DEFAULTINISECTION;
unless ( $file ) {
# Get storage.conf path
my( $filename, $directories ) = fileparse DEFAULTCONFFILE;
$file = $directories . LOCALCONFFILENAME;
}
# If local configuration file does not exists, exit silently.
unless ( -r $file ) {
return $r;
}
# Parse ini file
my $cfg = Config::IniFiles->new(
-file => $file,
-allowempty => 1,
);
unless (defined $cfg) {
$msg = "Local config error: ".@Config::IniFiles::errors;
return 0;
}
# First load all default section parameters
foreach ($cfg->Parameters( DEFAULTINISECTION )) {
$r->{$_} = $cfg->val( DEFAULTINISECTION, $_ );
}
# Stop if the requested section is the default section
return $r if ( $section eq DEFAULTINISECTION );
# Check if requested section exists
return 0 unless $cfg->SectionExists( $section );
# Load section parameters
foreach ($cfg->Parameters( $section )) {
$r->{$_} = $cfg->val( $section, $_ );
}
return $r;
}
## @method void setLocalConf(hashRef conf)
# Store $conf in the local cache.
# @param $conf Lemonldap::NG configuration hashRef
......
#==============================================================================
# LemonLDAP::NG local configuration parameters
#
# This file is dedicated to configuration parameters override
# You can set here configuration parameters that will be used only by
# local LemonLDAP::NG elements
#
# Parameters of section "all" are always read
# Other section are only read by the specific LemonLDAP::NG component
#==============================================================================
[all]
#cda = 1
[portal]
portalDisplayResetPassword = 0
[handler]
https = 0
[manager]
dhtmlXTreeImageLocation = /imgs/
#protection = authenticate
......@@ -25,7 +25,7 @@ use Cache::Cache qw($EXPIRES_NEVER);
use base qw(Lemonldap::NG::Handler::Vhost Lemonldap::NG::Handler::Simple);
#parameter reloadTime Time in second between 2 configuration check (600)
our $VERSION = '0.71';
our $VERSION = '0.72';
our $cfgNum = 0;
our $lastReload = 0;
our $reloadTime;
......@@ -61,8 +61,8 @@ BEGIN {
# @param $args hash containing parameters
sub init($$) {
my ( $class, $args ) = @_;
# TODO reloadTime in defaultValuesInit ?
$reloadTime = $args->{reloadTime} || 600;
$localConfig = $args;
$class->localInit($args);
}
......@@ -89,11 +89,19 @@ sub localInit {
unless ( $lmConf =
Lemonldap::NG::Common::Conf->new( $args->{configStorage} ) );
# Get local configuration parameters
my $localconf = $lmConf->getLocalConf("handler");
$args->{$_} ||= $localconf->{$_} foreach ( keys %$localconf );
# Store in localConfig global variable
$localConfig = $args;
# localStorage can be declared in configStorage or at the root or both
foreach (qw(localStorage localStorageOptions)) {
$args->{$_} ||= $args->{configStorage}->{$_} || $lmConf->{$_};
$args->{configStorage}->{$_} ||= $args->{$_};
}
$class->defaultValuesInit($args);
$class->SUPER::localInit($args);
}
......
......@@ -26,7 +26,7 @@ use MIME::Base64;
use base qw(Lemonldap::NG::Common::CGI);
our @ISA;
our $VERSION = '0.91';
our $VERSION = '0.92';
# Secure jail
our $msafe;
......@@ -58,20 +58,24 @@ sub msafe {
# @param $args hash reference containing parameters
sub new {
my ( $class, $args ) = @_;
my $self;
my $self = $class->SUPER::new();
# TODO load global configuration parameters ?
# Try to load local configuration parameters to get 'protection'
my $localconf = $self->config->getLocalConf("manager");
$args->{protection} ||= $localconf->{protection};
if ( $args->{protection} ) {
require Lemonldap::NG::Handler::CGI;
unshift @ISA, "Lemonldap::NG::Handler::CGI";
$self = $class->SUPER::new($args);
}
else {
$self = $class->SUPER::new();
}
unless ($args) {
$self->abort( "Unable to start",
"parameters are required, I can't start so" );
}
# Now push all local configuration parameters
%$self = ( %$self, %$args );
$self->{$_} = $args->{$_} || $localconf->{$_} foreach ( keys %$localconf );
foreach (qw(dhtmlXTreeImageLocation)) {
unless ( $self->{$_} ) {
$self->abort( "Unable to start",
......
......@@ -13,7 +13,7 @@ use Lemonldap::NG::Common::Conf; #link protected lmConf Configuration
*EXPORT_TAGS = *Lemonldap::NG::Portal::Simple::EXPORT_TAGS;
*EXPORT = *Lemonldap::NG::Portal::Simple::EXPORT;
our $VERSION = '0.6';
our $VERSION = '0.70';
use base qw(Lemonldap::NG::Portal::Simple);
##################
......@@ -33,12 +33,22 @@ sub getConf {
else {
%args = @_;
}
%$self = ( %$self, %args );
my $tmp = $self->_getLmConf;
return 0 unless $tmp;
# Local configuration prepends global
$self->{$_} = $args{$_} || $tmp->{$_} foreach ( keys %$tmp );
# Get global configuration
my $globalconf = $self->_getLmConf;
return 0 unless $globalconf;
# Get local configuration
my $localconf = $self->_getLocalLmConf;
# Configuration load order:
# 1/ Global configuration
# 2/ Local file configuration
# 3/ Script embedded configuration
$self->{$_} = $args{$_} || $globalconf->{$_} foreach ( keys %$globalconf );
$self->{$_} = $args{$_} || $localconf->{$_} foreach ( keys %$localconf );
1;
}
......@@ -65,6 +75,21 @@ sub _getLmConf {
return $self->{lmConf}->getConf;
}
## @method private hashref _getLocalLmConf()
# Call and return Lemonldap::NG::Common::getLocalConf() value
# @return Lemonldap::NG local configuration
sub _getLocalLmConf {
my $self = shift;
# Get Configuration object
unless ( defined $self->{lmConf} ) {
return 0 unless $self->_getLmConf();
}
# Get local configuration parameters for portal
return $self->{lmConf}->getLocalConf("portal");
}
1;
__END__
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment