dolibarr  7.0.0-beta
ldap_groups.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2005 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/ldap.lib.php';
35 
36 $langs->load("admin");
37 $langs->load("errors");
38 
39 if (!$user->admin)
41 
42 $action = GETPOST('action','aZ09');
43 
44 
45 /*
46  * Actions
47  */
48 
49 if ($action == 'setvalue' && $user->admin)
50 {
51  $error=0;
52  $db->begin();
53 
54  if (! dolibarr_set_const($db, 'LDAP_GROUP_DN',GETPOST("group"),'chaine',0,'',$conf->entity)) $error++;
55  if (! dolibarr_set_const($db, 'LDAP_GROUP_OBJECT_CLASS',GETPOST("objectclass"),'chaine',0,'',$conf->entity)) $error++;
56 
57  if (! dolibarr_set_const($db, 'LDAP_GROUP_FIELD_FULLNAME',GETPOST("fieldfullname"),'chaine',0,'',$conf->entity)) $error++;
58  //if (! dolibarr_set_const($db, 'LDAP_GROUP_FIELD_NAME',$_POST["fieldname"],'chaine',0,'',$conf->entity)) $error++;
59  if (! dolibarr_set_const($db, 'LDAP_GROUP_FIELD_DESCRIPTION',GETPOST("fielddescription"),'chaine',0,'',$conf->entity)) $error++;
60  if (! dolibarr_set_const($db, 'LDAP_GROUP_FIELD_GROUPMEMBERS',GETPOST("fieldgroupmembers"),'chaine',0,'',$conf->entity)) $error++;
61 
62  // This one must be after the others
63  $valkey='';
64  $key=GETPOST("key");
65  if ($key) $valkey=$conf->global->$key;
66  if (! dolibarr_set_const($db, 'LDAP_KEY_GROUPS',$valkey,'chaine',0,'',$conf->entity)) $error++;
67 
68  if (! $error)
69  {
70  $db->commit();
71  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
72  }
73  else
74  {
75  $db->rollback();
76  dol_print_error($db);
77  }
78 }
79 
80 
81 
82 /*
83  * View
84  */
85 
86 llxHeader('',$langs->trans("LDAPSetup"),'EN:Module_LDAP_En|FR:Module_LDAP|ES:M&oacute;dulo_LDAP');
87 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
88 
89 print load_fiche_titre($langs->trans("LDAPSetup"),$linkback,'title_setup');
90 
91 $head = ldap_prepare_head();
92 
93 // Test si fonction LDAP actives
94 if (! function_exists("ldap_connect"))
95 {
96  setEventMessages($langs->trans("LDAPFunctionsNotAvailableOnPHP"), null, 'errors');
97 }
98 
99 dol_fiche_head($head, 'groups', $langs->trans("LDAPSetup"), -1);
100 
101 
102 print $langs->trans("LDAPDescGroups").'<br>';
103 print '<br>';
104 
105 
106 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?action=setvalue">';
107 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
108 
109 $form=new Form($db);
110 
111 print '<table class="noborder" width="100%">';
112 $var=true;
113 
114 print '<tr class="liste_titre">';
115 print '<td colspan="4">'.$langs->trans("LDAPSynchronizeGroups").'</td>';
116 print "</tr>\n";
117 
118 // DN pour les groupes
119 
120 print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPGroupDn").'</span></td><td>';
121 print '<input size="48" type="text" name="group" value="'.$conf->global->LDAP_GROUP_DN.'">';
122 print '</td><td>'.$langs->trans("LDAPGroupDnExample").'</td>';
123 print '<td>&nbsp;</td>';
124 print '</tr>';
125 
126 // List of object class used to define attributes in structure
127 
128 print '<tr class="oddeven"><td width="25%"><span class="fieldrequired">'.$langs->trans("LDAPGroupObjectClassList").'</span></td><td>';
129 print '<input size="48" type="text" name="objectclass" value="'.$conf->global->LDAP_GROUP_OBJECT_CLASS.'">';
130 print '</td><td>'.$langs->trans("LDAPGroupObjectClassListExample").'</td>';
131 print '<td>&nbsp;</td>';
132 print '</tr>';
133 
134 print '</table>';
135 print '<br>';
136 print '<table class="noborder" width="100%">';
137 $var=true;
138 
139 print '<tr class="liste_titre">';
140 print '<td width="25%">'.$langs->trans("LDAPDolibarrMapping").'</td>';
141 print '<td colspan="2">'.$langs->trans("LDAPLdapMapping").'</td>';
142 print '<td align="right">'.$langs->trans("LDAPNamingAttribute").'</td>';
143 print "</tr>\n";
144 
145 // Filtre
146 
147 // Common name
148 
149 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
150 print '<input size="25" type="text" name="fieldfullname" value="'.$conf->global->LDAP_GROUP_FIELD_FULLNAME.'">';
151 print '</td><td>'.$langs->trans("LDAPFieldCommonNameExample").'</td>';
152 print '<td align="right"><input type="radio" name="key" value="LDAP_GROUP_FIELD_FULLNAME"'.(($conf->global->LDAP_KEY_GROUPS && $conf->global->LDAP_KEY_GROUPS==$conf->global->LDAP_GROUP_FIELD_FULLNAME)?' checked':'')."></td>";
153 print '</tr>';
154 
155 // Name
156 /*
157 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldName").'</td><td>';
158 print '<input size="25" type="text" name="fieldname" value="'.$conf->global->LDAP_GROUP_FIELD_NAME.'">';
159 print '</td><td>'.$langs->trans("LDAPFieldNameExample").'</td>';
160 print '<td align="right"><input type="radio" name="key" value="'.$conf->global->LDAP_GROUP_FIELD_NAME.'"'.($conf->global->LDAP_KEY_GROUPS==$conf->global->LDAP_GROUP_FIELD_NAME?' checked':'')."></td>";
161 print '</tr>';
162 */
163 
164 // Description
165 
166 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldDescription").'</td><td>';
167 print '<input size="25" type="text" name="fielddescription" value="'.$conf->global->LDAP_GROUP_FIELD_DESCRIPTION.'">';
168 print '</td><td>'.$langs->trans("LDAPFieldDescriptionExample").'</td>';
169 print '<td align="right"><input type="radio" name="key" value="LDAP_GROUP_FIELD_DESCRIPTION"'.(($conf->global->LDAP_KEY_GROUPS && $conf->global->LDAP_KEY_GROUPS==$conf->global->LDAP_GROUP_FIELD_DESCRIPTION)?' checked':'')."></td>";
170 print '</tr>';
171 
172 // User group
173 
174 print '<tr class="oddeven"><td>'.$langs->trans("LDAPFieldGroupMembers").'</td><td>';
175 print '<input size="25" type="text" name="fieldgroupmembers" value="'.$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS.'">';
176 print '</td><td>'.$langs->trans("LDAPFieldGroupMembersExample").'</td>';
177 print '<td align="right"><input type="radio" name="key" value="LDAP_GROUP_FIELD_GROUPMEMBERS"'.(($conf->global->LDAP_KEY_GROUPS && $conf->global->LDAP_KEY_GROUPS==$conf->global->LDAP_GROUP_FIELD_GROUPMEMBERS)?' checked':'')."></td>";
178 print '</tr>';
179 
180 print '</table>';
181 
182 print info_admin($langs->trans("LDAPDescValues"));
183 
184 dol_fiche_end();
185 
186 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></div>';
187 
188 print '</form>';
189 
190 
191 /*
192  * Test de la connexion
193  */
194 if ($conf->global->LDAP_SYNCHRO_ACTIVE == 'dolibarr2ldap')
195 {
196  $butlabel=$langs->trans("LDAPTestSynchroGroup");
197  $testlabel='testgroup';
198  $key=$conf->global->LDAP_KEY_GROUPS;
199  $dn=$conf->global->LDAP_GROUP_DN;
200  $objectclass=$conf->global->LDAP_GROUP_OBJECT_CLASS;
201 
202  show_ldap_test_button($butlabel,$testlabel,$key,$dn,$objectclass);
203 }
204 
205 if (function_exists("ldap_connect"))
206 {
207  if ($_GET["action"] == 'testgroup')
208  {
209  // Creation objet
210  $object=new UserGroup($db);
211  $object->initAsSpecimen();
212 
213  // Test synchro
214  $ldap=new Ldap();
215  $result=$ldap->connect_bind();
216 
217  if ($result > 0)
218  {
219  $info=$object->_load_ldap_info();
220  $dn=$object->_load_ldap_dn($info);
221 
222  // Get a gid number for objectclass PosixGroup
223  if (in_array('posixGroup',$info['objectclass'])) {
224  $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
225  }
226 
227  $result1=$ldap->delete($dn); // To be sure to delete existing records
228  $result2=$ldap->add($dn,$info,$user); // Now the test
229  $result3=$ldap->delete($dn); // Clean what we did
230 
231  if ($result2 > 0)
232  {
233  print img_picto('','info').' ';
234  print '<font class="ok">'.$langs->trans("LDAPSynchroOK").'</font><br>';
235  }
236  else
237  {
238  print img_picto('','error').' ';
239  print '<font class="error">'.$langs->trans("LDAPSynchroKOMayBePermissions");
240  print ': '.$ldap->error;
241  print '</font><br>';
242  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
243  }
244 
245  print "<br>\n";
246  print "LDAP input file used for test:<br><br>\n";
247  print nl2br($ldap->dump_content($dn,$info));
248  print "\n<br>";
249  }
250  else
251  {
252  print img_picto('','error').' ';
253  print '<font class="error">'.$langs->trans("LDAPSynchroKO");
254  print ': '.$ldap->error;
255  print '</font><br>';
256  print $langs->trans("ErrorLDAPMakeManualTest",$conf->ldap->dir_temp).'<br>';
257  }
258  }
259 }
260 
261 llxFooter();
262 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:485
Class to manage user groups.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
show_ldap_test_button($butlabel, $testlabel, $key, $dn, $objectclass)
Show button test LDAP synchro.
Definition: ldap.lib.php:106
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage LDAP features.
Definition: ldap.class.php:30
print
Draft customers invoices.
Definition: index.php:91
ldap_prepare_head()
Initialize the array of tabs for customer invoice.
Definition: ldap.lib.php:31