2007-03-29 18:10:14 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-05-08 14:33:20 +02:00
|
|
|
LSsession :: loadLSclass('LSlog_staticLoggerClass');
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSattribute');
|
2007-03-29 18:10:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base d'un objet ldap
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette classe définis la base de tout objet ldap géré par LdapSaisie
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
2020-05-08 14:33:20 +02:00
|
|
|
class LSldapObject extends LSlog_staticLoggerClass {
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-04-25 15:48:12 +02:00
|
|
|
var $config = array();
|
2008-02-08 18:39:24 +01:00
|
|
|
var $type_name;
|
2008-04-25 15:48:12 +02:00
|
|
|
var $attrs = array();
|
2007-03-29 18:10:14 +02:00
|
|
|
var $forms;
|
2008-02-08 18:39:24 +01:00
|
|
|
var $view;
|
2007-03-29 18:10:14 +02:00
|
|
|
var $dn=false;
|
2009-03-09 13:42:03 +01:00
|
|
|
var $oldDn=false;
|
2007-03-29 18:10:14 +02:00
|
|
|
var $other_values=array();
|
2008-02-08 18:39:24 +01:00
|
|
|
var $_whoami=NULL;
|
2009-01-08 00:06:05 +01:00
|
|
|
var $_LSrelationsCache=array();
|
2009-03-09 13:42:03 +01:00
|
|
|
|
|
|
|
var $_events=array();
|
|
|
|
var $_objectEvents=array();
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
var $cache=array();
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Constructeur
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette methode construit l'objet et définis la configuration.
|
|
|
|
* Elle lance la construction du tableau d'attributs représentés par un objet LSattribute.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si l'objet a été construit, false sinon.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct() {
|
2009-03-22 14:20:22 +01:00
|
|
|
$this -> type_name = get_class($this);
|
2009-03-25 18:46:48 +01:00
|
|
|
$config = LSconfig :: get('LSobjects.'.$this -> type_name);
|
|
|
|
if(is_array($config)) {
|
|
|
|
$this -> config = $config;
|
2009-03-22 14:20:22 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_01');
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2019-03-11 22:21:25 +01:00
|
|
|
foreach($this -> getConfig('attrs', array()) as $attr_name => $attr_config) {
|
2008-02-08 18:39:24 +01:00
|
|
|
if(!$this -> attrs[$attr_name]=new LSattribute($attr_name,$attr_config,$this)) {
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
return true;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Charge les données de l'objet
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette methode définis le DN de l'objet et charge les valeurs de attributs de l'objet
|
|
|
|
* Ã partir de l'annuaire.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $dn string Le DN de l'objet.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si la chargement a réussi, false sinon.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function loadData($dn) {
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> dn = $dn;
|
2020-05-14 11:07:18 +02:00
|
|
|
$data = LSldap :: getAttrs($dn, $this -> getObjectFilter());
|
|
|
|
if(is_array($data) && !empty($data)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
2010-11-08 17:04:14 +01:00
|
|
|
if( !$this -> attrs[$attr_name] -> loadData( (isset($data[$attr_name])?$data[$attr_name]:NULL) ) )
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-04-26 14:08:56 +02:00
|
|
|
$this->cache=array();
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Recharge les données de l'objet
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si la rechargement a réussi, false sinon.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function reloadData() {
|
2009-01-25 15:37:03 +01:00
|
|
|
$data = LSldap :: getAttrs($this -> dn);
|
2007-11-15 19:07:24 +01:00
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
2010-11-25 12:23:56 +01:00
|
|
|
if(!$this -> attrs[$attr_name] -> reloadData( (isset($data[$attr_name])?$data[$attr_name]:NULL) ))
|
2007-11-15 19:07:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne le format d'affichage de l'objet
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string Format d'affichage de l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getDisplayNameFormat() {
|
2019-03-11 22:21:25 +01:00
|
|
|
return $this -> getConfig('display_name_format');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne la valeur descriptive d'affichage de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2007-03-29 18:10:14 +02:00
|
|
|
* Cette fonction retourne la valeur descriptive d'affichage de l'objet en fonction
|
2008-10-14 13:58:00 +02:00
|
|
|
* du format défini dans la configuration de l'objet ou spécifié en paramètre.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $spe [<i>optionnel</i>] string Format d'affichage de l'objet
|
2008-07-05 22:28:49 +02:00
|
|
|
* @param[in] $full [<i>optionnel</i>] boolean True pour afficher en plus le
|
|
|
|
* subDnName
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @retval string Valeur descriptive d'affichage de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2020-02-18 12:32:25 +01:00
|
|
|
public function getDisplayName($spe=null, $full=false) {
|
|
|
|
if (is_null($spe))
|
2009-01-07 20:24:14 +01:00
|
|
|
$spe = $this -> getDisplayNameFormat();
|
2020-02-18 12:32:25 +01:00
|
|
|
$val = $this -> getFData($spe, $this -> attrs, 'getDisplayValue');
|
2009-01-24 18:45:14 +01:00
|
|
|
if (LSsession :: haveSubDn() && $full) {
|
2009-10-30 01:03:17 +01:00
|
|
|
$val.=' ('.$this -> subDnName.')';
|
2008-07-05 22:28:49 +02:00
|
|
|
}
|
|
|
|
return $val;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Chaine formatée
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette fonction retourne la valeur d'une chaine formatée en prennant les valeurs
|
2007-03-29 18:10:14 +02:00
|
|
|
* de l'objet.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $format string Format de la chaine
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval string Valeur d'une chaine formatée
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getFData($format) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$format=getFData($format,$this,'getValue');
|
|
|
|
return $format;
|
|
|
|
}
|
2011-01-20 10:32:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Chaine formatee
|
|
|
|
*
|
2011-01-20 12:12:05 +01:00
|
|
|
* Cette fonction retourne la valeur d'une chaine formatee en prennant les valeurs
|
2011-01-20 10:32:26 +01:00
|
|
|
* d'affichage de l'objet.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $format string Format de la chaine
|
|
|
|
*
|
|
|
|
* @retval string Valeur d'une chaine formatee
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getDisplayFData($format) {
|
2011-01-20 12:12:05 +01:00
|
|
|
return getFData($format,$this,'getDisplayValue');
|
2011-01-20 10:32:26 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Construit un formulaire de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
|
2007-03-29 18:10:14 +02:00
|
|
|
* et de chaque attribut.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
|
|
|
|
* @param[in] $load DN d'un objet similaire dont la valeur des attribut doit être chargé dans le formulaire.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval LSform Le formulaire crée
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getForm($idForm,$load=NULL) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSform');
|
2007-11-15 19:07:24 +01:00
|
|
|
$LSform = new LSform($this,$idForm);
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> forms[$idForm] = array($LSform,$load);
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($load) {
|
|
|
|
$type = $this -> getType();
|
|
|
|
$loadObject = new $type();
|
|
|
|
if (!$loadObject -> loadData($load)) {
|
|
|
|
$load=false;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($load) {
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
2008-11-10 00:55:17 +01:00
|
|
|
if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this,$loadObject -> attrs[$attr_name] -> getFormVal())) {
|
2008-02-12 18:59:44 +01:00
|
|
|
$LSform -> can_validate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
if(!$this -> attrs[$attr_name] -> addToForm($LSform,$idForm,$this)) {
|
|
|
|
$LSform -> can_validate = false;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
return $LSform;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
|
|
|
* Construit un formulaire de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
|
2008-02-08 18:39:24 +01:00
|
|
|
* et de chaque attribut.
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
|
|
|
|
* @param[in] $config Configuration spécifique pour le formulaire
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval LSform Le formulaire crée
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getView() {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: loadLSclass('LSform');
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> view = new LSform($this,'view');
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
$this -> attrs[$attr_name] -> addToView($this -> view);
|
|
|
|
}
|
|
|
|
$this -> view -> can_validate = false;
|
|
|
|
return $this -> view;
|
2020-04-29 15:54:21 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
|
|
|
* Rafraichis le formulaire de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode recharge les données d'un formulaire LSform.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true sile formulaire a été rafraichis, false sinon
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function refreshForm($idForm) {
|
2007-11-15 19:07:24 +01:00
|
|
|
$LSform = $this -> forms[$idForm][0];
|
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
|
|
|
if(!$this -> attrs[$attr_name] -> refreshForm($LSform,$idForm)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2015-07-30 16:37:42 +02:00
|
|
|
* Update LDAP object data from one form specify by it's ID.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2015-07-30 16:37:42 +02:00
|
|
|
* This method just valid form ID, extract form data and call
|
|
|
|
* _updateData() private method.
|
|
|
|
*
|
|
|
|
* @param[in] $idForm Form ID
|
|
|
|
* @param[in] $justValidate Boolean to enable just validation mode
|
|
|
|
*
|
|
|
|
* @see _updateData()
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2015-07-30 16:37:42 +02:00
|
|
|
* @retval boolean true if object data was updated, false otherwise
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2015-07-30 16:37:42 +02:00
|
|
|
public function updateData($idForm=NULL,$justValidate=False) {
|
2007-03-29 18:10:14 +02:00
|
|
|
if($idForm!=NULL) {
|
|
|
|
if(isset($this -> forms[$idForm]))
|
|
|
|
$LSform = $this -> forms[$idForm][0];
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_02',$this -> getType());
|
2007-03-29 18:10:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(count($this -> forms) > 0) {
|
|
|
|
reset($this -> forms);
|
|
|
|
$idForm = key($this -> forms);
|
|
|
|
$LSform = current($this -> forms);
|
|
|
|
$config = $LSform[1];
|
|
|
|
$LSform = $LSform[0];
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_03',$this -> getType());
|
2008-02-12 18:59:44 +01:00
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
$new_data = $LSform -> exportValues();
|
2015-07-30 16:37:42 +02:00
|
|
|
return $this -> _updateData($new_data,$idForm,$justValidate);
|
2010-03-15 16:42:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-30 16:37:42 +02:00
|
|
|
* Update LDAP object data from one form specify by it's ID.
|
|
|
|
*
|
|
|
|
* This method implement the continuation and the end of the object data
|
|
|
|
* udpate.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2015-07-30 16:37:42 +02:00
|
|
|
* @param[in] $new_data Array of object data
|
|
|
|
* @param[in] $idForm Form ID
|
|
|
|
* @param[in] $justValidate Boolean to enable just validation mode
|
2010-03-15 16:42:57 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2015-07-30 16:37:42 +02:00
|
|
|
* @retval boolean true if object data was updated, false otherwise
|
2010-03-15 16:42:57 +01:00
|
|
|
*
|
2015-07-30 16:37:42 +02:00
|
|
|
* @see updateData()
|
2010-03-15 16:42:57 +01:00
|
|
|
* @see validateAttrsData()
|
|
|
|
* @see submitChange()
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2015-07-30 16:37:42 +02:00
|
|
|
private function _updateData($new_data,$idForm=null,$justValidate=False) {
|
2008-07-18 16:02:46 +02:00
|
|
|
if(!is_array($new_data)) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
|
|
|
if(isset($this -> attrs[$attr_name])) {
|
|
|
|
$this -> attrs[$attr_name] -> setUpdateData($attr_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($this -> validateAttrsData($idForm)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug("les données sont validées");
|
2015-07-30 16:37:42 +02:00
|
|
|
if ($justValidate) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug('Just validate mode');
|
2015-07-30 16:37:42 +02:00
|
|
|
return True;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
if (!$this -> fireEvent('before_modify')) {
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// $this -> attrs[ {inNewData} ] -> fireEvent('before_modify')
|
2008-10-14 13:58:00 +02:00
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
2012-03-22 19:51:27 +01:00
|
|
|
if ($this -> attrs[$attr_name] -> isUpdate() && !$this -> attrs[$attr_name] -> fireEvent('before_modify')) {
|
2009-01-21 18:08:09 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-10-14 13:58:00 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
if ($this -> submitChange($idForm)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug('Les modifications sont submitées');
|
2012-03-22 19:51:27 +01:00
|
|
|
// Event After Modify
|
2014-04-08 12:14:22 +02:00
|
|
|
$this -> fireEvent('after_modify');
|
2012-03-22 19:51:27 +01:00
|
|
|
|
|
|
|
// $this -> attrs[*] => After Modify
|
|
|
|
foreach($new_data as $attr_name => $attr_val) {
|
|
|
|
if ($this -> attrs[$attr_name] -> isUpdate()) {
|
|
|
|
$this -> attrs[$attr_name] -> fireEvent('after_modify');
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
$this -> reloadData();
|
|
|
|
$this -> refreshForm($idForm);
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-22 19:51:27 +01:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Valide les données retournées par un formulaire
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @param[in] $idForm Identifiant du formulaire d'origine
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si les données sont valides, false sinon
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function validateAttrsData($idForm=null) {
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = true;
|
2010-03-16 14:54:39 +01:00
|
|
|
if ($idForm) {
|
|
|
|
$LSform=$this -> forms[$idForm][0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$LSform=false;
|
|
|
|
}
|
2019-02-26 17:47:29 +01:00
|
|
|
foreach($this -> attrs as $attr_name => $attr) {
|
2008-07-31 11:16:25 +02:00
|
|
|
$attr_values = $attr -> getValue();
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$attr -> isValidate()) {
|
|
|
|
if($attr -> isUpdate()) {
|
|
|
|
if (!$this -> validateAttrData($LSform, $attr)) {
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
else if( (empty($attr_values)) && ($attr -> isRequired()) ) {
|
2008-02-08 18:39:24 +01:00
|
|
|
if ( $attr -> canBeGenerated()) {
|
|
|
|
if ($attr -> generateValue()) {
|
|
|
|
if (!$this -> validateAttrData($LSform, $attr)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_08',$attr -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_07',$attr -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-02-28 15:24:37 +01:00
|
|
|
// Don't blame on non-create form for attributes not-present in form (or freezed)
|
2020-05-09 11:37:09 +02:00
|
|
|
if ($LSform && $idForm != 'create' && (!$LSform -> hasElement($attr_name) || $LSform -> isFreeze($attr_name)))
|
2019-02-28 15:24:37 +01:00
|
|
|
continue;
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_06',$attr -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-10 16:32:56 +01:00
|
|
|
return $retval;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Valide les données d'un attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @param[in] $LSForm Formulaire d'origine
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] &$attr Attribut à valider
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si les données sont valides, false sinon
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function validateAttrData(&$LSform,&$attr) {
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = true;
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$vconfig=$attr -> getValidateConfig();
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$data=$attr -> getUpdateData();
|
|
|
|
if(!is_array($data)) {
|
|
|
|
$data=array($data);
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
// Validation des valeurs de l'attribut
|
2007-11-15 19:07:24 +01:00
|
|
|
if(is_array($vconfig)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach($vconfig as $test) {
|
2008-10-14 13:58:00 +02:00
|
|
|
// Définition du basedn par défaut
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!isset($test['basedn'])) {
|
2009-01-24 18:45:14 +01:00
|
|
|
$test['basedn']=LSsession :: getTopDn();
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2008-10-14 13:58:00 +02:00
|
|
|
// Définition du message d'erreur
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!empty($test['msg'])) {
|
2010-08-03 19:23:20 +02:00
|
|
|
$msg_error=getFData(__($test['msg']),$this,'getValue');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-02-12 13:38:56 +01:00
|
|
|
$msg_error=getFData(_("The attribute %{attr} is not valid."),$attr -> getLabel());
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
foreach($data as $val) {
|
|
|
|
// validation par check LDAP
|
|
|
|
if((isset($test['filter'])||isset($test['basedn']))&&(isset($test['result']))) {
|
2017-03-23 15:15:31 +01:00
|
|
|
$sparams=array('onlyAccessible' => False);
|
|
|
|
if (isset($test['scope']))
|
|
|
|
$sparams['scope'] = $test['scope'];
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> other_values['val']=$val;
|
2014-11-28 16:19:01 +01:00
|
|
|
// Filter from test configuration
|
|
|
|
if (isset($test['filter']) && !empty($test['filter'])) {
|
|
|
|
$sfilter_user=getFData($test['filter'],$this,'getValue');
|
|
|
|
if ($sfilter_user[0]!='(') $sfilter_user="(".$sfilter_user.")";
|
|
|
|
$sfilter_user=Net_LDAP2_Filter::parse($sfilter_user);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sfilter_user=NULL;
|
|
|
|
}
|
|
|
|
if(isset($test['object_type']) && LSsession :: loadLSobject($test['object_type']) ) {
|
2019-03-12 12:19:44 +01:00
|
|
|
$sfilter=self :: _getObjectFilter($test['object_type']);
|
2014-11-28 16:19:01 +01:00
|
|
|
|
|
|
|
if ($sfilter_user) {
|
|
|
|
$sfilter=LSldap::combineFilters('and',array($sfilter_user,$sfilter));
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sfilter=$sfilter_user;
|
|
|
|
}
|
|
|
|
$sbasedn=(isset($test['basedn']))?getFData($test['basedn'],$this,'getValue'):NULL;
|
2015-08-10 10:16:32 +02:00
|
|
|
if (isset($test['except_current_object']) && (bool)$test['except_current_object'] && !$LSform -> idForm!='create') {
|
|
|
|
$sret=LSldap :: search ($sfilter,$sbasedn,$sparams);
|
|
|
|
$dn=$this->getDn();
|
|
|
|
$ret=0;
|
|
|
|
foreach($sret as $obj) {
|
|
|
|
if ($obj['dn']!=$dn)
|
|
|
|
$ret++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ret=LSldap :: getNumberResult ($sfilter,$sbasedn,$sparams);
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
if($test['result']==0) {
|
|
|
|
if($ret!=0) {
|
2010-03-16 14:54:39 +01:00
|
|
|
if ($LSform) $LSform -> setElementError($attr,$msg_error);
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-07-29 15:45:02 +02:00
|
|
|
if($ret<0) {
|
2010-03-16 14:54:39 +01:00
|
|
|
if ($LSform) $LSform -> setElementError($attr,$msg_error);
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Validation par fonction externe
|
|
|
|
else if(isset($test['function'])) {
|
|
|
|
if (function_exists($test['function'])) {
|
2017-04-28 10:22:01 +02:00
|
|
|
if(!call_user_func_array($test['function'],array(&$this))) {
|
2010-03-16 14:54:39 +01:00
|
|
|
if ($LSform) $LSform -> setElementError($attr,$msg_error);
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_04',array('attr' => $attr->name,'obj' => $this->getType(),'func' => $test['function']));
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_05',array('attr' => $attr->name,'obj' => $this->getType()));
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-14 13:58:00 +02:00
|
|
|
// Génération des valeurs des attributs dépendants
|
2008-02-08 18:39:24 +01:00
|
|
|
$dependsAttrs=$attr->getDependsAttrs();
|
|
|
|
if (!empty($dependsAttrs)) {
|
|
|
|
foreach($dependsAttrs as $dependAttr) {
|
|
|
|
if(!isset($this -> attrs[$dependAttr])){
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_14',array('attr_depend' => $dependAttr, 'attr' => $attr -> getLabel()));
|
2008-02-08 18:39:24 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if($this -> attrs[$dependAttr] -> canBeGenerated()) {
|
|
|
|
if (!$this -> attrs[$dependAttr] -> generateValue()) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_07',$this -> attrs[$dependAttr] -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2011-09-22 11:35:27 +02:00
|
|
|
elseif (!$this -> validateAttrData($LSform,$this -> attrs[$dependAttr])) {
|
|
|
|
LSerror :: addErrorCode('LSattribute_08',$this -> attrs[$dependAttr] -> getLabel());
|
|
|
|
$retval = false;
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSattribute_06',$this -> attrs[$dependAttr] -> getLabel());
|
2008-11-10 16:32:56 +01:00
|
|
|
$retval = false;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$attr -> validate();
|
2007-11-15 19:07:24 +01:00
|
|
|
unset($this -> other_values['val']);
|
2008-11-10 16:32:56 +01:00
|
|
|
return $retval;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Met à jour les données modifiés dans l'annuaire
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
|
|
|
* @param[in] $idForm Identifiant du formulaire d'origine
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si la mise à jour a réussi, false sinon
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function submitChange($idForm) {
|
2007-11-15 19:07:24 +01:00
|
|
|
$submitData=array();
|
2008-08-06 19:04:03 +02:00
|
|
|
$new = $this -> isNew();
|
2007-03-29 18:10:14 +02:00
|
|
|
foreach($this -> attrs as $attr) {
|
|
|
|
if(($attr -> isUpdate())&&($attr -> isValidate())) {
|
2019-03-11 22:21:25 +01:00
|
|
|
if(($attr -> name == $this -> getConfig('rdn')) && (!$new)) {
|
2008-08-06 19:04:03 +02:00
|
|
|
$new = true;
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug('Rename');
|
2009-03-09 13:42:03 +01:00
|
|
|
if (!$this -> fireEvent('before_rename')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_16');
|
2008-07-29 15:45:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$oldDn = $this -> getDn();
|
|
|
|
$this -> dn = false;
|
|
|
|
$newDn = $this -> getDn();
|
|
|
|
if ($newDn) {
|
2009-01-25 15:37:03 +01:00
|
|
|
if (!LSldap :: move($oldDn,$newDn)) {
|
2008-07-29 15:45:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-10-09 11:50:38 +02:00
|
|
|
$this -> dn = $newDn;
|
2009-03-09 13:42:03 +01:00
|
|
|
$this -> oldDn = $oldDn;
|
2019-02-26 18:48:45 +01:00
|
|
|
|
|
|
|
// PHP Net_LDAP2 does not remove old RDN value : replace RDN value
|
|
|
|
$submitData[$attr -> name] = $attr -> getUpdateData();
|
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
if (!$this -> fireEvent('after_rename')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_17');
|
2008-07-29 15:45:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$submitData[$attr -> name] = $attr -> getUpdateData();
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!empty($submitData)) {
|
|
|
|
$dn=$this -> getDn();
|
|
|
|
if($dn) {
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> dn=$dn;
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug($submitData);
|
2009-03-09 17:33:43 +01:00
|
|
|
if ($new) {
|
|
|
|
if (!$this -> fireEvent('before_create')) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_20');
|
|
|
|
return;
|
|
|
|
}
|
2009-03-10 10:22:41 +01:00
|
|
|
foreach ($submitData as $attr_name => $attr) {
|
|
|
|
if (!$this -> attrs[$attr_name] -> fireEvent('before_create')) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_20');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-03-09 17:33:43 +01:00
|
|
|
}
|
2009-01-25 15:37:03 +01:00
|
|
|
if (!LSldap :: update($this -> getType(),$dn, $submitData)) {
|
2008-08-06 19:04:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($new) {
|
2009-03-09 13:42:03 +01:00
|
|
|
if (!$this -> fireEvent('after_create')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_21');
|
2008-08-06 19:04:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-03-10 10:22:41 +01:00
|
|
|
foreach ($submitData as $attr_name => $attr) {
|
|
|
|
if (!$this -> attrs[$attr_name] -> fireEvent('after_create')) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_21');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
return true;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_13');
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne les informations issus d'un DN
|
|
|
|
*
|
|
|
|
* @param[in] $dn Un DN.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2020-04-29 15:54:21 +02:00
|
|
|
* @retval array Tableau :
|
2008-10-14 13:58:00 +02:00
|
|
|
* - [0] : le premier paramètre
|
|
|
|
* - [1] : les paramètres suivants
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public static function getDnInfos($dn) {
|
2007-03-29 18:10:14 +02:00
|
|
|
$infos=ldap_explode_dn($dn,0);
|
|
|
|
if(!$infos)
|
|
|
|
return;
|
|
|
|
$first=true;
|
|
|
|
for($i=1;$i<$infos['count'];$i++)
|
|
|
|
if($first) {
|
|
|
|
$basedn.=$infos[$i];
|
|
|
|
$first=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$basedn.=','.$infos[$i];
|
|
|
|
return array($infos[0],$basedn);
|
|
|
|
}
|
2019-03-12 12:19:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le filtre correpondants aux objetcClass de l'objet courant
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval Net_LDAP2_Filter le filtre ldap correspondant au type de l'objet
|
|
|
|
*/
|
|
|
|
public function getObjectFilter() {
|
2020-05-14 11:06:09 +02:00
|
|
|
return self :: _getObjectFilter($this -> type_name);
|
2019-03-12 12:19:44 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne le filtre correpondants aux objetcClass de l'objet
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2014-11-28 16:19:01 +01:00
|
|
|
* @retval Net_LDAP2_Filter le filtre ldap correspondant au type de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 12:19:44 +01:00
|
|
|
public static function _getObjectFilter($type) {
|
2009-10-30 01:03:17 +01:00
|
|
|
$oc=LSconfig::get("LSobjects.$type.objectclass");
|
|
|
|
if(!is_array($oc)) return;
|
|
|
|
$filters=array();
|
|
|
|
foreach ($oc as $class) {
|
|
|
|
$filters[]=Net_LDAP2_Filter::create('objectClass','equals',$class);
|
2008-12-05 17:15:10 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
$filter=LSconfig::get("LSobjects.$type.filter");
|
|
|
|
if ($filter) {
|
2014-11-28 16:19:01 +01:00
|
|
|
$filters[]=Net_LDAP2_Filter::parse($filter);
|
2008-12-05 17:15:10 +01:00
|
|
|
}
|
2009-10-30 01:03:17 +01:00
|
|
|
|
2014-11-28 16:19:01 +01:00
|
|
|
$filter = LSldap::combineFilters('and',$filters);
|
2009-10-30 01:03:17 +01:00
|
|
|
if ($filter)
|
|
|
|
return $filter;
|
|
|
|
LSerror :: addErrorCode('LSldapObject_30',$type);
|
|
|
|
return;
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-01-25 18:43:30 +01:00
|
|
|
/**
|
|
|
|
* Retourne le filtre correpondants au pattern passé
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-01-25 18:43:30 +01:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-01-25 18:43:30 +01:00
|
|
|
* @param[in] $pattern string Le mot clé recherché
|
|
|
|
* @param[in] $approx booléen Booléen activant ou non la recherche approximative
|
|
|
|
*
|
|
|
|
* @retval string le filtre ldap correspondant
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getPatternFilter($pattern=null,$approx=null) {
|
2018-06-09 00:08:47 +02:00
|
|
|
if ($pattern) {
|
|
|
|
$search = new LSsearch($this -> type_name, 'LSldapObject', array('approx' => (bool)$approx));
|
|
|
|
$filter = $search -> getFilterFromPattern($pattern);
|
|
|
|
if ($filter instanceof Net_LDAP2_Filter) {
|
|
|
|
return $filter -> asString();
|
2009-01-25 18:43:30 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-09 00:08:47 +02:00
|
|
|
return NULL;
|
2009-01-25 18:43:30 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourne une liste d'objet du même type.
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Effectue une recherche en fonction des paramètres passé et retourne un
|
2007-03-29 18:10:14 +02:00
|
|
|
* tableau d'objet correspond au resultat de la recherche.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $filter array (ou string) Filtre de recherche Ldap / Tableau de filtres de recherche
|
|
|
|
* @param[in] $basedn string DN de base pour la recherche
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @retval array Tableau d'objets correspondant au resultat de la recherche
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function listObjects($filter=NULL,$basedn=NULL,$params=array()) {
|
2009-10-30 01:03:17 +01:00
|
|
|
if (!LSsession :: loadLSclass('LSsearch')) {
|
|
|
|
LSerror::addErrorCode('LSsession_05','LSsearch');
|
|
|
|
return;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
$sparams = array(
|
|
|
|
'basedn' => $basedn,
|
2013-11-19 11:44:16 +01:00
|
|
|
'filter' => $filter
|
2009-10-30 01:03:17 +01:00
|
|
|
);
|
|
|
|
|
2020-04-29 15:54:21 +02:00
|
|
|
if (is_array($params)) {
|
2009-10-30 01:03:17 +01:00
|
|
|
$sparams=array_merge($sparams,$params);
|
|
|
|
}
|
|
|
|
$LSsearch = new LSsearch($this -> type_name,'LSldapObjet::listObjects',$sparams,true);
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
$LSsearch -> run();
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
return $LSsearch -> listObjects();
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-11-09 01:57:50 +01:00
|
|
|
/**
|
|
|
|
* Retourne une liste d'objet du même type et retourne leur noms
|
|
|
|
*
|
|
|
|
* Effectue une recherche en fonction des paramètres passé et retourne un
|
|
|
|
* tableau (dn => nom) correspondant au resultat de la recherche.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $filter string Filtre de recherche Ldap
|
|
|
|
* @param[in] $basedn string DN de base pour la recherche
|
|
|
|
* @param[in] $params array Paramètres de recherche au format Net_LDAP2::search()
|
|
|
|
* @param[in] $displayFormat string Format d'affichage du nom des objets
|
|
|
|
*
|
|
|
|
* @retval array Tableau dn => name correspondant au resultat de la recherche
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function listObjectsName($filter=NULL,$sbasedn=NULL,$sparams=array(),$displayFormat=false,$cache=true) {
|
2009-10-30 01:03:17 +01:00
|
|
|
if (!LSsession :: loadLSclass('LSsearch')) {
|
|
|
|
LSerror::addErrorCode('LSsession_05','LSsearch');
|
|
|
|
return;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-11-09 01:57:50 +01:00
|
|
|
if (!$displayFormat) {
|
2009-01-07 20:24:14 +01:00
|
|
|
$displayFormat = $this -> getDisplayNameFormat();
|
2008-11-09 01:57:50 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
$params = array(
|
|
|
|
'displayFormat' => $displayFormat,
|
|
|
|
'basedn' => $sbasedn,
|
|
|
|
'filter' => $filter
|
|
|
|
);
|
|
|
|
|
2020-04-29 15:54:21 +02:00
|
|
|
if (is_array($sparams)) {
|
2009-10-30 01:03:17 +01:00
|
|
|
$params=array_merge($sparams,$params);
|
2008-11-09 01:57:50 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
$LSsearch = new LSsearch($this -> type_name,'LSldapObject::listObjectsName',$params,true);
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
$LSsearch -> run($cache);
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
return $LSsearch -> listObjectsName();
|
2008-11-09 01:57:50 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
|
|
|
|
2008-06-19 16:07:57 +02:00
|
|
|
/**
|
2009-03-09 14:14:37 +01:00
|
|
|
* Recherche un objet à partir de la valeur exact de son RDN ou d'un filtre de
|
|
|
|
* recherche LDAP sous la forme d'un LSformat qui sera construit avec la valeur
|
|
|
|
* de $name.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 14:14:37 +01:00
|
|
|
* @param[in] $name string Valeur de son RDN ou de la valeur pour composer le filtre
|
2008-06-19 16:07:57 +02:00
|
|
|
* @param[in] $basedn string Le DN de base de la recherche
|
2009-03-09 14:14:37 +01:00
|
|
|
* @param[in] $filter string Le filtre de recherche de l'objet
|
2009-10-30 01:03:17 +01:00
|
|
|
* @param[in] $params array Tableau de paramètres
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @retval array Tableau d'objets correspondant au resultat de la recherche
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function searchObject($name,$basedn=NULL,$filter=NULL,$params=NULL) {
|
2009-03-09 14:14:37 +01:00
|
|
|
if (!$filter) {
|
2019-03-11 22:21:25 +01:00
|
|
|
$filter = '('.$this -> getConfig('rdn').'='.$name.')';
|
2009-03-09 14:14:37 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$filter = getFData($filter,$name);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
return $this -> listObjects($filter,$basedn,$params);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2007-03-29 18:10:14 +02:00
|
|
|
/**
|
|
|
|
* Retourne une valeur de l'objet
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourne une valeur en fonction du paramètre. Si la valeur est inconnue, la valeur retourné est ' '.
|
2007-03-29 18:10:14 +02:00
|
|
|
* tableau d'objet correspond au resultat de la recherche.
|
|
|
|
*
|
|
|
|
* Valeurs possibles :
|
|
|
|
* - 'dn' ou '%{dn} : DN de l'objet
|
|
|
|
* - [nom d'un attribut] : valeur de l'attribut
|
|
|
|
* - [clef de $this -> other_values] : valeur de $this -> other_values
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $val string Le nom de la valeur demandée
|
2007-03-29 18:10:14 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval mixed la valeur demandé ou ' ' si celle-ci est inconnue.
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getValue($val) {
|
2007-03-29 18:10:14 +02:00
|
|
|
if(($val=='dn')||($val=='%{dn}')) {
|
|
|
|
return $this -> dn;
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
else if(($val=='rdn')||($val=='%{rdn}')) {
|
2015-02-13 13:55:28 +01:00
|
|
|
return $this -> rdn;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-07-18 17:20:52 +02:00
|
|
|
else if(($val=='subDn')||($val=='%{subDn}')) {
|
2009-10-30 01:03:17 +01:00
|
|
|
return $this -> subDnValue;
|
2008-07-18 17:20:52 +02:00
|
|
|
}
|
|
|
|
else if(($val=='subDnName')||($val=='%{subDnName}')) {
|
2009-10-30 01:03:17 +01:00
|
|
|
return $this -> subDnName;
|
2008-07-18 17:20:52 +02:00
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
else if(isset($this -> attrs[$val])){
|
|
|
|
if (method_exists($this -> attrs[$val],'getValue'))
|
|
|
|
return $this -> attrs[$val] -> getValue();
|
|
|
|
else
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
else if(isset($this -> other_values[$val])){
|
|
|
|
return $this -> other_values[$val];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2011-01-20 12:13:46 +01:00
|
|
|
/**
|
|
|
|
* Retourne une valeur d'affichage de l'objet
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $val string Le nom de la valeur demandee
|
|
|
|
*
|
|
|
|
* @retval mixed la valeur demandee ou ' ' si celle-ci est inconnue.
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getDisplayValue($val) {
|
2011-01-20 12:13:46 +01:00
|
|
|
if(isset($this -> attrs[$val])){
|
|
|
|
if (method_exists($this -> attrs[$val],'getDisplayValue'))
|
|
|
|
return $this -> attrs[$val] -> getDisplayValue();
|
|
|
|
else
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $this -> getValue($val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 15:33:32 +01:00
|
|
|
/**
|
|
|
|
* Ajoute une valeur dans le tableau $this -> other_values
|
|
|
|
*
|
|
|
|
* @param[in] $name string Le nom de la valeur
|
|
|
|
* @param[in] $value mixed La valeur
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function registerOtherValue($name,$value) {
|
2010-11-18 15:33:32 +01:00
|
|
|
$this -> other_values[$name]=$value;
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourn un tableau pour un select d'un objet du même type
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-02-08 18:39:24 +01:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 15:48:12 +02:00
|
|
|
* @retval array('dn' => 'display')
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getSelectArray($pattern=NULL,$topDn=NULL,$displayFormat=NULL,$approx=false,$cache=true,$filter=NULL,$sparams=array()) {
|
2017-03-23 15:15:31 +01:00
|
|
|
$sparams['pattern']=$pattern;
|
|
|
|
return $this -> listObjectsName($filter,$topDn,$sparams,$displayFormat,$cache);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
|
|
|
* Retourne le DN de l'objet
|
|
|
|
*
|
2020-04-29 15:54:21 +02:00
|
|
|
* Cette methode retourne le DN de l'objet. Si celui-ci n'existe pas, il le construit à partir de la
|
2007-11-15 19:07:24 +01:00
|
|
|
* configuration de l'objet et la valeur de son attribut rdn.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string Le DN de l'objet
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getDn() {
|
2007-11-15 19:07:24 +01:00
|
|
|
if($this -> dn) {
|
|
|
|
return $this -> dn;
|
|
|
|
}
|
|
|
|
else {
|
2018-10-01 12:57:26 +02:00
|
|
|
$container_dn=$this -> getContainerDn();
|
|
|
|
if ($container_dn) {
|
2019-03-11 22:21:25 +01:00
|
|
|
$rdn_attr = $this -> getConfig('rdn');
|
|
|
|
if( $rdn_attr && isset($this -> attrs[$rdn_attr]) ) {
|
2018-10-01 12:57:26 +02:00
|
|
|
$rdn_val=$this -> attrs[$rdn_attr] -> getUpdateData();
|
|
|
|
if (!empty($rdn_val)) {
|
|
|
|
return $rdn_attr.'='.$rdn_val[0].','.$container_dn;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-11 22:21:25 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_12', $rdn_attr);
|
2018-10-01 12:57:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-01 12:57:26 +02:00
|
|
|
LSerror :: addErrorCode('LSldapObject_11',$this -> getType());
|
2007-11-15 19:07:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-10-01 12:57:26 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le container DN de l'objet
|
|
|
|
*
|
|
|
|
* Cette methode retourne le container DN de l'objet.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval string Le container DN de l'objet
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getContainerDn() {
|
2018-10-01 12:57:26 +02:00
|
|
|
$topDn = LSsession :: getTopDn();
|
2019-03-11 22:21:25 +01:00
|
|
|
$generate_container_dn = $this -> getConfig('generate_container_dn');
|
|
|
|
$container_dn = $this -> getConfig('container_dn');
|
|
|
|
if ($generate_container_dn) {
|
|
|
|
if (is_callable($generate_container_dn)) {
|
2018-10-01 12:57:26 +02:00
|
|
|
try {
|
2019-03-11 22:21:25 +01:00
|
|
|
$container_dn = call_user_func_array($generate_container_dn, array(&$this));
|
2018-10-01 12:57:26 +02:00
|
|
|
return $container_dn.','.$topDn;
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_34',$e);
|
|
|
|
}
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
else {
|
2019-03-11 22:21:25 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_33', $generate_container_dn);
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
else if ($container_dn && $topDn) {
|
|
|
|
return $container_dn.','.$topDn;
|
2018-10-01 12:57:26 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_11',$this -> getType());
|
|
|
|
}
|
|
|
|
LSerror :: addErrorCode('LSldapObject_32');
|
|
|
|
return;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
/**
|
|
|
|
* Retourne le type de l'objet
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-02-08 18:39:24 +01:00
|
|
|
* @retval string Le type de l'objet ($this -> type_name)
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getType() {
|
2008-02-08 18:39:24 +01:00
|
|
|
return $this -> type_name;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Retourne qui est l'utilisateur par rapport à cet object
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval string 'admin'/'self'/'user' pour Admin , l'utilisateur lui même ou un simple utilisateur
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function whoami() {
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> _whoami)
|
2009-01-24 18:45:14 +01:00
|
|
|
$this -> _whoami = LSsession :: whoami($this -> dn);
|
2008-02-08 18:39:24 +01:00
|
|
|
return $this -> _whoami;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2020-05-18 20:08:03 +02:00
|
|
|
* Retreive object type translated label
|
|
|
|
*
|
|
|
|
* @param[in] $type string|null The object type (optional, default: called class name)
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2020-05-18 20:08:03 +02:00
|
|
|
* @retval string The translated object type label
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2020-05-18 20:08:03 +02:00
|
|
|
public static function getLabel($type=null) {
|
|
|
|
if (is_null($type))
|
|
|
|
$type = get_called_class();
|
|
|
|
self :: log_debug("getLabel($type): LSobjects.$type.label");
|
|
|
|
$label = LSconfig::get("LSobjects.$type.label");
|
|
|
|
if (!$label) return;
|
|
|
|
return __($label);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
|
|
|
* Supprime l'objet dans l'annuaire
|
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean True si l'objet à été supprimé, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function remove() {
|
2009-03-09 13:42:03 +01:00
|
|
|
if ($this -> fireEvent('before_delete')) {
|
2009-01-25 15:37:03 +01:00
|
|
|
if (LSldap :: remove($this -> getDn())) {
|
2009-03-09 13:42:03 +01:00
|
|
|
if ($this -> fireEvent('after_delete')) {
|
2008-08-06 19:04:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_19');
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSldapObject_18');
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
return;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-06-19 16:07:57 +02:00
|
|
|
/**
|
|
|
|
* L'objet est-il nouveau
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-06-19 16:07:57 +02:00
|
|
|
* @retval boolean True si l'objet est nouveau, false sinon
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isNew() {
|
2008-06-19 16:07:57 +02:00
|
|
|
return (!$this -> dn);
|
|
|
|
}
|
2008-06-21 18:16:15 +02:00
|
|
|
|
|
|
|
/**
|
2020-04-29 15:54:21 +02:00
|
|
|
* Retourne la valeur (DN) du subDn de l'objet
|
|
|
|
*
|
2008-11-09 01:57:50 +01:00
|
|
|
* @parram[in] $dn string Un DN
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-06-21 18:16:15 +02:00
|
|
|
* @return string La valeur du subDn de l'object
|
|
|
|
*/
|
2009-10-30 01:03:17 +01:00
|
|
|
public static function getSubDnValue($dn) {
|
2008-06-21 18:16:15 +02:00
|
|
|
$subDn_value='';
|
2009-01-24 18:45:14 +01:00
|
|
|
$subDnLdapServer = LSsession :: getSortSubDnLdapServer();
|
2008-06-21 18:16:15 +02:00
|
|
|
foreach ($subDnLdapServer as $subDn => $subDn_name) {
|
|
|
|
if (isCompatibleDNs($subDn,$dn)&&($subDn!=$dn)) {
|
|
|
|
$subDn_value=$subDn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $subDn_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-29 15:54:21 +02:00
|
|
|
* Retourne la nom du subDn de l'objet
|
|
|
|
*
|
2008-11-09 01:57:50 +01:00
|
|
|
* @parram[in] $dn string Un DN
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-06-21 18:16:15 +02:00
|
|
|
* @return string Le nom du subDn de l'object
|
|
|
|
*/
|
2009-10-30 01:03:17 +01:00
|
|
|
public static function getSubDnName($dn) {
|
2009-01-24 18:45:14 +01:00
|
|
|
$subDnLdapServer = LSsession :: getSortSubDnLdapServer();
|
2009-10-30 01:03:17 +01:00
|
|
|
return $subDnLdapServer[self :: getSubDnValue($dn)];
|
2008-06-21 18:16:15 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode créant la liste des objets en relations avec l'objet courant et qui
|
2009-01-08 00:06:05 +01:00
|
|
|
* la met en cache ($this -> _LSrelationsCache)
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-07-29 15:45:02 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function updateLSrelationsCache() {
|
2009-01-08 00:06:05 +01:00
|
|
|
$this -> _LSrelationsCache=array();
|
2019-03-11 22:21:25 +01:00
|
|
|
$LSrelations = $this -> getConfig('LSrelation');
|
|
|
|
if (is_array($LSrelations) && LSsession :: loadLSclass('LSrelation')) {
|
2008-10-09 12:19:07 +02:00
|
|
|
$type = $this -> getType();
|
|
|
|
$me = new $type();
|
|
|
|
$me -> loadData($this -> getDn());
|
2019-03-11 22:21:25 +01:00
|
|
|
foreach($LSrelations as $relation_name => $relation_conf) {
|
2017-04-28 02:13:05 +02:00
|
|
|
$relation = new LSrelation($me, $relation_name);
|
|
|
|
$list = $relation -> listRelatedObjects();
|
|
|
|
if (is_array($list)) {
|
|
|
|
$this -> _LSrelationsCache[$relation_name] = array(
|
|
|
|
'list' => $list,
|
|
|
|
'keyvalue' => $relation -> getRelatedKeyValue()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug('Problème durant la mise en cache de la relation '.$relation_name);
|
2017-04-28 02:13:05 +02:00
|
|
|
return;
|
2008-07-29 15:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires avant le changement du DN de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function beforeRename() {
|
2009-03-09 13:42:03 +01:00
|
|
|
// LSrelations
|
2009-01-08 00:06:05 +01:00
|
|
|
return $this -> updateLSrelationsCache();
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires après le changement du DN de
|
2008-07-29 15:45:02 +02:00
|
|
|
* l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-07-29 15:45:02 +02:00
|
|
|
* pour les objets plus complexe.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-07-29 15:45:02 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function afterRename() {
|
2008-07-29 15:45:02 +02:00
|
|
|
$error = 0;
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// Change LSsession -> userObject Dn
|
|
|
|
if(LSsession :: getLSuserObjectDn() == $this -> oldDn) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSsession :: changeAuthUser($this);
|
2008-07-29 15:45:02 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// LSrelations
|
2009-01-08 00:06:05 +01:00
|
|
|
foreach($this -> _LSrelationsCache as $relation_name => $objInfos) {
|
2017-04-28 02:13:05 +02:00
|
|
|
$relation = new LSrelation($this, $relation_name);
|
|
|
|
if (is_array($objInfos['list'])) {
|
2008-10-09 11:50:38 +02:00
|
|
|
foreach($objInfos['list'] as $obj) {
|
2017-04-28 02:13:05 +02:00
|
|
|
if (!$relation -> renameRelationWithObject($obj, $objInfos['keyvalue'])) {
|
2008-07-29 15:45:02 +02:00
|
|
|
$error=1;
|
|
|
|
}
|
|
|
|
}
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return !$error;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires avant la suppression de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function beforeDelete() {
|
2009-01-22 16:35:37 +01:00
|
|
|
$return = $this -> updateLSrelationsCache();
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-01-22 16:35:37 +01:00
|
|
|
foreach(array_keys($this -> attrs) as $attr_name) {
|
|
|
|
if (!$this -> attrs[$attr_name] -> fireEvent('before_delete')) {
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-01-22 16:35:37 +01:00
|
|
|
return $return;
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires après la suppression de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function afterDelete() {
|
2008-08-06 19:04:03 +02:00
|
|
|
$error = 0;
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// LSrelations
|
2009-01-08 00:06:05 +01:00
|
|
|
foreach($this -> _LSrelationsCache as $relation_name => $objInfos) {
|
2017-04-28 02:13:05 +02:00
|
|
|
$relation = new LSrelation($this, $relation_name);
|
|
|
|
if (is_array($objInfos['list'])) {
|
2008-10-09 11:50:38 +02:00
|
|
|
foreach($objInfos['list'] as $obj) {
|
2017-04-28 02:13:05 +02:00
|
|
|
if (!$relation -> canEditRelationWithObject($obj)) {
|
|
|
|
LSerror :: addErrorCode('LSsession_11');
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
2017-04-28 02:13:05 +02:00
|
|
|
elseif (!$relation -> removeRelationWithObject($obj)) $error=1;
|
2008-08-06 19:04:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// Binding LSattributes
|
2009-01-22 16:35:37 +01:00
|
|
|
foreach(array_keys($this -> attrs) as $attr_name) {
|
|
|
|
if (!$this -> attrs[$attr_name] -> fireEvent('after_delete')) {
|
|
|
|
$error = true;
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
// LSsearch : Purge LSobject cache
|
|
|
|
if (LSsession :: loadLSclass('LSsearch')) {
|
|
|
|
LSsearch :: purgeCache($this -> type_name);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
return !$error;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-08-06 19:04:03 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Methode executant les actions nécéssaires après la création de
|
2008-08-06 19:04:03 +02:00
|
|
|
* l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
2008-08-06 19:04:03 +02:00
|
|
|
* pour les objets plus complexe.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
2008-08-06 19:04:03 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function afterCreate() {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug('after');
|
2008-08-06 19:04:03 +02:00
|
|
|
$error = 0;
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// container_auto_create
|
2009-01-24 18:45:14 +01:00
|
|
|
if (LSsession :: isSubDnLSobject($this -> getType())) {
|
|
|
|
if (is_array(LSsession :: $ldapServer['subDn']['LSobject'][$this -> getType()]['LSobjects'])) {
|
|
|
|
foreach(LSsession :: $ldapServer['subDn']['LSobject'][$this -> getType()]['LSobjects'] as $type) {
|
|
|
|
if (LSsession :: loadLSobject($type)) {
|
2009-03-25 18:46:48 +01:00
|
|
|
$conf_type=LSconfig :: get("LSobjects.$type");
|
|
|
|
if (isset($conf_type['container_auto_create'])&&isset($conf_type['container_dn'])) {
|
|
|
|
$dn = $conf_type['container_dn'].','.$this -> getDn();
|
|
|
|
if(!LSldap :: getNewEntry($dn,$conf_type['container_auto_create']['objectclass'],$conf_type['container_auto_create']['attrs'],true)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug("Impossible de créer l'entrée fille : ".print_r(
|
2008-08-06 19:04:03 +02:00
|
|
|
array(
|
|
|
|
'dn' => $dn,
|
2009-03-25 18:46:48 +01:00
|
|
|
'objectClass' => $conf_type['container_auto_create']['objectclass'],
|
|
|
|
'attrs' => $conf_type['container_auto_create']['attrs']
|
2008-08-06 19:04:03 +02:00
|
|
|
)
|
|
|
|
,true));
|
|
|
|
$error=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$error=1;
|
|
|
|
}
|
2008-07-29 15:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
// LSsearch : Purge LSobject cache
|
|
|
|
if (LSsession :: loadLSclass('LSsearch')) {
|
|
|
|
LSsearch :: purgeCache($this -> type_name);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
return !$error;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
/**
|
|
|
|
* Methode executant les actions nécéssaires après la modification de
|
|
|
|
* l'objet.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-10-30 01:03:17 +01:00
|
|
|
* Cette méthode n'est qu'un exemple et elle doit être certainement réécrite
|
|
|
|
* pour les objets plus complexe.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-10-30 01:03:17 +01:00
|
|
|
* @retval True en cas de cas ce succès, False sinon.
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
private function afterModify() {
|
2009-10-30 01:03:17 +01:00
|
|
|
$error = 0;
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
// LSsearch : Purge LSobject cache
|
|
|
|
if (LSsession :: loadLSclass('LSsearch')) {
|
|
|
|
LSsearch :: purgeCache($this -> type_name);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
return !$error;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-09 11:50:38 +02:00
|
|
|
/**
|
|
|
|
* Retourne la valeur clef d'un objet en relation
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-09 11:50:38 +02:00
|
|
|
* @param[in] $object Un object de type $objectType
|
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2017-04-28 17:04:55 +02:00
|
|
|
* @param[in] $attrValues La/les valeur(s) que doit/peut avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit une des valeurs d'un attribut
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-09 11:50:38 +02:00
|
|
|
* @retval Mixed La valeur clef d'un objet en relation
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public static function getObjectKeyValueInRelation($object,$objectType,$attrValues='dn') {
|
2010-03-16 16:01:14 +01:00
|
|
|
if (!$objectType) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSrelations_05','getObjectKeyValueInRelation');
|
2008-10-09 11:50:38 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!is_array($attrValues)) $attrValues=array($attrValues);
|
|
|
|
$keyValues=array();
|
|
|
|
foreach ($attrValues as $attrValue) {
|
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$dn=$object -> getDn();
|
|
|
|
if (!in_array($dn,$keyValues))
|
|
|
|
$keyValues[] = $dn;
|
|
|
|
}
|
|
|
|
else {
|
2017-08-18 11:59:12 +02:00
|
|
|
$values=$object -> getValue($attrValue);
|
|
|
|
if (is_array($values))
|
|
|
|
foreach ($values as $keyValue)
|
|
|
|
if (!in_array($keyValue,$keyValues))
|
|
|
|
$keyValues[]=$keyValue;
|
2017-04-28 17:04:55 +02:00
|
|
|
}
|
2008-10-09 11:50:38 +02:00
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
return $keyValues;
|
2008-10-09 11:50:38 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-08 15:24:18 +02:00
|
|
|
/**
|
2020-04-29 15:54:21 +02:00
|
|
|
* Retourne la liste des relations pour l'objet en fonction de sa présence
|
2008-10-08 15:24:18 +02:00
|
|
|
* dans un des attributs
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
|
|
|
* Retourne un tableau de d'objet (type : $objectType) correspondant à la
|
2008-10-08 15:24:18 +02:00
|
|
|
* relation entre l'objet $object et les objets de type $objectType. Cette relation
|
2020-04-29 15:54:21 +02:00
|
|
|
* est établis par la présence de la valeur de référence à l'objet dans
|
2008-10-08 19:06:36 +02:00
|
|
|
* l'attribut des objets de type $objectType.
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $object Un object de type $objectType
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit apparaitre
|
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2017-04-28 17:04:55 +02:00
|
|
|
* @param[in] $attrValues La/les valeur(s) que doit/peut avoir l'attribut :
|
2008-10-08 18:49:18 +02:00
|
|
|
* - soit le dn (par defaut)
|
2017-04-28 17:04:55 +02:00
|
|
|
* - soit une des valeurs d'un attribut
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-08 15:24:18 +02:00
|
|
|
* @retval Array of $objectType Les objets en relations
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function listObjectsInRelation($object,$attr,$objectType,$attrValues='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSrelations_05','listObjectsInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!is_array($attrValues)) $attrValues=array($attrValues);
|
|
|
|
$keyValues=self :: getObjectKeyValueInRelation($object,$objectType,$attrValues);
|
|
|
|
if (!empty($keyValues)) {
|
|
|
|
$keyValuesFilters=array();
|
|
|
|
foreach($keyValues as $keyValue) {
|
|
|
|
$keyValuesFilters[] = Net_LDAP2_Filter::create($attr,'equals',$keyValue);
|
|
|
|
}
|
|
|
|
$filter = LSldap::combineFilters('or', $keyValuesFilters);
|
2017-03-23 15:15:31 +01:00
|
|
|
return $this -> listObjects($filter,LSsession :: getRootDn(),array('scope' => 'sub','recursive' => true,'withoutCache'=>true, 'onlyAccessible' => false));
|
2008-10-08 18:49:18 +02:00
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
|
|
|
|
return array();
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajoute un objet en relation dans l'attribut $attr de $this
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $object Un objet de type $objectType à ajouter
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit être ajouté
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2009-11-11 21:00:59 +01:00
|
|
|
* @param[in] $canEditFunction Le nom de la fonction pour vérifier que la
|
|
|
|
* relation avec l'objet est éditable par le user
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si l'objet à été ajouté, False sinon
|
2020-04-29 15:54:21 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addOneObjectInRelation($object,$attr,$objectType,$attrValue='dn',$canEditFunction=NULL) {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSrelations_05','addOneObjectInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($object instanceof $objectType) {
|
2009-11-11 21:00:59 +01:00
|
|
|
if ($canEditFunction) {
|
|
|
|
if (!$this -> $canEditFunction()) {
|
|
|
|
LSerror :: addErrorCode('LSsession_11');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 02:13:05 +02:00
|
|
|
elseif (!LSsession::canEdit($this -> getType(), $this -> getDn(), $attr)) {
|
|
|
|
LSerror :: addErrorCode('LSsession_11');
|
|
|
|
return;
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
$values = $this -> attrs[$attr] -> getValue();
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($this -> attrs[$attr] -> config['multiple']) {
|
|
|
|
if (!is_array($values)) {
|
|
|
|
$updateData = array($val);
|
|
|
|
}
|
|
|
|
else if (!in_array($val,$values)) {
|
|
|
|
$values[]=$val;
|
|
|
|
$updateData = $values;
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
2008-10-08 18:49:18 +02:00
|
|
|
else {
|
|
|
|
if (($values[0]!=$val)&&($values!=$val)) {
|
|
|
|
$updateData = array($val);
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
if (isset($updateData)) {
|
2010-03-15 17:31:05 +01:00
|
|
|
return $this -> _updateData(array($attr => $updateData));
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-08 15:24:18 +02:00
|
|
|
/**
|
|
|
|
* Supprime un objet en relation dans l'attribut $attr de $this
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $object Un objet de type $objectType à supprimer
|
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit être supprimé
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2009-11-11 21:00:59 +01:00
|
|
|
* @param[in] $canEditFunction Le nom de la fonction pour vérifier que la
|
|
|
|
* relation avec l'objet est éditable par le user
|
2017-04-28 17:04:55 +02:00
|
|
|
* @param[in] $attrValues L'ensembe des valeurs que peut avoir l'attribut avant mise à jour :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit une des valeurs d'un attribut
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si l'objet à été supprimé, False sinon
|
2020-04-29 15:54:21 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function deleteOneObjectInRelation($object,$attr,$objectType,$attrValue='dn',$canEditFunction=NULL,$attrValues=null) {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSrelations_05','deleteOneObjectInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($object instanceof $objectType) {
|
2009-11-11 21:00:59 +01:00
|
|
|
if ($canEditFunction) {
|
|
|
|
if (!$this -> $canEditFunction()) {
|
|
|
|
LSerror :: addErrorCode('LSsession_11');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 02:13:05 +02:00
|
|
|
elseif (!LSsession::canEdit($this -> getType(), $this -> getDn(), $attr)) {
|
|
|
|
LSerror :: addErrorCode('LSsession_11');
|
|
|
|
return;
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!is_array($attrValues)) $attrValues=array($attrValue);
|
|
|
|
$keyValues=self :: getObjectKeyValueInRelation($object,$objectType,$attrValues);
|
2008-10-08 15:24:18 +02:00
|
|
|
$values = $this -> attrs[$attr] -> getValue();
|
|
|
|
if ((!is_array($values)) && (!empty($values))) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
if (is_array($values)) {
|
|
|
|
$updateData=array();
|
|
|
|
foreach($values as $value) {
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!in_array($value,$keyValues)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
$updateData[]=$value;
|
|
|
|
}
|
|
|
|
}
|
2010-03-15 17:31:05 +01:00
|
|
|
return $this -> _updateData(array($attr => $updateData));
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-08 15:24:18 +02:00
|
|
|
/**
|
|
|
|
* Renome un objet en relation dans l'attribut $attr de $this
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $object Un objet de type $objectType à renomer
|
2017-04-28 17:04:55 +02:00
|
|
|
* @param[in] $oldValues array|string Le(s) ancienne(s) valeur(s possible(s)
|
|
|
|
* faisant référence à l'objet
|
2008-10-14 13:58:00 +02:00
|
|
|
* @param[in] $attr L'attribut dans lequel l'objet doit être supprimé
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean True en cas de succès, False sinon
|
2008-10-08 15:24:18 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function renameOneObjectInRelation($object,$oldValues,$attr,$objectType,$attrValue='dn') {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSrelations_05','renameOneObjectInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!is_array($oldValues)) $oldValues=array($oldValues);
|
2008-10-08 15:24:18 +02:00
|
|
|
if ($object instanceof $objectType) {
|
|
|
|
if ($this -> attrs[$attr] instanceof LSattribute) {
|
|
|
|
$values = $this -> attrs[$attr] -> getValue();
|
|
|
|
if ((!is_array($values)) && (!empty($values))) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
if (is_array($values)) {
|
|
|
|
$updateData=array();
|
|
|
|
foreach($values as $value) {
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!in_array($value,$oldValues)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
$updateData[] = $value;
|
|
|
|
}
|
|
|
|
else {
|
2008-10-08 18:49:18 +02:00
|
|
|
if ($attrValue=='dn') {
|
|
|
|
$val = $object -> getDn();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$val = $object -> getValue($attrValue);
|
|
|
|
$val = $val[0];
|
|
|
|
}
|
|
|
|
$updateData[] = $val;
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-15 17:31:05 +01:00
|
|
|
return $this -> _updateData(array($attr => $updateData));
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-08 15:24:18 +02:00
|
|
|
/**
|
2008-10-14 13:58:00 +02:00
|
|
|
* Met à jour les objets du meme type que $this en relation avec l'objet $object
|
2008-10-08 15:24:18 +02:00
|
|
|
* de type $objectType en modifiant la valeur de leur attribut $attr des objets
|
|
|
|
* en relation
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $object Mixed Un object (type : $this -> userObjectType) : l'utilisateur
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $listDns Array(string) Un tableau des DNs des objets en relation
|
2008-10-08 15:24:18 +02:00
|
|
|
* @param[in] $attr L'attribut dans lequel l'utilisateur doit apparaitre
|
2008-10-08 18:49:18 +02:00
|
|
|
* @param[in] $objectType Le type d'objet en relation
|
|
|
|
* @param[in] $attrValue La valeur que doit avoir l'attribut :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit la valeur [0] d'un attribut
|
2009-11-11 21:00:59 +01:00
|
|
|
* @param[in] $canEditFunction Le nom de la fonction pour vérifier que la
|
|
|
|
* relation avec l'objet est éditable par le user
|
2017-04-28 17:04:55 +02:00
|
|
|
* @param[in] $attrValues L'ensembe des valeurs que peut avoir l'attribut avant mise à jour :
|
|
|
|
* - soit le dn (par defaut)
|
|
|
|
* - soit une des valeurs d'un attribut
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-10-14 13:58:00 +02:00
|
|
|
* @retval boolean true si tout c'est bien passé, False sinon
|
2020-04-29 15:54:21 +02:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function updateObjectsInRelation($object,$listDns,$attr,$objectType,$attrValue='dn',$canEditFunction=NULL,$attrValues=null) {
|
2008-10-08 15:24:18 +02:00
|
|
|
if ((!$attr)||(!$objectType)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('LSrelations_05','updateObjectsInRelation');
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
if (!is_array($attrValues)) $attrValues=array($attrValue);
|
|
|
|
$currentDns=array();
|
|
|
|
$currentObjects = $this -> listObjectsInRelation($object,$attr,$objectType,$attrValues);
|
2008-10-08 15:24:18 +02:00
|
|
|
if(is_array($currentObjects)) {
|
2017-04-28 17:04:55 +02:00
|
|
|
for ($i=0;$i<count($currentObjects);$i++) {
|
|
|
|
$currentDns[]=$currentObjects[$i] -> getDn();
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
$dontTouch=array_intersect($listDns,$currentDns);
|
|
|
|
|
|
|
|
for($i=0;$i<count($currentObjects);$i++) {
|
|
|
|
if (in_array($currentObjects[$i] -> getDn(),$dontTouch)) continue;
|
|
|
|
if (!$currentObjects[$i] -> deleteOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction,$attrValues)) {
|
|
|
|
return;
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$type=$this -> getType();
|
|
|
|
foreach($listDns as $dn) {
|
|
|
|
if (in_array($dn,$dontTouch)) continue;
|
|
|
|
$obj = new $type();
|
|
|
|
if ($obj -> loadData($dn)) {
|
|
|
|
if (!$obj -> addOneObjectInRelation($object,$attr,$objectType,$attrValue,$canEditFunction)) {
|
2008-10-08 15:24:18 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
2017-04-28 17:04:55 +02:00
|
|
|
return true;
|
2008-10-08 15:24:18 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
/**
|
|
|
|
* Ajouter une action lors d'un événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @param[in] $event string Le nom de l'événement
|
|
|
|
* @param[in] $fct string Le nom de la fonction à exectuer
|
|
|
|
* @param[in] $param mixed Paramètre pour le lancement de la fonction
|
|
|
|
* @param[in] $class Nom de la classe possèdant la méthode $fct à executer
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @retval void
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addEvent($event,$fct,$param=NULL,$class=NULL) {
|
2009-03-09 13:42:03 +01:00
|
|
|
$this -> _events[$event][] = array(
|
|
|
|
'function' => $fct,
|
|
|
|
'param' => $param,
|
|
|
|
'class' => $class
|
|
|
|
);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
/**
|
|
|
|
* Ajouter une action sur un objet lors d'un événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @param[in] $event string Le nom de l'événement
|
|
|
|
* @param[in] $obj object L'objet dont la méthode doit être executé
|
|
|
|
* @param[in] $meth string Le nom de la méthode
|
|
|
|
* @param[in] $param mixed Paramètre d'execution de la méthode
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @retval void
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addObjectEvent($event,&$obj,$meth,$param=NULL) {
|
2009-03-09 13:42:03 +01:00
|
|
|
$this -> _objectEvents[$event][] = array(
|
2015-04-14 15:10:40 +02:00
|
|
|
'obj' => &$obj,
|
2009-03-09 13:42:03 +01:00
|
|
|
'meth' => $meth,
|
|
|
|
'param' => $param
|
|
|
|
);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
/**
|
|
|
|
* Lance les actions à executer lors d'un événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @param[in] $event string Le nom de l'événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @retval boolean True si tout c'est bien passé, false sinon
|
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function fireEvent($event) {
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// Object event
|
|
|
|
$return = $this -> fireObjectEvent($event);
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// Config
|
2019-03-11 22:21:25 +01:00
|
|
|
$funcs = $this -> getConfig($event);
|
|
|
|
if($funcs) {
|
|
|
|
if (!is_array($funcs))
|
2009-03-09 13:42:03 +01:00
|
|
|
$funcs = array($this -> config[$event]);
|
|
|
|
foreach($funcs as $func) {
|
|
|
|
if(function_exists($func)) {
|
2019-03-11 22:21:25 +01:00
|
|
|
if(!call_user_func_array($func, array(&$this))) {
|
2009-03-09 13:42:03 +01:00
|
|
|
$return = false;
|
|
|
|
LSerror :: addErrorCode('LSldapObject_07',array('func' => $func,'event' => $event));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$return = false;
|
|
|
|
LSerror :: addErrorCode('LSldapObject_06',array('func' => $func,'event' => $event));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// Binding via addEvent
|
2010-11-25 12:25:05 +01:00
|
|
|
if (isset($this -> _events[$event]) && is_array($this -> _events[$event])) {
|
2009-03-09 13:42:03 +01:00
|
|
|
foreach ($this -> _events[$event] as $e) {
|
|
|
|
if ($e['class']) {
|
|
|
|
if (class_exists($e['class'])) {
|
|
|
|
$obj = new $e['class']();
|
|
|
|
if (method_exists($obj,$e['fct'])) {
|
|
|
|
try {
|
2017-04-28 10:22:01 +02:00
|
|
|
call_user_func_array(array($obj,$e['fct']),array(&$e['param']));
|
2009-03-09 13:42:03 +01:00
|
|
|
}
|
|
|
|
catch(Exception $er) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_10',array('class' => $e['class'],'meth' => $e['fct'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_09',array('class' => $e['class'],'meth' => $e['fct'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_08',array('class' => $e['class'],'meth' => $e['fct'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (function_exists($e['fct'])) {
|
|
|
|
try {
|
2017-04-28 10:22:01 +02:00
|
|
|
call_user_func_array($e['fct'],array(&$e['param']));
|
2009-03-09 13:42:03 +01:00
|
|
|
}
|
|
|
|
catch(Exception $er) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_27',array('func' => $e['fct'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_26',array('func' => $e['fct'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
// Binding via addObjectEvent
|
2010-11-25 12:25:05 +01:00
|
|
|
if (isset($this -> _objectEvents[$event]) && is_array($this -> _objectEvents[$event])) {
|
2009-03-09 13:42:03 +01:00
|
|
|
foreach ($this -> _objectEvents[$event] as $e) {
|
|
|
|
if (method_exists($e['obj'],$e['meth'])) {
|
|
|
|
try {
|
2017-04-28 10:22:01 +02:00
|
|
|
call_user_func_array(array($e['obj'], $e['meth']),array(&$e['param']));
|
2009-03-09 13:42:03 +01:00
|
|
|
}
|
|
|
|
catch(Exception $er) {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_29',array('meth' => $e['meth'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LSerror :: addErrorCode('LSldapObject_28',array('meth' => $e['meth'],'event' => $event));
|
|
|
|
$return = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
return $return;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-03-09 13:42:03 +01:00
|
|
|
/**
|
|
|
|
* Lance les actions à executer lors d'un événement sur l'objet lui-même
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @param[in] $event string Le nom de l'événement
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-03-09 13:42:03 +01:00
|
|
|
* @retval boolean True si tout c'est bien passé, false sinon
|
2009-10-30 01:03:17 +01:00
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function fireObjectEvent($event) {
|
2009-03-09 13:42:03 +01:00
|
|
|
switch($event) {
|
|
|
|
case 'after_create':
|
|
|
|
return $this -> afterCreate();
|
|
|
|
case 'after_delete':
|
|
|
|
return $this -> afterDelete();
|
|
|
|
case 'after_rename':
|
|
|
|
return $this -> afterRename();
|
|
|
|
case 'after_modify':
|
|
|
|
return $this -> afterModify();
|
|
|
|
/*
|
|
|
|
case 'before_create':
|
|
|
|
return $this -> beforeCreate();
|
|
|
|
*/
|
|
|
|
case 'before_delete':
|
|
|
|
return $this -> beforeDelete();
|
|
|
|
case 'before_rename':
|
|
|
|
return $this -> beforeRename();
|
|
|
|
/*
|
|
|
|
case 'before_modify':
|
|
|
|
return $this -> beforeModify();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
/**
|
|
|
|
* Access to infos of the object
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-10-30 01:03:17 +01:00
|
|
|
* @param[in] $key string The name of the value
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2009-10-30 01:03:17 +01:00
|
|
|
* @retval mixed The value
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __get($key) {
|
2009-10-30 01:03:17 +01:00
|
|
|
if ($key=='subDnValue') {
|
2010-11-25 12:25:44 +01:00
|
|
|
if (isset($this -> cache['subDnValue'])) {
|
2009-10-30 01:03:17 +01:00
|
|
|
return $this -> cache['subDnValue'];
|
|
|
|
}
|
|
|
|
$this -> cache['subDnValue'] = self :: getSubDnValue($this -> dn);
|
|
|
|
return $this -> cache['subDnValue'];
|
|
|
|
}
|
2015-02-13 13:55:28 +01:00
|
|
|
elseif ($key=='subDnName') {
|
2009-10-30 01:03:17 +01:00
|
|
|
if ($this -> cache['subDnName']) {
|
|
|
|
return $this -> cache['subDnName'];
|
|
|
|
}
|
|
|
|
$this -> cache['subDnName'] = self :: getSubDnName($this -> dn);
|
|
|
|
return $this -> cache['subDnName'];
|
|
|
|
}
|
2015-02-13 13:55:28 +01:00
|
|
|
elseif ($key=='rdn') {
|
2019-03-11 22:21:25 +01:00
|
|
|
$rdn_attr = $this -> getConfig('rdn');
|
|
|
|
if ($rdn_attr && isset($this -> attrs[ $rdn_attr ])) {
|
|
|
|
return $this -> attrs[ $rdn_attr ] -> getValue();
|
2015-02-13 13:55:28 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-30 01:03:17 +01:00
|
|
|
}
|
2015-07-30 16:37:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* List IOformats of this object type
|
|
|
|
*
|
|
|
|
* @retval mixed Array of valid IOformats of this object type
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function listValidIOformats() {
|
2015-07-30 16:37:42 +02:00
|
|
|
$ret=array();
|
2019-03-11 22:21:25 +01:00
|
|
|
$ioFormats = $this -> getConfig('ioFormat');
|
|
|
|
if (is_array($ioFormats)) {
|
|
|
|
foreach($ioFormats as $name => $conf) {
|
|
|
|
$ret[$name] = _((isset($conf['label'])?$conf['label']:$name));
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if an IOformat is valid for this object type
|
|
|
|
*
|
|
|
|
* @param[in] $f string The IOformat name to check
|
|
|
|
*
|
|
|
|
* @retval boolean True if it's a valid IOformat, false otherwise
|
|
|
|
**/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isValidIOformat($f) {
|
2019-03-11 22:21:25 +01:00
|
|
|
return is_array($this -> getConfig("ioFormat.$f"));
|
2015-07-30 16:37:42 +02:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a configuration parameter (or default value)
|
|
|
|
*
|
|
|
|
* @param[] $param The configuration parameter
|
|
|
|
* @param[] $default The default value (default : null)
|
|
|
|
* @param[] $cast Cast resulting value in specific type (default : disabled)
|
|
|
|
*
|
|
|
|
* @retval mixed The configuration parameter value or default value if not set
|
|
|
|
**/
|
|
|
|
public function getConfig($param, $default=null, $cast=null) {
|
|
|
|
return LSconfig :: get($param, $default, $cast, $this -> config);
|
|
|
|
}
|
|
|
|
|
2020-02-18 10:36:47 +01:00
|
|
|
/**
|
|
|
|
* Allow conversion of LdapObject to string
|
|
|
|
*
|
|
|
|
* @retval string The string representation of the LdapObject
|
|
|
|
*/
|
|
|
|
public function __toString() {
|
|
|
|
if ($this -> dn)
|
|
|
|
return "<LdapObject ".$this -> dn.">";
|
|
|
|
$rdn_attr = $this -> getConfig('rdn');
|
|
|
|
if( $rdn_attr && isset($this -> attrs[$rdn_attr]) ) {
|
|
|
|
$rdn_val = $this -> attrs[$rdn_attr] -> getUpdateData();
|
|
|
|
if (!empty($rdn_val))
|
|
|
|
return "<LdapObject (new) $rdn_attr=".$rdn_val[0].">";
|
|
|
|
}
|
|
|
|
return "<LdapObject (new)>";
|
|
|
|
}
|
2020-04-29 17:15:49 +02:00
|
|
|
|
2020-04-29 17:35:34 +02:00
|
|
|
/**
|
|
|
|
* CLI show command
|
|
|
|
*
|
|
|
|
* @param[in] $command_args array Command arguments :
|
|
|
|
* - Positional arguments :
|
|
|
|
* - LSobject type
|
|
|
|
* - object DN
|
|
|
|
* - Optional arguments :
|
|
|
|
* - -r|--raw-values : show raw values (instead of display ones)
|
|
|
|
*
|
|
|
|
* @retval boolean True on succes, false otherwise
|
|
|
|
**/
|
2020-04-29 17:15:49 +02:00
|
|
|
public static function cli_show($command_args) {
|
|
|
|
$objType = null;
|
|
|
|
$dn = null;
|
|
|
|
$raw_values = false;
|
|
|
|
foreach ($command_args as $arg) {
|
|
|
|
if ($arg == '-r' || $arg == '--raw-value')
|
|
|
|
$raw_values = true;
|
|
|
|
elseif (is_null($objType)) {
|
|
|
|
$objType = $arg;
|
|
|
|
}
|
|
|
|
elseif (is_null($dn)) {
|
|
|
|
$dn = $arg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LScli :: usage("Invalid $arg parameter.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($objType) || is_null($dn))
|
|
|
|
LScli :: usage('You must provide LSobject type and DN.');
|
|
|
|
|
|
|
|
if (!LSsession :: loadLSobject($objType))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$obj = new $objType();
|
|
|
|
if (!$obj->loadData($dn)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_fatal("Fail to load object $dn data from LDAP");
|
2020-04-29 17:15:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 21:02:28 +02:00
|
|
|
$obj -> _cli_show($raw_values);
|
2020-04-29 17:15:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-29 17:35:34 +02:00
|
|
|
/**
|
|
|
|
* CLI helper to show the object info
|
|
|
|
*
|
2020-05-01 13:05:30 +02:00
|
|
|
* @param[in] $raw_values bool Show attributes raw values (instead of display ones)
|
2020-04-29 17:35:34 +02:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
2020-05-01 13:05:30 +02:00
|
|
|
public function _cli_show($raw_values=false) {
|
2020-04-29 17:15:49 +02:00
|
|
|
echo $this -> type_name." (".($this -> dn?$this -> dn:'new').") :\n";
|
2020-05-01 13:25:23 +02:00
|
|
|
|
|
|
|
// Show attributes
|
2020-05-01 13:05:30 +02:00
|
|
|
if (is_array($this -> getConfig('LSform.layout'))) {
|
|
|
|
foreach($this -> getConfig('LSform.layout') as $tab_name => $tab) {
|
|
|
|
echo " - ".(isset($tab['label'])?$tab['label']:$tab_name)." :\n";
|
|
|
|
foreach ($tab['args'] as $attr_name) {
|
2020-05-08 21:02:28 +02:00
|
|
|
echo $this -> _cli_show_attr($attr_name, $raw_values, " ");
|
2020-05-01 13:05:30 +02:00
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($this -> attrs as $attr_name => $attr) {
|
2020-05-08 21:02:28 +02:00
|
|
|
echo $this -> _cli_show_attr($attr_name, $raw_values);
|
2020-04-29 17:15:49 +02:00
|
|
|
}
|
2020-05-01 13:25:23 +02:00
|
|
|
echo "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show LSrelations
|
|
|
|
if (LSsession :: loadLSclass('LSrelation') && is_array($this -> getConfig('LSrelation'))) {
|
|
|
|
foreach ($this -> getConfig('LSrelation') as $rel_name => $rel_conf) {
|
2020-05-01 15:49:21 +02:00
|
|
|
echo " - ".(isset($rel_conf['label'])?$rel_conf['label']." (relation $rel_name)":$rel_name)." :\n";
|
2020-05-01 13:25:23 +02:00
|
|
|
$relation = new LSrelation($this, $rel_name);
|
|
|
|
$list = $relation -> listRelatedObjects();
|
|
|
|
if (is_array($list)) {
|
|
|
|
foreach($list as $o) {
|
|
|
|
echo " - ".$o -> getDisplayName(NULL,true)." (".$o -> getDn().")\n";
|
|
|
|
}
|
|
|
|
if (empty($list)) {
|
|
|
|
echo " => ".(isset($rel_conf['emptyText'])?$rel_conf['emptyText']:"No objects.")."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_error("Fail to load related objects.");
|
2020-05-01 13:25:23 +02:00
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
}
|
2020-05-01 13:05:30 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-29 17:15:49 +02:00
|
|
|
|
2020-05-01 13:05:30 +02:00
|
|
|
/**
|
|
|
|
* CLI helper to show the attribute
|
|
|
|
*
|
|
|
|
* @param[in] $attr_name string The attribute name
|
|
|
|
* @param[in] $raw_values bool Show attributes raw values (instead of display ones)
|
|
|
|
* @param[in] $prefix string Prefix for each line displayed (optional, default: no prefix)
|
|
|
|
*
|
2020-05-08 21:02:28 +02:00
|
|
|
* @retval string The formated attribute message
|
2020-05-01 13:05:30 +02:00
|
|
|
**/
|
2020-05-08 21:02:28 +02:00
|
|
|
private function _cli_show_attr($attr_name, $raw_values=false, $prefix="") {
|
2020-05-01 13:05:30 +02:00
|
|
|
if (!isset($this -> attrs[$attr_name]))
|
|
|
|
return;
|
|
|
|
$values = ($raw_values?$this -> attrs[$attr_name]->getValue():$this -> attrs[$attr_name]->getDisplayValue());
|
2020-05-08 21:02:28 +02:00
|
|
|
return self :: _cli_show_attr_values($attr_name, $values, $prefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CLI helper to show the attribute values
|
|
|
|
*
|
|
|
|
* @param[in] $attr_name string The attribute name
|
|
|
|
* @param[in] $values array Attribute values
|
|
|
|
* @param[in] $prefix string Prefix for each line displayed (optional, default: no prefix)
|
|
|
|
*
|
|
|
|
* @retval string The formated attribute values message
|
|
|
|
**/
|
|
|
|
private function _cli_show_attr_values($attr_name, $values, $prefix="") {
|
|
|
|
$return = "$prefix - ".$this -> attrs[$attr_name]->getLabel()." ($attr_name) :";
|
2020-05-01 13:05:30 +02:00
|
|
|
if (empty($values)) {
|
2020-05-08 21:02:28 +02:00
|
|
|
return $return." empty\n";
|
2020-04-29 17:15:49 +02:00
|
|
|
}
|
2020-05-01 13:05:30 +02:00
|
|
|
if (!is_array($values)) $values = array($values);
|
|
|
|
|
|
|
|
// Truncate values if too long
|
|
|
|
for ($i=0; $i < count($values); $i++)
|
|
|
|
if (strlen($values[$i]) > 70)
|
|
|
|
$values[$i] = substr($values[$i], 0, 65)."[...]";
|
2020-05-08 21:02:28 +02:00
|
|
|
$return .= (count($values) > 1?"\n$prefix - ":" ");
|
|
|
|
$return .= implode("\n$prefix - ", $values);
|
|
|
|
return $return."\n";
|
2020-04-29 17:15:49 +02:00
|
|
|
}
|
2020-05-01 13:41:42 +02:00
|
|
|
|
2020-05-08 21:02:28 +02:00
|
|
|
/**
|
|
|
|
* CLI helper to show the attributes values
|
|
|
|
*
|
|
|
|
* @param[in] $attrs_values attrs The attributes values
|
|
|
|
* @param[in] $label string|null The label text to show before attributes values
|
|
|
|
* @param[in] $prefix string Prefix for each line displayed (optional, default: no prefix)
|
|
|
|
*
|
|
|
|
* @retval string The formated attributes values message
|
|
|
|
**/
|
|
|
|
private function _cli_show_attrs_values($attrs_values, $label=null, $prefix="") {
|
|
|
|
$return = "";
|
|
|
|
if ($label)
|
|
|
|
$return .= "$prefix$label\n";
|
|
|
|
foreach ($attrs_values as $attr => $values)
|
|
|
|
$return .= self :: _cli_show_attr_values($attr, $values, $prefix);
|
|
|
|
return $return;
|
|
|
|
}
|
2020-05-01 13:41:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CLI remove command
|
|
|
|
*
|
|
|
|
* @param[in] $command_args array Command arguments :
|
|
|
|
* - Positional arguments :
|
|
|
|
* - LSobject type
|
|
|
|
* - object DN
|
|
|
|
* - Optional arguments :
|
|
|
|
* - -N|--no-confirm : Do not ask for confirmation
|
|
|
|
*
|
|
|
|
* @retval boolean True on succes, false otherwise
|
|
|
|
**/
|
|
|
|
public static function cli_remove($command_args) {
|
|
|
|
$objType = null;
|
|
|
|
$dn = null;
|
|
|
|
$confirm = true;
|
|
|
|
foreach ($command_args as $arg) {
|
|
|
|
if ($arg == '-N' || $arg == '--no-confirm')
|
|
|
|
$confirm = false;
|
|
|
|
elseif (is_null($objType)) {
|
|
|
|
$objType = $arg;
|
|
|
|
}
|
|
|
|
elseif (is_null($dn)) {
|
|
|
|
$dn = $arg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LScli :: usage("Invalid $arg parameter.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($objType) || is_null($dn))
|
|
|
|
LScli :: usage('You must provide LSobject type and DN.');
|
|
|
|
|
|
|
|
if (!LSsession :: loadLSobject($objType))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$obj = new $objType();
|
|
|
|
if (!$obj->loadData($dn)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_fatal("Fail to load object $dn data from LDAP");
|
2020-05-01 13:41:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($confirm) {
|
2020-05-08 20:38:02 +02:00
|
|
|
$obj -> _cli_show($raw_values);
|
2020-05-01 13:41:42 +02:00
|
|
|
// Sure ?
|
2020-05-09 11:36:26 +02:00
|
|
|
if (!LScli :: confirm("\nAre you sure you want to delete this object?"))
|
2020-05-08 20:38:02 +02:00
|
|
|
return True;
|
2020-05-01 13:41:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($obj -> remove()) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_info("Object ".$obj->getDn()." removed.");
|
2020-05-01 13:41:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_error("Fail to remove object ".$obj->getDn().".");
|
2020-05-01 13:41:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-01 15:49:21 +02:00
|
|
|
|
2020-05-08 21:02:28 +02:00
|
|
|
/**
|
|
|
|
* CLI helper to parse attribute values given via command argument in format :
|
|
|
|
*
|
|
|
|
* attr=value1|value2
|
|
|
|
*
|
|
|
|
* @param[in] $obj LSldapObject The LDAP object
|
|
|
|
* @param[in] &$attrs_values array The reference of the array that store attributes values
|
|
|
|
* @param[in] $command_arg string The command argument to parse
|
|
|
|
* @param[in] $delimiter string The delimiter of multiple-value attribute (optional, default: '|')
|
|
|
|
*
|
|
|
|
* @retval boolean True if attribute values successfully parsed, False otherwise
|
|
|
|
**/
|
|
|
|
function _cli_parse_attr_values($obj, &$attrs_values, $command_arg, $delimiter='|') {
|
|
|
|
$arg_parts = explode('=', $command_arg);
|
|
|
|
if (count($arg_parts) < 2)
|
|
|
|
LScli :: usage("Invalid parameter '$command_arg'.");
|
|
|
|
$attr = $arg_parts[0];
|
|
|
|
if (!isset($obj -> attrs[$attr]))
|
|
|
|
LScli :: usage("Invalid parameter '$command_arg': ".$obj->type_name." object as no attribute '$attr'.");
|
|
|
|
|
|
|
|
// Split an check values
|
|
|
|
$values = array();
|
|
|
|
foreach (explode($delimiter, implode('=', array_slice($arg_parts, 1))) as $value)
|
|
|
|
if (!empty($value))
|
|
|
|
$values[] = $value;
|
|
|
|
if (!array_key_exists($attr, $attrs_values))
|
|
|
|
$attrs_values[$attr] = $values;
|
|
|
|
else
|
|
|
|
$attrs_values[$attr] = array_merge($attrs_values[$attr], $values);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-09 11:39:52 +02:00
|
|
|
/**
|
|
|
|
* CLI create command
|
|
|
|
*
|
|
|
|
* @param[in] $command_args array Command arguments :
|
|
|
|
* - Positional arguments :
|
|
|
|
* - LSobject type
|
|
|
|
* - object DN
|
|
|
|
* - attributes values in format attr=value1|value2
|
|
|
|
* - Optional arguments :
|
|
|
|
* - -D|--delimiter : delimiter for multiple values attributes (default: "|")
|
|
|
|
* - -N|--no-confirm : Do not ask for confirmation
|
|
|
|
* - -j|--just-try : Just-try mode = validate provided data but do not really
|
|
|
|
* create LDAP object data
|
|
|
|
*
|
|
|
|
* Note: for multiple-values attributes, you also could specify attribute and value
|
|
|
|
* multiple time, for instance : attr1=value1 attr1=value2
|
|
|
|
*
|
|
|
|
* @retval boolean True on succes, false otherwise
|
|
|
|
**/
|
|
|
|
public static function cli_create($command_args) {
|
|
|
|
$objType = null;
|
|
|
|
$delimiter = "|";
|
|
|
|
$confirm = true;
|
|
|
|
$just_try = false;
|
|
|
|
$attrs_values = array();
|
|
|
|
for ($i=0; $i < count($command_args); $i++) {
|
|
|
|
switch ($command_args[$i]) {
|
|
|
|
case '-d':
|
|
|
|
case '--delimiter':
|
|
|
|
$delimiter = $command_args[++$i];
|
|
|
|
if ($delimiter == '=')
|
|
|
|
LScli :: usage("Invalid delimiter: you can't use '=' as delimiter.");
|
|
|
|
break;
|
|
|
|
case '-N':
|
|
|
|
case '--no-confirm':
|
|
|
|
$confirm = false;
|
|
|
|
break;
|
|
|
|
case '-j':
|
|
|
|
case '--just-try':
|
|
|
|
$just_try = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (is_null($objType)) {
|
|
|
|
$objType = $command_args[$i];
|
|
|
|
if (!LSsession :: loadLSobject($objType))
|
|
|
|
return false;
|
|
|
|
$obj = new $objType();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Change on an attribute
|
|
|
|
$obj -> _cli_parse_attr_values($obj, $attrs_values, $command_args[$i], $delimiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($objType) || empty($attrs_values))
|
|
|
|
LScli :: usage('You must provide LSobject type, DN and at least one change.');
|
|
|
|
|
|
|
|
// Instanciate a create LSform
|
|
|
|
$form = $obj -> getForm('create');
|
|
|
|
|
|
|
|
// Check all changed attributes are in modify form and are'nn freezed
|
|
|
|
foreach ($attrs_values as $attr => $value) {
|
|
|
|
if (!$form -> hasElement($attr))
|
|
|
|
LScli :: usage("Change on attribute '$attr' is not possible (attribute not in create form).");
|
|
|
|
if ($form -> isFreeze($attr))
|
|
|
|
LScli :: usage("Change on attribute '$attr' is not possible (attribute freezed in create form).");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set form data from inputed data, validate form (only for present data) and validate data (just-validation)
|
|
|
|
if ($form -> setPostData($attrs_values, true) && $form -> validate(true) && $obj -> updateData('create', true)) {
|
|
|
|
// Data validated, get user confirmation
|
|
|
|
if ($confirm) {
|
|
|
|
echo $obj -> _cli_show(false);
|
|
|
|
// Sure ?
|
|
|
|
if (!LScli :: confirm("Are you sure you want to create an $objType with this attributes's values?"))
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
// Just-try mode: stop
|
|
|
|
if ($just_try) {
|
|
|
|
self :: log_info($obj -> getDn().": Just-try mode : provided information validated but object not updated.");
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
// Create object in LDAP
|
|
|
|
if ($obj -> updateData('create')) {
|
|
|
|
self :: log_info($obj -> getDn().": Object created.");
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// An error occured: show/log it
|
|
|
|
$error_msg = "Validation errors occured on provided information:";
|
|
|
|
$errors = $form->getErrors();
|
|
|
|
if (is_array($errors) && !empty($errors))
|
|
|
|
$error_msg .= "\n".$obj -> _cli_show_attrs_values($errors, "");
|
|
|
|
else
|
|
|
|
$error_msg .= " unknown error";
|
|
|
|
LSlog :: error($error_msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 21:02:28 +02:00
|
|
|
/**
|
|
|
|
* CLI modify command
|
|
|
|
*
|
|
|
|
* @param[in] $command_args array Command arguments :
|
|
|
|
* - Positional arguments :
|
|
|
|
* - LSobject type
|
|
|
|
* - object DN
|
|
|
|
* - changes to made on object in format attr=value1|value2
|
|
|
|
* - Optional arguments :
|
|
|
|
* - -D|--delimiter : delimiter for multiple values attributes (default: "|")
|
|
|
|
* - -N|--no-confirm : Do not ask for confirmation
|
|
|
|
* - -j|--just-try : Just-try mode = validate changes but do not really update LDAP object data
|
|
|
|
*
|
|
|
|
* Note: for multiple-values attributes, you also could specify attribute and value
|
|
|
|
* multiple time, for instance : attr1=value1 attr1=value2
|
|
|
|
*
|
|
|
|
* @retval boolean True on succes, false otherwise
|
|
|
|
**/
|
|
|
|
public static function cli_modify($command_args) {
|
|
|
|
$objType = null;
|
|
|
|
$dn = null;
|
|
|
|
$delimiter = "|";
|
|
|
|
$confirm = true;
|
|
|
|
$just_try = false;
|
|
|
|
$changes = array();
|
|
|
|
for ($i=0; $i < count($command_args); $i++) {
|
|
|
|
switch ($command_args[$i]) {
|
|
|
|
case '-d':
|
|
|
|
case '--delimiter':
|
|
|
|
$delimiter = $command_args[++$i];
|
|
|
|
if ($delimiter == '=')
|
|
|
|
LScli :: usage("Invalid delimiter: you can't use '=' as delimiter.");
|
|
|
|
break;
|
|
|
|
case '-N':
|
|
|
|
case '--no-confirm':
|
|
|
|
$confirm = false;
|
|
|
|
break;
|
|
|
|
case '-j':
|
|
|
|
case '--just-try':
|
|
|
|
$just_try = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (is_null($objType)) {
|
|
|
|
$objType = $command_args[$i];
|
|
|
|
if (!LSsession :: loadLSobject($objType))
|
|
|
|
return false;
|
|
|
|
$obj = new $objType();
|
|
|
|
}
|
|
|
|
elseif (is_null($dn)) {
|
|
|
|
$dn = $command_args[$i];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Change on an attribute
|
|
|
|
$obj -> _cli_parse_attr_values($obj, $changes, $command_args[$i], $delimiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($objType) || is_null($dn) || empty($changes))
|
|
|
|
LScli :: usage('You must provide LSobject type, DN and at least one change.');
|
|
|
|
|
|
|
|
if (!$obj->loadData($dn)) {
|
|
|
|
self :: log_fatal("Fail to load object $dn data from LDAP");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($confirm) {
|
|
|
|
echo $obj -> _cli_show_attrs_values($changes, "Attributes's values changes:");
|
|
|
|
// Sure ?
|
|
|
|
if (!LScli :: confirm("Are you sure you want to change attributes's values of this object as specified?"))
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instanciate a modify LSform
|
|
|
|
$form = $obj -> getForm('modify');
|
|
|
|
|
|
|
|
// Check all changed attributes are in modify form and are'nn freezed
|
|
|
|
foreach ($changes as $attr => $value) {
|
|
|
|
if (!$form -> hasElement($attr))
|
|
|
|
LScli :: usage("Change on attribute '$attr' is not possible (attribute not in modify form).");
|
|
|
|
if ($form -> isFreeze($attr))
|
|
|
|
LScli :: usage("Change on attribute '$attr' is not possible (attribute freezed in modify form).");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set form data from inputed data, validate form (only for present data) and validate data
|
|
|
|
if (!$form -> setPostData($changes, true) || !$form -> validate(true) || !$obj -> updateData('modify', $just_try)) {
|
|
|
|
$error_msg = "Validation errors occured on your changes:";
|
|
|
|
$errors = $form->getErrors();
|
|
|
|
if (is_array($errors) && !empty($errors))
|
|
|
|
$error_msg .= "\n".$obj -> _cli_show_attrs_values($errors, "");
|
|
|
|
else
|
|
|
|
$error_msg .= " unknown error";
|
|
|
|
LSlog :: error($error_msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
elseif ($just_try) {
|
|
|
|
self :: log_info("$dn: Just-try mode : changes validated but object not updated.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self :: log_info("$dn: Object updated.");
|
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2020-05-01 15:49:21 +02:00
|
|
|
/**
|
|
|
|
* CLI relation command
|
|
|
|
*
|
|
|
|
* @param[in] $command_args array Command arguments :
|
|
|
|
* - Positional arguments :
|
|
|
|
* - LSobject type
|
|
|
|
* - object DN
|
|
|
|
* - relation ID
|
|
|
|
* - Optional arguments :
|
|
|
|
* - -a|--add : Add related object (specified by DN)
|
|
|
|
* - -r|--remove : Remove related object (specified by DN)
|
|
|
|
*
|
|
|
|
* @retval boolean True on succes, false otherwise
|
|
|
|
**/
|
|
|
|
public static function cli_relation($command_args) {
|
|
|
|
$objType = null;
|
|
|
|
$dn = null;
|
|
|
|
$relName = null;
|
|
|
|
$add = array();
|
|
|
|
$remove = array();
|
|
|
|
for ($i=0; $i < count($command_args); $i++) {
|
|
|
|
if ($command_args[$i] == '-a' || $command_args[$i] == '--add')
|
|
|
|
$add[] = $command_args[++$i];
|
|
|
|
elseif ($command_args[$i] == '-r' || $command_args[$i] == '--remove')
|
|
|
|
$remove[] = $command_args[++$i];
|
|
|
|
elseif (is_null($objType)) {
|
|
|
|
$objType = $command_args[$i];
|
|
|
|
}
|
|
|
|
elseif (is_null($dn)) {
|
|
|
|
$dn = $command_args[$i];
|
|
|
|
}
|
|
|
|
elseif (is_null($relName)) {
|
|
|
|
$relName = $command_args[$i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LScli :: usage("Invalid ".$command_args[$i]." parameter.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($objType) || is_null($dn) || is_null($relName))
|
|
|
|
LScli :: usage('You must provide LSobject type, DN and relation ID.');
|
|
|
|
|
|
|
|
if (empty($add) && empty($remove))
|
|
|
|
LScli :: usage('You must provide at least one DN of related object to add/remove.');
|
|
|
|
|
|
|
|
if (!LSsession :: loadLSobject($objType))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$obj = new $objType();
|
|
|
|
if (!$obj->loadData($dn)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_fatal("Fail to load object $dn data from LDAP");
|
2020-05-01 15:49:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LSsession :: loadLSclass('LSrelation')) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_fatal("Fail to load LSrelation class.");
|
2020-05-01 15:49:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_array($obj -> getConfig("LSrelation.$relName"))) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_fatal("LSobject $objType have no relation '$relName'.");
|
2020-05-01 15:49:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$relation = new LSrelation($obj, $relName);
|
|
|
|
|
|
|
|
// List current related objects
|
|
|
|
$list = $relation -> listRelatedObjects();
|
|
|
|
$listDns = array();
|
|
|
|
if (is_array($list)) {
|
|
|
|
foreach($list as $o) {
|
|
|
|
$listDns[] = $o -> getDn();
|
|
|
|
}
|
|
|
|
}
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug("Current related object(s) :".varDump($listDns));
|
2020-05-01 15:49:21 +02:00
|
|
|
|
|
|
|
// Keep a copy of initial related objects list
|
|
|
|
$initialListDns = $listDns;
|
|
|
|
|
|
|
|
// Handle add
|
|
|
|
$relatedLSobject = $obj -> getConfig("LSrelation.$relName.LSobject");
|
|
|
|
$search = new LSsearch(
|
|
|
|
$relatedLSobject,
|
|
|
|
"LSldapObject.cli_relation.$objType.$relName",
|
|
|
|
array(
|
|
|
|
'scope' => 'base',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
foreach ($add as $dn) {
|
|
|
|
// Check if DN is already in relation
|
|
|
|
if (in_array($dn, $listDns)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug("LSobject $relatedLSobject $dn is already in relation with ".$obj -> getDn().".");
|
2020-05-01 15:49:21 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check DN refer to a related object
|
|
|
|
$search -> setParam('basedn', $dn);
|
|
|
|
$search -> run(false);
|
|
|
|
$result = $search -> listObjectsDn();
|
|
|
|
if (!is_array($result) || count($result) != 1) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_error("No $relatedLSobject found for DN $dn");
|
2020-05-01 15:49:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$listDns[] = $dn;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle remove
|
|
|
|
foreach ($remove as $dn) {
|
|
|
|
$found = false;
|
|
|
|
while(true) {
|
|
|
|
$key = array_search($dn, $listDns);
|
|
|
|
if ($key === false) break;
|
|
|
|
$found = true;
|
|
|
|
unset($listDns[$key]);
|
|
|
|
}
|
|
|
|
if (!$found)
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug("LSobject $relatedLSobject $dn is not in relation with ".$obj -> getDn().".");
|
2020-05-01 15:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($initialListDns == $listDns) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_info('No changes done.');
|
2020-05-01 15:49:21 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_debug("New related object(s) list: ".varDump($listDns));
|
2020-05-01 15:49:21 +02:00
|
|
|
if ($relation -> updateRelations($listDns)) {
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_info('Objects in relation updated.');
|
2020-05-01 15:49:21 +02:00
|
|
|
return True;
|
|
|
|
}
|
2020-05-08 15:16:24 +02:00
|
|
|
self :: log_error("Fail to update objects in relation");
|
2020-05-01 15:49:21 +02:00
|
|
|
return False;
|
|
|
|
}
|
2007-03-29 18:10:14 +02:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
/**
|
|
|
|
* Error Codes
|
|
|
|
**/
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_01',
|
2009-02-12 13:38:56 +01:00
|
|
|
_("LSldapObject : Object type unknown.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_02',
|
|
|
|
_("LSldapObject : Update form is not defined for the object %{obj}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_03',
|
2009-02-12 13:38:56 +01:00
|
|
|
_("LSldapObject : No form exists for the object %{obj}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_04',
|
|
|
|
_("LSldapObject : The function %{func} to validate the attribute %{attr} the object %{obj} is unknow.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_05',
|
|
|
|
_("LSldapObject : Configuration data are missing to validate the attribute %{attr} of the object %{obj}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
|
|
|
LSerror :: defineError('LSldapObject_06',
|
|
|
|
_("LSldapObject : The function %{func} to be executed on the object event %{event} doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_07',
|
2009-03-09 14:21:33 +01:00
|
|
|
_("LSldapObject : The %{func} execution on the object event %{event} failed.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_08',
|
2009-03-09 14:21:33 +01:00
|
|
|
_("LSldapObject : Class %{class}, which method %{meth} to be executed on the object event %{event}, doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_09',
|
2009-03-16 11:48:42 +01:00
|
|
|
_("LSldapObject : Method %{meth} within %{class} class to be executed on object event %{event}, doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_10',
|
2009-03-13 22:32:08 +01:00
|
|
|
_("LSldapObject : Error during execute %{meth} method within %{class} class, to be executed on object event %{event}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_11',
|
|
|
|
_("LSldapObject : Some configuration data of the object type %{obj} are missing to generate the DN of the new object.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_12',
|
2009-03-16 11:48:42 +01:00
|
|
|
_("LSldapObject : The attibute %{attr} of the object is not yet defined. Can't generate DN.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_13',
|
|
|
|
_("LSldapObject : Without DN, the object could not be changed.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_14',
|
|
|
|
_("LSldapObject : The attribute %{attr_depend} depending on the attribute %{attr} doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_15',
|
|
|
|
_("LSldapObject : Error during deleting the object %{objectname}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_16',
|
|
|
|
_("LSldapObject : Error during actions to be executed before renaming the objet.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_17',
|
|
|
|
_("LSldapObject : Error during actions to be executed after renaming the objet.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_18',
|
|
|
|
_("LSldapObject : Error during actions to be executed before deleting the objet.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_19',
|
|
|
|
_("LSldapObject : Error during actions to be executed after deleting the objet.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
2009-03-09 17:33:43 +01:00
|
|
|
LSerror :: defineError('LSldapObject_20',
|
|
|
|
_("LSldapObject : Error during the actions to be executed before creating the object.")
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_21',
|
|
|
|
_("LSldapObject : Error during the actions to be executed after creating the object. It was created anyway.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_22',
|
2009-03-16 11:48:42 +01:00
|
|
|
_("LSldapObject : The function %{func} to be executed before creating the object doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_23',
|
2009-03-16 11:48:42 +01:00
|
|
|
_("LSldapObject : Error executing the function %{func} to be execute after deleting the object.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_24',
|
2009-03-16 11:48:42 +01:00
|
|
|
_("LSldapObject : The function %{func} to be executed after deleting the object doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_25',
|
2009-03-16 11:48:42 +01:00
|
|
|
_("LSldapObject : Error executing the function %{func} to be execute after creating the object.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
|
|
|
LSerror :: defineError('LSldapObject_26',
|
2009-03-09 14:21:33 +01:00
|
|
|
_("LSldapObject : %{func} function, to be executed on object event %{event}, doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_27',
|
2009-03-09 14:21:33 +01:00
|
|
|
_("LSldapObject : Error during the execution of %{func} function on object event %{event}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
|
|
|
|
LSerror :: defineError('LSldapObject_28',
|
2009-03-09 14:26:26 +01:00
|
|
|
_("LSldapObject : %{meth} method, to be executed on object event %{event}, doesn't exist.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-03-09 13:42:03 +01:00
|
|
|
LSerror :: defineError('LSldapObject_29',
|
2009-03-09 14:21:33 +01:00
|
|
|
_("LSldapObject : Error during execution of %{meth} method on object event %{event}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|
2009-10-30 01:03:17 +01:00
|
|
|
LSerror :: defineError('LSldapObject_30',
|
|
|
|
_("LSldapObject : Error during generate LDAP filter for %{LSobject}.")
|
|
|
|
);
|
|
|
|
|
2011-04-07 19:31:56 +02:00
|
|
|
LSerror :: defineError('LSldapObject_31',
|
|
|
|
_("LSldapObject : Error during execution of the custom action %{customAction} on %{objectname}.")
|
|
|
|
);
|
|
|
|
|
2018-10-01 12:57:26 +02:00
|
|
|
LSerror :: defineError('LSldapObject_32',
|
|
|
|
_("LSldapObject : Fail to retrieve container DN.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSldapObject_33',
|
|
|
|
_("LSldapObject : The function %{func} to generate container DN is not callable.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSldapObject_34',
|
|
|
|
_("LSldapObject : Error during generating container DN : %{error}")
|
|
|
|
);
|
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
// LSrelation
|
|
|
|
LSerror :: defineError('LSrelations_05',
|
|
|
|
_("LSrelation : Some parameters are missing in the call of methods to handle standard relations (Method : %{meth}).")
|
|
|
|
);
|
2020-04-29 17:15:49 +02:00
|
|
|
|
|
|
|
// LScli
|
|
|
|
LScli :: add_command(
|
|
|
|
'show',
|
|
|
|
array('LSldapObject', 'cli_show'),
|
|
|
|
'Show an LSobject',
|
|
|
|
'[object type] [dn] [-r|--raw-values]'
|
|
|
|
);
|
2020-05-01 13:41:42 +02:00
|
|
|
|
2020-05-09 11:39:52 +02:00
|
|
|
LScli :: add_command(
|
|
|
|
'create',
|
|
|
|
array('LSldapObject', 'cli_create'),
|
|
|
|
'Create an LSobject',
|
|
|
|
'[object type] [-N|--no-confirm] [-D|--delimiter] attr1=value1|value2 attr2=value3',
|
|
|
|
array(
|
|
|
|
' - Positional arguments :',
|
|
|
|
' - LSobject type',
|
|
|
|
' - attributes values in format:',
|
|
|
|
'',
|
|
|
|
' attr_name=value1|value2',
|
|
|
|
'',
|
|
|
|
' Note: for multiple-values attributes, you also could specify',
|
|
|
|
' attribute and value multiple time, for instance :',
|
|
|
|
'',
|
|
|
|
' attr1=value1 attr1=value2',
|
|
|
|
'',
|
|
|
|
' - Optional arguments :',
|
|
|
|
' -j|--just-try Just-try mode: validate provided informations',
|
|
|
|
' but do not really create LDAP object. ',
|
|
|
|
' -D|--delimiter Delimiter for multiple values attributes',
|
|
|
|
' (default: "|")',
|
|
|
|
' -N|--no-confirm Do not ask for confirmation',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-05-08 21:02:28 +02:00
|
|
|
LScli :: add_command(
|
|
|
|
'modify',
|
|
|
|
array('LSldapObject', 'cli_modify'),
|
|
|
|
'Modify an LSobject',
|
|
|
|
'[object type] [dn] [-N|--no-confirm] [-D|--delimiter] attr1=value1|value2 attr2=value3',
|
|
|
|
array(
|
|
|
|
' - Positional arguments :',
|
|
|
|
' - LSobject type',
|
|
|
|
' - LSobject DN',
|
|
|
|
' - attributes values to modify in format:',
|
|
|
|
'',
|
|
|
|
' attr_name=value1|value2',
|
|
|
|
'',
|
|
|
|
' Note: for multiple-values attributes, you also could specify',
|
|
|
|
' attribute and value multiple time, for instance :',
|
|
|
|
'',
|
|
|
|
' attr1=value1 attr1=value2',
|
|
|
|
'',
|
|
|
|
' - Optional arguments :',
|
2020-05-09 11:39:52 +02:00
|
|
|
' -j|--just-try Just-try mode: validate changes but do not',
|
2020-05-08 21:02:28 +02:00
|
|
|
' really update LDAP object data',
|
|
|
|
' -D|--delimiter Delimiter for multiple values attributes',
|
|
|
|
' (default: "|")',
|
|
|
|
' -N|--no-confirm Do not ask for confirmation',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-05-01 13:41:42 +02:00
|
|
|
LScli :: add_command(
|
|
|
|
'remove',
|
|
|
|
array('LSldapObject', 'cli_remove'),
|
|
|
|
'Remove an LSobject',
|
|
|
|
'[object type] [dn] [-N|--no-confirm]'
|
|
|
|
);
|
2020-05-01 15:49:21 +02:00
|
|
|
|
|
|
|
LScli :: add_command(
|
|
|
|
'relation',
|
|
|
|
array('LSldapObject', 'cli_relation'),
|
|
|
|
'Manage LSobject related objects',
|
|
|
|
'[object type] [dn] [relation ID] [-a|--add DN] [-r|--remove DN]'
|
|
|
|
);
|