| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 5 |
Copyright (C) 2005 - 2026 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 |
* Manages Samba 3 domain entries. |
| 24 |
* |
| 25 |
* @package modules |
| 26 |
* @author Roland Gruber |
| 27 |
*/ |
| 28 |
|
| 29 |
use LAM\TYPES\ConfiguredType; |
| 30 |
|
| 31 |
/** |
| 32 |
* Manages Samba 3 domain entries. |
| 33 |
* |
| 34 |
* @package modules |
| 35 |
*/ |
| 36 |
class sambaDomain extends baseModule { |
| 37 |
|
| 38 |
/** |
| 39 |
* These attributes will be ignored by default if a new account is copied from an existing one. |
| 40 |
*/ |
| 41 |
private const ATTRIBUTES_TO_IGNORE_ON_COPY = ['sambaDomainName', 'sambaSID', 'sambaNextRid', |
| 42 |
'sambaNextGroupRid', 'sambaNextUserRid']; |
| 43 |
|
| 44 |
/** |
| 45 |
* {@inheritDoc} |
| 46 |
*/ |
| 47 |
public function can_manage(): bool { |
| 48 |
return $this->get_scope() === 'smbDomain'; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* {@inheritDoc} |
| 53 |
*/ |
| 54 |
public function get_metaData(): array { |
| 55 |
$return = []; |
| 56 |
// icon |
| 57 |
$return['icon'] = 'samba.svg'; |
| 58 |
// alias name |
| 59 |
$return["alias"] = _("Samba domain"); |
| 60 |
// this is a base module |
| 61 |
$return["is_base"] = true; |
| 62 |
// RDN attribute |
| 63 |
$return["RDN"] = ["sambaDomainName" => "high"]; |
| 64 |
// LDAP filter |
| 65 |
$return["ldap_filter"] = ['or' => "(objectClass=sambaDomain)"]; |
| 66 |
// module dependencies |
| 67 |
$return['dependencies'] = ['depends' => [], 'conflicts' => []]; |
| 68 |
// managed object classes |
| 69 |
$return['objectClasses'] = ['sambaDomain']; |
| 70 |
// managed attributes |
| 71 |
$return['attributes'] = ['sambaDomainName', 'sambaSID', 'sambaNextRid', 'sambaNextGroupRid', |
| 72 |
'sambaNextUserRid', 'sambaAlgorithmicRidBase', 'sambaMinPwdLength', 'sambaPwdHistoryLength', |
| 73 |
'sambaLogonToChgPwd', 'sambaForceLogoff', 'sambaRefuseMachinePwdChange', 'sambaLockoutThreshold', |
| 74 |
'sambaMinPwdAge', 'sambaMaxPwdAge', 'sambaLockoutDuration', 'sambaLockoutObservationWindow']; |
| 75 |
// help Entries |
| 76 |
$return['help'] = [ |
| 77 |
'sambaDomainName' => [ |
| 78 |
"Headline" => _("Domain name"), 'attr' => 'sambaDomainName', |
| 79 |
"Text" => _("The name of your Windows domain or workgroup.") |
| 80 |
], |
| 81 |
'sambaSID' => [ |
| 82 |
"Headline" => _("Domain SID"), 'attr' => 'sambaSID', |
| 83 |
"Text" => _("The SID of your Samba server. Get it with \"net getlocalsid\".") |
| 84 |
], |
| 85 |
'nextRID' => [ |
| 86 |
"Headline" => _("Next RID"), 'attr' => 'sambaNextRid', |
| 87 |
"Text" => _("Next RID to use when creating accounts (only used by Winbind).") |
| 88 |
], |
| 89 |
'nextUserRID' => [ |
| 90 |
"Headline" => _("Next user RID"), 'attr' => 'sambaNextUserRid', |
| 91 |
"Text" => _("Next RID to use when creating user accounts (only used by Winbind).") |
| 92 |
], |
| 93 |
'nextGroupRID' => [ |
| 94 |
"Headline" => _("Next group RID"), 'attr' => 'sambaNextGroupRid', |
| 95 |
"Text" => _("Next RID to use when creating group accounts (only used by Winbind).") |
| 96 |
], |
| 97 |
'RIDbase' => [ |
| 98 |
"Headline" => _("RID base"), 'attr' => 'sambaAlgorithmicRidBase', |
| 99 |
"Text" => _("Used for calculating RIDs from UID/GID. Do not change if unsure.") |
| 100 |
], |
| 101 |
'minPwdLength' => [ |
| 102 |
"Headline" => _("Minimal password length"), 'attr' => 'sambaMinPwdLength', |
| 103 |
"Text" => _("Here you can specify the minimum number of characters for a user password.") |
| 104 |
], |
| 105 |
'pwdHistLength' => [ |
| 106 |
"Headline" => _("Password history length"), 'attr' => 'sambaPwdHistoryLength', |
| 107 |
"Text" => _("This is the number of passwords which are saved to prevent that users reuse old passwords.") |
| 108 |
], |
| 109 |
'logonToChgPwd' => [ |
| 110 |
"Headline" => _("Logon for password change"), 'attr' => 'sambaLogonToChgPwd', |
| 111 |
"Text" => _("If set then users need to login to change their password.") |
| 112 |
], |
| 113 |
'forceLogoff' => [ |
| 114 |
"Headline" => _("Disconnect users outside logon hours"), 'attr' => 'sambaForceLogoff', |
| 115 |
"Text" => _("Disconnects users if they are logged in outside logon hours.") |
| 116 |
], |
| 117 |
'refuseMachinePwdChange' => [ |
| 118 |
"Headline" => _("Allow machine password changes"), 'attr' => 'sambaRefuseMachinePwdChange', |
| 119 |
"Text" => _("Defines if workstations may change their passwords.") |
| 120 |
], |
| 121 |
'lockoutThreshold' => [ |
| 122 |
"Headline" => _("Lockout users after bad logon attempts"), 'attr' => 'sambaLockoutThreshold', |
| 123 |
"Text" => _("This is the number of bad logon attempts (0 - 999) before the account is deactivated. 0 means unlimited attempts.") |
| 124 |
], |
| 125 |
'minPwdAge' => [ |
| 126 |
"Headline" => _("Minimum password age"), 'attr' => 'sambaMinPwdAge', |
| 127 |
"Text" => _("Number of seconds after the user is allowed to change his password again.") |
| 128 |
], |
| 129 |
'maxPwdAge' => [ |
| 130 |
"Headline" => _("Maximum password age"), 'attr' => 'sambaMaxPwdAge', |
| 131 |
"Text" => _("Number of seconds after which the user must change his password.") |
| 132 |
], |
| 133 |
'lockoutDuration' => [ |
| 134 |
"Headline" => _("Lockout duration"), 'attr' => 'sambaLockoutDuration', |
| 135 |
"Text" => _("This is the time (in minutes) for which the user may not log in after the account was locked. -1 means forever.") |
| 136 |
], |
| 137 |
'lockoutObservationWindow' => [ |
| 138 |
"Headline" => _("Reset time after lockout"), 'attr' => 'sambaLockoutObservationWindow', |
| 139 |
"Text" => _("Number of minutes after which the bad logon attempts are reset.") |
| 140 |
]]; |
| 141 |
// upload fields |
| 142 |
$return['upload_columns'] = [ |
| 143 |
[ |
| 144 |
'name' => 'sambaDomain_domainName', |
| 145 |
'description' => _('Domain name'), |
| 146 |
'help' => 'sambaDomainName', |
| 147 |
'example' => _('Workgroup'), |
| 148 |
'required' => true |
| 149 |
], |
| 150 |
[ |
| 151 |
'name' => 'sambaDomain_domainSID', |
| 152 |
'description' => _('Domain SID'), |
| 153 |
'help' => 'sambaSID', |
| 154 |
'example' => 'S-1-1-22-123-123-123', |
| 155 |
'required' => true |
| 156 |
], |
| 157 |
[ |
| 158 |
'name' => 'sambaDomain_RIDbase', |
| 159 |
'description' => _('RID base'), |
| 160 |
'help' => 'RIDbase', |
| 161 |
'example' => '1000', |
| 162 |
'default' => 1000 |
| 163 |
], |
| 164 |
[ |
| 165 |
'name' => 'sambaDomain_nextRID', |
| 166 |
'description' => _('Next RID'), |
| 167 |
'help' => 'nextRID', |
| 168 |
'example' => '12345' |
| 169 |
], |
| 170 |
[ |
| 171 |
'name' => 'sambaDomain_nextUserRID', |
| 172 |
'description' => _('Next user RID'), |
| 173 |
'help' => 'nextUserRID', |
| 174 |
'example' => '12345' |
| 175 |
], |
| 176 |
[ |
| 177 |
'name' => 'sambaDomain_nextGroupRID', |
| 178 |
'description' => _('Next group RID'), |
| 179 |
'help' => 'nextGroupRID', |
| 180 |
'example' => '12345' |
| 181 |
] |
| 182 |
]; |
| 183 |
// available PDF fields |
| 184 |
$return['PDF_fields'] = [ |
| 185 |
'domainName' => _('Domain name'), |
| 186 |
'domainSID' => _('Domain SID'), |
| 187 |
'nextRID' => _('Next RID'), |
| 188 |
'nextUserRID' => _('Next user RID'), |
| 189 |
'nextGroupRID' => _('Next group RID'), |
| 190 |
'RIDbase' => _('RID base'), |
| 191 |
'minPwdLength' => _('Minimal password length'), |
| 192 |
'pwdHistoryLength' => _('Password history length'), |
| 193 |
'logonToChgPwd' => _('Logon for password change'), |
| 194 |
'forceLogoff' => _('Disconnect users outside logon hours'), |
| 195 |
'refuseMachinePwdChange' => _('Allow machine password changes'), |
| 196 |
'lockoutThreshold' => _('Lockout users after bad logon attempts'), |
| 197 |
'minPwdAge' => _('Minimum password age'), |
| 198 |
'maxPwdAge' => _('Maximum password age'), |
| 199 |
'lockoutDuration' => _('Lockout duration'), |
| 200 |
'lockoutObservationWindow' => _('Reset time after lockout') |
| 201 |
]; |
| 202 |
return $return; |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* {@inheritDoc} |
| 207 |
*/ |
| 208 |
protected function load_Messages(): void { |
| 209 |
$this->messages['domainName'][0] = ['ERROR', _('Domain name is invalid!')]; |
| 210 |
$this->messages['domainName'][1] = ['ERROR', _('Account %s:') . ' sambaDomain_domainName', _('Domain name is invalid!')]; |
| 211 |
$this->messages['domainSID'][0] = ['ERROR', _('Samba 3 domain SID is invalid!')]; |
| 212 |
$this->messages['domainSID'][1] = ['ERROR', _('Account %s:') . ' sambaDomain_domainSID', _('Samba 3 domain SID is invalid!')]; |
| 213 |
$this->messages['nextRID'][0] = ['ERROR', _('Next RID is not a number!')]; |
| 214 |
$this->messages['nextRID'][1] = ['ERROR', _('Account %s:') . ' sambaDomain_nextRID', _('Next RID is not a number!')]; |
| 215 |
$this->messages['nextUserRID'][0] = ['ERROR', _('Next user RID is not a number!')]; |
| 216 |
$this->messages['nextUserRID'][1] = ['ERROR', _('Account %s:') . ' sambaDomain_nextUserRID', _('Next user RID is not a number!')]; |
| 217 |
$this->messages['nextGroupRID'][0] = ['ERROR', _('Next group RID is not a number!')]; |
| 218 |
$this->messages['nextGroupRID'][1] = ['ERROR', _('Account %s:') . ' sambaDomain_nextGroupRID', _('Next group RID is not a number!')]; |
| 219 |
$this->messages['RIDbase'][0] = ['ERROR', _('Algorithmic RID base is not a number!')]; |
| 220 |
$this->messages['RIDbase'][1] = ['ERROR', _('Account %s:') . ' sambaDomain_RIDbase', _('Algorithmic RID base is not a number!')]; |
| 221 |
$this->messages['pwdAge_cmp'][0] = ['ERROR', _('Maximum password age'), _('Password maximum age must be bigger than password minimum age.')]; |
| 222 |
$this->messages['pwdAgeMin'][0] = ['ERROR', _('Minimum password age'), _('Password minimum age must be are natural number.')]; |
| 223 |
$this->messages['pwdAgeMax'][0] = ['ERROR', _('Maximum password age'), _('Password maximum age must be are natural number.')]; |
| 224 |
$this->messages['lockoutDuration'][0] = ['ERROR', _('Lockout duration'), _('Lockout duration must be are natural number.')]; |
| 225 |
$this->messages['lockoutObservationWindow'][0] = ['ERROR', _('Reset time after lockout'), _('Reset time after lockout must be are natural number.')]; |
| 226 |
$this->messages['lockoutThreshold'][0] = ['ERROR', _('Lockout users after bad logon attempts'), _('Lockout users after bad logon attempts must be between 0 and 999.')]; |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* {@inheritDoc} |
| 231 |
*/ |
| 232 |
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void { |
| 233 |
parent::loadAttributesFromAccountCopy($ldapAttributes, array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY)); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* {@inheritDoc} |
| 238 |
*/ |
| 239 |
public function display_html_attributes(): htmlElement|array { |
| 240 |
$return = new htmlResponsiveRow(); |
| 241 |
// domain name |
| 242 |
if ($this->getAccountContainer()->isNewAccount) { |
| 243 |
$this->addSimpleInputTextField($return, 'sambaDomainName', _('Domain name'), true); |
| 244 |
} |
| 245 |
else { |
| 246 |
$return->addLabel(new htmlOutputText(_('Domain name'))); |
| 247 |
$domainNameGroup = new htmlGroup(); |
| 248 |
$domainName = $this->attributes['sambaDomainName'][0]; |
| 249 |
$domainNameGroup->addElement(new htmlOutputText($domainName)); |
| 250 |
$domainNameGroup->addElement(new htmlHelpLink('sambaDomainName')); |
| 251 |
$return->addField($domainNameGroup); |
| 252 |
} |
| 253 |
// domain SID |
| 254 |
if ($this->getAccountContainer()->isNewAccount) { |
| 255 |
$this->addSimpleInputTextField($return, 'sambaSID', _('Domain SID'), true); |
| 256 |
} |
| 257 |
else { |
| 258 |
$return->addLabel(new htmlOutputText(_('Domain SID'))); |
| 259 |
$domainSidGroup = new htmlGroup(); |
| 260 |
$domainSID = $this->attributes['sambaSID'][0]; |
| 261 |
$domainSidGroup->addElement(new htmlOutputText($domainSID)); |
| 262 |
$domainSidGroup->addElement(new htmlHelpLink('sambaSID')); |
| 263 |
$return->addField($domainSidGroup); |
| 264 |
} |
| 265 |
|
| 266 |
$return->add(new htmlSubTitle(_("Password policy"))); |
| 267 |
|
| 268 |
/* group policies */ |
| 269 |
|
| 270 |
// minimum password length |
| 271 |
$sambaMinPwdLength = '-'; |
| 272 |
if (isset($this->attributes['sambaMinPwdLength'][0])) { |
| 273 |
$sambaMinPwdLength = $this->attributes['sambaMinPwdLength'][0]; |
| 274 |
} |
| 275 |
$return->add(new htmlResponsiveSelect('minPwdLength', ['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15'], |
| 276 |
[$sambaMinPwdLength], _('Minimal password length'), 'minPwdLength')); |
| 277 |
// password history length |
| 278 |
$sambaPwdHistoryLength = '-'; |
| 279 |
if (isset($this->attributes['sambaPwdHistoryLength'][0])) { |
| 280 |
$sambaPwdHistoryLength = $this->attributes['sambaPwdHistoryLength'][0]; |
| 281 |
} |
| 282 |
$return->add(new htmlResponsiveSelect('pwdHistLength', ['-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15'], |
| 283 |
[$sambaPwdHistoryLength], _('Password history length'), 'pwdHistLength')); |
| 284 |
// logon to change password |
| 285 |
$sambaLogonToChgPwd = '-'; |
| 286 |
if (isset($this->attributes['sambaLogonToChgPwd'][0])) { |
| 287 |
$sambaLogonToChgPwd = $this->attributes['sambaLogonToChgPwd'][0]; |
| 288 |
} |
| 289 |
$logonPwdChangeSelect = new htmlResponsiveSelect('logonToChgPwd', ['-' => '-', _('Off') => '0', _('On') => '2'], |
| 290 |
[$sambaLogonToChgPwd], _('Logon for password change'), 'logonToChgPwd'); |
| 291 |
$logonPwdChangeSelect->setHasDescriptiveElements(true); |
| 292 |
$return->add($logonPwdChangeSelect); |
| 293 |
// force logoff |
| 294 |
$sambaForceLogoff = '-'; |
| 295 |
if (isset($this->attributes['sambaForceLogoff'][0])) { |
| 296 |
$sambaForceLogoff = $this->attributes['sambaForceLogoff'][0]; |
| 297 |
} |
| 298 |
$forceLogoffSelect = new htmlResponsiveSelect('forceLogoff', ['-' => '-', _('Off') => '-1', _('On') => '0'], |
| 299 |
[$sambaForceLogoff], _('Disconnect users outside logon hours'), 'forceLogoff'); |
| 300 |
$forceLogoffSelect->setHasDescriptiveElements(true); |
| 301 |
$return->add($forceLogoffSelect); |
| 302 |
// do not allow machine password change |
| 303 |
$sambaRefuseMachinePwdChange = '-'; |
| 304 |
if (isset($this->attributes['sambaRefuseMachinePwdChange'][0])) { |
| 305 |
$sambaRefuseMachinePwdChange = $this->attributes['sambaRefuseMachinePwdChange'][0]; |
| 306 |
} |
| 307 |
$refuseMachPwdChange = new htmlResponsiveSelect('refuseMachinePwdChange', ['-' => '-', _('Off') => '0', _('On') => '1'], |
| 308 |
[$sambaRefuseMachinePwdChange], _('Allow machine password changes'), 'refuseMachinePwdChange'); |
| 309 |
$refuseMachPwdChange->setHasDescriptiveElements(true); |
| 310 |
$return->add($refuseMachPwdChange); |
| 311 |
// Lockout users after bad logon attempts |
| 312 |
$sambaLockoutThreshold = ''; |
| 313 |
if (isset($this->attributes['sambaLockoutThreshold'][0])) { |
| 314 |
$sambaLockoutThreshold = $this->attributes['sambaLockoutThreshold'][0]; |
| 315 |
} |
| 316 |
$sambaLockoutThresholdInput = new htmlResponsiveInputField(_('Lockout users after bad logon attempts'), 'lockoutThreshold', $sambaLockoutThreshold, 'lockoutThreshold'); |
| 317 |
$sambaLockoutThresholdInput->setType('number'); |
| 318 |
$return->add($sambaLockoutThresholdInput); |
| 319 |
// Minimum password age |
| 320 |
$sambaMinPwdAge = ''; |
| 321 |
if (isset($this->attributes['sambaMinPwdAge'][0])) { |
| 322 |
$sambaMinPwdAge = $this->attributes['sambaMinPwdAge'][0]; |
| 323 |
} |
| 324 |
$sambaMinPwdAgeInput = new htmlResponsiveInputField(_('Minimum password age'), 'minPwdAge', $sambaMinPwdAge, 'minPwdAge'); |
| 325 |
$sambaMinPwdAgeInput->setType('number'); |
| 326 |
$return->add($sambaMinPwdAgeInput); |
| 327 |
// Maximum password age |
| 328 |
$sambaMaxPwdAge = ''; |
| 329 |
if (isset($this->attributes['sambaMaxPwdAge'][0])) { |
| 330 |
$sambaMaxPwdAge = $this->attributes['sambaMaxPwdAge'][0]; |
| 331 |
} |
| 332 |
$sambaMaxPwdAgeInput = new htmlResponsiveInputField(_('Maximum password age'), 'maxPwdAge', $sambaMaxPwdAge, 'maxPwdAge'); |
| 333 |
$sambaMaxPwdAgeInput->setValidationPattern('[-]?[0-9]+'); |
| 334 |
$return->add($sambaMaxPwdAgeInput); |
| 335 |
// Lockout duration |
| 336 |
$sambaLockoutDuration = ''; |
| 337 |
if (isset($this->attributes['sambaLockoutDuration'][0])) { |
| 338 |
$sambaLockoutDuration = $this->attributes['sambaLockoutDuration'][0]; |
| 339 |
} |
| 340 |
$sambaLockoutDurationInput = new htmlResponsiveInputField(_('Lockout duration'), 'lockoutDuration', $sambaLockoutDuration, 'lockoutDuration'); |
| 341 |
$sambaLockoutDurationInput->setType('number'); |
| 342 |
$return->add($sambaLockoutDurationInput); |
| 343 |
// Reset time after lockout |
| 344 |
$sambaLockoutObservationWindow = ''; |
| 345 |
if (isset($this->attributes['sambaLockoutObservationWindow'][0])) { |
| 346 |
$sambaLockoutObservationWindow = $this->attributes['sambaLockoutObservationWindow'][0]; |
| 347 |
} |
| 348 |
$sambaLockoutObservationWindowInput = new htmlResponsiveInputField(_('Reset time after lockout'), 'lockoutObservationWindow', $sambaLockoutObservationWindow, 'lockoutObservationWindow'); |
| 349 |
$sambaLockoutObservationWindowInput->setType('number'); |
| 350 |
$return->add($sambaLockoutObservationWindowInput); |
| 351 |
|
| 352 |
$return->add(new htmlSubTitle(_('RID settings'))); |
| 353 |
|
| 354 |
/* RID settings */ |
| 355 |
|
| 356 |
// next RID |
| 357 |
$nextRID = ''; |
| 358 |
if (isset($this->attributes['sambaNextRid'][0])) { |
| 359 |
$nextRID = $this->attributes['sambaNextRid'][0]; |
| 360 |
} |
| 361 |
$nextRIDInput = new htmlResponsiveInputField(_('Next RID'), 'nextRID', $nextRID, 'nextRID'); |
| 362 |
$nextRIDInput->setMinimumAndMaximumNumber(); |
| 363 |
$return->add($nextRIDInput); |
| 364 |
// next user RID |
| 365 |
$nextUserRID = ''; |
| 366 |
if (isset($this->attributes['sambaNextUserRid'][0])) { |
| 367 |
$nextUserRID = $this->attributes['sambaNextUserRid'][0]; |
| 368 |
} |
| 369 |
$nextUserRIDInput = new htmlResponsiveInputField(_('Next user RID'), 'nextUserRID', $nextUserRID, 'nextUserRID'); |
| 370 |
$nextUserRIDInput->setMinimumAndMaximumNumber(); |
| 371 |
$return->add($nextUserRIDInput); |
| 372 |
// next group RID |
| 373 |
$nextGroupRID = ''; |
| 374 |
if (isset($this->attributes['sambaNextGroupRid'][0])) { |
| 375 |
$nextGroupRID = $this->attributes['sambaNextGroupRid'][0]; |
| 376 |
} |
| 377 |
$nextGroupRIDInput = new htmlResponsiveInputField(_('Next group RID'), 'nextGroupRID', $nextGroupRID, 'nextGroupRID'); |
| 378 |
$nextGroupRIDInput->setMinimumAndMaximumNumber(); |
| 379 |
$return->add($nextGroupRIDInput); |
| 380 |
// RID base |
| 381 |
if (!isset($this->attributes['sambaAlgorithmicRidBase'][0])) { |
| 382 |
$this->attributes['sambaAlgorithmicRidBase'][0] = 1000; |
| 383 |
} |
| 384 |
if ($this->getAccountContainer()->isNewAccount) { |
| 385 |
$ridBaseInput = new htmlResponsiveInputField(_('RID base'), 'RIDbase', $this->attributes['sambaAlgorithmicRidBase'][0], 'RIDbase'); |
| 386 |
$ridBaseInput->setRequired(true); |
| 387 |
$ridBaseInput->setMinimumAndMaximumNumber(); |
| 388 |
$return->add($ridBaseInput); |
| 389 |
} |
| 390 |
else { |
| 391 |
$return->addLabel(new htmlOutputText(_('RID base'))); |
| 392 |
$ridBaseGroup = new htmlGroup(); |
| 393 |
$ridBaseGroup->addElement(new htmlOutputText($this->attributes['sambaAlgorithmicRidBase'][0])); |
| 394 |
$ridBaseGroup->addElement(new htmlHelpLink('RIDbase')); |
| 395 |
$return->addField($ridBaseGroup); |
| 396 |
} |
| 397 |
return $return; |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* {@inheritDoc} |
| 402 |
*/ |
| 403 |
public function process_attributes(): array { |
| 404 |
$errors = []; |
| 405 |
if ($this->getAccountContainer()->isNewAccount) { |
| 406 |
// domain SID |
| 407 |
$this->attributes['sambaSID'][0] = $_POST['sambaSID']; |
| 408 |
if (!get_preg($_POST['sambaSID'], 'domainSID')) { |
| 409 |
$errors[] = $this->messages['domainSID'][0]; |
| 410 |
} |
| 411 |
else { |
| 412 |
$this->attributes['sambaSID'][0] = $_POST['sambaSID']; |
| 413 |
} |
| 414 |
// RID base |
| 415 |
if (!get_preg($_POST['RIDbase'], 'digit') && ($_POST['RIDbase'] != '')) { |
| 416 |
$errors[] = $this->messages['RIDbase'][0]; |
| 417 |
} |
| 418 |
else { |
| 419 |
$this->attributes['sambaAlgorithmicRidBase'][0] = $_POST['RIDbase']; |
| 420 |
} |
| 421 |
// domain name |
| 422 |
if (!get_preg($_POST['sambaDomainName'], 'domainname') && ($_POST['sambaDomainName'] != '')) { |
| 423 |
$errors[] = $this->messages['domainName'][0]; |
| 424 |
} |
| 425 |
else { |
| 426 |
$this->attributes['sambaDomainName'][0] = $_POST['sambaDomainName']; |
| 427 |
} |
| 428 |
} |
| 429 |
// next RID |
| 430 |
if (!get_preg($_POST['nextRID'], 'digit')) { |
| 431 |
$errors[] = $this->messages['nextRID'][0]; |
| 432 |
} |
| 433 |
else { |
| 434 |
$this->attributes['sambaNextRid'][0] = $_POST['nextRID']; |
| 435 |
} |
| 436 |
// next user RID |
| 437 |
if (!get_preg($_POST['nextUserRID'], 'digit')) { |
| 438 |
$errors[] = $this->messages['nextUserRID'][0]; |
| 439 |
} |
| 440 |
else { |
| 441 |
$this->attributes['sambaNextUserRid'][0] = $_POST['nextUserRID']; |
| 442 |
} |
| 443 |
// next group RID |
| 444 |
if (!get_preg($_POST['nextGroupRID'], 'digit')) { |
| 445 |
$errors[] = $this->messages['nextGroupRID'][0]; |
| 446 |
} |
| 447 |
else { |
| 448 |
$this->attributes['sambaNextGroupRid'][0] = $_POST['nextGroupRID']; |
| 449 |
} |
| 450 |
// minimum password length |
| 451 |
if ($_POST['minPwdLength'] === '-') { |
| 452 |
if (isset($this->attributes['sambaMinPwdLength'])) { |
| 453 |
unset($this->attributes['sambaMinPwdLength'][0]); |
| 454 |
} |
| 455 |
} |
| 456 |
else { |
| 457 |
$this->attributes['sambaMinPwdLength'][0] = $_POST['minPwdLength']; |
| 458 |
} |
| 459 |
// password history length |
| 460 |
if ($_POST['pwdHistLength'] === '-') { |
| 461 |
if (isset($this->attributes['sambaPwdHistoryLength'])) { |
| 462 |
unset($this->attributes['sambaPwdHistoryLength'][0]); |
| 463 |
} |
| 464 |
} |
| 465 |
else { |
| 466 |
$this->attributes['sambaPwdHistoryLength'][0] = $_POST['pwdHistLength']; |
| 467 |
} |
| 468 |
// logon for password change |
| 469 |
if ($_POST['logonToChgPwd'] === '-') { |
| 470 |
if (isset($this->attributes['sambaLogonToChgPwd'])) { |
| 471 |
unset($this->attributes['sambaLogonToChgPwd'][0]); |
| 472 |
} |
| 473 |
} |
| 474 |
else { |
| 475 |
$this->attributes['sambaLogonToChgPwd'][0] = $_POST['logonToChgPwd']; |
| 476 |
} |
| 477 |
// force logoff |
| 478 |
if ($_POST['forceLogoff'] === '-') { |
| 479 |
if (isset($this->attributes['sambaForceLogoff'])) { |
| 480 |
unset($this->attributes['sambaForceLogoff'][0]); |
| 481 |
} |
| 482 |
} |
| 483 |
else { |
| 484 |
$this->attributes['sambaForceLogoff'][0] = $_POST['forceLogoff']; |
| 485 |
} |
| 486 |
// do not allow machine password changes |
| 487 |
if ($_POST['refuseMachinePwdChange'] === '-') { |
| 488 |
if (isset($this->attributes['sambaRefuseMachinePwdChange'])) { |
| 489 |
unset($this->attributes['sambaRefuseMachinePwdChange'][0]); |
| 490 |
} |
| 491 |
} |
| 492 |
else { |
| 493 |
$this->attributes['sambaRefuseMachinePwdChange'][0] = $_POST['refuseMachinePwdChange']; |
| 494 |
} |
| 495 |
// Lockout users after bad logon attempts |
| 496 |
if (!isset($_POST['lockoutThreshold']) || ($_POST['lockoutThreshold'] == '')) { |
| 497 |
if (isset($this->attributes['sambaLockoutThreshold'])) { |
| 498 |
unset($this->attributes['sambaLockoutThreshold'][0]); |
| 499 |
} |
| 500 |
} |
| 501 |
elseif (is_numeric($_POST['lockoutThreshold']) && ($_POST['lockoutThreshold'] >= 0) && ($_POST['lockoutThreshold'] < 1000)) { |
| 502 |
$this->attributes['sambaLockoutThreshold'][0] = $_POST['lockoutThreshold']; |
| 503 |
} |
| 504 |
else { |
| 505 |
$errors[] = $this->messages['lockoutThreshold'][0]; |
| 506 |
} |
| 507 |
// Minimum password age |
| 508 |
if (!isset($_POST['minPwdAge']) || ($_POST['minPwdAge'] == '')) { |
| 509 |
if (isset($this->attributes['sambaMinPwdAge'])) { |
| 510 |
unset($this->attributes['sambaMinPwdAge'][0]); |
| 511 |
} |
| 512 |
} |
| 513 |
elseif (is_numeric($_POST['minPwdAge']) && ($_POST['minPwdAge'] > -2)) { |
| 514 |
$this->attributes['sambaMinPwdAge'][0] = $_POST['minPwdAge']; |
| 515 |
} |
| 516 |
else { |
| 517 |
$errors[] = $this->messages['pwdAgeMin'][0]; |
| 518 |
} |
| 519 |
// Maximum password age |
| 520 |
if (!isset($_POST['maxPwdAge']) || ($_POST['maxPwdAge'] == '')) { |
| 521 |
if (isset($this->attributes['sambaMaxPwdAge'])) { |
| 522 |
unset($this->attributes['sambaMaxPwdAge'][0]); |
| 523 |
} |
| 524 |
} |
| 525 |
elseif (!is_numeric($_POST['maxPwdAge']) || ($_POST['maxPwdAge'] < -1)) { |
| 526 |
$errors[] = $this->messages['pwdAgeMax'][0]; |
| 527 |
} |
| 528 |
elseif (($_POST['maxPwdAge'] > 1) && ($_POST['maxPwdAge'] < $_POST['minPwdAge'])) { |
| 529 |
$errors[] = $this->messages['pwdAge_cmp'][0]; |
| 530 |
} |
| 531 |
else { |
| 532 |
$this->attributes['sambaMaxPwdAge'][0] = $_POST['maxPwdAge']; |
| 533 |
} |
| 534 |
// Lockout duration |
| 535 |
if (!isset($_POST['lockoutDuration']) || ($_POST['lockoutDuration'] == '')) { |
| 536 |
if (isset($this->attributes['sambaLockoutDuration'])) { |
| 537 |
unset($this->attributes['sambaLockoutDuration'][0]); |
| 538 |
} |
| 539 |
} |
| 540 |
elseif (is_numeric($_POST['lockoutDuration']) && ($_POST['lockoutDuration'] > -2)) { |
| 541 |
$this->attributes['sambaLockoutDuration'][0] = $_POST['lockoutDuration']; |
| 542 |
} |
| 543 |
else { |
| 544 |
$errors[] = $this->messages['lockoutDuration'][0]; |
| 545 |
} |
| 546 |
// Reset time after lockout |
| 547 |
if (!isset($_POST['lockoutObservationWindow']) || ($_POST['lockoutObservationWindow'] == '')) { |
| 548 |
if (isset($this->attributes['sambaLockoutObservationWindow'])) { |
| 549 |
unset($this->attributes['sambaLockoutObservationWindow'][0]); |
| 550 |
} |
| 551 |
} |
| 552 |
elseif (is_numeric($_POST['lockoutObservationWindow']) && ($_POST['lockoutObservationWindow'] > -1)) { |
| 553 |
$this->attributes['sambaLockoutObservationWindow'][0] = $_POST['lockoutObservationWindow']; |
| 554 |
} |
| 555 |
else { |
| 556 |
$errors[] = $this->messages['lockoutObservationWindow'][0]; |
| 557 |
} |
| 558 |
|
| 559 |
return $errors; |
| 560 |
} |
| 561 |
|
| 562 |
/** |
| 563 |
* {@inheritDoc} |
| 564 |
*/ |
| 565 |
public function build_uploadAccounts(array $rawAccounts, array $ids, array &$partialAccounts, array $selectedModules, ConfiguredType &$type): array { |
| 566 |
$messages = []; |
| 567 |
for ($i = 0; $i < count($rawAccounts); $i++) { |
| 568 |
// add object class |
| 569 |
if (!in_array("sambaDomain", $partialAccounts[$i]['objectClass'])) { |
| 570 |
$partialAccounts[$i]['objectClass'][] = "sambaDomain"; |
| 571 |
} |
| 572 |
// domain name |
| 573 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'sambaDomain_domainName', 'sambaDomainName', |
| 574 |
'domainname', $this->messages['domainName'][1], $messages); |
| 575 |
// domain SID |
| 576 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'sambaDomain_domainSID', 'sambaSID', |
| 577 |
'domainSID', $this->messages['domainSID'][1], $messages); |
| 578 |
// RID base |
| 579 |
$partialAccounts[$i]['sambaAlgorithmicRidBase'] = '1000'; |
| 580 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'sambaDomain_RIDbase', 'sambaAlgorithmicRidBase', |
| 581 |
'digit', $this->messages['RIDbase'][1], $messages); |
| 582 |
// next RID |
| 583 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'sambaDomain_nextRID', 'sambaNextRid', |
| 584 |
'digit', $this->messages['nextRID'][1], $messages); |
| 585 |
// next user RID |
| 586 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'sambaDomain_nextUserRID', 'sambaNextUserRid', |
| 587 |
'digit', $this->messages['nextUserRID'][1], $messages); |
| 588 |
// next group RID |
| 589 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'sambaDomain_nextGroupRID', 'sambaNextGroupRid', |
| 590 |
'digit', $this->messages['nextGroupRID'][1], $messages); |
| 591 |
} |
| 592 |
return $messages; |
| 593 |
} |
| 594 |
|
| 595 |
/** |
| 596 |
* {@inheritDoc} |
| 597 |
*/ |
| 598 |
public function get_pdfEntries(array $pdfKeys, string $typeId): array { |
| 599 |
$return = []; |
| 600 |
$this->addSimplePDFField($return, 'domainName', _('Domain name'), 'sambaDomainName'); |
| 601 |
$this->addSimplePDFField($return, 'domainSID', _('Domain SID'), 'sambaSID'); |
| 602 |
$this->addSimplePDFField($return, 'nextRID', _('Next RID'), 'sambaNextRid'); |
| 603 |
$this->addSimplePDFField($return, 'nextUserRID', _('Next user RID'), 'sambaNextUserRid'); |
| 604 |
$this->addSimplePDFField($return, 'nextGroupRID', _('Next group RID'), 'sambaNextGroupRid'); |
| 605 |
$this->addSimplePDFField($return, 'RIDbase', _('RID base'), 'sambaAlgorithmicRidBase'); |
| 606 |
$this->addSimplePDFField($return, 'minPwdLength', _('Minimal password length'), 'sambaMinPwdLength'); |
| 607 |
$this->addSimplePDFField($return, 'pwdHistoryLength', _('Password history length'), 'sambaPwdHistoryLength'); |
| 608 |
$this->addSimplePDFField($return, 'lockoutThreshold', _('Lockout users after bad logon attempts'), 'sambaLockoutThreshold'); |
| 609 |
$this->addSimplePDFField($return, 'minPwdAge', _('Minimum password age'), 'sambaMinPwdAge'); |
| 610 |
$this->addSimplePDFField($return, 'maxPwdAge', _('Maximum password age'), 'sambaMaxPwdAge'); |
| 611 |
$this->addSimplePDFField($return, 'lockoutDuration', _('Lockout duration'), 'sambaLockoutDuration'); |
| 612 |
$this->addSimplePDFField($return, 'lockoutObservationWindow', _('Reset time after lockout'), 'sambaLockoutObservationWindow'); |
| 613 |
|
| 614 |
if (isset($this->attributes['sambaLogonToChgPwd'])) { |
| 615 |
$logonToChgPwd = _('Off'); |
| 616 |
if ($this->attributes['sambaPwdHistoryLength'][0] == 2) { |
| 617 |
$logonToChgPwd = _('On'); |
| 618 |
} |
| 619 |
$this->addPDFKeyValue($return, 'logonToChgPwd', _('Logon for password change'), $logonToChgPwd); |
| 620 |
} |
| 621 |
if (isset($this->attributes['sambaForceLogoff'])) { |
| 622 |
$forceLogoff = _('Off'); |
| 623 |
if ($this->attributes['sambaForceLogoff'][0] == 0) { |
| 624 |
$forceLogoff = _('On'); |
| 625 |
} |
| 626 |
$this->addPDFKeyValue($return, 'forceLogoff', _('Disconnect users outside logon hours'), $forceLogoff); |
| 627 |
} |
| 628 |
if (isset($this->attributes['sambaRefuseMachinePwdChange'])) { |
| 629 |
$refuseMachinePwdChange = _('Off'); |
| 630 |
if ($this->attributes['sambaRefuseMachinePwdChange'][0] == 0) { |
| 631 |
$refuseMachinePwdChange = _('On'); |
| 632 |
} |
| 633 |
$this->addPDFKeyValue($return, 'refuseMachinePwdChange', _('Allow machine password changes'), $refuseMachinePwdChange); |
| 634 |
} |
| 635 |
return $return; |
| 636 |
} |
| 637 |
|
| 638 |
/** |
| 639 |
* @inheritDoc |
| 640 |
*/ |
| 641 |
public function getListAttributeDescriptions(ConfiguredType $type): array { |
| 642 |
return [ |
| 643 |
"sambasid" => _("Domain SID"), |
| 644 |
"sambadomainname" => _("Domain name") |
| 645 |
]; |
| 646 |
} |
| 647 |
|
| 648 |
} |