diff --git a/htdocs/admin/ldap.php b/htdocs/admin/ldap.php index 6cc42777343..7cb300b0384 100644 --- a/htdocs/admin/ldap.php +++ b/htdocs/admin/ldap.php @@ -245,6 +245,7 @@ print ''; print ''; +print '
'; /* diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index 909364fb00e..b67fd7ae930 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -5,7 +5,7 @@ * Copyright (C) 2005 Regis Houssin * Copyright (C) 2006-2011 Laurent Destailleur * Copyright (C) 2011 Juanjo Menent - * + * * 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 @@ -49,7 +49,7 @@ if ($action == 'setvalue' && $user->admin) { $error=0; $db->begin(); - + if (! dolibarr_set_const($db, 'LDAP_USER_DN',GETPOST("user"),'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS',GETPOST("objectclass"),'chaine',0,'',$conf->entity)) $error++; if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',GETPOST("filterconnection"),'chaine',0,'',$conf->entity)) $error++; @@ -249,7 +249,7 @@ print ''; // Description $var=!$var; -print ''.$langs->trans("LDAPFieldDescription").''; +print ''.$langs->trans("Note").''; print ''; print ''.$langs->trans("LDAPFieldDescriptionExample").''; print 'global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_DESCRIPTION)?' checked="checked"':'').">"; @@ -287,10 +287,19 @@ if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') 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 ($_GET["action"] == 'testuser') + if ($action == 'testuser') { // Creation objet $object=new User($db); @@ -339,6 +348,84 @@ if (function_exists("ldap_connect")) print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'
'; } } + + 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='
'.$ldap->error.'
'; + } + + print "
\n"; + print "LDAP search for user:
\n"; + print "search: *
\n"; + print "userDN: ".$conf->global->LDAP_USER_DN."
\n"; + print "useridentifier: ".$conf->global->LDAP_KEY_USERS."
\n"; + print "required_fields: ".join(',',$required_fields)."
\n"; + print "=> ".count($liste)." records
\n"; + print "\n
"; + } + else + { + print img_picto('','error').' '; + print ''.$langs->trans("LDAPSynchroKO"); + print ': '.$ldap->error; + print '
'; + print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'
'; + } + } } dol_htmloutput_mesg($mesg);