From e69b80ac527b60f72d21b958fd88d4b472b39778 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Nov 2006 21:59:10 +0000 Subject: [PATCH] =?UTF-8?q?Am=E9lioration=20gestion=20erreur=20synchro=20L?= =?UTF-8?q?DAP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev/ldap/ldapadd_sample1.txt | 13 + dev/ldap/ldapadd_sample2.txt | 10 + dev/ldap/ldapadd_sample3.txt | 19 + dev/ldap/ldapdelete_sample1.txt | 9 + dev/ldap/ldapdelete_sample3.txt | 9 + dev/ldap/ldapmodify_sample1.txt | 14 + htdocs/admin/ldap.php | 58 +- htdocs/admin/ldap_contacts.php | 53 +- htdocs/admin/ldap_users.php | 114 +--- htdocs/contact.class.php | 585 +++++++++--------- htdocs/includes/modules/modLdap.class.php | 124 +++- htdocs/langs/en_US/admin.lang | 21 +- htdocs/langs/fr_FR/admin.lang | 31 +- htdocs/lib/authldap.lib.php | 47 +- htdocs/main.inc.php | 8 +- scripts/company/ldap-update-allcontact.php | 57 -- .../company/sync_contacts_dolibarr2ldap.php | 90 +++ 17 files changed, 728 insertions(+), 534 deletions(-) create mode 100644 dev/ldap/ldapadd_sample1.txt create mode 100644 dev/ldap/ldapadd_sample2.txt create mode 100644 dev/ldap/ldapadd_sample3.txt create mode 100644 dev/ldap/ldapdelete_sample1.txt create mode 100644 dev/ldap/ldapdelete_sample3.txt create mode 100644 dev/ldap/ldapmodify_sample1.txt delete mode 100644 scripts/company/ldap-update-allcontact.php create mode 100644 scripts/company/sync_contacts_dolibarr2ldap.php diff --git a/dev/ldap/ldapadd_sample1.txt b/dev/ldap/ldapadd_sample1.txt new file mode 100644 index 00000000000..8a11738d1bb --- /dev/null +++ b/dev/ldap/ldapadd_sample1.txt @@ -0,0 +1,13 @@ +# ldapadd_sample1.txt +# +# Use this sample to add a dc "my-domain". +# This is the first thing to create +# +# ldapadd -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapadd_sample1.txt + +dn: dc=my-domain,dc=com +objectclass: dcObject +objectClass: organization +objectClass: top +dc: my-domain +o: Mon organisation \ No newline at end of file diff --git a/dev/ldap/ldapadd_sample2.txt b/dev/ldap/ldapadd_sample2.txt new file mode 100644 index 00000000000..47c86534a48 --- /dev/null +++ b/dev/ldap/ldapadd_sample2.txt @@ -0,0 +1,10 @@ +# ldapadd_sample2.txt +# +# Use this sample to add a ou "contacts" +# This is the second thing to create after creating the root my-domain +# +# ldapadd -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapadd_sample1.txt + +dn: ou=contacts,dc=my-domain,dc=com +objectClass: organizationalUnit +ou: contacts \ No newline at end of file diff --git a/dev/ldap/ldapadd_sample3.txt b/dev/ldap/ldapadd_sample3.txt new file mode 100644 index 00000000000..5acfad510b7 --- /dev/null +++ b/dev/ldap/ldapadd_sample3.txt @@ -0,0 +1,19 @@ +# ldapadd_sample3.txt +# +# Use this sample to add cn records +# This is the step to create records inside tree ou=contacts,dc=my-domain,dc=com +# +# ldapadd -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapadd_sample3.txt + +dn: cn=Bruno et Sabine Tary,ou=contacts,dc=my-domain,dc=com +objectClass: inetOrgPerson +objectClass: organizationalPerson +objectClass: person +objectClass: top +cn: Bruno et Sabine Tary +cn: Barbara Jensen +cn: Babs Jensen +sn: Jensen +description: aaa +title: this is title +mail: mail@mail.com diff --git a/dev/ldap/ldapdelete_sample1.txt b/dev/ldap/ldapdelete_sample1.txt new file mode 100644 index 00000000000..d9f6cd5a941 --- /dev/null +++ b/dev/ldap/ldapdelete_sample1.txt @@ -0,0 +1,9 @@ +# ldapdelete_sample1.txt +# +# Use this sample to delete a dc "my-domain" +# This delete the first level of LDAP tree. +# +# ldapmodify -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapdelete_sample1.txt + +dn: dc=my-domain,dc=com +changetype: delete diff --git a/dev/ldap/ldapdelete_sample3.txt b/dev/ldap/ldapdelete_sample3.txt new file mode 100644 index 00000000000..8571e16972a --- /dev/null +++ b/dev/ldap/ldapdelete_sample3.txt @@ -0,0 +1,9 @@ +# ldapdelete_sample3.txt +# +# Use this sample to delete cn records +# This is the step to delete a cn record stored inside tree ou=contacts,dc=my-domain,dc=com +# +# ldapmodify -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapdelete_sample3.txt + +dn: cn=Bruno et Sabine Tary,ou=contacts,dc=my-domain,dc=com +changetype: delete diff --git a/dev/ldap/ldapmodify_sample1.txt b/dev/ldap/ldapmodify_sample1.txt new file mode 100644 index 00000000000..2ecc031e62b --- /dev/null +++ b/dev/ldap/ldapmodify_sample1.txt @@ -0,0 +1,14 @@ +# ldapmodify_sample1.txt +# +# Use this sample to modify a dc "my-domain" +# +# ldapmodify -c -v -D cn=Manager,dc=my-domain,dc=com -W -f ldapmodify_sample1.txt + +dn: dc=my-domain,dc=com +changetype: modify +replace: o +objectclass: dcObject +objectClass: organization +objectClass: top +dc: my-domain +o: Mon organisation \ No newline at end of file diff --git a/htdocs/admin/ldap.php b/htdocs/admin/ldap.php index 89c1006b4fc..cc8f142135b 100644 --- a/htdocs/admin/ldap.php +++ b/htdocs/admin/ldap.php @@ -54,49 +54,23 @@ if (!$user->admin) if ($_GET["action"] == 'setvalue' && $user->admin) { - if (! dolibarr_set_const($db, 'LDAP_SERVER_TYPE',$_POST["type"])) + $error=0; + + if (! dolibarr_set_const($db, 'LDAP_SERVER_TYPE',$_POST["type"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',$_POST["version"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST',$_POST["host"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST_SLAVE',$_POST["slave"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_PORT',$_POST["port"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_DN',$_POST["dn"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_ADMIN_DN',$_POST["admin"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_ADMIN_PASS',$_POST["pass"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SERVER_USE_TLS',$_POST["usetls"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_CONTACT_ACTIVE',$_POST["activecontact"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_SYNCHRO_ACTIVE',$_POST["activesynchro"])) $error++; + + if ($error) { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SERVER_PROTOCOLVERSION',$_POST["version"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST',$_POST["host"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SERVER_HOST_SLAVE',$_POST["slave"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SERVER_PORT',$_POST["port"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SERVER_DN',$_POST["dn"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_ADMIN_DN',$_POST["admin"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_ADMIN_PASS',$_POST["pass"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SERVER_USE_TLS',$_POST["usetls"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_CONTACT_ACTIVE',$_POST["activecontact"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_SYNCHRO_ACTIVE',$_POST["activesynchro"])) - { - print $db->error(); + dolibarr_print_error($db->error()); } } diff --git a/htdocs/admin/ldap_contacts.php b/htdocs/admin/ldap_contacts.php index 9270529646f..035aee4d0ac 100644 --- a/htdocs/admin/ldap_contacts.php +++ b/htdocs/admin/ldap_contacts.php @@ -54,9 +54,18 @@ if (!$user->admin) if ($_GET["action"] == 'setvalue' && $user->admin) { - if (! dolibarr_set_const($db, 'LDAP_CONTACT_DN',$_POST["contactdn"])) + $error=0; + if (! dolibarr_set_const($db, 'LDAP_CONTACT_DN',$_POST["contactdn"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',$_POST["fieldmail"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_PHONE',$_POST["fieldphone"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',$_POST["fieldfax"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MOBILE',$_POST["fieldmobile"])) $error++; + + if ($error) { - print $db->error(); + dolibarr_print_error($db->error()); } } @@ -111,6 +120,8 @@ if ($conf->global->LDAP_MEMBERS_ACTIVE) dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP")); +print $langs->trans("LDAPDescContact").'
'; +print '
'; print '
'; @@ -130,6 +141,43 @@ print ''.$langs->trans("LDAPContactDn").''; print ''; print ''.$langs->trans("LDAPContactDnExample").''; +// Name +$var=!$var; +print ''.$langs->trans("LDAPFieldName").''; +print ''; +print ''.$langs->trans("LDAPFieldNameExample").''; + +// Firstname +$var=!$var; +print ''.$langs->trans("LDAPFieldFirstName").''; +print ''; +print ''.$langs->trans("LDAPFieldFirstNameExample").''; + + +// Mail +$var=!$var; +print ''.$langs->trans("LDAPFieldMail").''; +print ''; +print ''.$langs->trans("LDAPFieldMailExample").''; + +// Phone +$var=!$var; +print ''.$langs->trans("LDAPFieldPhone").''; +print ''; +print ''.$langs->trans("LDAPFieldPhoneExample").''; + +// Fax +$var=!$var; +print ''.$langs->trans("LDAPFieldFax").''; +print ''; +print ''.$langs->trans("LDAPFieldFaxExample").''; + +// Mobile +$var=!$var; +print ''.$langs->trans("LDAPFieldMobile").''; +print ''; +print ''.$langs->trans("LDAPFieldMobileExample").''; + print ''; print ''; @@ -138,6 +186,7 @@ print '
'; print ''; +print info_admin($langs->trans("LDAPDescValues")); $db->close(); diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index 3a64592558a..8ad0b85ae10 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -54,21 +54,21 @@ if (!$user->admin) if ($_GET["action"] == 'setvalue' && $user->admin) { - if (! dolibarr_set_const($db, 'LDAP_USER_DN',$_POST["user"])) + $error=0; + if (! dolibarr_set_const($db, 'LDAP_USER_DN',$_POST["user"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',$_POST["group"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',$_POST["fieldloginsamba"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',$_POST["fieldname"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',$_POST["fieldfirstname"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',$_POST["fieldmail"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_PHONE',$_POST["fieldphone"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',$_POST["fieldfax"])) $error++; + if (! dolibarr_set_const($db, 'LDAP_FIELD_MOBILE',$_POST["fieldmobile"])) $error++; + + if ($error) { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',$_POST["group"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',$_POST["fieldlogin"])) - { - print $db->error(); - } - if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',$_POST["filterconnection"])) - { - print $db->error(); + dolibarr_print_error($db->error()); } } @@ -123,6 +123,9 @@ if ($conf->global->LDAP_MEMBERS_ACTIVE) dolibarr_fiche_head($head, $hselected, $langs->trans("LDAP")); +print $langs->trans("LDAPDescUsers").'
'; +print '
'; + print '
'; @@ -151,122 +154,58 @@ print ''.$langs->trans("LDAPGroupDnExample").''; // Filtre de connexion $var=!$var; print ''.$langs->trans("LDAPFilterConnection").''; -if ($conf->global->LDAP_FILTER_CONNECTION) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFilterConnectionExample").''; // Login unix $var=!$var; print ''.$langs->trans("LDAPFieldLoginUnix").''; -if ($conf->global->LDAP_FIELD_LOGIN) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldLoginExample").''; // Login samba $var=!$var; print ''.$langs->trans("LDAPFieldLoginSamba").''; -if ($conf->global->LDAP_FIELD_LOGIN_SAMBA) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldLoginSambaExample").''; // Name $var=!$var; print ''.$langs->trans("LDAPFieldName").''; -if ($conf->global->LDAP_FIELD_NAME) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldNameExample").''; // Firstname $var=!$var; print ''.$langs->trans("LDAPFieldFirstName").''; -if ($conf->global->LDAP_FIELD_FIRSTNAME) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldFirstNameExample").''; // Mail $var=!$var; print ''.$langs->trans("LDAPFieldMail").''; -if ($conf->global->LDAP_FIELD_MAIL) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldMailExample").''; // Phone $var=!$var; print ''.$langs->trans("LDAPFieldPhone").''; -if ($conf->global->LDAP_FIELD_PHONE) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldPhoneExample").''; // Fax $var=!$var; print ''.$langs->trans("LDAPFieldFax").''; -if ($conf->global->LDAP_FIELD_FAX) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldFaxExample").''; // Mobile $var=!$var; print ''.$langs->trans("LDAPFieldMobile").''; -if ($conf->global->LDAP_FIELD_MOBILE) -{ - print ''; -} -else -{ - print ''; -} +print ''; print ''.$langs->trans("LDAPFieldMobileExample").''; - print ''; print ''; @@ -274,6 +213,7 @@ print '
'; print ''; +print info_admin($langs->trans("LDAPDescValues")); $db->close(); diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index fa59dd0c3ac..eac0cf5b2df 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -177,215 +177,240 @@ class Contact return 1; } - /** - * \brief Mise à jour de l'arbre ldap - * \param user Utilisateur qui effectue la mise à jour - * - */ - function update_ldap($user) - { - $info = array(); - dolibarr_syslog("Contact::update_ldap",LOG_DEBUG); - - $this->fetch($this->id); - $ldap = New AuthLdap(); - - if ($ldap->connect()) - { - if (bind()) - { - if (LDAP_SERVER_TYPE == 'activedirectory') //enlever utf8 pour etre compatible Windows - { - $info["objectclass"][0] = "top"; - $info["objectclass"][1] = "person"; - $info["objectclass"][2] = "organizationalPerson"; - //$info["objectclass"][3] = "inetOrgPerson"; - $info["objectclass"][3] = "user"; - - $info["cn"] = $this->firstname." ".$this->name; - $info["sn"] = $this->name; - $info["givenName"] = $this->firstname; - - if ($this->poste) $info["title"] = $this->poste; - - if ($this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $info["o"] = $soc->nom; - $info["company"] = $soc->nom; - - if ($soc->client == 1) - { - $info["businessCategory"] = "Clients"; - } - elseif ($soc->client == 2) - { - $info["businessCategory"] = "Prospects"; - } - - if ($soc->fournisseur == 1) - { - $info["businessCategory"] = "Fournisseurs"; - } - - if ($soc->ville) - { - if ($soc->adresse) - { - $info["streetAddress"] = $soc->adresse; - } - if ($soc->cp) - { - $info["postalCode"] = $soc->cp; - } - - $info["l"] = $soc->ville; - } - } - - if ($this->phone_pro) - $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); - - if ($this->phone_perso) - $info["homePhone"] = dolibarr_print_phone($this->phone_perso); - - if ($this->phone_mobile) - $info["mobile"] = dolibarr_print_phone($this->phone_mobile); - - if ($this->fax) - $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); - - if ($this->note) - $info["description"] = ($this->note); - if ($this->email) - $info["mail"] = $this->email; - - $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN; - - $r = @ldap_delete($ds, $dn); - - if (! @ldap_add($ds, $dn, $info)) - { - $this->error[0] = ldap_err2str(ldap_errno($ds)); - } - } - else - { - $info["objectclass"][0] = "top"; - $info["objectclass"][1] = "person"; - $info["objectclass"][2] = "organizationalPerson"; - $info["objectclass"][3] = "inetOrgPerson"; - - $info["cn"] = utf8_encode($this->firstname." ".$this->name); - $info["sn"] = utf8_encode($this->name); - $info["givenName"] = utf8_encode($this->firstname); - - if ($this->poste) - $info["title"] = utf8_encode($this->poste); - - if ($this->socid > 0) - { - $soc = new Societe($this->db); - $soc->fetch($this->socid); - $info["o"] = utf8_encode($soc->nom); - - if ($soc->client == 1) - $info["businessCategory"] = utf8_encode("Clients"); - elseif ($soc->client == 2) - $info["businessCategory"] = utf8_encode("Prospects"); - - if ($soc->fournisseur == 1) - $info["businessCategory"] = utf8_encode("Fournisseurs"); - - if ($soc->ville) - { - if ($soc->adresse) - $info["street"] = utf8_encode($soc->adresse); - - if ($soc->cp) - $info["postalCode"] = utf8_encode($soc->cp); - - $info["l"] = utf8_encode($soc->ville); - } - } - - if ($this->phone_pro) - $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); - - if ($this->phone_perso) - $info["homePhone"] = dolibarr_print_phone($this->phone_perso); - - if ($this->phone_mobile) - $info["mobile"] = dolibarr_print_phone($this->phone_mobile); - - if ($this->fax) - $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); - - if ($this->note) - $info["description"] = ($this->note); - - if(LDAP_SERVER_TYPE == 'egroupware') - { - $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware - - if ($this->email) - $info["rfc822Mailbox"] = $this->email; - - $info['uidnumber'] = $this->id; - - $info['phpgwTz'] = 0; - $info['phpgwMailType'] = 'INTERNET'; - $info['phpgwMailHomeType'] = 'INTERNET'; - - $info["uid"] = $this->id. ":".$info["sn"]; - $info["phpgwContactTypeId"] = 'n'; - $info["phpgwContactCatId"] = 0; - $info["phpgwContactAccess"] = "public"; - - if (strlen($user->egroupware_id) == 0) - { - $user->egroupware_id = 1; - } - - $info["phpgwContactOwner"] = $user->egroupware_id; - - if ($this->phone_mobile) - $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile); - } - else - { - if ($this->email) - $info["mail"] = $this->email; - } + /** + * \brief Mise à jour de l'arbre LDAP + * \param user Utilisateur qui effectue la mise à jour + * \return int <0 si ko, >0 si ok + */ + function update_ldap($user) + { + global $conf, $langs; + $info = array(); - $dn = "cn=".$info["cn"].",".LDAP_CONTACT_DN; - - dolibarr_syslog("Contact::update_ldap dn : ".$dn,LOG_DEBUG); - - $r = @ldap_delete($ds, $dn); - - if (! @ldap_add($ds, $dn, $info)) - { - $this->error[0] = ldap_err2str(ldap_errno($ds)); - dolibarr_syslog("Contact::update_ldap error : ".$this->error[0],LOG_ERR); - } - } - } - else - { - dolibarr_syslog("Contact::update_ldap bind failed",LOG_DEBUG); - } + dolibarr_syslog("Contact.class::update_ldap",LOG_DEBUG); - $ldap->unbind(); + $this->fetch($this->id); + + $ldap=new AuthLdap(); + $result=$ldap->connect(); + if ($result) + { + $bind=''; + if ($conf->global->LDAP_ADMIN_DN && $conf->global->LDAP_ADMIN_PASS) + { + dolibarr_syslog("Contact.class::update_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("Contact.class::update_ldap bind",LOG_DEBUG); + $bind=$ldap->bind(); + } + if ($bind) + { + if ($conf->global->LDAP_SERVER_TYPE == 'activedirectory') + { + // Pas de conversion utf8 pour etre compatible Windows + + $info["objectclass"][0] = "top"; + $info["objectclass"][1] = "person"; + $info["objectclass"][2] = "organizationalPerson"; + //$info["objectclass"][3] = "inetOrgPerson"; + $info["objectclass"][3] = "user"; - } - else - { - dolibarr_syslog("Contact::update_ldap Connexion failed",LOG_DEBUG); - echo "Impossible de se connecter au serveur LDAP !"; - } - } + $info["cn"] = trim($this->firstname." ".$this->name); + $info["sn"] = $this->name; + $info["givenName"] = $this->firstname; + + if ($this->poste) $info["title"] = $this->poste; + + if ($this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + $info["o"] = $soc->nom; + $info["company"] = $soc->nom; + + if ($soc->client == 1) + { + $info["businessCategory"] = "Customers"; + } + elseif ($soc->client == 2) + { + $info["businessCategory"] = "Prospects"; + } + + if ($soc->fournisseur == 1) + { + $info["businessCategory"] = "Suppliers"; + } + + if ($soc->ville) + { + if ($soc->adresse) + { + $info["streetAddress"] = $soc->adresse; + } + if ($soc->cp) + { + $info["postalCode"] = $soc->cp; + } + + $info["l"] = $soc->ville; + } + } + + if ($this->phone_pro) + $info["telephoneNumber"] = dolibarr_print_phone($this->phone_pro); + + if ($this->phone_perso) + $info["homePhone"] = dolibarr_print_phone($this->phone_perso); + + if ($this->phone_mobile) + $info["mobile"] = dolibarr_print_phone($this->phone_mobile); + + if ($this->fax) + $info["facsimileTelephoneNumber"] = dolibarr_print_phone($this->fax); + + if ($this->note) + $info["description"] = $this->note; + + if ($this->email) + $info["mail"] = $this->email; + + $dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; + + // On supprime et on insère + dolibarr_syslog("Contact.class::update_ldap dn=".$dn." info=".$info); + $r = @ldap_delete($ldap->connection, $dn); + if (! @ldap_add($ldap->connection, $dn, $info)) + { + $this->error = ldap_err2str(ldap_errno($ldap->connection)); + dolibarr_syslog("Contact.class::update_ldap ldap_add ".$this->error); + return -1; + } + else + { + dolibarr_syslog("Contact.class::update_ldap rowid=".$this->rowid." added in LDAP"); + } + } + else + { + // OpenLDAP. On encode les param en utf8 + + $info["objectclass"]=array("top", + "person", + "organizationalPerson", + "inetOrgPerson"); + + // Champs obligatoires + $info["cn"] = utf8_encode(trim($this->firstname." ".$this->name)); + if ($this->name) $info[$conf->global->LDAP_FIELD_NAME] = utf8_encode($this->name); + else + { + $langs->load("other"); + $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Name")); + return -1; + } + + // Champs optionnels + if ($this->firstname) $info[$conf->global->LDAP_FIELD_FIRSTNAME] = utf8_encode($this->firstname); + + if ($this->poste) $info["title"] = utf8_encode($this->poste); + + if ($this->socid > 0) + { + $soc = new Societe($this->db); + $soc->fetch($this->socid); + + $info["o"] = utf8_encode($soc->nom); + + if ($soc->client == 1) $info["businessCategory"] = utf8_encode("Customers"); + if ($soc->client == 2) $info["businessCategory"] = utf8_encode("Prospects"); + if ($soc->fournisseur == 1) $info["businessCategory"] = utf8_encode("Suppliers"); + if ($soc->adresse) $info["street"] = utf8_encode($soc->adresse); + if ($soc->cp) $info["postalCode"] = utf8_encode($soc->cp); + if ($soc->ville) $info["l"] = utf8_encode($soc->ville); + } + + if ($this->phone_pro) $info[$conf->global->LDAP_FIELD_PHONE] = utf8_encode($this->phone_pro); + + if ($this->phone_perso) $info["homePhone"] = utf8_encode($this->phone_perso); + + if ($this->phone_mobile) $info[$conf->global->LDAP_FIELD_MOBILE] = utf8_encode($this->phone_mobile); + + if ($this->fax) $info[$conf->global->LDAP_FIELD_FAX] = utf8_encode($this->fax); + + if ($this->note) $info["description"] = utf8_encode($this->note); + + if ($this->email) $info[$conf->global->LDAP_FIELD_MAIL] = utf8_encode($this->email); + + if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') + { + $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware + + if ($this->email) $info["rfc822Mailbox"] = $this->email; + + $info['uidnumber'] = $this->id; + + $info['phpgwTz'] = 0; + $info['phpgwMailType'] = 'INTERNET'; + $info['phpgwMailHomeType'] = 'INTERNET'; + + $info["phpgwContactTypeId"] = 'n'; + $info["phpgwContactCatId"] = 0; + $info["phpgwContactAccess"] = "public"; + + if (strlen($user->egroupware_id) == 0) + { + $user->egroupware_id = 1; + } + + $info["phpgwContactOwner"] = $user->egroupware_id; + + if ($this->phone_mobile) + $info["phpgwCellTelephoneNumber"] = dolibarr_print_phone($this->phone_mobile); + } + + $info["uid"] = "Dolibarr ".$this->id. ": ".utf8_encode(trim($this->firstname." ".$this->name)); + + $dn = "cn=".$info["cn"].",".$conf->global->LDAP_CONTACT_DN; + + // On supprime et on insère + dolibarr_syslog("Contact.class::update_ldap dn=".$dn." info=".$info); + $result = $ldap->delete($dn); + $result = $ldap->add($dn, $info); + if ($result <= 0) + { + $this->error = $ldap->error." ".ldap_errno($ldap->connection)." ".ldap_error($ldap->connection); + dolibarr_syslog("Contact.class::update_ldap ".$this->error); + print_r($info); + return -1; + } + else + { + dolibarr_syslog("Contact.class::update_ldap rowid=".$this->rowid." added in LDAP"); + } + } + + $ldap->unbind(); + + return 1; + } + else + { + $this->error = "Error ".ldap_errno($ldap->connection)." ".ldap_error($ldap->connection); + dolibarr_syslog("Contact.class::update_ldap bind failed",LOG_DEBUG); + return -1; + } + } + else + { + $this->error="Failed to connect to LDAP server !"; + dolibarr_syslog("Contact::update_ldap Connexion failed",LOG_DEBUG); + return -1; + } + } /* @@ -484,12 +509,12 @@ class Contact $this->socid = $obj->fk_soc; $this->poste = $obj->poste; - $this->fullname = $this->firstname . ' ' . $this->name; + $this->fullname = trim($this->firstname . ' ' . $this->name); - $this->phone_pro = $obj->phone; - $this->fax = $obj->fax; - $this->phone_perso = $obj->phone_perso; - $this->phone_mobile = $obj->phone_mobile; + $this->phone_pro = trim($obj->phone); + $this->fax = trim($obj->fax); + $this->phone_perso = trim($obj->phone_perso); + $this->phone_mobile = trim($obj->phone_mobile); $this->code = $obj->code; $this->email = $obj->email; @@ -609,74 +634,76 @@ class Contact } } - /* - * \brief Efface le contact de la base et éventuellement de l'annuaire LDAP - * \param id id du contact a effacer - */ - function delete($id) - { - $sql = "SELECT c.name, c.firstname FROM ".MAIN_DB_PREFIX."socpeople as c"; - $sql .= " WHERE c.idp = ". $id; - $resql=$this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { - $obj = $this->db->fetch_object($resql); - - $this->old_name = $obj->name; - $this->old_firstname = $obj->firstname; - } - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; - $sql .= " WHERE idp=$id"; - - $result = $this->db->query($sql); - - if (!$result) + /* + * \brief Efface le contact de la base et éventuellement de l'annuaire LDAP + * \param id id du contact a effacer + */ + function delete($id) { - print $this->db->error() . '
' . $sql; - } - - if (defined('MAIN_MODULE_LDAP') && MAIN_MODULE_LDAP) - { - if (defined('LDAP_CONTACT_ACTIVE') && LDAP_CONTACT_ACTIVE == 1) - { - $ldap = New AuthLdap(); - - if ($ldap->connect()) - { - if ($ldap->bind()) - { - // delete from ldap directory - if (LDAP_SERVER_TYPE == 'activedirectory') - { - $userdn = $this->old_firstname." ".$this->old_name; //enlever utf8 pour etre compatible Windows - } - else - { - $userdn = utf8_encode($this->old_firstname." ".$this->old_name); - } - - $dn = "cn=".$userdn.",".LDAP_CONTACT_DN; - $r = @ldap_delete($ds, $dn); - } - else - { - echo "LDAP bind failed..."; - } - - $ldap->close(); - } - else - { - echo "Unable to connect to LDAP server"; - } - - return $result; - } - } + global $conf, $langs; + + $sql = "SELECT c.name, c.firstname FROM ".MAIN_DB_PREFIX."socpeople as c"; + $sql .= " WHERE c.idp = ". $id; + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->old_name = $obj->name; + $this->old_firstname = $obj->firstname; + } + } + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople"; + $sql .= " WHERE idp=$id"; + + $result = $this->db->query($sql); + + if (!$result) + { + print $this->db->error() . '
' . $sql; + } + + if ($conf->ldap->enabled) + { + if (defined('LDAP_CONTACT_ACTIVE') && LDAP_CONTACT_ACTIVE == 1) + { + $ldap = New AuthLdap(); + + if ($ldap->connect()) + { + if ($ldap->bind()) + { + // delete from ldap directory + if (LDAP_SERVER_TYPE == 'activedirectory') + { + $userdn = $this->old_firstname." ".$this->old_name; //enlever utf8 pour etre compatible Windows + } + else + { + $userdn = utf8_encode($this->old_firstname." ".$this->old_name); + } + + $dn = "cn=".$userdn.",".$conf->global->LDAP_CONTACT_DN; + $r = @ldap_delete($ldap->connection, $dn); + } + else + { + echo "LDAP bind failed..."; + } + + $ldap->close(); + } + else + { + echo "Unable to connect to LDAP server"; + } + + return $result; + } + } } diff --git a/htdocs/includes/modules/modLdap.class.php b/htdocs/includes/modules/modLdap.class.php index b352db969f7..0774a15b610 100644 --- a/htdocs/includes/modules/modLdap.class.php +++ b/htdocs/includes/modules/modLdap.class.php @@ -1,7 +1,7 @@ - * Copyright (C) 2004 Laurent Destailleur - * Copyright (C) 2005 Regis Houssin +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2005 Regis Houssin * * 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 @@ -39,43 +39,99 @@ include_once "DolibarrModules.class.php"; class modLdap extends DolibarrModules { - /** - * \brief Constructeur. Definit les noms, constantes et boites - * \param DB handler d'accès base - */ - function modLdap($DB) - { - $this->db = $DB ; - $this->id = 'ldap'; // Same value xxx than in file modXxx.class.php file - $this->numero = 200 ; + /** + * \brief Constructeur. Definit les noms, constantes et boites + * \param DB handler d'accès base + */ + function modLdap($DB) + { + $this->db = $DB ; + $this->id = 'ldap'; // Same value xxx than in file modXxx.class.php file + $this->numero = 200 ; + + $this->name = "Ldap"; + $this->family = "technic"; + $this->description = "Synchronisation Ldap"; + $this->version = 'experimental'; // 'experimental' or 'dolibarr' or version + $this->const_name = 'MAIN_MODULE_LDAP'; + $this->special = 1; + + // Dir + $this->dirs = array(); + + // Config pages + $this->config_page_url = "ldap.php"; + + // Dépendances + $this->depends = array(); + $this->requiredby = array(); + + // Constantes + $this->const = array(); + $r=0; + + $this->const[$r][0] = "LDAP_USER_DN"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "ou=users,dc=my-domain,dc=com"; + $r++; - $this->name = "Ldap"; - $this->family = "technic"; - $this->description = "Synchronisation Ldap"; - $this->version = 'experimental'; // 'experimental' or 'dolibarr' or version - $this->const_name = 'MAIN_MODULE_LDAP'; - $this->special = 1; + $this->const[$r][0] = "LDAP_GROUP_DN"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "ou=groups,dc=my-domain,dc=com"; + $r++; - // Dir - $this->dirs = array(); + $this->const[$r][0] = "LDAP_FILTER_CONNECTION"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "&(objectClass=user)(objectCategory=person)"; + $r++; - // Config pages - $this->config_page_url = "ldap.php"; + $this->const[$r][0] = "LDAP_FIELD_LOGIN"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "uid"; + $r++; - // Dépendances - $this->depends = array(); - $this->requiredby = array(); + $this->const[$r][0] = "LDAP_FIELD_LOGIN_SAMBA"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "samaccountname"; + $r++; - // Constantes - $this->const = array(); - - // Boites - $this->boxes = array(); + $this->const[$r][0] = "LDAP_FIELD_NAME"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "sn"; + $r++; - // Permissions - $this->rights = array(); - $this->rights_class = 'ldap'; - } + $this->const[$r][0] = "LDAP_FIELD_FIRSTNAME"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "givenname"; + $r++; + + $this->const[$r][0] = "LDAP_FIELD_MAIL"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "mail"; + $r++; + + $this->const[$r][0] = "LDAP_FIELD_PHONE"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "telephonenumber"; + $r++; + + $this->const[$r][0] = "LDAP_FIELD_FAX"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "facsimiletelephonenumber"; + $r++; + + $this->const[$r][0] = "LDAP_FIELD_MOBILE"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "mobile"; + $r++; + + // Boites + $this->boxes = array(); + + // Permissions + $this->rights = array(); + $this->rights_class = 'ldap'; + } /** * \brief Fonction appelé lors de l'activation du module. Insère en base les constantes, boites, permissions du module. diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 2be50a082b8..7b7ee85314b 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -538,27 +538,30 @@ LDAPConnectToDNFailed=Connection au DN (%s) LDAPSetupForVersion3=LDAP server configured for version 3 LDAPSetupForVersion2=LDAP server configured for version 2 LDAPFieldLoginUnix=Login (unix) -LDAPFieldLoginExample=Default attribute : uid +LDAPFieldLoginExample=Suggested value : uid LDAPFilterConnection=Search filter -LDAPFilterConnectionExample=Default filter : &(objectClass=user)(objectCategory=person) +LDAPFilterConnectionExample=Suggested value : &(objectClass=user)(objectCategory=person) LDAPAttributes=LDAP attributes LDAPFieldLoginSamba=Login (samba, activedirectory) -LDAPFieldLoginSambaExample=Default attribute : samaccountname (Samba and ActiveDirectory) +LDAPFieldLoginSambaExample=Suggested value : samaccountname (Samba and ActiveDirectory) LDAPFieldName=Name -LDAPFieldNameExample=Default attribute : sn +LDAPFieldNameExample=Suggested value : sn LDAPFieldFirstName=Firstname -LDAPFieldFirstNameExample=Default attribute : givenname +LDAPFieldFirstNameExample=Suggested value : givenname LDAPFieldMail=E-Mail address -LDAPFieldMailExample=Default attribute : mail +LDAPFieldMailExample=Suggested value : mail LDAPFieldPhone=Phone number -LDAPFieldPhoneExample=Default attribute : telephonenumber +LDAPFieldPhoneExample=Suggested value : telephonenumber LDAPFieldFax=Fax number -LDAPFieldFaxExample=Default attribute : facsimiletelephonenumber +LDAPFieldFaxExample=Suggested value : facsimiletelephonenumber LDAPFieldMobile=Cellular phone -LDAPFieldMobileExample=Default attribute : mobile +LDAPFieldMobileExample=Suggested value : mobile LDAPParametersAreStillHardCoded=LDAP parametres are still hardcoded (in contact class) LDAPSetupNotComplete=LDAP setup not complete (go on others tabs) LDAPNoUserOrPasswordProvidedAccessIsReadOnly=No administrator or password provided. LDAP access will be anonymous and in read only mode. +LDAPDescContact=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr contacts. +LDAPDescUsers=This page allows you to define LDAP attributes name in LDAP tree for each data found on Dolibarr users. +LDAPDescValues=Suggested values are designed for OpenLDAP with following loaded schemas: core.schema, cosine.schema, inetorgperson.schema). If you use thoose values and OpenLDAP, modify your LDAP config file slapd.conf to have all thoose schemas loaded. ##### Products ##### ProductSetup=Products module setup NumberOfProductShowInSelect=Max number of products in combos select lists (0=no limit) diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang index 312fe02892b..a4e5899e6da 100644 --- a/htdocs/langs/fr_FR/admin.lang +++ b/htdocs/langs/fr_FR/admin.lang @@ -510,14 +510,14 @@ LDAPServerUseTLS=Utiliser TLS LDAPServerUseTLSExample=Votre serveur utilise le TLS LDAPServerDn=DN du serveur LDAPAdminDn=DN de l'administrateur -LDAPAdminDnExample=DN complet (ex: cn=adminldap,dc=societe,dc=com) +LDAPAdminDnExample=DN complet (ex: cn=adminldap,dc=my-domain,dc=com) LDAPPassword=Mot de passe de l'administrateur LDAPUserDn=DN des utilisateurs -LDAPUserDnExample=DN complet (ex: ou=users,dc=societe,dc=com) +LDAPUserDnExample=DN complet (ex: ou=users,dc=my-domain,dc=com) LDAPGroupDn=DN des groupes -LDAPGroupDnExample=DN complet (ex: ou=groups,dc=societe,dc=com) +LDAPGroupDnExample=DN complet (ex: ou=groups,dc=my-domain,dc=com) LDAPServerExample=Adresse du serveur (ex: localhost, 192.168.0.2, ldaps://ldap.example.com/) -LDAPServerDnExample=DN complet (ex: dc=societe,dc=com) +LDAPServerDnExample=DN complet (ex: dc=my-domain,dc=com) LDAPPasswordExample=Mot de passe de l'administrateur LDAPDnSynchroActive=Synchronisation des utilisateurs et groupes LDAPDnSynchroActiveExample=Synchronisation de LDAP vers Dolibarr ou Dolibarr vers LDAP @@ -525,7 +525,7 @@ LDAPDnContactActive=Synchronisation des contacts LDAPDnContactActiveYes=Synchronisation activée LDAPDnContactActiveExample=Synchronisation activée/désactivée LDAPContactDn=DN des contacts Dolibarr -LDAPContactDnExample=DN complet (ex: ou=contacts,dc=societe,dc=com) +LDAPContactDnExample=DN complet (ex: ou=contacts,dc=my-domain,dc=com) LDAPTestConnect=Tester la connexion LDAP LDAPTCPConnectOK=Connexion TCP au serveur LDAP réussie (Serveur=%s, Port=%s) LDAPTCPConnectKO=Connexion TCP au serveur LDAP échouée (Serveur=%s, Port=%s) @@ -538,27 +538,30 @@ LDAPConnectToDNFailed=Connection au DN (%s) LDAPSetupForVersion3=Serveur LDAP configuré en version 3 LDAPSetupForVersion2=Serveur LDAP configuré en version 2 LDAPFieldLoginUnix=Login (unix) -LDAPFieldLoginExample=Attribut par défaut : uid +LDAPFieldLoginExample=Valeur recommandée : uid LDAPFilterConnection=Filtre de recherche -LDAPFilterConnectionExample=Filtre par défaut : &(objectClass=user)(objectCategory=person) +LDAPFilterConnectionExample=Valeur recommandée : &(objectClass=user)(objectCategory=person) LDAPAttributes=Attributs LDAP LDAPFieldLoginSamba=Login (samba, activedirectory) -LDAPFieldLoginSambaExample=Attribut par défaut : samaccountname (Samba et ActiveDirectory) +LDAPFieldLoginSambaExample=Valeur recommandée : samaccountname (Samba et ActiveDirectory) LDAPFieldName=Nom -LDAPFieldNameExample=Attribut par défaut : sn +LDAPFieldNameExample=Valeur recommandée : sn LDAPFieldFirstName=Prénom -LDAPFieldFirstNameExample=Attribut par défaut : givenname +LDAPFieldFirstNameExample=Valeur recommandée : givenname LDAPFieldMail=Adresse E-Mail -LDAPFieldMailExample=Attribut par défaut : mail +LDAPFieldMailExample=Valeur recommandée : mail LDAPFieldPhone=Numéro de téléphone -LDAPFieldPhoneExample=Attribut par défaut : telephonenumber +LDAPFieldPhoneExample=Valeur recommandée : telephonenumber LDAPFieldFax=Numéro de fax -LDAPFieldFaxExample=Attribut par défaut : facsimiletelephonenumber +LDAPFieldFaxExample=Valeur recommandée : facsimiletelephonenumber LDAPFieldMobile=Téléphone portable -LDAPFieldMobileExample=Attribut par défaut : mobile +LDAPFieldMobileExample=Valeur recommandée : mobile LDAPParametersAreStillHardCoded=Les parametres LDAP sont codés en dur (dans classe contact) LDAPSetupNotComplete=Configuration LDAP incomplète (à compléter sur les autres onglets) LDAPNoUserOrPasswordProvidedAccessIsReadOnly=Administrateur ou mot de passe non renseigné. Les accès LDAP seront donc anonymes et en lecture seule. +LDAPDescContact=Cette page permet de définir le nom des attributs de l'arbre LDAP pour chaque informations des contacts Dolibarr. +LDAPDescUsers=Cette page permet de définir le nom des attributs de l'arbre LDAP pour chaque informations des utilisateurs Dolibarr. +LDAPDescValues=Les valeurs recommandées sont adaptées à OpenLDAP avec les schemas suivant chargés: core.schema, cosine.schema, inetorgperson.schema). Si vous utiliser les valeurs suggérés et OpenLDAP, modifier votre fichier de configuration LDAP slapd.conf pour avoir tous ces schémas actifs. ##### Products ##### ProductSetup=Configuration du module Produits NumberOfProductShowInSelect=Nombre de produits max dans les listes déroulantes (0=aucune limite) diff --git a/htdocs/lib/authldap.lib.php b/htdocs/lib/authldap.lib.php index 9398164db0e..254cbd2f5d1 100644 --- a/htdocs/lib/authldap.lib.php +++ b/htdocs/lib/authldap.lib.php @@ -23,16 +23,15 @@ * $Source$ */ + /** \file htdocs/lib/authldap.lib.php - \brief Librairie contenant les fonctions pour accèder au serveur ldap. - \author Rodolphe Quiedeville. - \author Benoit Mortier. - \author Regis Houssin. - \author Laurent Destailleur. + \brief Librairie contenant les fonctions pour accèder au serveur LDAP + \author Rodolphe Quiedeville + \author Benoit Mortier + \author Regis Houssin + \author Laurent Destailleur \version $Revision$ - - Ensemble des fonctions permettant d'accèder à un serveur LDAP. */ class AuthLdap { @@ -423,6 +422,40 @@ class AuthLdap { } } + + /* + * \brief Add a LDAP entry + * \param dn DN entry key + * \param info Attributes array + * \return boolean <0 si KO, >0 si OK + */ + function add($dn, $info) + { + dolibarr_syslog("authldap::add Add LDAP entry dn=".$dn); + + //print_r($info); + $result=@ldap_add($this->connection, $dn, $info); + + if ($result) return 1; + return -1; + } + + /* + * \brief Delete a LDAP entry + * \param dn DN entry key + * \return boolean <0 si KO, >0 si OK + */ + function delete($dn) + { + dolibarr_syslog("authldap::delete Delete LDAP entry dn=".$dn); + + $result=@ldap_delete($this->connection, $dn); + + if ($result) return 1; + return -1; + } + + // 2.4 Attribute methods ----------------------------------------------------- /** * 2.4.1 : Returns an array containing a set of attribute values. diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 3926ade1ebc..f1d55d83ae8 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -172,9 +172,11 @@ if (! session_id() && ! isset($_SESSION["dol_user"]) && ! isset($_SESSION["dol_ 'basedn' => $conf->global->LDAP_SERVER_DN, 'binddn' => $conf->global->LDAP_ADMIN_DN, 'bindpw' => $conf->global->LDAP_ADMIN_PASS, - //'userattr' => $conf->global->LDAP_FIELD_LOGIN_SAMBA, - 'userattr' => 'samAccountName', - 'userfilter' => '(objectClass=user)', + + 'userattr' => $conf->global->LDAP_FIELD_LOGIN_SAMBA, + 'userfilter' => $conf->global->$conf->global->LDAP_FILTER_CONNECTION + //'userattr' => 'samAccountName', + //'userfilter' => '(objectClass=user)', ); $aDol = new DOLIAuth("LDAP", $params, "dol_loginfunction"); diff --git a/scripts/company/ldap-update-allcontact.php b/scripts/company/ldap-update-allcontact.php deleted file mode 100644 index 7cc452046c2..00000000000 --- a/scripts/company/ldap-update-allcontact.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * 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 - * (at your option) any later version. - * - * 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. - * - * $Id$ - * $Source$ - * - * Mets à jour tous les contacts dans LDAP à partir de la base sql - */ - -require_once("../htdocs/master.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); -require_once(DOL_DOCUMENT_ROOT."/user.class.php"); - -$error = 0; - -$user = new User($db); - -$sql = "SELECT idp"; -$sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; - -$resql = $db->query($sql); - -if ( $resql ) -{ - $num = $db->num_rows($resql); - $i = 0; - - while ($i < $num) - { - $row = $db->fetch_row($resql); - - print "Mise à jour $row[0]\n"; - - $contact = new Contact($db); - $contact->id = $row[0]; - $contact->update_ldap($user); - - $i++; - } -} - - -?> diff --git a/scripts/company/sync_contacts_dolibarr2ldap.php b/scripts/company/sync_contacts_dolibarr2ldap.php new file mode 100644 index 00000000000..a1ad74fc1fb --- /dev/null +++ b/scripts/company/sync_contacts_dolibarr2ldap.php @@ -0,0 +1,90 @@ + + * + * 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 + * (at your option) any later version. + * + * 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. + * + * $Id$ + * $Source$ + */ + +/** + \file scripts/company/ldap-update-allcontact.php + \ingroup ldap company + \brief Script de mise a jour des contacts dans LDAP depuis base Dolibarr +*/ + +// Test si mode batch +$sapi_type = php_sapi_name(); +$script_file=__FILE__; +if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1]; + +if (substr($sapi_type, 0, 3) == 'cgi') { + echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; + exit; +} + +if (! isset($argv[1]) || ! $argv[1]) { + print "Usage: $script_file now\n"; + exit; +} +$now=$argv[1]; + +// Recupere root dolibarr +$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]); + +require_once($path."../../htdocs/master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/user.class.php"); + +$user = new User($db); + +$sql = "SELECT idp as rowid"; +$sql .= " FROM ".MAIN_DB_PREFIX."socpeople"; + +$resql = $db->query($sql); +if ($resql) +{ + $num = $db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + print $langs->trans("UpdateContact")." rowid=".$obj->rowid; + + $contact = new Contact($db); + + $contact->id = $obj->rowid; + $result=$contact->update_ldap($user); + if ($result > 0) + { + print " - ".$langs->trans("OK"); + } + else + { + print " - ".$langs->trans("KO").' - '.$contact->error; + } + print "\n"; + + $i++; + } +} +else +{ + dolibarr_print_error($db); +} + +?>