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-2017 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2019-2024 Frédéric France <frederic.france@free.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.'/user/class/usergroup.class.php';
29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
33
42// Load translation files required by page
43$langs->loadLangs(array('companies', 'ldap', 'users', 'admin'));
44
45$id = GETPOSTINT('id');
46$action = GETPOST('action', 'aZ09');
47
48$socid = 0;
49if ($user->socid > 0) {
50 $socid = $user->socid;
51}
52
53$object = new UserGroup($db);
54$object->fetch($id, '', true);
55$object->loadRights();
56
57// Users/Groups management only in master entity if transverse mode
58if (isModEnabled('multicompany') && $conf->entity > 1 && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
60}
61
62$permissiontoread = true;
63if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
64 $permissiontoread = (!empty($user->admin) || $user->hasRight('user', 'group_advance', 'read'));
65}
66
67
68/*
69 * Actions
70 */
71
72if ($action == 'dolibarr2ldap') {
73 $ldap = new Ldap();
74 $result = $ldap->connectBind();
75
76 if ($result > 0) {
77 $info = $object->_load_ldap_info();
78
79 // Get a gid number for objectclass PosixGroup if none was provided
80 if (empty($info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')]) && in_array('posixGroup', $info['objectclass'])) {
81 $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
82 }
83
84 $dn = $object->_load_ldap_dn($info);
85 $olddn = $dn; // We can say that old dn = dn as we force synchro
86
87 $result = $ldap->update($dn, $info, $user, $olddn);
88 }
89
90 if ($result >= 0) {
91 setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
92 } else {
93 setEventMessages($ldap->error, $ldap->errors, 'errors');
94 }
95}
96
97
98/*
99 * View
100 */
101
102$form = new Form($db);
103
104$title = $object->name." - ".$langs->trans('LDAP');
105$help_url = '';
106llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-group_ldap');
107
108$head = group_prepare_head($object);
109
110print dol_get_fiche_head($head, 'ldap', $langs->trans("Group"), -1, 'group');
111
112$linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
113
114dol_banner_tab($object, 'id', $linkback, ($user->hasRight('user', 'user', 'lire') || !empty($user->admin)));
115
116print '<div class="fichecenter">';
117print '<div class="underbanner clearboth"></div>';
118
119print '<table class="border centpercent tableforfield">';
120
121// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
122if (isModEnabled('multicompany')) {
123 print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
124 print '<td class="valeur">'.$object->name;
125 if (!$object->entity) {
126 print img_picto($langs->trans("GlobalGroup"), 'redstar');
127 }
128 print "</td></tr>\n";
129}
130
131// Note
132print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
133print '<td class="valeur sensiblehtmlcontent">';
135print '</td>';
136print "</tr>\n";
137
138// LDAP DN
139print '<tr><td>LDAP '.$langs->trans("LDAPGroupDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_GROUP_DN')."</td></tr>\n";
140
141// LDAP Cle
142print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_GROUPS')."</td></tr>\n";
143
144// LDAP Server
145print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
146print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
147print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
148
149print "</table>\n";
150
151print '</div>';
152
153print dol_get_fiche_end();
154
155
156/*
157 * Action bar
158 */
159print '<div class="tabsAction">';
160
161if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
162 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
163}
164
165print "</div>\n";
166
167if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
168 print "<br>\n";
169}
170
171
172
173// Affichage attributes LDAP
174print load_fiche_titre($langs->trans("LDAPInformationsForThisGroup"));
175
176print '<table class="noborder centpercent">';
177
178print '<tr class="liste_titre">';
179print '<td>'.$langs->trans("LDAPAttributes").'</td>';
180print '<td>'.$langs->trans("Value").'</td>';
181print '</tr>';
182
183// Lecture LDAP
184$ldap = new Ldap();
185$result = $ldap->connectBind();
186if ($result > 0) {
187 $info = $object->_load_ldap_info();
188 $dn = $object->_load_ldap_dn($info, 1);
189 $search = "(".$object->_load_ldap_dn($info, 2).")";
190
191 $records = $ldap->getAttribute($dn, $search);
192
193 //var_dump($records);
194
195 // Show tree
196 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
197 if (!is_array($records)) {
198 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
199 } else {
200 $result = show_ldap_content($records, 0, $records['count'], true);
201 }
202 } else {
203 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
204 }
205 $ldap->unbind();
206} else {
207 setEventMessages($ldap->error, $ldap->errors, 'errors');
208}
209
210print '</table>';
211
212// End of page
213llxFooter();
214$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 user groups.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0)
Clean a string to keep only desirable HTML tags.
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.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
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
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
group_prepare_head($object)
Prepare array with list of tabs.