2008-02-05 17:11:21 +01: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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Objet Ldap eegroup
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSeegroup extends LSldapObject {
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
var $userObjectType = 'LSeepeople';
|
|
|
|
|
2008-02-05 17:11:21 +01:00
|
|
|
/**
|
|
|
|
* Constructeur
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette methode construit l'objet et définis la configuration.
|
2008-02-05 17:11:21 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $config array La configuration de l'objet
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'objet a été construit, false sinon.
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @see LSldapObject::LSldapObject()
|
2008-02-05 17:11:21 +01:00
|
|
|
*/
|
|
|
|
function LSeegroup ($config='auto') {
|
|
|
|
$this -> LSldapObject('LSeegroup',$config);
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne la liste des groupes d'un utilisateur
|
|
|
|
*
|
|
|
|
* Retourne un tableau de LSeegroup correspondant aux groupes
|
|
|
|
* auxquels appartient un utilisateur
|
|
|
|
*
|
2008-07-29 15:45:02 +02:00
|
|
|
* @param[in] $userObject Un object user (type : $this -> userObjectType)
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @retval Array of LSeegroup Les groupes de l'utilisateur
|
|
|
|
**/
|
|
|
|
function listUserGroups($userObject) {
|
|
|
|
$dn = $userObject -> getDn();
|
|
|
|
$filter = $this -> getObjectFilter();
|
|
|
|
$filter = '(&'.$filter.'(uniqueMember='.$dn.'))';
|
|
|
|
return $this -> listObjects($filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ajoute un utilisateur au groupe
|
|
|
|
*
|
2008-07-29 15:45:02 +02:00
|
|
|
* @param[in] $object Un object user ($this -> userObjectType) : l'utilisateur à ajouter
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'utilisateur à été ajouté, False sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
**/
|
|
|
|
function addOneMember($object) {
|
2008-07-29 15:45:02 +02:00
|
|
|
if ($object instanceof $this -> userObjectType) {
|
2008-02-26 18:40:05 +01:00
|
|
|
if ($this -> attrs['uniqueMember'] instanceof LSattribute) {
|
|
|
|
$dn = $object -> getDn();
|
|
|
|
$values = $this -> attrs['uniqueMember'] -> getValue();
|
|
|
|
if (!is_array($values)) {
|
|
|
|
$updateData = array($dn);
|
|
|
|
}
|
|
|
|
else if (!in_array($dn,$values)) {
|
|
|
|
$values[]=$dn;
|
|
|
|
$updateData = $values;
|
|
|
|
}
|
|
|
|
if (isset($updateData)) {
|
|
|
|
return $GLOBALS['LSldap'] -> update($this -> getType(),$this -> getDn(), array('uniqueMember' => $updateData));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Supprime un utilisateur du groupe
|
|
|
|
*
|
2008-07-29 15:45:02 +02:00
|
|
|
* @param[in] $object Un object (type : $this -> userObjectType) : l'utilisateur à supprimer
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'utilisateur à été supprimé, False sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
**/
|
|
|
|
function deleteOneMember($object) {
|
2008-07-29 15:45:02 +02:00
|
|
|
if ($object instanceof $this -> userObjectType) {
|
2008-02-26 18:40:05 +01:00
|
|
|
if ($this -> attrs['uniqueMember'] instanceof LSattribute) {
|
|
|
|
$dn = $object -> getDn();
|
|
|
|
$values = $this -> attrs['uniqueMember'] -> getValue();
|
|
|
|
if ((!is_array($values)) && (!empty($values))) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
if (is_array($values)) {
|
|
|
|
$updateData=array();
|
|
|
|
foreach($values as $value) {
|
|
|
|
if ($value!=$dn) {
|
|
|
|
$updateData[]=$value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $GLOBALS['LSldap'] -> update($this -> getType(),$this -> getDn(), array('uniqueMember' => $updateData));
|
|
|
|
}
|
2008-07-29 15:45:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renome un utilisateur
|
|
|
|
*
|
|
|
|
* @param[in] $object Un object (type : $this -> userObjectType) : l'utilisateur à renomer
|
|
|
|
* @param[in] $oldDn string L'ancien DN de l'utilisateur
|
|
|
|
*
|
|
|
|
* @retval boolean True en cas de succès, False sinon
|
|
|
|
*/
|
|
|
|
function renameOneMember($object,$oldDn) {
|
|
|
|
if ($object instanceof $this -> userObjectType) {
|
|
|
|
if ($this -> attrs['uniqueMember'] instanceof LSattribute) {
|
|
|
|
$values = $this -> attrs['uniqueMember'] -> getValue();
|
|
|
|
if ((!is_array($values)) && (!empty($values))) {
|
|
|
|
$values = array($values);
|
|
|
|
}
|
|
|
|
if (is_array($values)) {
|
|
|
|
$updateData=array();
|
|
|
|
foreach($values as $value) {
|
|
|
|
if ($value!=$oldDn) {
|
|
|
|
$updateData[] = $value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$updateData[] = $object-> getDn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $GLOBALS['LSldap'] -> update($this -> getType(),$this -> getDn(), array('uniqueMember' => $updateData));
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Met à jour les groupes d'un utilisateur
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2008-07-29 15:45:02 +02:00
|
|
|
* @param[in] $userObject Mixed Un object (type : $this -> userObjectType) : l'utilisateur
|
2008-02-26 18:40:05 +01:00
|
|
|
* @param[in] $listDns Array(string) Un tableau des DNs des groupes de l'utilisateur
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si tout c'est bien passé, False sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
**/
|
|
|
|
function updateUserGroups($userObject,$listDns) {
|
|
|
|
$currentGroups = $this -> listUserGroups($userObject);
|
|
|
|
$type=$this -> getType();
|
|
|
|
if(is_array($currentGroups)) {
|
|
|
|
if (is_array($listDns)) {
|
|
|
|
$dontDelete=array();
|
|
|
|
$dontAdd=array();
|
|
|
|
for ($i=0;$i<count($currentGroups);$i++) {
|
|
|
|
$dn = $currentGroups[$i] -> getDn();
|
|
|
|
if (in_array($dn, $listDns)) {
|
|
|
|
$dontDelete[$i]=true;
|
|
|
|
$dontAdd[]=$dn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for($i=0;$i<count($currentGroups);$i++) {
|
|
|
|
if ($dontDelete[$i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!$currentGroups[$i] -> deleteOneMember($userObject)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($listDns as $dn) {
|
|
|
|
if (in_array($dn,$dontAdd)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$object = new $type();
|
|
|
|
if ($object -> loadData($dn)) {
|
|
|
|
if (!$object -> addOneMember($userObject)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!is_array($listDns)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
foreach($listDns as $dn) {
|
|
|
|
$object = new $type();
|
|
|
|
if ($object -> loadData($dn)) {
|
|
|
|
if (!$object -> addOneMember($userObject)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|