Debian Codegraph @

lib/modules/windowsGroup.inc

raw
1 <?php
2
3 use LAM\PDF\PDFTable;
4 use LAM\PDF\PDFTableCell;
5 use LAM\PDF\PDFTableRow;
6 use LAM\TYPES\ConfiguredType;
7 use LAM\TYPES\TypeManager;
8
9 /*
10
11 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
12 Copyright (C) 2013 - 2026 Roland Gruber
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */
28
29 /**
30 * Manages Windows AD (e.g. Samba 4) groups.
31 *
32 * @package modules
33 * @author Roland Gruber
34 */
35
36 /**
37 * Manages Windows AD (e.g. Samba 4) groups.
38 *
39 * @package modules
40 */
41 class windowsGroup extends baseModule {
42
43 /**
44 * These attributes will be ignored by default if a new account is copied from an existing one.
45 */
46 private const ATTRIBUTES_TO_IGNORE_ON_COPY = ['sAMAccountName', 'msSFU30Name', 'msSFU30NisDomain'];
47
48 /** @var array<string, string> $groupTypes possible group types (e.g. distribution) */
49 private array $groupTypes;
50 /** @var array<string, string> $groupScopes possible group scopes (e.g. universal) */
51 private array $groupScopes;
52 /** @var string[]|null $groupCache group cache */
53 private ?array $groupCache = null;
54
55 /** security group */
56 const TYPE_SECURITY = 'security';
57 /** email list */
58 const TYPE_DISTRIBUTION = 'distribution';
59 /** domain local group */
60 const SCOPE_DOMAIN_LOCAL = 'domain';
61 /** global group */
62 const SCOPE_GLOBAL = 'global';
63 /** universal group */
64 const SCOPE_UNIVERSAL = 'universal';
65
66 /**
67 * Creates a new module for Samba 3 groups.
68 *
69 * @param string $scope account type
70 */
71 public function __construct($scope) {
72 $this->groupTypes = [
73 _('Security') => windowsGroup::TYPE_SECURITY,
74 _('Distribution') => windowsGroup::TYPE_DISTRIBUTION,
75 ];
76 $this->groupScopes = [
77 _('Domain local') => windowsGroup::SCOPE_DOMAIN_LOCAL,
78 _('Global') => windowsGroup::SCOPE_GLOBAL,
79 _('Universal') => windowsGroup::SCOPE_UNIVERSAL,
80 ];
81 // call parent constructor
82 parent::__construct($scope);
83 }
84
85 /**
86 * {@inheritDoc}
87 */
88 public function can_manage(): bool {
89 return $this->get_scope() === 'group';
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 public function get_metaData(): array {
96 $return = [];
97 // icon
98 $return['icon'] = 'samba.svg';
99 // this is a base module
100 $return["is_base"] = true;
101 // RDN attribute
102 $return["RDN"] = ["cn" => "high"];
103 // LDAP filter
104 $return["ldap_filter"] = ['and' => "", 'or' => '(objectClass=group)'];
105 // alias name
106 $return["alias"] = _("Windows");
107 // module dependencies
108 $return['dependencies'] = ['depends' => [], 'conflicts' => []];
109 // managed object classes
110 $return['objectClasses'] = ['group', 'securityPrincipal', 'mailRecipient'];
111 // managed attributes
112 $return['attributes'] = ['cn', 'description', 'info', 'mail', 'member', 'memberOf', 'sAMAccountName',
113 'groupType', 'managedBy', 'msSFU30Name', 'msSFU30NisDomain'];
114 // help Entries
115 $return['help'] = [
116 'hiddenOptions' => [
117 "Headline" => _("Hidden options"),
118 "Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.")
119 ],
120 'cn' => [
121 "Headline" => _('Group name'), 'attr' => 'cn, sAMAccountName',
122 "Text" => _('Please enter the group name.')
123 ],
124 'description' => [
125 "Headline" => _('Description'), 'attr' => 'description',
126 "Text" => _('Please enter a descriptive text for this group.')
127 ],
128 'info' => [
129 "Headline" => _('Notes'), 'attr' => 'info',
130 "Text" => _('Additional notes to describe this entry.')
131 ],
132 'mail' => [
133 "Headline" => _('Email address'), 'attr' => 'mail',
134 "Text" => _('The list\'s email address.')
135 ],
136 'member' => [
137 "Headline" => _('Members'), 'attr' => 'member',
138 "Text" => _('This is a list of members of this group.')
139 ],
140 'memberOf' => [
141 "Headline" => _('Member of'), 'attr' => 'memberOf',
142 "Text" => _('This is a list of groups this group is member of.')
143 ],
144 'memberList' => [
145 "Headline" => _('Members'), 'attr' => 'member',
146 "Text" => _('This is a list of members of this group. Multiple members are separated by semicolons.')
147 ],
148 'groupType' => [
149 "Headline" => _('Group type'), 'attr' => 'groupType',
150 "Text" => _('Security groups are used for permission management and distribution groups as email lists.')
151 ],
152 'groupScope' => [
153 "Headline" => _('Group scope'), 'attr' => 'groupType',
154 "Text" => _('Please specify the group scope.')
155 ],
156 'managedBy' => [
157 "Headline" => _('Managed by'), 'attr' => 'managedBy',
158 "Text" => _('The group is managed by this contact person.')
159 ],
160 'msSFU30Name' => [
161 "Headline" => _('NIS name'), 'attr' => 'msSFU30Name',
162 "Text" => _('Group name for NIS.')
163 ],
164 'msSFU30NisDomain' => [
165 "Headline" => _('NIS domain'), 'attr' => 'msSFU30NisDomain',
166 "Text" => _('NIS domain name.')
167 ],
168 'filter' => [
169 "Headline" => _("Filter"),
170 "Text" => _("Here you can enter a filter value. Only entries which contain the filter text will be shown.")
171 . ' ' . _('Possible wildcards are: "*" = any character, "^" = line start, "$" = line end')
172 ],
173 ];
174 // upload fields
175 $return['upload_columns'] = [
176 [
177 'name' => 'windowsGroup_name',
178 'description' => _('Group name'),
179 'help' => 'cn',
180 'example' => _('Domain administrators'),
181 'required' => true
182 ],
183 [
184 'name' => 'windowsGroup_description',
185 'description' => _('Description'),
186 'help' => 'description',
187 'example' => _('Domain administrators'),
188 ],
189 [
190 'name' => 'windowsGroup_notes',
191 'description' => _('Notes'),
192 'help' => 'info',
193 'example' => _('Domain administrators'),
194 ],
195 [
196 'name' => 'windowsGroup_scope',
197 'description' => _('Group scope'),
198 'help' => 'groupScope',
199 'values' => implode(', ', array_values($this->groupScopes)),
200 'example' => windowsGroup::SCOPE_GLOBAL,
201 'default' => windowsGroup::SCOPE_GLOBAL,
202 ],
203 [
204 'name' => 'windowsGroup_type',
205 'description' => _('Group type'),
206 'help' => 'groupType',
207 'values' => implode(', ', array_values($this->groupTypes)),
208 'example' => windowsGroup::TYPE_SECURITY,
209 'default' => windowsGroup::TYPE_SECURITY,
210 ],
211 [
212 'name' => 'windowsGroup_members',
213 'description' => _('Members'),
214 'help' => 'memberList',
215 'example' => 'uid=user1,o=test;uid=user2,o=test',
216 ],
217 ];
218 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
219 $return['upload_columns'][] = [
220 'name' => 'windowsGroup_mail',
221 'description' => _('Email address'),
222 'help' => 'mail',
223 'example' => _('[email protected]'),
224 ];
225 }
226 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemanagedBy')) {
227 $return['upload_columns'][] = [
228 'name' => 'windowsGroup_managedBy',
229 'description' => _('Managed by'),
230 'help' => 'managedBy',
231 'example' => 'cn=user1,o=test',
232 ];
233 }
234 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true)) {
235 $return['upload_columns'][] = [
236 'name' => 'windowsGroup_msSFU30Name',
237 'description' => _('NIS name'),
238 'help' => 'msSFU30Name',
239 'example' => _('adminstrators'),
240 ];
241 }
242 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30NisDomain', true)) {
243 $return['upload_columns'][] = [
244 'name' => 'windowsGroup_msSFU30NisDomain',
245 'description' => _('NIS domain'),
246 'help' => 'msSFU30NisDomain',
247 'example' => _('domain'),
248 ];
249 }
250 // profile options
251 $profileContainer = new htmlResponsiveRow();
252 $profileContainer->add(new htmlResponsiveInputField(_('Description'),'windowsGroup_description', '', 'description'));
253 $return['profile_mappings']['windowsGroup_description'] = 'description';
254 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
255 $profileContainer->add(new htmlResponsiveInputField(_('Email address'),'windowsGroup_mail', '', 'mail'));
256 $return['profile_mappings']['windowsGroup_mail'] = 'mail';
257 }
258 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30NisDomain', true)) {
259 $profileContainer->add(new htmlResponsiveInputField(_('NIS domain'), 'windowsGroup_msSFU30NisDomain', null, 'msSFU30NisDomain'));
260 $return['profile_mappings']['windowsGroup_msSFU30NisDomain'] = 'msSFU30NisDomain';
261 }
262 $return['profile_options'] = $profileContainer;
263 // available PDF fields
264 $return['PDF_fields'] = [
265 'cn' => _('Group name'),
266 'description' => _('Description'),
267 'info' => _('Notes'),
268 'member' => _('Members'),
269 'memberOf' => _('Member of'),
270 'groupType' => _('Group type'),
271 'groupScope' => _('Group scope'),
272 ];
273 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
274 $return['PDF_fields']['mail'] = _('Email address');
275 }
276 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemanagedBy')) {
277 $return['PDF_fields']['managedBy'] = _('Managed by');
278 }
279 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true)) {
280 $return['PDF_fields']['msSFU30Name'] = _('NIS name');
281 }
282 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30NisDomain', true)) {
283 $return['PDF_fields']['msSFU30NisDomain'] = _('NIS domain');
284 }
285 return $return;
286 }
287
288 /**
289 * {@inheritDoc}
290 */
291 protected function load_Messages(): void {
292 $this->messages['cn'][0] = ['ERROR', _('Group name'), _('Group name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
293 $this->messages['cn'][1] = ['ERROR', _('Account %s:') . ' windowsGroup_cn', _('Group name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
294 $this->messages['mail'][0] = ['ERROR', _('Email address'), _('Please enter a valid email address!')];
295 $this->messages['mail'][1] = ['ERROR', _('Account %s:') . ' windowsGroup_mail', _('Please enter a valid email address!')];
296 $this->messages['groupScope'][0] = ['ERROR', _('Account %s:') . ' windowsGroup_groupScope', _('Please enter a valid group scope.')];
297 $this->messages['groupType'][0] = ['ERROR', _('Account %s:') . ' windowsGroup_groupType', _('Please enter a valid group type.')];
298 $this->messages['msSFU30Name'][0] = ['ERROR', _('NIS name'), _('NIS name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
299 $this->messages['msSFU30Name'][1] = ['ERROR', _('Account %s:') . ' windowsGroup_msSFU30Name', _('NIS name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
300 }
301
302 /**
303 * {@inheritDoc}
304 */
305 public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void {
306 parent::loadAttributesFromAccountCopy($ldapAttributes, array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY));
307 }
308
309 /**
310 * {@inheritDoc}
311 */
312 public function display_html_attributes(): htmlElement|array {
313 $container = new htmlResponsiveRow();
314 $this->addSimpleInputTextField($container, 'cn', _('Group name'), true);
315 $this->addSimpleInputTextField($container, 'description', _('Description'));
316 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
317 $this->addSimpleInputTextField($container, 'mail', _('Email address'));
318 }
319 // group type
320 $groupType = windowsGroup::TYPE_SECURITY;
321 $groupScope = windowsGroup::SCOPE_GLOBAL;
322 if (isset($this->attributes['groupType'][0])) {
323 if ((((int) $this->attributes['groupType'][0]) & 4) !== 0) {
324 $groupScope = windowsGroup::SCOPE_DOMAIN_LOCAL;
325 }
326 elseif ((((int) $this->attributes['groupType'][0]) & 8) !== 0) {
327 $groupScope = windowsGroup::SCOPE_UNIVERSAL;
328 }
329 if ((((int) $this->attributes['groupType'][0]) & 0x80000000) === 0) {
330 $groupType = windowsGroup::TYPE_DISTRIBUTION;
331 }
332 }
333 $scopeList = $this->groupScopes;
334 // do not allow invalid conversions
335 if (isset($this->orig['groupType'][0])) {
336 $flippedScopes = array_flip($this->groupScopes);
337 if ((((int) $this->orig['groupType'][0]) & 2) !== 0) {
338 // no change from global to domain local
339 unset($scopeList[$flippedScopes[windowsGroup::SCOPE_DOMAIN_LOCAL]]);
340 }
341 elseif ((((int) $this->orig['groupType'][0]) & 4) !== 0) {
342 // no change from domain local to global
343 unset($scopeList[$flippedScopes[windowsGroup::SCOPE_GLOBAL]]);
344 }
345 }
346 $groupScopeSelect = new htmlResponsiveSelect('groupScope', $scopeList, [$groupScope], _('Group scope'), 'groupScope');
347 $groupScopeSelect->setHasDescriptiveElements(true);
348 $container->add($groupScopeSelect);
349 $groupTypeSelect = new htmlResponsiveSelect('groupType', $this->groupTypes, [$groupType], _('Group type'), 'groupType');
350 $groupTypeSelect->setHasDescriptiveElements(true);
351 $container->add($groupTypeSelect);
352 // notes
353 $this->addSimpleInputTextField($container, 'info', _('Notes'), false, null, true);
354 // managed by
355 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemanagedBy')) {
356 $container->addLabel(new htmlOutputText(_('Managed by')));
357 $managedBy = '-';
358 if (isset($this->attributes['managedBy'][0])) {
359 $managedBy = $this->attributes['managedBy'][0];
360 }
361 $managedByGroup = new htmlGroup();
362 $managedByGroup->addElement(new htmlOutputText(getAbstractDN($managedBy)));
363 $managedByGroup->addElement(new htmlSpacer('0.5rem', null));
364 $managedByGroup->addElement(new htmlHelpLink('managedBy'));
365 $container->addField($managedByGroup);
366 $managedByButtons = new htmlGroup();
367 $managedByButtons->addElement(new htmlAccountPageButton(static::class, 'managedBy', 'edit', _('Change')));
368 if (isset($this->attributes['managedBy'][0])) {
369 $managedByButtons->addElement(new htmlSpacer('5px', null));
370 $managedByButtons->addElement(new htmlAccountPageButton(static::class, 'attributes', 'removeManagedBy', _('Remove')));
371 }
372 $container->addLabel(new htmlOutputText('&nbsp;', false));
373 $container->addField($managedByButtons);
374 }
375 // NIS
376 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true) || !$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30NisDomain', true)) {
377 $container->add(new htmlSubTitle(_('NIS')));
378 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true)) {
379 $this->addSimpleInputTextField($container, 'msSFU30Name', _('NIS name'));
380 }
381 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30NisDomain', true)) {
382 $this->addSimpleInputTextField($container, 'msSFU30NisDomain', _('NIS domain'));
383 }
384 $container->addVerticalSpacer('2rem');
385 }
386 // group members
387 $container->addVerticalSpacer('1rem');
388 $container->addLabel(new htmlOutputText(_("Group members")));
389 $memberButtons = new htmlGroup();
390 $memberButtons->addElement(new htmlAccountPageButton(static::class, 'user', 'open', _('Edit')));
391 if (!empty($this->attributes['member'])) {
392 $memberButtons->addElement(new htmlSpacer('0.5rem', null));
393 $memberButtons->addElement(new htmlAccountPageButton(static::class, 'effectiveMembers', 'open', _('Show effective members')));
394 }
395 $memberButtons->addElement(new htmlSpacer('0.5rem', null));
396 $memberButtons->addElement(new htmlHelpLink('member'));
397 $container->addField($memberButtons);
398 $memberList = [];
399 if (isset($this->attributes['member'])) {
400 for ($i = 0; $i < count($this->attributes['member']); $i++) {
401 $memberList[] = $this->attributes['member'][$i];
402 }
403 usort($memberList, compareDN(...));
404 }
405 $members = new htmlTable();
406 $members->alignment = htmlElement::ALIGN_RIGHT;
407 $members->setCSSClasses(['fullwidth']);
408 for ($i = 0; $i < count($memberList); $i++) {
409 $member = new htmlOutputText(getAbstractDN($memberList[$i]));
410 $member->alignment = htmlElement::ALIGN_RIGHT;
411 $members->addElement($member, true);
412 }
413 $container->addLabel(new htmlOutputText('&nbsp;', false));
414 $container->addField($members);
415 // member of
416 $container->addVerticalSpacer('2rem');
417 $container->addLabel(new htmlOutputText(_("Member of")));
418 $memberOfGroup = new htmlGroup();
419 $memberOfGroup->addElement(new htmlAccountPageButton(static::class, 'memberof', 'open', _('Edit')));
420 $memberOfGroup->addElement(new htmlSpacer('0.5rem', null));
421 $memberOfGroup->addElement(new htmlHelpLink('memberOf'));
422 $container->addField($memberOfGroup);
423 $memberList = [];
424 if (isset($this->attributes['memberOf'])) {
425 for ($i = 0; $i < count($this->attributes['memberOf']); $i++) {
426 $memberList[] = $this->attributes['memberOf'][$i];
427 }
428 usort($memberList, compareDN(...));
429 }
430 $memberOf = new htmlTable();
431 $memberOf->setCSSClasses(['fullwidth']);
432 $memberOf->alignment = htmlElement::ALIGN_RIGHT;
433 for ($i = 0; $i < count($memberList); $i++) {
434 $member = new htmlOutputText(getAbstractDN($memberList[$i]));
435 $member->alignment = htmlElement::ALIGN_RIGHT;
436 $memberOf->addElement($member, true);
437 }
438 $container->addLabel(new htmlOutputText('&nbsp;', false));
439 $container->addField($memberOf);
440
441 return $container;
442 }
443
444 /**
445 * {@inheritDoc}
446 */
447 public function process_attributes(): array {
448 $this->getAccountContainer()->replaceWildcardsInPOST($this->getWildcardTargetAttributeNames());
449 $return = [];
450 // cn
451 $this->attributes['cn'][0] = $_POST['cn'];
452 $this->attributes['sAMAccountName'][0] = $_POST['cn'];
453 if (!get_preg($_POST['cn'], 'groupname')) {
454 $return[] = $this->messages['cn'][0];
455 }
456 // description
457 $this->attributes['description'][0] = $_POST['description'];
458 // email
459 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
460 $this->attributes['mail'][0] = $_POST['mail'];
461 if (!empty($_POST['mail']) && !get_preg($_POST['mail'], 'email')) {
462 $return[] = $this->messages['mail'][0];
463 }
464 }
465 // group scope
466 switch ($_POST['groupScope']) {
467 case windowsGroup::SCOPE_DOMAIN_LOCAL:
468 $this->attributes['groupType'][0] = 4;
469 break;
470 case windowsGroup::SCOPE_GLOBAL:
471 $this->attributes['groupType'][0] = 2;
472 break;
473 case windowsGroup::SCOPE_UNIVERSAL:
474 $this->attributes['groupType'][0] = 8;
475 break;
476 }
477 // group type
478 if ($_POST['groupType'] == windowsGroup::TYPE_SECURITY) {
479 $this->attributes['groupType'][0] -= 2147483648;
480 }
481 // notes
482 $this->attributes['info'][0] = $_POST['info'];
483 // managed by
484 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemanagedBy') && isset($_POST['form_subpage_' . static::class . '_attributes_removeManagedBy'])) {
485 unset($this->attributes['managedBy']);
486 }
487 // NIS name
488 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true)) {
489 if ($this->getAccountContainer()->isNewAccount && !isset($this->attributes['msSFU30Name']) && empty($_POST['msSFU30Name'])) {
490 $this->attributes['msSFU30Name'][0] = $_POST['cn'];
491 }
492 else {
493 $this->attributes['msSFU30Name'][0] = $_POST['msSFU30Name'];
494 }
495 if (!empty($this->attributes['msSFU30Name'][0]) && !get_preg($this->attributes['msSFU30Name'][0], 'groupname')) {
496 $return[] = $this->messages['msSFU30Name'][0];
497 }
498 }
499 // NIS domain
500 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true)) {
501 $this->attributes['msSFU30NisDomain'][0] = $_POST['msSFU30NisDomain'];
502 }
503 return $return;
504 }
505
506 /**
507 * Displays the memberof selection.
508 *
509 * @return htmlElement meta HTML code
510 */
511 public function display_html_memberof(): htmlElement {
512 $return = new htmlResponsiveRow();
513 $return->add(new htmlSubTitle(_("Groups")));
514 $groups = $this->findGroups();
515 // sort by DN
516 usort($groups, compareDN(...));
517
518 $selectedGroups = [];
519 if (empty($this->attributes['memberOf'])) {
520 $this->attributes['memberOf'] = [];
521 }
522 // sort by DN
523 usort($this->attributes['memberOf'], compareDN(...));
524 for ($i = 0; $i < count($this->attributes['memberOf']); $i++) {
525 if (in_array($this->attributes['memberOf'][$i], $groups)) {
526 $selectedGroups[getAbstractDN($this->attributes['memberOf'][$i])] = $this->attributes['memberOf'][$i];
527 }
528 }
529 $availableGroups = [];
530 foreach ($groups as $dn) {
531 if (!in_array($dn, $this->attributes['memberOf'])) {
532 $availableGroups[getAbstractDN($dn)] = $dn;
533 }
534 }
535
536 $this->addDoubleSelectionArea($return, _("Selected groups"), _("Available groups"), $selectedGroups,
537 [], $availableGroups, [], 'memberof', false, true);
538
539 $return->addVerticalSpacer('2rem');
540 $backButton = new htmlAccountPageButton(static::class, 'attributes', 'back', _('Back'));
541 $return->add($backButton);
542
543 return $return;
544 }
545
546 /**
547 * Processes user input of the memberof selection page.
548 * It checks if all input values are correct and updates the associated LDAP attributes.
549 *
550 * @return string[][] list of info/error messages
551 */
552 public function process_memberof(): array {
553 if (isset($_POST['memberof_2']) && isset($_POST['memberof_left'])) { // Add groups to list
554 // add new group
555 $this->attributes['memberOf'] = @array_merge($this->attributes['memberOf'], $_POST['memberof_2']);
556 }
557 elseif (isset($_POST['memberof_1']) && isset($_POST['memberof_right'])) { // remove groups from list
558 $this->attributes['memberOf'] = array_delete($_POST['memberof_1'], $this->attributes['memberOf']);
559 }
560 return [];
561 }
562
563 /**
564 * This function will create the meta HTML code to show a page to change the member attribute.
565 *
566 * @return htmlElement HTML meta data
567 */
568 public function display_html_managedBy(): htmlElement {
569 $return = new htmlResponsiveRow();
570 // show possible managers
571 $options = [];
572 $filter = get_ldap_filter('user');
573 $entries = searchLDAPByFilter($filter, ['dn'], ['user']);
574 for ($i = 0; $i < count($entries); $i++) {
575 $entries[$i] = $entries[$i]['dn'];
576 }
577 // sort by DN
578 usort($entries, compareDN(...));
579 for ($i = 0; $i < count($entries); $i++) {
580 $options[getAbstractDN($entries[$i])] = $entries[$i];
581 }
582 $selected = [];
583 if (isset($this->attributes['managedBy'][0])) {
584 $selected = [$this->attributes['managedBy'][0]];
585 if (!in_array($selected[0], $options)) {
586 $options[getAbstractDN($selected[0])] = $selected[0];
587 }
588 }
589 $membersSelect = new htmlSelect('managedBy', $options, $selected);
590 $membersSelect->setHasDescriptiveElements(true);
591 $membersSelect->setRightToLeftTextDirection(true);
592 $membersSelect->setSortElements(false);
593 $membersSelect->setTransformSingleSelect(false);
594 $return->add($membersSelect);
595 $filterGroup = new htmlGroup();
596 $filterGroup->addElement(new htmlOutputText(_('Filter')));
597 $filterInput = new htmlInputField('filter');
598 $filterInput->filterSelectBox('managedBy');
599 $filterInput->setCSSClasses(['max-width-10']);
600 $filterGroup->addElement($filterInput);
601 $filterGroup->addElement(new htmlHelpLink('filter'));
602 $return->add($filterGroup);
603 $return->addVerticalSpacer('2rem');
604 $buttonTable = new htmlGroup();
605 $buttonTable->addElement(new htmlAccountPageButton(static::class, 'attributes', 'set', _('Change')));
606 $buttonTable->addElement(new htmlSpacer('0.5rem', null));
607 $buttonTable->addElement(new htmlAccountPageButton(static::class, 'attributes', 'cancel', _('Cancel')));
608 $return->add($buttonTable);
609 return $return;
610 }
611
612 /**
613 * Processes user input of the members page.
614 * It checks if all input values are correct and updates the associated LDAP attributes.
615 *
616 * @return string[][] list of info/error messages
617 */
618 public function process_managedBy(): array {
619 $return = [];
620 if (isset($_POST['form_subpage_' . static::class . '_attributes_set'])) {
621 $this->attributes['managedBy'][0] = $_POST['managedBy'];
622 }
623 return $return;
624 }
625
626 /**
627 * This function will create the meta HTML code to show a page to change the member attribute.
628 *
629 * @return htmlElement HTML meta data
630 */
631 public function display_html_user(): htmlElement {
632 $return = new htmlResponsiveRow();
633 $typeManager = new TypeManager();
634 // show list of possible new members
635 if (isset($_POST['form_subpage_' . static::class . '_user_select']) && isset($_POST['type'])) {
636 $type = $typeManager->getConfiguredType($_POST['type']);
637 $filterGroup = new htmlGroup();
638 $filterGroup->addElement(new htmlOutputText(_('Filter') . ' '));
639 $filter = new htmlInputField('windows_filter');
640 $filter->filterSelectBox('members');
641 $filterGroup->addElement($filter);
642 $return->add($filterGroup);
643 $return->addVerticalSpacer('1rem');
644
645 $options = [];
646 $filter = get_ldap_filter($type->getId());
647 $entries = searchLDAP($type->getSuffix(), $filter, ['dn']);
648 for ($i = 0; $i < count($entries); $i++) {
649 $entries[$i] = $entries[$i]['dn'];
650 }
651 // sort by DN
652 usort($entries, compareDN(...));
653 for ($i = 0; $i < count($entries); $i++) {
654 if (!isset($this->attributes['member']) || !in_array($entries[$i], $this->attributes['member'])) {
655 $options[getAbstractDN($entries[$i])] = $entries[$i];
656 }
657 }
658 $size = 20;
659 if (count($options) < 20) {
660 $size = count($options);
661 }
662 $membersSelect = new htmlSelect('members', $options, [], $size);
663 $membersSelect->setHasDescriptiveElements(true);
664 $membersSelect->setMultiSelect(true);
665 $membersSelect->setRightToLeftTextDirection(true);
666 $membersSelect->setSortElements(false);
667 $membersSelect->setTransformSingleSelect(false);
668 $return->add($membersSelect);
669 $return->addVerticalSpacer('2rem');
670 $buttonTable = new htmlGroup();
671 $buttonTable->addElement(new htmlAccountPageButton(static::class, 'user', 'addMembers', _('Add')));
672 $buttonTable->addElement(new htmlAccountPageButton(static::class, 'user', 'cancel', _('Cancel')));
673 $return->add($buttonTable);
674 return $return;
675 }
676 // show existing members
677 $membersTemp = [];
678 if (isset($this->attributes['member'])) {
679 $membersTemp = $this->attributes['member'];
680 }
681 // sort by DN
682 usort($membersTemp, compareDN(...));
683 $members = [];
684 for ($i = 0; $i < count($membersTemp); $i++) {
685 $members[getAbstractDN($membersTemp[$i])] = $membersTemp[$i];
686 }
687 $size = 20;
688 if (isset($this->attributes['member']) && (count($this->attributes['member']) < 20)) {
689 $size = count($this->attributes['member']);
690 }
691 if ($members !== []) {
692 $membersSelect = new htmlSelect('members', $members, [], $size);
693 $membersSelect->setHasDescriptiveElements(true);
694 $membersSelect->setMultiSelect(true);
695 $membersSelect->setRightToLeftTextDirection(true);
696 $membersSelect->setSortElements(false);
697 $membersSelect->setTransformSingleSelect(false);
698 $return->add($membersSelect);
699 $return->addVerticalSpacer('0.5rem');
700 $removeButton = new htmlAccountPageButton(static::class, 'user', 'remove', _('Remove selected entries'));
701 $return->add($removeButton);
702 $return->addVerticalSpacer('2rem');
703 $return->add(new htmlHorizontalLine());
704 $return->addVerticalSpacer('2rem');
705 }
706 $types = $typeManager->getConfiguredTypes();
707 $options = [];
708 $optionsSelected = [];
709 foreach ($types as $type) {
710 $options[$type->getAlias()] = $type->getId();
711 if ($type->getScope() == 'user') {
712 $optionsSelected[] = $type->getId();
713 }
714 }
715 $return->addLabel(new htmlOutputText(_('Add entries of this type:')));
716 $typeSelect = new htmlSelect('type', $options, $optionsSelected);
717 $typeSelect->setHasDescriptiveElements(true);
718 $return->addField($typeSelect);
719 $return->addLabel(new htmlOutputText('&nbsp;', false));
720 $return->addField(new htmlAccountPageButton(static::class, 'user', 'select', _('Ok')));
721 $return->addVerticalSpacer('2rem');
722 $return->add(new htmlAccountPageButton(static::class, 'attributes', 'membersBack', _('Back')));
723 return $return;
724 }
725
726 /**
727 * Processes user input of the members page.
728 * It checks if all input values are correct and updates the associated LDAP attributes.
729 *
730 * @return string[][] list of info/error messages
731 */
732 public function process_user(): array {
733 $return = [];
734 if (isset($_POST['form_subpage_' . static::class . '_user_remove']) && isset($_POST['members'])) {
735 $members = array_flip($this->attributes['member']);
736 for ($i = 0; $i < count($_POST['members']); $i++) {
737 if (isset($members[$_POST['members'][$i]])) {
738 unset($members[$_POST['members'][$i]]);
739 }
740 }
741 $this->attributes['member'] = array_values(array_flip($members));
742 }
743 elseif (isset($_POST['form_subpage_' . static::class . '_user_addMembers']) && isset($_POST['members'])) {
744 for ($i = 0; $i < count($_POST['members']); $i++) {
745 $this->attributes['member'][] = $_POST['members'][$i];
746 $this->attributes['member'] = array_unique($this->attributes['member']);
747 }
748 }
749 return $return;
750 }
751
752 /**
753 * This function will create the meta HTML code to show a page to list effective members.
754 *
755 * @return htmlElement HTML meta data
756 */
757 public function display_html_effectiveMembers(): htmlElement {
758 $return = new htmlResponsiveRow();
759 $effectiveMembers = $this->getEffectiveMembers();
760 $entryTable = new htmlTable();
761 // sort by DN, align right
762 usort($effectiveMembers, compareDN(...));
763 $entryTable->alignment = htmlElement::ALIGN_RIGHT;
764 foreach ($effectiveMembers as $member) {
765 $entry = new htmlOutputText(getAbstractDN($member));
766 $entry->alignment = htmlElement::ALIGN_RIGHT;
767 $entryTable->addElement($entry, true);
768 }
769 $return->add($entryTable);
770 $return->addVerticalSpacer('2rem');
771 $return->add(new htmlAccountPageButton(static::class, 'attributes', 'membersEffectiveBack', _('Back')));
772 return $return;
773 }
774
775 /**
776 * Processes user input of the effective members page.
777 *
778 * @return string[][] list of info/error messages
779 */
780 public function process_effectiveMembers(): array {
781 // no processing, page is read-only
782 return [];
783 }
784
785 /**
786 * {@inheritdoc}
787 */
788 public function getWildCardReplacements(): array {
789 $replacements = [];
790 // group name
791 if (!empty($_POST['cn'])) {
792 $replacements['group'] = $_POST['cn'];
793 }
794 elseif (!empty($this->attributes['cn'][0])) {
795 $replacements['group'] = $this->attributes['cn'][0];
796 }
797 return $replacements;
798 }
799
800 /**
801 * {@inheritdoc}
802 */
803 public function getWildcardTargetAttributeNames(): array {
804 $attrs = ['description'];
805 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
806 $attrs[] = 'mail';
807 }
808 return $attrs;
809 }
810
811 /**
812 * {@inheritDoc}
813 */
814 public function build_uploadAccounts(array $rawAccounts, array $ids, array &$partialAccounts, array $selectedModules, ConfiguredType &$type): array {
815 $errors = [];
816 for ($i = 0; $i < count($rawAccounts); $i++) {
817 // add object class
818 if (!in_array('group', $partialAccounts[$i]['objectClass'])) {
819 $partialAccounts[$i]['objectClass'][] = 'group';
820 }
821 // cn + sAMAccountName
822 if ($rawAccounts[$i][$ids['windowsGroup_name']] != "") {
823 if (get_preg($rawAccounts[$i][$ids['windowsGroup_name']], 'groupname')) {
824 $partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['windowsGroup_name']];
825 $partialAccounts[$i]['sAMAccountName'] = $rawAccounts[$i][$ids['windowsGroup_name']];
826 }
827 else {
828 $errMsg = $this->messages['cn'][1];
829 $errMsg[] = [$i];
830 $errors[] = $errMsg;
831 }
832 }
833 // description
834 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsGroup_description', 'description');
835 // notes
836 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsGroup_notes', 'info');
837 // email
838 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemail')) {
839 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsGroup_mail', 'mail',
840 'email', $this->messages['mail'][1], $errors);
841 }
842 // managed by
843 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemanagedBy')) {
844 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsGroup_managedBy', 'managedBy');
845 }
846 // add members
847 if ($rawAccounts[$i][$ids['windowsGroup_members']] != "") {
848 $partialAccounts[$i]['member'] = explode(";", $rawAccounts[$i][$ids['windowsGroup_members']]);
849 }
850 // group scope
851 if ($rawAccounts[$i][$ids['windowsGroup_scope']] != "") {
852 if (in_array($rawAccounts[$i][$ids['windowsGroup_scope']], $this->groupScopes)) {
853 switch ($rawAccounts[$i][$ids['windowsGroup_scope']]) {
854 case windowsGroup::SCOPE_DOMAIN_LOCAL:
855 $partialAccounts[$i]['groupType'] = 4;
856 break;
857 case windowsGroup::SCOPE_GLOBAL:
858 $partialAccounts[$i]['groupType'] = 2;
859 break;
860 case windowsGroup::SCOPE_UNIVERSAL:
861 $partialAccounts[$i]['groupType'] = 8;
862 break;
863 }
864 }
865 else {
866 $errMsg = $this->messages['groupScope'][0];
867 $errMsg[] = [$i];
868 $errors[] = $errMsg;
869 }
870 }
871 else {
872 $partialAccounts[$i]['groupType'] = 2;
873 }
874 // group type
875 if ($rawAccounts[$i][$ids['windowsGroup_type']] != "") {
876 if (in_array($rawAccounts[$i][$ids['windowsGroup_type']], $this->groupTypes)) {
877 if ($rawAccounts[$i][$ids['windowsGroup_type']] == windowsGroup::TYPE_SECURITY) {
878 $partialAccounts[$i]['groupType'] -= 2147483648;
879 }
880 }
881 else {
882 $errMsg = $this->messages['groupType'][0];
883 $errMsg[] = [$i];
884 $errors[] = $errMsg;
885 }
886 }
887 else {
888 $partialAccounts[$i]['groupType'] -= 2147483648;
889 }
890 // NIS name
891 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30Name', true)) {
892 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsGroup_msSFU30Name', 'msSFU30Name',
893 'groupname', $this->messages['msSFU30Name'][1], $errors);
894 }
895 // NIS domain
896 if (!$this->isBooleanConfigOptionSet('windowsGroup_hidemsSFU30NisDomain', true)) {
897 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsGroup_msSFU30NisDomain', 'msSFU30NisDomain');
898 }
899 }
900 return $errors;
901 }
902
903 /**
904 * {@inheritDoc}
905 */
906 public function get_pdfEntries(array $pdfKeys, string $typeId): array {
907 $return = [];
908 $this->addSimplePDFField($return, 'cn', _('Group name'));
909 $this->addSimplePDFField($return, 'description', _('Description'));
910 $this->addSimplePDFField($return, 'info', _('Notes'));
911 $this->addSimplePDFField($return, 'mail', _('Email address'));
912 $this->addSimplePDFField($return, 'msSFU30Name', _('NIS name'));
913 $this->addSimplePDFField($return, 'msSFU30NisDomain', _('NIS domain'));
914 // group type
915 $groupType = windowsGroup::TYPE_SECURITY;
916 $groupScope = windowsGroup::SCOPE_GLOBAL;
917 if (isset($this->attributes['groupType'][0])) {
918 if ((((int) $this->attributes['groupType'][0]) & 4) !== 0) {
919 $groupScope = windowsGroup::SCOPE_DOMAIN_LOCAL;
920 }
921 elseif ((((int) $this->attributes['groupType'][0]) & 8) !== 0) {
922 $groupScope = windowsGroup::SCOPE_UNIVERSAL;
923 }
924 if ((((int) $this->attributes['groupType'][0]) & 0x80000000) === 0) {
925 $groupType = windowsGroup::TYPE_DISTRIBUTION;
926 }
927 }
928 $groupTypeLabels = array_flip($this->groupTypes);
929 $groupType = $groupTypeLabels[$groupType];
930 $groupScopeLabels = array_flip($this->groupScopes);
931 $groupScope = $groupScopeLabels[$groupScope];
932 $this->addPDFKeyValue($return, 'groupScope', _('Group scope'), $groupScope);
933 $this->addPDFKeyValue($return, 'groupType', _('Group type'), $groupType);
934 // managed by
935 if (isset($this->attributes['managedBy'][0])) {
936 $managedBy = getAbstractDN($this->attributes['managedBy'][0]);
937 $this->addPDFKeyValue($return, 'managedBy', _('Managed by'), $managedBy);
938 }
939 // members
940 if (!empty($this->attributes['member'])) {
941 $memberList = [];
942 if (isset($this->attributes['member'][0])) {
943 $memberList = $this->attributes['member'];
944 }
945 usort($memberList, compareDN(...));
946 $pdfTable = new PDFTable(_('Members'));
947 for ($i = 0; $i < count($memberList); $i++) {
948 $pdfRow = new PDFTableRow();
949 $pdfRow->cells[] = new PDFTableCell($memberList[$i]);
950 $pdfTable->rows[] = $pdfRow;
951 }
952 $this->addPDFTable($return, 'member', $pdfTable);
953 }
954 // member of
955 if (!empty($this->attributes['memberOf'])) {
956 $memberOfList = [];
957 if (isset($this->attributes['memberOf'][0])) {
958 $memberOfList = $this->attributes['memberOf'];
959 }
960 usort($memberOfList, compareDN(...));
961 $pdfTable = new PDFTable(_('Member of'));
962 for ($i = 0; $i < count($memberOfList); $i++) {
963 $pdfRow = new PDFTableRow();
964 $pdfRow->cells[] = new PDFTableCell($memberOfList[$i]);
965 $pdfTable->rows[] = $pdfRow;
966 }
967 $this->addPDFTable($return, 'memberOf', $pdfTable);
968 }
969 return $return;
970 }
971
972 /**
973 * Finds all existing groups.
974 *
975 * @return string[] group DNs
976 */
977 private function findGroups(): array {
978 if ($this->groupCache != null) {
979 return $this->groupCache;
980 }
981 $return = [];
982 $types = ['group'];
983 $results = searchLDAPByFilter('(objectClass=group)', ['dn'], $types);
984 $count = count($results);
985 for ($i = 0; $i < $count; $i++) {
986 if (isset($results[$i]['dn'])) {
987 $return[] = $results[$i]['dn'];
988 }
989 }
990 $this->groupCache = $return;
991 return $return;
992 }
993
994 /**
995 * {@inheritDoc}
996 */
997 public function save_attributes(): array {
998 $attrs = $this->attributes;
999 $orig = $this->orig;
1000 $attrs['memberOf'] = [];
1001 $orig['memberOf'] = [];
1002 return $this->getAccountContainer()->save_module_attributes($attrs, $orig);
1003 }
1004
1005 /**
1006 * {@inheritDoc}
1007 */
1008 public function postModifyActions(bool $newAccount, array $attributes): array {
1009 $messages = [];
1010 // set groups
1011 $groups = $this->findGroups();
1012 if (!isset($this->orig['memberOf'])) {
1013 $this->orig['memberOf'] = [];
1014 }
1015 if (!isset($this->attributes['memberOf'])) {
1016 $this->attributes['memberOf'] = [];
1017 }
1018 $toAdd = array_values(array_diff($this->attributes['memberOf'], $this->orig['memberOf']));
1019 $toRem = array_values(array_diff($this->orig['memberOf'], $this->attributes['memberOf']));
1020 // add groups
1021 for ($i = 0; $i < count($toAdd); $i++) {
1022 if (in_array($toAdd[$i], $groups)) {
1023 $success = @ldap_mod_add($_SESSION['ldap']->server(), $toAdd[$i], ['member' => [$this->getAccountContainer()->finalDN]]);
1024 if (!$success) {
1025 logNewMessage(LOG_ERR, 'Unable to add group ' . $this->getAccountContainer()->finalDN . ' to group: ' . $toAdd[$i] . ' (' . ldap_error($_SESSION['ldap']->server()) . ').');
1026 $messages[] = ['ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $toAdd[$i]), getDefaultLDAPErrorString($_SESSION['ldap']->server())];
1027 }
1028 else {
1029 logNewMessage(LOG_NOTICE, 'Added group ' . $this->getAccountContainer()->finalDN . ' to group: ' . $toAdd[$i]);
1030 }
1031 }
1032 }
1033 // remove groups
1034 for ($i = 0; $i < count($toRem); $i++) {
1035 if (in_array($toRem[$i], $groups)) {
1036 $success = @ldap_mod_del($_SESSION['ldap']->server(), $toRem[$i], ['member' => [$this->getAccountContainer()->dn_orig]]);
1037 if (!$success) {
1038 logNewMessage(LOG_ERR, 'Unable to delete group ' . $this->getAccountContainer()->finalDN . ' from group: ' . $toRem[$i] . ' (' . ldap_error($_SESSION['ldap']->server()) . ').');
1039 $messages[] = ['ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $toRem[$i]), getDefaultLDAPErrorString($_SESSION['ldap']->server())];
1040 }
1041 else {
1042 logNewMessage(LOG_NOTICE, 'Removed group ' . $this->getAccountContainer()->finalDN . ' from group: ' . $toRem[$i]);
1043 }
1044 }
1045 }
1046 return $messages;
1047 }
1048
1049 /**
1050 * Recursively gets the members of this group and its subgroups.
1051 *
1052 * @return string[] list of DNs
1053 */
1054 private function getEffectiveMembers(): array {
1055 $membersToCheck = $this->attributes['member'];
1056 $effectiveMembers = $membersToCheck;
1057 while (!empty($membersToCheck)) {
1058 $member = array_pop($membersToCheck);
1059 $attrs = ldapGetDN($member, ['member']);
1060 if (!empty($attrs['member'])) {
1061 foreach ($attrs['member'] as $newMember) {
1062 if (!in_array($newMember, $effectiveMembers)) {
1063 $effectiveMembers[] = $newMember;
1064 $membersToCheck[] = $newMember;
1065 }
1066 }
1067 }
1068 }
1069 return $effectiveMembers;
1070 }
1071
1072 /**
1073 * {@inheritDoc}
1074 */
1075 public function get_configOptions(array $scopes, array $allScopes): htmlElement|array {
1076 $configContainer = new htmlResponsiveRow();
1077 $configContainerHead = new htmlGroup();
1078 $configContainerHead->addElement(new htmlOutputText(_('Hidden options')));
1079 $configContainerHead->addElement(new htmlHelpLink('hiddenOptions'));
1080 $configContainer->add($configContainerHead);
1081 $configContainer->add(new htmlResponsiveInputCheckbox('windowsGroup_hidemail', false, _('Email address'), null, true), 12, 4);
1082 $configContainer->add(new htmlResponsiveInputCheckbox('windowsGroup_hidemanagedBy', false, _('Managed by'), null, true), 12, 4);
1083 $configContainer->add(new htmlResponsiveInputCheckbox('windowsGroup_hidemsSFU30Name', true, _('NIS name'), null, true), 12, 4);
1084 $configContainer->add(new htmlResponsiveInputCheckbox('windowsGroup_hidemsSFU30NisDomain', true, _('NIS domain'), null, true), 12, 4);
1085 for ($i = 0; $i < 2; $i++) {
1086 $configContainer->add(new htmlOutputText(''), 0, 4);
1087 }
1088 return $configContainer;
1089 }
1090
1091 /**
1092 * @inheritDoc
1093 */
1094 public function getListAttributeDescriptions(ConfiguredType $type): array {
1095 return [
1096 'cn' => _('Group name'),
1097 'description' => _('Description'),
1098 'info' => _('Notes'),
1099 'member' => _('Members'),
1100 'member_count' => _('Member count'),
1101 'memberof' => _('Member of'),
1102 'memberof_count' => _('Membership count'),
1103 'managedby' => _('Managed by'),
1104 'grouptype' => _('Group type'),
1105 'groupscope' => _('Group scope'),
1106 'whencreated' => _('Creation time'),
1107 'whenchanged' => _('Change date'),
1108 ];
1109 }
1110
1111 /**
1112 * @inheritDoc
1113 */
1114 public function getListRenderFunction(string $attributeName, ConfiguredType $type): ?callable {
1115 if (($attributeName === 'whencreated') || ($attributeName === 'whenchanged')) {
1116 return function(array $entry, string $attribute): htmlElement {
1117 $value = ' - ';
1118 if (!empty($entry[$attribute][0])) {
1119 $value = formatLDAPTimestamp($entry[$attribute][0]);
1120 }
1121 return new htmlOutputText($value);
1122 };
1123 }
1124 elseif (($attributeName === 'managedby') || ($attributeName === 'member')) {
1125 return $this->listRenderDnList(...);
1126 }
1127 elseif (($attributeName === 'member_count') || ($attributeName === 'memberof_count')) {
1128 return function(array $entry, string $attribute) use ($type): htmlElement {
1129 $count = 0;
1130 $realAttributeName = str_replace('_count', '', $attribute);
1131 $values = &$entry[$realAttributeName];
1132 if (!empty($values)) {
1133 $count = count($values);
1134 }
1135 $subpage = 'user';
1136 if ($realAttributeName === 'memberof') {
1137 $subpage = 'memberof';
1138 }
1139 return new htmlLink((string) $count, '../account/edit.php?type=' . $type->getId()
1140 . '&DN=\'' . $entry['dn'] . '\'&initialTab=windowsGroup&initialSubpage=' . $subpage);
1141 };
1142 }
1143 return null;
1144 }
1145
1146 }