Merge branch '3.2' of https://github.com/Dolibarr/dolibarr into 3.2
This commit is contained in:
commit
8416014cff
@ -48,7 +48,7 @@ if ($action == 'setvalue' && $user->admin)
|
||||
|
||||
$db->begin();
|
||||
if (! dolibarr_set_const($db, 'LDAP_SERVER_TYPE',GETPOST("type"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',GETPOST("version"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',GETPOST("LDAP_SERVER_PROTOCOLVERSION"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST',GETPOST("host"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST_SLAVE',GETPOST("slave"),'chaine',0,'',$conf->entity)) $error++;
|
||||
if (! dolibarr_set_const($db, 'LDAP_SERVER_PORT',GETPOST("port"),'chaine',0,'',$conf->entity)) $error++;
|
||||
@ -169,7 +169,7 @@ print '<tr '.$bc[$var].'><td>'.$langs->trans("Version").'</td><td>';
|
||||
$arraylist=array();
|
||||
$arraylist['3']='Version 3';
|
||||
$arraylist['2']='Version 2';
|
||||
print $form->selectarray('version',$arraylist,$conf->global->LDAP_SERVER_PROTOCOLVERSION);
|
||||
print $form->selectarray('LDAP_SERVER_PROTOCOLVERSION',$arraylist,$conf->global->LDAP_SERVER_PROTOCOLVERSION);
|
||||
print '</td><td>'.$langs->trans("LDAPServerProtocolVersion").'</td></tr>';
|
||||
|
||||
// Serveur primaire
|
||||
|
||||
@ -207,7 +207,7 @@ class Ldap
|
||||
$this->connection = ldap_connect($host,$this->serverPort);
|
||||
}
|
||||
|
||||
if ($this->connection)
|
||||
if (is_resource($this->connection))
|
||||
{
|
||||
$this->setVersion();
|
||||
|
||||
@ -274,9 +274,9 @@ class Ldap
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error='Failed to connect to LDAP';
|
||||
$this->error='Failed to connect to LDAP'.($this->error?': '.$this->error:'');
|
||||
$return=-1;
|
||||
dol_syslog("Ldap::connect_bind return=".$return, LOG_WARNING);
|
||||
dol_syslog("Ldap::connect_bind return=".$return.' - '.$this->error, LOG_WARNING);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@ -508,7 +508,7 @@ class Ldap
|
||||
*
|
||||
* @param string $dn DN entry key
|
||||
* @param string $info Attributes array
|
||||
* @param User $user Objet user that delete
|
||||
* @param User $user Objet user that update
|
||||
* @param string $olddn Old DN entry key (before update)
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@ -1400,4 +1400,4 @@ class Ldap
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
@ -85,8 +85,8 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
|
||||
{
|
||||
dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType);
|
||||
dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword);
|
||||
print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."\n";
|
||||
print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."\n";
|
||||
print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n";
|
||||
print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."<br>\n";
|
||||
}
|
||||
|
||||
$resultFetchLdapUser=0;
|
||||
@ -104,7 +104,7 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
|
||||
if ($ldapadminlogin)
|
||||
{
|
||||
$result=$ldap->connect_bind();
|
||||
if ($result)
|
||||
if ($result > 0)
|
||||
{
|
||||
$resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter);
|
||||
//dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser);
|
||||
@ -119,6 +119,10 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
|
||||
return '';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n";
|
||||
}
|
||||
$ldap->close();
|
||||
}
|
||||
|
||||
@ -191,11 +195,11 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
|
||||
** 53 - Account inactive (manually locked out by administrator)
|
||||
*/
|
||||
dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'");
|
||||
if ($this->connection) // If connection ok but bind ko
|
||||
if (is_resource($ldap->connection)) // If connection ok but bind ko
|
||||
{
|
||||
$this->ldapErrorCode = ldap_errno($this->connection);
|
||||
$this->ldapErrorText = ldap_error($this->connection);
|
||||
dol_syslog("unctions_ldap::check_user_password_ldap ".$this->ldapErrorText);
|
||||
$ldap->ldapErrorCode = ldap_errno($ldap->connection);
|
||||
$ldap->ldapErrorText = ldap_error($ldap->connection);
|
||||
dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorText);
|
||||
}
|
||||
sleep(1);
|
||||
$langs->load('main');
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
* \brief Fichier de gestion des triggers LDAP
|
||||
*/
|
||||
require_once (DOL_DOCUMENT_ROOT."/core/class/ldap.class.php");
|
||||
require_once (DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php");
|
||||
|
||||
|
||||
/**
|
||||
@ -210,6 +211,82 @@ class InterfaceLdapsynchro
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_SETINGROUP')
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
|
||||
// Must edit $object->newgroupid
|
||||
$usergroup=new UserGroup($this->db);
|
||||
if ($object->newgroupid > 0)
|
||||
{
|
||||
$usergroup->fetch($object->newgroupid);
|
||||
|
||||
$oldinfo=$usergroup->_load_ldap_info();
|
||||
$olddn=$usergroup->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$usergroup->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
|
||||
$info=$usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call)
|
||||
$dn=$usergroup->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
elseif ($action == 'USER_REMOVEFROMGROUP')
|
||||
{
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
if ($conf->ldap->enabled && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
|
||||
{
|
||||
$ldap=new Ldap();
|
||||
$ldap->connect_bind();
|
||||
|
||||
// Must edit $object->newgroupid
|
||||
$usergroup=new UserGroup($this->db);
|
||||
if ($object->oldgroupid > 0)
|
||||
{
|
||||
$usergroup->fetch($object->oldgroupid);
|
||||
|
||||
$oldinfo=$usergroup->_load_ldap_info();
|
||||
$olddn=$usergroup->_load_ldap_dn($oldinfo);
|
||||
|
||||
// Verify if entry exist
|
||||
$container=$usergroup->_load_ldap_dn($oldinfo,1);
|
||||
$search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")";
|
||||
$records=$ldap->search($container,$search);
|
||||
if (count($records) && $records['count'] == 0)
|
||||
{
|
||||
$olddn = '';
|
||||
}
|
||||
|
||||
$info=$usergroup->_load_ldap_info(); // Contains all members, included the new one (insert already done before trigger call)
|
||||
$dn=$usergroup->_load_ldap_dn($info);
|
||||
|
||||
$result=$ldap->update($dn,$info,$user,$olddn);
|
||||
if ($result < 0)
|
||||
{
|
||||
$this->error="ErrorLDAP ".$ldap->error;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Groupes
|
||||
elseif ($action == 'GROUP_CREATE')
|
||||
|
||||
@ -1579,6 +1579,8 @@ class User extends CommonObject
|
||||
{
|
||||
if (! $error && ! $notrigger)
|
||||
{
|
||||
$this->newgroupid=$group;
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
$interface=new Interfaces($this->db);
|
||||
@ -1635,6 +1637,8 @@ class User extends CommonObject
|
||||
{
|
||||
if (! $error && ! $notrigger)
|
||||
{
|
||||
$this->oldgroupid=$group;
|
||||
|
||||
// Appel des triggers
|
||||
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
|
||||
$interface=new Interfaces($this->db);
|
||||
@ -1885,8 +1889,10 @@ class User extends CommonObject
|
||||
$this->ref = 'SPECIMEN';
|
||||
$this->specimen=1;
|
||||
|
||||
$this->nom='DOLIBARR';
|
||||
$this->prenom='SPECIMEN';
|
||||
$this->nom='DOLIBARR'; // deprecated
|
||||
$this->prenom='SPECIMEN'; // deprecated
|
||||
$this->lastname='DOLIBARR';
|
||||
$this->firstname='SPECIMEN';
|
||||
$this->note='This is a note';
|
||||
$this->email='email@specimen.com';
|
||||
$this->office_phone='0999999999';
|
||||
|
||||
@ -53,11 +53,11 @@ class UserGroup extends CommonObject
|
||||
/**
|
||||
* Constructor de la classe
|
||||
*
|
||||
* @param DoliDb $DB Database handler
|
||||
* @param DoliDb $db Database handler
|
||||
*/
|
||||
function UserGroup($DB)
|
||||
function UserGroup($db)
|
||||
{
|
||||
$this->db = $DB;
|
||||
$this->db = $db;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -683,19 +683,18 @@ class UserGroup extends CommonObject
|
||||
if ($conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)
|
||||
{
|
||||
$valueofldapfield=array();
|
||||
foreach($this->members as $key=>$val)
|
||||
foreach($this->members as $key=>$val) // This is array of users for group into dolibarr database.
|
||||
{
|
||||
$muser=new User($this->db);
|
||||
$muser->fetch($val);
|
||||
|
||||
$ldapuserid=$muser->login;
|
||||
// TODO ldapuserid should depends on value $conf->global->LDAP_KEY_USERS;
|
||||
$muser->fetch($val->id);
|
||||
if ($conf->global->LDAP_KEY_USERS == 'cn') $ldapuserid=$muser->getFullName($langs);
|
||||
elseif ($conf->global->LDAP_KEY_USERS == 'sn') $ldapuserid=$muser->lastname;
|
||||
elseif ($conf->global->LDAP_KEY_USERS == 'uid') $ldapuserid=$muser->login;
|
||||
|
||||
$valueofldapfield[] = $conf->global->LDAP_KEY_USERS.'='.$ldapuserid.','.$conf->global->LDAP_USER_DN;
|
||||
}
|
||||
$info[$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield)?$valueofldapfield:'');
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
/* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006-2012 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -179,7 +179,7 @@ if ($result > 0)
|
||||
//var_dump($records);
|
||||
|
||||
// Affichage arbre
|
||||
if (count($records) && (! isset($records['count']) || $records['count'] > 0))
|
||||
if (count($records) && $records != false && (! isset($records['count']) || $records['count'] > 0))
|
||||
{
|
||||
if (! is_array($records))
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user