ldap_users.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  7. * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/ldap_users.php
  24. * \ingroup ldap
  25. * \brief Page d'administration/configuration du module Ldap
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
  33. $langs->load("admin");
  34. $langs->load("errors");
  35. if (!$user->admin)
  36. accessforbidden();
  37. $action = GETPOST('action','aZ09');
  38. /*
  39. * Actions
  40. */
  41. if ($action == 'setvalue' && $user->admin)
  42. {
  43. $error=0;
  44. $db->begin();
  45. if (! dolibarr_set_const($db, 'LDAP_USER_DN',GETPOST("user"),'chaine',0,'',$conf->entity)) $error++;
  46. if (! dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS',GETPOST("objectclass"),'chaine',0,'',$conf->entity)) $error++;
  47. if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',GETPOST("filterconnection"),'chaine',0,'',$conf->entity)) $error++;
  48. if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',GETPOST("fieldfullname"),'chaine',0,'',$conf->entity)) $error++;
  49. if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',GETPOST("fieldlogin"),'chaine',0,'',$conf->entity)) $error++;
  50. if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',GETPOST("fieldloginsamba"),'chaine',0,'',$conf->entity)) $error++;
  51. if (! dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD',GETPOST("fieldpassword"),'chaine',0,'',$conf->entity)) $error++;
  52. if (! dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD_CRYPTED',GETPOST("fieldpasswordcrypted"),'chaine',0,'',$conf->entity)) $error++;
  53. if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',GETPOST("fieldname"),'chaine',0,'',$conf->entity)) $error++;
  54. if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',GETPOST("fieldfirstname"),'chaine',0,'',$conf->entity)) $error++;
  55. if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',GETPOST("fieldmail"),'chaine',0,'',$conf->entity)) $error++;
  56. if (! dolibarr_set_const($db, 'LDAP_FIELD_PHONE',GETPOST("fieldphone"),'chaine',0,'',$conf->entity)) $error++;
  57. if (! dolibarr_set_const($db, 'LDAP_FIELD_MOBILE',GETPOST("fieldmobile"),'chaine',0,'',$conf->entity)) $error++;
  58. if (! dolibarr_set_const($db, 'LDAP_FIELD_SKYPE',GETPOST("fieldskype"),'chaine',0,'',$conf->entity)) $error++;
  59. if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',GETPOST("fieldfax"),'chaine',0,'',$conf->entity)) $error++;
  60. if (! dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION',GETPOST("fielddescription"),'chaine',0,'',$conf->entity)) $error++;
  61. if (! dolibarr_set_const($db, 'LDAP_FIELD_SID',GETPOST("fieldsid"),'chaine',0,'',$conf->entity)) $error++;
  62. if (! dolibarr_set_const($db, 'LDAP_FIELD_TITLE',GETPOST("fieldtitle"),'chaine',0,'',$conf->entity)) $error++;
  63. // This one must be after the others
  64. $valkey='';
  65. $key=GETPOST("key");
  66. if ($key) $valkey=$conf->global->$key;
  67. if (! dolibarr_set_const($db, 'LDAP_KEY_USERS',$valkey,'chaine',0,'',$conf->entity)) $error++;
  68. if (! $error)
  69. {
  70. $db->commit();
  71. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  72. }
  73. else
  74. {
  75. $db->rollback();
  76. dol_print_error($db);
  77. }
  78. }
  79. /*
  80. * Visu
  81. */
  82. $form=new Form($db);
  83. llxHeader('',$langs->trans("LDAPSetup"),'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP');
  84. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  85. print load_fiche_titre($langs->trans("LDAPSetup"),$linkback,'title_setup');
  86. $head = ldap_prepare_head();
  87. // Test si fonction LDAP actives
  88. if (! function_exists("ldap_connect"))
  89. {
  90. setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
  91. }
  92. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
  93. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  94. dol_fiche_head($head, 'users', $langs->trans("LDAPSetup"));
  95. print $langs->trans("LDAPDescUsers").'<br>';
  96. print '<br>';
  97. print '<table class="noborder" width="100%">';
  98. $var=true;
  99. print '<tr class="liste_titre">';
  100. print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
  101. print "</tr>\n";
  102. // DN Pour les utilisateurs
  103. print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>';
  104. print '<input size="48" type="text" name="user" value="'.$conf->global->LDAP_USER_DN.'">';
  105. print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
  106. print '<td>&nbsp;</td>';
  107. print '</tr>';
  108. // List of object class used to define attributes in structure
  109. print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>';
  110. print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_USER_OBJECT_CLASS.'">';
  111. print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>';
  112. print '<td>&nbsp;</td>';
  113. print '</tr>';
  114. // Filter, used to filter search
  115. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
  116. print '<input size="48" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
  117. print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
  118. print '<td></td>';
  119. print '</tr>';
  120. print '</table>';
  121. print '<br>';
  122. print '<table class="noborder" width="100%">';
  123. $var=true;
  124. print '<tr class="liste_titre">';
  125. print '<td width="25%">'.$langs->trans("LDAPDolibarrMapping").'</td>';
  126. print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
  127. print '<td align="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
  128. print "</tr>\n";
  129. // Common name
  130. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
  131. print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">';
  132. print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
  133. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FULLNAME)?' checked':'')."></td>";
  134. print '</tr>';
  135. // Name
  136. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
  137. print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
  138. print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
  139. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_NAME)?' checked':'')."></td>";
  140. print '</tr>';
  141. // Firstname
  142. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
  143. print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
  144. print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
  145. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FIRSTNAME)?' checked':'')."></td>";
  146. print '</tr>';
  147. // Login unix
  148. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
  149. print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
  150. print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
  151. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN)?' checked':'')."></td>";
  152. print '</tr>';
  153. // Login samba
  154. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
  155. print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
  156. print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
  157. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA)?' checked':'')."></td>";
  158. print '</tr>';
  159. // Password not crypted
  160. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>';
  161. print '<input size="25" type="text" name="fieldpassword" value="'.$conf->global->LDAP_FIELD_PASSWORD.'">';
  162. print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
  163. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_PASSWORD"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PASSWORD)?' checked':'')."></td>";
  164. print '</tr>';
  165. // Password crypted
  166. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>';
  167. print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.$conf->global->LDAP_FIELD_PASSWORD_CRYPTED.'">';
  168. print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
  169. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_PASSWORD_CRYPTED"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PASSWORD_CRYPTED)?' checked':'')."></td>";
  170. print '</tr>';
  171. // Mail
  172. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
  173. print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
  174. print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
  175. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MAIL)?' checked':'')."></td>";
  176. print '</tr>';
  177. // Phone
  178. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
  179. print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
  180. print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
  181. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PHONE)?' checked':'')."></td>";
  182. print '</tr>';
  183. // Mobile
  184. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
  185. print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
  186. print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
  187. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MOBILE)?' checked':'')."></td>";
  188. print '</tr>';
  189. // Skype
  190. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSkype").'</td><td>';
  191. print '<input size="25" type="text" name="fieldskype" value="'.$conf->global->LDAP_FIELD_SKYPE.'">';
  192. print '</td><td>'.$langs->trans("LDAPFieldSkypeExample").'</td>';
  193. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_SKYPE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_SKYPE)?' checked':'')."></td>";
  194. print '</tr>';
  195. // Fax
  196. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
  197. print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
  198. print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
  199. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FAX)?' checked':'')."></td>";
  200. print '</tr>';
  201. // Title
  202. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>';
  203. print '<input size="25" type="text" name="fieldtitle" value="'.$conf->global->LDAP_FIELD_TITLE.'">';
  204. print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>';
  205. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_TITLE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_TITLE)?' checked':'')."></td>";
  206. print '</tr>';
  207. // Note
  208. print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>';
  209. print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_FIELD_DESCRIPTION.'">';
  210. print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
  211. 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':'')."></td>";
  212. print '</tr>';
  213. // Sid
  214. print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>';
  215. print '<input size="25" type="text" name="fieldsid" value="'.$conf->global->LDAP_FIELD_SID.'">';
  216. print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>';
  217. print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_SID)?' checked':'')."></td>";
  218. print '</tr>';
  219. print '</table>';
  220. print info_admin($langs->trans("LDAPDescValues"));
  221. dol_fiche_end();
  222. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
  223. print '</form>';
  224. /*
  225. * Test de la connexion
  226. */
  227. if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
  228. {
  229. $butlabel=$langs->trans("LDAPTestSynchroUser");
  230. $testlabel='testuser';
  231. $key=$conf->global->LDAP_KEY_USERS;
  232. $dn=$conf->global->LDAP_USER_DN;
  233. $objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
  234. show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
  235. }
  236. elseif ($conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')
  237. {
  238. $butlabel=$langs->trans("LDAPTestSearch");
  239. $testlabel='testsearchuser';
  240. $key=$conf->global->LDAP_KEY_USERS;
  241. $dn=$conf->global->LDAP_USER_DN;
  242. $objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
  243. show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
  244. }
  245. if (function_exists("ldap_connect"))
  246. {
  247. if ($action == 'testuser')
  248. {
  249. // Creation objet
  250. $object=new User($db);
  251. $object->initAsSpecimen();
  252. // TODO Mutualize code following with other ldap_xxxx.php pages
  253. // Test synchro
  254. $ldap=new Ldap();
  255. $result=$ldap->connect_bind();
  256. if ($result > 0)
  257. {
  258. $info=$object->_load_ldap_info();
  259. $dn=$object->_load_ldap_dn($info);
  260. $result1=$ldap->delete($dn); // To be sure to delete existing records
  261. $result2=$ldap->add($dn,$info,$user); // Now the test
  262. $result3=$ldap->delete($dn); // Clean what we did
  263. if ($result2 > 0)
  264. {
  265. print img_picto('','info').' ';
  266. print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
  267. }
  268. else
  269. {
  270. print img_picto('','error').' ';
  271. print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
  272. print ': '.$ldap->error;
  273. print '</font><br>';
  274. print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
  275. }
  276. print "<br>\n";
  277. print "LDAP input file used for test:<br><br>\n";
  278. print nl2br($ldap->dump_content($dn,$info));
  279. print "\n<br>";
  280. }
  281. else
  282. {
  283. print img_picto('','error').' ';
  284. print '<font class="error">'.$langs->trans("LDAPSynchroKO");
  285. print ': '.$ldap->error;
  286. print '</font><br>';
  287. print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
  288. }
  289. }
  290. if ($action == 'testsearchuser')
  291. {
  292. // Creation objet
  293. $object=new User($db);
  294. $object->initAsSpecimen();
  295. // TODO Mutualize code following with other ldap_xxxx.php pages
  296. // Test synchro
  297. $ldap=new Ldap();
  298. $result=$ldap->connect_bind();
  299. if ($result > 0)
  300. {
  301. $required_fields = array(
  302. $conf->global->LDAP_KEY_USERS,
  303. $conf->global->LDAP_FIELD_FULLNAME,
  304. $conf->global->LDAP_FIELD_NAME,
  305. $conf->global->LDAP_FIELD_FIRSTNAME,
  306. $conf->global->LDAP_FIELD_LOGIN,
  307. $conf->global->LDAP_FIELD_LOGIN_SAMBA,
  308. $conf->global->LDAP_FIELD_PASSWORD,
  309. $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
  310. $conf->global->LDAP_FIELD_PHONE,
  311. $conf->global->LDAP_FIELD_FAX,
  312. $conf->global->LDAP_FIELD_SKYPE,
  313. $conf->global->LDAP_FIELD_MOBILE,
  314. $conf->global->LDAP_FIELD_MAIL,
  315. $conf->global->LDAP_FIELD_TITLE,
  316. $conf->global->LDAP_FIELD_DESCRIPTION,
  317. $conf->global->LDAP_FIELD_SID
  318. );
  319. // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
  320. $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
  321. // Get from LDAP database an array of results
  322. $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
  323. //$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, '', 1);
  324. if (is_array($ldapusers))
  325. {
  326. $liste=array();
  327. foreach ($ldapusers as $key => $ldapuser)
  328. {
  329. // Define the label string for this user
  330. $label='';
  331. foreach ($required_fields as $value)
  332. {
  333. if ($value)
  334. {
  335. $label.=$value."=".$ldapuser[$value]." ";
  336. }
  337. }
  338. $liste[$key] = $label;
  339. }
  340. }
  341. else
  342. {
  343. setEventMessages($ldap->error, $ldap->errors, 'errors');
  344. }
  345. print "<br>\n";
  346. print "LDAP search for user:<br>\n";
  347. print "search: *<br>\n";
  348. print "userDN: ".$conf->global->LDAP_USER_DN."<br>\n";
  349. print "useridentifier: ".$conf->global->LDAP_KEY_USERS."<br>\n";
  350. print "required_fields: ".implode(',',$required_fields)."<br>\n";
  351. print "=> ".count($liste)." records<br>\n";
  352. print "\n<br>";
  353. }
  354. else
  355. {
  356. print img_picto('','error').' ';
  357. print '<font class="error">'.$langs->trans("LDAPSynchroKO");
  358. print ': '.$ldap->error;
  359. print '</font><br>';
  360. print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
  361. }
  362. }
  363. }
  364. llxFooter();
  365. $db->close();