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