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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
define('LS_DEFAULT_CONF_DIR','conf');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gestion des sessions
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette classe gère les sessions d'utilisateurs.
|
2008-02-05 17:11:21 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
class LSsession {
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
var $confDir = NULL;
|
|
|
|
var $ldapServer = NULL;
|
|
|
|
var $ldapServerId = NULL;
|
|
|
|
var $topDn = NULL;
|
|
|
|
var $LSuserObject = NULL;
|
|
|
|
var $dn = NULL;
|
|
|
|
var $rdn = NULL;
|
|
|
|
var $JSscripts = array();
|
|
|
|
var $CssFiles = array();
|
|
|
|
var $template = NULL;
|
|
|
|
var $LSrights = array (
|
|
|
|
'topDn_admin' => array ()
|
|
|
|
);
|
|
|
|
var $LSaccess = array();
|
2008-02-26 18:40:05 +01:00
|
|
|
var $tmp_file = array();
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructeur
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function LSsession ($configDir=LS_DEFAULT_CONF_DIR) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> confDir = $configDir;
|
|
|
|
if ($this -> loadConfig()) {
|
|
|
|
$this -> startLSerror();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Chargement de la configuration
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Chargement des fichiers de configuration et création de l'objet Smarty.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval true si tout c'est bien passé, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function loadConfig() {
|
|
|
|
if (loadDir($this -> confDir, '^config\..*\.php$')) {
|
2008-04-25 15:48:12 +02:00
|
|
|
if ( include_once $GLOBALS['LSconfig']['Smarty'] ) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['Smarty'] = new Smarty();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2008-04-25 15:48:12 +02:00
|
|
|
die($GLOBALS['LSerror_code'][1008]['msg']);
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Initialisation de la gestion des erreurs
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Création de l'objet LSerror
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si l'initialisation a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function startLSerror() {
|
|
|
|
if(!$this -> loadLSclass('LSerror'))
|
|
|
|
return;
|
|
|
|
$GLOBALS['LSerror'] = new LSerror();
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Chargement d'une classe d'LdapSaisie
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $class Nom de la classe à charger (Exemple : LSeepeople)
|
|
|
|
* @param[in] $type (Optionnel) Type de classe à charger (Exemple : LSobjects)
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function loadLSclass($class,$type='') {
|
|
|
|
if (class_exists($class))
|
|
|
|
return true;
|
|
|
|
if($type!='')
|
|
|
|
$type=$type.'.';
|
2008-04-25 15:48:12 +02:00
|
|
|
return include_once LS_CLASS_DIR .'class.'.$type.$class.'.php';
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Chargement d'un object LdapSaisie
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $object Nom de l'objet à charger
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function loadLSobject($object) {
|
2008-04-25 15:48:12 +02:00
|
|
|
$this -> loadLSclass('LSldapObject');
|
|
|
|
if (!$this -> loadLSclass($object,'LSobjects')) {
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
2008-04-25 15:48:12 +02:00
|
|
|
}
|
|
|
|
if (!require_once( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) {
|
2008-02-08 18:39:24 +01:00
|
|
|
return;
|
2008-04-25 15:48:12 +02:00
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Chargement des objects LdapSaisie
|
|
|
|
*
|
|
|
|
* Chargement des LSobjects contenue dans la variable
|
2008-04-25 15:48:12 +02:00
|
|
|
* $this -> ldapServer['LSobjects']
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function loadLSobjects() {
|
|
|
|
|
|
|
|
$this -> loadLSclass('LSldapObject');
|
|
|
|
|
2008-04-25 15:48:12 +02:00
|
|
|
if(!is_array($this -> ldapServer['LSobjects'])) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1001,"LSobjects['loads']");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-25 15:48:12 +02:00
|
|
|
foreach ($this -> ldapServer['LSobjects'] as $object) {
|
2008-02-08 18:39:24 +01:00
|
|
|
if ( !$this -> loadLSobject($object) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Chargement d'un addons d'LdapSaisie
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $addon Nom de l'addon à charger (Exemple : samba)
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function loadLSaddon($addon) {
|
|
|
|
return require_once LS_ADDONS_DIR .'LSaddons.'.$addon.'.php';
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Chargement des addons LdapSaisie
|
|
|
|
*
|
|
|
|
* Chargement des LSaddons contenue dans la variable
|
|
|
|
* $GLOBALS['LSaddons']['loads']
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function loadLSaddons() {
|
|
|
|
if(!is_array($GLOBALS['LSaddons']['loads'])) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1001,"LSaddons['loads']");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($GLOBALS['LSaddons']['loads'] as $addon) {
|
|
|
|
$this -> loadLSaddon($addon);
|
|
|
|
if (!call_user_func('LSaddon_'. $addon .'_support')) {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1002,$addon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialisation de la session LdapSaisie
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* Initialisation d'une LSsession :
|
2008-04-25 16:09:27 +02:00
|
|
|
* - Authentification et activation du mécanisme de session de LdapSaisie
|
|
|
|
* - ou Chargement des paramètres de la session à partir de la variable
|
2008-02-08 18:39:24 +01:00
|
|
|
* $_SESSION['LSsession'].
|
|
|
|
* - ou Destruction de la session en cas de $_GET['LSsession_logout'].
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'initialisation à réussi (utilisateur authentifié), false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function startLSsession() {
|
|
|
|
$this -> loadLSaddons();
|
|
|
|
session_start();
|
|
|
|
|
2008-04-25 16:09:27 +02:00
|
|
|
// Déconnexion
|
2008-02-08 18:39:24 +01:00
|
|
|
if (isset($_GET['LSsession_logout'])) {
|
|
|
|
session_destroy();
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
if (is_array($_SESSION['LSsession']['tmp_file'])) {
|
|
|
|
$this -> tmp_file = $_SESSION['LSsession']['tmp_file'];
|
|
|
|
}
|
|
|
|
$this -> deleteTmpFile();
|
2008-02-08 18:39:24 +01:00
|
|
|
unset($_SESSION['LSsession']);
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
|
|
if(isset($_SESSION['LSsession'])) {
|
|
|
|
// Session existante
|
2008-02-26 18:40:05 +01:00
|
|
|
$this -> confDir = $_SESSION['LSsession']['confDir'];
|
|
|
|
$this -> topDn = $_SESSION['LSsession']['topDn'];
|
|
|
|
$this -> dn = $_SESSION['LSsession']['dn'];
|
|
|
|
$this -> rdn = $_SESSION['LSsession']['rdn'];
|
|
|
|
$this -> ldapServerId = $_SESSION['LSsession']['ldapServerId'];
|
|
|
|
$this -> tmp_file = $_SESSION['LSsession']['tmp_file'];
|
2008-04-25 15:48:12 +02:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
if ( ($GLOBALS['LSconfig']['cacheLSrights']) || ($this -> ldapServer['cacheLSrights']) ) {
|
2008-02-26 18:40:05 +01:00
|
|
|
$this -> ldapServer = $_SESSION['LSsession']['ldapServer'];
|
|
|
|
$this -> LSrights = $_SESSION['LSsession']['LSrights'];
|
|
|
|
$this -> LSaccess = $_SESSION['LSsession']['LSaccess'];
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> LSldapConnect())
|
|
|
|
return;
|
2008-04-25 15:48:12 +02:00
|
|
|
$this -> loadLSobjects();
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this -> setLdapServer($this -> ldapServerId);
|
|
|
|
if (!$this -> LSldapConnect())
|
|
|
|
return;
|
2008-04-25 15:48:12 +02:00
|
|
|
$this -> loadLSobjects();
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> loadLSrights();
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
$this -> loadLSobject($this -> ldapServer['authobject']);
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> LSuserObject = new $this -> ldapServer['authobject']();
|
|
|
|
$this -> LSuserObject -> loadData($this -> dn);
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> loadLSaccess();
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_username',$this -> LSuserObject -> getDisplayValue());
|
2008-04-25 15:48:12 +02:00
|
|
|
|
|
|
|
if ($_POST['LSsession_topDn']) {
|
|
|
|
if ($this -> validSubDnLdapServer($_POST['LSsession_topDn'])) {
|
|
|
|
$this -> topDn = $_POST['LSsession_topDn'];
|
|
|
|
$_SESSION['LSsession']['topDn'] = $_POST['LSsession_topDn'];
|
|
|
|
} // end if
|
|
|
|
} // end if
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Session inexistante
|
|
|
|
|
|
|
|
if (isset($_POST['LSsession_user'])) {
|
|
|
|
if (isset($_POST['LSsession_ldapserver'])) {
|
|
|
|
$this -> setLdapServer($_POST['LSsession_ldapserver']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this -> setLdapServer(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connexion au serveur LDAP
|
|
|
|
if ($this -> LSldapConnect()) {
|
2008-04-25 15:48:12 +02:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
// topDn
|
|
|
|
if ( $_POST['LSsession_topDn'] != '' ){
|
|
|
|
$this -> topDn = $_POST['LSsession_topDn'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this -> topDn = $this -> ldapServer['ldap_config']['basedn'];
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
$_SESSION['LSsession_topDn']=$this -> topDn;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
|
|
if ( $this -> loadLSobject($this -> ldapServer['authobject']) ) {
|
|
|
|
$authobject = new $this -> ldapServer['authobject']();
|
|
|
|
$result = $authobject -> searchObject($_POST['LSsession_user'],$this -> topDn);
|
|
|
|
$nbresult=count($result);
|
|
|
|
if ($nbresult==0) {
|
|
|
|
// identifiant incorrect
|
|
|
|
debug('identifiant incorrect');
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1006);
|
|
|
|
}
|
|
|
|
else if ($nbresult>1) {
|
2008-04-25 16:09:27 +02:00
|
|
|
// duplication d'authentité
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1007);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ( $this -> checkUserPwd($result[0],$_POST['LSsession_pwd']) ) {
|
2008-04-25 16:09:27 +02:00
|
|
|
// Authentification réussi
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> LSuserObject = $result[0];
|
|
|
|
$this -> dn = $result[0]->getValue('dn');
|
|
|
|
$this -> rdn = $_POST['LSsession_user'];
|
|
|
|
$this -> loadLSrights();
|
|
|
|
$this -> loadLSaccess();
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_username',$this -> LSuserObject -> getDisplayValue());
|
2008-02-26 18:40:05 +01:00
|
|
|
$_SESSION['LSsession']=get_object_vars($this);
|
2008-02-08 18:39:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1006);
|
|
|
|
debug('mdp incorrect');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1010);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1009);
|
|
|
|
}
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
if ($this -> ldapServerId) {
|
|
|
|
$GLOBALS['Smarty'] -> assign('ldapServerId',$this -> ldapServerId);
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('topDn',$this -> topDn);
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> displayLoginForm();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Définition du serveur Ldap de la session
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Définition du serveur Ldap de la session à partir de son ID dans
|
2008-02-08 18:39:24 +01:00
|
|
|
* le tableau $GLOBALS['LSconfig']['ldap_servers'].
|
|
|
|
*
|
|
|
|
* @param[in] integer Index du serveur Ldap
|
|
|
|
*
|
|
|
|
* @retval boolean True sinon false.
|
|
|
|
*/
|
|
|
|
function setLdapServer($id) {
|
|
|
|
if ( isset($GLOBALS['LSconfig']['ldap_servers'][$id]) ) {
|
|
|
|
$this -> ldapServerId = $id;
|
|
|
|
$this -> ldapServer=$GLOBALS['LSconfig']['ldap_servers'][$id];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Connexion au serveur Ldap
|
|
|
|
*
|
|
|
|
* @retval boolean True sinon false.
|
|
|
|
*/
|
|
|
|
function LSldapConnect() {
|
|
|
|
if ($this -> ldapServer) {
|
2008-04-25 15:48:12 +02:00
|
|
|
include_once($GLOBALS['LSconfig']['NetLDAP2']);
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> loadLSclass('LSldap'))
|
|
|
|
return;
|
|
|
|
$GLOBALS['LSldap'] = new LSldap($this -> ldapServer['ldap_config']);
|
|
|
|
if ($GLOBALS['LSldap'] -> isConnected())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
return $GLOBALS['LSldap'] = new LSldap($this -> ldapServer['ldap_config']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1003);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
/*
|
|
|
|
* Retourne les sous-dns du serveur Ldap courant
|
|
|
|
*
|
|
|
|
* @retval mixed Tableau des subDn, false si une erreur est survenue.
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
function getSubDnLdapServer() {
|
2008-04-25 15:48:12 +02:00
|
|
|
if ( is_array($this ->ldapServer['subDn']) ) {
|
|
|
|
$return=array();
|
|
|
|
foreach($this ->ldapServer['subDn'] as $subDn_name => $subDn_config) {
|
|
|
|
if ($subDn_name == 'LSobject') {
|
|
|
|
if (is_array($subDn_config)) {
|
|
|
|
foreach($subDn_config as $LSobject_name => $LSoject_topDn) {
|
|
|
|
if ($LSoject_topDn) {
|
|
|
|
$topDn = $LSoject_topDn;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$topDn = NULL;
|
|
|
|
}
|
|
|
|
if( $this -> loadLSobject($LSobject_name) ) {
|
|
|
|
if ($subdnobject = new $LSobject_name()) {
|
|
|
|
$tbl_return = $subdnobject -> getSelectArray($topDn);
|
|
|
|
if (is_array($tbl_return)) {
|
|
|
|
$return=array_merge($return,$tbl_return);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1017);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1017);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1004,$LSobject_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1017);
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-04-25 15:48:12 +02:00
|
|
|
$return[$subDn_config] = $subDn_name;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
return $return;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne les options d'une liste déroulante pour le choix du topDn
|
2008-02-08 18:39:24 +01:00
|
|
|
* de connexion au serveur Ldap
|
|
|
|
*
|
2008-04-25 15:48:12 +02:00
|
|
|
* Liste les subdn ($this ->ldapServer['subDn'])
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval string Les options (<option>) pour la sélection du topDn.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
2008-04-25 15:48:12 +02:00
|
|
|
function getSubDnLdapServerOptions($selected=NULL) {
|
|
|
|
$list = $this -> getSubDnLdapServer();
|
|
|
|
if ($list) {
|
|
|
|
$display='';
|
|
|
|
foreach($list as $dn => $txt) {
|
|
|
|
if ($selected && ($selected==$dn)) {
|
|
|
|
$selected_txt = ' selected';
|
2008-02-05 17:11:21 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-04-25 15:48:12 +02:00
|
|
|
$selected_txt = '';
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
$display.="<option value=\"".$dn."\"$selected_txt>".$txt."</option>\n";
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
return $display;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function validSubDnLdapServer($subDn) {
|
|
|
|
$listTopDn = $this -> getSubDnLdapServer();
|
|
|
|
if(is_array($listTopDn)) {
|
|
|
|
foreach($listTopDn as $dn => $txt) {
|
|
|
|
if ($subDn==$dn) {
|
|
|
|
return true;
|
|
|
|
} // end if
|
|
|
|
} // end foreach
|
|
|
|
} // end if
|
|
|
|
return;
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Test un couple LSobject/pwd
|
|
|
|
*
|
|
|
|
* Test un bind sur le serveur avec le dn de l'objet et le mot de passe fourni.
|
|
|
|
*
|
|
|
|
* @param[in] LSobject L'object "user" pour l'authentification
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string Le mot de passe à tester
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'authentification à réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
*/
|
|
|
|
function checkUserPwd($object,$pwd) {
|
|
|
|
return $GLOBALS['LSldap'] -> checkBind($object -> getValue('dn'),$pwd);
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Affiche le formulaire de login
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini les informations pour le template Smarty du formulaire de login.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function displayLoginForm() {
|
|
|
|
$GLOBALS['Smarty'] -> assign('pagetitle',_('Connexion'));
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_action',$_SERVER['PHP_SELF']);
|
|
|
|
if (count($GLOBALS['LSconfig']['ldap_servers'])==1) {
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_ldapserver_style','style="display: none"');
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_label_ldapserver',_('Serveur LDAP'));
|
|
|
|
$ldapservers_name=array();
|
|
|
|
$ldapservers_index=array();
|
|
|
|
foreach($GLOBALS['LSconfig']['ldap_servers'] as $id => $infos) {
|
|
|
|
$ldapservers_index[]=$id;
|
|
|
|
$ldapservers_name[]=$infos['name'];
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_ldapservers_name',$ldapservers_name);
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_ldapservers_index',$ldapservers_index);
|
|
|
|
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_label_level',_('Niveau'));
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_label_user',_('Identifiant'));
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_label_pwd',_('Mot de passe'));
|
|
|
|
$GLOBALS['Smarty'] -> assign('loginform_label_submit',_('Connexion'));
|
|
|
|
|
|
|
|
$this -> addJSscript('LSsession_login.js');
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini le template Smarty à utiliser
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* Remarque : les fichiers de templates doivent se trouver dans le dossier
|
|
|
|
* templates/.
|
|
|
|
*
|
|
|
|
* @param[in] string Le nom du fichier de template
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function setTemplate($template) {
|
|
|
|
$this -> template = $template;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Ajoute un script JS au chargement de la page
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Remarque : les scripts doivents être dans le dossier LS_JS_DIR.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $script Le nom du fichier de script à charger.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function addJSscript($script) {
|
2008-02-26 18:40:05 +01:00
|
|
|
if (in_array($script, $this -> JSscripts))
|
|
|
|
return;
|
2008-02-08 18:39:24 +01:00
|
|
|
$this -> JSscripts[]=$script;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Ajoute une feuille de style au chargement de la page
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Remarque : les scripts doivents être dans le dossiers templates/css/.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] $script Le nom du fichier css à charger.
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function addCssFile($file) {
|
|
|
|
$this -> CssFiles[]=$file;
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
|
|
/*
|
2008-02-08 18:39:24 +01:00
|
|
|
* Affiche le template Smarty
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Charge les dépendances et affiche le template Smarty
|
2008-02-08 18:39:24 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
|
|
|
function displayTemplate() {
|
|
|
|
// JS
|
|
|
|
$JSscript_txt='';
|
|
|
|
foreach ($GLOBALS['defaultJSscipts'] as $script) {
|
|
|
|
$JSscript_txt.="<script src='".LS_JS_DIR.$script."' type='text/javascript'></script>\n";
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach ($this -> JSscripts as $script) {
|
|
|
|
$JSscript_txt.="<script src='".LS_JS_DIR.$script."' type='text/javascript'></script>\n";
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
if ($GLOBALS['LSdebug']['active']) {
|
|
|
|
$JSscript_txt.="<script type='text/javascript'>LSdebug_active = 1;</script>\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$JSscript_txt.="<script type='text/javascript'>LSdebug_active = 0;</script>\n";
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_js',$JSscript_txt);
|
|
|
|
|
|
|
|
// Css
|
2008-02-26 18:40:05 +01:00
|
|
|
$Css_txt="<link rel='stylesheet' type='text/css' href='templates/css/LSdefault.css' />\n";
|
|
|
|
$Css_txt="<link rel='stylesheet' type='text/css' href='templates/css/LSdefault.css' />\n";
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach ($this -> CssFiles as $file) {
|
2008-02-26 18:40:05 +01:00
|
|
|
$Css_txt.="<link rel='stylesheet' type='text/css' href='templates/css/$file' />\n";
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_css',$Css_txt);
|
|
|
|
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSaccess',$this -> LSaccess);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
|
|
|
// Niveau
|
|
|
|
$listTopDn = $this -> getSubDnLdapServer();
|
|
|
|
if (is_array($listTopDn)) {
|
|
|
|
$GLOBALS['Smarty'] -> assign('label_level',_('Niveau'));
|
|
|
|
$LSsession_topDn_index = array();
|
|
|
|
$LSsession_topDn_name = array();
|
|
|
|
foreach($listTopDn as $index => $name) {
|
|
|
|
$LSsession_topDn_index[] = $index;
|
|
|
|
$LSsession_topDn_name[] = $name;
|
|
|
|
}
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_topDn_index',$LSsession_topDn_index);
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_topDn_name',$LSsession_topDn_name);
|
|
|
|
$GLOBALS['Smarty'] -> assign('LSsession_topDn',$this -> topDn);
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
$GLOBALS['LSerror'] -> display();
|
|
|
|
debug_print();
|
|
|
|
if (!$this -> template)
|
|
|
|
$this -> setTemplate('empty.tpl');
|
|
|
|
$GLOBALS['Smarty'] -> display($this -> template);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Charge les droits LS de l'utilisateur
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si le chargement à réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
**/
|
|
|
|
function loadLSrights() {
|
|
|
|
if (is_array($this -> ldapServer['LSadmins'])) {
|
|
|
|
foreach ($this -> ldapServer['LSadmins'] as $topDn => $adminsInfos) {
|
|
|
|
if (is_array($adminsInfos)) {
|
|
|
|
foreach($adminsInfos as $dn => $conf) {
|
|
|
|
if ((isset($conf['attr'])) && (isset($conf['LSobject']))) {
|
|
|
|
if( $this -> loadLSobject($conf['LSobject']) ) {
|
|
|
|
if ($object = new $conf['LSobject']()) {
|
|
|
|
if ($object -> loadData($dn)) {
|
|
|
|
$listDns=$object -> getValue($conf['attr']);
|
|
|
|
if (is_array($listDns)) {
|
|
|
|
if (in_array($this -> dn,$listDns)) {
|
|
|
|
$this -> LSrights['topDn_admin'][] = $topDn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-04-25 16:09:27 +02:00
|
|
|
debug('Impossible de chargé le dn : '.$dn);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2008-04-25 16:09:27 +02:00
|
|
|
debug('Impossible de créer l\'objet de type : '.$conf['LSobject']);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$GLOBALS['LSerror'] -> addErrorCode(1004,$conf['LSobject']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ($this -> dn == $dn) {
|
|
|
|
$this -> LSrights['topDn_admin'][] = $topDn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ( $this -> dn == $adminsInfos ) {
|
|
|
|
$this -> LSrights['topDn_admin'][] = $topDn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Charge les droits d'accès de l'utilisateur pour construire le menu de l'interface
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
function loadLSaccess() {
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($this -> canAccess($this -> LSuserObject -> getType(),$this -> dn)) {
|
|
|
|
$LSaccess = array(
|
|
|
|
'SELF' => array(
|
|
|
|
'label' => _('Mon compte'),
|
|
|
|
'DNs' => $this -> dn
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$LSaccess = array();
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
foreach ($GLOBALS['LSobjects'] as $objecttype => $objectconf) {
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($this -> canAccess($objecttype) ) {
|
2008-02-08 18:39:24 +01:00
|
|
|
$LSaccess[$objecttype] = array (
|
|
|
|
'label' => $objectconf['label'],
|
|
|
|
'Dns' => 'All'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this -> LSaccess = $LSaccess;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Dit si l'utilisateur est admin de le DN spécifié
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @param[in] string DN de l'objet
|
|
|
|
*
|
|
|
|
* @retval boolean True si l'utilisateur est admin sur l'objet, false sinon.
|
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
function isAdmin($dn) {
|
|
|
|
foreach($this -> LSrights['topDn_admin'] as $topDn_admin) {
|
|
|
|
if($dn == $topDn_admin) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if ( isCompatibleDNs($dn,$topDn_admin) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne qui est l'utilisateur par rapport à l'object
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @param[in] string Le DN de l'objet
|
|
|
|
*
|
2008-04-25 16:09:27 +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
|
|
|
*/
|
2008-02-08 18:39:24 +01:00
|
|
|
function whoami($dn) {
|
|
|
|
if ($this -> isAdmin($dn)) {
|
|
|
|
return 'admin';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this -> dn == $dn) {
|
|
|
|
return 'self';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'user';
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le droit de l'utilisateur à accèder à un objet
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
|
|
|
* @param[in] string $right Le type de droit d'accès à tester ('r'/'w')
|
|
|
|
* @param[in] string $attr Le nom de l'attribut auquel on test l'accès
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function canAccess($LSobject,$dn=NULL,$right=NULL,$attr=NULL) {
|
2008-02-08 18:39:24 +01:00
|
|
|
if (!$this -> loadLSobject($LSobject))
|
|
|
|
return;
|
|
|
|
if ($dn) {
|
|
|
|
$whoami = $this -> whoami($dn);
|
|
|
|
}
|
|
|
|
else {
|
2008-02-12 18:59:44 +01:00
|
|
|
$objectdn=$GLOBALS['LSobjects'][$LSobject]['container_dn'].','.$this -> topDn;
|
|
|
|
$whoami = $this -> whoami($objectdn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pour un attribut particulier
|
|
|
|
if ($attr) {
|
|
|
|
if ($attr=='rdn') {
|
|
|
|
$attr=$GLOBALS['LSobjects'][$LSobject]['rdn'];
|
|
|
|
}
|
|
|
|
if (!isset($GLOBALS['LSobjects'][$LSobject]['attrs'][$attr])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($right=='r')||($right=='w')) {
|
|
|
|
if ($GLOBALS['LSobjects'][$LSobject]['attrs'][$attr]['rights'][$whoami]==$right) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ( ($GLOBALS['LSobjects'][$LSobject]['attrs'][$attr]['rights'][$whoami]=='r') || ($GLOBALS['LSobjects'][$LSobject]['attrs'][$attr]['rights'][$whoami]=='w') ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
// Pour un attribut quelconque
|
2008-02-08 18:39:24 +01:00
|
|
|
if (is_array($GLOBALS['LSobjects'][$LSobject]['attrs'])) {
|
|
|
|
if (($right=='r')||($right=='w')) {
|
|
|
|
foreach ($GLOBALS['LSobjects'][$LSobject]['attrs'] as $attr_name => $attr_config) {
|
|
|
|
if ($attr_config['rights'][$whoami]==$right) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ($GLOBALS['LSobjects'][$LSobject]['attrs'] as $attr_name => $attr_config) {
|
|
|
|
if ( ($attr_config['rights'][$whoami]=='r') || ($attr_config['rights'][$whoami]=='w') ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le droit de l'utilisateur à editer à un objet
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
|
|
|
* @param[in] string $attr Le nom de l'attribut auquel on test l'accès
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function canEdit($LSobject,$dn=NULL,$attr=NULL) {
|
|
|
|
return $this -> canAccess($LSobject,$dn,'w',$attr);
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le droit de l'utilisateur à supprimer un objet
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function canRemove($LSobject,$dn) {
|
|
|
|
return $this -> canAccess($LSobject,$dn,'w','rdn');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le droit de l'utilisateur à créer un objet
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
|
|
|
function canCreate($LSobject) {
|
|
|
|
return $this -> canAccess($LSobject,NULL,'w','rdn');
|
2008-02-08 18:39:24 +01:00
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le droit de l'utilisateur à gérer la relation d'objet
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
2008-02-26 18:40:05 +01:00
|
|
|
* @param[in] string $relationName Le nom de la relation avec l'objet
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $right Le type de droit a vérifier ('r' ou 'w')
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
|
|
|
function relationCanAccess($dn,$relationName,$right=NULL) {
|
|
|
|
$LSobject=$this -> LSuserObject -> getType();
|
|
|
|
if (!isset($GLOBALS['LSobjects'][$LSobject]['relations'][$relationName]))
|
|
|
|
return;
|
|
|
|
$whoami = $this -> whoami($dn);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
if (($right=='w') || ($right=='r')) {
|
|
|
|
if ($GLOBALS['LSobjects'][$LSobject]['relations'][$relationName]['rights'][$whoami] == $right) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (($GLOBALS['LSobjects'][$LSobject]['relations'][$relationName]['rights'][$whoami] == 'w') || ($GLOBALS['LSobjects'][$LSobject]['relations'][$relationName]['rights'][$whoami] == 'r')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le droit de l'utilisateur à modifier la relation d'objet
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
2008-02-26 18:40:05 +01:00
|
|
|
* @param[in] string $relationName Le nom de la relation avec l'objet
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
|
|
|
function relationCanEdit($dn,$relationName) {
|
|
|
|
return $this -> relationCanAccess($dn,$relationName,'w');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ajoute un fichier temporaire
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
function addTmpFile($value,$filePath) {
|
|
|
|
$hash = mhash(MHASH_MD5,$value);
|
|
|
|
$this -> tmp_file[$filePath] = $hash;
|
|
|
|
$_SESSION['LSsession']['tmp_file'][$filePath] = $hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le chemin du fichier temporaire si l'existe
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $value La valeur du fichier
|
|
|
|
*
|
|
|
|
* @retval mixed
|
|
|
|
**/
|
|
|
|
function tmpFileExist($value) {
|
|
|
|
$hash = mhash(MHASH_MD5,$value);
|
|
|
|
foreach($this -> tmp_file as $filePath => $contentHash) {
|
|
|
|
if ($hash == $contentHash) {
|
|
|
|
return $filePath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le chemin du fichier temporaire
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le chemin du fichier temporaire qu'il créera à partir de la valeur
|
|
|
|
* s'il n'existe pas déjà.
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $value La valeur du fichier
|
|
|
|
*
|
|
|
|
* @retval mixed
|
|
|
|
**/
|
|
|
|
function getTmpFile($value) {
|
|
|
|
$exist = $this -> tmpFileExist($value);
|
|
|
|
if (!$exist) {
|
|
|
|
$img_path = LS_TMP_DIR .rand().'.tmp';
|
|
|
|
$fp = fopen($img_path, "w");
|
|
|
|
fwrite($fp, $value);
|
|
|
|
fclose($fp);
|
|
|
|
$this -> addTmpFile($value,$img_path);
|
|
|
|
return $img_path;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return $exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supprime les fichiers temporaires
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval void
|
|
|
|
**/
|
|
|
|
function deleteTmpFile($filePath=NULL) {
|
|
|
|
if ($filePath) {
|
|
|
|
@unlink($filePath);
|
|
|
|
unset($this -> tmp_file[$filePath]);
|
|
|
|
unset($_SESSION['LSsession']['tmp_file'][$filePath]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach($this -> tmp_file as $file => $content) {
|
|
|
|
@unlink($file);
|
|
|
|
}
|
|
|
|
$this -> tmp_file = array();
|
|
|
|
$_SESSION['LSsession']['tmp_file'] = array();
|
|
|
|
}
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
2008-02-05 17:11:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|