forked from Wavyzz/dolibarr
New: Add test for synchro ldap 2 dolibarr
This commit is contained in:
@@ -245,6 +245,7 @@ print '</form>';
|
|||||||
|
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
|
print '<br>';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ print '</tr>';
|
|||||||
|
|
||||||
// Description
|
// Description
|
||||||
$var=!$var;
|
$var=!$var;
|
||||||
print '<tr '.$bc[$var].'><td>'.$langs->trans("LDAPFieldDescription").'</td><td>';
|
print '<tr '.$bc[$var].'><td>'.$langs->trans("Note").'</td><td>';
|
||||||
print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_FIELD_DESCRIPTION.'">';
|
print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_FIELD_DESCRIPTION.'">';
|
||||||
print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
|
print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
|
||||||
print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_DESCRIPTION"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_DESCRIPTION)?' checked="checked"':'')."></td>";
|
print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_DESCRIPTION"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_DESCRIPTION)?' checked="checked"':'')."></td>";
|
||||||
@@ -287,10 +287,19 @@ if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
|
|||||||
|
|
||||||
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
|
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
|
||||||
}
|
}
|
||||||
|
elseif ($conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')
|
||||||
|
{
|
||||||
|
$butlabel=$langs->trans("LDAPTestSearch");
|
||||||
|
$testlabel='testsearchuser';
|
||||||
|
$key=$conf->global->LDAP_KEY_USERS;
|
||||||
|
$dn=$conf->global->LDAP_USER_DN;
|
||||||
|
$objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
|
||||||
|
show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
|
||||||
|
}
|
||||||
|
|
||||||
if (function_exists("ldap_connect"))
|
if (function_exists("ldap_connect"))
|
||||||
{
|
{
|
||||||
if ($_GET["action"] == 'testuser')
|
if ($action == 'testuser')
|
||||||
{
|
{
|
||||||
// Creation objet
|
// Creation objet
|
||||||
$object=new User($db);
|
$object=new User($db);
|
||||||
@@ -339,6 +348,84 @@ if (function_exists("ldap_connect"))
|
|||||||
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
|
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($action == 'testsearchuser')
|
||||||
|
{
|
||||||
|
// Creation objet
|
||||||
|
$object=new User($db);
|
||||||
|
$object->initAsSpecimen();
|
||||||
|
|
||||||
|
// TODO Mutualize code following with other ldap_xxxx.php pages
|
||||||
|
|
||||||
|
// Test synchro
|
||||||
|
$ldap=new Ldap();
|
||||||
|
$result=$ldap->connect_bind();
|
||||||
|
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$required_fields = array(
|
||||||
|
$conf->global->LDAP_KEY_USERS,
|
||||||
|
$conf->global->LDAP_FIELD_FULLNAME,
|
||||||
|
$conf->global->LDAP_FIELD_NAME,
|
||||||
|
$conf->global->LDAP_FIELD_FIRSTNAME,
|
||||||
|
$conf->global->LDAP_FIELD_LOGIN,
|
||||||
|
$conf->global->LDAP_FIELD_LOGIN_SAMBA,
|
||||||
|
$conf->global->LDAP_FIELD_PASSWORD,
|
||||||
|
$conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
|
||||||
|
$conf->global->LDAP_FIELD_PHONE,
|
||||||
|
$conf->global->LDAP_FIELD_FAX,
|
||||||
|
$conf->global->LDAP_FIELD_MOBILE,
|
||||||
|
$conf->global->LDAP_FIELD_MAIL,
|
||||||
|
$conf->global->LDAP_FIELD_SID);
|
||||||
|
|
||||||
|
// Remove from required_fields all entries not configured in LDAP (empty) and duplicated
|
||||||
|
$required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
|
||||||
|
|
||||||
|
// Get from LDAP database an array of results
|
||||||
|
$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
|
||||||
|
//$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, '', 1);
|
||||||
|
|
||||||
|
if (is_array($ldapusers))
|
||||||
|
{
|
||||||
|
$liste=array();
|
||||||
|
foreach ($ldapusers as $key => $ldapuser)
|
||||||
|
{
|
||||||
|
// Define the label string for this user
|
||||||
|
$label='';
|
||||||
|
foreach ($required_fields as $value)
|
||||||
|
{
|
||||||
|
if ($value)
|
||||||
|
{
|
||||||
|
$label.=$value."=".$ldapuser[$value]." ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$liste[$key] = $label;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$ldap->error.'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
print "<br>\n";
|
||||||
|
print "LDAP search for user:<br>\n";
|
||||||
|
print "search: *<br>\n";
|
||||||
|
print "userDN: ".$conf->global->LDAP_USER_DN."<br>\n";
|
||||||
|
print "useridentifier: ".$conf->global->LDAP_KEY_USERS."<br>\n";
|
||||||
|
print "required_fields: ".join(',',$required_fields)."<br>\n";
|
||||||
|
print "=> ".count($liste)." records<br>\n";
|
||||||
|
print "\n<br>";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print img_picto('','error').' ';
|
||||||
|
print '<font class="error">'.$langs->trans("LDAPSynchroKO");
|
||||||
|
print ': '.$ldap->error;
|
||||||
|
print '</font><br>';
|
||||||
|
print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_htmloutput_mesg($mesg);
|
dol_htmloutput_mesg($mesg);
|
||||||
|
|||||||
Reference in New Issue
Block a user