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