dolibarr 24.0.0-beta
ldap_users.php
Go to the documentation of this file.
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
36require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
39
48// Load translation files required by the page
49$langs->loadLangs(array('admin', 'errors'));
50
51if (!$user->admin) {
53}
54
55$action = GETPOST('action', 'aZ09');
56
57/*
58 * Actions
59 */
60
61if ($action == 'setvalue' /* && $user->admin */) {
62 $error = 0;
63 $db->begin();
64
65 if (!dolibarr_set_const($db, 'LDAP_USER_DN', GETPOST("user"), 'chaine', 0, '', $conf->entity)) {
66 $error++;
67 }
68 if (!dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS', GETPOST("objectclass"), 'chaine', 0, '', $conf->entity)) {
69 $error++;
70 }
71 if (!dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION', GETPOST("filterconnection"), 'chaine', 0, '', $conf->entity)) {
72 $error++;
73 }
74 if (!dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME', GETPOST("fieldfullname"), 'chaine', 0, '', $conf->entity)) {
75 $error++;
76 }
77 if (!dolibarr_set_const($db, 'LDAP_FIELD_LOGIN', GETPOST("fieldlogin"), 'chaine', 0, '', $conf->entity)) {
78 $error++;
79 }
80 if (!dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA', GETPOST("fieldloginsamba"), 'chaine', 0, '', $conf->entity)) {
81 $error++;
82 }
83 if (!dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD', GETPOST("fieldpassword"), 'chaine', 0, '', $conf->entity)) {
84 $error++;
85 }
86 if (!dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD_CRYPTED', GETPOST("fieldpasswordcrypted"), 'chaine', 0, '', $conf->entity)) {
87 $error++;
88 }
89 if (!dolibarr_set_const($db, 'LDAP_FIELD_NAME', GETPOST("fieldname"), 'chaine', 0, '', $conf->entity)) {
90 $error++;
91 }
92 if (!dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME', GETPOST("fieldfirstname"), 'chaine', 0, '', $conf->entity)) {
93 $error++;
94 }
95 if (!dolibarr_set_const($db, 'LDAP_FIELD_MAIL', GETPOST("fieldmail"), 'chaine', 0, '', $conf->entity)) {
96 $error++;
97 }
98 if (!dolibarr_set_const($db, 'LDAP_FIELD_PHONE', GETPOST("fieldphone"), 'chaine', 0, '', $conf->entity)) {
99 $error++;
100 }
101 if (!dolibarr_set_const($db, 'LDAP_FIELD_MOBILE', GETPOST("fieldmobile"), 'chaine', 0, '', $conf->entity)) {
102 $error++;
103 }
104 if (!dolibarr_set_const($db, 'LDAP_FIELD_FAX', GETPOST("fieldfax"), 'chaine', 0, '', $conf->entity)) {
105 $error++;
106 }
107 if (!dolibarr_set_const($db, 'LDAP_FIELD_COMPANY', GETPOST("fieldcompany"), 'chaine', 0, '', $conf->entity)) {
108 $error++;
109 }
110 if (!dolibarr_set_const($db, 'LDAP_FIELD_ADDRESS', GETPOST("fieldaddress"), 'chaine', 0, '', $conf->entity)) {
111 $error++;
112 }
113 if (!dolibarr_set_const($db, 'LDAP_FIELD_ZIP', GETPOST("fieldzip"), 'chaine', 0, '', $conf->entity)) {
114 $error++;
115 }
116 if (!dolibarr_set_const($db, 'LDAP_FIELD_TOWN', GETPOST("fieldtown"), 'chaine', 0, '', $conf->entity)) {
117 $error++;
118 }
119 if (!dolibarr_set_const($db, 'LDAP_FIELD_COUNTRY', GETPOST("fieldcountry"), 'chaine', 0, '', $conf->entity)) {
120 $error++;
121 }
122 if (!dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION', GETPOST("fielddescription"), 'chaine', 0, '', $conf->entity)) {
123 $error++;
124 }
125 if (!dolibarr_set_const($db, 'LDAP_FIELD_SID', GETPOST("fieldsid"), 'chaine', 0, '', $conf->entity)) {
126 $error++;
127 }
128 if (!dolibarr_set_const($db, 'LDAP_FIELD_TITLE', GETPOST("fieldtitle"), 'chaine', 0, '', $conf->entity)) {
129 $error++;
130 }
131 if (!dolibarr_set_const($db, 'LDAP_FIELD_GROUPID', GETPOST("fieldgroupid"), 'chaine', 0, '', $conf->entity)) {
132 $error++;
133 }
134 if (!dolibarr_set_const($db, 'LDAP_FIELD_USERID', GETPOST("fielduserid"), 'chaine', 0, '', $conf->entity)) {
135 $error++;
136 }
137 if (!dolibarr_set_const($db, 'LDAP_FIELD_HOMEDIRECTORY', GETPOST("fieldhomedirectory"), 'chaine', 0, '', $conf->entity)) {
138 $error++;
139 }
140 if (!dolibarr_set_const($db, 'LDAP_FIELD_HOMEDIRECTORYPREFIX', GETPOST("fieldhomedirectoryprefix"), 'chaine', 0, '', $conf->entity)) {
141 $error++;
142 }
143
144 // This one must be after the others
145 $valkey = '';
146 $key = GETPOST("key");
147 if ($key) {
148 $valkey = getDolGlobalString($key);
149 }
150 if (!dolibarr_set_const($db, 'LDAP_KEY_USERS', $valkey, 'chaine', 0, '', $conf->entity)) {
151 $error++;
152 }
153
154 if (!$error) {
155 $db->commit();
156 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
157 } else {
158 $db->rollback();
160 }
161}
162
163
164
165/*
166 * Visu
167 */
168
169$form = new Form($db);
170
171llxHeader('', $langs->trans("LDAPSetup"), 'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP', '', 0, 0, '', '', '', 'mod-admin page-ldap_users');
172
173$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
174
175print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup');
176
177$head = ldap_prepare_head();
178
179// Test if the LDAP functionality is available
180if (!function_exists("ldap_connect")) {
181 setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
182}
183
184
185print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue&token='.newToken().'">';
186print '<input type="hidden" name="token" value="'.newToken().'">';
187
188
189print dol_get_fiche_head($head, 'users', '', -1);
190
191print '<span class="opacitymedium">'.$langs->trans("LDAPDescUsers").'</span><br>';
192print '<br>';
193
194
195print '<table class="noborder centpercent">';
196
197print '<tr class="liste_titre">';
198print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
199print "</tr>\n";
200
201// DN (Domain Name) for the users
202print '<!-- LDAP_USER_DN -->';
203print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>';
204print '<input size="48" type="text" name="user" value="'.getDolGlobalString('LDAP_USER_DN').'">';
205print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
206print '<td>&nbsp;</td>';
207print '</tr>';
208
209// List of object class used to define attributes in structure
210print '<!-- LDAP_USER_OBJECT_CLASS -->';
211print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>';
212print '<input size="48" type="text" name="objectclass" value="'.getDolGlobalString('LDAP_USER_OBJECT_CLASS').'">';
213print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>';
214print '<td>&nbsp;</td>';
215print '</tr>';
216
217// Filter, used to filter search
218print '<!-- LDAP_FILTER_CONNECTION -->';
219print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
220print '<input size="48" type="text" name="filterconnection" value="'.getDolGlobalString('LDAP_FILTER_CONNECTION').'">';
221print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
222print '<td></td>';
223print '</tr>';
224
225print '</table>';
226print '<br>';
227print '<table class="noborder centpercent">';
228
229print '<tr class="liste_titre">';
230print '<td>'.$langs->trans("LDAPDolibarrMapping").'</td>';
231print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
232print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
233print "</tr>\n";
234
235// Common name
236print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
237print '<input size="25" type="text" name="fieldfullname" value="'.getDolGlobalString('LDAP_FIELD_FULLNAME').'">';
238print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
239print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FULLNAME') ? ' checked' : '')."></td>";
240print '</tr>';
241
242// Name
243print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
244print '<input size="25" type="text" name="fieldname" value="'.getDolGlobalString('LDAP_FIELD_NAME').'">';
245print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
246print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_NAME') ? ' checked' : '')."></td>";
247print '</tr>';
248
249// Firstname
250print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
251print '<input size="25" type="text" name="fieldfirstname" value="'.getDolGlobalString('LDAP_FIELD_FIRSTNAME').'">';
252print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
253print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FIRSTNAME') ? ' checked' : '')."></td>";
254print '</tr>';
255
256// Login unix
257print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
258print '<input size="25" type="text" name="fieldlogin" value="'.getDolGlobalString('LDAP_FIELD_LOGIN').'">';
259print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
260print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_LOGIN') ? ' checked' : '')."></td>";
261print '</tr>';
262
263// Login samba
264print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
265print '<input size="25" type="text" name="fieldloginsamba" value="'.getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA').'">';
266print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
267print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA') ? ' checked' : '')."></td>";
268print '</tr>';
269
270// Password not encrypted
271print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>';
272print '<input size="25" type="text" name="fieldpassword" value="'.getDolGlobalString('LDAP_FIELD_PASSWORD').'">';
273print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
274print '<td class="right">&nbsp;</td>';
275print '</tr>';
276
277// Password encrypted
278print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>';
279print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED').'">';
280print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
281print '<td class="right">&nbsp;</td>';
282print '</tr>';
283
284// Mail
285print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
286print '<input size="25" type="text" name="fieldmail" value="'.getDolGlobalString('LDAP_FIELD_MAIL').'">';
287print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
288print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_MAIL') ? ' checked' : '')."></td>";
289print '</tr>';
290
291// Phone
292print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
293print '<input size="25" type="text" name="fieldphone" value="'.getDolGlobalString('LDAP_FIELD_PHONE').'">';
294print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
295print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_PHONE') ? ' checked' : '')."></td>";
296print '</tr>';
297
298// Mobile
299print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
300print '<input size="25" type="text" name="fieldmobile" value="'.getDolGlobalString('LDAP_FIELD_MOBILE').'">';
301print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
302print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_MOBILE') ? ' checked' : '')."></td>";
303print '</tr>';
304
305// Fax
306print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
307print '<input size="25" type="text" name="fieldfax" value="'.getDolGlobalString('LDAP_FIELD_FAX').'">';
308print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
309print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FAX') ? ' checked' : '')."></td>";
310print '</tr>';
311
312// Company
313print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCompany").'</td><td>';
314print '<input size="25" type="text" name="fieldcompany" value="'.getDolGlobalString('LDAP_FIELD_COMPANY').'">';
315print '</td><td>'.$langs->trans("LDAPFieldCompanyExample").'</td>';
316print '<td class="right">&nbsp;</td>';
317print '</tr>';
318
319// Address
320print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldAddress").'</td><td>';
321print '<input size="25" type="text" name="fieldaddress" value="'.getDolGlobalString('LDAP_FIELD_ADDRESS').'">';
322print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>';
323print '<td class="right">&nbsp;</td>';
324print '</tr>';
325
326// ZIP
327print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldZip").'</td><td>';
328print '<input size="25" type="text" name="fieldzip" value="'.getDolGlobalString('LDAP_FIELD_ZIP').'">';
329print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>';
330print '<td class="right">&nbsp;</td>';
331print '</tr>';
332
333// TOWN
334print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTown").'</td><td>';
335print '<input size="25" type="text" name="fieldtown" value="'.getDolGlobalString('LDAP_FIELD_TOWN').'">';
336print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>';
337print '<td class="right">&nbsp;</td>';
338print '</tr>';
339
340// COUNTRY
341print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCountry").'</td><td>';
342print '<input size="25" type="text" name="fieldcountry" value="'.getDolGlobalString('LDAP_FIELD_COUNTRY').'">';
343print '</td><td>&nbsp;</td>';
344print '<td class="right">&nbsp;</td>';
345print '</tr>';
346
347// Title
348print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>';
349print '<input size="25" type="text" name="fieldtitle" value="'.getDolGlobalString('LDAP_FIELD_TITLE').'">';
350print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>';
351print '<td class="right">&nbsp;</td>';
352print '</tr>';
353
354// Note
355print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>';
356print '<input size="25" type="text" name="fielddescription" value="'.getDolGlobalString('LDAP_FIELD_DESCRIPTION').'">';
357print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
358print '<td class="right">&nbsp;</td>';
359print '</tr>';
360
361// Sid
362print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>';
363print '<input size="25" type="text" name="fieldsid" value="'.getDolGlobalString('LDAP_FIELD_SID').'">';
364print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>';
365print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_SID') ? ' checked' : '')."></td>";
366print '</tr>';
367
368// Group id
369print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupid").'</td><td>';
370print '<input size="25" type="text" name="fieldgroupid" value="'.getDolGlobalString('LDAP_FIELD_GROUPID').'">';
371print '</td><td>'.$langs->trans("LDAPFieldGroupidExample").'</td>';
372print '<td class="right">&nbsp;</td>';
373print '</tr>';
374
375// Userid
376print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldUserid").'</td><td>';
377print '<input size="25" type="text" name="fielduserid" value="'.getDolGlobalString('LDAP_FIELD_USERID').'">';
378print '</td><td>'.$langs->trans("LDAPFieldUseridExample").'</td>';
379print '<td class="right">&nbsp;</td>';
380print '</tr>';
381
382// Home Directory
383print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectory").'</td><td>';
384print '<input size="25" type="text" name="fieldhomedirectory" value="'.getDolGlobalString('LDAP_FIELD_HOMEDIRECTORY').'">';
385print '</td><td>'.$langs->trans("LDAPFieldHomedirectoryExample").'</td>';
386print '<td class="right">&nbsp;</td>';
387print '</tr>';
388
389// Home Directory Prefix
390print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectoryprefix").'</td><td>';
391print '<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.getDolGlobalString('LDAP_FIELD_HOMEDIRECTORYPREFIX').'">';
392print '</td><td></td>';
393print '<td class="right">&nbsp;</td>';
394print '</tr>';
395
396print '</table>';
397
398print info_admin($langs->trans("LDAPDescValues"));
399
400print dol_get_fiche_end();
401
402print $form->buttonsSaveCancel("Modify", '');
403
404print '</form>';
405
406
407/*
408 * Test de la connection
409 */
410if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
411 $butlabel = $langs->trans("LDAPTestSynchroUser");
412 $testlabel = 'testuser';
413 $key = getDolGlobalString('LDAP_KEY_USERS');
414 $dn = getDolGlobalString('LDAP_USER_DN');
415 $objectclass = getDolGlobalString('LDAP_USER_OBJECT_CLASS');
416
417 show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
418} elseif (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') == Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
419 $butlabel = $langs->trans("LDAPTestSearch");
420 $testlabel = 'testsearchuser';
421 $key = getDolGlobalString('LDAP_KEY_USERS');
422 $dn = getDolGlobalString('LDAP_USER_DN');
423 $objectclass = getDolGlobalString('LDAP_USER_OBJECT_CLASS');
424 show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
425}
426
427if (function_exists("ldap_connect")) {
428 if ($action == 'testuser') {
429 // Create object
430 $object = new User($db);
431 $object->initAsSpecimen();
432
433 // TODO Mutualize code following with other ldap_xxxx.php pages
434
435 // Test synchro
436 $ldap = new Ldap();
437 $result = $ldap->connectBind();
438
439 if ($result > 0) {
440 $info = $object->_load_ldap_info();
441 $dn = $object->_load_ldap_dn($info);
442
443 $result1 = $ldap->delete($dn); // To be sure to delete existing records
444 $result2 = $ldap->add($dn, $info, $user); // Now the test
445 $result3 = $ldap->delete($dn); // Clean what we did
446
447 if ($result2 > 0) {
448 print img_picto('', 'info').' ';
449 print '<span class="ok">'.$langs->trans("LDAPSynchroOK").'</span><br>';
450 } else {
451 print img_picto('', 'error').' ';
452 print '<span class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
453 print ': '.$ldap->error;
454 print '</span><br>';
455 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
456 }
457
458 print "<br>\n";
459 print "LDAP input file used for test:<br><br>\n";
460 print nl2br($ldap->dumpContent($dn, $info));
461 print "\n<br>";
462 } else {
463 print img_picto('', 'error').' ';
464 print '<span class="error">'.$langs->trans("LDAPSynchroKO");
465 print ': '.$ldap->error;
466 print '</span><br>';
467 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
468 }
469 }
470
471 if ($action == 'testsearchuser') {
472 // Create object
473 $object = new User($db);
474 $object->initAsSpecimen();
475
476 // TODO Mutualize code following with other ldap_xxxx.php pages
477
478 // Test synchro
479 $ldap = new Ldap();
480 $result = $ldap->connectBind();
481
482 if ($result > 0) {
483 $required_fields = array(
484 getDolGlobalString('LDAP_KEY_USERS'),
485 getDolGlobalString('LDAP_FIELD_FULLNAME'),
486 getDolGlobalString('LDAP_FIELD_NAME'),
487 getDolGlobalString('LDAP_FIELD_FIRSTNAME'),
488 getDolGlobalString('LDAP_FIELD_LOGIN'),
489 getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA'),
490 getDolGlobalString('LDAP_FIELD_PASSWORD'),
491 getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED'),
492 getDolGlobalString('LDAP_FIELD_PHONE'),
493 getDolGlobalString('LDAP_FIELD_FAX'),
494 getDolGlobalString('LDAP_FIELD_SKYPE'),
495 getDolGlobalString('LDAP_FIELD_MOBILE'),
496 getDolGlobalString('LDAP_FIELD_MAIL'),
497 getDolGlobalString('LDAP_FIELD_TITLE'),
498 getDolGlobalString('LDAP_FIELD_DESCRIPTION'),
499 getDolGlobalString('LDAP_FIELD_SID')
500 );
501
502 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
503 $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement")));
504
505 // Get from LDAP database an array of results by making a search on
506 // $filter = '('.ldap_escape(getDolGlobalString('LDAP_KEY_USERS'), '', LDAP_ESCAPE_FILTER).'=*)';
507 $ldapusers = $ldap->getRecords('*', getDolGlobalString('LDAP_USER_DN'), getDolGlobalString('LDAP_KEY_USERS'), $required_fields, 1);
508
509 $liste = array();
510 if (is_array($ldapusers)) {
511 foreach ($ldapusers as $key => $ldapuser) {
512 // Define the label string for this user
513 $label = '';
514 foreach ($required_fields as $value) {
515 if ($value) {
516 $label .= $value."=".$ldapuser[$value]." ";
517 }
518 }
519 $liste[$key] = $label;
520 }
521 } else {
522 setEventMessages($ldap->error, $ldap->errors, 'errors');
523 }
524
525 print "<br>\n";
526 print "LDAP search for user:<br>\n";
527 print "search: *<br>\n";
528 print "userDN: ".getDolGlobalString('LDAP_USER_DN')."<br>\n";
529 print "useridentifier: ".getDolGlobalString('LDAP_KEY_USERS')."<br>\n";
530 print "requested fields: ".implode(',', $required_fields)."<br>\n";
531 print "=> ".count($liste)." records<br>\n";
532 print "\n<br>";
533 } else {
534 print img_picto('', 'error').' ';
535 print '<span class="error">'.$langs->trans("LDAPSynchroKO");
536 print ': '.$ldap->error;
537 print '</span><br>';
538 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
539 }
540 }
541}
542
543// End of page
544llxFooter();
545$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='')
Show information in HTML for admin users or standard users.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition ldap.lib.php:33
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition ldap.lib.php:104
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.