diff --git a/ChangeLog b/ChangeLog index 1defc966497..7c0cf8c87d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,20 +41,22 @@ English Dolibarr changelog - Save and show last connexion date for users. - Enhancements on a lot of forms for better ergonomy. - Can add/remove company logo. +- Added LDAP synchronisation for users, groups and/or contacts. - Can configure your own SMTP server/port for mail sendings. - Works even on "UTF8 by default" systems (Mysql, Linux...) - Better compatibility with different PHP version or setup. - Lot of fixes after 2.0 release not fixed in 2.0.1. - Added mysqli driver. -- Traduction more complete. - 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. - Removed obsolete files and documentation. +- Traduction more complete. - Added admin tools (backup and files purge). - Added a tool to build a lang package. - Added a tool to build a module package. - Added a tool to build a theme package. -- Modules boxes on main page can be dragged and dropped (with firefox only). diff --git a/htdocs/admin/ldap_contacts.php b/htdocs/admin/ldap_contacts.php index 49dedce1a1c..8f852299486 100644 --- a/htdocs/admin/ldap_contacts.php +++ b/htdocs/admin/ldap_contacts.php @@ -210,7 +210,8 @@ if (function_exists("ldap_connect")) if ($conf->global->LDAP_SERVER_HOST) { print '
'; - print ''.$langs->trans("LDAPTestSynchroContact").'

'; + print ''.$langs->trans("LDAPTestSynchroContact").''; + print '

'; } if ($_GET["action"] == 'test') @@ -220,7 +221,7 @@ if (function_exists("ldap_connect")) $contact->initAsSpecimen(); // Test synchro - $result1=$contact->delete_ldap($user); + //$result1=$contact->delete_ldap($user); $result2=$contact->update_ldap($user); $result3=$contact->delete_ldap($user); diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index 88c40e9850d..c745c6ec56b 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -31,6 +31,8 @@ */ 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"); $langs->load("admin"); @@ -206,6 +208,71 @@ print ''; 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 '
'; + print ''.$langs->trans("LDAPTestSynchroUser").''; + print ''.$langs->trans("LDAPTestSynchroGroup").''; + print '

'; + } + + 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 ''.$langs->trans("LDAPSynchroOK").'
'; + } + else + { + print img_picto('','error').' '; + print ''.$langs->trans("LDAPSynchroKO"); + print ': '.$fuser->error; + print '
'; + } + + } + + 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 ''.$langs->trans("LDAPSynchroOK").'
'; + } + else + { + print img_picto('','error').' '; + print ''.$langs->trans("LDAPSynchroKO"); + print ': '.$fgroup->error; + print '
'; + } + + } +} $db->close(); diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index af3ff8abdc4..6f7098f3217 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -211,7 +211,7 @@ class Contact { 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); @@ -233,7 +233,7 @@ class Contact 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; $result=$ldap->delete($dn); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 9248786b77f..682f809ac22 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -529,6 +529,7 @@ LDAPContactDnExample=Complete DN (ex: ou=contacts,dc=society,dc=com) LDAPTestConnect=Test LDAP connection LDAPTestSynchroContact=Test contact's synchronization LDAPTestSynchroUser=Test user's synchronization +LDAPTestSynchroGroup=Test group's synchronization LDAPTestSynchroMember=Test member's synchronization LDAPSynchroOK=Synchronization test successful LDAPSynchroKO=Failed synchronization test diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index d20428bc194..d73e84e82ca 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -529,6 +529,7 @@ LDAPContactDnExample=DN complet (ex: ou=contacts,dc=my-domain,dc=com) LDAPTestConnect=Tester la connexion LDAP LDAPTestSynchroContact=Tester synchronisation contacts LDAPTestSynchroUser=Tester synchronisation utilisateur +LDAPTestSynchroGroup=Tester synchronisation groupe LDAPTestSynchroMember=Tester synchronisation adhérent LDAPSynchroOK=Test de synchronisation réalisé avec succès LDAPSynchroKO=Echec du test de synchronisation diff --git a/htdocs/user.class.php b/htdocs/user.class.php index a7f687f961c..03cf0560b24 100644 --- a/htdocs/user.class.php +++ b/htdocs/user.class.php @@ -1341,7 +1341,108 @@ class User return -1; } } + + + /** + * \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]; + } } ?> diff --git a/htdocs/usergroup.class.php b/htdocs/usergroup.class.php index 0a8dad3adb9..1220e3a8779 100644 --- a/htdocs/usergroup.class.php +++ b/htdocs/usergroup.class.php @@ -1,7 +1,7 @@ * Copyright (c) 2005 Laurent Destailleur - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -20,14 +20,14 @@ * $Source$ */ -/** +/** \file htdocs/usergroup.class.php \brief Fichier de la classe des groupes d'utilisateur \author Rodolphe Qiedeville \version $Revision$ */ -/** +/** \class UserGroup \brief Classe permettant la gestion des groupes d'utilisateur */ @@ -35,7 +35,7 @@ class UserGroup { var $db; - + var $id; var $nom; var $note; @@ -52,7 +52,7 @@ class UserGroup { $this->db = $DB; $this->id = $id; - + return 0; } @@ -64,19 +64,19 @@ class UserGroup function fetch($id) { $this->id = $id; - + $sql = "SELECT g.rowid, g.nom, g.note, g.datec, tms as datem"; $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g"; $sql .= " WHERE g.rowid = ".$this->id; - + $result = $this->db->query($sql); - + if ($result) { if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); - + $this->id = $obj->rowid; $this->nom = $obj->nom; $this->note = $obj->note; @@ -84,16 +84,16 @@ class UserGroup $this->datem = $obj->datem; } $this->db->free($result); - + } else { dolibarr_syslog("UserGroup::Fetch Erreur"); } - + } - + /** * \brief Ajoute un droit a l'utilisateur * \param rid id du droit à ajouter @@ -105,10 +105,10 @@ class UserGroup { $err=0; $whereforadd=''; - + $this->db->begin(); - if ($rid) + if ($rid) { // Si on a demandé ajout d'un droit en particulier, on récupère // les caractéristiques (module, perms et subperms) de ce droit. @@ -116,7 +116,7 @@ class UserGroup $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; $sql.= " WHERE "; $sql.=" id = '".$rid."'"; - + $result=$this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); @@ -152,7 +152,7 @@ class UserGroup $sql = "SELECT id"; $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; $sql.= " WHERE $whereforadd"; - + $result=$this->db->query($sql); if ($result) { @@ -162,22 +162,22 @@ class UserGroup { $obj = $this->db->fetch_object($result); $nid = $obj->id; - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights WHERE fk_usergroup = $this->id AND fk_id=$nid"; if (! $this->db->query($sql)) $err++; $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_rights (fk_usergroup, fk_id) VALUES ($this->id, $nid)"; if (! $this->db->query($sql)) $err++; - + $i++; } } - else + else { $err++; dolibarr_print_error($this->db); } } - + if ($err) { $this->db->rollback(); return -$err; @@ -186,7 +186,7 @@ class UserGroup $this->db->commit(); return 1; } - + } @@ -201,10 +201,10 @@ class UserGroup { $err=0; $wherefordel=''; - + $this->db->begin(); - if ($rid) + if ($rid) { // Si on a demandé supression d'un droit en particulier, on récupère // les caractéristiques module, perms et subperms de ce droit. @@ -212,7 +212,7 @@ class UserGroup $sql.= " FROM ".MAIN_DB_PREFIX."rights_def"; $sql.= " WHERE "; $sql.=" id = '".$rid."'"; - + $result=$this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); @@ -258,20 +258,20 @@ class UserGroup { $obj = $this->db->fetch_object($result); $nid = $obj->id; - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights WHERE fk_usergroup = $this->id AND fk_id=$nid"; if (! $this->db->query($sql)) $err++; - + $i++; } } - else + else { $err++; dolibarr_print_error($this->db); } } - + if ($err) { $this->db->rollback(); return -$err; @@ -282,7 +282,7 @@ class UserGroup } } - + /** * \brief Charge dans l'objet group, la liste des permissions auquels le groupe a droit @@ -333,7 +333,7 @@ class UserGroup // que les droits sont en cache (car tous chargés) pour cet instance de user $this->all_permissions_are_loaded=1; } - + } /** @@ -343,7 +343,7 @@ class UserGroup function delete() { $this->db->begin(); - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights"; $sql .= " WHERE fk_usergroup = ".$this->id; $this->db->query($sql); @@ -355,7 +355,7 @@ class UserGroup $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup"; $sql .= " WHERE rowid = ".$this->id; $result=$this->db->query($sql); - if ($result) + if ($result) { $this->db->commit(); return 1; @@ -439,7 +439,7 @@ class UserGroup $info = array(); dolibarr_syslog("UserGroup.class::update_ldap this->id=".$this->id,LOG_DEBUG); - + $ldap=new AuthLdap(); $result=$ldap->connect(); if ($result) @@ -457,7 +457,7 @@ class UserGroup } if ($bind) { - if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') { $info["objectclass"]=array("top", "person", @@ -470,7 +470,7 @@ class UserGroup "person", "organizationalPerson", "inetOrgPerson"); - } + } // Champs obligatoires $info["cn"] = trim($this->nom); @@ -481,7 +481,7 @@ class UserGroup $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); return -1; } - + // Champs optionnels if ($this->note) $info["description"] = $this->note; @@ -492,20 +492,20 @@ class UserGroup if ($this->old_name) $olddn="cn=".trim($this->old_name).",".$conf->global->LDAP_CONTACT_DN; // On supprime et on insère - dolibarr_syslog("UserGroup.class::update_ldap olddn=".$olddn." newdn=".$newdn); + dolibarr_syslog("UserGroup.class::update_ldap olddn=".$olddn." newdn=".$newdn); $result = $ldap->delete($olddn); $result = $ldap->add($newdn, $info); if ($result <= 0) { $this->error = ldap_errno($ldap->connection)." ".ldap_error($ldap->connection)." ".$ldap->error; - dolibarr_syslog("UserGroup.class::update_ldap ".$this->error,LOG_ERROR); + dolibarr_syslog("UserGroup.class::update_ldap ".$this->error,LOG_ERROR); //print_r($info); return -1; } else { - dolibarr_syslog("UserGroup.class::update_ldap rowid=".$this->id." added in LDAP"); + dolibarr_syslog("UserGroup.class::update_ldap rowid=".$this->id." added in LDAP"); } $ldap->unbind(); @@ -526,7 +526,71 @@ class UserGroup return -1; } } - + + /** + * \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(); + } } ?>