dolibarr  9.0.0
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  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('admin', 'errors'));
38 
39 if (!$user->admin)
41 
42 $action = GETPOST('action','aZ09');
43 
44 /*
45  * Actions
46  */
47 
48 if ($action == 'setvalue' && $user->admin)
49 {
50  $error=0;
51  $db->begin();
52 
53  if (! dolibarr_set_const($db, 'LDAP_USER_DN',GETPOST("user"),'chaine',0,'',$conf->entity)) $error++;
54  if (! dolibarr_set_const($db, 'LDAP_USER_OBJECT_CLASS',GETPOST("objectclass"),'chaine',0,'',$conf->entity)) $error++;
55  if (! dolibarr_set_const($db, 'LDAP_FILTER_CONNECTION',GETPOST("filterconnection"),'chaine',0,'',$conf->entity)) $error++;
56  if (! dolibarr_set_const($db, 'LDAP_FIELD_FULLNAME',GETPOST("fieldfullname"),'chaine',0,'',$conf->entity)) $error++;
57  if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN',GETPOST("fieldlogin"),'chaine',0,'',$conf->entity)) $error++;
58  if (! dolibarr_set_const($db, 'LDAP_FIELD_LOGIN_SAMBA',GETPOST("fieldloginsamba"),'chaine',0,'',$conf->entity)) $error++;
59  if (! dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD',GETPOST("fieldpassword"),'chaine',0,'',$conf->entity)) $error++;
60  if (! dolibarr_set_const($db, 'LDAP_FIELD_PASSWORD_CRYPTED',GETPOST("fieldpasswordcrypted"),'chaine',0,'',$conf->entity)) $error++;
61  if (! dolibarr_set_const($db, 'LDAP_FIELD_NAME',GETPOST("fieldname"),'chaine',0,'',$conf->entity)) $error++;
62  if (! dolibarr_set_const($db, 'LDAP_FIELD_FIRSTNAME',GETPOST("fieldfirstname"),'chaine',0,'',$conf->entity)) $error++;
63  if (! dolibarr_set_const($db, 'LDAP_FIELD_MAIL',GETPOST("fieldmail"),'chaine',0,'',$conf->entity)) $error++;
64  if (! dolibarr_set_const($db, 'LDAP_FIELD_PHONE',GETPOST("fieldphone"),'chaine',0,'',$conf->entity)) $error++;
65  if (! dolibarr_set_const($db, 'LDAP_FIELD_MOBILE',GETPOST("fieldmobile"),'chaine',0,'',$conf->entity)) $error++;
66  if (! dolibarr_set_const($db, 'LDAP_FIELD_SKYPE',GETPOST("fieldskype"),'chaine',0,'',$conf->entity)) $error++;
67  if (! dolibarr_set_const($db, 'LDAP_FIELD_FAX',GETPOST("fieldfax"),'chaine',0,'',$conf->entity)) $error++;
68  if (! dolibarr_set_const($db, 'LDAP_FIELD_COMPANY',GETPOST("fieldcompany"),'chaine',0,'',$conf->entity)) $error++;
69  if (! dolibarr_set_const($db, 'LDAP_FIELD_ADDRESS',GETPOST("fieldaddress"),'chaine',0,'',$conf->entity)) $error++;
70  if (! dolibarr_set_const($db, 'LDAP_FIELD_ZIP',GETPOST("fieldzip"),'chaine',0,'',$conf->entity)) $error++;
71  if (! dolibarr_set_const($db, 'LDAP_FIELD_TOWN',GETPOST("fieldtown"),'chaine',0,'',$conf->entity)) $error++;
72  if (! dolibarr_set_const($db, 'LDAP_FIELD_COUNTRY',GETPOST("fieldcountry"),'chaine',0,'',$conf->entity)) $error++;
73  if (! dolibarr_set_const($db, 'LDAP_FIELD_DESCRIPTION',GETPOST("fielddescription"),'chaine',0,'',$conf->entity)) $error++;
74  if (! dolibarr_set_const($db, 'LDAP_FIELD_SID',GETPOST("fieldsid"),'chaine',0,'',$conf->entity)) $error++;
75  if (! dolibarr_set_const($db, 'LDAP_FIELD_TITLE',GETPOST("fieldtitle"),'chaine',0,'',$conf->entity)) $error++;
76 
77  // This one must be after the others
78  $valkey='';
79  $key=GETPOST("key");
80  if ($key) $valkey=$conf->global->$key;
81  if (! dolibarr_set_const($db, 'LDAP_KEY_USERS',$valkey,'chaine',0,'',$conf->entity)) $error++;
82 
83  if (! $error)
84  {
85  $db->commit();
86  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
87  }
88  else
89  {
90  $db->rollback();
91  dol_print_error($db);
92  }
93 }
94 
95 
96 
97 /*
98  * Visu
99  */
100 
101 $form=new Form($db);
102 
103 llxHeader('',$langs->trans("LDAPSetup"),'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP');
104 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
105 
106 print load_fiche_titre($langs->trans("LDAPSetup"),$linkback,'title_setup');
107 
108 $head = ldap_prepare_head();
109 
110 // Test si fonction LDAP actives
111 if (! function_exists("ldap_connect"))
112 {
113  setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
114 }
115 
116 
117 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
118 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
119 
120 
121 dol_fiche_head($head, 'users', $langs->trans("LDAPSetup"), -1);
122 
123 print $langs->trans("LDAPDescUsers").'<br>';
124 print '<br>';
125 
126 
127 print '<table class="noborder" width="100%">';
128 
129 print '<tr class="liste_titre">';
130 print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>';
131 print "</tr>\n";
132 
133 // DN Pour les utilisateurs
134 print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>';
135 print '<input size="48" type="text" name="user" value="'.$conf->global->LDAP_USER_DN.'">';
136 print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>';
137 print '<td>&nbsp;</td>';
138 print '</tr>';
139 
140 // List of object class used to define attributes in structure
141 print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>';
142 print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_USER_OBJECT_CLASS.'">';
143 print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>';
144 print '<td>&nbsp;</td>';
145 print '</tr>';
146 
147 // Filter, used to filter search
148 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>';
149 print '<input size="48" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">';
150 print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>';
151 print '<td></td>';
152 print '</tr>';
153 
154 print '</table>';
155 print '<br>';
156 print '<table class="noborder" width="100%">';
157 
158 print '<tr class="liste_titre">';
159 print '<td width="25%">'.$langs->trans("LDAPDolibarrMapping").'</td>';
160 print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
161 print '<td align="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
162 print "</tr>\n";
163 
164 // Common name
165 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>';
166 print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">';
167 print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>';
168 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FULLNAME)?' checked':'')."></td>";
169 print '</tr>';
170 
171 // Name
172 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
173 print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">';
174 print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
175 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_NAME)?' checked':'')."></td>";
176 print '</tr>';
177 
178 // Firstname
179 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>';
180 print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">';
181 print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>';
182 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FIRSTNAME)?' checked':'')."></td>";
183 print '</tr>';
184 
185 // Login unix
186 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>';
187 print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">';
188 print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>';
189 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN)?' checked':'')."></td>";
190 print '</tr>';
191 
192 // Login samba
193 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>';
194 print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">';
195 print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>';
196 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_LOGIN_SAMBA)?' checked':'')."></td>";
197 print '</tr>';
198 
199 // Password not crypted
200 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>';
201 print '<input size="25" type="text" name="fieldpassword" value="'.$conf->global->LDAP_FIELD_PASSWORD.'">';
202 print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
203 print '<td align="right">&nbsp;</td>';
204 print '</tr>';
205 
206 // Password crypted
207 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>';
208 print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.$conf->global->LDAP_FIELD_PASSWORD_CRYPTED.'">';
209 print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>';
210 print '<td align="right">&nbsp;</td>';
211 print '</tr>';
212 
213 // Mail
214 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>';
215 print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">';
216 print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>';
217 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MAIL)?' checked':'')."></td>";
218 print '</tr>';
219 
220 // Phone
221 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>';
222 print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">';
223 print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>';
224 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_PHONE)?' checked':'')."></td>";
225 print '</tr>';
226 
227 // Mobile
228 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>';
229 print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">';
230 print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>';
231 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_MOBILE)?' checked':'')."></td>";
232 print '</tr>';
233 
234 // Skype
235 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSkype").'</td><td>';
236 print '<input size="25" type="text" name="fieldskype" value="'.$conf->global->LDAP_FIELD_SKYPE.'">';
237 print '</td><td>'.$langs->trans("LDAPFieldSkypeExample").'</td>';
238 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_SKYPE"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_SKYPE)?' checked':'')."></td>";
239 print '</tr>';
240 
241 // Fax
242 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>';
243 print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">';
244 print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>';
245 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_FAX)?' checked':'')."></td>";
246 print '</tr>';
247 
248 // Company
249 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCompany").'</td><td>';
250 print '<input size="25" type="text" name="fieldcompany" value="'.$conf->global->LDAP_FIELD_COMPANY.'">';
251 print '</td><td>'.$langs->trans("LDAPFieldCompanyExample").'</td>';
252 print '<td align="right">&nbsp;</td>';
253 print '</tr>';
254 
255 // Address
256 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldAddress").'</td><td>';
257 print '<input size="25" type="text" name="fieldaddress" value="'.$conf->global->LDAP_FIELD_ADDRESS.'">';
258 print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>';
259 print '<td align="right">&nbsp;</td>';
260 print '</tr>';
261 
262 // ZIP
263 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldZip").'</td><td>';
264 print '<input size="25" type="text" name="fieldzip" value="'.$conf->global->LDAP_FIELD_ZIP.'">';
265 print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>';
266 print '<td align="right">&nbsp;</td>';
267 print '</tr>';
268 
269 // TOWN
270 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTown").'</td><td>';
271 print '<input size="25" type="text" name="fieldtown" value="'.$conf->global->LDAP_FIELD_TOWN.'">';
272 print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>';
273 print '<td align="right">&nbsp;</td>';
274 print '</tr>';
275 
276 // COUNTRY
277 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCountry").'</td><td>';
278 print '<input size="25" type="text" name="fieldcountry" value="'.$conf->global->LDAP_FIELD_COUNTRY.'">';
279 print '</td><td>&nbsp;</td>';
280 print '<td align="right">&nbsp;</td>';
281 print '</tr>';
282 
283 // Title
284 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>';
285 print '<input size="25" type="text" name="fieldtitle" value="'.$conf->global->LDAP_FIELD_TITLE.'">';
286 print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>';
287 print '<td align="right">&nbsp;</td>';
288 print '</tr>';
289 
290 // Note
291 print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>';
292 print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_FIELD_DESCRIPTION.'">';
293 print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
294 print '<td align="right">&nbsp;</td>';
295 print '</tr>';
296 
297 // Sid
298 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>';
299 print '<input size="25" type="text" name="fieldsid" value="'.$conf->global->LDAP_FIELD_SID.'">';
300 print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>';
301 print '<td align="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(($conf->global->LDAP_KEY_USERS && $conf->global->LDAP_KEY_USERS==$conf->global->LDAP_FIELD_SID)?' checked':'')."></td>";
302 print '</tr>';
303 
304 print '</table>';
305 
306 print info_admin($langs->trans("LDAPDescValues"));
307 
308 dol_fiche_end();
309 
310 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
311 
312 print '</form>';
313 
314 
315 /*
316  * Test de la connexion
317  */
318 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
319 {
320  $butlabel=$langs->trans("LDAPTestSynchroUser");
321  $testlabel='testuser';
322  $key=$conf->global->LDAP_KEY_USERS;
323  $dn=$conf->global->LDAP_USER_DN;
324  $objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
325 
326  show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
327 }
328 elseif ($conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')
329 {
330  $butlabel=$langs->trans("LDAPTestSearch");
331  $testlabel='testsearchuser';
332  $key=$conf->global->LDAP_KEY_USERS;
333  $dn=$conf->global->LDAP_USER_DN;
334  $objectclass=$conf->global->LDAP_USER_OBJECT_CLASS;
335  show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
336 }
337 
338 if (function_exists("ldap_connect"))
339 {
340  if ($action == 'testuser')
341  {
342  // Creation objet
343  $object=new User($db);
344  $object->initAsSpecimen();
345 
346  // TODO Mutualize code following with other ldap_xxxx.php pages
347 
348  // Test synchro
349  $ldap=new Ldap();
350  $result=$ldap->connect_bind();
351 
352  if ($result > 0)
353  {
354  $info=$object->_load_ldap_info();
355  $dn=$object->_load_ldap_dn($info);
356 
357  $result1=$ldap->delete($dn); // To be sure to delete existing records
358  $result2=$ldap->add($dn,$info,$user); // Now the test
359  $result3=$ldap->delete($dn); // Clean what we did
360 
361  if ($result2 > 0)
362  {
363  print img_picto('','info').' ';
364  print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
365  }
366  else
367  {
368  print img_picto('','error').' ';
369  print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
370  print ': '.$ldap->error;
371  print '</font><br>';
372  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
373  }
374 
375  print "<br>\n";
376  print "LDAP input file used for test:<br><br>\n";
377  print nl2br($ldap->dump_content($dn,$info));
378  print "\n<br>";
379  }
380  else
381  {
382  print img_picto('','error').' ';
383  print '<font class="error">'.$langs->trans("LDAPSynchroKO");
384  print ': '.$ldap->error;
385  print '</font><br>';
386  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
387  }
388  }
389 
390  if ($action == 'testsearchuser')
391  {
392  // Creation objet
393  $object=new User($db);
394  $object->initAsSpecimen();
395 
396  // TODO Mutualize code following with other ldap_xxxx.php pages
397 
398  // Test synchro
399  $ldap=new Ldap();
400  $result=$ldap->connect_bind();
401 
402  if ($result > 0)
403  {
404  $required_fields = array(
405  $conf->global->LDAP_KEY_USERS,
406  $conf->global->LDAP_FIELD_FULLNAME,
407  $conf->global->LDAP_FIELD_NAME,
408  $conf->global->LDAP_FIELD_FIRSTNAME,
409  $conf->global->LDAP_FIELD_LOGIN,
410  $conf->global->LDAP_FIELD_LOGIN_SAMBA,
411  $conf->global->LDAP_FIELD_PASSWORD,
412  $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
413  $conf->global->LDAP_FIELD_PHONE,
414  $conf->global->LDAP_FIELD_FAX,
415  $conf->global->LDAP_FIELD_SKYPE,
416  $conf->global->LDAP_FIELD_MOBILE,
417  $conf->global->LDAP_FIELD_MAIL,
418  $conf->global->LDAP_FIELD_TITLE,
419  $conf->global->LDAP_FIELD_DESCRIPTION,
420  $conf->global->LDAP_FIELD_SID
421  );
422 
423  // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
424  $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
425 
426  // Get from LDAP database an array of results
427  $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
428  //$ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, '', 1);
429 
430  if (is_array($ldapusers))
431  {
432  $liste=array();
433  foreach ($ldapusers as $key => $ldapuser)
434  {
435  // Define the label string for this user
436  $label='';
437  foreach ($required_fields as $value)
438  {
439  if ($value)
440  {
441  $label.=$value."=".$ldapuser[$value]." ";
442  }
443  }
444  $liste[$key] = $label;
445  }
446  }
447  else
448  {
449  setEventMessages($ldap->error, $ldap->errors, 'errors');
450  }
451 
452  print "<br>\n";
453  print "LDAP search for user:<br>\n";
454  print "search: *<br>\n";
455  print "userDN: ".$conf->global->LDAP_USER_DN."<br>\n";
456  print "useridentifier: ".$conf->global->LDAP_KEY_USERS."<br>\n";
457  print "required_fields: ".implode(',',$required_fields)."<br>\n";
458  print "=> ".count($liste)." records<br>\n";
459  print "\n<br>";
460  }
461  else
462  {
463  print img_picto('','error').' ';
464  print '<font class="error">'.$langs->trans("LDAPSynchroKO");
465  print ': '.$ldap->error;
466  print '</font><br>';
467  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
468  }
469  }
470 }
471 
472 // End of page
473 llxFooter();
474 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage Dolibarr users.
Definition: user.class.php:41
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:510
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:106
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage LDAP features.
Definition: ldap.class.php:30
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.