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