-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgroup.inc
449 lines (417 loc) · 13.5 KB
/
group.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<?php
use \LAM\TYPES\TypeManager;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2005 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* The account type for group accounts (e.g. Unix and Samba).
*
* @package types
* @author Roland Gruber
* @author Ludek Finstrle
*/
/**
* The account type for group accounts (e.g. Unix and Samba).
*
* @package types
*/
class group extends baseType {
/**
* Constructs a new group type object.
*
* @param ConfiguredType $type configuration
*/
public function __construct($type) {
parent::__construct($type);
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another group');
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to group list');
if ($this->getType() != null) {
$modules = $this->getType()->getModules();
if (in_array('organizationalRole', $modules)) {
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another role');
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to role list');
}
}
}
/**
* Returns the alias name of this account type.
*
* @return string alias name
*/
function getAlias() {
if ($this->getType() != null) {
$modules = $this->getType()->getModules();
if (in_array('organizationalRole', $modules)) {
return _('Roles');
}
}
return _("Groups");
}
/**
* Returns the description of this account type.
*
* @return string description
*/
function getDescription() {
return _("Group accounts (e.g. Unix and Samba)");
}
/**
* Returns the class name for the list object.
*
* @return string class name
*/
function getListClassName() {
return "lamGroupList";
}
/**
* Returns the default attribute list for this account type.
*
* @return string attribute list
*/
function getDefaultListAttributes() {
return "#cn;#gidNumber;#memberUID;#description";
}
/**
* Returns a list of attributes which have a translated description.
* This is used for the head row in the list view.
*
* @return array list of descriptions
*/
function getListAttributeDescriptions() {
$return = array_merge(
parent::getListAttributeDescriptions(),
array(
"cn" => _("Group name"),
"description" => _("Group description"),
"displayName" => _("Display name"),
"gidnumber" => _("GID number"),
"member" => _("Group member DNs"),
"memberuid" => _("Group members"),
"roleOccupant" => _("Role member DNs"),
"uniqueMember" => _("Group member DNs"),
"memberUrl" => _("Entries"),
));
if ($this->getType() != null) {
$modules = $this->getType()->getModules();
if (in_array('organizationalRole', $modules)) {
$return['cn'] = _('Role name');
}
}
return $return;
}
/**
* Returns the the title text for the title bar on the new/edit page.
*
* @param accountContainer $container account container
* @return String title text
*/
public function getTitleBarTitle($container) {
// get attributes
$attributes = null;
if ($container->getAccountModule('posixGroup') != null) {
$attributes = $container->getAccountModule('posixGroup')->getAttributes();
}
elseif ($container->getAccountModule('rfc2307bisPosixGroup') != null) {
$attributes = $container->getAccountModule('rfc2307bisPosixGroup')->getAttributes();
}
elseif ($container->getAccountModule('windowsGroup') != null) {
$attributes = $container->getAccountModule('windowsGroup')->getAttributes();
}
$gonAttributes = null;
if ($container->getAccountModule('groupOfNames') != null) {
$gonAttributes = $container->getAccountModule('groupOfNames')->getAttributes();
}
elseif ($container->getAccountModule('groupOfUniqueNames') != null) {
$gonAttributes = $container->getAccountModule('groupOfUniqueNames')->getAttributes();
}
elseif ($container->getAccountModule('organizationalRole') != null) {
$gonAttributes = $container->getAccountModule('organizationalRole')->getAttributes();
}
// check if a group name is set
if (isset($attributes['gid'][0])) {
return htmlspecialchars($attributes['gid'][0]);
}
// check if a common name is set
if (isset($attributes['cn'][0])) {
return htmlspecialchars($attributes['cn'][0]);
}
if (isset($gonAttributes['cn'][0])) {
return htmlspecialchars($gonAttributes['cn'][0]);
}
// new entry
if ($container->isNewAccount) {
return _("New group");
}
// fall back to default
return parent::getTitleBarTitle($container);
}
/**
* Returns the the title text for the title bar on the new/edit page.
*
* @param accountContainer $container account container
* @return String title text
*/
public function getTitleBarSubtitle($container) {
// get attributes
$attributes = null;
if ($container->getAccountModule('posixGroup') != null) {
$attributes = $container->getAccountModule('posixGroup')->getAttributes();
}
elseif ($container->getAccountModule('rfc2307bisPosixGroup') != null) {
$attributes = $container->getAccountModule('rfc2307bisPosixGroup')->getAttributes();
}
elseif ($container->getAccountModule('windowsGroup') != null) {
$attributes = $container->getAccountModule('windowsGroup')->getAttributes();
}
$gonAttributes = null;
if ($container->getAccountModule('groupOfNames') != null) {
$gonAttributes = $container->getAccountModule('groupOfNames')->getAttributes();
}
elseif ($container->getAccountModule('groupOfUniqueNames') != null) {
$gonAttributes = $container->getAccountModule('groupOfUniqueNames')->getAttributes();
}
elseif ($container->getAccountModule('organizationalRole') != null) {
$gonAttributes = $container->getAccountModule('organizationalRole')->getAttributes();
}
// check if an description can be shown
if (($attributes != null) && isset($attributes['description'][0])) {
return htmlspecialchars($attributes['description'][0]);
}
if (($gonAttributes != null) && isset($gonAttributes['description'][0])) {
return htmlspecialchars($gonAttributes['description'][0]);
}
return null;
}
}
/**
* Generates the list view.
*
* @package lists
* @author Roland Gruber
*
*/
class lamGroupList extends lamList {
/** Controls if include primary group members into group memebers */
private $use_primary = false;
/** Primary group members hash */
private $primary_hash = array();
/** Controls if primary group members needs refresh */
private $refresh_primary = false;
/** ID for config option */
const TRANS_PRIMARY_OPTION_NAME = "LG_TP";
/** specifies if primary group members are visible */
private $include_primary = false;
/** LDAP suffix of membership types */
private $suffixList = array();
/**
* Constructor
*
* @param string $type account type
* @return lamList list object
*/
function __construct($type) {
parent::__construct($type);
$this->labels = array(
'nav' => _("Group count: %s"),
'error_noneFound' => _("No groups found!"),
'newEntry' => _("New group"),
'deleteEntry' => _("Delete selected groups"));
$modules = $this->type->getModules();
if (in_array('organizationalRole', $modules)) {
$this->labels = array(
'nav' => _("Role count: %s"),
'error_noneFound' => _("No roles found!"),
'newEntry' => _("New role"),
'deleteEntry' => _("Delete selected roles"));
}
// build suffix list for account types
$typeManager = new TypeManager();
$scopes = array('user', 'gon', 'group');
$types = $typeManager->getConfiguredTypesForScopes($scopes);
foreach ($types as $type) {
$suffix = $type->getSuffix();
// stop if suffixes are not unique
if (isset($this->suffixList[$suffix])) {
$this->suffixList = array();
break;
}
if (!empty($suffix)) {
$this->suffixList[$suffix] = $type->getId();
}
}
}
/**
* Sets some internal parameters.
*/
function listGetParams() {
parent::listGetParams();
// generate list primary group memebers
// after parent::listGetParams is $this->refresh set to correct value
if ($this->include_primary && !$this->refresh && ($this->refresh_primary || (sizeof($this->primary_hash) == 0)))
$this->groupRefreshPrimary();
}
/**
* {@inheritDoc}
* @see lamList::getTableCellContent()
*/
protected function getTableCellContent(&$entry, &$attribute) {
if ($attribute == "memberuid") {
// $gid is used for linking primary group memebers
$gid = -1;
$use_primary = false;
if ($this->include_primary == "on") {
// Get the gid number
if (isset($entry['gidnumber']) && is_array($entry['gidnumber'])) {
$gid = $entry['gidnumber'][0];
}
$use_primary = (($gid >= 0) && (sizeof($this->primary_hash) > 0) &&
isset($this->primary_hash[$gid]) && is_array($this->primary_hash[$gid]) &&
(sizeof($this->primary_hash[$gid]) > 0));
}
if (!$use_primary) {
if (!isset($entry[$attribute]) || !is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1)) return;
// sort array
sort($entry[$attribute]);
}
// make a link for each member of the group
$linklist = array();
if ($use_primary) {
$primary_hash = $this->primary_hash[$gid];
// merge primary members into secondary ones
$primaryvals = array_flip(array_values($primary_hash));
// test if group has some secondary members
if (isset($entry[$attribute])) {
$attr = array_merge($primary_hash,$entry[$attribute]);
}
else {
$attr = $primary_hash;
}
// sort array
sort($attr);
// make a link for each member of the group
for ($d = 0; $d < sizeof($attr); $d++) {
$user = $attr[$d]; // user name
if (isAccountTypeHidden('user')) {
$linklist[$d] = $user;
}
elseif (isset($primaryvals[$user])) {
$linklist[$d] = "<b><a href=\"userlink.php?user='" . $user . "' \">" . $user . "</a></b>";
}
else {
$linklist[$d] = "<a href=\"userlink.php?user='" . $user . "' \">" . $user . "</a>";
}
}
}
else {
// make a link for each member of the group
for ($d = 0; $d < sizeof($entry[$attribute]); $d++) {
$user = $entry[$attribute][$d]; // user name
if (!isAccountTypeHidden('user')) {
$linklist[$d] = "<a href=\"userlink.php?user='" . $user . "' \">" . $user . "</a>";
}
else {
$linklist[$d] = $user;
}
}
}
return new htmlOutputText(implode("; ", $linklist), false);
}
// pretty print member DNs
elseif (in_array_ignore_case($attribute, array('member', 'uniqueMember', 'owner', 'roleOccupant')) && !empty($entry[$attribute])) {
$values = $entry[$attribute];
if (!empty($values)) {
usort($values, 'compareDN');
}
$count = sizeof($values);
for ($i = 0; $i < $count; $i++) {
$replaced = false;
foreach ($this->suffixList as $suffix => $type) {
if (stripos($values[$i], $suffix) > 0) {
if (!isAccountTypeHidden($type)) {
$values[$i] = '<a style="display:inline-block;" href="../account/edit.php?type=' . $type . '&DN=\'' . $values[$i] . '\'">' . explode(">", getAbstractDN($values[$i]))[0] . '</a>; ';
$replaced = true;
break;
}
}
}
if (!$replaced) {
$values[$i] = getAbstractDN($values[$i]);
}
}
return new htmlDiv(null, new htmlOutputText(implode('', $values), false), array('rightToLeftText'));
}
// print all other attributes
else {
return parent::getTableCellContent($entry, $attribute);
}
}
/**
* Rereads the entries from LDAP.
*/
function listRefreshData() {
parent::listRefreshData();
if ($this->include_primary) {
$this->groupRefreshPrimary();
}
}
/**
* Refreshes the primary group members list.
*/
function groupRefreshPrimary() {
$this->refresh_primary = false;
// return unless some entries
if (sizeof($this->ldapEntries) <= 0) {
return;
}
$scope = "user";
// configure search filter
$module_filter = get_ldap_filter($scope); // basic filter is provided by modules
$attrs = array( "uid" );
for ($i = 0; $i < sizeof($this->ldapEntries); $i++) {
if (empty($this->ldapEntries[$i]['gidnumber'][0])) {
continue;
}
$gid = $this->ldapEntries[$i]['gidnumber'][0];
$filter = "(&(&" . $module_filter . ")(gidNumber=" . $gid . "))";
$entries = searchLDAPByFilter($filter, $attrs, array($scope));
for ($j = 0; $j < sizeof($entries); $j++) {
$this->primary_hash[$gid][$j] = $entries[$j]['uid'][0];
}
}
}
/**
* Returns a list of possible configuration options.
*
* @return array list of lamListOption objects
*/
protected function listGetAllConfigOptions() {
$options = parent::listGetAllConfigOptions();
$options[] = new lamBooleanListOption(_('Show primary group members as normal group members'), self::TRANS_PRIMARY_OPTION_NAME);
return $options;
}
/**
* Called when the configuration options changed.
*/
protected function listConfigurationChanged() {
parent::listConfigurationChanged();
$tpOption = $this->listGetConfigOptionByID(self::TRANS_PRIMARY_OPTION_NAME);
$use_primary = $this->include_primary;
$this->include_primary = $tpOption->isSelected();
if (!$use_primary && $this->include_primary) {
$this->refresh_primary = true;
}
}
}
?>