dolibarr  16.0.5
ldap.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006-2017 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
32 
33 // Load translation files required by page
34 $langs->loadLangs(array('companies', 'ldap', 'users', 'admin'));
35 
36 $id = GETPOST('id', 'int');
37 $action = GETPOST('action', 'aZ09');
38 
39 $socid = 0;
40 if ($user->socid > 0) {
41  $socid = $user->socid;
42 }
43 
44 $object = new Usergroup($db);
45 $object->fetch($id);
46 $object->getrights();
47 
48 // Users/Groups management only in master entity if transverse mode
49 if (!empty($conf->multicompany->enabled) && $conf->entity > 1 && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
51 }
52 
53 $canreadperms = true;
54 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
55  $canreadperms = (!empty($user->admin) || !empty($user->rights->user->group_advance->read));
56 }
57 
58 
59 /*
60  * Actions
61  */
62 
63 if ($action == 'dolibarr2ldap') {
64  $ldap = new Ldap();
65  $result = $ldap->connect_bind();
66 
67  if ($result > 0) {
68  $info = $object->_load_ldap_info();
69 
70  // Get a gid number for objectclass PosixGroup if none was provided
71  if (empty($info[$conf->global->LDAP_GROUP_FIELD_GROUPID]) && in_array('posixGroup', $info['objectclass'])) {
72  $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
73  }
74 
75  $dn = $object->_load_ldap_dn($info);
76  $olddn = $dn; // We can say that old dn = dn as we force synchro
77 
78  $result = $ldap->update($dn, $info, $user, $olddn);
79  }
80 
81  if ($result >= 0) {
82  setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
83  } else {
84  setEventMessages($ldap->error, $ldap->errors, 'errors');
85  }
86 }
87 
88 
89 /*
90  * View
91  */
92 
93 $form = new Form($db);
94 
95 llxHeader();
96 
97 $head = group_prepare_head($object);
98 
99 print dol_get_fiche_head($head, 'ldap', $langs->trans("Group"), -1, 'group');
100 
101 $linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
102 
103 dol_banner_tab($object, 'id', $linkback, (!empty($user->rights->user->user->lire) || !empty($user->admin)));
104 
105 print '<div class="fichecenter">';
106 print '<div class="underbanner clearboth"></div>';
107 
108 print '<table class="border centpercent">';
109 
110 // Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
111 if (!empty($conf->mutlicompany->enabled)) {
112  print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
113  print '<td class="valeur">'.$object->name;
114  if (!$object->entity) {
115  print img_picto($langs->trans("GlobalGroup"), 'redstar');
116  }
117  print "</td></tr>\n";
118 }
119 
120 // Note
121 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
122 print '<td class="valeur sensiblehtmlcontent">';
124 print '</td>';
125 print "</tr>\n";
126 
127 // LDAP DN
128 print '<tr><td>LDAP '.$langs->trans("LDAPGroupDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_GROUP_DN')."</td></tr>\n";
129 
130 // LDAP Cle
131 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_GROUPS')."</td></tr>\n";
132 
133 // LDAP Server
134 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
135 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
136 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
137 
138 print "</table>\n";
139 
140 print '</div>';
141 
142 print dol_get_fiche_end();
143 
144 
145 /*
146  * Action bar
147  */
148 print '<div class="tabsAction">';
149 
150 if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
151  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
152 }
153 
154 print "</div>\n";
155 
156 if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
157  print "<br>\n";
158 }
159 
160 
161 
162 // Affichage attributs LDAP
163 print load_fiche_titre($langs->trans("LDAPInformationsForThisGroup"));
164 
165 print '<table class="noborder centpercent">';
166 
167 print '<tr class="liste_titre">';
168 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
169 print '<td>'.$langs->trans("Value").'</td>';
170 print '</tr>';
171 
172 // Lecture LDAP
173 $ldap = new Ldap();
174 $result = $ldap->connect_bind();
175 if ($result > 0) {
176  $info = $object->_load_ldap_info();
177  $dn = $object->_load_ldap_dn($info, 1);
178  $search = "(".$object->_load_ldap_dn($info, 2).")";
179 
180  $records = $ldap->getAttribute($dn, $search);
181 
182  //var_dump($records);
183 
184  // Show tree
185  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
186  if (!is_array($records)) {
187  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
188  } else {
189  $result = show_ldap_content($records, 0, $records['count'], true);
190  }
191  } else {
192  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
193  }
194  $ldap->unbind();
195 } else {
196  setEventMessages($ldap->error, $ldap->errors, 'errors');
197 }
198 
199 print '</table>';
200 
201 // End of page
202 llxFooter();
203 $db->close();
Ldap
Class to manage LDAP features.
Definition: ldap.class.php:34
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
Ldap\SYNCHRO_DOLIBARR_TO_LDAP
const SYNCHRO_DOLIBARR_TO_LDAP
Dolibarr to Ldap synchronization.
Definition: ldap.class.php:133
img_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)
Definition: functions.lib.php:3880
show_ldap_content
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:132
group_prepare_head
group_prepare_head($object)
Prepare array with list of tabs.
Definition: usergroups.lib.php:202
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:6991
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
dol_string_onlythesehtmltags
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0)
Clean a string to keep only desirable HTML tags.
Definition: functions.lib.php:6760
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59