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