| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 5 |
Copyright (C) 2005 - 2025 Roland Gruber |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program; if not, write to the Free Software |
| 19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
|
| 21 |
*/ |
| 22 |
|
| 23 |
/** |
| 24 |
* The account type for host accounts (e.g. Samba). |
| 25 |
* |
| 26 |
* @package types |
| 27 |
* @author Roland Gruber |
| 28 |
*/ |
| 29 |
|
| 30 |
use LAM\TYPES\ConfiguredType; |
| 31 |
|
| 32 |
/** |
| 33 |
* The account type for host accounts (e.g. Samba). |
| 34 |
* |
| 35 |
* @package types |
| 36 |
*/ |
| 37 |
class host extends baseType { |
| 38 |
|
| 39 |
/** |
| 40 |
* Constructs a new host type object. |
| 41 |
* |
| 42 |
* @param ConfiguredType $type configuration |
| 43 |
*/ |
| 44 |
public function __construct($type) { |
| 45 |
parent::__construct($type); |
| 46 |
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another host'); |
| 47 |
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to host list'); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* {@inheritDoc} |
| 52 |
*/ |
| 53 |
public function getAlias(): string { |
| 54 |
return _("Hosts"); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* {@inheritDoc} |
| 59 |
*/ |
| 60 |
public function getDescription(): string { |
| 61 |
return _("Host accounts (e.g. Samba)"); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* {@inheritDoc} |
| 66 |
*/ |
| 67 |
public function getIcon(): string { |
| 68 |
return 'computer.svg'; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* {@inheritDoc} |
| 73 |
*/ |
| 74 |
public function getListClassName(): string { |
| 75 |
return lamHostList::class; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* {@inheritDoc} |
| 80 |
*/ |
| 81 |
public function getDefaultListAttributes(): string { |
| 82 |
return "#cn;#description;#uidNumber;#gidNumber"; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* {@inheritDoc} |
| 87 |
*/ |
| 88 |
public function getTitleBarTitle(accountContainer $container): ?string { |
| 89 |
// get attributes |
| 90 |
$attributes = null; |
| 91 |
if ($container->getAccountModule('account') != null) { |
| 92 |
$attributes = $container->getAccountModule('account')->getAttributes(); |
| 93 |
} |
| 94 |
elseif ($container->getAccountModule('device') != null) { |
| 95 |
$attributes = $container->getAccountModule('device')->getAttributes(); |
| 96 |
} |
| 97 |
elseif ($container->getAccountModule('windowsHost') != null) { |
| 98 |
$attributes = $container->getAccountModule('windowsHost')->getAttributes(); |
| 99 |
} |
| 100 |
// check if a user name is set |
| 101 |
if (isset($attributes['uid'][0])) { |
| 102 |
return htmlspecialchars($attributes['uid'][0]); |
| 103 |
} |
| 104 |
// check if a common name is set |
| 105 |
if (isset($attributes['cn'][0])) { |
| 106 |
return htmlspecialchars($attributes['cn'][0]); |
| 107 |
} |
| 108 |
if ($container->isNewAccount) { |
| 109 |
return _("New host"); |
| 110 |
} |
| 111 |
// fall back to default |
| 112 |
return parent::getTitleBarTitle($container); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* {@inheritDoc} |
| 117 |
*/ |
| 118 |
public function getTitleBarSubtitle(accountContainer $container): string { |
| 119 |
// get attributes |
| 120 |
$attributes = null; |
| 121 |
if ($container->getAccountModule('account') != null) { |
| 122 |
$attributes = $container->getAccountModule('account')->getAttributes(); |
| 123 |
} |
| 124 |
elseif ($container->getAccountModule('device') != null) { |
| 125 |
$attributes = $container->getAccountModule('device')->getAttributes(); |
| 126 |
} |
| 127 |
elseif ($container->getAccountModule('windowsHost') != null) { |
| 128 |
$attributes = $container->getAccountModule('windowsHost')->getAttributes(); |
| 129 |
} |
| 130 |
$sambaAttributes = null; |
| 131 |
if ($container->getAccountModule('sambaSamAccount') != null) { |
| 132 |
$sambaAttributes = $container->getAccountModule('sambaSamAccount')->getAttributes(); |
| 133 |
} |
| 134 |
// check if a display name is set |
| 135 |
if (($sambaAttributes != null) && isset($sambaAttributes['displayName'][0]) && ($sambaAttributes['displayName'][0] != '')) { |
| 136 |
return htmlspecialchars($sambaAttributes['displayName'][0]); |
| 137 |
} |
| 138 |
// check if a serial number is set |
| 139 |
if (($attributes != null) && isset($attributes['serialNumber'][0]) && ($attributes['serialNumber'][0] != '')) { |
| 140 |
return htmlspecialchars($attributes['serialNumber'][0]); |
| 141 |
} |
| 142 |
// check if a description is set |
| 143 |
if (($attributes != null) && isset($attributes['description'][0])) { |
| 144 |
return htmlspecialchars($attributes['description'][0]); |
| 145 |
} |
| 146 |
// fall back to default |
| 147 |
return parent::getTitleBarSubtitle($container); |
| 148 |
} |
| 149 |
|
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
/** |
| 154 |
* Generates the list view. |
| 155 |
* |
| 156 |
* @package lists |
| 157 |
* @author Roland Gruber |
| 158 |
* |
| 159 |
*/ |
| 160 |
class lamHostList extends lamList { |
| 161 |
|
| 162 |
/** |
| 163 |
* Constructor |
| 164 |
* |
| 165 |
* @param ConfiguredType $type account type |
| 166 |
*/ |
| 167 |
public function __construct(ConfiguredType $type) { |
| 168 |
parent::__construct($type); |
| 169 |
$this->labels = [ |
| 170 |
'nav' => _("Host count: %s"), |
| 171 |
'error_noneFound' => _("No hosts found!"), |
| 172 |
'newEntry' => _("New host"), |
| 173 |
'deleteEntry' => _("Delete selected hosts") |
| 174 |
]; |
| 175 |
} |
| 176 |
|
| 177 |
} |