Debian Codegraph @

lib/modules/nisnetgroup.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
8 /*
9
10 This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
11 Copyright (C) 2009 - 2026 Roland Gruber
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 */
28
29 /**
30 * Manages entries based on the object class nisNetgroup.
31 *
32 * @package modules
33 * @author Roland Gruber
34 */
35
36 /**
37 * Manages entries based on the object class nisNetgroup.
38 *
39 * @package modules
40 */
41 class nisnetgroup extends baseModule {
42
43 /* caches to reduce LDAP queries */
44 /** @var string[]|null user cache */
45 private ?array $cachedUserList = null;
46 /** @var string[]|null $cachedHostList host cache */
47 private ?array $cachedHostList = null;
48 /** @var string[]|null group cache */
49 private ?array $cachedGroupList = null;
50
51 /**
52 * {@inheritDoc}
53 */
54 public function can_manage(): bool {
55 return $this->get_scope() === 'netgroup';
56 }
57
58 /**
59 * {@inheritDoc}
60 */
61 public function get_metaData(): array {
62 $return = [];
63 // icon
64 $return['icon'] = 'group.svg';
65 // alias name
66 $return["alias"] = _("NIS net group");
67 // this is a base module
68 $return["is_base"] = true;
69 // LDAP filter
70 $return["ldap_filter"] = ['or' => "(objectClass=nisNetgroup)"];
71 // RDN attributes
72 $return["RDN"] = ["cn" => "normal"];
73 // module dependencies
74 $return['dependencies'] = ['depends' => [], 'conflicts' => []];
75 // managed object classes
76 $return['objectClasses'] = ['nisNetgroup'];
77 // managed attributes
78 $return['attributes'] = ['cn', 'description', 'memberNisNetgroup', 'nisNetgroupTriple'];
79 // help Entries
80 $return['help'] = [
81 'cn' => [
82 "Headline" => _("Group name"), 'attr' => 'cn',
83 "Text" => _("This is the name of this group.")
84 ],
85 'description' => [
86 "Headline" => _("Description"), 'attr' => 'description',
87 "Text" => _("Here you can enter a description for this group.")
88 ],
89 'memberNisNetgroup' => [
90 "Headline" => _("Subgroups"), 'attr' => 'memberNisNetgroup',
91 "Text" => _("Here you can specify subgroups which are included in this NIS netgroup. All members of the subgroups will be treated as members of this group.")
92 ],
93 'members' => [
94 "Headline" => _("Members"), 'attr' => 'nisNetgroupTriple',
95 "Text" => _("These entries specify the members of the netgroup. You can limit the set to a host name, a user name, a domain name or any combination of them.")
96 ],
97 'membersUpload' => [
98 "Headline" => _("Members"), 'attr' => 'nisNetgroupTriple',
99 "Text" => _("These entries specify the members of the netgroup. You can limit the set to a host name, a user name, a domain name or any combination of them.") . ' ' .
100 _("For the upload please specify the entries in the format \"(HOST,USER,DOMAIN)\". Multiple entries are separated by semicolon.")
101 ],
102 'filter' => [
103 "Headline" => _("Filter"),
104 "Text" => _("Here you can enter a filter value. Only entries which contain the filter text will be shown.")
105 ]
106 ];
107 // upload fields
108 $return['upload_columns'] = [
109 [
110 'name' => 'nisnetgroup_cn',
111 'description' => _('Group name'),
112 'help' => 'cn',
113 'example' => _('adminstrators'),
114 'required' => true,
115 'unique' => true
116 ],
117 [
118 'name' => 'nisnetgroup_description',
119 'description' => _('Group description'),
120 'help' => 'description',
121 'example' => _('Administrators group')
122 ],
123 [
124 'name' => 'nisnetgroup_subgroups',
125 'description' => _('Subgroups'),
126 'help' => 'memberNisNetgroup',
127 'example' => _('group01,group02')
128 ],
129 [
130 'name' => 'nisnetgroup_members',
131 'description' => _('Members'),
132 'help' => 'membersUpload',
133 'example' => _('(host1,user1,example.com);(host2,user2,example.com)')
134 ]
135 ];
136 // available PDF fields
137 $return['PDF_fields'] = [
138 'cn' => _('Group name'),
139 'description' => _('Description'),
140 'subgroups' => _('Subgroups'),
141 'members' => _('Members')
142 ];
143 return $return;
144 }
145
146 /**
147 * {@inheritDoc}
148 */
149 protected function load_Messages(): void {
150 $this->messages['cn'][0] = ['ERROR', _('Group name'), _('Group name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
151 $this->messages['user'][0] = ['ERROR', _('User name'), _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
152 $this->messages['host'][0] = ['ERROR', _('Host name'), _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')];
153 $this->messages['domain'][0] = ['ERROR', _('Domain name'), _('Domain name is invalid!')];
154 }
155
156 /**
157 * {@inheritDoc}
158 */
159 public function display_html_attributes(): htmlElement|array {
160 $return = new htmlResponsiveRow();
161 // user name
162 $groupName = '';
163 if (isset($this->attributes['cn'][0])) {
164 $groupName = $this->attributes['cn'][0];
165 }
166 $nameInput = new htmlResponsiveInputField(_("Group name"), 'cn', $groupName, 'cn');
167 $nameInput->setRequired(true);
168 $nameInput->setFieldMaxLength(20);
169 $return->add($nameInput);
170 $description = '';
171 if (isset($this->attributes['description'][0])) {
172 $description = $this->attributes['description'][0];
173 }
174 $return->add(new htmlResponsiveInputField(_('Description'), 'description', $description, 'description'));
175 $subgroupsContainer = new htmlTable();
176 if (isset($this->attributes['memberNisNetgroup']) && is_array($this->attributes['memberNisNetgroup'])) {
177 $membergroups = $this->attributes['memberNisNetgroup'];
178 while ($membergroups !== []) {
179 $parts = array_splice($membergroups, 0, 8);
180 $subgroupsContainer->addElement(new htmlOutputText(implode(', ', $parts)), true);
181 }
182 }
183 $subGroupsButtonGroup = new htmlGroup();
184 $subGroupsButtonGroup->addElement(new htmlAccountPageButton(static::class, 'group', 'open', _('Edit subgroups')));
185 $subGroupsButtonGroup->addElement(new htmlHelpLink('memberNisNetgroup'));
186 $subgroupsContainer->addElement($subGroupsButtonGroup);
187 $subgroupsLabel = new htmlOutputText(_('Subgroups'));
188 $return->addLabel($subgroupsLabel);
189 $return->addField($subgroupsContainer);
190 $return->addLabel(new htmlOutputText('&nbsp;', false));
191 // members
192 $membersLabel = new htmlSubTitle(_('Members'));
193 $membersLabel->setHelpId('members');
194 $return->add($membersLabel);
195 $titles = [_('Host'), _('User'), _('Domain'), ''];
196 $data = [];
197 if (isset($this->attributes['nisNetgroupTriple']) && (count($this->attributes['nisNetgroupTriple']) > 0)) {
198 for ($i = 0; $i < count($this->attributes['nisNetgroupTriple']); $i++) {
199 $triple = substr($this->attributes['nisNetgroupTriple'][$i], 1, strlen($this->attributes['nisNetgroupTriple'][$i]) - 2);
200 $triple = explode(',', $triple);
201 if (isset($_POST['form_subpage_nisnetgroup_attributes_select']) && ($_POST['type'] == 'host') && ($_POST['position'] == strval($i))) {
202 $triple[0] = $_POST['selectBox'];
203 }
204 if (isset($_POST['form_subpage_nisnetgroup_attributes_select']) && ($_POST['type'] == 'user') && ($_POST['position'] == strval($i))) {
205 $triple[1] = $_POST['selectBox'];
206 }
207 $dataRow = [];
208 $hostGroup = new htmlGroup();
209 $hostField = new htmlInputField('host_' . $i, $triple[0]);
210 $hostField->setCSSClasses(['auto-width']);
211 $hostField->setFieldSize(null);
212 $hostGroup->addElement($hostField);
213 $hostButton = new htmlAccountPageButton(static::class, 'select', 'host' . $i, 'computer.svg', true);
214 $hostButton->setTitle(_('Select host'));
215 $hostGroup->addElement($hostButton);
216 $dataRow[] = $hostGroup;
217 $userGroup = new htmlGroup();
218 $userField = new htmlInputField('user_' . $i, $triple[1]);
219 $userField->setCSSClasses(['auto-width']);
220 $userField->setFieldSize(null);
221 $userGroup->addElement($userField);
222 $userButton = new htmlAccountPageButton(static::class, 'select', 'user' . $i, 'user.svg', true);
223 $userButton->setTitle(_('Select user'));
224 $userGroup->addElement($userButton);
225 $dataRow[] = $userGroup;
226 $domainField = new htmlInputField('domain_' . $i, $triple[2]);
227 $domainField->setFieldSize(null);
228 $dataRow[] = $domainField;
229 $delButton = new htmlButton('del_' . $i, 'del.svg', true);
230 $delButton->setTitle(_('Delete'));
231 $dataRow[] = $delButton;
232 $data[] = $dataRow;
233 }
234 }
235 $dataRowNew = [];
236 $hostNew = '';
237 $userNew = '';
238 $domainNew = '';
239 if (isset($_POST['host_new'])) {
240 $hostNew = $_POST['host_new'];
241 }
242 if (isset($_POST['user_new'])) {
243 $userNew = $_POST['user_new'];
244 }
245 if (isset($_POST['domain_new'])) {
246 $domainNew = $_POST['domain_new'];
247 }
248 $hostNewGroup = new htmlGroup();
249 $hostField = new htmlInputField('host_new', $hostNew);
250 $hostField->setCSSClasses(['auto-width']);
251 $hostField->setFieldSize(null);
252 $hostNewGroup->addElement($hostField);
253 $hostButton = new htmlAccountPageButton(static::class, 'select', 'hostNew', 'computer.svg', true);
254 $hostButton->setTitle(_('Select host'));
255 $hostNewGroup->addElement($hostButton);
256 $dataRowNew[] = $hostNewGroup;
257 $userNewGroup = new htmlGroup();
258 $userField = new htmlInputField('user_new', $userNew);
259 $userField->setCSSClasses(['auto-width']);
260 $userField->setFieldSize(null);
261 $userNewGroup->addElement($userField);
262 $userButton = new htmlAccountPageButton(static::class, 'select', 'userNew', 'user.svg', true);
263 $userButton->setTitle(_('Select user'));
264 $userNewGroup->addElement($userButton);
265 $dataRowNew[] = $userNewGroup;
266 $domainField = new htmlInputField('domain_new', $domainNew);
267 $domainField->setFieldSize(null);
268 $dataRowNew[] = $domainField;
269 $addButton = new htmlButton('add_new', 'add.svg', true);
270 $addButton->setTitle(_('Add'));
271 $dataRowNew[] = $addButton;
272 $data[] = $dataRowNew;
273
274 $memberTable = new htmlResponsiveTable($titles, $data);
275 $return->add($memberTable);
276 return $return;
277 }
278
279 /**
280 * {@inheritDoc}
281 */
282 public function process_attributes(): array {
283 $errors = [];
284 // user name
285 $this->attributes['cn'][0] = $_POST['cn'];
286 if (!get_preg($this->attributes['cn'][0], 'groupname')) {
287 $errors[] = $this->messages['cn'][0];
288 }
289 // description
290 $this->attributes['description'][0] = $_POST['description'];
291 // members
292 $this->attributes['nisNetgroupTriple'] = [];
293 $i = 0;
294 while (isset($_POST['host_' . $i]) || isset($_POST['user_' . $i]) || isset($_POST['domain_' . $i])) {
295 if (isset($_POST['del_' . $i])) {
296 $i++;
297 continue;
298 }
299 // build NIS triple
300 $this->attributes['nisNetgroupTriple'][] = '(' . $_POST['host_' . $i] . ',' . $_POST['user_' . $i] . ',' . $_POST['domain_' . $i] . ')';
301 // check user input
302 if (($_POST['host_' . $i] != '') && !get_preg($_POST['host_' . $i], 'DNSname')) {
303 $message = $this->messages['host'][0];
304 $message[2] = $message[2] . '<br><br>' . $_POST['host_' . $i];
305 $errors[] = $message;
306 }
307 if (($_POST['user_' . $i] != '') && !get_preg($_POST['user_' . $i], 'username')) {
308 $message = $this->messages['user'][0];
309 $message[2] = $message[2] . '<br><br>' . $_POST['user_' . $i];
310 $errors[] = $message;
311 }
312 if (($_POST['domain_' . $i] != '') && !get_preg($_POST['domain_' . $i], 'DNSname')) {
313 $message = $this->messages['domain'][0];
314 $message[2] = $message[2] . '<br><br>' . $_POST['domain_' . $i];
315 $errors[] = $message;
316 }
317 $i++;
318 }
319 $addNewTriple = isset($_POST['add_new']);
320 // check user input
321 if (($_POST['host_new'] != '') && !get_preg($_POST['host_new'], 'DNSname')) {
322 $message = $this->messages['host'][0];
323 $message[2] = $message[2] . '<br><br>' . $_POST['host_new'];
324 $errors[] = $message;
325 $addNewTriple = false;
326 }
327 if (($_POST['user_new'] != '') && !get_preg($_POST['user_new'], 'username')) {
328 $message = $this->messages['user'][0];
329 $message[2] = $message[2] . '<br><br>' . $_POST['user_new'];
330 $errors[] = $message;
331 $addNewTriple = false;
332 }
333 if (($_POST['domain_new'] != '') && !get_preg($_POST['domain_new'], 'DNSname')) {
334 $message = $this->messages['domain'][0];
335 $message[2] = $message[2] . '<br><br>' . $_POST['domain_new'];
336 $errors[] = $message;
337 $addNewTriple = false;
338 }
339 if ($addNewTriple) {
340 $this->attributes['nisNetgroupTriple'][] = '(' . $_POST['host_new'] . ',' . $_POST['user_new'] . ',' . $_POST['domain_new'] . ')';
341 unset($_POST['host_new']);
342 unset($_POST['user_new']);
343 unset($_POST['domain_new']);
344 }
345 return $errors;
346 }
347
348 /**
349 * Displays the group selection.
350 *
351 * @return htmlElement meta HTML code
352 */
353 public function display_html_group(): htmlElement {
354 // load list with all groups
355 $allGroups = $this->getGroupList();
356 // remove own entry
357 if (!$this->getAccountContainer()->isNewAccount) {
358 $allGroups = array_delete([$this->attributes['cn'][0]], $allGroups);
359 }
360 $subgroups = [];
361 if (is_array($this->attributes['memberNisNetgroup'])) {
362 $subgroups = $this->attributes['memberNisNetgroup'];
363 $allGroups = array_delete($subgroups, $allGroups);
364 }
365 $selectedGroups = [];
366 foreach ($subgroups as $subgroup) {
367 $selectedGroups[$subgroup] = $subgroup;
368 }
369 $availableGroups = [];
370 foreach ($allGroups as $availableGroup) {
371 $availableGroups[$availableGroup] = $availableGroup;
372 }
373
374 $return = new htmlResponsiveRow();
375 $return->add(new htmlSubTitle(_("Subgroups")));
376
377 $this->addDoubleSelectionArea($return, _("Selected groups"), _("Available groups"), $selectedGroups, [], $availableGroups, [], 'subgroup', false, true);
378
379 $return->addVerticalSpacer('2rem');
380 $backButton = new htmlAccountPageButton(static::class, 'attributes', 'back', _('Back'));
381 $return->add($backButton);
382 return $return;
383 }
384
385 /**
386 * Processes user input of the group selection page.
387 * It checks if all input values are correct and updates the associated LDAP attributes.
388 *
389 * @return array<string|string[]>[] list of info/error messages
390 */
391 public function process_group(): array {
392 if (isset($_POST['subgroup_2']) && isset($_POST['subgroup_left'])) { // Add groups to list
393 if (!is_array($this->attributes['memberNisNetgroup'])) {
394 $this->attributes['memberNisNetgroup'] = [];
395 }
396 // Add new group
397 $this->attributes['memberNisNetgroup'] = @array_merge($this->attributes['memberNisNetgroup'], $_POST['subgroup_2']);
398 }
399 elseif (isset($_POST['subgroup_1']) && isset($_POST['subgroup_right'])) { // remove groups from list
400 $this->attributes['memberNisNetgroup'] = array_delete($_POST['subgroup_1'], $this->attributes['memberNisNetgroup']);
401 }
402 return [];
403 }
404
405 /**
406 * Displays the host/user selection.
407 *
408 * @return htmlElement meta HTML code
409 */
410 public function display_html_select(): htmlElement {
411 $return = new htmlResponsiveRow();
412 $selectHost = true;
413 $postKeys = array_keys($_POST);
414 $position = 'New';
415 for ($i = 0; $i < count($postKeys); $i++) {
416 if (str_starts_with($postKeys[$i], 'form_subpage_nisnetgroup_select_user')) {
417 $selectHost = false;
418 $position = substr($postKeys[$i], 36);
419 break;
420 }
421 if (str_starts_with($postKeys[$i], 'form_subpage_nisnetgroup_select_host')) {
422 $position = substr($postKeys[$i], 36);
423 break;
424 }
425 }
426 if ($selectHost) {
427 // load list with all hosts
428 $options = $this->getHostList();
429 $count = count($options);
430 for ($i = 0; $i < $count; $i++) {
431 if (!get_preg($options[$i], 'DNSname')) {
432 unset($options[$i]);
433 }
434 }
435 }
436 else {
437 // load list with all users
438 $options = $this->getUserList();
439 }
440 $options = array_values($options);
441 $return->addLabel(new htmlOutputText(_('Filter')));
442 $filterInput = new htmlInputField('filter');
443 $filterInput->filterSelectBox('selectBox');
444 $return->addField($filterInput);
445 $title = _('Host name');
446 if (!$selectHost) {
447 $title = _('User name');
448 }
449 $return->addLabel(new htmlOutputText($title));
450 $return->addField(new htmlSelect('selectBox', $options));
451 $return->addVerticalSpacer('2rem');
452 $type = 'host';
453 if (!$selectHost) {
454 $type = 'user';
455 }
456 $return->addLabel(new htmlAccountPageButton(static::class, 'attributes', 'select', _('Ok')));
457 $return->addField(new htmlAccountPageButton(static::class, 'attributes', 'back', _('Cancel')));
458 $return->add(new htmlHiddenInput('host_new', $_POST['host_new']));
459 $return->add(new htmlHiddenInput('user_new', $_POST['user_new']));
460 $return->add(new htmlHiddenInput('domain_new', $_POST['domain_new']));
461 $return->add(new htmlHiddenInput('type', $type));
462 $return->add(new htmlHiddenInput('position', $position));
463 return $return;
464 }
465
466 /**
467 * Processes user input of the host/user selection page.
468 * It checks if all input values are correct and updates the associated LDAP attributes.
469 *
470 * @return array<string|string[]>[] list of info/error messages
471 */
472 public function process_select(): array {
473 if (isset($_POST['form_subpage_nisnetgroup_attributes_back'])) {
474 return [];
475 }
476 if ($_POST['position'] == 'New') {
477 $_POST[$_POST['type'] . '_new'] = $_POST['selectBox'];
478 }
479 return [];
480 }
481
482 /**
483 * {@inheritDoc}
484 */
485 public function build_uploadAccounts(array $rawAccounts, array $ids, array &$partialAccounts, array $selectedModules, ConfiguredType &$type): array {
486 $messages = [];
487 // get list of existing groups
488 $existingGroups = $this->getGroupList();
489 for ($i = 0; $i < count($rawAccounts); $i++) {
490 // add object class
491 if (!in_array('nisNetgroup', $partialAccounts[$i]['objectClass'])) {
492 $partialAccounts[$i]['objectClass'][] = 'nisNetgroup';
493 }
494 // add cn
495 $partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['nisnetgroup_cn']];
496 // description (UTF-8, no regex check needed)
497 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'nisnetgroup_description', 'description');
498 // additional groups
499 if ($rawAccounts[$i][$ids['nisnetgroup_subgroups']] != "") {
500 $groups = explode(",", $rawAccounts[$i][$ids['nisnetgroup_subgroups']]);
501 $skipSubgroups = false;
502 for ($g = 0; $g < count($groups); $g++) {
503 if (!in_array($groups[$g], $existingGroups)) {
504 $messages[] = ['ERROR', _('Unable to find group in LDAP.'), $groups[$g]];
505 $skipSubgroups = true;
506 }
507 }
508 if (!$skipSubgroups) {
509 $partialAccounts[$i]['memberNisNetgroup'] = $groups;
510 }
511 }
512 // members
513 $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'nisnetgroup_members',
514 'nisNetgroupTriple', null, [], $messages, '/;[ ]*/');
515 }
516 return $messages;
517 }
518
519 /**
520 * {@inheritDoc}
521 */
522 public function module_complete(): bool {
523 return (isset($this->attributes['cn']) && (count($this->attributes['cn']) > 0));
524 }
525
526 /**
527 * {@inheritDoc}
528 */
529 public function get_pdfEntries(array $pdfKeys, string $typeId): array {
530 $return = [];
531 $this->addSimplePDFField($return, 'cn', _('Group name'));
532 $this->addSimplePDFField($return, 'description', _('Description'));
533 $this->addSimplePDFField($return, 'subgroups', _('Subgroups'), 'memberNisNetgroup');
534 if (count($this->attributes['nisNetgroupTriple']) > 0) {
535 $pdfTable = new PDFTable(_('Members'));
536 $pdfRow = new PDFTableRow();
537 $pdfRow->cells[] = new PDFTableCell(_('Host'), '20%', null, true);
538 $pdfRow->cells[] = new PDFTableCell(_('User'), '20%', null, true);
539 $pdfRow->cells[] = new PDFTableCell(_('Domain'), '20%', null, true);
540 $pdfTable->rows[] = $pdfRow;
541 for ($i = 0; $i < count($this->attributes['nisNetgroupTriple']); $i++) {
542 $triple = substr($this->attributes['nisNetgroupTriple'][$i], 1, strlen($this->attributes['nisNetgroupTriple'][$i]) - 2);
543 $triple = explode(',', $triple);
544 $pdfRow = new PDFTableRow();
545 $pdfRow->cells[] = new PDFTableCell($triple[0], '20%');
546 $pdfRow->cells[] = new PDFTableCell($triple[1], '20%');
547 $pdfRow->cells[] = new PDFTableCell($triple[2], '30%');
548 $pdfTable->rows[] = $pdfRow;
549 }
550 $this->addPDFTable($return, 'members', $pdfTable);
551 }
552 return $return;
553 }
554
555 /**
556 * Returns a list of existing NIS net groups.
557 *
558 * @return string[] group names
559 */
560 private function getGroupList(): array {
561 if ($this->cachedGroupList !== null) {
562 return $this->cachedGroupList;
563 }
564 $this->cachedGroupList = [];
565 $entries = searchLDAPByAttribute('cn', '*', 'nisNetgroup', ['cn'], ['netgroup']);
566 foreach ($entries as $entry) {
567 $this->cachedGroupList[] = $entry['cn'][0];
568 }
569 return $this->cachedGroupList;
570 }
571
572 /**
573 * Returns a list of existing users.
574 *
575 * @return string[] user names
576 */
577 private function getUserList(): array {
578 if ($this->cachedUserList !== null) {
579 return $this->cachedUserList;
580 }
581 $this->cachedUserList = [];
582 $entries = searchLDAPByAttribute('uid', '*', 'posixAccount', ['uid'], ['user']);
583 foreach ($entries as $entry) {
584 $this->cachedUserList[] = $entry['uid'][0];
585 }
586 return $this->cachedUserList;
587 }
588
589 /**
590 * Returns a list of existing hosts.
591 *
592 * @return string[] host names
593 */
594 private function getHostList(): array {
595 if ($this->cachedHostList !== null) {
596 return $this->cachedHostList;
597 }
598 $this->cachedHostList = [];
599 $list = searchLDAPByFilter('(|(objectClass=account)(objectClass=device))', ['uid', 'cn'], ['host']);
600 foreach ($list as $attrs) {
601 if (!empty($attrs['uid'][0])) {
602 $this->cachedHostList[] = $attrs['uid'][0];
603 }
604 if (!empty($attrs['cn'][0])) {
605 $this->cachedHostList[] = $attrs['cn'][0];
606 }
607 }
608 $this->cachedHostList = array_values(array_unique($this->cachedHostList));
609 return $this->cachedHostList;
610 }
611
612 /**
613 * @inheritDoc
614 */
615 public function getListAttributeDescriptions(ConfiguredType $type): array {
616 return [
617 "cn" => _("Group name"),
618 'description' => _('Description'),
619 'membernisnetgroup' => _('Subgroups'),
620 'nisnetgrouptriple' => _('Members')
621 ];
622 }
623
624 }