31 require
'../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/ldap.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ldap.lib.php';
39 $langs->loadLangs(array(
'admin',
'errors'));
45 $action =
GETPOST(
'action',
'aZ09');
51 if ($action ==
'setvalue' && $user->admin) {
76 if (!
dolibarr_set_const($db,
'LDAP_FIELD_PASSWORD_CRYPTED',
GETPOST(
"fieldpasswordcrypted"),
'chaine', 0,
'', $conf->entity)) {
130 if (!
dolibarr_set_const($db,
'LDAP_FIELD_HOMEDIRECTORY',
GETPOST(
"fieldhomedirectory"),
'chaine', 0,
'', $conf->entity)) {
133 if (!
dolibarr_set_const($db,
'LDAP_FIELD_HOMEDIRECTORYPREFIX',
GETPOST(
"fieldhomedirectoryprefix"),
'chaine', 0,
'', $conf->entity)) {
141 $valkey = $conf->global->$key;
143 if (!
dolibarr_set_const($db,
'LDAP_KEY_USERS', $valkey,
'chaine', 0,
'', $conf->entity)) {
164 llxHeader(
'', $langs->trans(
"LDAPSetup"),
'EN:Module_LDAP_En|FR:Module_LDAP|ES:Módulo_LDAP');
165 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
167 print
load_fiche_titre($langs->trans(
"LDAPSetup"), $linkback,
'title_setup');
172 if (!function_exists(
"ldap_connect")) {
173 setEventMessages($langs->trans(
"LDAPFunctionsNotAvailableOnPHP"),
null,
'errors');
177 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?action=setvalue&token='.
newToken().
'">';
178 print
'<input type="hidden" name="token" value="'.newToken().
'">';
183 print
'<span class="opacitymedium">'.$langs->trans(
"LDAPDescUsers").
'</span><br>';
187 print
'<table class="noborder centpercent">';
189 print
'<tr class="liste_titre">';
190 print
'<td colspan="4">'.$langs->trans(
"LDAPSynchronizeUsers").
'</td>';
194 print
'<!-- LDAP_USER_DN -->';
195 print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPUserDn").
'</span></td><td>';
196 print
'<input size="48" type="text" name="user" value="'.getDolGlobalString(
'LDAP_USER_DN').
'">';
197 print
'</td><td>'.$langs->trans(
"LDAPUserDnExample").
'</td>';
198 print
'<td> </td>';
202 print
'<!-- LDAP_USER_OBJECT_CLASS -->';
203 print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPUserObjectClassList").
'</span></td><td>';
204 print
'<input size="48" type="text" name="objectclass" value="'.getDolGlobalString(
'LDAP_USER_OBJECT_CLASS').
'">';
205 print
'</td><td>'.$langs->trans(
"LDAPUserObjectClassListExample").
'</td>';
206 print
'<td> </td>';
210 print
'<!-- LDAP_FILTER_CONNECTION -->';
211 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFilterConnection").
'</td><td>';
212 print
'<input size="48" type="text" name="filterconnection" value="'.getDolGlobalString(
'LDAP_FILTER_CONNECTION').
'">';
213 print
'</td><td>'.$langs->trans(
"LDAPFilterConnectionExample").
'</td>';
219 print
'<table class="noborder centpercent">';
221 print
'<tr class="liste_titre">';
222 print
'<td>'.$langs->trans(
"LDAPDolibarrMapping").
'</td>';
223 print
'<td colspan="2">'.$langs->trans(
"LDAPLdapMapping").
'</td>';
224 print
'<td class="right">'.$langs->trans(
"LDAPNamingAttribute").
'</td>';
228 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFullname").
'</td><td>';
229 print
'<input size="25" type="text" name="fieldfullname" value="'.getDolGlobalString(
'LDAP_FIELD_FULLNAME').
'">';
230 print
'</td><td>'.$langs->trans(
"LDAPFieldFullnameExample").
'</td>';
231 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FULLNAME') ?
' checked' :
'').
"></td>";
235 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldName").
'</td><td>';
236 print
'<input size="25" type="text" name="fieldname" value="'.getDolGlobalString(
'LDAP_FIELD_NAME').
'">';
237 print
'</td><td>'.$langs->trans(
"LDAPFieldNameExample").
'</td>';
238 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_NAME') ?
' checked' :
'').
"></td>";
242 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFirstName").
'</td><td>';
243 print
'<input size="25" type="text" name="fieldfirstname" value="'.getDolGlobalString(
'LDAP_FIELD_FIRSTNAME').
'">';
244 print
'</td><td>'.$langs->trans(
"LDAPFieldFirstNameExample").
'</td>';
245 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FIRSTNAME') ?
' checked' :
'').
"></td>";
249 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldLoginUnix").
'</td><td>';
250 print
'<input size="25" type="text" name="fieldlogin" value="'.getDolGlobalString(
'LDAP_FIELD_LOGIN').
'">';
251 print
'</td><td>'.$langs->trans(
"LDAPFieldLoginExample").
'</td>';
252 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_LOGIN') ?
' checked' :
'').
"></td>";
256 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldLoginSamba").
'</td><td>';
257 print
'<input size="25" type="text" name="fieldloginsamba" value="'.getDolGlobalString(
'LDAP_FIELD_LOGIN_SAMBA').
'">';
258 print
'</td><td>'.$langs->trans(
"LDAPFieldLoginSambaExample").
'</td>';
259 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>";
263 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPasswordNotCrypted").
'</td><td>';
264 print
'<input size="25" type="text" name="fieldpassword" value="'.getDolGlobalString(
'LDAP_FIELD_PASSWORD').
'">';
265 print
'</td><td>'.$langs->trans(
"LDAPFieldPasswordExample").
'</td>';
266 print
'<td class="right"> </td>';
270 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPasswordCrypted").
'</td><td>';
271 print
'<input size="25" type="text" name="fieldpasswordcrypted" value="'.getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED').
'">';
272 print
'</td><td>'.$langs->trans(
"LDAPFieldPasswordExample").
'</td>';
273 print
'<td class="right"> </td>';
277 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldMail").
'</td><td>';
278 print
'<input size="25" type="text" name="fieldmail" value="'.getDolGlobalString(
'LDAP_FIELD_MAIL').
'">';
279 print
'</td><td>'.$langs->trans(
"LDAPFieldMailExample").
'</td>';
280 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_MAIL') ?
' checked' :
'').
"></td>";
284 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPhone").
'</td><td>';
285 print
'<input size="25" type="text" name="fieldphone" value="'.getDolGlobalString(
'LDAP_FIELD_PHONE').
'">';
286 print
'</td><td>'.$langs->trans(
"LDAPFieldPhoneExample").
'</td>';
287 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_PHONE') ?
' checked' :
'').
"></td>";
291 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldMobile").
'</td><td>';
292 print
'<input size="25" type="text" name="fieldmobile" value="'.getDolGlobalString(
'LDAP_FIELD_MOBILE').
'">';
293 print
'</td><td>'.$langs->trans(
"LDAPFieldMobileExample").
'</td>';
294 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_MOBILE') ?
' checked' :
'').
"></td>";
298 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldSkype").
'</td><td>';
299 print
'<input size="25" type="text" name="fieldskype" value="'.getDolGlobalString(
'LDAP_FIELD_SKYPE').
'">';
300 print
'</td><td>'.$langs->trans(
"LDAPFieldSkypeExample").
'</td>';
301 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SKYPE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_SKYPE') ?
' checked' :
'').
"></td>";
305 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFax").
'</td><td>';
306 print
'<input size="25" type="text" name="fieldfax" value="'.getDolGlobalString(
'LDAP_FIELD_FAX').
'">';
307 print
'</td><td>'.$langs->trans(
"LDAPFieldFaxExample").
'</td>';
308 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FAX') ?
' checked' :
'').
"></td>";
312 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldCompany").
'</td><td>';
313 print
'<input size="25" type="text" name="fieldcompany" value="'.getDolGlobalString(
'LDAP_FIELD_COMPANY').
'">';
314 print
'</td><td>'.$langs->trans(
"LDAPFieldCompanyExample").
'</td>';
315 print
'<td class="right"> </td>';
319 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldAddress").
'</td><td>';
320 print
'<input size="25" type="text" name="fieldaddress" value="'.getDolGlobalString(
'LDAP_FIELD_ADDRESS').
'">';
321 print
'</td><td>'.$langs->trans(
"LDAPFieldAddressExample").
'</td>';
322 print
'<td class="right"> </td>';
326 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldZip").
'</td><td>';
327 print
'<input size="25" type="text" name="fieldzip" value="'.getDolGlobalString(
'LDAP_FIELD_ZIP').
'">';
328 print
'</td><td>'.$langs->trans(
"LDAPFieldZipExample").
'</td>';
329 print
'<td class="right"> </td>';
333 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldTown").
'</td><td>';
334 print
'<input size="25" type="text" name="fieldtown" value="'.getDolGlobalString(
'LDAP_FIELD_TOWN').
'">';
335 print
'</td><td>'.$langs->trans(
"LDAPFieldTownExample").
'</td>';
336 print
'<td class="right"> </td>';
340 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldCountry").
'</td><td>';
341 print
'<input size="25" type="text" name="fieldcountry" value="'.getDolGlobalString(
'LDAP_FIELD_COUNTRY').
'">';
342 print
'</td><td> </td>';
343 print
'<td class="right"> </td>';
347 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldTitle").
'</td><td>';
348 print
'<input size="25" type="text" name="fieldtitle" value="'.getDolGlobalString(
'LDAP_FIELD_TITLE').
'">';
349 print
'</td><td>'.$langs->trans(
"LDAPFieldTitleExample").
'</td>';
350 print
'<td class="right"> </td>';
354 print
'<tr class="oddeven"><td>'.$langs->trans(
"Note").
'</td><td>';
355 print
'<input size="25" type="text" name="fielddescription" value="'.getDolGlobalString(
'LDAP_FIELD_DESCRIPTION').
'">';
356 print
'</td><td>'.$langs->trans(
"LDAPFieldDescriptionExample").
'</td>';
357 print
'<td class="right"> </td>';
361 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldSid").
'</td><td>';
362 print
'<input size="25" type="text" name="fieldsid" value="'.getDolGlobalString(
'LDAP_FIELD_SID').
'">';
363 print
'</td><td>'.$langs->trans(
"LDAPFieldSidExample").
'</td>';
364 print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_SID') ?
' checked' :
'').
"></td>";
368 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldGroupid").
'</td><td>';
369 print
'<input size="25" type="text" name="fieldgroupid" value="'.getDolGlobalString(
'LDAP_FIELD_GROUPID').
'">';
370 print
'</td><td>'.$langs->trans(
"LDAPFieldGroupidExample").
'</td>';
371 print
'<td class="right"> </td>';
375 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldUserid").
'</td><td>';
376 print
'<input size="25" type="text" name="fielduserid" value="'.getDolGlobalString(
'LDAP_FIELD_USERID').
'">';
377 print
'</td><td>'.$langs->trans(
"LDAPFieldUseridExample").
'</td>';
378 print
'<td class="right"> </td>';
382 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldHomedirectory").
'</td><td>';
383 print
'<input size="25" type="text" name="fieldhomedirectory" value="'.getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY').
'">';
384 print
'</td><td>'.$langs->trans(
"LDAPFieldHomedirectoryExample").
'</td>';
385 print
'<td class="right"> </td>';
389 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldHomedirectoryprefix").
'</td><td>';
390 print
'<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORYPREFIX').
'">';
391 print
'</td><td></td>';
392 print
'<td class="right"> </td>';
397 print
info_admin($langs->trans(
"LDAPDescValues"));
401 print
$form->buttonsSaveCancel(
"Modify",
'');
410 $butlabel = $langs->trans(
"LDAPTestSynchroUser");
411 $testlabel =
'testuser';
418 $butlabel = $langs->trans(
"LDAPTestSearch");
419 $testlabel =
'testsearchuser';
426 if (function_exists(
"ldap_connect")) {
427 if ($action ==
'testuser') {
429 $object =
new User($db);
430 $object->initAsSpecimen();
436 $result = $ldap->connect_bind();
439 $info = $object->_load_ldap_info();
440 $dn = $object->_load_ldap_dn($info);
442 $result1 = $ldap->delete($dn);
443 $result2 = $ldap->add($dn, $info, $user);
444 $result3 = $ldap->delete($dn);
448 print
'<span class="ok">'.$langs->trans(
"LDAPSynchroOK").
'</span><br>';
451 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKOMayBePermissions");
452 print
': '.$ldap->error;
454 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
458 print
"LDAP input file used for test:<br><br>\n";
459 print nl2br($ldap->dump_content($dn, $info));
463 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
464 print
': '.$ldap->error;
466 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
470 if ($action ==
'testsearchuser') {
472 $object =
new User($db);
473 $object->initAsSpecimen();
479 $result = $ldap->connect_bind();
482 $required_fields = array(
502 $required_fields = array_unique(array_values(array_filter($required_fields,
"dol_validElement")));
508 if (is_array($ldapusers)) {
510 foreach ($ldapusers as $key => $ldapuser) {
513 foreach ($required_fields as $value) {
515 $label .= $value.
"=".$ldapuser[$value].
" ";
518 $liste[$key] = $label;
525 print
"LDAP search for user:<br>\n";
526 print
"search: *<br>\n";
527 print
"userDN: ".getDolGlobalString(
'LDAP_USER_DN').
"<br>\n";
528 print
"useridentifier: ".getDolGlobalString(
'LDAP_KEY_USERS').
"<br>\n";
529 print
"requested fields: ".implode(
',', $required_fields).
"<br>\n";
530 print
"=> ".count($liste).
" records<br>\n";
534 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
535 print
': '.$ldap->error;
537 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
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).
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage LDAP features.
const SYNCHRO_LDAP_TO_DOLIBARR
Ldap to Dolibarr synchronization.
const SYNCHRO_DOLIBARR_TO_LDAP
Dolibarr to Ldap synchronization.
Class to manage Dolibarr users.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.