New: Ajout fonction test synchro LDAP sur page config synchro des users et groupes
This commit is contained in:
parent
583d7ef206
commit
6fb4cb6fdd
@ -41,20 +41,22 @@ English Dolibarr changelog
|
|||||||
- Save and show last connexion date for users.
|
- Save and show last connexion date for users.
|
||||||
- Enhancements on a lot of forms for better ergonomy.
|
- Enhancements on a lot of forms for better ergonomy.
|
||||||
- Can add/remove company logo.
|
- Can add/remove company logo.
|
||||||
|
- Added LDAP synchronisation for users, groups and/or contacts.
|
||||||
- Can configure your own SMTP server/port for mail sendings.
|
- Can configure your own SMTP server/port for mail sendings.
|
||||||
- Works even on "UTF8 by default" systems (Mysql, Linux...)
|
- Works even on "UTF8 by default" systems (Mysql, Linux...)
|
||||||
- Better compatibility with different PHP version or setup.
|
- Better compatibility with different PHP version or setup.
|
||||||
- Lot of fixes after 2.0 release not fixed in 2.0.1.
|
- Lot of fixes after 2.0 release not fixed in 2.0.1.
|
||||||
- Added mysqli driver.
|
- Added mysqli driver.
|
||||||
- Traduction more complete.
|
|
||||||
- Add a WISIWYG editor (FCKEditor) to edit note and comment areas.
|
- Add a WISIWYG editor (FCKEditor) to edit note and comment areas.
|
||||||
|
- Added AJAX features like a 'search product selector'.
|
||||||
|
- Modules boxes on main page can be dragged and dropped (with firefox only).
|
||||||
- Support for PHP5.
|
- Support for PHP5.
|
||||||
- Removed obsolete files and documentation.
|
- Removed obsolete files and documentation.
|
||||||
|
- Traduction more complete.
|
||||||
- Added admin tools (backup and files purge).
|
- Added admin tools (backup and files purge).
|
||||||
- Added a tool to build a lang package.
|
- Added a tool to build a lang package.
|
||||||
- Added a tool to build a module package.
|
- Added a tool to build a module package.
|
||||||
- Added a tool to build a theme package.
|
- Added a tool to build a theme package.
|
||||||
- Modules boxes on main page can be dragged and dropped (with firefox only).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -210,7 +210,8 @@ if (function_exists("ldap_connect"))
|
|||||||
if ($conf->global->LDAP_SERVER_HOST)
|
if ($conf->global->LDAP_SERVER_HOST)
|
||||||
{
|
{
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<a class="tabAction" href="'.$_SERVER["PHP_SELF"].'?action=test">'.$langs->trans("LDAPTestSynchroContact").'</a><br><br>';
|
print '<a class="tabAction" href="'.$_SERVER["PHP_SELF"].'?action=test">'.$langs->trans("LDAPTestSynchroContact").'</a>';
|
||||||
|
print '<br><br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_GET["action"] == 'test')
|
if ($_GET["action"] == 'test')
|
||||||
@ -220,7 +221,7 @@ if (function_exists("ldap_connect"))
|
|||||||
$contact->initAsSpecimen();
|
$contact->initAsSpecimen();
|
||||||
|
|
||||||
// Test synchro
|
// Test synchro
|
||||||
$result1=$contact->delete_ldap($user);
|
//$result1=$contact->delete_ldap($user);
|
||||||
$result2=$contact->update_ldap($user);
|
$result2=$contact->update_ldap($user);
|
||||||
$result3=$contact->delete_ldap($user);
|
$result3=$contact->delete_ldap($user);
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require("./pre.inc.php");
|
require("./pre.inc.php");
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/user.class.php");
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/usergroup.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
|
require_once(DOL_DOCUMENT_ROOT."/lib/authldap.lib.php");
|
||||||
|
|
||||||
$langs->load("admin");
|
$langs->load("admin");
|
||||||
@ -206,6 +208,71 @@ print '</div>';
|
|||||||
|
|
||||||
print info_admin($langs->trans("LDAPDescValues"));
|
print info_admin($langs->trans("LDAPDescValues"));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test de la connexion
|
||||||
|
*/
|
||||||
|
if (function_exists("ldap_connect"))
|
||||||
|
{
|
||||||
|
if ($conf->global->LDAP_SERVER_HOST && $conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
|
||||||
|
{
|
||||||
|
print '<br>';
|
||||||
|
print '<a class="tabAction" href="'.$_SERVER["PHP_SELF"].'?action=testuser">'.$langs->trans("LDAPTestSynchroUser").'</a>';
|
||||||
|
print '<a class="tabAction" href="'.$_SERVER["PHP_SELF"].'?action=testgroup">'.$langs->trans("LDAPTestSynchroGroup").'</a>';
|
||||||
|
print '<br><br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_GET["action"] == 'testuser')
|
||||||
|
{
|
||||||
|
// Creation contact
|
||||||
|
$fuser=new User($db);
|
||||||
|
$fuser->initAsSpecimen();
|
||||||
|
|
||||||
|
// Test synchro
|
||||||
|
//$result1=$fuser->delete_ldap($user);
|
||||||
|
$result2=$fuser->update_ldap($user);
|
||||||
|
$result3=$fuser->delete_ldap($user);
|
||||||
|
|
||||||
|
if ($result2 > 0)
|
||||||
|
{
|
||||||
|
print img_picto('','info').' ';
|
||||||
|
print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print img_picto('','error').' ';
|
||||||
|
print '<font class="warning">'.$langs->trans("LDAPSynchroKO");
|
||||||
|
print ': '.$fuser->error;
|
||||||
|
print '</font><br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_GET["action"] == 'testgroup')
|
||||||
|
{
|
||||||
|
// Creation contact
|
||||||
|
$fgroup=new UserGroup($db);
|
||||||
|
$fgroup->initAsSpecimen();
|
||||||
|
|
||||||
|
// Test synchro
|
||||||
|
//$result1=$fgroup->delete_ldap($user);
|
||||||
|
$result2=$fgroup->update_ldap($user);
|
||||||
|
$result3=$fgroup->delete_ldap($user);
|
||||||
|
|
||||||
|
if ($result2 > 0)
|
||||||
|
{
|
||||||
|
print img_picto('','info').' ';
|
||||||
|
print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print img_picto('','error').' ';
|
||||||
|
print '<font class="warning">'.$langs->trans("LDAPSynchroKO");
|
||||||
|
print ': '.$fgroup->error;
|
||||||
|
print '</font><br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
|
|||||||
@ -211,7 +211,7 @@ class Contact
|
|||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
|
|
||||||
if (! $conf->ldap->enabled || ! $conf->global->LDAP_CONTACT_ACTIVE) return 0;
|
//if (! $conf->ldap->enabled || ! $conf->global->LDAP_CONTACT_ACTIVE) return 0;
|
||||||
|
|
||||||
dolibarr_syslog("Contact.class::delete_ldap this->id=".$this->id,LOG_DEBUG);
|
dolibarr_syslog("Contact.class::delete_ldap this->id=".$this->id,LOG_DEBUG);
|
||||||
|
|
||||||
@ -233,7 +233,7 @@ class Contact
|
|||||||
|
|
||||||
if ($bind)
|
if ($bind)
|
||||||
{
|
{
|
||||||
$info["cn"] = utf8_encode(trim($this->firstname." ".$this->name));
|
$info["cn"] = trim($this->firstname." ".$this->name);
|
||||||
$dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN;
|
$dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN;
|
||||||
|
|
||||||
$result=$ldap->delete($dn);
|
$result=$ldap->delete($dn);
|
||||||
|
|||||||
@ -529,6 +529,7 @@ LDAPContactDnExample=Complete DN (ex: ou=contacts,dc=society,dc=com)
|
|||||||
LDAPTestConnect=Test LDAP connection
|
LDAPTestConnect=Test LDAP connection
|
||||||
LDAPTestSynchroContact=Test contact's synchronization
|
LDAPTestSynchroContact=Test contact's synchronization
|
||||||
LDAPTestSynchroUser=Test user's synchronization
|
LDAPTestSynchroUser=Test user's synchronization
|
||||||
|
LDAPTestSynchroGroup=Test group's synchronization
|
||||||
LDAPTestSynchroMember=Test member's synchronization
|
LDAPTestSynchroMember=Test member's synchronization
|
||||||
LDAPSynchroOK=Synchronization test successful
|
LDAPSynchroOK=Synchronization test successful
|
||||||
LDAPSynchroKO=Failed synchronization test
|
LDAPSynchroKO=Failed synchronization test
|
||||||
|
|||||||
@ -529,6 +529,7 @@ LDAPContactDnExample=DN complet (ex: ou=contacts,dc=my-domain,dc=com)
|
|||||||
LDAPTestConnect=Tester la connexion LDAP
|
LDAPTestConnect=Tester la connexion LDAP
|
||||||
LDAPTestSynchroContact=Tester synchronisation contacts
|
LDAPTestSynchroContact=Tester synchronisation contacts
|
||||||
LDAPTestSynchroUser=Tester synchronisation utilisateur
|
LDAPTestSynchroUser=Tester synchronisation utilisateur
|
||||||
|
LDAPTestSynchroGroup=Tester synchronisation groupe
|
||||||
LDAPTestSynchroMember=Tester synchronisation adhérent
|
LDAPTestSynchroMember=Tester synchronisation adhérent
|
||||||
LDAPSynchroOK=Test de synchronisation réalisé avec succès
|
LDAPSynchroOK=Test de synchronisation réalisé avec succès
|
||||||
LDAPSynchroKO=Echec du test de synchronisation
|
LDAPSynchroKO=Echec du test de synchronisation
|
||||||
|
|||||||
@ -1342,6 +1342,107 @@ class User
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Mise à jour de l'arbre LDAP
|
||||||
|
* \param user Utilisateur qui efface
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
|
*/
|
||||||
|
function delete_ldap($user)
|
||||||
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
|
//if (! $conf->ldap->enabled || ! $conf->global->LDAP_SYNCHRO_ACTIVE) return 0;
|
||||||
|
|
||||||
|
dolibarr_syslog("User.class::delete_ldap this->id=".$this->id,LOG_DEBUG);
|
||||||
|
|
||||||
|
$ldap=new AuthLdap();
|
||||||
|
$result=$ldap->connect();
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
$bind='';
|
||||||
|
if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS)
|
||||||
|
{
|
||||||
|
dolibarr_syslog("User.class::delete_ldap authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG);
|
||||||
|
$bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog("User.class::delete_ldap bind",LOG_DEBUG);
|
||||||
|
$bind=$ldap->bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bind)
|
||||||
|
{
|
||||||
|
$info["cn"] = trim($this->prenom." ".$this->nom);
|
||||||
|
$dn = "cn=".$info["cn"].",".$conf->global->LDAP_USER_DN;
|
||||||
|
|
||||||
|
$result=$ldap->delete($dn);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error="Failed to connect to LDAP server !";
|
||||||
|
dolibarr_syslog("User.class::update_ldap Connexion failed",LOG_DEBUG);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Initialise le user avec valeurs fictives aléatoire
|
||||||
|
*/
|
||||||
|
function initAsSpecimen()
|
||||||
|
{
|
||||||
|
global $user,$langs;
|
||||||
|
|
||||||
|
// Charge tableau des id de société socids
|
||||||
|
$socids = array();
|
||||||
|
$sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10";
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num_socs = $this->db->num_rows($resql);
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $num_socs)
|
||||||
|
{
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
$row = $this->db->fetch_row($resql);
|
||||||
|
$socids[$i] = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialise paramètres
|
||||||
|
$this->id=0;
|
||||||
|
$this->ref = 'SPECIMEN';
|
||||||
|
$this->specimen=1;
|
||||||
|
|
||||||
|
$this->nom='DOLIBARR';
|
||||||
|
$this->prenom='SPECIMEN';
|
||||||
|
$this->fullname=trim($this->prenom.' '.$this->nom);
|
||||||
|
$this->note='This is a note';
|
||||||
|
$this->code='DOSP';
|
||||||
|
$this->email='email@specimen.com';
|
||||||
|
$this->office_tel='0999999999';
|
||||||
|
$this->office_fax='0999999998';
|
||||||
|
$this->user_mobile='0999999997';
|
||||||
|
$this->admin=0;
|
||||||
|
$this->login='dolibspec';
|
||||||
|
$this->pass='dolibspec';
|
||||||
|
$this->datec=time();
|
||||||
|
$this->datem=time();
|
||||||
|
$this->webcal_login='dolibspec';
|
||||||
|
|
||||||
|
$this->datelastlogi=time();
|
||||||
|
$this->datepreviouslogin=time();
|
||||||
|
$this->statut=1;
|
||||||
|
|
||||||
|
$socid = rand(1, $num_socs);
|
||||||
|
$this->societe_id = $socids[$socid];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -527,6 +527,70 @@ class UserGroup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Mise à jour de l'arbre LDAP
|
||||||
|
* \param user Utilisateur qui efface
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
|
*/
|
||||||
|
function delete_ldap($user)
|
||||||
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
|
//if (! $conf->ldap->enabled || ! $conf->global->LDAP_SYNCHRO_ACTIVE) return 0;
|
||||||
|
|
||||||
|
dolibarr_syslog("UserGroup.class::delete_ldap this->id=".$this->id,LOG_DEBUG);
|
||||||
|
|
||||||
|
$ldap=new AuthLdap();
|
||||||
|
$result=$ldap->connect();
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
$bind='';
|
||||||
|
if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS)
|
||||||
|
{
|
||||||
|
dolibarr_syslog("UserGroup.class::delete_ldap authBind user=".$conf->global->LDAP_ADMIN_DN,LOG_DEBUG);
|
||||||
|
$bind=$ldap->authBind($conf->global->LDAP_ADMIN_DN,$conf->global->LDAP_ADMIN_PASS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dolibarr_syslog("UserGroup.class::delete_ldap bind",LOG_DEBUG);
|
||||||
|
$bind=$ldap->bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($bind)
|
||||||
|
{
|
||||||
|
$info["cn"] = trim($this->nom);
|
||||||
|
$dn = "cn=".$info["cn"].",".$conf->global->LDAP_GROUP_DN;
|
||||||
|
|
||||||
|
$result=$ldap->delete($dn);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error="Failed to connect to LDAP server !";
|
||||||
|
dolibarr_syslog("UserGroup.class::update_ldap Connexion failed",LOG_DEBUG);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Initialise le groupe avec valeurs fictives aléatoire
|
||||||
|
*/
|
||||||
|
function initAsSpecimen()
|
||||||
|
{
|
||||||
|
global $user,$langs;
|
||||||
|
|
||||||
|
// Initialise paramètres
|
||||||
|
$this->id=0;
|
||||||
|
$this->ref = 'SPECIMEN';
|
||||||
|
$this->specimen=1;
|
||||||
|
|
||||||
|
$this->nom='DOLIBARR GROUP SPECIMEN';
|
||||||
|
$this->note='This is a note';
|
||||||
|
$this->datec=time();
|
||||||
|
$this->datem=time();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user