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  * 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 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
32 
33 // Load translation files required by page
34 $langs->loadLangs(array('companies', 'ldap', 'users', 'admin'));
35 
36 // Users/Groups management only in master entity if transverse mode
37 if (!empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)
38 {
40 }
41 
42 $canreadperms = true;
43 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS))
44 {
45  $canreadperms = ($user->admin || $user->rights->user->group_advance->read);
46 }
47 
48 $id = GETPOST('id', 'int');
49 $action = GETPOST('action', 'aZ09');
50 
51 $socid = 0;
52 if ($user->socid > 0) $socid = $user->socid;
53 
54 $object = new Usergroup($db);
55 $object->fetch($id);
56 $object->getrights();
57 
58 
59 /*
60  * Actions
61  */
62 
63 if ($action == 'dolibarr2ldap')
64 {
65  $ldap = new Ldap();
66  $result = $ldap->connect_bind();
67 
68  if ($result > 0)
69  {
70  $info = $object->_load_ldap_info();
71 
72  // Get a gid number for objectclass PosixGroup
73  if (in_array('posixGroup', $info['objectclass'])) {
74  $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
75  }
76 
77  $dn = $object->_load_ldap_dn($info);
78  $olddn = $dn; // We can say that old dn = dn as we force synchro
79 
80  $result = $ldap->update($dn, $info, $user, $olddn);
81  }
82 
83  if ($result >= 0)
84  {
85  setEventMessages($langs->trans("GroupSynchronized"), null, 'mesgs');
86  } else {
87  setEventMessages($ldap->error, $ldap->errors, 'errors');
88  }
89 }
90 
91 
92 /*
93  * View
94  */
95 
96 $form = new Form($db);
97 
98 llxHeader();
99 
100 $head = group_prepare_head($object);
101 
102 print 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 
106 dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin);
107 
108 print '<div class="fichecenter">';
109 print '<div class="underbanner clearboth"></div>';
110 
111 print '<table class="border centpercent">';
112 
113 // Name (already in dol_banner, we keep it to have the GlobalGroup picto, but we should move it in dol_banner)
114 if (!empty($conf->mutlicompany->enabled))
115 {
116  print '<tr><td class="titlefield">'.$langs->trans("Name").'</td>';
117  print '<td class="valeur">'.$object->name;
118  if (!$object->entity)
119  {
120  print img_picto($langs->trans("GlobalGroup"), 'redstar');
121  }
122  print "</td></tr>\n";
123 }
124 
125 // Note
126 print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
127 print '<td class="valeur sensiblehtmlcontent">';
129 print '</td>';
130 print "</tr>\n";
131 
132 // LDAP DN
133 print '<tr><td>LDAP '.$langs->trans("LDAPGroupDn").'</td><td class="valeur">'.$conf->global->LDAP_GROUP_DN."</td></tr>\n";
134 
135 // LDAP Cle
136 print '<tr><td>LDAP '.$langs->trans("LDAPNamingAttribute").'</td><td class="valeur">'.$conf->global->LDAP_KEY_GROUPS."</td></tr>\n";
137 
138 // LDAP Server
139 print '<tr><td>LDAP '.$langs->trans("LDAPPrimaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST."</td></tr>\n";
140 print '<tr><td>LDAP '.$langs->trans("LDAPSecondaryServer").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_HOST_SLAVE."</td></tr>\n";
141 print '<tr><td>LDAP '.$langs->trans("LDAPServerPort").'</td><td class="valeur">'.$conf->global->LDAP_SERVER_PORT."</td></tr>\n";
142 
143 print "</table>\n";
144 
145 print '</div>';
146 
148 
149 
150 /*
151  * Barre d'actions
152  */
153 
154 print '<div class="tabsAction">';
155 
156 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
157 {
158  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=dolibarr2ldap">'.$langs->trans("ForceSynchronize").'</a>';
159 }
160 
161 print "</div>\n";
162 
163 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap') print "<br>\n";
164 
165 
166 
167 // Affichage attributs LDAP
168 print load_fiche_titre($langs->trans("LDAPInformationsForThisGroup"));
169 
170 print '<table class="noborder centpercent">';
171 
172 print '<tr class="liste_titre">';
173 print '<td>'.$langs->trans("LDAPAttributes").'</td>';
174 print '<td>'.$langs->trans("Value").'</td>';
175 print '</tr>';
176 
177 // Lecture LDAP
178 $ldap = new Ldap();
179 $result = $ldap->connect_bind();
180 if ($result > 0)
181 {
182  $info = $object->_load_ldap_info();
183  $dn = $object->_load_ldap_dn($info, 1);
184  $search = "(".$object->_load_ldap_dn($info, 2).")";
185 
186  $records = $ldap->getAttribute($dn, $search);
187 
188  //var_dump($records);
189 
190  // Show tree
191  if (((!is_numeric($records)) || $records != 0) && (!isset($records['count']) || $records['count'] > 0))
192  {
193  if (!is_array($records))
194  {
195  print '<tr class="oddeven"><td colspan="2"><font class="error">'.$langs->trans("ErrorFailedToReadLDAP").'</font></td></tr>';
196  } else {
197  $result = show_ldap_content($records, 0, $records['count'], true);
198  }
199  } else {
200  print '<tr class="oddeven"><td colspan="2">'.$langs->trans("LDAPRecordNotFound").' (dn='.$dn.' - search='.$search.')</td></tr>';
201  }
202  $ldap->unbind();
203  $ldap->close();
204 } else {
205  setEventMessages($ldap->error, $ldap->errors, 'errors');
206 }
207 
208 print '</table>';
209 
210 // End of page
211 llxFooter();
212 $db->close();
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...
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.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
group_prepare_head($object)
Prepare array with list of tabs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0)
Clean a string to keep only desirable HTML tags.
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