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