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