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'));
43 $action =
GETPOST(
'action',
'aZ09');
49 if ($action ==
'setvalue' && $user->admin)
56 if (!
dolibarr_set_const($db,
'LDAP_FILTER_CONNECTION',
GETPOST(
"filterconnection"),
'chaine', 0,
'', $conf->entity)) $error++;
59 if (!
dolibarr_set_const($db,
'LDAP_FIELD_LOGIN_SAMBA',
GETPOST(
"fieldloginsamba"),
'chaine', 0,
'', $conf->entity)) $error++;
61 if (!
dolibarr_set_const($db,
'LDAP_FIELD_PASSWORD_CRYPTED',
GETPOST(
"fieldpasswordcrypted"),
'chaine', 0,
'', $conf->entity)) $error++;
63 if (!
dolibarr_set_const($db,
'LDAP_FIELD_FIRSTNAME',
GETPOST(
"fieldfirstname"),
'chaine', 0,
'', $conf->entity)) $error++;
74 if (!
dolibarr_set_const($db,
'LDAP_FIELD_DESCRIPTION',
GETPOST(
"fielddescription"),
'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++;
85 if ($key) $valkey = $conf->global->$key;
86 if (!
dolibarr_set_const($db,
'LDAP_KEY_USERS', $valkey,
'chaine', 0,
'', $conf->entity)) $error++;
104 $form =
new Form($db);
106 llxHeader(
'', $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>';
114 if (!function_exists(
"ldap_connect"))
116 setEventMessages($langs->trans(
"LDAPFunctionsNotAvailableOnPHP"), null,
'errors');
120 print '<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?action=setvalue">';
121 print '<input type="hidden" name="token" value="'.newToken().
'">';
126 print $langs->trans(
"LDAPDescUsers").
'<br>';
130 print '<table class="noborder centpercent">';
132 print '<tr class="liste_titre">';
133 print '<td colspan="4">'.$langs->trans(
"LDAPSynchronizeUsers").
'</td>';
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> </td>';
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> </td>';
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>';
159 print '<table class="noborder centpercent">';
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>';
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>";
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>";
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>";
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>";
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>";
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"> </td>';
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"> </td>';
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>";
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>";
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>";
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>";
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>";
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"> </td>';
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"> </td>';
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"> </td>';
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"> </td>';
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> </td>';
283 print '<td class="right"> </td>';
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"> </td>';
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"> </td>';
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>";
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"> </td>';
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"> </td>';
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"> </td>';
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"> </td>';
341 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans(
"Modify").
'"></div>';
349 if ($conf->global->LDAP_SYNCHRO_ACTIVE ==
'dolibarr2ldap')
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;
358 } elseif ($conf->global->LDAP_SYNCHRO_ACTIVE ==
'ldap2dolibarr')
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;
368 if (function_exists(
"ldap_connect"))
370 if ($action ==
'testuser')
373 $object =
new User($db);
374 $object->initAsSpecimen();
380 $result = $ldap->connect_bind();
384 $info = $object->_load_ldap_info();
385 $dn = $object->_load_ldap_dn($info);
387 $result1 = $ldap->delete($dn);
388 $result2 = $ldap->add($dn, $info, $user);
389 $result3 = $ldap->delete($dn);
394 print '<font class="ok">'.$langs->trans(
"LDAPSynchroOK").
'</font><br>';
397 print '<font class="error">'.$langs->trans(
"LDAPSynchroKOMayBePermissions");
398 print ': '.$ldap->error;
400 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
404 print "LDAP input file used for test:<br><br>\n";
405 print nl2br($ldap->dump_content($dn, $info));
409 print '<font class="error">'.$langs->trans(
"LDAPSynchroKO");
410 print ': '.$ldap->error;
412 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
416 if ($action ==
'testsearchuser')
419 $object =
new User($db);
420 $object->initAsSpecimen();
426 $result = $ldap->connect_bind();
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
450 $required_fields = array_unique(array_values(array_filter($required_fields,
"dol_validElement")));
453 $ldapusers = $ldap->getRecords(
'*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
456 if (is_array($ldapusers))
459 foreach ($ldapusers as $key => $ldapuser)
463 foreach ($required_fields as $value)
467 $label .= $value.
"=".$ldapuser[$value].
" ";
470 $liste[$key] = $label;
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";
486 print '<font class="error">'.$langs->trans(
"LDAPSynchroKO");
487 print ': '.$ldap->error;
489 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
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).
Class to manage Dolibarr users.
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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'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.
print
Draft customers invoices.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.