31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/ldap.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/ldap.lib.php';
39$langs->loadLangs(array(
'admin',
'errors'));
45$action =
GETPOST(
'action',
'aZ09');
51if ($action ==
'setvalue' && $user->admin) {
76 if (!
dolibarr_set_const($db,
'LDAP_FIELD_PASSWORD_CRYPTED',
GETPOST(
"fieldpasswordcrypted"),
'chaine', 0,
'', $conf->entity)) {
127 if (!
dolibarr_set_const($db,
'LDAP_FIELD_HOMEDIRECTORY',
GETPOST(
"fieldhomedirectory"),
'chaine', 0,
'', $conf->entity)) {
130 if (!
dolibarr_set_const($db,
'LDAP_FIELD_HOMEDIRECTORYPREFIX',
GETPOST(
"fieldhomedirectoryprefix"),
'chaine', 0,
'', $conf->entity)) {
140 if (!
dolibarr_set_const($db,
'LDAP_KEY_USERS', $valkey,
'chaine', 0,
'', $conf->entity)) {
159$form =
new Form($db);
161llxHeader(
'', $langs->trans(
"LDAPSetup"),
'EN:Module_LDAP_En|FR:Module_LDAP|ES:Módulo_LDAP');
162$linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
164print
load_fiche_titre($langs->trans(
"LDAPSetup"), $linkback,
'title_setup');
169if (!function_exists(
"ldap_connect")) {
170 setEventMessages($langs->trans(
"LDAPFunctionsNotAvailableOnPHP"),
null,
'errors');
174print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?action=setvalue&token='.newToken().
'">';
175print
'<input type="hidden" name="token" value="'.newToken().
'">';
180print
'<span class="opacitymedium">'.$langs->trans(
"LDAPDescUsers").
'</span><br>';
184print
'<table class="noborder centpercent">';
186print
'<tr class="liste_titre">';
187print
'<td colspan="4">'.$langs->trans(
"LDAPSynchronizeUsers").
'</td>';
191print
'<!-- LDAP_USER_DN -->';
192print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPUserDn").
'</span></td><td>';
193print
'<input size="48" type="text" name="user" value="'.getDolGlobalString(
'LDAP_USER_DN').
'">';
194print
'</td><td>'.$langs->trans(
"LDAPUserDnExample").
'</td>';
195print
'<td> </td>';
199print
'<!-- LDAP_USER_OBJECT_CLASS -->';
200print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPUserObjectClassList").
'</span></td><td>';
201print
'<input size="48" type="text" name="objectclass" value="'.getDolGlobalString(
'LDAP_USER_OBJECT_CLASS').
'">';
202print
'</td><td>'.$langs->trans(
"LDAPUserObjectClassListExample").
'</td>';
203print
'<td> </td>';
207print
'<!-- LDAP_FILTER_CONNECTION -->';
208print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFilterConnection").
'</td><td>';
209print
'<input size="48" type="text" name="filterconnection" value="'.getDolGlobalString(
'LDAP_FILTER_CONNECTION').
'">';
210print
'</td><td>'.$langs->trans(
"LDAPFilterConnectionExample").
'</td>';
216print
'<table class="noborder centpercent">';
218print
'<tr class="liste_titre">';
219print
'<td>'.$langs->trans(
"LDAPDolibarrMapping").
'</td>';
220print
'<td colspan="2">'.$langs->trans(
"LDAPLdapMapping").
'</td>';
221print
'<td class="right">'.$langs->trans(
"LDAPNamingAttribute").
'</td>';
225print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFullname").
'</td><td>';
226print
'<input size="25" type="text" name="fieldfullname" value="'.getDolGlobalString(
'LDAP_FIELD_FULLNAME').
'">';
227print
'</td><td>'.$langs->trans(
"LDAPFieldFullnameExample").
'</td>';
228print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FULLNAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FULLNAME') ?
' checked' :
'').
"></td>";
232print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldName").
'</td><td>';
233print
'<input size="25" type="text" name="fieldname" value="'.getDolGlobalString(
'LDAP_FIELD_NAME').
'">';
234print
'</td><td>'.$langs->trans(
"LDAPFieldNameExample").
'</td>';
235print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_NAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_NAME') ?
' checked' :
'').
"></td>";
239print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFirstName").
'</td><td>';
240print
'<input size="25" type="text" name="fieldfirstname" value="'.getDolGlobalString(
'LDAP_FIELD_FIRSTNAME').
'">';
241print
'</td><td>'.$langs->trans(
"LDAPFieldFirstNameExample").
'</td>';
242print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FIRSTNAME"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FIRSTNAME') ?
' checked' :
'').
"></td>";
246print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldLoginUnix").
'</td><td>';
247print
'<input size="25" type="text" name="fieldlogin" value="'.getDolGlobalString(
'LDAP_FIELD_LOGIN').
'">';
248print
'</td><td>'.$langs->trans(
"LDAPFieldLoginExample").
'</td>';
249print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_LOGIN') ?
' checked' :
'').
"></td>";
253print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldLoginSamba").
'</td><td>';
254print
'<input size="25" type="text" name="fieldloginsamba" value="'.getDolGlobalString(
'LDAP_FIELD_LOGIN_SAMBA').
'">';
255print
'</td><td>'.$langs->trans(
"LDAPFieldLoginSambaExample").
'</td>';
256print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_LOGIN_SAMBA"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_LOGIN_SAMBA') ?
' checked' :
'').
"></td>";
260print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPasswordNotCrypted").
'</td><td>';
261print
'<input size="25" type="text" name="fieldpassword" value="'.getDolGlobalString(
'LDAP_FIELD_PASSWORD').
'">';
262print
'</td><td>'.$langs->trans(
"LDAPFieldPasswordExample").
'</td>';
263print
'<td class="right"> </td>';
267print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPasswordCrypted").
'</td><td>';
268print
'<input size="25" type="text" name="fieldpasswordcrypted" value="'.getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED').
'">';
269print
'</td><td>'.$langs->trans(
"LDAPFieldPasswordExample").
'</td>';
270print
'<td class="right"> </td>';
274print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldMail").
'</td><td>';
275print
'<input size="25" type="text" name="fieldmail" value="'.getDolGlobalString(
'LDAP_FIELD_MAIL').
'">';
276print
'</td><td>'.$langs->trans(
"LDAPFieldMailExample").
'</td>';
277print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MAIL"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_MAIL') ?
' checked' :
'').
"></td>";
281print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldPhone").
'</td><td>';
282print
'<input size="25" type="text" name="fieldphone" value="'.getDolGlobalString(
'LDAP_FIELD_PHONE').
'">';
283print
'</td><td>'.$langs->trans(
"LDAPFieldPhoneExample").
'</td>';
284print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_PHONE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_PHONE') ?
' checked' :
'').
"></td>";
288print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldMobile").
'</td><td>';
289print
'<input size="25" type="text" name="fieldmobile" value="'.getDolGlobalString(
'LDAP_FIELD_MOBILE').
'">';
290print
'</td><td>'.$langs->trans(
"LDAPFieldMobileExample").
'</td>';
291print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_MOBILE"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_MOBILE') ?
' checked' :
'').
"></td>";
295print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldFax").
'</td><td>';
296print
'<input size="25" type="text" name="fieldfax" value="'.getDolGlobalString(
'LDAP_FIELD_FAX').
'">';
297print
'</td><td>'.$langs->trans(
"LDAPFieldFaxExample").
'</td>';
298print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_FAX"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_FAX') ?
' checked' :
'').
"></td>";
302print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldCompany").
'</td><td>';
303print
'<input size="25" type="text" name="fieldcompany" value="'.getDolGlobalString(
'LDAP_FIELD_COMPANY').
'">';
304print
'</td><td>'.$langs->trans(
"LDAPFieldCompanyExample").
'</td>';
305print
'<td class="right"> </td>';
309print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldAddress").
'</td><td>';
310print
'<input size="25" type="text" name="fieldaddress" value="'.getDolGlobalString(
'LDAP_FIELD_ADDRESS').
'">';
311print
'</td><td>'.$langs->trans(
"LDAPFieldAddressExample").
'</td>';
312print
'<td class="right"> </td>';
316print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldZip").
'</td><td>';
317print
'<input size="25" type="text" name="fieldzip" value="'.getDolGlobalString(
'LDAP_FIELD_ZIP').
'">';
318print
'</td><td>'.$langs->trans(
"LDAPFieldZipExample").
'</td>';
319print
'<td class="right"> </td>';
323print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldTown").
'</td><td>';
324print
'<input size="25" type="text" name="fieldtown" value="'.getDolGlobalString(
'LDAP_FIELD_TOWN').
'">';
325print
'</td><td>'.$langs->trans(
"LDAPFieldTownExample").
'</td>';
326print
'<td class="right"> </td>';
330print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldCountry").
'</td><td>';
331print
'<input size="25" type="text" name="fieldcountry" value="'.getDolGlobalString(
'LDAP_FIELD_COUNTRY').
'">';
332print
'</td><td> </td>';
333print
'<td class="right"> </td>';
337print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldTitle").
'</td><td>';
338print
'<input size="25" type="text" name="fieldtitle" value="'.getDolGlobalString(
'LDAP_FIELD_TITLE').
'">';
339print
'</td><td>'.$langs->trans(
"LDAPFieldTitleExample").
'</td>';
340print
'<td class="right"> </td>';
344print
'<tr class="oddeven"><td>'.$langs->trans(
"Note").
'</td><td>';
345print
'<input size="25" type="text" name="fielddescription" value="'.getDolGlobalString(
'LDAP_FIELD_DESCRIPTION').
'">';
346print
'</td><td>'.$langs->trans(
"LDAPFieldDescriptionExample").
'</td>';
347print
'<td class="right"> </td>';
351print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldSid").
'</td><td>';
352print
'<input size="25" type="text" name="fieldsid" value="'.getDolGlobalString(
'LDAP_FIELD_SID').
'">';
353print
'</td><td>'.$langs->trans(
"LDAPFieldSidExample").
'</td>';
354print
'<td class="right"><input type="radio" name="key" value="LDAP_FIELD_SID"'.(getDolGlobalString(
'LDAP_KEY_USERS') ==
getDolGlobalString(
'LDAP_FIELD_SID') ?
' checked' :
'').
"></td>";
358print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldGroupid").
'</td><td>';
359print
'<input size="25" type="text" name="fieldgroupid" value="'.getDolGlobalString(
'LDAP_FIELD_GROUPID').
'">';
360print
'</td><td>'.$langs->trans(
"LDAPFieldGroupidExample").
'</td>';
361print
'<td class="right"> </td>';
365print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldUserid").
'</td><td>';
366print
'<input size="25" type="text" name="fielduserid" value="'.getDolGlobalString(
'LDAP_FIELD_USERID').
'">';
367print
'</td><td>'.$langs->trans(
"LDAPFieldUseridExample").
'</td>';
368print
'<td class="right"> </td>';
372print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldHomedirectory").
'</td><td>';
373print
'<input size="25" type="text" name="fieldhomedirectory" value="'.getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY').
'">';
374print
'</td><td>'.$langs->trans(
"LDAPFieldHomedirectoryExample").
'</td>';
375print
'<td class="right"> </td>';
379print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldHomedirectoryprefix").
'</td><td>';
380print
'<input size="25" type="text" name="fieldhomedirectoryprefix" value="'.getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORYPREFIX').
'">';
381print
'</td><td></td>';
382print
'<td class="right"> </td>';
387print
info_admin($langs->trans(
"LDAPDescValues"));
391print $form->buttonsSaveCancel(
"Modify",
'');
400 $butlabel = $langs->trans(
"LDAPTestSynchroUser");
401 $testlabel =
'testuser';
408 $butlabel = $langs->trans(
"LDAPTestSearch");
409 $testlabel =
'testsearchuser';
416if (function_exists(
"ldap_connect")) {
417 if ($action ==
'testuser') {
419 $object =
new User($db);
420 $object->initAsSpecimen();
426 $result = $ldap->connect_bind();
429 $info = $object->_load_ldap_info();
430 $dn = $object->_load_ldap_dn($info);
432 $result1 = $ldap->delete($dn);
433 $result2 = $ldap->add($dn, $info, $user);
434 $result3 = $ldap->delete($dn);
438 print
'<span class="ok">'.$langs->trans(
"LDAPSynchroOK").
'</span><br>';
441 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKOMayBePermissions");
442 print
': '.$ldap->error;
444 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
448 print
"LDAP input file used for test:<br><br>\n";
449 print nl2br($ldap->dump_content($dn, $info));
453 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
454 print
': '.$ldap->error;
456 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
460 if ($action ==
'testsearchuser') {
462 $object =
new User($db);
463 $object->initAsSpecimen();
469 $result = $ldap->connect_bind();
472 $required_fields = array(
492 $required_fields = array_unique(array_values(array_filter($required_fields,
"dol_validElement")));
498 if (is_array($ldapusers)) {
500 foreach ($ldapusers as $key => $ldapuser) {
503 foreach ($required_fields as $value) {
505 $label .= $value.
"=".$ldapuser[$value].
" ";
508 $liste[$key] = $label;
515 print
"LDAP search for user:<br>\n";
516 print
"search: *<br>\n";
517 print
"userDN: ".getDolGlobalString(
'LDAP_USER_DN').
"<br>\n";
518 print
"useridentifier: ".getDolGlobalString(
'LDAP_KEY_USERS').
"<br>\n";
519 print
"requested fields: ".implode(
',', $required_fields).
"<br>\n";
520 print
"=> ".count($liste).
" records<br>\n";
524 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
525 print
': '.$ldap->error;
527 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.
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='', $dragdropfile=0)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.