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-2021 Regis Houssin <regis.houssin@inodbox.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 require '../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
29 
30 // Load translation files required by page
31 $langs->loadLangs(array('users', 'admin', 'companies', 'ldap'));
32 
33 $id = GETPOST('id', 'int');
34 $action = GETPOST('action', 'aZ09');
35 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userldap'; // To manage different context of search
36 
37 // Security check
38 $socid = 0;
39 if ($user->socid > 0) {
40  $socid = $user->socid;
41 }
42 $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
43 
44 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
45 
46 $object = new User($db);
47 $object->fetch($id, '', '', 1);
48 $object->getrights();
49 
50 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
51 $hookmanager->initHooks(array('usercard', 'userldap', 'globalcard'));
52 
53 
54 /*
55  * Actions
56  */
57 
58 
59 $parameters = array('id'=>$socid);
60 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
61 if ($reshook < 0) {
62  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
63 }
64 
65 if (empty($reshook)) {
66  if ($action == 'dolibarr2ldap') {
67  $ldap = new Ldap();
68  $result = $ldap->connect_bind();
69 
70  if ($result > 0) {
71  $info = $object->_load_ldap_info();
72  $dn = $object->_load_ldap_dn($info);
73  $olddn = $dn; // We can say that old dn = dn as we force synchro
74 
75  $result = $ldap->update($dn, $info, $user, $olddn);
76  }
77 
78  if ($result >= 0) {
79  setEventMessages($langs->trans("UserSynchronized"), null, 'mesgs');
80  } else {
81  setEventMessages($ldap->error, $ldap->errors, 'errors');
82  }
83  }
84 }
85 
86 /*
87  * View
88  */
89 
90 $form = new Form($db);
91 
92 llxHeader();
93 
94 $head = user_prepare_head($object);
95 
96 $title = $langs->trans("User");
97 print dol_get_fiche_head($head, 'ldap', $title, -1, 'user');
98 
99 $linkback = '';
100 
101 if (!empty($user->rights->user->user->lire) || !empty($user->admin)) {
102  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
103 }
104 
105 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
106 
107 print '<div class="fichecenter">';
108 print '<div class="underbanner clearboth"></div>';
109 
110 print '<table class="border centpercent tableforfield">';
111 
112 // Login
113 print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
114 if ($object->ldap_sid) {
115  print '<td class="warning">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
116 } else {
117  print '<td>'.$object->login.'</td>';
118 }
119 print '</tr>';
120 
121 if ($conf->global->LDAP_SERVER_TYPE == "activedirectory") {
122  $ldap = new Ldap();
123  $result = $ldap->connect_bind();
124  if ($result > 0) {
125  $userSID = $ldap->getObjectSid($object->login);
126  }
127  print '<tr><td class="valigntop">'.$langs->trans("SID").'</td>';
128  print '<td>'.$userSID.'</td>';
129  print "</tr>\n";
130 }
131 
132 // LDAP DN
133 print '<tr><td>LDAP '.$langs->trans("LDAPUserDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_USER_DN')."</td></tr>\n";
134 
135 // LDAP Cle
136 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_USERS')."</td></tr>\n";
137 
138 // LDAP Server
139 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
140 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
141 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
142 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
143 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
144 
145 print '</table>';
146 
147 print '</div>';
148 
149 print dol_get_fiche_end();
150 
151 /*
152  * Action bar
153  */
154 print '<div class="tabsAction">';
155 
156 if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
157  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
158 }
159 
160 print "</div>\n";
161 
162 if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
163  print "<br>\n";
164 }
165 
166 
167 
168 // Affichage attributs LDAP
169 print load_fiche_titre($langs->trans("LDAPInformationsForThisUser"));
170 
171 print '<table class="noborder centpercent">';
172 
173 print '<tr class="liste_titre">';
174 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
175 print '<td>'.$langs->trans("Value").'</td>';
176 print '</tr>';
177 
178 // Lecture LDAP
179 $ldap = new Ldap();
180 $result = $ldap->connect_bind();
181 if ($result > 0) {
182  $info = $object->_load_ldap_info();
183  $dn = $object->_load_ldap_dn($info, 1);
184  $search = "(".$object->_load_ldap_dn($info, 2).")";
185 
186  $records = $ldap->getAttribute($dn, $search);
187 
188  //print_r($records);
189 
190  // Affichage arbre
191  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
192  if (!is_array($records)) {
193  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
194  } else {
195  $result = show_ldap_content($records, 0, $records['count'], true);
196  }
197  } else {
198  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
199  }
200 
201  $ldap->unbind();
202 } else {
203  setEventMessages($ldap->error, $ldap->errors, 'errors');
204 }
205 
206 print '</table>';
207 
208 // End of page
209 llxFooter();
210 $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
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
user_prepare_head
user_prepare_head(User $object)
Prepare array with list of tabs.
Definition: usergroups.lib.php:35
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
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
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
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:93
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