ldap_users.php 22 KB

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