Go to the documentation of this file.
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';
38 $langs->loadLangs(array(
'admin',
'errors'));
44 $action =
GETPOST(
'action',
'aZ09');
50 if ($action ==
'setvalue' && $user->admin) {
75 if (!
dolibarr_set_const($db,
'LDAP_FIELD_PASSWORD_CRYPTED',
GETPOST(
"fieldpasswordcrypted"),
'chaine', 0,
'', $conf->entity)) {
129 if (!
dolibarr_set_const($db,
'LDAP_FIELD_HOMEDIRECTORY',
GETPOST(
"fieldhomedirectory"),
'chaine', 0,
'', $conf->entity)) {
132 if (!
dolibarr_set_const($db,
'LDAP_FIELD_HOMEDIRECTORYPREFIX',
GETPOST(
"fieldhomedirectoryprefix"),
'chaine', 0,
'', $conf->entity)) {
140 $valkey = $conf->global->$key;
142 if (!
dolibarr_set_const($db,
'LDAP_KEY_USERS', $valkey,
'chaine', 0,
'', $conf->entity)) {
163 llxHeader(
'', $langs->trans(
"LDAPSetup"),
'EN:Module_LDAP_En|FR:Module_LDAP|ES:Módulo_LDAP');
164 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
166 print
load_fiche_titre($langs->trans(
"LDAPSetup"), $linkback,
'title_setup');
171 if (!function_exists(
"ldap_connect")) {
172 setEventMessages($langs->trans(
"LDAPFunctionsNotAvailableOnPHP"),
null,
'errors');
176 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?action=setvalue&token='.
newToken().
'">';
177 print
'<input type="hidden" name="token" value="'.newToken().
'">';
182 print
'<span class="opacitymedium">'.$langs->trans(
"LDAPDescUsers").
'</span><br>';
186 print
'<table class="noborder centpercent">';
188 print
'<tr class="liste_titre">';
189 print
'<td colspan="4">'.$langs->trans(
"LDAPSynchronizeUsers").
'</td>';
193 print
'<!-- LDAP_USER_DN -->';
194 print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPUserDn").
'</span></td><td>';
195 print
'<input size="48" type="text" name="user" value="'.getDolGlobalString(
'LDAP_USER_DN').
'">';
196 print
'</td><td>'.$langs->trans(
"LDAPUserDnExample").
'</td>';
197 print
'<td> </td>';
201 print
'<!-- LDAP_USER_OBJECT_CLASS -->';
202 print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPUserObjectClassList").
'</span></td><td>';
203 print
'<input size="48" type="text" name="objectclass" value="'.getDolGlobalString(
'LDAP_USER_OBJECT_CLASS').
'">';
204 print
'</td><td>'.$langs->trans(
"LDAPUserObjectClassListExample").
'</td>';
205 print
'<td> </td>';
209 print
'<!-- LDAP_FILTER_CONNECTION -->';
210 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFilterConnection").
'</td><td>';
211 print
'<input size="48" type="text" name="filterconnection" value="'.getDolGlobalString(
'LDAP_FILTER_CONNECTION').
'">';
212 print
'</td><td>'.$langs->trans(
"LDAPFilterConnectionExample").
'</td>';
218 print
'<table class="noborder centpercent">';
220 print
'<tr class="liste_titre">';
221 print
'<td>'.$langs->trans(
"LDAPDolibarrMapping").
'</td>';
222 print
'<td colspan="2">'.$langs->trans(
"LDAPLdapMapping").
'</td>';
223 print
'<td class="right">'.$langs->trans(
"LDAPNamingAttribute").
'</td>';
227 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFullname").
'</td><td>';
228 print
'<input size="25" type="text" name="fieldfullname" value="'.getDolGlobalString(
'LDAP_FIELD_FULLNAME').
'">';
229 print
'</td><td>'.$langs->trans(
"LDAPFieldFullnameExample").
'</td>';
230 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FULLNAME') ?
' checked' :
'').
"></td>";
234 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldName").
'</td><td>';
235 print
'<input size="25" type="text" name="fieldname" value="'.getDolGlobalString(
'LDAP_FIELD_NAME').
'">';
236 print
'</td><td>'.$langs->trans(
"LDAPFieldNameExample").
'</td>';
237 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_NAME') ?
' checked' :
'').
"></td>";
241 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFirstName").
'</td><td>';
242 print
'<input size="25" type="text" name="fieldfirstname" value="'.getDolGlobalString(
'LDAP_FIELD_FIRSTNAME').
'">';
243 print
'</td><td>'.$langs->trans(
"LDAPFieldFirstNameExample").
'</td>';
244 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FIRSTNAME') ?
' checked' :
'').
"></td>";
248 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldLoginUnix").
'</td><td>';
249 print
'<input size="25" type="text" name="fieldlogin" value="'.getDolGlobalString(
'LDAP_FIELD_LOGIN').
'">';
250 print
'</td><td>'.$langs->trans(
"LDAPFieldLoginExample").
'</td>';
251 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_LOGIN') ?
' checked' :
'').
"></td>";
255 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldLoginSamba").
'</td><td>';
256 print
'<input size="25" type="text" name="fieldloginsamba" value="'.getDolGlobalString(
'LDAP_FIELD_LOGIN_SAMBA').
'">';
257 print
'</td><td>'.$langs->trans(
"LDAPFieldLoginSambaExample").
'</td>';
258 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_LOGIN_SAMBA') ?
' checked' :
'').
"></td>";
262 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPasswordNotCrypted").
'</td><td>';
263 print
'<input size="25" type="text" name="fieldpassword" value="'.getDolGlobalString(
'LDAP_FIELD_PASSWORD').
'">';
264 print
'</td><td>'.$langs->trans(
"LDAPFieldPasswordExample").
'</td>';
265 print
'<td class="right"> </td>';
269 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPasswordCrypted").
'</td><td>';
270 print
'<input size="25" type="text" name="fieldpasswordcrypted" value="'.getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED').
'">';
271 print
'</td><td>'.$langs->trans(
"LDAPFieldPasswordExample").
'</td>';
272 print
'<td class="right"> </td>';
276 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldMail").
'</td><td>';
277 print
'<input size="25" type="text" name="fieldmail" value="'.getDolGlobalString(
'LDAP_FIELD_MAIL').
'">';
278 print
'</td><td>'.$langs->trans(
"LDAPFieldMailExample").
'</td>';
279 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_MAIL') ?
' checked' :
'').
"></td>";
283 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPhone").
'</td><td>';
284 print
'<input size="25" type="text" name="fieldphone" value="'.getDolGlobalString(
'LDAP_FIELD_PHONE').
'">';
285 print
'</td><td>'.$langs->trans(
"LDAPFieldPhoneExample").
'</td>';
286 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_PHONE') ?
' checked' :
'').
"></td>";
290 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldMobile").
'</td><td>';
291 print
'<input size="25" type="text" name="fieldmobile" value="'.getDolGlobalString(
'LDAP_FIELD_MOBILE').
'">';
292 print
'</td><td>'.$langs->trans(
"LDAPFieldMobileExample").
'</td>';
293 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_MOBILE') ?
' checked' :
'').
"></td>";
297 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldSkype").
'</td><td>';
298 print
'<input size="25" type="text" name="fieldskype" value="'.getDolGlobalString(
'LDAP_FIELD_SKYPE').
'">';
299 print
'</td><td>'.$langs->trans(
"LDAPFieldSkypeExample").
'</td>';
300 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SKYPE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_SKYPE') ?
' checked' :
'').
"></td>";
304 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFax").
'</td><td>';
305 print
'<input size="25" type="text" name="fieldfax" value="'.getDolGlobalString(
'LDAP_FIELD_FAX').
'">';
306 print
'</td><td>'.$langs->trans(
"LDAPFieldFaxExample").
'</td>';
307 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FAX') ?
' checked' :
'').
"></td>";
311 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldCompany").
'</td><td>';
312 print
'<input size="25" type="text" name="fieldcompany" value="'.getDolGlobalString(
'LDAP_FIELD_COMPANY').
'">';
313 print
'</td><td>'.$langs->trans(
"LDAPFieldCompanyExample").
'</td>';
314 print
'<td class="right"> </td>';
318 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldAddress").
'</td><td>';
319 print
'<input size="25" type="text" name="fieldaddress" value="'.getDolGlobalString(
'LDAP_FIELD_ADDRESS').
'">';
320 print
'</td><td>'.$langs->trans(
"LDAPFieldAddressExample").
'</td>';
321 print
'<td class="right"> </td>';
325 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldZip").
'</td><td>';
326 print
'<input size="25" type="text" name="fieldzip" value="'.getDolGlobalString(
'LDAP_FIELD_ZIP').
'">';
327 print
'</td><td>'.$langs->trans(
"LDAPFieldZipExample").
'</td>';
328 print
'<td class="right"> </td>';
332 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldTown").
'</td><td>';
333 print
'<input size="25" type="text" name="fieldtown" value="'.getDolGlobalString(
'LDAP_FIELD_TOWN').
'">';
334 print
'</td><td>'.$langs->trans(
"LDAPFieldTownExample").
'</td>';
335 print
'<td class="right"> </td>';
339 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldCountry").
'</td><td>';
340 print
'<input size="25" type="text" name="fieldcountry" value="'.getDolGlobalString(
'LDAP_FIELD_COUNTRY').
'">';
341 print
'</td><td> </td>';
342 print
'<td class="right"> </td>';
346 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldTitle").
'</td><td>';
347 print
'<input size="25" type="text" name="fieldtitle" value="'.getDolGlobalString(
'LDAP_FIELD_TITLE').
'">';
348 print
'</td><td>'.$langs->trans(
"LDAPFieldTitleExample").
'</td>';
349 print
'<td class="right"> </td>';
353 print
'<tr class="oddeven"><td>'.$langs->trans(
"Note").
'</td><td>';
354 print
'<input size="25" type="text" name="fielddescription" value="'.getDolGlobalString(
'LDAP_FIELD_DESCRIPTION').
'">';
355 print
'</td><td>'.$langs->trans(
"LDAPFieldDescriptionExample").
'</td>';
356 print
'<td class="right"> </td>';
360 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldSid").
'</td><td>';
361 print
'<input size="25" type="text" name="fieldsid" value="'.getDolGlobalString(
'LDAP_FIELD_SID').
'">';
362 print
'</td><td>'.$langs->trans(
"LDAPFieldSidExample").
'</td>';
363 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_SID') ?
' checked' :
'').
"></td>";
367 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldGroupid").
'</td><td>';
368 print
'<input size="25" type="text" name="fieldgroupid" value="'.getDolGlobalString(
'LDAP_FIELD_GROUPID').
'">';
369 print
'</td><td>'.$langs->trans(
"LDAPFieldGroupidExample").
'</td>';
370 print
'<td class="right"> </td>';
374 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldUserid").
'</td><td>';
375 print
'<input size="25" type="text" name="fielduserid" value="'.getDolGlobalString(
'LDAP_FIELD_USERID').
'">';
376 print
'</td><td>'.$langs->trans(
"LDAPFieldUseridExample").
'</td>';
377 print
'<td class="right"> </td>';
381 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldHomedirectory").
'</td><td>';
382 print
'<input size="25" type="text" name="fieldhomedirectory" value="'.getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY').
'">';
383 print
'</td><td>'.$langs->trans(
"LDAPFieldHomedirectoryExample").
'</td>';
384 print
'<td class="right"> </td>';
388 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldHomedirectoryprefix").
'</td><td>';
389 print
'<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORYPREFIX').
'">';
390 print
'</td><td></td>';
391 print
'<td class="right"> </td>';
396 print
info_admin($langs->trans(
"LDAPDescValues"));
400 print
$form->buttonsSaveCancel(
"Modify",
'');
409 $butlabel = $langs->trans(
"LDAPTestSynchroUser");
410 $testlabel =
'testuser';
417 $butlabel = $langs->trans(
"LDAPTestSearch");
418 $testlabel =
'testsearchuser';
425 if (function_exists(
"ldap_connect")) {
426 if ($action ==
'testuser') {
428 $object =
new User($db);
429 $object->initAsSpecimen();
435 $result = $ldap->connect_bind();
438 $info = $object->_load_ldap_info();
439 $dn = $object->_load_ldap_dn($info);
441 $result1 = $ldap->delete($dn);
442 $result2 = $ldap->add($dn, $info, $user);
443 $result3 = $ldap->delete($dn);
447 print
'<span class="ok">'.$langs->trans(
"LDAPSynchroOK").
'</span><br>';
450 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKOMayBePermissions");
451 print
': '.$ldap->error;
453 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
457 print
"LDAP input file used for test:<br><br>\n";
458 print nl2br($ldap->dump_content($dn, $info));
462 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
463 print
': '.$ldap->error;
465 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
469 if ($action ==
'testsearchuser') {
471 $object =
new User($db);
472 $object->initAsSpecimen();
478 $result = $ldap->connect_bind();
481 $required_fields = array(
501 $required_fields = array_unique(array_values(array_filter($required_fields,
"dol_validElement")));
507 if (is_array($ldapusers)) {
509 foreach ($ldapusers as $key => $ldapuser) {
512 foreach ($required_fields as $value) {
514 $label .= $value.
"=".$ldapuser[$value].
" ";
517 $liste[$key] = $label;
524 print
"LDAP search for user:<br>\n";
525 print
"search: *<br>\n";
526 print
"userDN: ".getDolGlobalString(
'LDAP_USER_DN').
"<br>\n";
527 print
"useridentifier: ".getDolGlobalString(
'LDAP_KEY_USERS').
"<br>\n";
528 print
"required_fields: ".implode(
',', $required_fields).
"<br>\n";
529 print
"=> ".count($liste).
" records<br>\n";
533 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
534 print
': '.$ldap->error;
536 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
Class to manage LDAP features.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
const SYNCHRO_DOLIBARR_TO_LDAP
Dolibarr to Ldap synchronization.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $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='')
Show tabs of a record.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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).
Class to manage Dolibarr users.
const SYNCHRO_LDAP_TO_DOLIBARR
Ldap to Dolibarr synchronization.
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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 ...
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.