ldap_users.php 22 KB

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