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.
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
2009-10-31 02:33:01 +01:00
|
|
|
|
/**
|
2008-02-05 17:11:21 +01:00
|
|
|
|
* Gestion des sessions
|
|
|
|
|
*
|
2008-06-05 15:21:18 +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 {
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
// La configuration du serveur Ldap utilisé
|
|
|
|
|
public static $ldapServer = NULL;
|
|
|
|
|
|
|
|
|
|
// L'id du serveur Ldap utilisé
|
|
|
|
|
private static $ldapServerId = NULL;
|
|
|
|
|
|
|
|
|
|
// Le topDn courant
|
|
|
|
|
private static $topDn = NULL;
|
|
|
|
|
|
|
|
|
|
// Le DN de l'utilisateur connecté
|
|
|
|
|
private static $dn = NULL;
|
|
|
|
|
|
|
|
|
|
// Le RDN de l'utilisateur connecté (son identifiant)
|
|
|
|
|
private static $rdn = NULL;
|
|
|
|
|
|
|
|
|
|
// Les LSprofiles de l'utilisateur
|
|
|
|
|
private static $LSprofiles = array();
|
|
|
|
|
|
|
|
|
|
// Les droits d'accès de l'utilisateur
|
|
|
|
|
private static $LSaccess = array();
|
2015-08-21 17:51:52 +02:00
|
|
|
|
|
|
|
|
|
// LSaddons views
|
|
|
|
|
private static $LSaddonsViews = array();
|
|
|
|
|
private static $LSaddonsViewsAccess = array();
|
2009-01-24 18:45:14 +01:00
|
|
|
|
|
|
|
|
|
// Les fichiers temporaires
|
|
|
|
|
private static $tmp_file = array();
|
|
|
|
|
|
2009-03-19 18:42:51 +01:00
|
|
|
|
// Langue et encodage actuel
|
|
|
|
|
private static $lang = NULL;
|
|
|
|
|
private static $encoding = NULL;
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
/*
|
|
|
|
|
* Constante de classe non stockée en session
|
2008-02-05 17:11:21 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
// Le template à afficher
|
|
|
|
|
private static $template = NULL;
|
|
|
|
|
|
|
|
|
|
// Les subDn des serveurs Ldap
|
|
|
|
|
private static $_subDnLdapServer = array();
|
|
|
|
|
|
|
|
|
|
// Affichage Ajax
|
|
|
|
|
private static $ajaxDisplay = false;
|
|
|
|
|
|
|
|
|
|
// Les fichiers JS à charger dans la page
|
|
|
|
|
private static $JSscripts = array();
|
|
|
|
|
|
|
|
|
|
// Les paramètres JS à communiquer dans la page
|
|
|
|
|
private static $_JSconfigParams = array();
|
|
|
|
|
|
|
|
|
|
// Les fichiers CSS à charger dans la page
|
|
|
|
|
private static $CssFiles = array();
|
|
|
|
|
|
|
|
|
|
// L'objet de l'utilisateur connecté
|
|
|
|
|
private static $LSuserObject = NULL;
|
2010-03-10 19:07:58 +01:00
|
|
|
|
|
|
|
|
|
// The LSauht object of the session
|
|
|
|
|
private static $LSauthObject = false;
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2014-11-18 13:16:38 +01:00
|
|
|
|
// User LDAP credentials
|
|
|
|
|
private static $userLDAPcreds = false;
|
|
|
|
|
|
2009-01-21 18:08:09 +01:00
|
|
|
|
/**
|
|
|
|
|
* Include un fichier PHP
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval true si tout c'est bien passé, false sinon
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function includeFile($file) {
|
2013-03-31 05:23:10 +02:00
|
|
|
|
if (file_exists(LS_LOCAL_DIR.'/'.$file)) {
|
|
|
|
|
$file=LS_LOCAL_DIR.'/'.$file;
|
|
|
|
|
}
|
|
|
|
|
elseif (!file_exists($file)) {
|
2009-01-21 18:08:09 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-11-08 16:57:17 +01:00
|
|
|
|
if (defined('LSdebug') && constant('LSdebug')) {
|
2009-01-21 18:08:09 +01:00
|
|
|
|
return include_once($file);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return @include_once($file);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2009-03-25 13:26:32 +01:00
|
|
|
|
* Lancement de LSconfig
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval true si tout c'est bien passé, false sinon
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-03-25 13:26:32 +01:00
|
|
|
|
private static function startLSconfig() {
|
|
|
|
|
if (self :: loadLSclass('LSconfig')) {
|
|
|
|
|
if (LSconfig :: start()) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-03-25 13:26:32 +01:00
|
|
|
|
}
|
|
|
|
|
die("ERROR : Can't load configuration files.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lancement et initialisation de Smarty
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval true si tout c'est bien passé, false sinon
|
|
|
|
|
*/
|
|
|
|
|
private static function startLStemplate() {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
if ( self :: loadLSclass('LStemplate') ) {
|
2013-06-19 03:00:58 +02:00
|
|
|
|
return LStemplate :: start(
|
2013-06-17 23:39:22 +02:00
|
|
|
|
array(
|
|
|
|
|
'smarty_path' => LSconfig :: get('Smarty'),
|
|
|
|
|
'template_dir' => LS_TEMPLATES_DIR,
|
2013-06-19 00:53:26 +02:00
|
|
|
|
'image_dir' => LS_IMAGES_DIR,
|
2013-06-19 03:06:29 +02:00
|
|
|
|
'css_dir' => LS_CSS_DIR,
|
2013-06-17 23:39:22 +02:00
|
|
|
|
'compile_dir' => LS_TMP_DIR,
|
|
|
|
|
'debug' => LSdebug,
|
|
|
|
|
'debug_smarty' => (isset($_REQUEST['LStemplate_debug'])),
|
|
|
|
|
)
|
|
|
|
|
);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
return False;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le topDn de la session
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval string le topDn de la session
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function getTopDn() {
|
2009-10-30 01:03:17 +01:00
|
|
|
|
if (!is_null(self :: $topDn)) {
|
|
|
|
|
return self :: $topDn;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return self :: getRootDn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le rootDn de la session
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval string le rootDn de la session
|
|
|
|
|
*/
|
|
|
|
|
public static function getRootDn() {
|
|
|
|
|
return self :: $ldapServer['ldap_config']['basedn'];
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Initialisation de la gestion des erreurs
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Création de l'objet LSerror
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean true si l'initialisation a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
private static function startLSerror() {
|
|
|
|
|
if(!self :: loadLSclass('LSerror')) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
2009-01-02 17:00:25 +01:00
|
|
|
|
}
|
2014-11-20 12:04:03 +01:00
|
|
|
|
set_error_handler(array('LSerror','errorHandler'),E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
self :: defineLSerrors();
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Chargement d'une classe d'LdapSaisie
|
|
|
|
|
*
|
2009-04-17 12:39:03 +02:00
|
|
|
|
* @param[in] $class Nom de la classe à charger (Exemple : LSpeople)
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function loadLSclass($class,$type='') {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if (class_exists($class))
|
|
|
|
|
return true;
|
|
|
|
|
if($type!='')
|
|
|
|
|
$type=$type.'.';
|
2009-01-24 18:45:14 +01:00
|
|
|
|
return self :: includeFile(LS_CLASS_DIR .'class.'.$type.$class.'.php');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Chargement d'un object LdapSaisie
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @param[in] $object Nom de l'objet à charger
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function loadLSobject($object) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
if(class_exists($object)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2009-01-02 17:00:25 +01:00
|
|
|
|
$error = 0;
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: loadLSclass('LSldapObject');
|
|
|
|
|
if (!self :: loadLSclass($object,'LSobjects')) {
|
2018-09-13 16:12:41 +02:00
|
|
|
|
LSdebug("LSsession :: loadLSobject($object) : Fail to load LSldapObject class");
|
2009-01-02 17:00:25 +01:00
|
|
|
|
$error = 1;
|
2008-04-25 15:48:12 +02:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (!self :: includeFile( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) {
|
2018-09-13 16:12:41 +02:00
|
|
|
|
LSdebug("LSsession :: loadLSobject($object) : Fail to include 'config.LSobjects.$object.php' file");
|
2009-01-02 17:00:25 +01:00
|
|
|
|
$error = 1;
|
|
|
|
|
}
|
2009-03-25 13:26:32 +01:00
|
|
|
|
else {
|
|
|
|
|
if (!LSconfig :: set("LSobjects.$object",$GLOBALS['LSobjects'][$object])) {
|
2018-09-13 16:12:41 +02:00
|
|
|
|
LSdebug("LSsession :: loadLSobject($object) : Fail to LSconfig :: set('LSobjects.$object', \$GLOBALS['LSobjects'][$object])");
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$error = 1;
|
|
|
|
|
}
|
2010-03-05 17:44:07 +01:00
|
|
|
|
else if (isset($GLOBALS['LSobjects'][$object]['LSaddons'])){
|
|
|
|
|
if (is_array($GLOBALS['LSobjects'][$object]['LSaddons'])) {
|
|
|
|
|
foreach ($GLOBALS['LSobjects'][$object]['LSaddons'] as $addon) {
|
|
|
|
|
if (!self :: loadLSaddon($addon)) {
|
2018-09-13 16:12:41 +02:00
|
|
|
|
LSdebug("LSsession :: loadLSobject($object) : Fail to load LSaddon '$addon'");
|
2010-03-05 17:44:07 +01:00
|
|
|
|
$error = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (!self :: loadLSaddon($GLOBALS['LSobjects'][$object]['LSaddons'])) {
|
2018-09-13 16:12:41 +02:00
|
|
|
|
LSdebug("LSsession :: loadLSobject($object) : Fail to load LSaddon '".$GLOBALS['LSobjects'][$object]['LSaddons']."'");
|
2010-03-05 17:44:07 +01:00
|
|
|
|
$error = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-25 13:26:32 +01:00
|
|
|
|
}
|
2009-01-02 17:00:25 +01:00
|
|
|
|
if ($error) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_04',$object);
|
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-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Chargement d'un addons d'LdapSaisie
|
|
|
|
|
*
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function loadLSaddon($addon) {
|
|
|
|
|
if(self :: includeFile(LS_ADDONS_DIR .'LSaddons.'.$addon.'.php')) {
|
|
|
|
|
self :: includeFile(LS_CONF_DIR."LSaddons/config.LSaddons.".$addon.".php");
|
2008-09-25 17:15:33 +02:00
|
|
|
|
if (!call_user_func('LSaddon_'. $addon .'_support')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_02',$addon);
|
2008-09-25 17:15:33 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2010-03-10 17:07:18 +01:00
|
|
|
|
/**
|
|
|
|
|
* Chargement d'une classe d'authentification d'LdapSaisie
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean true si le chargement a reussi, false sinon.
|
|
|
|
|
*/
|
2010-11-24 19:12:21 +01:00
|
|
|
|
public static function loadLSauth() {
|
2010-03-10 17:07:18 +01:00
|
|
|
|
if (self :: loadLSclass('LSauth')) {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
return true;
|
2010-03-10 17:07:18 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_05','LSauth');
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Chargement des addons LdapSaisie
|
|
|
|
|
*
|
|
|
|
|
* Chargement des LSaddons contenue dans la variable
|
|
|
|
|
* $GLOBALS['LSaddons']['loads']
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean true si le chargement a réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function loadLSaddons() {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$conf=LSconfig :: get('LSaddons.loads');
|
|
|
|
|
if(!is_array($conf)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_01',"LSaddons['loads']");
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
|
foreach ($conf as $addon) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: loadLSaddon($addon);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2009-03-19 18:42:51 +01:00
|
|
|
|
/**
|
|
|
|
|
* Défini la locale
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2015-08-21 12:58:50 +02:00
|
|
|
|
public static function setLocale($lang=null,$encoding=null) {
|
|
|
|
|
if (is_null($lang)) {
|
|
|
|
|
if (isset($_REQUEST['lang'])) {
|
|
|
|
|
$lang = $_REQUEST['lang'];
|
|
|
|
|
}
|
|
|
|
|
elseif (isset($_SESSION['LSlang'])) {
|
|
|
|
|
$lang = $_SESSION['LSlang'];
|
|
|
|
|
}
|
|
|
|
|
elseif (isset(self :: $ldapServer['lang'])) {
|
|
|
|
|
$lang = self :: $ldapServer['lang'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$lang = LSconfig :: get('lang');
|
|
|
|
|
}
|
2009-03-19 18:42:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 12:58:50 +02:00
|
|
|
|
if (is_null($enconding)) {
|
|
|
|
|
if (isset($_REQUEST['encoding'])) {
|
|
|
|
|
$encoding = $_REQUEST['encoding'];
|
|
|
|
|
}
|
|
|
|
|
elseif (isset($_SESSION['LSencoding'])) {
|
|
|
|
|
$encoding = $_SESSION['LSencoding'];
|
|
|
|
|
}
|
|
|
|
|
elseif (isset(self :: $ldapServer['encoding'])) {
|
|
|
|
|
$encoding = self :: $ldapServer['encoding'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$encoding = LSconfig :: get('encoding');
|
|
|
|
|
}
|
2009-03-19 18:42:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$_SESSION['LSlang']=$lang;
|
|
|
|
|
self :: $lang=$lang;
|
|
|
|
|
$_SESSION['LSencoding']=$encoding;
|
|
|
|
|
self :: $encoding=$encoding;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (self :: localeExist($lang,$encoding)) {
|
|
|
|
|
if ($encoding) {
|
|
|
|
|
$lang.='.'.$encoding;
|
|
|
|
|
}
|
|
|
|
|
setlocale(LC_ALL, $lang);
|
|
|
|
|
bindtextdomain(LS_TEXT_DOMAIN, LS_I18N_DIR);
|
|
|
|
|
textdomain(LS_TEXT_DOMAIN);
|
|
|
|
|
|
2013-03-31 05:23:10 +02:00
|
|
|
|
self :: includeFile(LS_I18N_DIR.'/'.$lang.'/lang.php');
|
|
|
|
|
|
|
|
|
|
foreach (listFiles(LS_LOCAL_DIR.'/'.LS_I18N_DIR.'/'.$lang,'/^lang.+\.php$/') as $file) {
|
|
|
|
|
include(LS_LOCAL_DIR.'/'.LS_I18N_DIR."/$lang/$file");
|
2011-02-03 17:49:36 +01:00
|
|
|
|
}
|
2009-03-19 18:42:51 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ($encoding && $lang) {
|
|
|
|
|
$lang.='.'.$encoding;
|
|
|
|
|
}
|
|
|
|
|
LSdebug('La locale "'.$lang.'" n\'existe pas, utilisation de la locale par défaut.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne la liste des langues disponibles
|
|
|
|
|
*
|
|
|
|
|
* @retval array Tableau/Liste des langues disponibles
|
|
|
|
|
**/
|
|
|
|
|
public static function getLangList() {
|
|
|
|
|
$list=array('en_US');
|
|
|
|
|
if (self :: $encoding) {
|
2018-01-08 19:08:39 +01:00
|
|
|
|
$regex = '/^([a-zA-Z_]*)\.'.self :: $encoding.'$/';
|
2009-03-19 18:42:51 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2018-01-08 19:08:39 +01:00
|
|
|
|
$regex = '/^([a-zA-Z_]*)$/';
|
2009-03-19 18:42:51 +01:00
|
|
|
|
}
|
|
|
|
|
if ($handle = opendir(LS_I18N_DIR)) {
|
|
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
|
if(is_dir(LS_I18N_DIR.'/'.$file)) {
|
2018-01-08 19:08:39 +01:00
|
|
|
|
if (preg_match($regex,$file,$regs)) {
|
2009-03-19 18:42:51 +01:00
|
|
|
|
if (!in_array($regs[1],$list)) {
|
|
|
|
|
$list[]=$regs[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $list;
|
|
|
|
|
}
|
2009-03-25 18:46:48 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne la langue courante de la session
|
|
|
|
|
*
|
|
|
|
|
* @param[in] boolean Si true, le code langue retourné sera court
|
|
|
|
|
*
|
|
|
|
|
* @retval string La langue de la session
|
|
|
|
|
**/
|
|
|
|
|
public static function getLang($short=false) {
|
|
|
|
|
if ($short) {
|
|
|
|
|
return strtolower(self :: $lang[0].self :: $lang[1]);
|
|
|
|
|
}
|
|
|
|
|
return self :: $lang;
|
|
|
|
|
}
|
2009-03-19 18:42:51 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Vérifie si une locale est disponible
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $lang string La langue (Ex : fr_FR)
|
|
|
|
|
* @param[in] $encoding string L'encodage de caractère (Ex : UTF8)
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si la locale est disponible, False sinon
|
|
|
|
|
**/
|
|
|
|
|
public static function localeExist($lang,$encoding) {
|
|
|
|
|
if ( !$lang && !$encoding ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$locale=$lang.(($encoding)?'.'.$encoding:'');
|
|
|
|
|
if ($locale=='en_US.UTF8') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return (is_dir(LS_I18N_DIR.'/'.$locale));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-24 18:45:14 +01:00
|
|
|
|
* Initialisation LdapSaisie
|
|
|
|
|
*
|
2015-08-21 12:58:50 +02:00
|
|
|
|
* @param[in] $lang string La langue (Ex : fr_FR / Optionnel)
|
|
|
|
|
* @param[in] $encoding string L'encodage de caractère (Ex : UTF8 / Optionnel)
|
|
|
|
|
*
|
2009-01-24 18:45:14 +01:00
|
|
|
|
* @retval boolean True si l'initialisation à réussi, false sinon.
|
|
|
|
|
*/
|
2015-08-21 13:37:43 +02:00
|
|
|
|
public static function initialize($lang=null,$encoding=null) {
|
2015-07-25 18:24:03 +02:00
|
|
|
|
try {
|
|
|
|
|
if (!self :: startLSconfig()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self :: startLSerror();
|
|
|
|
|
self :: startLStemplate();
|
|
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
|
2015-08-21 12:58:50 +02:00
|
|
|
|
self :: setLocale($lang,$encoding);
|
2015-07-25 18:24:03 +02:00
|
|
|
|
|
|
|
|
|
self :: loadLSaddons();
|
|
|
|
|
self :: loadLSauth();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
|
die('LSsession : fail to initialize session. Error : '.$e->getMessage());
|
2009-03-19 18:42:51 +01:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
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-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'initialisation à réussi (utilisateur authentifié), false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function startLSsession() {
|
|
|
|
|
if (!self :: initialize()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 19:07:58 +01:00
|
|
|
|
if(isset($_SESSION['LSsession']['dn']) && !isset($_GET['LSsession_recoverPassword'])) {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
LSdebug('LSsession : Session existente');
|
|
|
|
|
// --------------------- Session existante --------------------- //
|
2014-11-18 13:16:38 +01:00
|
|
|
|
self :: $topDn = $_SESSION['LSsession']['topDn'];
|
|
|
|
|
self :: $dn = $_SESSION['LSsession']['dn'];
|
|
|
|
|
self :: $rdn = $_SESSION['LSsession']['rdn'];
|
|
|
|
|
self :: $ldapServerId = $_SESSION['LSsession']['ldapServerId'];
|
|
|
|
|
self :: $tmp_file = $_SESSION['LSsession']['tmp_file'];
|
|
|
|
|
self :: $userLDAPcreds = $_SESSION['LSsession']['userLDAPcreds'];
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if ( self :: cacheLSprofiles() && !isset($_REQUEST['LSsession_refresh']) ) {
|
|
|
|
|
self :: setLdapServer(self :: $ldapServerId);
|
2010-11-24 19:12:21 +01:00
|
|
|
|
if (!LSauth :: start()) {
|
|
|
|
|
LSdebug("LSsession : can't start LSauth -> stop");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $LSprofiles = $_SESSION['LSsession']['LSprofiles'];
|
|
|
|
|
self :: $LSaccess = $_SESSION['LSsession']['LSaccess'];
|
2015-08-21 17:51:52 +02:00
|
|
|
|
self :: $LSaddonsViewsAccess = $_SESSION['LSsession']['LSaddonsViewsAccess'];
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (!self :: LSldapConnect())
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self :: setLdapServer(self :: $ldapServerId);
|
2010-11-24 19:12:21 +01:00
|
|
|
|
if (!LSauth :: start()) {
|
|
|
|
|
LSdebug("LSsession : can't start LSauth -> stop");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (!self :: LSldapConnect())
|
|
|
|
|
return;
|
|
|
|
|
self :: loadLSprofiles();
|
2008-06-05 15:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if ( self :: cacheSudDn() && (!isset($_REQUEST['LSsession_refresh'])) ) {
|
2010-11-08 17:00:33 +01:00
|
|
|
|
self :: $_subDnLdapServer = ((isset($_SESSION['LSsession_subDnLdapServer']))?$_SESSION['LSsession_subDnLdapServer']:NULL);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!self :: loadLSobject(self :: $ldapServer['authObjectType'])) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 19:36:23 +01:00
|
|
|
|
if (isset($_GET['LSsession_logout'])) {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
LSauth :: logout();
|
2010-03-10 19:36:23 +01:00
|
|
|
|
session_destroy();
|
|
|
|
|
|
|
|
|
|
if (is_array($_SESSION['LSsession']['tmp_file'])) {
|
|
|
|
|
self :: $tmp_file = $_SESSION['LSsession']['tmp_file'];
|
|
|
|
|
}
|
|
|
|
|
self :: deleteTmpFile();
|
|
|
|
|
unset($_SESSION['LSsession']);
|
|
|
|
|
|
|
|
|
|
self :: redirect('index.php');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if ( !self :: cacheLSprofiles() || isset($_REQUEST['LSsession_refresh']) ) {
|
2015-08-21 17:49:04 +02:00
|
|
|
|
self :: loadLSprofiles();
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: loadLSaccess();
|
2015-08-21 17:51:52 +02:00
|
|
|
|
self :: loadLSaddonsViewsAccess();
|
2015-08-21 17:49:04 +02:00
|
|
|
|
$_SESSION['LSsession']=self :: getContextInfos();
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSsession_username',self :: getLSuserObject() -> getDisplayName());
|
2009-01-24 18:45:14 +01:00
|
|
|
|
|
2010-11-08 17:00:33 +01:00
|
|
|
|
if (isset ($_POST['LSsession_topDn']) && $_POST['LSsession_topDn']) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: validSubDnLdapServer($_POST['LSsession_topDn'])) {
|
|
|
|
|
self :: $topDn = $_POST['LSsession_topDn'];
|
|
|
|
|
$_SESSION['LSsession']['topDn'] = $_POST['LSsession_topDn'];
|
|
|
|
|
} // end if
|
|
|
|
|
} // end if
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
// --------------------- Session inexistante --------------------- //
|
2010-03-10 19:07:58 +01:00
|
|
|
|
if (isset($_GET['LSsession_recoverPassword'])) {
|
|
|
|
|
session_destroy();
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
// Session inexistante
|
2009-10-31 02:33:01 +01:00
|
|
|
|
if (isset($_POST['LSsession_ldapserver'])) {
|
|
|
|
|
self :: setLdapServer($_POST['LSsession_ldapserver']);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
self :: setLdapServer(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connexion au serveur LDAP
|
|
|
|
|
if (self :: LSldapConnect()) {
|
|
|
|
|
|
|
|
|
|
// topDn
|
2010-11-16 19:26:49 +01:00
|
|
|
|
if (isset($_POST['LSsession_topDn']) && $_POST['LSsession_topDn'] != '' ){
|
2009-10-31 02:33:01 +01:00
|
|
|
|
self :: $topDn = $_POST['LSsession_topDn'];
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-10-31 02:33:01 +01:00
|
|
|
|
self :: $topDn = self :: $ldapServer['ldap_config']['basedn'];
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
2009-10-31 02:33:01 +01:00
|
|
|
|
$_SESSION['LSsession_topDn']=self :: $topDn;
|
2010-11-24 19:12:21 +01:00
|
|
|
|
|
|
|
|
|
if (!LSauth :: start()) {
|
|
|
|
|
LSdebug("LSsession : can't start LSauth -> stop");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-31 02:33:01 +01:00
|
|
|
|
if (isset($_GET['LSsession_recoverPassword'])) {
|
|
|
|
|
$recoveryPasswordInfos = self :: recoverPasswd(
|
|
|
|
|
$_REQUEST['LSsession_user'],
|
|
|
|
|
$_GET['recoveryHash']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-11-24 19:12:21 +01:00
|
|
|
|
$LSuserObject = LSauth :: forceAuthentication();
|
|
|
|
|
if ($LSuserObject) {
|
|
|
|
|
// Authentication successful
|
|
|
|
|
self :: $LSuserObject = $LSuserObject;
|
|
|
|
|
self :: $dn = $LSuserObject->getValue('dn');
|
|
|
|
|
self :: $rdn = $LSuserObject->getValue('rdn');
|
2014-11-18 13:16:38 +01:00
|
|
|
|
if (isset(self :: $ldapServer['useUserCredentials']) && self :: $ldapServer['useUserCredentials']) {
|
|
|
|
|
self :: $userLDAPcreds = LSauth :: getLDAPcredentials($LSuserObject);
|
|
|
|
|
if (!is_array(self :: $userLDAPcreds)) {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_14');
|
|
|
|
|
self :: $userLDAPcreds = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!LSldap :: reconnectAs(self :: $userLDAPcreds['dn'],self :: $userLDAPcreds['pwd'])) {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_15');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
|
self :: loadLSprofiles();
|
|
|
|
|
self :: loadLSaccess();
|
2015-08-21 17:51:52 +02:00
|
|
|
|
self :: loadLSaddonsViewsAccess();
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSsession_username',self :: getLSuserObject() -> getDisplayName());
|
2010-11-24 19:12:21 +01:00
|
|
|
|
$_SESSION['LSsession']=self :: getContextInfos();
|
|
|
|
|
return true;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-06-05 15:21:18 +02:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
2009-10-31 02:33:01 +01:00
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_09');
|
|
|
|
|
}
|
2010-03-10 19:07:58 +01:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: $ldapServerId) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('ldapServerId',self :: $ldapServerId);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('topDn',self :: $topDn);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (isset($_GET['LSsession_recoverPassword'])) {
|
|
|
|
|
self :: displayRecoverPasswordForm($recoveryPasswordInfos);
|
|
|
|
|
}
|
2010-11-24 19:12:21 +01:00
|
|
|
|
elseif(LSauth :: displayLoginForm()) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: displayLoginForm();
|
|
|
|
|
}
|
2009-10-31 02:33:01 +01:00
|
|
|
|
else {
|
|
|
|
|
self :: setTemplate('blank.tpl');
|
|
|
|
|
LSerror :: addErrorCode('LSsession_10');
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
|
/**
|
|
|
|
|
* Do recover password
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $username string The submited username
|
|
|
|
|
* @param[in] $recoveryHash string The submited recoveryHash
|
|
|
|
|
*
|
|
|
|
|
* @retval array The recoveryPassword infos for template
|
|
|
|
|
**/
|
|
|
|
|
private static function recoverPasswd($username,$recoveryHash) {
|
|
|
|
|
$recoveryPasswordInfos=array();
|
|
|
|
|
if ( self :: loadLSobject(self :: $ldapServer['authObjectType']) ) {
|
|
|
|
|
$authobject = new self :: $ldapServer['authObjectType']();
|
|
|
|
|
if (!empty($recoveryHash)) {
|
|
|
|
|
$filter=Net_LDAP2_Filter::create(
|
|
|
|
|
self :: $ldapServer['recoverPassword']['recoveryHashAttr'],
|
|
|
|
|
'equals',
|
|
|
|
|
$recoveryHash
|
|
|
|
|
);
|
2017-03-23 15:15:31 +01:00
|
|
|
|
$result = $authobject -> listObjects($filter,self :: $topDn,array('onlyAccessible' => false));
|
2009-10-30 01:03:17 +01:00
|
|
|
|
}
|
2010-03-10 19:07:58 +01:00
|
|
|
|
elseif (!empty($username)) {
|
2009-10-30 01:03:17 +01:00
|
|
|
|
$result = $authobject -> searchObject(
|
|
|
|
|
$username,
|
|
|
|
|
self :: $topDn,
|
2017-03-23 15:15:31 +01:00
|
|
|
|
self :: $ldapServer['authObjectFilter'],
|
|
|
|
|
array('onlyAccessible' => false)
|
2009-10-30 01:03:17 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2010-03-10 19:07:58 +01:00
|
|
|
|
else {
|
|
|
|
|
return $recoveryPasswordInfos;
|
|
|
|
|
}
|
2009-10-30 01:03:17 +01:00
|
|
|
|
|
|
|
|
|
$nbresult=count($result);
|
|
|
|
|
|
|
|
|
|
if ($nbresult==0) {
|
|
|
|
|
LSdebug('hash/username incorrect');
|
|
|
|
|
LSerror :: addErrorCode('LSsession_06');
|
|
|
|
|
}
|
|
|
|
|
elseif ($nbresult>1) {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_07');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$rdn = $result[0] -> getValue('rdn');
|
|
|
|
|
$username = $rdn[0];
|
|
|
|
|
LSdebug('Recover : Id trouvé : '.$username);
|
|
|
|
|
if (self :: $ldapServer['recoverPassword']) {
|
|
|
|
|
if (self :: loadLSaddon('mail')) {
|
|
|
|
|
LSdebug('Récupération active');
|
|
|
|
|
$user=$result[0];
|
|
|
|
|
$emailAddress = $user -> getValue(self :: $ldapServer['recoverPassword']['mailAttr']);
|
|
|
|
|
$emailAddress = $emailAddress[0];
|
|
|
|
|
|
|
|
|
|
if (checkEmail($emailAddress)) {
|
|
|
|
|
LSdebug('Email : '.$emailAddress);
|
|
|
|
|
self :: $dn = $user -> getDn();
|
|
|
|
|
|
|
|
|
|
// 1ère étape : envoie du recoveryHash
|
|
|
|
|
if (empty($recoveryHash)) {
|
|
|
|
|
$hash=self :: recoverPasswdFirstStep($user);
|
|
|
|
|
if ($hash) {
|
|
|
|
|
if (self :: recoverPasswdSendMail($emailAddress,1,$hash)) {
|
|
|
|
|
// Mail a bien été envoyé
|
|
|
|
|
$recoveryPasswordInfos['recoveryHashMail']=$emailAddress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 2nd étape : génération du mot de passe + envoie par mail
|
|
|
|
|
else {
|
|
|
|
|
$pwd=self :: recoverPasswdSecondStep($user);
|
|
|
|
|
if ($pwd) {
|
|
|
|
|
if (self :: recoverPasswdSendMail($emailAddress,2,$pwd)){
|
|
|
|
|
// Mail a bien été envoyé
|
|
|
|
|
$recoveryPasswordInfos['newPasswordMail']=$emailAddress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_19');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_18');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $recoveryPasswordInfos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send recover password mail
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $mail string The user's mail
|
|
|
|
|
* @param[in] $step integer The step
|
|
|
|
|
* @param[in] $info string The info for formatted message
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True on success or False
|
|
|
|
|
**/
|
|
|
|
|
private static function recoverPasswdSendMail($mail,$step,$info) {
|
|
|
|
|
// Header des mails
|
|
|
|
|
$sendParams=array();
|
|
|
|
|
if (self :: $ldapServer['recoverPassword']['recoveryEmailSender']) {
|
|
|
|
|
$sendParams['From']=self :: $ldapServer['recoverPassword']['recoveryEmailSender'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($step==1) {
|
|
|
|
|
if ($_SERVER['HTTPS']=='on') {
|
|
|
|
|
$recovery_url='https://';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$recovery_url='http://';
|
|
|
|
|
}
|
|
|
|
|
$recovery_url .= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'&recoveryHash='.$info;
|
|
|
|
|
|
|
|
|
|
$subject = self :: $ldapServer['recoverPassword']['recoveryHashMail']['subject'];
|
|
|
|
|
$msg = getFData(
|
|
|
|
|
self :: $ldapServer['recoverPassword']['recoveryHashMail']['msg'],
|
|
|
|
|
$recovery_url
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$subject = self :: $ldapServer['recoverPassword']['newPasswordMail']['subject'];
|
|
|
|
|
$msg = getFData(
|
|
|
|
|
self :: $ldapServer['recoverPassword']['newPasswordMail']['msg'],
|
|
|
|
|
$info
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sendMail($mail,$subject,$msg,$sendParams)) {
|
|
|
|
|
LSdebug("Problème durant l'envoie du mail");
|
|
|
|
|
LSerror :: addErrorCode('LSsession_20',4);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do first step of recovering password
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $user LSldapObject The LSldapObject of the user
|
|
|
|
|
*
|
|
|
|
|
* @retval string|False The recory hash on success or False
|
|
|
|
|
**/
|
|
|
|
|
private static function recoverPasswdFirstStep($user) {
|
|
|
|
|
// Generer un hash
|
|
|
|
|
$rdn=$user -> getValue('rdn');
|
|
|
|
|
$rdn = $rdn[0];
|
|
|
|
|
$recovery_hash = md5($rdn . strval(time()) . strval(rand()));
|
|
|
|
|
|
|
|
|
|
$lostPasswdForm = $user -> getForm('lostPassword');
|
|
|
|
|
$lostPasswdForm -> setPostData(
|
|
|
|
|
array(
|
|
|
|
|
self :: $ldapServer['recoverPassword']['recoveryHashAttr'] => $recovery_hash
|
|
|
|
|
)
|
|
|
|
|
,true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if($lostPasswdForm -> validate()) {
|
|
|
|
|
if ($user -> updateData('lostPassword')) {
|
|
|
|
|
// recoveryHash de l'utilisateur mis à jour
|
|
|
|
|
return $recovery_hash;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Erreur durant la mise à jour de l'objet
|
|
|
|
|
LSdebug("Erreur durant la mise à jour de l'objet");
|
|
|
|
|
LSerror :: addErrorCode('LSsession_20',6);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Erreur durant la validation du formulaire de modification de perte de password
|
|
|
|
|
LSdebug("Erreur durant la validation du formulaire de modification de perte de password");
|
|
|
|
|
LSerror :: addErrorCode('LSsession_20',5);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do second step of recovering password
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $user LSldapObject The LSldapObject of the user
|
|
|
|
|
*
|
|
|
|
|
* @retval string|False The new password on success or False
|
|
|
|
|
**/
|
|
|
|
|
private static function recoverPasswdSecondStep($user) {
|
|
|
|
|
$attr=$user -> attrs[self :: $ldapServer['authObjectTypeAttrPwd']];
|
|
|
|
|
if ($attr instanceof LSattribute) {
|
|
|
|
|
$mdp = generatePassword(
|
|
|
|
|
$attr -> config['html_options']['chars'],
|
|
|
|
|
$attr -> config['html_options']['lenght']
|
|
|
|
|
);
|
|
|
|
|
LSdebug('Nvx mpd : '.$mdp);
|
|
|
|
|
$lostPasswdForm = $user -> getForm('lostPassword');
|
|
|
|
|
$lostPasswdForm -> setPostData(
|
|
|
|
|
array(
|
|
|
|
|
self :: $ldapServer['recoverPassword']['recoveryHashAttr'] => array(''),
|
|
|
|
|
self :: $ldapServer['authObjectTypeAttrPwd'] => array($mdp)
|
|
|
|
|
)
|
|
|
|
|
,true
|
|
|
|
|
);
|
|
|
|
|
if($lostPasswdForm -> validate()) {
|
|
|
|
|
if ($user -> updateData('lostPassword')) {
|
|
|
|
|
return $mdp;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Erreur durant la mise à jour de l'objet
|
|
|
|
|
LSdebug("Erreur durant la mise à jour de l'objet");
|
|
|
|
|
LSerror :: addErrorCode('LSsession_20',3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Erreur durant la validation du formulaire de modification de perte de password
|
|
|
|
|
LSdebug("Erreur durant la validation du formulaire de modification de perte de password");
|
|
|
|
|
LSerror :: addErrorCode('LSsession_20',2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// l'attribut password n'existe pas
|
|
|
|
|
LSdebug("L'attribut password n'existe pas");
|
|
|
|
|
LSerror :: addErrorCode('LSsession_20',1);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
/**
|
|
|
|
|
* Retourne les informations du contexte
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
|
*
|
|
|
|
|
* @retval array Tableau associatif des informations du contexte
|
|
|
|
|
*/
|
|
|
|
|
private static function getContextInfos() {
|
|
|
|
|
return array(
|
|
|
|
|
'tmp_file' => self :: $tmp_file,
|
|
|
|
|
'topDn' => self :: $topDn,
|
|
|
|
|
'dn' => self :: $dn,
|
|
|
|
|
'rdn' => self :: $rdn,
|
2014-11-18 13:16:38 +01:00
|
|
|
|
'userLDAPcreds' => self :: $userLDAPcreds,
|
2009-01-24 18:45:14 +01:00
|
|
|
|
'ldapServerId' => self :: $ldapServerId,
|
|
|
|
|
'ldapServer' => self :: $ldapServer,
|
|
|
|
|
'LSprofiles' => self :: $LSprofiles,
|
2015-08-21 17:51:52 +02:00
|
|
|
|
'LSaccess' => self :: $LSaccess,
|
|
|
|
|
'LSaddonsViewsAccess' => self :: $LSaddonsViewsAccess
|
2009-01-24 18:45:14 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne l'objet de l'utilisateur connecté
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
|
*
|
|
|
|
|
* @retval mixed L'objet de l'utilisateur connecté ou false si il n'a pas put
|
|
|
|
|
* être créé
|
|
|
|
|
*/
|
|
|
|
|
public static function getLSuserObject($dn=null) {
|
|
|
|
|
if ($dn) {
|
|
|
|
|
self :: $dn = $dn;
|
|
|
|
|
}
|
|
|
|
|
if (!self :: $LSuserObject) {
|
|
|
|
|
if (self :: loadLSobject(self :: $ldapServer['authObjectType'])) {
|
|
|
|
|
self :: $LSuserObject = new self :: $ldapServer['authObjectType']();
|
|
|
|
|
self :: $LSuserObject -> loadData(self :: $dn);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
|
|
|
|
return self :: $LSuserObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le DN de l'utilisateur connecté
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com
|
|
|
|
|
*
|
|
|
|
|
* @retval string Le DN de l'utilisateur connecté
|
|
|
|
|
*/
|
|
|
|
|
public static function getLSuserObjectDn() {
|
|
|
|
|
return self :: $dn;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-07-29 15:45:02 +02:00
|
|
|
|
/**
|
|
|
|
|
* Modifie l'utilisateur connecté à la volé
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $object Mixed L'objet Ldap du nouvel utilisateur
|
|
|
|
|
* le type doit correspondre à
|
2009-01-24 18:45:14 +01:00
|
|
|
|
* self :: $ldapServer['authObjectType']
|
2008-07-29 15:45:02 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval boolean True en cas de succès, false sinon
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function changeAuthUser($object) {
|
|
|
|
|
if ($object instanceof self :: $ldapServer['authObjectType']) {
|
|
|
|
|
self :: $dn = $object -> getDn();
|
2008-07-29 15:45:02 +02:00
|
|
|
|
$rdn = $object -> getValue('rdn');
|
|
|
|
|
if(is_array($rdn)) {
|
|
|
|
|
$rdn = $rdn[0];
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $rdn = $rdn;
|
|
|
|
|
self :: $LSuserObject = $object;
|
2008-07-29 15:45:02 +02:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if(self :: loadLSprofiles()) {
|
|
|
|
|
self :: loadLSaccess();
|
2015-08-21 17:51:52 +02:00
|
|
|
|
self :: loadLSaddonsViewsAccess();
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$_SESSION['LSsession']=self :: getContextInfos();
|
2008-07-29 15:45:02 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Définition du serveur Ldap de la session
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Définition du serveur Ldap de la session à partir de son ID dans
|
2009-03-25 18:46:48 +01:00
|
|
|
|
* le tableau LSconfig :: get('ldap_servers').
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @param[in] integer Index du serveur Ldap
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True sinon false.
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function setLdapServer($id) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$conf = LSconfig :: get("ldap_servers.$id");
|
|
|
|
|
if ( is_array($conf) ) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $ldapServerId = $id;
|
2009-03-25 13:26:32 +01:00
|
|
|
|
self :: $ldapServer = $conf;
|
2009-03-19 18:42:51 +01:00
|
|
|
|
self :: setLocale();
|
2014-12-12 22:11:32 +01:00
|
|
|
|
self :: setGlobals();
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Connexion au serveur Ldap
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True sinon false.
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function LSldapConnect() {
|
|
|
|
|
if (self :: $ldapServer) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
self :: includeFile(LSconfig :: get('NetLDAP2'));
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (!self :: loadLSclass('LSldap')) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
2008-12-05 15:38:42 +01:00
|
|
|
|
}
|
2014-11-18 13:16:38 +01:00
|
|
|
|
if (self :: $dn && isset(self :: $ldapServer['useUserCredentials']) && self :: $ldapServer['useUserCredentials']) {
|
|
|
|
|
LSldap :: reconnectAs(self :: $userLDAPcreds['dn'], self :: $userLDAPcreds['pwd'],self :: $ldapServer['ldap_config']);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSldap :: connect(self :: $ldapServer['ldap_config']);
|
|
|
|
|
}
|
2009-01-25 15:37:03 +01:00
|
|
|
|
if (LSldap :: isConnected()) {
|
2008-12-05 15:38:42 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_03');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 00:34:06 +01:00
|
|
|
|
/**
|
|
|
|
|
* Use this function to know if subDn is enabled for the curent LdapServer
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean
|
|
|
|
|
**/
|
|
|
|
|
public static function subDnIsEnabled() {
|
|
|
|
|
if (!isset(self :: $ldapServer['subDn'])) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( !is_array(self :: $ldapServer['subDn']) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
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.
|
|
|
|
|
*/
|
2010-11-16 11:50:18 +01:00
|
|
|
|
public static function getSubDnLdapServer($login=false) {
|
|
|
|
|
$login=(bool)$login;
|
|
|
|
|
if (self :: cacheSudDn() && isset(self :: $_subDnLdapServer[self :: $ldapServerId][$login])) {
|
2010-11-26 14:46:48 +01:00
|
|
|
|
return self :: $_subDnLdapServer[self :: $ldapServerId][$login];
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
2009-10-26 00:34:06 +01:00
|
|
|
|
if (!self::subDnIsEnabled()) {
|
2009-01-02 17:00:25 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$return=array();
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $ldapServer['subDn'] as $subDn_name => $subDn_config) {
|
2010-11-25 12:27:46 +01:00
|
|
|
|
if ($login && isset($subDn_config['nologin']) && $subDn_config['nologin']) continue;
|
2009-01-02 17:00:25 +01:00
|
|
|
|
if ($subDn_name == 'LSobject') {
|
|
|
|
|
if (is_array($subDn_config)) {
|
|
|
|
|
foreach($subDn_config as $LSobject_name => $LSoject_config) {
|
2010-11-25 12:27:46 +01:00
|
|
|
|
if (isset($LSoject_config['basedn']) && !empty($LSoject_config['basedn'])) {
|
2009-01-03 23:00:32 +01:00
|
|
|
|
$basedn = $LSoject_config['basedn'];
|
2009-01-02 17:00:25 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-10-30 01:03:17 +01:00
|
|
|
|
$basedn = self::getRootDn();
|
2009-01-03 23:00:32 +01:00
|
|
|
|
}
|
2010-11-25 12:27:46 +01:00
|
|
|
|
if (isset($LSoject_config['displayName']) && !empty($LSoject_config['displayName'])) {
|
2009-01-07 20:58:08 +01:00
|
|
|
|
$displayName = $LSoject_config['displayName'];
|
2009-01-03 23:00:32 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-07 20:58:08 +01:00
|
|
|
|
$displayName = NULL;
|
2009-01-02 17:00:25 +01:00
|
|
|
|
}
|
2017-03-23 16:26:28 +01:00
|
|
|
|
$sparams = array();
|
|
|
|
|
$sparams['onlyAccessible'] = (isset($LSoject_config['onlyAccessible'])?$LSoject_config['onlyAccessible']:False);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if( self :: loadLSobject($LSobject_name) ) {
|
2009-01-02 17:00:25 +01:00
|
|
|
|
if ($subdnobject = new $LSobject_name()) {
|
2017-03-23 16:26:28 +01:00
|
|
|
|
$tbl_return = $subdnobject -> getSelectArray(NULL,$basedn,$displayName,false,false,NULL,$sparams);
|
2009-01-02 17:00:25 +01:00
|
|
|
|
if (is_array($tbl_return)) {
|
|
|
|
|
$return=array_merge($return,$tbl_return);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_17',3);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_17',2);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: addErrorCode('LSsession_17',1);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-02 17:00:25 +01:00
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if ((isCompatibleDNs($subDn_config['dn'],self :: $ldapServer['ldap_config']['basedn']))&&($subDn_config['dn']!="")) {
|
2009-03-20 11:42:45 +01:00
|
|
|
|
$return[$subDn_config['dn']] = __($subDn_name);
|
2009-01-02 17:00:25 +01:00
|
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: cacheSudDn()) {
|
2010-11-16 11:50:18 +01:00
|
|
|
|
self :: $_subDnLdapServer[self :: $ldapServerId][$login]=$return;
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$_SESSION['LSsession_subDnLdapServer'] = self :: $_subDnLdapServer;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2009-01-02 17:00:25 +01:00
|
|
|
|
return $return;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne la liste de subDn du serveur Ldap utilise
|
|
|
|
|
* trié par la profondeur dans l'arboressence (ordre décroissant)
|
|
|
|
|
*
|
|
|
|
|
* @return array() Tableau des subDn trié
|
|
|
|
|
*/
|
2010-11-16 11:50:18 +01:00
|
|
|
|
public static function getSortSubDnLdapServer($login=false) {
|
|
|
|
|
$subDnLdapServer = self :: getSubDnLdapServer($login);
|
2008-06-20 17:52:15 +02:00
|
|
|
|
if (!$subDnLdapServer) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2008-06-18 14:27:35 +02:00
|
|
|
|
uksort($subDnLdapServer,"compareDn");
|
|
|
|
|
return $subDnLdapServer;
|
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +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
|
|
|
|
|
*
|
2009-01-24 18:45:14 +01:00
|
|
|
|
* Liste les subdn (self :: $ldapServer['subDn'])
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval string Les options (<option>) pour la sélection du topDn.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2010-11-16 11:50:18 +01:00
|
|
|
|
public static function getSubDnLdapServerOptions($selected=NULL,$login=false) {
|
|
|
|
|
$list = self :: getSubDnLdapServer($login);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
if ($list) {
|
2008-07-19 21:14:57 +02:00
|
|
|
|
asort($list);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
/**
|
|
|
|
|
* Vérifie qu'un subDn est déclaré
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string Un subDn
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si le subDn existe, False sinon
|
|
|
|
|
*/
|
|
|
|
|
public static function validSubDnLdapServer($subDn) {
|
|
|
|
|
$listTopDn = self :: getSubDnLdapServer();
|
2008-04-25 15:48:12 +02:00
|
|
|
|
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-05-15 12:56:55 +02: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-06-05 15:21:18 +02:00
|
|
|
|
* @param[in] string Le mot de passe à tester
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'authentification à réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function checkUserPwd($object,$pwd) {
|
2009-01-25 15:37:03 +01:00
|
|
|
|
return LSldap :: checkBind($object -> getValue('dn'),$pwd);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Affiche le formulaire de login
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Défini les informations pour le template Smarty du formulaire de login.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function displayLoginForm() {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('pagetitle',_('Connection'));
|
2008-05-14 11:24:47 +02:00
|
|
|
|
if (isset($_GET['LSsession_logout'])) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('loginform_action','index.php');
|
2008-05-14 11:24:47 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('loginform_action',$_SERVER['REQUEST_URI']);
|
2008-05-14 11:24:47 +02:00
|
|
|
|
}
|
2009-03-25 13:26:32 +01:00
|
|
|
|
if (count(LSconfig :: get('ldap_servers'))==1) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('loginform_ldapserver_style','style="display: none"');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('loginform_label_ldapserver',_('LDAP server'));
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$ldapservers_name=array();
|
|
|
|
|
$ldapservers_index=array();
|
2009-03-25 13:26:32 +01:00
|
|
|
|
foreach(LSconfig :: get('ldap_servers') as $id => $infos) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
$ldapservers_index[]=$id;
|
2009-03-20 11:42:45 +01:00
|
|
|
|
$ldapservers_name[]=__($infos['name']);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('loginform_ldapservers_name',$ldapservers_name);
|
|
|
|
|
LStemplate :: assign('loginform_ldapservers_index',$ldapservers_index);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('loginform_label_level',_('Level'));
|
|
|
|
|
LStemplate :: assign('loginform_label_user',_('Identifier'));
|
|
|
|
|
LStemplate :: assign('loginform_label_pwd',_('Password'));
|
|
|
|
|
LStemplate :: assign('loginform_label_submit',_('Connect'));
|
|
|
|
|
LStemplate :: assign('loginform_label_recoverPassword',_('Forgot your password ?'));
|
2008-06-05 15:21:18 +02:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: setTemplate('login.tpl');
|
|
|
|
|
self :: addJSscript('LSsession_login.js');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Affiche le formulaire de récupération de mot de passe
|
|
|
|
|
*
|
|
|
|
|
* Défini les informations pour le template Smarty du formulaire de
|
|
|
|
|
* récupération de mot de passe
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $infos array() Information sur le status du processus de
|
|
|
|
|
* recouvrement de mot de passe
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function displayRecoverPasswordForm($recoveryPasswordInfos) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('pagetitle',_('Recovery of your credentials'));
|
|
|
|
|
LStemplate :: assign('recoverpasswordform_action','index.php?LSsession_recoverPassword');
|
2008-06-05 15:21:18 +02:00
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
|
if (count(LSconfig :: get('ldap_servers'))==1) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('recoverpasswordform_ldapserver_style','style="display: none"');
|
2008-06-05 15:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('recoverpasswordform_label_ldapserver',_('LDAP server'));
|
2008-06-05 15:21:18 +02:00
|
|
|
|
$ldapservers_name=array();
|
|
|
|
|
$ldapservers_index=array();
|
2009-03-25 13:26:32 +01:00
|
|
|
|
foreach(LSconfig :: get('ldap_servers') as $id => $infos) {
|
2008-06-05 15:21:18 +02:00
|
|
|
|
$ldapservers_index[]=$id;
|
|
|
|
|
$ldapservers_name[]=$infos['name'];
|
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('recoverpasswordform_ldapservers_name',$ldapservers_name);
|
|
|
|
|
LStemplate :: assign('recoverpasswordform_ldapservers_index',$ldapservers_index);
|
2008-06-05 15:21:18 +02:00
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('recoverpasswordform_label_user',_('Identifier'));
|
|
|
|
|
LStemplate :: assign('recoverpasswordform_label_submit',_('Validate'));
|
|
|
|
|
LStemplate :: assign('recoverpasswordform_label_back',_('Back'));
|
2008-06-05 15:21:18 +02:00
|
|
|
|
|
2009-02-12 13:38:56 +01:00
|
|
|
|
$recoverpassword_msg = _('Please fill the identifier field to proceed recovery procedure');
|
2008-06-19 16:20:59 +02:00
|
|
|
|
|
2008-06-05 15:21:18 +02:00
|
|
|
|
if (isset($recoveryPasswordInfos['recoveryHashMail'])) {
|
2008-06-19 16:20:59 +02:00
|
|
|
|
$recoverpassword_msg = getFData(
|
2009-02-12 13:38:56 +01:00
|
|
|
|
_("An email has been sent to %{mail}. " .
|
|
|
|
|
"Please follow the instructions on it."),
|
2008-06-19 16:20:59 +02:00
|
|
|
|
$recoveryPasswordInfos['recoveryHashMail']
|
2008-06-05 15:21:18 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($recoveryPasswordInfos['newPasswordMail'])) {
|
2008-06-19 16:20:59 +02:00
|
|
|
|
$recoverpassword_msg = getFData(
|
2009-02-12 13:38:56 +01:00
|
|
|
|
_("Your new password has been sent to %{mail}. "),
|
2008-06-19 16:20:59 +02:00
|
|
|
|
$recoveryPasswordInfos['newPasswordMail']
|
2008-06-05 15:21:18 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('recoverpassword_msg',$recoverpassword_msg);
|
2008-06-19 16:20:59 +02:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: setTemplate('recoverpassword.tpl');
|
|
|
|
|
self :: addJSscript('LSsession_recoverPassword.js');
|
2008-06-05 15:21:18 +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
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function setTemplate($template) {
|
|
|
|
|
self :: $template = $template;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Ajoute un script JS au chargement de la page
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Remarque : les scripts doivents être dans le dossier LS_JS_DIR.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @param[in] $script Le nom du fichier de script à charger.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function addJSscript($file,$path=NULL) {
|
2008-07-18 16:02:46 +02:00
|
|
|
|
$script=array(
|
|
|
|
|
'file' => $file,
|
|
|
|
|
'path' => $path
|
|
|
|
|
);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $JSscripts[$path.$file]=$script;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-07-18 16:02:46 +02:00
|
|
|
|
/**
|
|
|
|
|
* Ajouter un paramètre de configuration Javascript
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $name string Nom de la variable de configuration
|
|
|
|
|
* @param[in] $val mixed Valeur de la variable de configuration
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function addJSconfigParam($name,$val) {
|
|
|
|
|
self :: $_JSconfigParams[$name]=$val;
|
2008-07-18 16:02:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Ajoute une feuille de style au chargement de la page
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @param[in] $script Le nom du fichier css à charger.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function addCssFile($file,$path=NULL) {
|
2013-06-19 03:06:29 +02:00
|
|
|
|
if ($path) {
|
|
|
|
|
$file = $path.$file;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$file = LStemplate :: getCSSPath($file);
|
|
|
|
|
}
|
|
|
|
|
self :: $CssFiles[$file]=$file;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-05 17:11:21 +01:00
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-08 18:39:24 +01:00
|
|
|
|
* Affiche le template Smarty
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Charge les dépendances et affiche le template Smarty
|
2008-02-08 18:39:24 +01:00
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function displayTemplate() {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
// JS
|
|
|
|
|
$JSscript_txt='';
|
|
|
|
|
foreach ($GLOBALS['defaultJSscipts'] as $script) {
|
2018-05-22 18:47:08 +02:00
|
|
|
|
$nocache = LStemplate :: getNoCacheFileValue(LS_JS_DIR.$script);
|
|
|
|
|
$JSscript_txt.="<script src='".LS_JS_DIR.$script."?nocache=$nocache' type='text/javascript'></script>\n";
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach (self :: $JSscripts as $script) {
|
2008-07-18 16:02:46 +02:00
|
|
|
|
if (!$script['path']) {
|
|
|
|
|
$script['path']=LS_JS_DIR;
|
|
|
|
|
}
|
2008-09-26 20:03:56 +02:00
|
|
|
|
else {
|
|
|
|
|
$script['path'].='/';
|
|
|
|
|
}
|
2018-05-22 18:47:08 +02:00
|
|
|
|
$nocache = LStemplate :: getNoCacheFileValue($script['path'].$script['file']);
|
|
|
|
|
$JSscript_txt.="<script src='".$script['path'].$script['file']."?nocache=$nocache' type='text/javascript'></script>\n";
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-07-18 16:02:46 +02:00
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$KAconf = LSconfig :: get('keepLSsessionActive');
|
2009-02-21 12:42:26 +01:00
|
|
|
|
if (
|
|
|
|
|
(
|
|
|
|
|
(!isset(self :: $ldapServer['keepLSsessionActive']))
|
|
|
|
|
&&
|
2009-03-25 13:26:32 +01:00
|
|
|
|
(!($KAconf === false))
|
2009-02-21 12:42:26 +01:00
|
|
|
|
)
|
|
|
|
|
||
|
|
|
|
|
(self :: $ldapServer['keepLSsessionActive'])
|
|
|
|
|
) {
|
2009-02-20 15:05:22 +01:00
|
|
|
|
self :: addJSconfigParam('keepLSsessionActive',ini_get('session.gc_maxlifetime'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 11:06:10 +02:00
|
|
|
|
LStemplate :: assign('LSjsConfig',base64_encode(json_encode(self :: $_JSconfigParams)));
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
2009-03-25 13:26:32 +01:00
|
|
|
|
if (LSdebug) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$JSscript_txt.="<script type='text/javascript'>LSdebug_active = 1;</script>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$JSscript_txt.="<script type='text/javascript'>LSdebug_active = 0;</script>\n";
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSsession_js',$JSscript_txt);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
|
|
|
|
// Css
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: addCssFile("LSdefault.css");
|
2015-01-08 15:15:40 +01:00
|
|
|
|
if (isset($GLOBALS['defaultCSSfiles']) && is_array($GLOBALS['defaultCSSfiles'])) {
|
|
|
|
|
foreach ($GLOBALS['defaultCSSfiles'] as $file) {
|
|
|
|
|
self :: addCssFile($file);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-02 17:00:25 +01:00
|
|
|
|
$Css_txt='';
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach (self :: $CssFiles as $file) {
|
2018-05-22 18:47:08 +02:00
|
|
|
|
$nocache = LStemplate :: getNoCacheFileValue($file);
|
|
|
|
|
$Css_txt.="<link rel='stylesheet' type='text/css' href='".$file."?nocache=$nocache' />\n";
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSsession_css',$Css_txt);
|
2008-06-21 18:16:15 +02:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (isset(self :: $LSaccess[self :: $topDn])) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSaccess',self :: $LSaccess[self :: $topDn]);
|
2009-01-02 17:00:25 +01:00
|
|
|
|
}
|
2015-08-21 17:51:52 +02:00
|
|
|
|
LStemplate :: assign('LSaddonsViewsAccess',self :: $LSaddonsViewsAccess);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
|
|
|
|
|
// Niveau
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$listTopDn = self :: getSubDnLdapServer();
|
2008-04-25 15:48:12 +02:00
|
|
|
|
if (is_array($listTopDn)) {
|
2008-07-19 21:14:57 +02:00
|
|
|
|
asort($listTopDn);
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('label_level',self :: getSubDnLabel());
|
|
|
|
|
LStemplate :: assign('_refresh',_('Refresh'));
|
2008-04-25 15:48:12 +02:00
|
|
|
|
$LSsession_topDn_index = array();
|
|
|
|
|
$LSsession_topDn_name = array();
|
|
|
|
|
foreach($listTopDn as $index => $name) {
|
|
|
|
|
$LSsession_topDn_index[] = $index;
|
|
|
|
|
$LSsession_topDn_name[] = $name;
|
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSsession_subDn_indexes',$LSsession_topDn_index);
|
|
|
|
|
LStemplate :: assign('LSsession_subDn_names',$LSsession_topDn_name);
|
|
|
|
|
LStemplate :: assign('LSsession_subDn',self :: $topDn);
|
|
|
|
|
LStemplate :: assign('LSsession_subDnName',self :: getSubDnName());
|
2008-04-25 15:48:12 +02:00
|
|
|
|
}
|
2009-03-19 18:42:51 +01:00
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSlanguages',self :: getLangList());
|
|
|
|
|
LStemplate :: assign('LSlang',self :: $lang);
|
|
|
|
|
LStemplate :: assign('LSencoding',self :: $encoding);
|
|
|
|
|
LStemplate :: assign('lang_label',_('Language'));
|
2009-10-31 02:33:01 +01:00
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('displayLogoutBtn',LSauth :: displayLogoutBtn());
|
|
|
|
|
LStemplate :: assign('displaySelfAccess',LSauth :: displaySelfAccess());
|
2008-09-09 17:48:07 +02:00
|
|
|
|
|
|
|
|
|
// Infos
|
|
|
|
|
if((!empty($_SESSION['LSsession_infos']))&&(is_array($_SESSION['LSsession_infos']))) {
|
2018-06-08 17:41:28 +02:00
|
|
|
|
LStemplate :: assign('LSinfos',$_SESSION['LSsession_infos']);
|
2008-09-09 17:48:07 +02:00
|
|
|
|
$_SESSION['LSsession_infos']=array();
|
|
|
|
|
}
|
2008-04-25 15:48:12 +02:00
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: $ajaxDisplay) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('LSerror_txt',LSerror :: getErrors());
|
|
|
|
|
LStemplate :: assign('LSdebug_txt',LSdebug_print(true));
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
LSerror :: display();
|
2008-09-26 20:03:56 +02:00
|
|
|
|
LSdebug_print();
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (!self :: $template)
|
|
|
|
|
self :: setTemplate('empty.tpl');
|
2009-02-17 14:55:07 +01:00
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('connected_as',_("Connected as"));
|
2009-02-17 14:55:07 +01:00
|
|
|
|
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: display(self :: $template);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Défini que l'affichage se fera ou non via un retour Ajax
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $val boolean True pour que l'affichage se fasse par un retour
|
|
|
|
|
* Ajax, false sinon
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
public static function setAjaxDisplay($val=true) {
|
|
|
|
|
self :: $ajaxDisplay = (boolean)$val;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-11-10 00:14:51 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Affiche un retour Ajax
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function displayAjaxReturn($data=array()) {
|
2009-01-21 18:08:09 +01:00
|
|
|
|
if (isset($data['LSredirect']) && (!LSdebugDefined()) ) {
|
|
|
|
|
echo json_encode($data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$data['LSjsConfig'] = self :: $_JSconfigParams;
|
2008-11-10 00:14:51 +01:00
|
|
|
|
|
|
|
|
|
// Infos
|
|
|
|
|
if((!empty($_SESSION['LSsession_infos']))&&(is_array($_SESSION['LSsession_infos']))) {
|
|
|
|
|
$txt_infos="<ul>\n";
|
|
|
|
|
foreach($_SESSION['LSsession_infos'] as $info) {
|
|
|
|
|
$txt_infos.="<li>$info</li>\n";
|
|
|
|
|
}
|
|
|
|
|
$txt_infos.="</ul>\n";
|
|
|
|
|
$data['LSinfos'] = $txt_infos;
|
|
|
|
|
$_SESSION['LSsession_infos']=array();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (LSerror :: errorsDefined()) {
|
|
|
|
|
$data['LSerror'] = LSerror :: getErrors();
|
2008-11-10 00:14:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_REQUEST['imgload'])) {
|
|
|
|
|
$data['imgload'] = $_REQUEST['imgload'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (LSdebugDefined()) {
|
2009-10-30 01:03:17 +01:00
|
|
|
|
$data['LSdebug'] = LSdebug_print(true,false);
|
2008-11-10 00:14:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo json_encode($data);
|
|
|
|
|
}
|
2008-10-15 19:40:04 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retournne un template Smarty compilé
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $template Le template à retourner
|
|
|
|
|
* @param[in] array $variables Variables Smarty à assigner avant l'affichage
|
|
|
|
|
*
|
|
|
|
|
* @retval string Le HTML compilé du template
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function fetchTemplate($template,$variables=array()) {
|
2008-10-15 19:40:04 +02:00
|
|
|
|
foreach($variables as $name => $val) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign($name,$val);
|
2008-10-15 19:40:04 +02:00
|
|
|
|
}
|
2013-06-17 23:39:22 +02:00
|
|
|
|
return LStemplate :: fetch($template);
|
2008-10-15 19:40:04 +02:00
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
Allow a sequence of filters in LSobjects profile configurations
It's now possible for example to define a profile on an LSobject whose
attribute would contain the DN of a group the user is member of instead
of directly the dn of the user. A possible configuation using this new feature:
'LSprofile' => array(
'admin' => array(
'LSobjects' => array(
'LSsupannGroupAdminByGroup' => array(
'filters' => array(
array(
'basedn' => $basedn,
'attr' => 'member',
'attr_value' => '%{dn}',
'LSobject' => 'LSsupannGroup',
),
array(
'basedn' => $basedn,
'attr' => 'supannGroupeAdminDN',
'attr_value' => '%{dn}',
'LSobject' => 'LSsupannGroup',
)
),
),
),
),
)
Signed-off-by: Benjamin Renard <brenard@easter-eggs.com>
2014-12-13 12:15:37 +01:00
|
|
|
|
/**
|
|
|
|
|
* Prend un tableau de LSobject et le réduit en utilisant un filtre de
|
|
|
|
|
* recherche sur un autre type de LSobject.
|
|
|
|
|
*
|
|
|
|
|
* Si une erreur est présente dans le tableau de définition du filtre, un
|
|
|
|
|
* tableau vide est renvoyé.
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $LSobject le type LSobject par défaut
|
|
|
|
|
* @param[in] array $set tableau de LSobject
|
|
|
|
|
* @param[in] array $filter_def définition du filtre de recherche pour la réduction
|
|
|
|
|
* @param[in] string $basend basedn pour la recherche, null par défaut
|
|
|
|
|
*
|
|
|
|
|
* @retval array le nouveau tableau de LSobject
|
|
|
|
|
*/
|
|
|
|
|
private static function reduceLdapSet($LSobject, $set, $filter_def, $basedn=null) {
|
|
|
|
|
if (empty($set)) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! isset($filter_def['filter']) &&
|
|
|
|
|
(! isset($filter_def['attr']) ||
|
|
|
|
|
! isset($filter_def['attr_value']))) {
|
|
|
|
|
LSdebug("Filtre de profil LSobject invalide " . var_export($filter_def, true));
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LSdebug('LSsession :: reducing set of');
|
|
|
|
|
foreach ($set as $object) {
|
|
|
|
|
LSdebug('LSsession :: -> ' . $object -> getDn());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$LSobject = isset($filter_def['LSObject']) ? $filter_def['LSobject'] : $LSobject;
|
|
|
|
|
LSdebug('LSobject :: ' . $LSobject);
|
|
|
|
|
$filters = array();
|
|
|
|
|
foreach ($set as $object) {
|
|
|
|
|
if (isset($filter_def['filter'])) {
|
|
|
|
|
$filters[] = $object -> getFData($filter_def['filter']);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$value = $object -> getFData($filter_def['attr_value']);
|
|
|
|
|
$filters[] = Net_LDAP2_Filter::create($filter_def['attr'], 'equals', $value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$filter = LSldap::combineFilters('or', $filters);
|
|
|
|
|
$params = array(
|
|
|
|
|
'basedn' => isset($filter_def['basedn']) ? $filter_def['basedn'] : $basedn,
|
|
|
|
|
'filter' => $filter,
|
2017-03-23 14:43:23 +01:00
|
|
|
|
'onlyAccessible' => False
|
Allow a sequence of filters in LSobjects profile configurations
It's now possible for example to define a profile on an LSobject whose
attribute would contain the DN of a group the user is member of instead
of directly the dn of the user. A possible configuation using this new feature:
'LSprofile' => array(
'admin' => array(
'LSobjects' => array(
'LSsupannGroupAdminByGroup' => array(
'filters' => array(
array(
'basedn' => $basedn,
'attr' => 'member',
'attr_value' => '%{dn}',
'LSobject' => 'LSsupannGroup',
),
array(
'basedn' => $basedn,
'attr' => 'supannGroupeAdminDN',
'attr_value' => '%{dn}',
'LSobject' => 'LSsupannGroup',
)
),
),
),
),
)
Signed-off-by: Benjamin Renard <brenard@easter-eggs.com>
2014-12-13 12:15:37 +01:00
|
|
|
|
);
|
|
|
|
|
if (isset($filter_def['params']) && is_array($filter_def['params'])) {
|
|
|
|
|
$params = array_merge($filter_def['params'],$params);
|
|
|
|
|
}
|
|
|
|
|
$LSsearch = new LSsearch($LSobject,'LSsession :: loadLSprofiles',$params,true);
|
|
|
|
|
$LSsearch -> run(false);
|
|
|
|
|
|
|
|
|
|
$set = $LSsearch -> listObjects();
|
|
|
|
|
LSdebug('LSsession :: reduced set to');
|
|
|
|
|
foreach ($set as $object) {
|
|
|
|
|
LSdebug('LSsession :: -> ' . $object -> getDn());
|
|
|
|
|
}
|
|
|
|
|
return $set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Charge les droits LS de l'utilisateur : uniquement du type LSobjects
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
private static function loadLSprofilesLSobjects($profile, $LSobject, $listInfos) {
|
|
|
|
|
if (! self :: loadLSclass('LSsearch')) {
|
|
|
|
|
LSdebug('Impossible de charger la classe LSsearch');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
# we are gonna grow a set of objects progressively, we start from the user
|
|
|
|
|
$set = array(self :: getLSuserObject());
|
|
|
|
|
$basedn = isset($listInfos['basedn']) ? $listInfos['basedn'] : null;
|
|
|
|
|
$LSobject = isset($listInfos['LSobject']) ? $listInfos['LSobject'] : $LSobject;
|
|
|
|
|
|
|
|
|
|
if (isset($listInfos['filters']) && is_array($listInfos['filters'])) {
|
|
|
|
|
foreach ($listInfos['filters'] as $filter_def) {
|
|
|
|
|
$set = self :: reduceLdapSet($LSobject, $set, $filter_def, $basedn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isset($listInfos['filter']) || (isset($listInfos['attr']) && isset($listInfos['attr_value']))) {
|
|
|
|
|
# support legacy profile definition
|
|
|
|
|
$set = self :: reduceLdapSet($LSobject, $set, $listInfos, $basedn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$DNs = [];
|
|
|
|
|
foreach ($set as $object) {
|
|
|
|
|
$DNs[] = $object -> getDn();
|
|
|
|
|
}
|
|
|
|
|
if (!is_array(self :: $LSprofiles[$profile])) {
|
|
|
|
|
self :: $LSprofiles[$profile]=$DNs;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
foreach($DNs as $dn) {
|
|
|
|
|
if (!in_array($dn,self :: $LSprofiles[$profile])) {
|
|
|
|
|
self :: $LSprofiles[$profile][] = $dn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-08 18:39:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Charge les droits LS de l'utilisateur
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si le chargement à réussi, false sinon.
|
2008-02-08 18:39:24 +01:00
|
|
|
|
**/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
private static function loadLSprofiles() {
|
|
|
|
|
if (is_array(self :: $ldapServer['LSprofiles'])) {
|
|
|
|
|
foreach (self :: $ldapServer['LSprofiles'] as $profile => $profileInfos) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if (is_array($profileInfos)) {
|
|
|
|
|
foreach ($profileInfos as $topDn => $rightsInfos) {
|
2009-01-02 17:00:25 +01:00
|
|
|
|
/*
|
|
|
|
|
* If $topDn == 'LSobject', we search for each LSobject type to find
|
|
|
|
|
* all items on witch the user will have powers.
|
|
|
|
|
*/
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if ($topDn == 'LSobjects') {
|
|
|
|
|
if (is_array($rightsInfos)) {
|
|
|
|
|
foreach ($rightsInfos as $LSobject => $listInfos) {
|
Allow a sequence of filters in LSobjects profile configurations
It's now possible for example to define a profile on an LSobject whose
attribute would contain the DN of a group the user is member of instead
of directly the dn of the user. A possible configuation using this new feature:
'LSprofile' => array(
'admin' => array(
'LSobjects' => array(
'LSsupannGroupAdminByGroup' => array(
'filters' => array(
array(
'basedn' => $basedn,
'attr' => 'member',
'attr_value' => '%{dn}',
'LSobject' => 'LSsupannGroup',
),
array(
'basedn' => $basedn,
'attr' => 'supannGroupeAdminDN',
'attr_value' => '%{dn}',
'LSobject' => 'LSsupannGroup',
)
),
),
),
),
)
Signed-off-by: Benjamin Renard <brenard@easter-eggs.com>
2014-12-13 12:15:37 +01:00
|
|
|
|
LSdebug('loading LSprofile ' . $profile . ' for LSobject ' . $LSobject . ' with params ' . var_export($listInfos, true));
|
|
|
|
|
self :: loadLSprofilesLSobjects($profile, $LSobject, $listInfos);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
LSdebug('LSobjects => [] doit etre un tableau');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if (is_array($rightsInfos)) {
|
|
|
|
|
foreach($rightsInfos as $dn => $conf) {
|
|
|
|
|
if ((isset($conf['attr'])) && (isset($conf['LSobject']))) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if( self :: loadLSobject($conf['LSobject']) ) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if ($object = new $conf['LSobject']()) {
|
|
|
|
|
if ($object -> loadData($dn)) {
|
|
|
|
|
$listDns=$object -> getValue($conf['attr']);
|
2008-12-06 01:27:18 +01:00
|
|
|
|
$valKey = (isset($conf['attr_value']))?$conf['attr_value']:'%{dn}';
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$val = self :: getLSuserObject() -> getFData($valKey);
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if (is_array($listDns)) {
|
2008-12-05 15:38:42 +01:00
|
|
|
|
if (in_array($val,$listDns)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $LSprofiles[$profile][] = $topDn;
|
2008-11-12 17:57:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSdebug('Impossible de chargé le dn : '.$dn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSdebug('Impossible de créer l\'objet de type : '.$conf['LSobject']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: $dn == $dn) {
|
|
|
|
|
self :: $LSprofiles[$profile][] = $topDn;
|
2008-11-12 17:57:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-11-12 17:57:40 +01:00
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if ( self :: $dn == $rightsInfos ) {
|
|
|
|
|
self :: $LSprofiles[$profile][] = $topDn;
|
2008-11-12 17:57:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // fin else ($topDn == 'LSobjects')
|
|
|
|
|
} // fin foreach($profileInfos)
|
|
|
|
|
} // fin is_array($profileInfos)
|
2009-01-02 17:00:25 +01:00
|
|
|
|
} // fin foreach LSprofiles
|
2017-01-25 11:53:42 +01:00
|
|
|
|
LSdebug("LSprofiles : ".print_r(self :: $LSprofiles,1));
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +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
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
private static function loadLSaccess() {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
$LSaccess=array();
|
2010-11-16 19:31:07 +01:00
|
|
|
|
if (isset(self :: $ldapServer['subDn']) && is_array(self :: $ldapServer['subDn'])) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $ldapServer['subDn'] as $name => $config) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
if ($name=='LSobject') {
|
|
|
|
|
if (is_array($config)) {
|
|
|
|
|
|
|
|
|
|
// Définition des subDns
|
|
|
|
|
foreach($config as $objectType => $objectConf) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: loadLSobject($objectType)) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
if ($subdnobject = new $objectType()) {
|
2017-03-23 15:15:31 +01:00
|
|
|
|
$tbl = $subdnobject -> getSelectArray(NULL,self::getRootDn(),NULL,NULL,false,NULL,array('onlyAccessible' => False));
|
2008-06-21 18:16:15 +02:00
|
|
|
|
if (is_array($tbl)) {
|
|
|
|
|
// Définition des accès
|
|
|
|
|
$access=array();
|
|
|
|
|
if (is_array($objectConf['LSobjects'])) {
|
|
|
|
|
foreach($objectConf['LSobjects'] as $type) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: loadLSobject($type)) {
|
|
|
|
|
if (self :: canAccess($type)) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$access[$type] = LSconfig :: get('LSobjects.'.$type.'.label');
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach($tbl as $dn => $dn_name) {
|
|
|
|
|
$LSaccess[$dn]=$access;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if ((isCompatibleDNs(self :: $ldapServer['ldap_config']['basedn'],$config['dn']))&&($config['dn']!='')) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
$access=array();
|
|
|
|
|
if (is_array($config['LSobjects'])) {
|
|
|
|
|
foreach($config['LSobjects'] as $objectType) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: loadLSobject($objectType)) {
|
|
|
|
|
if (self :: canAccess($objectType)) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$access[$objectType] = LSconfig :: get('LSobjects.'.$objectType.'.label');
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$LSaccess[$config['dn']]=$access;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if(is_array(self :: $ldapServer['LSaccess'])) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
$access=array();
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $ldapServer['LSaccess'] as $objectType) {
|
|
|
|
|
if (self :: loadLSobject($objectType)) {
|
|
|
|
|
if (self :: canAccess($objectType)) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$access[$objectType] = LSconfig :: get('LSobjects.'.$objectType.'.label');
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$LSaccess[self :: $topDn] = $access;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-25 12:39:35 +01:00
|
|
|
|
if (LSauth :: displaySelfAccess()) {
|
|
|
|
|
foreach($LSaccess as $dn => $access) {
|
|
|
|
|
$LSaccess[$dn] = array_merge(
|
|
|
|
|
array(
|
|
|
|
|
'SELF' => 'My account'
|
|
|
|
|
),
|
|
|
|
|
$access
|
|
|
|
|
);
|
|
|
|
|
}
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $LSaccess = $LSaccess;
|
2008-06-21 18:16:15 +02:00
|
|
|
|
$_SESSION['LSsession']['LSaccess'] = $LSaccess;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2015-08-21 17:51:52 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load user access to LSaddons views
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
private static function loadLSaddonsViewsAccess() {
|
|
|
|
|
$LSaddonsViewsAccess=array();
|
|
|
|
|
foreach (self :: $LSaddonsViews as $addon => $conf) {
|
|
|
|
|
foreach ($conf as $viewId => $viewConf) {
|
|
|
|
|
if (self :: canAccessLSaddonView($addon,$viewId)) {
|
2018-09-13 18:36:45 +02:00
|
|
|
|
$LSaddonsViewsAccess["$addon::$viewId"]=array (
|
2015-08-21 17:51:52 +02:00
|
|
|
|
'LSaddon' => $addon,
|
|
|
|
|
'id' => $viewId,
|
2015-08-24 12:24:33 +02:00
|
|
|
|
'label' => $viewConf['label'],
|
|
|
|
|
'showInMenu' => $viewConf['showInMenu']
|
2015-08-21 17:51:52 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self :: $LSaddonsViewsAccess = $LSaddonsViewsAccess;
|
|
|
|
|
$_SESSION['LSsession']['LSaddonsViewsAccess'] = $LSaddonsViewsAccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-11-12 17:57:40 +01:00
|
|
|
|
* Dit si l'utilisateur est du profil pour le DN spécifié
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*
|
2008-11-12 17:57:40 +01:00
|
|
|
|
* @param[in] string $dn DN de l'objet
|
2017-01-25 15:39:06 +01:00
|
|
|
|
* @param[in] string $profile Profil
|
|
|
|
|
*
|
2008-11-12 17:57:40 +01:00
|
|
|
|
* @retval boolean True si l'utilisateur est du profil sur l'objet, false sinon.
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function isLSprofile($dn,$profile) {
|
|
|
|
|
if (is_array(self :: $LSprofiles[$profile])) {
|
|
|
|
|
foreach(self :: $LSprofiles[$profile] as $topDn) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if($dn == $topDn) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if ( isCompatibleDNs($dn,$topDn) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-01-25 15:39:06 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dit si l'utilisateur est d'au moins un des profils pour le DN spécifié
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $dn DN de l'objet
|
|
|
|
|
* @param[in] string $profiles Profils
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si l'utilisateur est d'au moins un profil sur l'objet, false sinon.
|
|
|
|
|
*/
|
|
|
|
|
public static function isLSprofiles($dn,$profiles) {
|
|
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
|
if (self :: isLSprofile($dn,$profile))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +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
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function whoami($dn) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
$retval = array('user');
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $LSprofiles as $profile => $infos) {
|
|
|
|
|
if(self :: isLSprofile($dn,$profile)) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
$retval[]=$profile;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 18:45:14 +01:00
|
|
|
|
if (self :: $dn == $dn) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
$retval[]='self';
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-12 17:57:40 +01:00
|
|
|
|
return $retval;
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function canAccess($LSobject,$dn=NULL,$right=NULL,$attr=NULL) {
|
|
|
|
|
if (!self :: loadLSobject($LSobject)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
return;
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if ($dn) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$whoami = self :: whoami($dn);
|
|
|
|
|
if ($dn==self :: getLSuserObject() -> getValue('dn')) {
|
|
|
|
|
if (!self :: in_menu('SELF')) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$obj = new $LSobject();
|
|
|
|
|
$obj -> dn = $dn;
|
2009-10-30 01:03:17 +01:00
|
|
|
|
if (!self :: in_menu($LSobject,$obj -> subDnValue)) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$objectdn=LSconfig :: get('LSobjects.'.$LSobject.'.container_dn').','.self :: $topDn;
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$whoami = self :: whoami($objectdn);
|
2008-02-12 18:59:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pour un attribut particulier
|
|
|
|
|
if ($attr) {
|
|
|
|
|
if ($attr=='rdn') {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$attr=LSconfig :: get('LSobjects.'.$LSobject.'.rdn');
|
2008-02-12 18:59:44 +01:00
|
|
|
|
}
|
2009-03-25 13:26:32 +01:00
|
|
|
|
if (!is_array(LSconfig :: get('LSobjects.'.$LSobject.'.attrs.'.$attr))) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2008-11-12 17:57:40 +01:00
|
|
|
|
|
|
|
|
|
$r = 'n';
|
|
|
|
|
foreach($whoami as $who) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$nr = LSconfig :: get('LSobjects.'.$LSobject.'.attrs.'.$attr.'.rights.'.$who);
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if($nr == 'w') {
|
|
|
|
|
$r = 'w';
|
|
|
|
|
}
|
|
|
|
|
else if($nr == 'r') {
|
|
|
|
|
if ($r=='n') {
|
|
|
|
|
$r='r';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
|
|
if (($right=='r')||($right=='w')) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if ($r==$right) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if ( ($r=='r') || ($r=='w') ) {
|
2008-02-12 18:59:44 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
|
|
// Pour un attribut quelconque
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$attrs_conf=LSconfig :: get('LSobjects.'.$LSobject.'.attrs');
|
|
|
|
|
if (is_array($attrs_conf)) {
|
2008-02-08 18:39:24 +01:00
|
|
|
|
if (($right=='r')||($right=='w')) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
foreach($whoami as $who) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
foreach ($attrs_conf as $attr_name => $attr_config) {
|
2010-11-16 19:32:10 +01:00
|
|
|
|
if (isset($attr_config['rights'][$who]) && $attr_config['rights'][$who]==$right) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
foreach($whoami as $who) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
foreach ($attrs_conf as $attr_name => $attr_config) {
|
2010-11-16 19:32:10 +01:00
|
|
|
|
if ( (isset($attr_config['rights'][$who])) && ( ($attr_config['rights'][$who]=='r') || ($attr_config['rights'][$who]=='w') ) ) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function canEdit($LSobject,$dn=NULL,$attr=NULL) {
|
|
|
|
|
return self :: canAccess($LSobject,$dn,'w',$attr);
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function canRemove($LSobject,$dn) {
|
|
|
|
|
return self :: canAccess($LSobject,$dn,'w','rdn');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
|
/**
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function canCreate($LSobject) {
|
2010-08-02 14:39:50 +02:00
|
|
|
|
if (!self :: loadLSobject($LSobject)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (LSconfig :: get("LSobjects.$LSobject.disable_creation")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
return self :: canAccess($LSobject,NULL,'w','rdn');
|
2008-02-08 18:39:24 +01:00
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Retourne le droit de l'utilisateur à gérer la relation d'objet
|
2008-02-26 18:40:05 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
2008-10-08 16:50:48 +02:00
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
2008-02-26 18:40:05 +01:00
|
|
|
|
* @param[in] string $relationName Le nom de la relation avec l'objet
|
2008-06-05 15:21:18 +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-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function relationCanAccess($dn,$LSobject,$relationName,$right=NULL) {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
$relConf=LSconfig :: get('LSobjects.'.$LSobject.'.LSrelation.'.$relationName);
|
|
|
|
|
if (!is_array($relConf))
|
2008-02-26 18:40:05 +01:00
|
|
|
|
return;
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$whoami = self :: whoami($dn);
|
2008-04-25 15:48:12 +02:00
|
|
|
|
|
2008-02-26 18:40:05 +01:00
|
|
|
|
if (($right=='w') || ($right=='r')) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
$r = 'n';
|
|
|
|
|
foreach($whoami as $who) {
|
2010-11-16 19:34:04 +01:00
|
|
|
|
$nr = ((isset($relConf['rights'][$who]))?$relConf['rights'][$who]:'');
|
2008-11-12 17:57:40 +01:00
|
|
|
|
if($nr == 'w') {
|
|
|
|
|
$r = 'w';
|
|
|
|
|
}
|
|
|
|
|
else if($nr == 'r') {
|
|
|
|
|
if ($r=='n') {
|
|
|
|
|
$r='r';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($r == $right) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
foreach($whoami as $who) {
|
2010-11-16 19:34:04 +01:00
|
|
|
|
if ((isset($relConf['rights'][$who])) && ( ($relConf['rights'][$who] == 'w') || ($relConf['rights'][$who] == 'r') ) ) {
|
2008-11-12 17:57:40 +01:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-02-26 18:40:05 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* Retourne le droit de l'utilisateur à modifier la relation d'objet
|
2008-02-26 18:40:05 +01:00
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @param[in] string $dn Le DN de l'objet (le container_dn du type de l'objet par défaut)
|
2008-10-08 16:50:48 +02:00
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
2008-02-26 18:40:05 +01:00
|
|
|
|
* @param[in] string $relationName Le nom de la relation avec l'objet
|
|
|
|
|
*
|
2008-06-05 15:21:18 +02:00
|
|
|
|
* @retval boolean True si l'utilisateur a accès, false sinon
|
2008-02-26 18:40:05 +01:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function relationCanEdit($dn,$LSobject,$relationName) {
|
|
|
|
|
return self :: relationCanAccess($dn,$LSobject,$relationName,'w');
|
2008-02-26 18:40:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-03-25 18:05:26 +01:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le droit de l'utilisateur a executer une customAction
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $dn Le DN de l'objet
|
|
|
|
|
* @param[in] string $LSobject Le type de l'objet
|
|
|
|
|
* @param[in] string $customActionName Le nom de la customAction
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si l'utilisateur peut executer cette customAction, false sinon
|
|
|
|
|
*/
|
|
|
|
|
public static function canExecuteCustomAction($dn,$LSobject,$customActionName) {
|
|
|
|
|
$conf=LSconfig :: get('LSobjects.'.$LSobject.'.customActions.'.$customActionName);
|
|
|
|
|
if (!is_array($conf))
|
|
|
|
|
return;
|
|
|
|
|
$whoami = self :: whoami($dn);
|
|
|
|
|
|
|
|
|
|
if (isset($conf['rights']) && is_array($conf['rights'])) {
|
|
|
|
|
foreach($whoami as $who) {
|
|
|
|
|
if (in_array($who,$conf['rights'])) {
|
|
|
|
|
return True;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 17:24:30 +02:00
|
|
|
|
/**
|
|
|
|
|
* Retourne le droit de l'utilisateur a executer une customAction
|
|
|
|
|
* sur une recherche
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $LSsearch L'objet LSsearch
|
|
|
|
|
* @param[in] string $customActionName Le nom de la customAction
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si l'utilisateur peut executer cette customAction, false sinon
|
|
|
|
|
*/
|
|
|
|
|
public static function canExecuteLSsearchCustomAction($LSsearch,$customActionName) {
|
|
|
|
|
$conf=LSconfig :: get('LSobjects.'.$LSsearch -> LSobject.'.LSsearch.customActions.'.$customActionName);
|
|
|
|
|
if (!is_array($conf))
|
|
|
|
|
return;
|
|
|
|
|
$dn=$LSsearch -> basedn;
|
|
|
|
|
if (is_null($dn)) $dn=self::getTopDn();
|
|
|
|
|
|
|
|
|
|
$whoami = self :: whoami($dn);
|
|
|
|
|
|
|
|
|
|
if (isset($conf['rights']) && is_array($conf['rights'])) {
|
|
|
|
|
foreach($whoami as $who) {
|
|
|
|
|
if (in_array($who,$conf['rights'])) {
|
|
|
|
|
return True;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 17:51:52 +02:00
|
|
|
|
/**
|
|
|
|
|
* Return user right to access to a LSaddon view
|
|
|
|
|
*
|
|
|
|
|
* @param[in] string $LSaddon The LSaddon
|
|
|
|
|
* @param[in] string $viewId The LSaddon view ID
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True if user is allowed, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
public static function canAccessLSaddonView($LSaddon,$viewId) {
|
|
|
|
|
if (self :: loadLSaddon($LSaddon)) {
|
|
|
|
|
if (!isset(self :: $LSaddonsViews[$LSaddon]) || !isset(self :: $LSaddonsViews[$LSaddon][$viewId]))
|
|
|
|
|
return;
|
|
|
|
|
if (!is_array(self :: $LSaddonsViews[$LSaddon][$viewId]['allowedLSprofiles'])) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
$whoami = self :: whoami(self :: $topDn);
|
|
|
|
|
|
|
|
|
|
if (isset(self :: $LSaddonsViews[$LSaddon][$viewId]['allowedLSprofiles']) && is_array(self :: $LSaddonsViews[$LSaddon][$viewId]['allowedLSprofiles'])) {
|
|
|
|
|
foreach($whoami as $who) {
|
|
|
|
|
if (in_array($who,self :: $LSaddonsViews[$LSaddon][$viewId]['allowedLSprofiles'])) {
|
|
|
|
|
return True;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-26 18:40:05 +01:00
|
|
|
|
* Ajoute un fichier temporaire
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
**/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function addTmpFile($value,$filePath) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$hash = mhash(MHASH_MD5,$value);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $tmp_file[$filePath] = $hash;
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$_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
|
|
|
|
|
**/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function tmpFileExist($value) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$hash = mhash(MHASH_MD5,$value);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $tmp_file as $filePath => $contentHash) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
if ($hash == $contentHash) {
|
|
|
|
|
return $filePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le chemin du fichier temporaire
|
|
|
|
|
*
|
2008-06-05 15:21:18 +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
|
|
|
|
|
**/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function getTmpFile($value) {
|
|
|
|
|
$exist = self :: tmpFileExist($value);
|
2008-02-26 18:40:05 +01:00
|
|
|
|
if (!$exist) {
|
|
|
|
|
$img_path = LS_TMP_DIR .rand().'.tmp';
|
|
|
|
|
$fp = fopen($img_path, "w");
|
|
|
|
|
fwrite($fp, $value);
|
|
|
|
|
fclose($fp);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: addTmpFile($value,$img_path);
|
2008-02-26 18:40:05 +01:00
|
|
|
|
return $img_path;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return $exist;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
|
/**
|
2008-02-26 18:40:05 +01:00
|
|
|
|
* Supprime les fichiers temporaires
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
**/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function deleteTmpFile($filePath=NULL) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
if ($filePath) {
|
|
|
|
|
@unlink($filePath);
|
2009-01-24 18:45:14 +01:00
|
|
|
|
unset(self :: $tmp_file[$filePath]);
|
2008-02-26 18:40:05 +01:00
|
|
|
|
unset($_SESSION['LSsession']['tmp_file'][$filePath]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $tmp_file as $file => $content) {
|
2008-02-26 18:40:05 +01:00
|
|
|
|
@unlink($file);
|
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $tmp_file = array();
|
2008-02-26 18:40:05 +01:00
|
|
|
|
$_SESSION['LSsession']['tmp_file'] = array();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
|
|
2008-06-18 14:27:35 +02:00
|
|
|
|
/**
|
|
|
|
|
* Retourne true si le cache des droits est activé
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si le cache des droits est activé, false sinon.
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function cacheLSprofiles() {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
return ( (LSconfig :: get('cacheLSprofiles')) || (self :: $ldapServer['cacheLSprofiles']) );
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne true si le cache des subDn est activé
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si le cache des subDn est activé, false sinon.
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function cacheSudDn() {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
return ( (LSconfig :: get('cacheSubDn')) || (self :: $ldapServer['cacheSubDn']));
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne true si le cache des recherches est activé
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean True si le cache des recherches est activé, false sinon.
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function cacheSearch() {
|
2009-03-25 13:26:32 +01:00
|
|
|
|
return ( (LSconfig :: get('cacheSearch')) || (self :: $ldapServer['cacheSearch']));
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le label des niveaux pour le serveur ldap courant
|
|
|
|
|
*
|
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
|
*
|
|
|
|
|
* @retval string Le label des niveaux pour le serveur ldap dourant
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function getSubDnLabel() {
|
2009-03-20 11:42:45 +01:00
|
|
|
|
return (self :: $ldapServer['subDnLabel']!='')?__(self :: $ldapServer['subDnLabel']):_('Level');
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne le nom du subDn
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $subDn string subDn
|
|
|
|
|
*
|
2008-06-21 18:16:15 +02:00
|
|
|
|
* @retval string Le nom du subDn ou '' sinon
|
2008-06-18 14:27:35 +02:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function getSubDnName($subDn=false) {
|
2008-06-18 14:27:35 +02:00
|
|
|
|
if (!$subDn) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$subDn = self :: $topDn;
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
2010-11-26 14:46:48 +01:00
|
|
|
|
if (self :: getSubDnLdapServer(false)) {
|
|
|
|
|
if (isset(self :: $_subDnLdapServer[self :: $ldapServerId][false][$subDn])) {
|
|
|
|
|
return self :: $_subDnLdapServer[self :: $ldapServerId][false][$subDn];
|
2008-06-18 14:27:35 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-20 17:52:15 +02:00
|
|
|
|
/**
|
|
|
|
|
* L'objet est t-il utilisé pour listé les subDnS
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $type string Le type d'objet
|
|
|
|
|
*
|
2008-06-21 18:16:15 +02:00
|
|
|
|
* @retval boolean true si le type d'objet est un subDnObject, false sinon
|
2008-06-20 17:52:15 +02:00
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function isSubDnLSobject($type) {
|
2008-06-20 17:52:15 +02:00
|
|
|
|
$result = false;
|
2010-11-16 19:34:57 +01:00
|
|
|
|
if (isset(self :: $ldapServer['subDn']['LSobject']) && is_array(self :: $ldapServer['subDn']['LSobject'])) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
foreach(self :: $ldapServer['subDn']['LSobject'] as $key => $value) {
|
2008-06-20 17:52:15 +02:00
|
|
|
|
if ($key==$type) {
|
|
|
|
|
$result=true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2008-06-21 18:16:15 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2008-07-05 22:28:49 +02:00
|
|
|
|
* Indique si un type d'objet est dans le menu courant
|
2008-06-21 18:16:15 +02:00
|
|
|
|
*
|
|
|
|
|
* @retval boolean true si le type d'objet est dans le menu, false sinon
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function in_menu($LSobject,$topDn=NULL) {
|
2008-06-21 18:16:15 +02:00
|
|
|
|
if (!$topDn) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
$topDn=self :: $topDn;
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
|
return isset(self :: $LSaccess[$topDn][$LSobject]);
|
2008-06-21 18:16:15 +02:00
|
|
|
|
}
|
2008-07-05 22:28:49 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Indique si le serveur LDAP courant a des subDn
|
|
|
|
|
*
|
|
|
|
|
* @retval boolean true si le serveur LDAP courant a des subDn, false sinon
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function haveSubDn() {
|
2010-11-08 17:02:35 +01:00
|
|
|
|
return (isset(self :: $ldapServer['subDn']) && is_array(self :: $ldapServer['subDn']));
|
2008-07-05 22:28:49 +02:00
|
|
|
|
}
|
2008-09-09 17:48:07 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ajoute une information à afficher
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $msg string Le message à afficher
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function addInfo($msg) {
|
2008-09-09 17:48:07 +02:00
|
|
|
|
$_SESSION['LSsession_infos'][]=$msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Redirection de l'utilisateur vers une autre URL
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $url string L'URL
|
|
|
|
|
* @param[in] $exit boolean Si true, l'execution script s'arrête après la redirection
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function redirect($url,$exit=true) {
|
2013-06-17 23:39:22 +02:00
|
|
|
|
LStemplate :: assign('url',$url);
|
|
|
|
|
LStemplate :: display('redirect.tpl');
|
2008-09-09 17:48:07 +02:00
|
|
|
|
if ($exit) {
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-25 17:15:33 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retourne l'adresse mail d'emission configurée pour le serveur courant
|
|
|
|
|
*
|
|
|
|
|
* @retval string Adresse mail d'emission
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function getEmailSender() {
|
|
|
|
|
return self :: $ldapServer['emailSender'];
|
2008-09-25 17:15:33 +02:00
|
|
|
|
}
|
2018-09-13 18:36:45 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Redirect to default view (if defined)
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
public static function redirectToDefaultView($force=false) {
|
|
|
|
|
if (isset(self :: $ldapServer['defaultView'])) {
|
|
|
|
|
if (array_key_exists(self :: $ldapServer['defaultView'], self :: $LSaccess[self :: $topDn])) {
|
|
|
|
|
self :: redirect('view.php?LSobject='.self :: $ldapServer['defaultView']);
|
|
|
|
|
}
|
|
|
|
|
elseif (array_key_exists(self :: $ldapServer['defaultView'], self :: $LSaddonsViewsAccess)) {
|
|
|
|
|
$addon = self :: $LSaddonsViewsAccess[self :: $ldapServer['defaultView']];
|
|
|
|
|
self :: redirect('addon_view.php?LSaddon='.urlencode(self :: $LSaddonsViewsAccess[self :: $ldapServer['defaultView']]['LSaddon'])."&view=".urlencode(self :: $LSaddonsViewsAccess[self :: $ldapServer['defaultView']]['id']));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($force)
|
|
|
|
|
self :: redirect('index.php');
|
|
|
|
|
}
|
2008-11-10 03:10:42 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ajout d'une information d'aide
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $group string Le nom du groupe d'infos dans lequels ajouter
|
|
|
|
|
* celle-ci
|
|
|
|
|
* @param[in] $infos array Tableau array(name => value) des infos
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
2009-01-24 18:45:14 +01:00
|
|
|
|
public static function addHelpInfos($group,$infos) {
|
2008-11-10 03:10:42 +01:00
|
|
|
|
if (is_array($infos)) {
|
2010-11-16 19:35:44 +01:00
|
|
|
|
if (isset(self :: $_JSconfigParams['helpInfos'][$group]) && is_array(self :: $_JSconfigParams['helpInfos'][$group])) {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $_JSconfigParams['helpInfos'][$group] = array_merge(self :: $_JSconfigParams['helpInfos'][$group],$infos);
|
2008-11-10 03:10:42 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2009-01-24 18:45:14 +01:00
|
|
|
|
self :: $_JSconfigParams['helpInfos'][$group] = $infos;
|
2008-11-10 03:10:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-25 15:37:03 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Défini les codes erreur relative à la classe LSsession
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
private static function defineLSerrors() {
|
|
|
|
|
/*
|
|
|
|
|
* Error Codes
|
|
|
|
|
*/
|
|
|
|
|
LSerror :: defineError('LSsession_01',
|
|
|
|
|
_("LSsession : The constant %{const} is not defined.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_02',
|
|
|
|
|
_("LSsession : The %{addon} support is uncertain. Verify system compatibility and the add-on configuration.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_03',
|
2009-03-13 22:32:08 +01:00
|
|
|
|
_("LSsession : LDAP server's configuration data are invalid. Can't connect.")
|
2009-01-25 15:37:03 +01:00
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_04',
|
|
|
|
|
_("LSsession : Failed to load LSobject type %{type} : unknon type.")
|
|
|
|
|
);
|
2009-10-26 00:34:06 +01:00
|
|
|
|
LSerror :: defineError('LSsession_05',
|
|
|
|
|
_("LSsession : Failed to load LSclass %{class}.")
|
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSsession_06',
|
|
|
|
|
_("LSsession : Login or password incorrect.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_07',
|
|
|
|
|
_("LSsession : Impossible to identify you : Duplication of identities.")
|
|
|
|
|
);
|
2009-10-31 02:33:01 +01:00
|
|
|
|
LSerror :: defineError('LSsession_08',
|
|
|
|
|
_("LSsession : Can't load class of authentification (%{class}).")
|
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSsession_09',
|
|
|
|
|
_("LSsession : Can't connect to LDAP server.")
|
|
|
|
|
);
|
2009-10-31 02:33:01 +01:00
|
|
|
|
LSerror :: defineError('LSsession_10',
|
|
|
|
|
_("LSsession : Impossible to authenticate you.")
|
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSsession_11',
|
|
|
|
|
_("LSsession : Your are not authorized to do this action.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_12',
|
|
|
|
|
_("LSsession : Some informations are missing to display this page.")
|
|
|
|
|
);
|
2011-03-25 18:05:26 +01:00
|
|
|
|
LSerror :: defineError('LSsession_13',
|
|
|
|
|
_("LSsession : The function of the custom action %{name} does not exists or is not configured.")
|
|
|
|
|
);
|
2014-11-18 13:16:38 +01:00
|
|
|
|
LSerror :: defineError('LSsession_14',
|
|
|
|
|
_("LSsession : Fail to retreive user's LDAP credentials from LSauth.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_15',
|
|
|
|
|
_("LSsession : Fail to reconnect to LDAP server with user's LDAP credentials.")
|
|
|
|
|
);
|
2015-07-30 16:37:42 +02:00
|
|
|
|
LSerror :: defineError('LSsession_16',
|
|
|
|
|
_("LSsession : No import/export format define for this object type.")
|
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSsession_17',
|
|
|
|
|
_("LSsession : Error during creation of list of levels. Contact administrators. (Code : %{code})")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_18',
|
|
|
|
|
_("LSsession : The password recovery is disabled for this LDAP server.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_19',
|
|
|
|
|
_("LSsession : Some informations are missing to recover your password. Contact administrators.")
|
|
|
|
|
);
|
|
|
|
|
LSerror :: defineError('LSsession_20',
|
|
|
|
|
_("LSsession : Error during password recovery. Contact administrators.(Step : %{step})")
|
|
|
|
|
);
|
2015-08-12 14:16:25 +02:00
|
|
|
|
LSerror :: defineError('LSsession_21',
|
|
|
|
|
_("LSsession : call function %{func} do not provided from LSaddon %{addon}.")
|
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
LSerror :: defineError('LSsession_22',
|
|
|
|
|
_("LSsession : problem during initialisation.")
|
|
|
|
|
);
|
2015-08-21 17:51:52 +02:00
|
|
|
|
LSerror :: defineError('LSsession_23',
|
|
|
|
|
_("LSsession : view function %{func} for LSaddon %{addon} doet not exist.")
|
|
|
|
|
);
|
2017-08-02 12:00:11 +02:00
|
|
|
|
LSerror :: defineError('LSsession_24',
|
|
|
|
|
_("LSsession : invalid related object's DN pass in parameter.")
|
|
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
|
}
|
2009-02-20 15:05:22 +01:00
|
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
|
/**
|
|
|
|
|
* Ajax method when change ldapserver on login form
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $data array The return data address
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
**/
|
2009-02-20 15:05:22 +01:00
|
|
|
|
public static function ajax_onLdapServerChangedLogin(&$data) {
|
|
|
|
|
if ( isset($_REQUEST['server']) ) {
|
|
|
|
|
self :: setLdapServer($_REQUEST['server']);
|
|
|
|
|
$data = array();
|
|
|
|
|
if ( self :: LSldapConnect() ) {
|
2010-11-16 19:36:26 +01:00
|
|
|
|
if (session_id()=="") session_start();
|
2009-02-20 15:05:22 +01:00
|
|
|
|
if (isset($_SESSION['LSsession_topDn'])) {
|
|
|
|
|
$sel = $_SESSION['LSsession_topDn'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$sel = NULL;
|
|
|
|
|
}
|
2010-11-16 11:50:18 +01:00
|
|
|
|
$list = self :: getSubDnLdapServerOptions($sel,true);
|
2009-02-20 15:05:22 +01:00
|
|
|
|
if (is_string($list)) {
|
|
|
|
|
$data['list_topDn'] = "<select name='LSsession_topDn' id='LSsession_topDn'>".$list."</select>";
|
|
|
|
|
$data['subDnLabel'] = self :: getSubDnLabel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$data['recoverPassword'] = isset(self :: $ldapServer['recoverPassword']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-30 01:03:17 +01:00
|
|
|
|
/**
|
|
|
|
|
* Ajax method when change ldapserver on recoverPassword form
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $data array The return data address
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
**/
|
2009-02-20 15:05:22 +01:00
|
|
|
|
public static function ajax_onLdapServerChangedRecoverPassword(&$data) {
|
|
|
|
|
if ( isset($_REQUEST['server']) ) {
|
|
|
|
|
self :: setLdapServer($_REQUEST['server']);
|
|
|
|
|
$data=array('recoverPassword' => isset(self :: $ldapServer['recoverPassword']));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-12 22:11:32 +01:00
|
|
|
|
|
2015-08-21 17:50:31 +02:00
|
|
|
|
/**
|
|
|
|
|
* Set globals from the ldap server
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
public static function setGlobals() {
|
|
|
|
|
if ( isset(self :: $ldapServer['globals'])) {
|
|
|
|
|
foreach(self :: $ldapServer['globals'] as $key => $value) {
|
|
|
|
|
$GLOBALS[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 17:51:52 +02:00
|
|
|
|
/**
|
|
|
|
|
* Register a LSaddon view
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $LSaddon string The LSaddon
|
|
|
|
|
* @param[in] $viewId string The view ID
|
|
|
|
|
* @param[in] $label string The view's label
|
|
|
|
|
* @param[in] $viewFunction string The view's function name
|
|
|
|
|
* @param[in] $allowedLSprofiles array|null Array listing allowed profiles.
|
|
|
|
|
* If null, no access control will
|
|
|
|
|
* be done for this view.
|
2015-08-24 12:24:33 +02:00
|
|
|
|
* @param[in] $showInMenu boolean Show (or not) this view in menu
|
|
|
|
|
*
|
2015-08-21 17:51:52 +02:00
|
|
|
|
* @retval bool True is the view have been registred, false otherwise
|
|
|
|
|
**/
|
2015-08-24 12:24:33 +02:00
|
|
|
|
public static function registerLSaddonView($LSaddon,$viewId,$label,$viewFunction,$allowedLSprofiles=null,$showInMenu=True) {
|
2015-08-21 17:51:52 +02:00
|
|
|
|
if (function_exists($viewFunction)) {
|
|
|
|
|
$func = new ReflectionFunction($viewFunction);
|
|
|
|
|
if (basename($func->getFileName())=="LSaddons.$LSaddon.php") {
|
|
|
|
|
self :: $LSaddonsViews[$LSaddon][$viewId]=array (
|
|
|
|
|
'LSaddon' => $LSaddon,
|
|
|
|
|
'label' => $label,
|
|
|
|
|
'function' => $viewFunction,
|
2015-08-24 12:24:33 +02:00
|
|
|
|
'allowedLSprofiles' => $allowedLSprofiles,
|
|
|
|
|
'showInMenu' => (bool)$showInMenu
|
2015-08-21 17:51:52 +02:00
|
|
|
|
);
|
|
|
|
|
return True;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_21',array('func' => $func -> getName(),'addon' => $addon));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LSerror :: addErrorCode('LSsession_23',array('func' => $viewFunction,'addon' => $LSaddon));
|
|
|
|
|
}
|
|
|
|
|
return False;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show LSaddon view
|
|
|
|
|
*
|
|
|
|
|
* @param[in] $LSaddon string The LSaddon
|
|
|
|
|
* @param[in] $viewId string The view ID
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
**/
|
|
|
|
|
public static function showLSaddonView($LSaddon,$viewId) {
|
|
|
|
|
if (self :: canAccessLSaddonView($LSaddon,$viewId)) {
|
|
|
|
|
call_user_func(self :: $LSaddonsViews[$LSaddon][$viewId]['function']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|