dolibarr 21.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 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();
159 dol_print_error($db);
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$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
173
174print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup');
175
176$head = ldap_prepare_head();
177
178// Test if the LDAP functionality is available
179if (!function_exists("ldap_connect")) {
180 setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
181}
182
183
184print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue&token='.newToken().'">';
185print '<input type="hidden" name="token" value="'.newToken().'">';
186
187
188print dol_get_fiche_head($head, 'users', '', -1);
189
190print '<span class="opacitymedium">'.$langs->trans("LDAPDescUsers").'</span><br>';
191print '<br>';
192
193
194print '<table class="noborder centpercent">';
195
196print '<tr class="liste_titre">';
197print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
198print "</tr>\n";
199
200// DN (Domain Name) for the users
201print '<!-- LDAP_USER_DN -->';
202print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>';
203print '<input size="48" type="text" name="user" value="'.getDolGlobalString('LDAP_USER_DN').'">';
204print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
205print '<td>&nbsp;</td>';
206print '</tr>';
207
208// List of object class used to define attributes in structure
209print '<!-- LDAP_USER_OBJECT_CLASS -->';
210print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>';
211print '<input size="48" type="text" name="objectclass" value="'.getDolGlobalString('LDAP_USER_OBJECT_CLASS').'">';
212print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>';
213print '<td>&nbsp;</td>';
214print '</tr>';
215
216// Filter, used to filter search
217print '<!-- LDAP_FILTER_CONNECTION -->';
218print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
219print '<input size="48" type="text" name="filterconnection" value="'.getDolGlobalString('LDAP_FILTER_CONNECTION').'">';
220print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
221print '<td></td>';
222print '</tr>';
223
224print '</table>';
225print '<br>';
226print '<table class="noborder centpercent">';
227
228print '<tr class="liste_titre">';
229print '<td>'.$langs->trans("LDAPDolibarrMapping").'</td>';
230print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
231print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
232print "</tr>\n";
233
234// Common name
235print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
236print '<input size="25" type="text" name="fieldfullname" value="'.getDolGlobalString('LDAP_FIELD_FULLNAME').'">';
237print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
238print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FULLNAME') ? ' checked' : '')."></td>";
239print '</tr>';
240
241// Name
242print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
243print '<input size="25" type="text" name="fieldname" value="'.getDolGlobalString('LDAP_FIELD_NAME').'">';
244print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
245print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_NAME') ? ' checked' : '')."></td>";
246print '</tr>';
247
248// Firstname
249print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
250print '<input size="25" type="text" name="fieldfirstname" value="'.getDolGlobalString('LDAP_FIELD_FIRSTNAME').'">';
251print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
252print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FIRSTNAME') ? ' checked' : '')."></td>";
253print '</tr>';
254
255// Login unix
256print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
257print '<input size="25" type="text" name="fieldlogin" value="'.getDolGlobalString('LDAP_FIELD_LOGIN').'">';
258print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
259print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_LOGIN') ? ' checked' : '')."></td>";
260print '</tr>';
261
262// Login samba
263print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
264print '<input size="25" type="text" name="fieldloginsamba" value="'.getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA').'">';
265print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
266print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA') ? ' checked' : '')."></td>";
267print '</tr>';
268
269// Password not encrypted
270print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>';
271print '<input size="25" type="text" name="fieldpassword" value="'.getDolGlobalString('LDAP_FIELD_PASSWORD').'">';
272print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
273print '<td class="right">&nbsp;</td>';
274print '</tr>';
275
276// Password encrypted
277print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>';
278print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED').'">';
279print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
280print '<td class="right">&nbsp;</td>';
281print '</tr>';
282
283// Mail
284print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
285print '<input size="25" type="text" name="fieldmail" value="'.getDolGlobalString('LDAP_FIELD_MAIL').'">';
286print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
287print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_MAIL') ? ' checked' : '')."></td>";
288print '</tr>';
289
290// Phone
291print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
292print '<input size="25" type="text" name="fieldphone" value="'.getDolGlobalString('LDAP_FIELD_PHONE').'">';
293print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
294print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_PHONE') ? ' checked' : '')."></td>";
295print '</tr>';
296
297// Mobile
298print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
299print '<input size="25" type="text" name="fieldmobile" value="'.getDolGlobalString('LDAP_FIELD_MOBILE').'">';
300print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
301print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_MOBILE') ? ' checked' : '')."></td>";
302print '</tr>';
303
304// Fax
305print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
306print '<input size="25" type="text" name="fieldfax" value="'.getDolGlobalString('LDAP_FIELD_FAX').'">';
307print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
308print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FAX') ? ' checked' : '')."></td>";
309print '</tr>';
310
311// Company
312print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCompany").'</td><td>';
313print '<input size="25" type="text" name="fieldcompany" value="'.getDolGlobalString('LDAP_FIELD_COMPANY').'">';
314print '</td><td>'.$langs->trans("LDAPFieldCompanyExample").'</td>';
315print '<td class="right">&nbsp;</td>';
316print '</tr>';
317
318// Address
319print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldAddress").'</td><td>';
320print '<input size="25" type="text" name="fieldaddress" value="'.getDolGlobalString('LDAP_FIELD_ADDRESS').'">';
321print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>';
322print '<td class="right">&nbsp;</td>';
323print '</tr>';
324
325// ZIP
326print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldZip").'</td><td>';
327print '<input size="25" type="text" name="fieldzip" value="'.getDolGlobalString('LDAP_FIELD_ZIP').'">';
328print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>';
329print '<td class="right">&nbsp;</td>';
330print '</tr>';
331
332// TOWN
333print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTown").'</td><td>';
334print '<input size="25" type="text" name="fieldtown" value="'.getDolGlobalString('LDAP_FIELD_TOWN').'">';
335print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>';
336print '<td class="right">&nbsp;</td>';
337print '</tr>';
338
339// COUNTRY
340print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCountry").'</td><td>';
341print '<input size="25" type="text" name="fieldcountry" value="'.getDolGlobalString('LDAP_FIELD_COUNTRY').'">';
342print '</td><td>&nbsp;</td>';
343print '<td class="right">&nbsp;</td>';
344print '</tr>';
345
346// Title
347print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>';
348print '<input size="25" type="text" name="fieldtitle" value="'.getDolGlobalString('LDAP_FIELD_TITLE').'">';
349print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>';
350print '<td class="right">&nbsp;</td>';
351print '</tr>';
352
353// Note
354print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>';
355print '<input size="25" type="text" name="fielddescription" value="'.getDolGlobalString('LDAP_FIELD_DESCRIPTION').'">';
356print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
357print '<td class="right">&nbsp;</td>';
358print '</tr>';
359
360// Sid
361print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>';
362print '<input size="25" type="text" name="fieldsid" value="'.getDolGlobalString('LDAP_FIELD_SID').'">';
363print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>';
364print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_SID') ? ' checked' : '')."></td>";
365print '</tr>';
366
367// Group id
368print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupid").'</td><td>';
369print '<input size="25" type="text" name="fieldgroupid" value="'.getDolGlobalString('LDAP_FIELD_GROUPID').'">';
370print '</td><td>'.$langs->trans("LDAPFieldGroupidExample").'</td>';
371print '<td class="right">&nbsp;</td>';
372print '</tr>';
373
374// Userid
375print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldUserid").'</td><td>';
376print '<input size="25" type="text" name="fielduserid" value="'.getDolGlobalString('LDAP_FIELD_USERID').'">';
377print '</td><td>'.$langs->trans("LDAPFieldUseridExample").'</td>';
378print '<td class="right">&nbsp;</td>';
379print '</tr>';
380
381// Home Directory
382print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectory").'</td><td>';
383print '<input size="25" type="text" name="fieldhomedirectory" value="'.getDolGlobalString('LDAP_FIELD_HOMEDIRECTORY').'">';
384print '</td><td>'.$langs->trans("LDAPFieldHomedirectoryExample").'</td>';
385print '<td class="right">&nbsp;</td>';
386print '</tr>';
387
388// Home Directory Prefix
389print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectoryprefix").'</td><td>';
390print '<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.getDolGlobalString('LDAP_FIELD_HOMEDIRECTORYPREFIX').'">';
391print '</td><td></td>';
392print '<td class="right">&nbsp;</td>';
393print '</tr>';
394
395print '</table>';
396
397print info_admin($langs->trans("LDAPDescValues"));
398
399print dol_get_fiche_end();
400
401print $form->buttonsSaveCancel("Modify", '');
402
403print '</form>';
404
405
406/*
407 * Test de la connection
408 */
409if (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') == Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
410 $butlabel = $langs->trans("LDAPTestSynchroUser");
411 $testlabel = 'testuser';
412 $key = getDolGlobalString('LDAP_KEY_USERS');
413 $dn = getDolGlobalString('LDAP_USER_DN');
414 $objectclass = getDolGlobalString('LDAP_USER_OBJECT_CLASS');
415
416 show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
417} elseif (getDolGlobalString('LDAP_SYNCHRO_ACTIVE') == Ldap::SYNCHRO_LDAP_TO_DOLIBARR) {
418 $butlabel = $langs->trans("LDAPTestSearch");
419 $testlabel = 'testsearchuser';
420 $key = getDolGlobalString('LDAP_KEY_USERS');
421 $dn = getDolGlobalString('LDAP_USER_DN');
422 $objectclass = getDolGlobalString('LDAP_USER_OBJECT_CLASS');
423 show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass);
424}
425
426if (function_exists("ldap_connect")) {
427 if ($action == 'testuser') {
428 // Create object
429 $object = new User($db);
430 $object->initAsSpecimen();
431
432 // TODO Mutualize code following with other ldap_xxxx.php pages
433
434 // Test synchro
435 $ldap = new Ldap();
436 $result = $ldap->connectBind();
437
438 if ($result > 0) {
439 $info = $object->_load_ldap_info();
440 $dn = $object->_load_ldap_dn($info);
441
442 $result1 = $ldap->delete($dn); // To be sure to delete existing records
443 $result2 = $ldap->add($dn, $info, $user); // Now the test
444 $result3 = $ldap->delete($dn); // Clean what we did
445
446 if ($result2 > 0) {
447 print img_picto('', 'info').' ';
448 print '<span class="ok">'.$langs->trans("LDAPSynchroOK").'</span><br>';
449 } else {
450 print img_picto('', 'error').' ';
451 print '<span class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
452 print ': '.$ldap->error;
453 print '</span><br>';
454 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
455 }
456
457 print "<br>\n";
458 print "LDAP input file used for test:<br><br>\n";
459 print nl2br($ldap->dumpContent($dn, $info));
460 print "\n<br>";
461 } else {
462 print img_picto('', 'error').' ';
463 print '<span class="error">'.$langs->trans("LDAPSynchroKO");
464 print ': '.$ldap->error;
465 print '</span><br>';
466 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
467 }
468 }
469
470 if ($action == 'testsearchuser') {
471 // Create object
472 $object = new User($db);
473 $object->initAsSpecimen();
474
475 // TODO Mutualize code following with other ldap_xxxx.php pages
476
477 // Test synchro
478 $ldap = new Ldap();
479 $result = $ldap->connectBind();
480
481 if ($result > 0) {
482 $required_fields = array(
483 getDolGlobalString('LDAP_KEY_USERS'),
484 getDolGlobalString('LDAP_FIELD_FULLNAME'),
485 getDolGlobalString('LDAP_FIELD_NAME'),
486 getDolGlobalString('LDAP_FIELD_FIRSTNAME'),
487 getDolGlobalString('LDAP_FIELD_LOGIN'),
488 getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA'),
489 getDolGlobalString('LDAP_FIELD_PASSWORD'),
490 getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED'),
491 getDolGlobalString('LDAP_FIELD_PHONE'),
492 getDolGlobalString('LDAP_FIELD_FAX'),
493 getDolGlobalString('LDAP_FIELD_SKYPE'),
494 getDolGlobalString('LDAP_FIELD_MOBILE'),
495 getDolGlobalString('LDAP_FIELD_MAIL'),
496 getDolGlobalString('LDAP_FIELD_TITLE'),
497 getDolGlobalString('LDAP_FIELD_DESCRIPTION'),
498 getDolGlobalString('LDAP_FIELD_SID')
499 );
500
501 // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
502 $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement")));
503
504 // Get from LDAP database an array of results by making a search on
505 // $filter = '('.ldap_escape(getDolGlobalString('LDAP_KEY_USERS'), '', LDAP_ESCAPE_FILTER).'=*)';
506 $ldapusers = $ldap->getRecords('*', getDolGlobalString('LDAP_USER_DN'), getDolGlobalString('LDAP_KEY_USERS'), $required_fields, 1);
507
508 $liste = array();
509 if (is_array($ldapusers)) {
510 foreach ($ldapusers as $key => $ldapuser) {
511 // Define the label string for this user
512 $label = '';
513 foreach ($required_fields as $value) {
514 if ($value) {
515 $label .= $value."=".$ldapuser[$value]." ";
516 }
517 }
518 $liste[$key] = $label;
519 }
520 } else {
521 setEventMessages($ldap->error, $ldap->errors, 'errors');
522 }
523
524 print "<br>\n";
525 print "LDAP search for user:<br>\n";
526 print "search: *<br>\n";
527 print "userDN: ".getDolGlobalString('LDAP_USER_DN')."<br>\n";
528 print "useridentifier: ".getDolGlobalString('LDAP_KEY_USERS')."<br>\n";
529 print "requested fields: ".implode(',', $required_fields)."<br>\n";
530 print "=> ".count($liste)." records<br>\n";
531 print "\n<br>";
532 } else {
533 print img_picto('', 'error').' ';
534 print '<span class="error">'.$langs->trans("LDAPSynchroKO");
535 print ': '.$ldap->error;
536 print '</span><br>';
537 print $langs->trans("ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).'<br>';
538 }
539 }
540}
541
542// End of page
543llxFooter();
544$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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).
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:71
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
Class to manage Dolibarr users.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
Show picto whatever it's its name (generic function)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.