dolibarr  13.0.2
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  *
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 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'userldap'; // To manage different context of search
35 
36 // Security check
37 $socid = 0;
38 if ($user->socid > 0) $socid = $user->socid;
39 $feature2 = (($socid && $user->rights->user->self->creer) ? '' : 'user');
40 
41 $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
42 
43 $object = new User($db);
44 $object->fetch($id, '', '', 1);
45 $object->getrights();
46 
47 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
48 $hookmanager->initHooks(array('usercard', 'userldap', 'globalcard'));
49 
50 
51 /*
52  * Actions
53  */
54 
55 
56 $parameters = array('id'=>$socid);
57 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
58 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
59 
60 if (empty($reshook))
61 {
62  if ($_GET["action"] == 'dolibarr2ldap')
63  {
64  $ldap = new Ldap();
65  $result = $ldap->connect_bind();
66 
67  if ($result > 0)
68  {
69  $info = $object->_load_ldap_info();
70  $dn = $object->_load_ldap_dn($info);
71  $olddn = $dn; // We can say that old dn = dn as we force synchro
72 
73  $result = $ldap->update($dn, $info, $user, $olddn);
74  }
75 
76  if ($result >= 0) {
77  setEventMessages($langs->trans("UserSynchronized"), null, 'mesgs');
78  } else {
79  setEventMessages($ldap->error, $ldap->errors, 'errors');
80  }
81  }
82 }
83 
84 /*
85  * View
86  */
87 
88 $form = new Form($db);
89 
90 llxHeader();
91 
92 $head = user_prepare_head($object);
93 
94 $title = $langs->trans("User");
95 print dol_get_fiche_head($head, 'ldap', $title, 0, 'user');
96 
97 $linkback = '';
98 
99 if ($user->rights->user->user->lire || $user->admin) {
100  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
101 }
102 
103 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
104 
105 print '<div class="fichecenter">';
106 print '<div class="underbanner clearboth"></div>';
107 
108 print '<table class="border centpercent">';
109 
110 // Login
111 print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
112 if ($object->ldap_sid)
113 {
114  print '<td class="warning">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
115 } else {
116  print '<td>'.$object->login.'</td>';
117 }
118 print '</tr>';
119 
120 if ($conf->global->LDAP_SERVER_TYPE == "activedirectory")
121 {
122  $ldap = new Ldap();
123  $result = $ldap->connect_bind();
124  if ($result > 0)
125  {
126  $userSID = $ldap->getObjectSid($object->login);
127  }
128  print '<tr><td class="valigntop">'.$langs->trans("SID").'</td>';
129  print '<td>'.$userSID.'</td>';
130  print "</tr>\n";
131 }
132 
133 // LDAP DN
134 print '<tr><td>LDAP '.$langs->trans("LDAPUserDn").'</td><td class="valeur">'.$conf->global->LDAP_USER_DN."</td></tr>\n";
135 
136 // LDAP Cle
137 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_USERS."</td></tr>\n";
138 
139 // LDAP Server
140 print '<tr><td>LDAP '.$langs->trans("Type").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_TYPE."</td></tr>\n";
141 print '<tr><td>LDAP '.$langs->trans("Version").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PROTOCOLVERSION."</td></tr>\n";
142 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
143 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
144 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
145 
146 print '</table>';
147 
148 print '</div>';
149 
151 
152 /*
153  * Barre d'actions
154  */
155 
156 print '<div class="tabsAction">';
157 
158 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
159 {
160  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
161 }
162 
163 print "</div>\n";
164 
165 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') print "<br>\n";
166 
167 
168 
169 // Affichage attributs LDAP
170 print load_fiche_titre($langs->trans("LDAPInformationsForThisUser"));
171 
172 print '<table class="noborder centpercent">';
173 
174 print '<tr class="liste_titre">';
175 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
176 print '<td>'.$langs->trans("Value").'</td>';
177 print '</tr>';
178 
179 // Lecture LDAP
180 $ldap = new Ldap();
181 $result = $ldap->connect_bind();
182 if ($result > 0)
183 {
184  $info = $object->_load_ldap_info();
185  $dn = $object->_load_ldap_dn($info, 1);
186  $search = "(".$object->_load_ldap_dn($info, 2).")";
187 
188  $records = $ldap->getAttribute($dn, $search);
189 
190  //print_r($records);
191 
192  // Affichage arbre
193  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0))
194  {
195  if (!is_array($records))
196  {
197  print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></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='.$dn.' - search='.$search.')</td></tr>';
203  }
204 
205  $ldap->unbind();
206  $ldap->close();
207 } else {
208  setEventMessages($ldap->error, $ldap->errors, 'errors');
209 }
210 
211 print '</table>';
212 
213 // End of page
214 llxFooter();
215 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
user_prepare_head($object)
Prepare array with list of tabs.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
show_ldap_content($result, $level, $count, $var, $hide=0, $subcount=0)
Show a LDAP array into an HTML output array.
Definition: ldap.lib.php:142
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:89
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59