Amlioration gestion erreur synchro LDAP

This commit is contained in:
Laurent Destailleur 2006-11-18 21:59:10 +00:00
parent 75a82a31ce
commit e69b80ac52
17 changed files with 728 additions and 534 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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());
}
}

View File

@ -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").'<br>';
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
@ -130,6 +141,43 @@ print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPContactDn").'</td><td>';
print '<input size="38" type="text" name="contactdn" value="'.$conf->global->LDAP_CONTACT_DN.'">';
print '</td><td>'.$langs->trans("LDAPContactDnExample").'</td></tr>';
// Name
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldName").'</td><td>';
print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td></tr>';
// Firstname
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td></tr>';
// Mail
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td></tr>';
// Phone
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td></tr>';
// Fax
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td></tr>';
// Mobile
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td></tr>';
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
print '</table>';
@ -138,6 +186,7 @@ print '</form>';
print '</div>';
print info_admin($langs->trans("LDAPDescValues"));
$db->close();

View File

@ -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").'<br>';
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
@ -151,122 +154,58 @@ print '</td><td>'.$langs->trans("LDAPGroupDnExample").'</td></tr>';
// Filtre de connexion
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
if ($conf->global->LDAP_FILTER_CONNECTION)
{
print '<input size="38" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
}
else
{
print '<input size="38" type="text" name="filterconnection" value="&(objectClass=user)(objectCategory=person)">';
}
print '<input size="38" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td></tr>';
// Login unix
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
if ($conf->global->LDAP_FIELD_LOGIN)
{
print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
}
else
{
print '<input size="25" type="text" name="fieldlogin" value="uid">';
}
print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td></tr>';
// Login samba
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
if ($conf->global->LDAP_FIELD_LOGIN_SAMBA)
{
print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
}
else
{
print '<input size="25" type="text" name="fieldloginsamba" value="samaccountname">';
}
print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td></tr>';
// Name
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldName").'</td><td>';
if ($conf->global->LDAP_FIELD_NAME)
{
print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
}
else
{
print '<input size="25" type="text" name="fieldname" value="sn">';
}
print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td></tr>';
// Firstname
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
if ($conf->global->LDAP_FIELD_FIRSTNAME)
{
print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
}
else
{
print '<input size="25" type="text" name="fieldfirstname" value="givenname">';
}
print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td></tr>';
// Mail
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
if ($conf->global->LDAP_FIELD_MAIL)
{
print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
}
else
{
print '<input size="25" type="text" name="fieldmail" value="mail">';
}
print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td></tr>';
// Phone
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
if ($conf->global->LDAP_FIELD_PHONE)
{
print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
}
else
{
print '<input size="25" type="text" name="fieldphone" value="telephonenumber">';
}
print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td></tr>';
// Fax
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
if ($conf->global->LDAP_FIELD_FAX)
{
print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
}
else
{
print '<input size="25" type="text" name="fieldfax" value="facsimiletelephonenumber">';
}
print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td></tr>';
// Mobile
$var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
if ($conf->global->LDAP_FIELD_MOBILE)
{
print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
}
else
{
print '<input size="25" type="text" name="fieldmobile" value="mobile">';
}
print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td></tr>';
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
print '</table>';
@ -274,6 +213,7 @@ print '</form>';
print '</div>';
print info_admin($langs->trans("LDAPDescValues"));
$db->close();

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
*
* 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() . '<br>' . $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() . '<br>' . $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;
}
}
}

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Regis Houssin <regis.houssin@cap-networks.com>
*
* 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.

View File

@ -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 <b>OpenLDAP</b> with following loaded schemas: <b>core.schema, cosine.schema, inetorgperson.schema</b>). If you use thoose values and OpenLDAP, modify your LDAP config file <b>slapd.conf</b> to have all thoose schemas loaded.
##### Products #####
ProductSetup=Products module setup
NumberOfProductShowInSelect=Max number of products in combos select lists (0=no limit)

View File

@ -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 à <b>OpenLDAP</b> avec les schemas suivant chargés: <b>core.schema, cosine.schema, inetorgperson.schema</b>). Si vous utiliser les valeurs suggérés et OpenLDAP, modifier votre fichier de configuration LDAP <b>slapd.conf</b> 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)

View File

@ -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.

View File

@ -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");

View File

@ -1,57 +0,0 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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++;
}
}
?>

View File

@ -0,0 +1,90 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* 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);
}
?>