2008-12-30 10:37:56 +01:00
|
|
|
##@file
|
|
|
|
# Base package for Lemonldap::NG configuration system
|
|
|
|
|
|
|
|
##@class
|
|
|
|
# Implements Lemonldap::NG shared configuration system.
|
|
|
|
# In case of error or warning, the message is stored in the global variable
|
|
|
|
# $Lemonldap::NG::Common::Conf::msg
|
2008-11-17 17:59:56 +01:00
|
|
|
package Lemonldap::NG::Common::Conf;
|
2006-12-18 12:32:33 +01:00
|
|
|
|
|
|
|
use strict;
|
2007-04-29 14:07:20 +02:00
|
|
|
no strict 'refs';
|
2010-03-01 21:32:28 +01:00
|
|
|
use Lemonldap::NG::Common::Conf::Constants; #inherits
|
2009-12-15 17:31:13 +01:00
|
|
|
use Lemonldap::NG::Common::Crypto
|
|
|
|
; #link protected cipher Object "cypher" in configuration hash
|
2009-11-30 17:46:14 +01:00
|
|
|
use Config::IniFiles;
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2009-02-03 10:36:13 +01:00
|
|
|
#inherits Lemonldap::NG::Common::Conf::File
|
|
|
|
#inherits Lemonldap::NG::Common::Conf::DBI
|
|
|
|
#inherits Lemonldap::NG::Common::Conf::SOAP
|
2009-04-06 12:11:05 +02:00
|
|
|
#inherits Lemonldap::NG::Common::Conf::LDAP
|
2009-02-03 10:36:13 +01:00
|
|
|
|
2012-08-13 12:53:29 +02:00
|
|
|
our $VERSION = '1.2.2';
|
2008-11-21 18:51:52 +01:00
|
|
|
our $msg;
|
2010-10-27 10:04:28 +02:00
|
|
|
our $iniObj;
|
2006-12-18 12:32:33 +01:00
|
|
|
|
2010-10-30 22:26:11 +02:00
|
|
|
BEGIN {
|
|
|
|
eval {
|
|
|
|
require threads::shared;
|
|
|
|
threads::shared::share($iniObj);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @cmethod Lemonldap::NG::Common::Conf new(hashRef arg)
|
|
|
|
# Constructor.
|
|
|
|
# Succeed if it has found a way to access to Lemonldap::NG configuration with
|
|
|
|
# $arg (or default file). It can be :
|
2009-12-03 11:08:33 +01:00
|
|
|
# - Nothing: default configuration file is tested,
|
2009-02-17 15:56:38 +01:00
|
|
|
# - { confFile => "/path/to/storage.conf" },
|
2008-12-30 10:37:56 +01:00
|
|
|
# - { Type => "File", dirName => "/path/to/conf/dir/" },
|
|
|
|
# - { Type => "DBI", dbiChain => "DBI:mysql:database=lemonldap-ng;host=1.2.3.4",
|
|
|
|
# dbiUser => "user", dbiPassword => "password" },
|
2009-06-29 11:42:44 +02:00
|
|
|
# - { Type => "SOAP", proxy => "https://auth.example.com/index.pl/config" },
|
2009-04-06 12:11:05 +02:00
|
|
|
# - { Type => "LDAP", ldapServer => "ldap://localhost", ldapConfBranch => "ou=conf,ou=applications,dc=example,dc=com",
|
|
|
|
# ldapBindDN => "cn=manager,dc=example,dc=com", ldapBindPassword => "secret"},
|
2008-12-30 10:37:56 +01:00
|
|
|
#
|
|
|
|
# $self->{type} contains the type of configuration access system and the
|
|
|
|
# corresponding package is loaded.
|
|
|
|
# @param $arg hash reference or hash table
|
|
|
|
# @return New Lemonldap::NG::Common::Conf object
|
2006-12-18 12:32:33 +01:00
|
|
|
sub new {
|
|
|
|
my $class = shift;
|
2008-11-19 12:25:35 +01:00
|
|
|
my $self = bless {}, $class;
|
2006-12-18 12:32:33 +01:00
|
|
|
if ( ref( $_[0] ) ) {
|
2008-11-19 18:49:46 +01:00
|
|
|
%$self = %{ $_[0] };
|
2006-12-18 12:32:33 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-06-26 14:02:31 +02:00
|
|
|
if ( (@_) && $#_ % 2 == 1 ) {
|
2009-12-02 10:01:17 +01:00
|
|
|
%$self = @_;
|
|
|
|
}
|
2006-12-18 12:32:33 +01:00
|
|
|
}
|
2007-01-04 09:42:13 +01:00
|
|
|
unless ( $self->{mdone} ) {
|
2009-12-02 16:08:35 +01:00
|
|
|
unless ( $self->{type} ) {
|
2009-12-03 11:08:33 +01:00
|
|
|
|
2009-12-02 16:08:35 +01:00
|
|
|
# Use local conf to get configStorage and localStorage
|
2009-12-03 11:08:33 +01:00
|
|
|
my $localconf =
|
|
|
|
$self->getLocalConf( CONFSECTION, $self->{confFile}, 0 );
|
|
|
|
if ( defined $localconf ) {
|
2009-12-02 16:08:35 +01:00
|
|
|
%$self = ( %$self, %$localconf );
|
|
|
|
}
|
|
|
|
}
|
2007-01-04 09:42:13 +01:00
|
|
|
unless ( $self->{type} ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Error: configStorage: type is not defined.\n";
|
2007-01-04 09:42:13 +01:00
|
|
|
return 0;
|
2006-12-18 12:32:33 +01:00
|
|
|
}
|
2009-10-20 15:20:53 +02:00
|
|
|
unless ( $self->{type} =~ /^[\w:]+$/ ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Error: configStorage: type is not well formed.\n";
|
2009-10-20 15:20:53 +02:00
|
|
|
}
|
2008-11-17 17:59:56 +01:00
|
|
|
$self->{type} = "Lemonldap::NG::Common::Conf::$self->{type}"
|
2008-12-22 18:49:36 +01:00
|
|
|
unless $self->{type} =~ /^Lemonldap::/;
|
2006-12-18 12:32:33 +01:00
|
|
|
eval "require $self->{type}";
|
2008-11-21 18:51:52 +01:00
|
|
|
if ($@) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Error: Unknown package $self->{type}.\n";
|
2008-11-21 18:51:52 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2006-12-18 12:32:33 +01:00
|
|
|
return 0 unless $self->prereq;
|
2007-01-04 09:42:13 +01:00
|
|
|
$self->{mdone}++;
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "$self->{type} loaded.\n";
|
2006-12-18 12:32:33 +01:00
|
|
|
}
|
2008-11-19 18:49:46 +01:00
|
|
|
if ( $self->{localStorage} and not defined( $self->{refLocalStorage} ) ) {
|
|
|
|
eval "use $self->{localStorage};";
|
|
|
|
if ($@) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Unable to load $self->{localStorage}: $@.\n";
|
2008-11-19 18:49:46 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->{refLocalStorage} =
|
|
|
|
$self->{localStorage}->new( $self->{localStorageOptions} );
|
|
|
|
}
|
|
|
|
}
|
2006-12-18 12:32:33 +01:00
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method int saveConf(hashRef conf)
|
|
|
|
# Serialize $conf and call store().
|
|
|
|
# @param $conf Lemonldap::NG configuration hashRef
|
|
|
|
# @return Number of the saved configuration, 0 if case of error.
|
2006-12-18 12:32:33 +01:00
|
|
|
sub saveConf {
|
2007-01-04 09:42:13 +01:00
|
|
|
my ( $self, $conf ) = @_;
|
2008-11-19 18:49:46 +01:00
|
|
|
|
2009-12-30 16:40:37 +01:00
|
|
|
my $last = $self->lastCfg;
|
|
|
|
|
2007-03-04 15:52:51 +01:00
|
|
|
# If configuration was modified, return an error
|
2009-12-30 16:40:37 +01:00
|
|
|
if ( not $self->{force} ) {
|
|
|
|
return CONFIG_WAS_CHANGED if ( $conf->{cfgNum} != $last );
|
2010-10-23 10:00:07 +02:00
|
|
|
return DATABASE_LOCKED if ( $self->isLocked() or not $self->lock() );
|
2009-12-30 16:40:37 +01:00
|
|
|
}
|
|
|
|
$conf->{cfgNum} = $last + 1 unless ( $self->{cfgNumFixed} );
|
2012-08-09 20:42:40 +02:00
|
|
|
delete $conf->{cipher};
|
2012-02-26 16:13:53 +01:00
|
|
|
|
|
|
|
# Try to store configuration
|
2010-10-23 10:00:07 +02:00
|
|
|
my $tmp = $self->store($conf);
|
2012-02-26 16:13:53 +01:00
|
|
|
|
|
|
|
unless ( $tmp > 0 ) {
|
|
|
|
$msg .= "Configuration $conf->{cfgNum} not stored.\n";
|
|
|
|
return ( $tmp ? $tmp : UNKNOWN_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
$msg .= "Configuration $conf->{cfgNum} stored.\n";
|
2010-10-23 10:00:07 +02:00
|
|
|
return ( $self->unlock() ? $tmp : UNKNOWN_ERROR );
|
2006-12-18 12:32:33 +01:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method hashRef getConf(hashRef args)
|
|
|
|
# Get configuration from remote configuration storage system or from local
|
|
|
|
# cache if configuration has not been changed. If $args->{local} is set and if
|
|
|
|
# a local configuration is available, remote configuration is not tested.
|
|
|
|
#
|
|
|
|
# Uses lastCfg to test and getDBConf() to get the remote configuration
|
|
|
|
# @param $args Optional, contains {local=>1} or nothing
|
|
|
|
# @return Lemonldap::NG configuration
|
2006-12-18 12:32:33 +01:00
|
|
|
sub getConf {
|
2007-01-04 09:42:13 +01:00
|
|
|
my ( $self, $args ) = @_;
|
2008-11-19 18:49:46 +01:00
|
|
|
if ( $args->{'local'}
|
|
|
|
and ref( $self->{refLocalStorage} )
|
|
|
|
and my $res = $self->{refLocalStorage}->get('conf') )
|
|
|
|
{
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Get configuration from cache without verification.\n";
|
2008-11-19 18:49:46 +01:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
else {
|
2008-11-20 07:53:44 +01:00
|
|
|
$args->{cfgNum} ||= $self->lastCfg;
|
2009-06-23 22:36:44 +02:00
|
|
|
unless ( $args->{cfgNum} ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "No configuration available.\n";
|
2009-06-23 22:36:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-28 18:37:10 +01:00
|
|
|
my $r;
|
2008-11-19 18:49:46 +01:00
|
|
|
unless ( ref( $self->{refLocalStorage} ) ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Get remote configuration (localStorage unavailable).\n";
|
|
|
|
$r = $self->getDBConf($args);
|
2008-11-19 18:49:46 +01:00
|
|
|
}
|
2009-01-28 18:37:10 +01:00
|
|
|
else {
|
2010-11-01 10:16:32 +01:00
|
|
|
eval { $r = $self->{refLocalStorage}->get('conf') };
|
|
|
|
$msg = "Warn: $@" if ($@);
|
|
|
|
if ( ref($r) and $r->{cfgNum} == $args->{cfgNum} ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .=
|
|
|
|
"Configuration unchanged, get configuration from cache.\n";
|
2009-12-03 11:08:33 +01:00
|
|
|
}
|
2009-01-28 18:37:10 +01:00
|
|
|
else {
|
|
|
|
$r = $self->getDBConf($args);
|
|
|
|
}
|
|
|
|
}
|
2012-08-14 14:01:10 +02:00
|
|
|
print STDERR "Warning: key is not defined, set it in the manager !\n"
|
2012-08-09 20:42:40 +02:00
|
|
|
unless ( $r->{key} );
|
|
|
|
eval {
|
|
|
|
$r->{cipher} =
|
|
|
|
Lemonldap::NG::Common::Crypto->new( $r->{key}
|
|
|
|
|| 'lemonldap-ng-key' );
|
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
$msg .= "Bad key: $@. \n";
|
|
|
|
return $r;
|
2009-02-15 12:30:25 +01:00
|
|
|
}
|
2009-01-28 18:37:10 +01:00
|
|
|
return $r;
|
2008-11-19 18:49:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-02 16:08:35 +01:00
|
|
|
## @method hashRef getLocalConf(string section, string file, int loaddefault)
|
2009-11-30 17:46:14 +01:00
|
|
|
# Get configuration from local file
|
|
|
|
#
|
2009-12-02 16:08:35 +01:00
|
|
|
# @param $section Optional section name (default DEFAULTSECTION)
|
|
|
|
# @param $file Optional file name (default DEFAULTCONFFILE)
|
|
|
|
# @param $loaddefault Optional load default section parameters (default 1)
|
2009-11-30 17:46:14 +01:00
|
|
|
# @return Lemonldap::NG configuration
|
|
|
|
sub getLocalConf {
|
2009-12-02 16:08:35 +01:00
|
|
|
my ( $self, $section, $file, $loaddefault ) = @_;
|
2010-09-23 12:19:06 +02:00
|
|
|
my $r = {};
|
2009-11-30 17:46:14 +01:00
|
|
|
|
2009-12-03 11:08:33 +01:00
|
|
|
$section ||= DEFAULTSECTION;
|
2010-10-30 22:26:11 +02:00
|
|
|
$file ||= $self->{confFile} || DEFAULTCONFFILE;
|
2009-12-02 16:08:35 +01:00
|
|
|
$loaddefault = 1 unless ( defined $loaddefault );
|
2010-03-09 22:42:31 +01:00
|
|
|
my $cfg;
|
|
|
|
|
|
|
|
# First, search if this file has been parsed
|
2010-10-27 10:04:28 +02:00
|
|
|
unless ( $cfg = $iniObj->{$file} ) {
|
2009-11-30 17:46:14 +01:00
|
|
|
|
2010-03-11 16:00:59 +01:00
|
|
|
# If default configuration cannot be read
|
|
|
|
# - Error if configuration section is requested
|
|
|
|
# - Silent exit for other section requests
|
|
|
|
unless ( -r $file ) {
|
|
|
|
if ( $section eq CONFSECTION ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .=
|
|
|
|
"Cannot read $file to get configuration access parameters.\n";
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2010-03-11 16:00:59 +01:00
|
|
|
}
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2009-12-02 16:08:35 +01:00
|
|
|
}
|
2009-11-30 17:46:14 +01:00
|
|
|
|
2010-03-11 16:00:59 +01:00
|
|
|
# Parse ini file
|
2010-03-09 22:42:31 +01:00
|
|
|
$cfg = Config::IniFiles->new( -file => $file, -allowcontinue => 1 );
|
2009-11-30 17:46:14 +01:00
|
|
|
|
2010-03-11 16:00:59 +01:00
|
|
|
unless ( defined $cfg ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Local config error: " . @Config::IniFiles::errors . "\n";
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2010-03-11 16:00:59 +01:00
|
|
|
}
|
2009-11-30 17:46:14 +01:00
|
|
|
|
2010-03-11 16:00:59 +01:00
|
|
|
# Check if default section exists
|
|
|
|
unless ( $cfg->SectionExists(DEFAULTSECTION) ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Default section (" . DEFAULTSECTION . ") is missing. \n";
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2010-03-11 16:00:59 +01:00
|
|
|
}
|
2009-12-02 16:08:35 +01:00
|
|
|
|
2010-03-11 16:00:59 +01:00
|
|
|
# Check if configuration section exists
|
|
|
|
if ( $section eq CONFSECTION and !$cfg->SectionExists(CONFSECTION) ) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Configuration section (" . CONFSECTION . ") is missing.\n";
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2010-03-11 16:00:59 +01:00
|
|
|
}
|
2010-03-09 22:42:31 +01:00
|
|
|
}
|
2010-10-27 10:04:28 +02:00
|
|
|
$self->{_iniObj} = $cfg;
|
2009-12-02 16:08:35 +01:00
|
|
|
|
2009-11-30 17:46:14 +01:00
|
|
|
# First load all default section parameters
|
2009-12-03 11:08:33 +01:00
|
|
|
if ($loaddefault) {
|
|
|
|
foreach ( $cfg->Parameters(DEFAULTSECTION) ) {
|
2009-12-02 16:08:35 +01:00
|
|
|
$r->{$_} = $cfg->val( DEFAULTSECTION, $_ );
|
2011-04-14 11:50:40 +02:00
|
|
|
if ( $r->{$_} =~ /^[{\[].*[}\]]$/ || $r->{$_} =~ /^sub\s*{.*}$/ ) {
|
2009-12-02 16:08:35 +01:00
|
|
|
eval "\$r->{$_} = $r->{$_}";
|
|
|
|
if ($@) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Warning: error in file $file: $@.\n";
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2009-12-02 16:08:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 17:46:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Stop if the requested section is the default section
|
2009-12-02 16:08:35 +01:00
|
|
|
return $r if ( $section eq DEFAULTSECTION );
|
2009-11-30 17:46:14 +01:00
|
|
|
|
|
|
|
# Check if requested section exists
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r unless $cfg->SectionExists($section);
|
2009-11-30 17:46:14 +01:00
|
|
|
|
|
|
|
# Load section parameters
|
2009-12-03 11:08:33 +01:00
|
|
|
foreach ( $cfg->Parameters($section) ) {
|
2009-11-30 17:46:14 +01:00
|
|
|
$r->{$_} = $cfg->val( $section, $_ );
|
2011-04-14 11:50:40 +02:00
|
|
|
if ( $r->{$_} =~ /^[{\[].*[}\]]$/ || $r->{$_} =~ /^sub\s*{.*}$/ ) {
|
2009-12-02 16:08:35 +01:00
|
|
|
eval "\$r->{$_} = $r->{$_}";
|
|
|
|
if ($@) {
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Warning: error in file $file: $@.\n";
|
2010-09-23 12:19:06 +02:00
|
|
|
return $r;
|
2009-12-02 16:08:35 +01:00
|
|
|
}
|
|
|
|
}
|
2009-11-30 17:46:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $r;
|
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method void setLocalConf(hashRef conf)
|
|
|
|
# Store $conf in the local cache.
|
|
|
|
# @param $conf Lemonldap::NG configuration hashRef
|
2008-11-19 18:49:46 +01:00
|
|
|
sub setLocalConf {
|
|
|
|
my ( $self, $conf ) = @_;
|
2010-11-01 10:16:32 +01:00
|
|
|
eval { $self->{refLocalStorage}->set( "conf", $conf ) };
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Warn: $@\n" if ($@);
|
2008-11-19 18:49:46 +01:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method hashRef getDBConf(hashRef args)
|
|
|
|
# Get configuration from remote storage system.
|
|
|
|
# @param $args hashRef that must contains a key "cfgNum" (number of the wanted
|
|
|
|
# configuration) and optionaly a key "fields" that points to an array of wanted
|
|
|
|
# configuration keys
|
|
|
|
# @return Lemonldap::NG configuration hashRef
|
2008-11-19 18:49:46 +01:00
|
|
|
sub getDBConf {
|
|
|
|
my ( $self, $args ) = @_;
|
2006-12-18 12:32:33 +01:00
|
|
|
return undef unless $args->{cfgNum};
|
2008-11-19 18:49:46 +01:00
|
|
|
if ( $args->{cfgNum} < 0 ) {
|
2007-05-05 16:13:44 +02:00
|
|
|
my @a = $self->available();
|
2008-11-19 18:49:46 +01:00
|
|
|
$args->{cfgNum} =
|
|
|
|
( @a + $args->{cfgNum} > 0 )
|
|
|
|
? ( $a[ $#a + $args->{cfgNum} ] )
|
|
|
|
: $a[0];
|
2007-05-05 16:13:44 +02:00
|
|
|
}
|
2009-10-20 15:20:53 +02:00
|
|
|
my $conf = $self->load( $args->{cfgNum} );
|
2011-07-07 17:08:45 +02:00
|
|
|
$msg .= "Get configuration $conf->{cfgNum}.\n";
|
2009-06-23 22:36:44 +02:00
|
|
|
$self->setLocalConf($conf)
|
|
|
|
if ( $self->{refLocalStorage} and not( $args->{noCache} ) );
|
2006-12-18 12:32:33 +01:00
|
|
|
return $conf;
|
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method boolean prereq()
|
|
|
|
# Call prereq() from the $self->{type} package.
|
|
|
|
# @return True if succeed
|
2007-04-29 14:07:20 +02:00
|
|
|
sub prereq {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::prereq' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method @ available()
|
|
|
|
# Call available() from the $self->{type} package.
|
|
|
|
# @return list of available configuration numbers
|
2007-04-29 14:07:20 +02:00
|
|
|
sub available {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::available' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method int lastCfg()
|
|
|
|
# Call lastCfg() from the $self->{type} package.
|
|
|
|
# @return Number of the last configuration available
|
2007-04-29 14:07:20 +02:00
|
|
|
sub lastCfg {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::lastCfg' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method boolean lock()
|
|
|
|
# Call lock() from the $self->{type} package.
|
|
|
|
# @return True if succeed
|
2007-04-29 14:07:20 +02:00
|
|
|
sub lock {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::lock' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method boolean isLocked()
|
|
|
|
# Call isLocked() from the $self->{type} package.
|
|
|
|
# @return True if database is locked
|
2007-04-29 14:07:20 +02:00
|
|
|
sub isLocked {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::isLocked' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method boolean unlock()
|
|
|
|
# Call unlock() from the $self->{type} package.
|
|
|
|
# @return True if succeed
|
2007-04-29 14:07:20 +02:00
|
|
|
sub unlock {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::unlock' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method int store(hashRef conf)
|
|
|
|
# Call store() from the $self->{type} package.
|
|
|
|
# @param $conf Lemondlap configuration serialized
|
|
|
|
# @return Number of new configuration stored if succeed, 0 else.
|
2007-04-29 14:07:20 +02:00
|
|
|
sub store {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::store' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method load(int cfgNum, arrayRef fields)
|
|
|
|
# Call load() from the $self->{type} package.
|
|
|
|
# @return Lemonldap::NG Configuration hashRef if succeed, 0 else.
|
2007-04-29 14:07:20 +02:00
|
|
|
sub load {
|
2008-11-19 18:49:46 +01:00
|
|
|
return &{ $_[0]->{type} . '::load' }(@_);
|
2007-04-29 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:37:56 +01:00
|
|
|
## @method boolean delete(int cfgNum)
|
|
|
|
# Call delete() from the $self->{type} package.
|
|
|
|
# @param $cfgNum Number of configuration to delete
|
|
|
|
# @return True if succeed
|
2007-05-05 16:13:44 +02:00
|
|
|
sub delete {
|
2008-11-19 18:49:46 +01:00
|
|
|
my ( $self, $c ) = @_;
|
2007-05-05 16:13:44 +02:00
|
|
|
my @a = $self->available();
|
2008-11-19 18:49:46 +01:00
|
|
|
return 0 unless ( @a + $c > 0 );
|
|
|
|
return &{ $self->{type} . '::delete' }( $self, $a[ $#a + $c ] );
|
2007-05-05 16:13:44 +02:00
|
|
|
}
|
|
|
|
|
2009-12-15 17:31:13 +01:00
|
|
|
sub logError {
|
|
|
|
return &{ $_[0]->{type} . '::logError' }(@_);
|
|
|
|
}
|
|
|
|
|
2006-12-18 12:32:33 +01:00
|
|
|
1;
|
|
|
|
__END__
|
2006-12-23 16:42:58 +01:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2010-01-03 09:09:59 +01:00
|
|
|
=encoding utf8
|
|
|
|
|
2008-11-17 17:59:56 +01:00
|
|
|
Lemonldap::NG::Common::Conf - Perl extension written to manage Lemonldap::NG
|
2006-12-23 16:42:58 +01:00
|
|
|
Web-SSO configuration.
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2008-11-17 17:59:56 +01:00
|
|
|
use Lemonldap::NG::Common::Conf;
|
|
|
|
my $confAccess = new Lemonldap::NG::Common::Conf(
|
2008-11-19 18:49:46 +01:00
|
|
|
{
|
2007-01-14 20:39:07 +01:00
|
|
|
type=>'File',
|
|
|
|
dirName=>"/tmp/",
|
2008-11-19 18:49:46 +01:00
|
|
|
|
|
|
|
# To use local cache, set :
|
|
|
|
localStorage => "Cache::FileCache",
|
|
|
|
localStorageOptions = {
|
2012-08-13 12:53:29 +02:00
|
|
|
'namespace' => 'lemonldap-ng-config',
|
2008-11-19 18:49:46 +01:00
|
|
|
'default_expires_in' => 600,
|
|
|
|
'directory_umask' => '007',
|
|
|
|
'cache_root' => '/tmp',
|
|
|
|
'cache_depth' => 5,
|
2007-01-14 20:39:07 +01:00
|
|
|
},
|
2008-11-19 18:49:46 +01:00
|
|
|
},
|
2008-11-17 17:59:56 +01:00
|
|
|
) or die "Unable to build Lemonldap::NG::Common::Conf, see Apache logs";
|
2006-12-23 16:42:58 +01:00
|
|
|
my $config = $confAccess->getConf();
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2008-11-17 17:59:56 +01:00
|
|
|
Lemonldap::NG::Common::Conf provides a simple interface to access to
|
2007-02-28 13:56:35 +01:00
|
|
|
Lemonldap::NG Web-SSO configuration. It is used by L<Lemonldap::NG::Handler>,
|
|
|
|
L<Lemonldap::NG::Portal> and L<Lemonldap::NG::Manager>.
|
2006-12-23 16:42:58 +01:00
|
|
|
|
|
|
|
=head2 SUBROUTINES
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * B<new> (constructor): it takes different arguments depending on the
|
2010-01-03 09:09:59 +01:00
|
|
|
chosen type. Examples:
|
2006-12-23 16:42:58 +01:00
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * B<File>:
|
2008-11-17 17:59:56 +01:00
|
|
|
$confAccess = new Lemonldap::NG::Common::Conf(
|
2007-03-09 20:46:09 +01:00
|
|
|
{
|
|
|
|
type => 'File',
|
|
|
|
dirName => '/var/lib/lemonldap-ng/',
|
|
|
|
});
|
2006-12-23 16:42:58 +01:00
|
|
|
|
|
|
|
=item * B<DBI>:
|
2008-11-17 17:59:56 +01:00
|
|
|
$confAccess = new Lemonldap::NG::Common::Conf(
|
2007-03-09 20:46:09 +01:00
|
|
|
{
|
|
|
|
type => 'DBI',
|
2007-06-03 08:29:15 +02:00
|
|
|
dbiChain => 'DBI:mysql:database=lemonldap-ng;host=1.2.3.4',
|
2007-03-09 20:46:09 +01:00
|
|
|
dbiUser => 'lemonldap'
|
|
|
|
dbiPassword => 'pass'
|
|
|
|
dbiTable => 'lmConfig',
|
|
|
|
});
|
2006-12-23 16:42:58 +01:00
|
|
|
|
2007-02-28 13:56:35 +01:00
|
|
|
=item * B<SOAP>:
|
2008-11-17 17:59:56 +01:00
|
|
|
$confAccess = new Lemonldap::NG::Common::Conf(
|
2007-03-09 20:46:09 +01:00
|
|
|
{
|
|
|
|
type => 'SOAP',
|
2009-06-29 11:42:44 +02:00
|
|
|
proxy => 'http://auth.example.com/index.pl/config',
|
2007-03-09 20:46:09 +01:00
|
|
|
proxyOptions => {
|
|
|
|
timeout => 5,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2009-06-29 11:42:44 +02:00
|
|
|
SOAP configuration access is a sort of proxy: the portal is configured to use
|
|
|
|
the real session storage type (DBI or File for example). See HTML documentation
|
|
|
|
for more.
|
2007-02-28 13:56:35 +01:00
|
|
|
|
2009-04-06 12:11:05 +02:00
|
|
|
=item * B<LDAP>:
|
|
|
|
$confAccess = new Lemonldap::NG::Common::Conf(
|
|
|
|
{
|
|
|
|
type => 'LDAP',
|
|
|
|
ldapServer => 'ldap://localhost',
|
|
|
|
ldapConfBranch => 'ou=conf,ou=applications,dc=example,dc=com',
|
|
|
|
ldapBindDN => 'cn=manager,dc=example,dc=com",
|
|
|
|
ldapBindPassword => 'secret'
|
|
|
|
});
|
|
|
|
|
2006-12-23 16:42:58 +01:00
|
|
|
=back
|
|
|
|
|
2007-03-23 20:56:33 +01:00
|
|
|
WARNING: You have to use the same storage type on all Lemonldap::NG parts in
|
|
|
|
the same server.
|
|
|
|
|
2006-12-23 16:42:58 +01:00
|
|
|
=item * B<getConf>: returns a hash reference to the configuration. it takes
|
|
|
|
a hash reference as first argument containing 2 optional parameters:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item * C<cfgNum => $number>: the number of the configuration wanted. If this
|
|
|
|
argument is omitted, the last configuration is returned.
|
|
|
|
|
|
|
|
=item * C<fields => [array of names]: the desired fields asked. By default,
|
|
|
|
getConf returns all (C<select * from lmConfig>).
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
2007-04-29 16:36:57 +02:00
|
|
|
=item * B<saveConf>: stores the Lemonldap::NG configuration passed in argument
|
2006-12-23 16:42:58 +01:00
|
|
|
(hash reference). it returns the number of the new configuration.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2007-04-02 21:13:05 +02:00
|
|
|
L<Lemonldap::NG::Handler>, L<Lemonldap::NG::Portal>,
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://lemonldap-ng.org/>
|
2006-12-23 16:42:58 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
Xavier Guimard, E<lt>x.guimard@free.frE<gt>
|
|
|
|
|
2007-04-14 15:12:11 +02:00
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://jira.ow2.org>
|
2007-04-14 15:12:11 +02:00
|
|
|
|
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
2006-12-23 16:42:58 +01:00
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
2010-10-23 10:35:38 +02:00
|
|
|
Copyright (C) 2006, 2007, 2010 by Xavier Guimard
|
2006-12-23 16:42:58 +01:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2010-10-24 09:25:44 +02:00
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or,
|
2006-12-23 16:42:58 +01:00
|
|
|
at your option, any later version of Perl 5 you may have available.
|
|
|
|
|
|
|
|
=cut
|