dolibarr  20.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  *
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
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
36 require_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 
41 if (!$user->admin) {
43 }
44 
45 $action = GETPOST('action', 'aZ09');
46 
47 /*
48  * Actions
49  */
50 
51 if ($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 
161 llxHeader('', $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 
164 print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup');
165 
166 $head = ldap_prepare_head();
167 
168 // Test if the LDAP functionality is available
169 if (!function_exists("ldap_connect")) {
170  setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
171 }
172 
173 
174 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue&token='.newToken().'">';
175 print '<input type="hidden" name="token" value="'.newToken().'">';
176 
177 
178 print dol_get_fiche_head($head, 'users', '', -1);
179 
180 print '<span class="opacitymedium">'.$langs->trans("LDAPDescUsers").'</span><br>';
181 print '<br>';
182 
183 
184 print '<table class="noborder centpercent">';
185 
186 print '<tr class="liste_titre">';
187 print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
188 print "</tr>\n";
189 
190 // DN (Domain Name) for the users
191 print '<!-- LDAP_USER_DN -->';
192 print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>';
193 print '<input size="48" type="text" name="user" value="'.getDolGlobalString('LDAP_USER_DN').'">';
194 print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
195 print '<td>&nbsp;</td>';
196 print '</tr>';
197 
198 // List of object class used to define attributes in structure
199 print '<!-- LDAP_USER_OBJECT_CLASS -->';
200 print '<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>';
201 print '<input size="48" type="text" name="objectclass" value="'.getDolGlobalString('LDAP_USER_OBJECT_CLASS').'">';
202 print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>';
203 print '<td>&nbsp;</td>';
204 print '</tr>';
205 
206 // Filter, used to filter search
207 print '<!-- LDAP_FILTER_CONNECTION -->';
208 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
209 print '<input size="48" type="text" name="filterconnection" value="'.getDolGlobalString('LDAP_FILTER_CONNECTION').'">';
210 print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
211 print '<td></td>';
212 print '</tr>';
213 
214 print '</table>';
215 print '<br>';
216 print '<table class="noborder centpercent">';
217 
218 print '<tr class="liste_titre">';
219 print '<td>'.$langs->trans("LDAPDolibarrMapping").'</td>';
220 print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
221 print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
222 print "</tr>\n";
223 
224 // Common name
225 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
226 print '<input size="25" type="text" name="fieldfullname" value="'.getDolGlobalString('LDAP_FIELD_FULLNAME').'">';
227 print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
228 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FULLNAME') ? ' checked' : '')."></td>";
229 print '</tr>';
230 
231 // Name
232 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
233 print '<input size="25" type="text" name="fieldname" value="'.getDolGlobalString('LDAP_FIELD_NAME').'">';
234 print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
235 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_NAME') ? ' checked' : '')."></td>";
236 print '</tr>';
237 
238 // Firstname
239 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
240 print '<input size="25" type="text" name="fieldfirstname" value="'.getDolGlobalString('LDAP_FIELD_FIRSTNAME').'">';
241 print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
242 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FIRSTNAME') ? ' checked' : '')."></td>";
243 print '</tr>';
244 
245 // Login unix
246 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
247 print '<input size="25" type="text" name="fieldlogin" value="'.getDolGlobalString('LDAP_FIELD_LOGIN').'">';
248 print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
249 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_LOGIN') ? ' checked' : '')."></td>";
250 print '</tr>';
251 
252 // Login samba
253 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
254 print '<input size="25" type="text" name="fieldloginsamba" value="'.getDolGlobalString('LDAP_FIELD_LOGIN_SAMBA').'">';
255 print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
256 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>";
257 print '</tr>';
258 
259 // Password not encrypted
260 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>';
261 print '<input size="25" type="text" name="fieldpassword" value="'.getDolGlobalString('LDAP_FIELD_PASSWORD').'">';
262 print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
263 print '<td class="right">&nbsp;</td>';
264 print '</tr>';
265 
266 // Password encrypted
267 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>';
268 print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.getDolGlobalString('LDAP_FIELD_PASSWORD_CRYPTED').'">';
269 print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
270 print '<td class="right">&nbsp;</td>';
271 print '</tr>';
272 
273 // Mail
274 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
275 print '<input size="25" type="text" name="fieldmail" value="'.getDolGlobalString('LDAP_FIELD_MAIL').'">';
276 print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
277 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_MAIL') ? ' checked' : '')."></td>";
278 print '</tr>';
279 
280 // Phone
281 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
282 print '<input size="25" type="text" name="fieldphone" value="'.getDolGlobalString('LDAP_FIELD_PHONE').'">';
283 print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
284 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_PHONE') ? ' checked' : '')."></td>";
285 print '</tr>';
286 
287 // Mobile
288 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
289 print '<input size="25" type="text" name="fieldmobile" value="'.getDolGlobalString('LDAP_FIELD_MOBILE').'">';
290 print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
291 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_MOBILE') ? ' checked' : '')."></td>";
292 print '</tr>';
293 
294 // Fax
295 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
296 print '<input size="25" type="text" name="fieldfax" value="'.getDolGlobalString('LDAP_FIELD_FAX').'">';
297 print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
298 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_FAX') ? ' checked' : '')."></td>";
299 print '</tr>';
300 
301 // Company
302 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCompany").'</td><td>';
303 print '<input size="25" type="text" name="fieldcompany" value="'.getDolGlobalString('LDAP_FIELD_COMPANY').'">';
304 print '</td><td>'.$langs->trans("LDAPFieldCompanyExample").'</td>';
305 print '<td class="right">&nbsp;</td>';
306 print '</tr>';
307 
308 // Address
309 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldAddress").'</td><td>';
310 print '<input size="25" type="text" name="fieldaddress" value="'.getDolGlobalString('LDAP_FIELD_ADDRESS').'">';
311 print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>';
312 print '<td class="right">&nbsp;</td>';
313 print '</tr>';
314 
315 // ZIP
316 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldZip").'</td><td>';
317 print '<input size="25" type="text" name="fieldzip" value="'.getDolGlobalString('LDAP_FIELD_ZIP').'">';
318 print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>';
319 print '<td class="right">&nbsp;</td>';
320 print '</tr>';
321 
322 // TOWN
323 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTown").'</td><td>';
324 print '<input size="25" type="text" name="fieldtown" value="'.getDolGlobalString('LDAP_FIELD_TOWN').'">';
325 print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>';
326 print '<td class="right">&nbsp;</td>';
327 print '</tr>';
328 
329 // COUNTRY
330 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCountry").'</td><td>';
331 print '<input size="25" type="text" name="fieldcountry" value="'.getDolGlobalString('LDAP_FIELD_COUNTRY').'">';
332 print '</td><td>&nbsp;</td>';
333 print '<td class="right">&nbsp;</td>';
334 print '</tr>';
335 
336 // Title
337 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>';
338 print '<input size="25" type="text" name="fieldtitle" value="'.getDolGlobalString('LDAP_FIELD_TITLE').'">';
339 print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>';
340 print '<td class="right">&nbsp;</td>';
341 print '</tr>';
342 
343 // Note
344 print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>';
345 print '<input size="25" type="text" name="fielddescription" value="'.getDolGlobalString('LDAP_FIELD_DESCRIPTION').'">';
346 print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
347 print '<td class="right">&nbsp;</td>';
348 print '</tr>';
349 
350 // Sid
351 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>';
352 print '<input size="25" type="text" name="fieldsid" value="'.getDolGlobalString('LDAP_FIELD_SID').'">';
353 print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>';
354 print '<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(getDolGlobalString('LDAP_KEY_USERS') == getDolGlobalString('LDAP_FIELD_SID') ? ' checked' : '')."></td>";
355 print '</tr>';
356 
357 // Group id
358 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupid").'</td><td>';
359 print '<input size="25" type="text" name="fieldgroupid" value="'.getDolGlobalString('LDAP_FIELD_GROUPID').'">';
360 print '</td><td>'.$langs->trans("LDAPFieldGroupidExample").'</td>';
361 print '<td class="right">&nbsp;</td>';
362 print '</tr>';
363 
364 // Userid
365 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldUserid").'</td><td>';
366 print '<input size="25" type="text" name="fielduserid" value="'.getDolGlobalString('LDAP_FIELD_USERID').'">';
367 print '</td><td>'.$langs->trans("LDAPFieldUseridExample").'</td>';
368 print '<td class="right">&nbsp;</td>';
369 print '</tr>';
370 
371 // Home Directory
372 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectory").'</td><td>';
373 print '<input size="25" type="text" name="fieldhomedirectory" value="'.getDolGlobalString('LDAP_FIELD_HOMEDIRECTORY').'">';
374 print '</td><td>'.$langs->trans("LDAPFieldHomedirectoryExample").'</td>';
375 print '<td class="right">&nbsp;</td>';
376 print '</tr>';
377 
378 // Home Directory Prefix
379 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectoryprefix").'</td><td>';
380 print '<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.getDolGlobalString('LDAP_FIELD_HOMEDIRECTORYPREFIX').'">';
381 print '</td><td></td>';
382 print '<td class="right">&nbsp;</td>';
383 print '</tr>';
384 
385 print '</table>';
386 
387 print info_admin($langs->trans("LDAPDescValues"));
388 
389 print dol_get_fiche_end();
390 
391 print $form->buttonsSaveCancel("Modify", '');
392 
393 print '</form>';
394 
395 
396 /*
397  * Test de la connection
398  */
399 if (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 
416 if (function_exists("ldap_connect")) {
417  if ($action == 'testuser') {
418  // Create object
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->connectBind();
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->dumpContent($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  // Create object
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->connectBind();
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
533 llxFooter();
534 $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).
Definition: admin.lib.php:656
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.
Definition: ldap.class.php:37
Class to manage Dolibarr users.
Definition: user.class.php:50
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information in HTML for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.