dolibarr 20.0.0
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 Frédéric France <frederic.france@netlogic.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
34// Load translation files required by page
35$langs->loadLangs(array('companies', 'ldap', 'users', 'admin'));
36
37$id = GETPOSTINT('id');
38$action = GETPOST('action', 'aZ09');
39
40$socid = 0;
41if ($user->socid > 0) {
42 $socid = $user->socid;
43}
44
45$object = new UserGroup($db);
46$object->fetch($id, '', true);
47$object->getrights();
48
49// Users/Groups management only in master entity if transverse mode
50if (isModEnabled('multicompany') && $conf->entity > 1 && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
52}
53
54$canreadperms = true;
55if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
56 $canreadperms = (!empty($user->admin) || $user->hasRight('user', 'group_advance', 'read'));
57}
58
59
60/*
61 * Actions
62 */
63
64if ($action == 'dolibarr2ldap') {
65 $ldap = new Ldap();
66 $result = $ldap->connectBind();
67
68 if ($result > 0) {
69 $info = $object->_load_ldap_info();
70
71 // Get a gid number for objectclass PosixGroup if none was provided
72 if (empty($info[getDolGlobalString('LDAP_GROUP_FIELD_GROUPID')]) && in_array('posixGroup', $info['objectclass'])) {
73 $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
74 }
75
76 $dn = $object->_load_ldap_dn($info);
77 $olddn = $dn; // We can say that old dn = dn as we force synchro
78
79 $result = $ldap->update($dn, $info, $user, $olddn);
80 }
81
82 if ($result >= 0) {
83 setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
84 } else {
85 setEventMessages($ldap->error, $ldap->errors, 'errors');
86 }
87}
88
89
90/*
91 * View
92 */
93
94$form = new Form($db);
95
96$title = $object->name." - ".$langs->trans('LDAP');
97$help_url = '';
98llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-user page-group_ldap');
99
100$head = group_prepare_head($object);
101
102print dol_get_fiche_head($head, 'ldap', $langs->trans("Group"), -1, 'group');
103
104$linkback = '<a href="'.DOL_URL_ROOT.'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
105
106dol_banner_tab($object, 'id', $linkback, ($user->hasRight('user', 'user', 'lire') || !empty($user->admin)));
107
108print '<div class="fichecenter">';
109print '<div class="underbanner clearboth"></div>';
110
111print '<table class="border centpercent tableforfield">';
112
113// Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
114if (!empty($conf->mutlicompany->enabled)) {
115 print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
116 print '<td class="valeur">'.$object->name;
117 if (!$object->entity) {
118 print img_picto($langs->trans("GlobalGroup"), 'redstar');
119 }
120 print "</td></tr>\n";
121}
122
123// Note
124print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
125print '<td class="valeur sensiblehtmlcontent">';
127print '</td>';
128print "</tr>\n";
129
130// LDAP DN
131print '<tr><td>LDAP '.$langs->trans("LDAPGroupDn").'</td><td class="valeur">'.getDolGlobalString('LDAP_GROUP_DN')."</td></tr>\n";
132
133// LDAP Cle
134print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.getDolGlobalString('LDAP_KEY_GROUPS')."</td></tr>\n";
135
136// LDAP Server
137print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST')."</td></tr>\n";
138print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_HOST_SLAVE')."</td></tr>\n";
139print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.getDolGlobalString('LDAP_SERVER_PORT')."</td></tr>\n";
140
141print "</table>\n";
142
143print '</div>';
144
145print dol_get_fiche_end();
146
147
148/*
149 * Action bar
150 */
151print '<div class="tabsAction">';
152
153if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
154 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
155}
156
157print "</div>\n";
158
159if (getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_DOLIBARR_TO_LDAP) {
160 print "<br>\n";
161}
162
163
164
165// Affichage attributes LDAP
166print load_fiche_titre($langs->trans("LDAPInformationsForThisGroup"));
167
168print '<table class="noborder centpercent">';
169
170print '<tr class="liste_titre">';
171print '<td>'.$langs->trans("LDAPAttributes").'</td>';
172print '<td>'.$langs->trans("Value").'</td>';
173print '</tr>';
174
175// Lecture LDAP
176$ldap = new Ldap();
177$result = $ldap->connectBind();
178if ($result > 0) {
179 $info = $object->_load_ldap_info();
180 $dn = $object->_load_ldap_dn($info, 1);
181 $search = "(".$object->_load_ldap_dn($info, 2).")";
182
183 $records = $ldap->getAttribute($dn, $search);
184
185 //var_dump($records);
186
187 // Show tree
188 if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0)) {
189 if (!is_array($records)) {
190 print '<tr class="oddeven"><td colspan="2"><span class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</span></td></tr>';
191 } else {
192 $result = show_ldap_content($records, 0, $records['count'], true);
193 }
194 } else {
195 print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.dol_escape_htmltag($dn).' - search='.dol_escape_htmltag($search).')</td></tr>';
196 }
197 $ldap->unbind();
198} else {
199 setEventMessages($ldap->error, $ldap->errors, 'errors');
200}
201
202print '</table>';
203
204// End of page
205llxFooter();
206$db->close();
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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage generation of HTML components Only common components must be here.
Class to manage LDAP features.
Class to manage user groups.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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_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.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0)
Clean a string to keep only desirable HTML tags.
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.
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 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
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.