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');
51 if ($action ==
'setvalue' && $user->admin) {
58 if (!
dolibarr_set_const($db,
'LDAP_GROUP_OBJECT_CLASS',
GETPOST(
"objectclass",
'alphanohtml'),
'chaine', 0,
'', $conf->entity)) {
64 if (!
dolibarr_set_const($db,
'LDAP_GROUP_FIELD_FULLNAME',
GETPOST(
"fieldfullname",
'alphanohtml'),
'chaine', 0,
'', $conf->entity)) {
68 if (!
dolibarr_set_const($db,
'LDAP_GROUP_FIELD_DESCRIPTION',
GETPOST(
"fielddescription",
'alphanohtml'),
'chaine', 0,
'', $conf->entity)) {
71 if (!
dolibarr_set_const($db,
'LDAP_GROUP_FIELD_GROUPMEMBERS',
GETPOST(
"fieldgroupmembers",
'alphanohtml'),
'chaine', 0,
'', $conf->entity)) {
74 if (!
dolibarr_set_const($db,
'LDAP_GROUP_FIELD_GROUPID',
GETPOST(
"fieldgroupid",
'alphanohtml'),
'chaine', 0,
'', $conf->entity)) {
82 $valkey = $conf->global->$key;
84 if (!
dolibarr_set_const($db,
'LDAP_KEY_GROUPS', $valkey,
'chaine', 0,
'', $conf->entity)) {
105 llxHeader(
'', $langs->trans(
"LDAPSetup"),
'EN:Module_LDAP_En|FR:Module_LDAP|ES:Módulo_LDAP');
106 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
108 print
load_fiche_titre($langs->trans(
"LDAPSetup"), $linkback,
'title_setup');
113 if (!function_exists(
"ldap_connect")) {
114 setEventMessages($langs->trans(
"LDAPFunctionsNotAvailableOnPHP"),
null,
'errors');
120 print
'<span class="opacitymedium">'.$langs->trans(
"LDAPDescGroups").
'</span><br>';
124 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'?action=setvalue&token='.
newToken().
'">';
125 print
'<input type="hidden" name="token" value="'.newToken().
'">';
127 print
'<table class="noborder centpercent">';
129 print
'<tr class="liste_titre">';
130 print
'<td colspan="4">'.$langs->trans(
"LDAPSynchronizeGroups").
'</td>';
134 print
'<!-- LDAP_GROUP_DN -->';
135 print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPGroupDn").
'</span></td><td>';
136 print
'<input size="48" type="text" name="group" value="'.$conf->global->LDAP_GROUP_DN.
'">';
137 print
'</td><td>'.$langs->trans(
"LDAPGroupDnExample").
'</td>';
138 print
'<td> </td>';
142 print
'<!-- LDAP_GROUP_OBJECT_CLASS -->';
143 print
'<tr class="oddeven"><td><span class="fieldrequired">'.$langs->trans(
"LDAPGroupObjectClassList").
'</span></td><td>';
144 print
'<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_GROUP_OBJECT_CLASS.
'">';
145 print
'</td><td>'.$langs->trans(
"LDAPGroupObjectClassListExample").
'</td>';
146 print
'<td> </td>';
150 print
'<!-- LDAP_GROUP_FILTER -->';
151 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFilterConnection").
'</td><td>';
152 print
'<input size="48" type="text" name="filter" value="'.$conf->global->LDAP_GROUP_FILTER.
'">';
153 print
'</td><td>'.$langs->trans(
"LDAPGroupFilterExample").
'</td>';
161 print
'<table class="noborder centpercent">';
163 print
'<tr class="liste_titre">';
164 print
'<td>'.$langs->trans(
"LDAPDolibarrMapping").
'</td>';
165 print
'<td colspan="2">'.$langs->trans(
"LDAPLdapMapping").
'</td>';
166 print
'<td class="right">'.$langs->trans(
"LDAPNamingAttribute").
'</td>';
172 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldName").
'</td><td>';
173 print
'<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_GROUP_FIELD_FULLNAME.
'">';
174 print
'</td><td>'.$langs->trans(
"LDAPFieldCommonNameExample").
'</td>';
175 print
'<td class="right"><input type="radio" name="key" value="LDAP_GROUP_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_GROUPS && $conf->global->LDAP_KEY_GROUPS == $conf->global->LDAP_GROUP_FIELD_FULLNAME) ?
' checked' :
'').
"></td>";
188 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldDescription").
'</td><td>';
189 print
'<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_GROUP_FIELD_DESCRIPTION.
'">';
190 print
'</td><td>'.$langs->trans(
"LDAPFieldDescriptionExample").
'</td>';
191 print
'<td class="right"><input type="radio" name="key" value="LDAP_GROUP_FIELD_DESCRIPTION"'.(($conf->global->LDAP_KEY_GROUPS && $conf->global->LDAP_KEY_GROUPS == $conf->global->LDAP_GROUP_FIELD_DESCRIPTION) ?
' checked' :
'').
"></td>";
195 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldGroupMembers").
'</td><td>';
196 print
'<input size="25" type="text" name="fieldgroupmembers" value="'.$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS.
'">';
197 print
'</td><td>'.$langs->trans(
"LDAPFieldGroupMembersExample").
'</td>';
198 print
'<td class="right"><input type="radio" name="key" value="LDAP_GROUP_FIELD_GROUPMEMBERS"'.(($conf->global->LDAP_KEY_GROUPS && $conf->global->LDAP_KEY_GROUPS == $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS) ?
' checked' :
'').
"></td>";
202 print
'<tr class="oddeven"><td>'.$langs->trans(
"LDAPFieldGroupid").
'</td><td>';
203 print
'<input size="25" type="text" name="fieldgroupid" value="'.$conf->global->LDAP_GROUP_FIELD_GROUPID.
'">';
204 print
'</td><td>'.$langs->trans(
"LDAPFieldGroupidExample").
'</td>';
205 print
'<td class="right"> </td>';
210 print
info_admin($langs->trans(
"LDAPDescValues"));
214 print
$form->buttonsSaveCancel(
"Modify",
'');
223 $butlabel = $langs->trans(
"LDAPTestSynchroGroup");
224 $testlabel =
'testgroup';
225 $key = $conf->global->LDAP_KEY_GROUPS;
226 $dn = $conf->global->LDAP_GROUP_DN;
227 $objectclass = $conf->global->LDAP_GROUP_OBJECT_CLASS;
231 $butlabel = $langs->trans(
"LDAPTestSearch");
232 $testlabel =
'testsearchgroup';
233 $key = $conf->global->LDAP_KEY_GROUPS;
234 $dn = $conf->global->LDAP_GROUP_DN;
235 $objectclass = $conf->global->LDAP_GROUP_OBJECT_CLASS;
239 if (function_exists(
"ldap_connect")) {
240 if ($action ==
'testgroup') {
243 $object->initAsSpecimen();
247 $result = $ldap->connect_bind();
250 $info = $object->_load_ldap_info();
251 $dn = $object->_load_ldap_dn($info);
254 if (in_array(
'posixGroup', $info[
'objectclass'])) {
255 $info[
'gidNumber'] = $ldap->getNextGroupGid(
'LDAP_KEY_GROUPS');
258 $result1 = $ldap->delete($dn);
259 $result2 = $ldap->add($dn, $info, $user);
260 $result3 = $ldap->delete($dn);
264 print
'<span class="ok">'.$langs->trans(
"LDAPSynchroOK").
'</span><br>';
267 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKOMayBePermissions");
268 print
': '.$ldap->error;
270 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
274 print
"LDAP input file used for test:<br><br>\n";
275 print nl2br($ldap->dump_content($dn, $info));
279 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
280 print
': '.$ldap->error;
282 print $langs->trans(
"ErrorLDAPMakeManualTest", $conf->ldap->dir_temp).
'<br>';
286 if ($action ==
'testsearchgroup') {
291 $result = $ldap->connect_bind();
294 $required_fields = array(
295 $conf->global->LDAP_KEY_GROUPS,
297 $conf->global->LDAP_GROUP_FIELD_DESCRIPTION,
298 $conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS,
299 $conf->global->LDAP_GROUP_FIELD_GROUPID
303 $required_fields = array_unique(array_values(array_filter($required_fields,
"dol_validElement")));
306 $ldapgroups = $ldap->getRecords(
'*', $conf->global->LDAP_GROUP_DN, $conf->global->LDAP_KEY_GROUPS, $required_fields,
'group');
309 if (is_array($ldapgroups)) {
311 foreach ($ldapgroups as $key => $ldapgroup) {
314 foreach ($required_fields as $value) {
316 $label .= $value.
"=".$ldapgroup[$value].
" ";
319 $liste[$key] = $label;
326 print
"LDAP search for group:<br>\n";
327 print
"search: *<br>\n";
328 print
"userDN: ".$conf->global->LDAP_GROUP_DN.
"<br>\n";
329 print
"useridentifier: ".$conf->global->LDAP_KEY_GROUPS.
"<br>\n";
330 print
"required_fields: ".implode(
',', $required_fields).
"<br>\n";
331 print
"=> ".count($liste).
" records<br>\n";
335 print
'<span class="error">'.$langs->trans(
"LDAPSynchroKO");
336 print
': '.$ldap->error;
338 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 user groups.
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.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
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.