dolibarr  19.0.0-dev
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 // Load Dolibarr environment
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
30 
31 // Load translation files required by page
32 $langs->loadLangs(array('users', 'admin', 'companies', 'ldap'));
33 
34 $id = GETPOST('id', 'int');
35 $action = GETPOST('action', 'aZ09');
36 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userldap'; // To manage different context of search
37 
38 // Security check
39 $socid = 0;
40 if ($user->socid > 0) {
41  $socid = $user->socid;
42 }
43 $feature2 = (($socid && $user->hasRight('user', 'self', 'creer')) ? '' : 'user');
44 
45 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
46 
47 $object = new User($db);
48 $object->fetch($id, '', '', 1);
49 $object->getrights();
50 
51 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
52 $hookmanager->initHooks(array('usercard', 'userldap', 'globalcard'));
53 
54 
55 /*
56  * Actions
57  */
58 
59 
60 $parameters = array('id'=>$socid);
61 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
62 if ($reshook < 0) {
63  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
64 }
65 
66 if (empty($reshook)) {
67  if ($action == 'dolibarr2ldap') {
68  $ldap = new Ldap();
69  $result = $ldap->connect_bind();
70 
71  if ($result > 0) {
72  $info = $object->_load_ldap_info();
73  $dn = $object->_load_ldap_dn($info);
74  $olddn = $dn; // We can say that old dn = dn as we force synchro
75 
76  $result = $ldap->update($dn, $info, $user, $olddn);
77  }
78 
79  if ($result >= 0) {
80  setEventMessages($langs->trans("UserSynchronized"), null, 'mesgs');
81  } else {
82  setEventMessages($ldap->error, $ldap->errors, 'errors');
83  }
84  }
85 }
86 
87 /*
88  * View
89  */
90 
91 $form = new Form($db);
92 
93 $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
94 $title = $person_name." - ".$langs->trans('LDAP');
95 $help_url = '';
96 llxHeader('', $title, $help_url);
97 
98 $head = user_prepare_head($object);
99 
100 $title = $langs->trans("User");
101 print dol_get_fiche_head($head, 'ldap', $title, -1, 'user');
102 
103 $linkback = '';
104 
105 if (!empty($user->rights->user->user->lire) || !empty($user->admin)) {
106  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
107 }
108 
109 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
110 
111 print '<div class="fichecenter">';
112 print '<div class="underbanner clearboth"></div>';
113 
114 print '<table class="border centpercent tableforfield">';
115 
116 // Login
117 print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
118 if ($object->ldap_sid) {
119  print '<td class="warning">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
120 } else {
121  print '<td>'.$object->login.'</td>';
122 }
123 print '</tr>';
124 
125 if ($conf->global->LDAP_SERVER_TYPE == "activedirectory") {
126  $ldap = new Ldap();
127  $result = $ldap->connect_bind();
128  if ($result > 0) {
129  $userSID = $ldap->getObjectSid($object->login);
130  }
131  print '<tr><td class="valigntop">'.$langs->trans("SID").'</td>';
132  print '<td>'.$userSID.'</td>';
133  print "</tr>\n";
134 }
135 
136 // LDAP DN
137 print '<tr><td>LDAP '.$langs->trans("LDAPUserDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_USER_DN')."</td></tr>\n";
138 
139 // LDAP Cle
140 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_USERS')."</td></tr>\n";
141 
142 // LDAP Server
143 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_TYPE')."</td></tr>\n";
144 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION')."</td></tr>\n";
145 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
146 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
147 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
148 
149 print '</table>';
150 
151 print '</div>';
152 
153 print dol_get_fiche_end();
154 
155 /*
156  * Action bar
157  */
158 print '<div class="tabsAction">';
159 
160 if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
161  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
162 }
163 
164 print "</div>\n";
165 
166 if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
167  print "<br>\n";
168 }
169 
170 
171 
172 // Affichage attributs LDAP
173 print load_fiche_titre($langs->trans("LDAPInformationsForThisUser"));
174 
175 print '<table class="noborder centpercent">';
176 
177 print '<tr class="liste_titre">';
178 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
179 print '<td>'.$langs->trans("Value").'</td>';
180 print '</tr>';
181 
182 // Lecture LDAP
183 $ldap = new Ldap();
184 $result = $ldap->connect_bind();
185 if ($result > 0) {
186  $info = $object->_load_ldap_info();
187  $dn = $object->_load_ldap_dn($info, 1);
188  $search = "(".$object->_load_ldap_dn($info, 2).")";
189 
190  $records = $ldap->getAttribute($dn, $search);
191 
192  //print_r($records);
193 
194  // Affichage arbre
195  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
196  if (!is_array($records)) {
197  print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
198  } else {
199  $result = show_ldap_content($records, 0, $records['count'], true);
200  }
201  } else {
202  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
203  }
204 
205  $ldap->unbind();
206 } else {
207  setEventMessages($ldap->error, $ldap->errors, 'errors');
208 }
209 
210 print '</table>';
211 
212 // End of page
213 llxFooter();
214 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
Definition: ldap.class.php:35
const SYNCHRO_DOLIBARR_TO_LDAP
Dolibarr to Ldap synchronization.
Definition: ldap.class.php:136
Class to manage Dolibarr users.
Definition: user.class.php:48
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
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_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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
restrictedArea(User $user, $features, $object=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.
user_prepare_head(User $object)
Prepare array with list of tabs.