ldap_users.php 22 KB

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