ldap_users.php 22 KB

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