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 24/** 25 * \file htdocs/admin/ldap_users.php 26 * \ingroup ldap 27 * \brief Page d'administration/configuration du module Ldap 28 */ 29 30require '../main.inc.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; 32require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; 33require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php'; 34require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; 35require_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 40if (!$user->admin) 41 accessforbidden(); 42 43$action = GETPOST('action', 'aZ09'); 44 45/* 46 * Actions 47 */ 48 49if ($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 106llxHeader('', $langs->trans("LDAPSetup"), 'EN:Module_LDAP_En|FR:Module_LDAP|ES:Módulo_LDAP'); 107$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; 108 109print load_fiche_titre($langs->trans("LDAPSetup"), $linkback, 'title_setup'); 110 111$head = ldap_prepare_head(); 112 113// Test si fonction LDAP actives 114if (!function_exists("ldap_connect")) 115{ 116 setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors'); 117} 118 119 120print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">'; 121print '<input type="hidden" name="token" value="'.newToken().'">'; 122 123 124print dol_get_fiche_head($head, 'users', $langs->trans("LDAPSetup"), -1); 125 126print $langs->trans("LDAPDescUsers").'<br>'; 127print '<br>'; 128 129 130print '<table class="noborder centpercent">'; 131 132print '<tr class="liste_titre">'; 133print '<td colspan="4">'.$langs->trans("LDAPSynchronizeUsers").'</td>'; 134print "</tr>\n"; 135 136// DN Pour les utilisateurs 137print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserDn").'</span></td><td>'; 138print '<input size="48" type="text" name="user" value="'.$conf->global->LDAP_USER_DN.'">'; 139print '</td><td>'.$langs->trans("LDAPUserDnExample").'</td>'; 140print '<td> </td>'; 141print '</tr>'; 142 143// List of object class used to define attributes in structure 144print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPUserObjectClassList").'</span></td><td>'; 145print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_USER_OBJECT_CLASS.'">'; 146print '</td><td>'.$langs->trans("LDAPUserObjectClassListExample").'</td>'; 147print '<td> </td>'; 148print '</tr>'; 149 150// Filter, used to filter search 151print '<tr class="oddeven"><td>'.$langs->trans("LDAPFilterConnection").'</td><td>'; 152print '<input size="48" type="text" name="filterconnection" value="'.$conf->global->LDAP_FILTER_CONNECTION.'">'; 153print '</td><td>'.$langs->trans("LDAPFilterConnectionExample").'</td>'; 154print '<td></td>'; 155print '</tr>'; 156 157print '</table>'; 158print '<br>'; 159print '<table class="noborder centpercent">'; 160 161print '<tr class="liste_titre">'; 162print '<td width="25%">'.$langs->trans("LDAPDolibarrMapping").'</td>'; 163print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>'; 164print '<td class="right">'.$langs->trans("LDAPNamingAttribute").'</td>'; 165print "</tr>\n"; 166 167// Common name 168print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFullname").'</td><td>'; 169print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_FIELD_FULLNAME.'">'; 170print '</td><td>'.$langs->trans("LDAPFieldFullnameExample").'</td>'; 171print '<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>"; 172print '</tr>'; 173 174// Name 175print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>'; 176print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_FIELD_NAME.'">'; 177print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>'; 178print '<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>"; 179print '</tr>'; 180 181// Firstname 182print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFirstName").'</td><td>'; 183print '<input size="25" type="text" name="fieldfirstname" value="'.$conf->global->LDAP_FIELD_FIRSTNAME.'">'; 184print '</td><td>'.$langs->trans("LDAPFieldFirstNameExample").'</td>'; 185print '<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>"; 186print '</tr>'; 187 188// Login unix 189print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginUnix").'</td><td>'; 190print '<input size="25" type="text" name="fieldlogin" value="'.$conf->global->LDAP_FIELD_LOGIN.'">'; 191print '</td><td>'.$langs->trans("LDAPFieldLoginExample").'</td>'; 192print '<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>"; 193print '</tr>'; 194 195// Login samba 196print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldLoginSamba").'</td><td>'; 197print '<input size="25" type="text" name="fieldloginsamba" value="'.$conf->global->LDAP_FIELD_LOGIN_SAMBA.'">'; 198print '</td><td>'.$langs->trans("LDAPFieldLoginSambaExample").'</td>'; 199print '<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>"; 200print '</tr>'; 201 202// Password not crypted 203print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordNotCrypted").'</td><td>'; 204print '<input size="25" type="text" name="fieldpassword" value="'.$conf->global->LDAP_FIELD_PASSWORD.'">'; 205print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>'; 206print '<td class="right"> </td>'; 207print '</tr>'; 208 209// Password crypted 210print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPasswordCrypted").'</td><td>'; 211print '<input size="25" type="text" name="fieldpasswordcrypted" value="'.$conf->global->LDAP_FIELD_PASSWORD_CRYPTED.'">'; 212print '</td><td>'.$langs->trans("LDAPFieldPasswordExample").'</td>'; 213print '<td class="right"> </td>'; 214print '</tr>'; 215 216// Mail 217print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMail").'</td><td>'; 218print '<input size="25" type="text" name="fieldmail" value="'.$conf->global->LDAP_FIELD_MAIL.'">'; 219print '</td><td>'.$langs->trans("LDAPFieldMailExample").'</td>'; 220print '<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>"; 221print '</tr>'; 222 223// Phone 224print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldPhone").'</td><td>'; 225print '<input size="25" type="text" name="fieldphone" value="'.$conf->global->LDAP_FIELD_PHONE.'">'; 226print '</td><td>'.$langs->trans("LDAPFieldPhoneExample").'</td>'; 227print '<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>"; 228print '</tr>'; 229 230// Mobile 231print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldMobile").'</td><td>'; 232print '<input size="25" type="text" name="fieldmobile" value="'.$conf->global->LDAP_FIELD_MOBILE.'">'; 233print '</td><td>'.$langs->trans("LDAPFieldMobileExample").'</td>'; 234print '<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>"; 235print '</tr>'; 236 237// Skype 238print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSkype").'</td><td>'; 239print '<input size="25" type="text" name="fieldskype" value="'.$conf->global->LDAP_FIELD_SKYPE.'">'; 240print '</td><td>'.$langs->trans("LDAPFieldSkypeExample").'</td>'; 241print '<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>"; 242print '</tr>'; 243 244// Fax 245print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldFax").'</td><td>'; 246print '<input size="25" type="text" name="fieldfax" value="'.$conf->global->LDAP_FIELD_FAX.'">'; 247print '</td><td>'.$langs->trans("LDAPFieldFaxExample").'</td>'; 248print '<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>"; 249print '</tr>'; 250 251// Company 252print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCompany").'</td><td>'; 253print '<input size="25" type="text" name="fieldcompany" value="'.$conf->global->LDAP_FIELD_COMPANY.'">'; 254print '</td><td>'.$langs->trans("LDAPFieldCompanyExample").'</td>'; 255print '<td class="right"> </td>'; 256print '</tr>'; 257 258// Address 259print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldAddress").'</td><td>'; 260print '<input size="25" type="text" name="fieldaddress" value="'.$conf->global->LDAP_FIELD_ADDRESS.'">'; 261print '</td><td>'.$langs->trans("LDAPFieldAddressExample").'</td>'; 262print '<td class="right"> </td>'; 263print '</tr>'; 264 265// ZIP 266print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldZip").'</td><td>'; 267print '<input size="25" type="text" name="fieldzip" value="'.$conf->global->LDAP_FIELD_ZIP.'">'; 268print '</td><td>'.$langs->trans("LDAPFieldZipExample").'</td>'; 269print '<td class="right"> </td>'; 270print '</tr>'; 271 272// TOWN 273print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTown").'</td><td>'; 274print '<input size="25" type="text" name="fieldtown" value="'.$conf->global->LDAP_FIELD_TOWN.'">'; 275print '</td><td>'.$langs->trans("LDAPFieldTownExample").'</td>'; 276print '<td class="right"> </td>'; 277print '</tr>'; 278 279// COUNTRY 280print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldCountry").'</td><td>'; 281print '<input size="25" type="text" name="fieldcountry" value="'.$conf->global->LDAP_FIELD_COUNTRY.'">'; 282print '</td><td> </td>'; 283print '<td class="right"> </td>'; 284print '</tr>'; 285 286// Title 287print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldTitle").'</td><td>'; 288print '<input size="25" type="text" name="fieldtitle" value="'.$conf->global->LDAP_FIELD_TITLE.'">'; 289print '</td><td>'.$langs->trans("LDAPFieldTitleExample").'</td>'; 290print '<td class="right"> </td>'; 291print '</tr>'; 292 293// Note 294print '<tr class="oddeven"><td>'.$langs->trans("Note").'</td><td>'; 295print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_FIELD_DESCRIPTION.'">'; 296print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>'; 297print '<td class="right"> </td>'; 298print '</tr>'; 299 300// Sid 301print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldSid").'</td><td>'; 302print '<input size="25" type="text" name="fieldsid" value="'.$conf->global->LDAP_FIELD_SID.'">'; 303print '</td><td>'.$langs->trans("LDAPFieldSidExample").'</td>'; 304print '<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>"; 305print '</tr>'; 306 307// Group id 308print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupid").'</td><td>'; 309print '<input size="25" type="text" name="fieldgroupid" value="'.$conf->global->LDAP_FIELD_GROUPID.'">'; 310print '</td><td>'.$langs->trans("LDAPFieldGroupidExample").'</td>'; 311print '<td class="right"> </td>'; 312print '</tr>'; 313 314// Userid 315print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldUserid").'</td><td>'; 316print '<input size="25" type="text" name="fielduserid" value="'.$conf->global->LDAP_FIELD_USERID.'">'; 317print '</td><td>'.$langs->trans("LDAPFieldUseridExample").'</td>'; 318print '<td class="right"> </td>'; 319print '</tr>'; 320 321// Home Directory 322print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectory").'</td><td>'; 323print '<input size="25" type="text" name="fieldhomedirectory" value="'.$conf->global->LDAP_FIELD_HOMEDIRECTORY.'">'; 324print '</td><td>'.$langs->trans("LDAPFieldHomedirectoryExample").'</td>'; 325print '<td class="right"> </td>'; 326print '</tr>'; 327 328// Home Directory Prefix 329print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldHomedirectoryprefix").'</td><td>'; 330print '<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX.'">'; 331print '</td><td></td>'; 332print '<td class="right"> </td>'; 333print '</tr>'; 334 335print '</table>'; 336 337print info_admin($langs->trans("LDAPDescValues")); 338 339print dol_get_fiche_end(); 340 341print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>'; 342 343print '</form>'; 344 345 346/* 347 * Test de la connexion 348 */ 349if ($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 368if (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 495llxFooter(); 496$db->close(); 497