Qual: Meilleure gestion erreur sur fiches LDAP

This commit is contained in:
Laurent Destailleur 2007-05-01 22:13:34 +00:00
parent 80d4b0f11d
commit d480cb561c
4 changed files with 46 additions and 24 deletions

View File

@ -177,8 +177,10 @@ if ($result > 0)
$search = "(".$adh->_load_ldap_dn($info,2).")"; $search = "(".$adh->_load_ldap_dn($info,2).")";
$records=$ldap->search($dn,$search); $records=$ldap->search($dn,$search);
//print_r($records);
// Affichage arbre // Affichage arbre
if (sizeof($records)) if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
{ {
if (! is_array($records)) if (! is_array($records))
{ {

View File

@ -159,17 +159,26 @@ if ($result > 0)
$info=$contact->_load_ldap_info(); $info=$contact->_load_ldap_info();
$dn=$contact->_load_ldap_dn($info,1); $dn=$contact->_load_ldap_dn($info,1);
$search = "(".$contact->_load_ldap_dn($info,2).")"; $search = "(".$contact->_load_ldap_dn($info,2).")";
$result=$ldap->search($dn,$search); $records=$ldap->search($dn,$search);
//print_r($records);
// Affichage arbre // Affichage arbre
if (sizeof($result)) if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
{ {
$html=new Form($db); if (! is_array($records))
$html->show_ldap_content($result,0,0,true); {
print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
}
else
{
$html=new Form($db);
$result=$html->show_ldap_content($records,0,0,true);
}
} }
else else
{ {
print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>'; print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
} }
$ldap->unbind(); $ldap->unbind();

View File

@ -762,17 +762,17 @@ class Ldap
/** /**
* \brief Returns an array containing a details of elements * \brief Returns an array containing a details of elements
* \param $search * \param $search Valeur champ clé recherché, sinon '*' pour tous.
* \param $userDn * \param $userDn DN (Ex: ou=adherents,ou=people,dc=parinux,dc=org)
* \param $useridentifier * \param $useridentifier Nom du champ clé (Ex: uid)
* \param $attributeArray Variables required * \param $attributeArray Array of fields required (Ex: sn,userPassword)
* \param $activefilter 1=utilise le champ this->filter comme filtre * \param $activefilter 1=utilise le champ this->filter comme filtre
* * \return array Array of [id_record][ldap_field]=value
* \remarks ldapsearch -LLLx -hlocalhost -Dcn=admin,dc=parinux,dc=org -w password -b "ou=adherents,ou=people,dc=parinux,dc=org" userPassword * \remarks ldapsearch -LLLx -hlocalhost -Dcn=admin,dc=parinux,dc=org -w password -b "ou=adherents,ou=people,dc=parinux,dc=org" userPassword
*/ */
function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0) function getRecords($search, $userDn, $useridentifier, $attributeArray, $activefilter=0)
{ {
$userslist=array(); $fulllist=array();
dolibarr_syslog("Ldap::getRecords search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".join(',',$attributeArray).")"); dolibarr_syslog("Ldap::getRecords search=".$search." userDn=".$userDn." useridentifier=".$useridentifier." attributeArray=array(".join(',',$attributeArray).")");
@ -822,7 +822,7 @@ class Ldap
if ($recordid) if ($recordid)
{ {
//print "Found record with key $useridentifier=".$recordid."<br>\n"; //print "Found record with key $useridentifier=".$recordid."<br>\n";
$userslist[$recordid][$useridentifier]=$recordid; $fulllist[$recordid][$useridentifier]=$recordid;
// Add to the array for each attribute in my list // Add to the array for each attribute in my list
for ($j = 0; $j < count($attributeArray); $j++) for ($j = 0; $j < count($attributeArray); $j++)
@ -834,18 +834,18 @@ class Ldap
if ($this->serverType == "activedirectory" && $keyattributelower == "objectsid") if ($this->serverType == "activedirectory" && $keyattributelower == "objectsid")
{ {
$objectsid = $this->getObjectSid($recordid); $objectsid = $this->getObjectSid($recordid);
$userslist[$recordid][$attributeArray[$j]] = $objectsid; $fulllist[$recordid][$attributeArray[$j]] = $objectsid;
} }
else else
{ {
$userslist[$recordid][$attributeArray[$j]] = $this->ldap_utf8_decode($info[$i][$keyattributelower][0]); $fulllist[$recordid][$attributeArray[$j]] = $this->ldap_utf8_decode($info[$i][$keyattributelower][0]);
} }
} }
} }
} }
asort($userslist); asort($fulllist);
return $userslist; return $fulllist;
} }
/** /**
@ -922,7 +922,10 @@ class Ldap
* \remarks this->connection doit etre défini donc la methode bind ou bindauth doit avoir deja été appelée * \remarks this->connection doit etre défini donc la methode bind ou bindauth doit avoir deja été appelée
* \param checkDn DN de recherche (Ex: ou=users,cn=my-domain,cn=com) * \param checkDn DN de recherche (Ex: ou=users,cn=my-domain,cn=com)
* \param filter Filtre de recherche (ex: (sn=nom_personne) ) * \param filter Filtre de recherche (ex: (sn=nom_personne) )
* \return array Tableau des reponses * \return array Tableau des reponses (clé en minuscule-valeur)
* \remarks Ne pas utiliser pour recherche d'une liste donnée de propriétés
* car conflit majuscule-minuscule. A n'utiliser que pour les pages
* 'Fiche LDAP' qui affiche champ lisibles par defaut.
*/ */
function search($checkDn, $filter) function search($checkDn, $filter)
{ {

View File

@ -123,19 +123,27 @@ if ($result > 0)
$info=$fgroup->_load_ldap_info(); $info=$fgroup->_load_ldap_info();
$dn=$fgroup->_load_ldap_dn($info,1); $dn=$fgroup->_load_ldap_dn($info,1);
$search = "(".$fgroup->_load_ldap_dn($info,2).")"; $search = "(".$fgroup->_load_ldap_dn($info,2).")";
$result=$ldap->search($dn,$search); $records=$ldap->search($dn,$search);
//print_r($records);
// Affichage arbre // Affichage arbre
if (sizeof($result)) if (sizeof($records) && (! isset($records['count']) || $records['count'] > 0))
{ {
$html=new Form($db); if (! is_array($records))
$html->show_ldap_content($result,0,0,true); {
print '<tr '.$bc[false].'><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
}
else
{
$html=new Form($db);
$result=$html->show_ldap_content($records,0,0,true);
}
} }
else else
{ {
print '<tr><td colspan="2">'.$langs->trans("LDAPRecordNotFound").'</td></tr>'; print '<tr '.$bc[false].'><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
} }
$ldap->unbind(); $ldap->unbind();
$ldap->close(); $ldap->close();
} }