| 1 |
<?php |
| 2 |
|
| 3 |
use LAM\JOB\AccountExpirationCleanupJob; |
| 4 |
use LAM\JOB\JobResultLog; |
| 5 |
use LAM\JOB\PasswordExpirationJob; |
| 6 |
use LAM\TYPES\TypeManager; |
| 7 |
use LAM\TYPES\ConfiguredType; |
| 8 |
use LAM\ImageUtils\ImageManipulationFactory; |
| 9 |
|
| 10 |
/* |
| 11 |
|
| 12 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 13 |
Copyright (C) 2013 - 2026 Roland Gruber |
| 14 |
|
| 15 |
This program is free software; you can redistribute it and/or modify |
| 16 |
it under the terms of the GNU General Public License as published by |
| 17 |
the Free Software Foundation; either version 2 of the License, or |
| 18 |
(at your option) any later version. |
| 19 |
|
| 20 |
This program is distributed in the hope that it will be useful, |
| 21 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
GNU General Public License for more details. |
| 24 |
|
| 25 |
You should have received a copy of the GNU General Public License |
| 26 |
along with this program; if not, write to the Free Software |
| 27 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
*/ |
| 29 |
|
| 30 |
/** |
| 31 |
* Manages Windows AD (e.g. Samba 4) users. |
| 32 |
* |
| 33 |
* @package modules |
| 34 |
* @author Roland Gruber |
| 35 |
*/ |
| 36 |
|
| 37 |
/** |
| 38 |
* Manages Windows AD (e.g. Samba 4) users. |
| 39 |
* |
| 40 |
* @package modules |
| 41 |
*/ |
| 42 |
class windowsUser extends baseModule implements passwordService, AccountStatusProvider { |
| 43 |
|
| 44 |
/** |
| 45 |
* ID for locked password status. |
| 46 |
*/ |
| 47 |
private const STATUS_PASSWORD_LOCKED = "WINDOWS_PASSWORD_LOCKED"; |
| 48 |
|
| 49 |
/** |
| 50 |
* ID for locked account status. |
| 51 |
*/ |
| 52 |
private const STATUS_ACCOUNT_LOCKED = "WINDOWS_ACCOUNT_LOCKED"; |
| 53 |
|
| 54 |
/** |
| 55 |
* ID for expired account status. |
| 56 |
*/ |
| 57 |
private const STATUS_ACCOUNT_EXPIRED = "WINDOWS_ACCOUNT_EXPIRED"; |
| 58 |
|
| 59 |
/** |
| 60 |
* These attributes will be ignored by default if a new account is copied from an existing one. |
| 61 |
*/ |
| 62 |
private const ATTRIBUTES_TO_IGNORE_ON_COPY = ['userPrincipalName', 'sAMAccountName', 'displayName', |
| 63 |
'profilePath', 'scriptPath', 'pwdLastSet', 'otherMailbox', 'homeDirectory', 'msSFU30Name', |
| 64 |
'pwdLastSet', 'lastLogonTimestamp', 'accountexpires', 'lockouttime', 'personaltitle', 'roomnumber', |
| 65 |
'jpegPhoto', 'thumbnailphoto']; |
| 66 |
|
| 67 |
/** HEX to binary conversion table */ |
| 68 |
private const HEX2BIT_STRING = ['0' => '0000', '1' => '0001', '2' => '0010', '3' => '0011', '4' => '0100', |
| 69 |
'5' => '0101', '6' => '0110', '7' => '0111', '8' => '1000', '9' => '1001', 'a' => '1010', |
| 70 |
'b' => '1011', 'c' => '1100', 'd' => '1101', 'e' => '1110', 'f' => '1111']; |
| 71 |
|
| 72 |
/** initial account flags */ |
| 73 |
private const DEFAULT_ACCOUNT_CONTROL = 0x00000200; |
| 74 |
/** password never expires */ |
| 75 |
private const AC_PWD_NEVER_EXPIRES = 0x00010000; |
| 76 |
/** login requires smartcard */ |
| 77 |
private const AC_SMARTCARD_REQUIRED = 0x00040000; |
| 78 |
/** account is disabled */ |
| 79 |
private const AC_ACCOUNT_DISABLED = 0x00000002; |
| 80 |
|
| 81 |
/** display groups as dn */ |
| 82 |
private const DISPLAY_GROUPS_DN = 'DN'; |
| 83 |
/** display groups as cn */ |
| 84 |
private const DISPLAY_GROUPS_CN = 'CN'; |
| 85 |
public const ACCOUNT_DOES_NOT_EXPIRE = '9223372036854775807'; |
| 86 |
|
| 87 |
/** @var string[] $groupList current group list */ |
| 88 |
private array $groupList = []; |
| 89 |
/** @var string[] $groupList_orig original group list */ |
| 90 |
private array $groupList_orig = []; |
| 91 |
/** @var string[]|null $groupCache cache for groups */ |
| 92 |
private ?array $groupCache = null; |
| 93 |
/** @var string[]|null $cachedHostList host cache to reduce LDAP queries */ |
| 94 |
private ?array $cachedHostList = null; |
| 95 |
/** @var string|null $pwdLastSet option for forcing password change, used in postModifyActions */ |
| 96 |
private ?string $pwdLastSet = null; |
| 97 |
/** @var string|null $clearTextPassword clear text password */ |
| 98 |
private ?string $clearTextPassword = null; |
| 99 |
/** @var string[]|null $departmentCache cache for departments */ |
| 100 |
private ?array $departmentCache = null; |
| 101 |
/** @var string[]|null $departmentNumberCache cache for department numbers */ |
| 102 |
private ?array $departmentNumberCache = null; |
| 103 |
/** @var string[]|null $oCache organization cache */ |
| 104 |
private ?array $oCache = null; |
| 105 |
/** @var string[]|null $ouCache organizational unit cache */ |
| 106 |
private ?array $ouCache = null; |
| 107 |
/** @var string[]|null $titleCache title cache */ |
| 108 |
private ?array $titleCache = null; |
| 109 |
/** @var string[]|null $employeeTypeCache employee type cache */ |
| 110 |
private ?array $employeeTypeCache = null; |
| 111 |
/** @var string[]|null $businessCategoryCache business category cache */ |
| 112 |
private ?array $businessCategoryCache = null; |
| 113 |
|
| 114 |
/** @var array<string, string> $cachedUserNameList cache for username */ |
| 115 |
private ?array $cachedUserNameList = null; |
| 116 |
/** @var array<string, string> $cachedCnList cache for cn */ |
| 117 |
private ?array $cachedCnList = null; |
| 118 |
|
| 119 |
|
| 120 |
/** |
| 121 |
* {@inheritDoc} |
| 122 |
*/ |
| 123 |
public function can_manage(): bool { |
| 124 |
return $this->get_scope() === 'user'; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* {@inheritDoc} |
| 129 |
*/ |
| 130 |
public function get_metaData(): array { |
| 131 |
$return = []; |
| 132 |
// icon |
| 133 |
$return['icon'] = 'samba.svg'; |
| 134 |
// this is a base module |
| 135 |
$return["is_base"] = true; |
| 136 |
// RDN attribute |
| 137 |
$return["RDN"] = ["cn" => "high"]; |
| 138 |
// LDAP filter |
| 139 |
$return["ldap_filter"] = ['and' => '(!(objectClass=computer))', 'or' => "(objectClass=user)"]; |
| 140 |
// alias name |
| 141 |
$return["alias"] = _("Windows"); |
| 142 |
// module dependencies |
| 143 |
$return['dependencies'] = ['depends' => [], 'conflicts' => []]; |
| 144 |
// managed object classes |
| 145 |
$return['objectClasses'] = ['user', 'securityPrincipal']; |
| 146 |
// managed attributes |
| 147 |
$return['attributes'] = ['userPrincipalName', 'cn', 'sAMAccountName', 'description', 'displayName', 'givenName', 'initials', |
| 148 |
'l', 'mail', 'otherTelephone', 'physicalDeliveryOfficeName', 'postalCode', 'postOfficeBox', 'sn', 'st', |
| 149 |
'streetAddress', 'telephoneNumber', 'url', 'wWWHomePage', 'useraccountcontrol', 'profilePath', 'scriptPath', |
| 150 |
'pwdLastSet', 'otherMailbox', 'homeDirectory', 'homeDrive', 'msSFU30Name', 'msSFU30NisDomain', 'pwdLastSet', |
| 151 |
'lastLogonTimestamp', 'accountexpires', 'jpegPhoto', 'title', 'carLicense', 'employeeNumber', 'employeeType', |
| 152 |
'businessCategory', 'department', 'departmentNumber', 'ou', 'o', 'manager', 'facsimileTelephoneNumber', 'company', |
| 153 |
'pager', 'otherPager', 'mobile', 'otherMobile', 'proxyAddresses', 'lockouttime', 'userWorkstations', 'roomnumber', |
| 154 |
'personaltitle', 'thumbnailphoto', 'logonhours' |
| 155 |
]; |
| 156 |
$return['hiddenAttributes'] = ['msds-userpasswordexpirytimecomputed']; |
| 157 |
// help Entries |
| 158 |
$return['help'] = [ |
| 159 |
'cn' => [ |
| 160 |
"Headline" => _('Common name'), 'attr' => 'cn', |
| 161 |
"Text" => _('This is the natural name of the user. If empty, the first and last name or user name is used.') |
| 162 |
], |
| 163 |
'userPrincipalName' => [ |
| 164 |
"Headline" => _('User name'), 'attr' => 'userPrincipalName', |
| 165 |
"Text" => _('Please enter the user\'s name.') |
| 166 |
], |
| 167 |
'userPrincipalNameDomain' => [ |
| 168 |
"Headline" => _('Domain'), 'attr' => 'userPrincipalName', |
| 169 |
"Text" => _('Windows domain name of account.') |
| 170 |
], |
| 171 |
'sAMAccountName' => [ |
| 172 |
"Headline" => _('User name (pre W2K)'), 'attr' => 'sAMAccountName', |
| 173 |
"Text" => _('Please enter the user\'s name.') . ' ' . _('This user name is only used for old Windows versions (e.g. NT4, W98).') |
| 174 |
], |
| 175 |
'description' => [ |
| 176 |
"Headline" => _('Description'), 'attr' => 'description', |
| 177 |
"Text" => _('Please enter a descriptive text for this user.') |
| 178 |
], |
| 179 |
'displayName' => [ |
| 180 |
"Headline" => _('Display name'), 'attr' => 'displayName', |
| 181 |
"Text" => _('This is the account\'s full name on Windows systems.') |
| 182 |
], |
| 183 |
'givenName' => [ |
| 184 |
"Headline" => _('First name'), 'attr' => 'givenName', |
| 185 |
"Text" => _('First name of user. Only letters, - and spaces are allowed.') |
| 186 |
], |
| 187 |
'initials' => [ |
| 188 |
"Headline" => _('Initials'), 'attr' => 'initials', |
| 189 |
"Text" => _('The initials of the user\'s first names.') |
| 190 |
], |
| 191 |
'l' => [ |
| 192 |
"Headline" => _('Location'), 'attr' => 'l', |
| 193 |
"Text" => _('This describes the location of the user.') |
| 194 |
], |
| 195 |
'mail' => [ |
| 196 |
"Headline" => _('Email address'), 'attr' => 'mail', |
| 197 |
"Text" => _('The user\'s email address.') |
| 198 |
], |
| 199 |
'otherTelephone' => [ |
| 200 |
"Headline" => _('Other telephone numbers'), 'attr' => 'otherTelephone', |
| 201 |
"Text" => _('If the user has multiple telephone numbers then please enter it here.') |
| 202 |
], |
| 203 |
'otherTelephoneList' => [ |
| 204 |
"Headline" => _('Other telephone numbers'), 'attr' => 'otherTelephone', |
| 205 |
"Text" => _('If the user has multiple telephone numbers then please enter it here.') . ' ' . _("Multiple values are separated by semicolon.") |
| 206 |
], |
| 207 |
'physicalDeliveryOfficeName' => [ |
| 208 |
"Headline" => _('Office name'), 'attr' => 'physicalDeliveryOfficeName', |
| 209 |
"Text" => _('The office name of the user (e.g. YourCompany, Human Resources).') |
| 210 |
], |
| 211 |
'roomnumber' => [ |
| 212 |
"Headline" => _('Room number'), 'attr' => 'roomnumber', |
| 213 |
"Text" => _('The room number(s) of the user.') |
| 214 |
], |
| 215 |
'roomnumberList' => [ |
| 216 |
"Headline" => _('Room number'), 'attr' => 'roomnumber', |
| 217 |
"Text" => _('The room number(s) of the user.') . ' ' . _("Multiple values are separated by semicolon.") |
| 218 |
], |
| 219 |
'postalCode' => [ |
| 220 |
"Headline" => _('Postal code'), 'attr' => 'postalCode', |
| 221 |
"Text" => _('The postal code of the user\'s address.') |
| 222 |
], |
| 223 |
'postOfficeBox' => [ |
| 224 |
"Headline" => _('Post office box'), 'attr' => 'postOfficeBox', |
| 225 |
"Text" => _('The post office box of the user\'s address.') |
| 226 |
], |
| 227 |
'sn' => [ |
| 228 |
"Headline" => _('Last name'), 'attr' => 'sn', |
| 229 |
"Text" => _('Last name of user. Only letters, - and spaces are allowed.') |
| 230 |
], |
| 231 |
'st' => [ |
| 232 |
"Headline" => _('State'), 'attr' => 'st', |
| 233 |
"Text" => _('The state where the user resides or works.') |
| 234 |
], |
| 235 |
'streetAddress' => [ |
| 236 |
"Headline" => _('Street'), 'attr' => 'streetAddress', |
| 237 |
"Text" => _('The street name of the user\'s address.') |
| 238 |
], |
| 239 |
'telephoneNumber' => [ |
| 240 |
"Headline" => _('Telephone number'), 'attr' => 'telephoneNumber', |
| 241 |
"Text" => _('The user\'s telephone number.') |
| 242 |
], |
| 243 |
'facsimileTelephoneNumber' => [ |
| 244 |
"Headline" => _("Fax number"), 'attr' => 'facsimileTelephoneNumber', |
| 245 |
"Text" => _("The user's fax number.") |
| 246 |
], |
| 247 |
'url' => [ |
| 248 |
"Headline" => _('Other web sites'), 'attr' => 'url', |
| 249 |
"Text" => _('Here you can enter additional web sites for the user.') |
| 250 |
], |
| 251 |
'urlList' => [ |
| 252 |
"Headline" => _('Other web sites'), 'attr' => 'url', |
| 253 |
"Text" => _('Here you can enter additional web sites for the user.') . ' ' . _("Multiple values are separated by semicolon.") |
| 254 |
], |
| 255 |
'wWWHomePage' => [ |
| 256 |
"Headline" => _('Web site'), 'attr' => 'wWWHomePage', |
| 257 |
"Text" => _('The user\'s web site (e.g. https://www.company.com).') |
| 258 |
], |
| 259 |
"deactivated" => [ |
| 260 |
"Headline" => _("Account is deactivated"), |
| 261 |
"Text" => _("If checked then the account will be deactivated.")], |
| 262 |
"noExpire" => [ |
| 263 |
"Headline" => _("Password does not expire"), |
| 264 |
"Text" => _("If checked password does not expire.")], |
| 265 |
"requireCard" => [ |
| 266 |
"Headline" => _("Require smartcard"), |
| 267 |
"Text" => _("The user must log on using a smart card.")], |
| 268 |
"profilePath" => [ |
| 269 |
"Headline" => _("Profile path"), 'attr' => 'profilePath', |
| 270 |
"Text" => _('Path of the user profile (UNC-path, e.g. \\\\server\\share\\user).') . ' ' . _("Can be left empty.") |
| 271 |
], |
| 272 |
"scriptPath" => [ |
| 273 |
"Headline" => _("Logon script"), 'attr' => 'scriptPath', |
| 274 |
"Text" => _('File name and path relative to netlogon-share which should be executed on logon.') . ' ' . _("Can be left empty.") |
| 275 |
], |
| 276 |
"pwdMustChange" => [ |
| 277 |
"Headline" => _("Password change at next login"), |
| 278 |
"Text" => _("If you set this option then the user has to change his password at the next login.")], |
| 279 |
"groups" => [ |
| 280 |
"Headline" => _("Groups"), |
| 281 |
"Text" => _("Hold the CTRL-key to (de)select multiple groups.")], |
| 282 |
"groupsUpload" => [ |
| 283 |
"Headline" => _("Groups"), |
| 284 |
"Text" => _("The groups for this account. You can insert a group name or DN.") . ' ' . _("Multiple values are separated by semicolon.")], |
| 285 |
'password' => [ |
| 286 |
"Headline" => _("Password"), |
| 287 |
"Text" => _("Please enter the password which you want to set for this account.") |
| 288 |
], |
| 289 |
'otherMailbox' => [ |
| 290 |
"Headline" => _("Email alias"), 'attr' => 'otherMailbox', |
| 291 |
"Text" => _("Email alias for this account.") |
| 292 |
], |
| 293 |
'otherMailboxList' => [ |
| 294 |
"Headline" => _("Email alias"), 'attr' => 'otherMailbox', |
| 295 |
"Text" => _("Email alias for this account.") . ' ' . _("Multiple values are separated by semicolon.") |
| 296 |
], |
| 297 |
'hiddenOptions' => [ |
| 298 |
"Headline" => _("Hidden options"), |
| 299 |
"Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.") |
| 300 |
], |
| 301 |
'domains' => [ |
| 302 |
"Headline" => _('Domains'), |
| 303 |
"Text" => _('Please enter a list of Windows domains that can be selected for your user accounts.') |
| 304 |
], |
| 305 |
"homeDrive" => [ |
| 306 |
"Headline" => _("Home drive"), 'attr' => 'homeDrive', |
| 307 |
"Text" => _("The home directory will be connected under this drive letter.")], |
| 308 |
"homeDirectory" => [ |
| 309 |
"Headline" => _("Home directory"), 'attr' => 'homeDirectory', |
| 310 |
"Text" => _('UNC-path (\\\\server\\share\) of home directory. If no home drive is set then this directory must start with a drive letter (e.g. "c:\dir\user").') |
| 311 |
], |
| 312 |
'msSFU30Name' => [ |
| 313 |
"Headline" => _('NIS name'), 'attr' => 'msSFU30Name', |
| 314 |
"Text" => _('User name for NIS.') |
| 315 |
], |
| 316 |
'msSFU30NisDomain' => [ |
| 317 |
"Headline" => _('NIS domain'), 'attr' => 'msSFU30NisDomain', |
| 318 |
"Text" => _('NIS domain name.') |
| 319 |
], |
| 320 |
'pwdLastSet' => [ |
| 321 |
"Headline" => _('Last password change'), 'attr' => 'pwdLastSet', |
| 322 |
"Text" => _('Time of user\'s last password change.') |
| 323 |
], |
| 324 |
'lastLogonTimestamp' => [ |
| 325 |
"Headline" => _('Last login'), 'attr' => 'lastLogonTimestamp', |
| 326 |
"Text" => _('Time of user\'s last login.') |
| 327 |
], |
| 328 |
"logonhours" => [ |
| 329 |
"Headline" => _("Logon hours"), 'attr' => 'logonHours', |
| 330 |
"Text" => _("This option defines the allowed logon hours for this account.") |
| 331 |
], |
| 332 |
'accountexpires' => [ |
| 333 |
"Headline" => _('Account expiration date'), 'attr' => 'accountExpires', |
| 334 |
"Text" => _('This is the date when the account will expire.') |
| 335 |
], |
| 336 |
'accountexpiresUpload' => [ |
| 337 |
"Headline" => _('Account expiration date'), 'attr' => 'accountExpires', |
| 338 |
"Text" => _('This is the date when the account will expire. Format: DD-MM-YYYY') |
| 339 |
], |
| 340 |
'accountexpiresProfile' => [ |
| 341 |
"Headline" => _('Account expiration'), 'attr' => 'accountExpires', |
| 342 |
"Text" => _('Number of days after which the account will expire.') |
| 343 |
], |
| 344 |
'jpegPhoto' => [ |
| 345 |
"Headline" => _("Add photo"), 'attr' => 'jpegPhoto', |
| 346 |
"Text" => _("Please select an image file to upload. It must be in JPG format (.jpg/.jpeg).") |
| 347 |
], |
| 348 |
'thumbnailphoto' => [ |
| 349 |
"Headline" => _("Add thumbnail"), 'attr' => 'thumbnailPhoto', |
| 350 |
"Text" => _("Please select an image file to upload. It must be in JPG format (.jpg/.jpeg).") |
| 351 |
], |
| 352 |
'title' => [ |
| 353 |
"Headline" => _("Job title"), 'attr' => 'title', |
| 354 |
"Text" => _("Job title of user: President, department manager, ...") |
| 355 |
], |
| 356 |
'personaltitle' => [ |
| 357 |
"Headline" => _("Personal title"), 'attr' => 'personaltitle', |
| 358 |
"Text" => _("Can be used to specify gender (Mr, Mrs, ...) or academic title (e.g. Prof., PhD., ...).") |
| 359 |
], |
| 360 |
'carLicense' => [ |
| 361 |
"Headline" => _("Car license"), 'attr' => 'carLicense', |
| 362 |
"Text" => _("This can be used to specify if the user has a car license.") |
| 363 |
], |
| 364 |
'employeeNumber' => [ |
| 365 |
"Headline" => _("Employee number"), 'attr' => 'employeeNumber', |
| 366 |
"Text" => _("The user's unique employee number.") |
| 367 |
], |
| 368 |
'employeeType' => [ |
| 369 |
"Headline" => _("Employee type"), 'attr' => 'employeeType', |
| 370 |
"Text" => _("Employee type: Contractor, Employee, Intern, Temp, External, ...") |
| 371 |
], |
| 372 |
'businessCategory' => [ |
| 373 |
"Headline" => _("Business category"), 'attr' => 'businessCategory', |
| 374 |
"Text" => _("Business category (e.g. Administration, IT-Services, Management, ...)") |
| 375 |
], |
| 376 |
'businessCategoryList' => [ |
| 377 |
"Headline" => _("Business category"), 'attr' => 'businessCategory', |
| 378 |
"Text" => _("Business category (e.g. Administration, IT-Services, Management, ...)") . '. ' . _("Multiple values are separated by semicolon.") |
| 379 |
], |
| 380 |
'department' => [ |
| 381 |
"Headline" => _("Department"), 'attr' => 'department', |
| 382 |
"Text" => _("Here you can enter the user's department.") |
| 383 |
], |
| 384 |
'departmentNumber' => [ |
| 385 |
"Headline" => _("Department number"), 'attr' => 'departmentNumber', |
| 386 |
"Text" => _("Here you can enter the user's department number.") |
| 387 |
], |
| 388 |
'departmentNumberList' => [ |
| 389 |
"Headline" => _("Department number"), 'attr' => 'departmentNumber', |
| 390 |
"Text" => _("Here you can enter the user's department number.") . ' ' . _("Multiple values are separated by semicolon.") |
| 391 |
], |
| 392 |
'ou' => [ |
| 393 |
"Headline" => _("Organisational unit"), 'attr' => 'ou', |
| 394 |
"Text" => _("The user's organisational unit.") |
| 395 |
], |
| 396 |
'ouList' => [ |
| 397 |
"Headline" => _("Organisational unit"), 'attr' => 'ou', |
| 398 |
"Text" => _("The user's organisational unit.") . ' ' . _('Multiple values are separated by semicolon.') |
| 399 |
], |
| 400 |
'o' => [ |
| 401 |
"Headline" => _("Organisation"), 'attr' => 'o', |
| 402 |
"Text" => _("The user's organisation name.") |
| 403 |
], |
| 404 |
'oList' => [ |
| 405 |
"Headline" => _("Organisation"), 'attr' => 'o', |
| 406 |
"Text" => _("The user's organisation name.") . ' ' . _('Multiple values are separated by semicolon.') |
| 407 |
], |
| 408 |
'manager' => [ |
| 409 |
"Headline" => _("Manager"), 'attr' => 'manager', |
| 410 |
"Text" => _("This is the LDAP DN of the user's manager. Use this property to represent hierarchies in your company.") |
| 411 |
], |
| 412 |
'company' => [ |
| 413 |
"Headline" => _('Company'), 'attr' => 'company', |
| 414 |
"Text" => _('Please enter the company name.') |
| 415 |
], |
| 416 |
'pager' => [ |
| 417 |
"Headline" => _('Pager'), 'attr' => 'pager', |
| 418 |
"Text" => _('The user\'s pager number.') |
| 419 |
], |
| 420 |
'otherPager' => [ |
| 421 |
"Headline" => _('Other pagers'), 'attr' => 'otherPager', |
| 422 |
"Text" => _('Any secondary pager numbers.') |
| 423 |
], |
| 424 |
'otherPagerUpload' => [ |
| 425 |
"Headline" => _('Other pagers'), 'attr' => 'otherPager', |
| 426 |
"Text" => _('Any secondary pager numbers.') . ' ' . _('Multiple values are separated by semicolon.') |
| 427 |
], |
| 428 |
'mobile' => [ |
| 429 |
"Headline" => _('Mobile'), 'attr' => 'mobile', |
| 430 |
"Text" => _('The user\'s mobile number.') |
| 431 |
], |
| 432 |
'otherMobile' => [ |
| 433 |
"Headline" => _('Other mobiles'), 'attr' => 'otherMobile', |
| 434 |
"Text" => _('Any secondary mobile numbers.') |
| 435 |
], |
| 436 |
'otherMobileUpload' => [ |
| 437 |
"Headline" => _('Other mobiles'), 'attr' => 'otherMobile', |
| 438 |
"Text" => _('Any secondary mobile numbers.') . ' ' . _('Multiple values are separated by semicolon.') |
| 439 |
], |
| 440 |
'proxyAddresses' => [ |
| 441 |
"Headline" => _('Proxy-Addresses'), 'attr' => 'proxyAddresses', |
| 442 |
"Text" => _('Use this to enter additional email addresses in format "smtp:[email protected]".') |
| 443 |
], |
| 444 |
'proxyAddressesUpload' => [ |
| 445 |
"Headline" => _('Proxy-Addresses'), 'attr' => 'proxyAddresses', |
| 446 |
"Text" => _('Use this to enter additional email addresses in format "smtp:[email protected]".') . ' ' . _('Multiple values are separated by semicolon.') |
| 447 |
], |
| 448 |
'crop' => [ |
| 449 |
"Headline" => _('Image cropping'), |
| 450 |
"Text" => _('Uploaded images will be cropped to these maximum values.') |
| 451 |
], |
| 452 |
'photoUpload' => [ |
| 453 |
"Headline" => _("Add photo"), 'attr' => 'jpegPhoto', |
| 454 |
"Text" => _("Please select an image file to upload. It must be in JPG format (.jpg/.jpeg).") |
| 455 |
], |
| 456 |
'thumbnailphotoUpload' => [ |
| 457 |
"Headline" => _("Add thumbnail"), 'attr' => 'thumbnailPhoto', |
| 458 |
"Text" => _("Please select an image file to upload. It must be in JPG format (.jpg/.jpeg).") |
| 459 |
], |
| 460 |
'excludeFromGroupSync' => [ |
| 461 |
"Headline" => _('Exclude from group sync'), |
| 462 |
"Text" => _('Enter one group per line that should be ignored when syncing groups.') |
| 463 |
], |
| 464 |
"userWorkstations" => [ |
| 465 |
"Headline" => _("Workstations"), 'attr' => 'userWorkstations', |
| 466 |
"Text" => _("List of workstations the user is allowed to login. Empty means every workstation.") |
| 467 |
], |
| 468 |
"workstations" => [ |
| 469 |
"Headline" => _("Workstations"), 'attr' => 'userWorkstations', |
| 470 |
"Text" => _("Comma separated list of workstations the user is allowed to login. Empty means every workstation.") . ' ' . _("Can be left empty.") |
| 471 |
], |
| 472 |
'displayGroups' => [ |
| 473 |
"Headline" => _('Display format'), |
| 474 |
"Text" => _('Specifies how groups are displayed.') |
| 475 |
], |
| 476 |
'filter' => [ |
| 477 |
"Headline" => _("Filter"), |
| 478 |
"Text" => _("Here you can enter a filter value. Only entries which contain the filter text will be shown.") |
| 479 |
. ' ' . _('Possible wildcards are: "*" = any character, "^" = line start, "$" = line end') |
| 480 |
], |
| 481 |
]; |
| 482 |
// upload fields |
| 483 |
$return['upload_columns'] = [ |
| 484 |
[ |
| 485 |
'name' => 'windowsUser_userPrincipalName', |
| 486 |
'description' => _('User name'), |
| 487 |
'help' => 'userPrincipalName', |
| 488 |
'example' => _('smiller'), |
| 489 |
'required' => true, |
| 490 |
'unique' => true, |
| 491 |
], |
| 492 |
[ |
| 493 |
'name' => 'windowsUser_password', |
| 494 |
'description' => _('Password'), |
| 495 |
'help' => 'password', |
| 496 |
'example' => _('secret'), |
| 497 |
], |
| 498 |
[ |
| 499 |
'name' => 'windowsUser_firstName', |
| 500 |
'description' => _('First name'), |
| 501 |
'help' => 'givenName', |
| 502 |
'example' => _('Steve'), |
| 503 |
], |
| 504 |
[ |
| 505 |
'name' => 'windowsUser_lastName', |
| 506 |
'description' => _('Last name'), |
| 507 |
'help' => 'sn', |
| 508 |
'example' => _('Miller'), |
| 509 |
], |
| 510 |
[ |
| 511 |
'name' => 'windowsUser_cn', |
| 512 |
'description' => _('Common name'), |
| 513 |
'help' => 'cn', |
| 514 |
'example' => _('Steve Miller'), |
| 515 |
], |
| 516 |
[ |
| 517 |
'name' => 'windowsUser_deactivated', |
| 518 |
'description' => _('Account is deactivated'), |
| 519 |
'help' => 'deactivated', |
| 520 |
'example' => _('no'), |
| 521 |
'default' => _('no'), |
| 522 |
'values' => _('yes') . ', ' . _('no') |
| 523 |
], |
| 524 |
[ |
| 525 |
'name' => 'windowsUser_noExpire', |
| 526 |
'description' => _('Password does not expire'), |
| 527 |
'help' => 'noExpire', |
| 528 |
'example' => _('no'), |
| 529 |
'default' => _('no'), |
| 530 |
'values' => _('yes') . ', ' . _('no') |
| 531 |
], |
| 532 |
[ |
| 533 |
'name' => 'windowsUser_accountExpires', |
| 534 |
'description' => _('Account expiration date'), |
| 535 |
'help' => 'accountexpiresUpload', |
| 536 |
'example' => '21-11-2030', |
| 537 |
], |
| 538 |
[ |
| 539 |
'name' => 'windowsUser_pwdMustChange', |
| 540 |
'description' => _('Password change at next login'), |
| 541 |
'help' => 'pwdMustChange', |
| 542 |
'example' => _('no'), |
| 543 |
'default' => _('no'), |
| 544 |
'values' => _('yes') . ', ' . _('no') |
| 545 |
], |
| 546 |
[ |
| 547 |
'name' => 'windowsUser_groups', |
| 548 |
'description' => _('Groups'), |
| 549 |
'help' => 'groupsUpload', |
| 550 |
], |
| 551 |
]; |
| 552 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 553 |
$return['upload_columns'][] = [ |
| 554 |
'name' => 'windowsUser_displayName', |
| 555 |
'description' => _('Display name'), |
| 556 |
'help' => 'displayName', |
| 557 |
'example' => _('Steve Miller'), |
| 558 |
]; |
| 559 |
} |
| 560 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideinitials')) { |
| 561 |
$return['upload_columns'][] = [ |
| 562 |
'name' => 'windowsUser_initials', |
| 563 |
'description' => _('Initials'), |
| 564 |
'help' => 'initials', |
| 565 |
'example' => _('S.M.'), |
| 566 |
]; |
| 567 |
} |
| 568 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedescription')) { |
| 569 |
$return['upload_columns'][] = [ |
| 570 |
'name' => 'windowsUser_description', |
| 571 |
'description' => _('Description'), |
| 572 |
'help' => 'description', |
| 573 |
'example' => _('Temp, contract till December'), |
| 574 |
]; |
| 575 |
} |
| 576 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidestreetAddress')) { |
| 577 |
$return['upload_columns'][] = [ |
| 578 |
'name' => 'windowsUser_streetAddress', |
| 579 |
'description' => _('Street'), |
| 580 |
'help' => 'streetAddress', |
| 581 |
'example' => _('Mystreetname 42'), |
| 582 |
]; |
| 583 |
} |
| 584 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox')) { |
| 585 |
$return['upload_columns'][] = [ |
| 586 |
'name' => 'windowsUser_postOfficeBox', |
| 587 |
'description' => _('Post office box'), |
| 588 |
'help' => 'postOfficeBox', |
| 589 |
'example' => _('12345'), |
| 590 |
]; |
| 591 |
} |
| 592 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode')) { |
| 593 |
$return['upload_columns'][] = [ |
| 594 |
'name' => 'windowsUser_postalCode', |
| 595 |
'description' => _('Postal code'), |
| 596 |
'help' => 'postalCode', |
| 597 |
'example' => _('GB-12345'), |
| 598 |
]; |
| 599 |
} |
| 600 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidel')) { |
| 601 |
$return['upload_columns'][] = [ |
| 602 |
'name' => 'windowsUser_l', |
| 603 |
'description' => _('Location'), |
| 604 |
'help' => 'l', |
| 605 |
'example' => _('MyCity'), |
| 606 |
]; |
| 607 |
} |
| 608 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidest')) { |
| 609 |
$return['upload_columns'][] = [ |
| 610 |
'name' => 'windowsUser_state', |
| 611 |
'description' => _('State'), |
| 612 |
'help' => 'st', |
| 613 |
'example' => _('New York'), |
| 614 |
]; |
| 615 |
} |
| 616 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName')) { |
| 617 |
$return['upload_columns'][] = [ |
| 618 |
'name' => 'windowsUser_officeName', |
| 619 |
'description' => _('Office name'), |
| 620 |
'help' => 'physicalDeliveryOfficeName', |
| 621 |
'example' => _('YourCompany'), |
| 622 |
]; |
| 623 |
} |
| 624 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true)) { |
| 625 |
$return['upload_columns'][] = [ |
| 626 |
'name' => 'windowsUser_roomNumber', |
| 627 |
'description' => _('Room number'), |
| 628 |
'help' => 'roomnumber', |
| 629 |
'example' => 'A.123; B.456', |
| 630 |
]; |
| 631 |
} |
| 632 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemail')) { |
| 633 |
$return['upload_columns'][] = [ |
| 634 |
'name' => 'windowsUser_mail', |
| 635 |
'description' => _('Email address'), |
| 636 |
'help' => 'mail', |
| 637 |
'example' => _('[email protected]'), |
| 638 |
]; |
| 639 |
} |
| 640 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMailbox')) { |
| 641 |
$return['upload_columns'][] = [ |
| 642 |
'name' => 'windowsUser_otherMailbox', |
| 643 |
'description' => _('Email alias'), |
| 644 |
'help' => 'otherMailboxList', |
| 645 |
'example' => _('[email protected]'), |
| 646 |
]; |
| 647 |
} |
| 648 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetelephoneNumber')) { |
| 649 |
$return['upload_columns'][] = [ |
| 650 |
'name' => 'windowsUser_telephoneNumber', |
| 651 |
'description' => _('Telephone number'), |
| 652 |
'help' => 'telephoneNumber', |
| 653 |
'example' => _('123-124-1234'), |
| 654 |
]; |
| 655 |
} |
| 656 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherTelephone')) { |
| 657 |
$return['upload_columns'][] = [ |
| 658 |
'name' => 'windowsUser_otherTelephone', |
| 659 |
'description' => _('Other telephone numbers'), |
| 660 |
'help' => 'otherTelephoneList', |
| 661 |
'example' => _('123-124-1234'), |
| 662 |
]; |
| 663 |
} |
| 664 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidewWWHomePage')) { |
| 665 |
$return['upload_columns'][] = [ |
| 666 |
'name' => 'windowsUser_webSite', |
| 667 |
'description' => _('Web site'), |
| 668 |
'help' => 'wWWHomePage', |
| 669 |
'example' => _('https://www.company.com'), |
| 670 |
]; |
| 671 |
} |
| 672 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideurl')) { |
| 673 |
$return['upload_columns'][] = [ |
| 674 |
'name' => 'windowsUser_otherWebSites', |
| 675 |
'description' => _('Other web sites'), |
| 676 |
'help' => 'urlList', |
| 677 |
'example' => _('https://www.company.com'), |
| 678 |
]; |
| 679 |
} |
| 680 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideproxyAddresses', true)) { |
| 681 |
$return['upload_columns'][] = [ |
| 682 |
'name' => 'windowsUser_proxyAddresses', |
| 683 |
'description' => _('Proxy-Addresses'), |
| 684 |
'help' => 'proxyAddressesUpload', |
| 685 |
'example' => _('smtp:[email protected]') |
| 686 |
]; |
| 687 |
} |
| 688 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidefacsimileTelephoneNumber')) { |
| 689 |
$return['upload_columns'][] = [ |
| 690 |
'name' => 'windowsUser_facsimileTelephoneNumber', |
| 691 |
'description' => _('Fax number'), |
| 692 |
'help' => 'facsimileTelephoneNumber', |
| 693 |
'example' => _('123-123-1236') |
| 694 |
]; |
| 695 |
} |
| 696 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepager', true)) { |
| 697 |
$return['upload_columns'][] = [ |
| 698 |
'name' => 'windowsUser_pager', |
| 699 |
'description' => _('Pager'), |
| 700 |
'help' => 'pager', |
| 701 |
'example' => _('123-123-1236') |
| 702 |
]; |
| 703 |
} |
| 704 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherPager', true)) { |
| 705 |
$return['upload_columns'][] = [ |
| 706 |
'name' => 'windowsUser_otherPager', |
| 707 |
'description' => _('Other pagers'), |
| 708 |
'help' => 'otherPagerUpload', |
| 709 |
'example' => _('123-123-1236') |
| 710 |
]; |
| 711 |
} |
| 712 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemobile', true)) { |
| 713 |
$return['upload_columns'][] = [ |
| 714 |
'name' => 'windowsUser_mobile', |
| 715 |
'description' => _('Mobile'), |
| 716 |
'help' => 'mobile', |
| 717 |
'example' => _('123-123-1235') |
| 718 |
]; |
| 719 |
} |
| 720 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMobile', true)) { |
| 721 |
$return['upload_columns'][] = [ |
| 722 |
'name' => 'windowsUser_otherMobile', |
| 723 |
'description' => _('Other mobiles'), |
| 724 |
'help' => 'otherMobileUpload', |
| 725 |
'example' => _('123-123-1235') |
| 726 |
]; |
| 727 |
} |
| 728 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecompany', true)) { |
| 729 |
$return['upload_columns'][] = [ |
| 730 |
'name' => 'windowsUser_company', |
| 731 |
'description' => _('Company'), |
| 732 |
'help' => 'company', |
| 733 |
]; |
| 734 |
} |
| 735 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidesAMAccountName', true)) { |
| 736 |
$return['upload_columns'][] = [ |
| 737 |
'name' => 'windowsUser_sAMAccountName', |
| 738 |
'description' => _('User name (pre W2K)'), |
| 739 |
'help' => 'sAMAccountName', |
| 740 |
'example' => _('smiller'), |
| 741 |
'unique' => true, |
| 742 |
]; |
| 743 |
} |
| 744 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true)) { |
| 745 |
$return['upload_columns'][] = [ |
| 746 |
'name' => 'windowsUser_msSFU30Name', |
| 747 |
'description' => _('NIS name'), |
| 748 |
'help' => 'msSFU30Name', |
| 749 |
'example' => _('smiller'), |
| 750 |
]; |
| 751 |
} |
| 752 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 753 |
$return['upload_columns'][] = [ |
| 754 |
'name' => 'windowsUser_msSFU30NisDomain', |
| 755 |
'description' => _('NIS domain'), |
| 756 |
'help' => 'msSFU30NisDomain', |
| 757 |
'example' => _('domain'), |
| 758 |
]; |
| 759 |
} |
| 760 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 761 |
$return['upload_columns'][] = [ |
| 762 |
'name' => 'windowsUser_title', |
| 763 |
'description' => _('Job title'), |
| 764 |
'help' => 'title', |
| 765 |
'example' => _('President'), |
| 766 |
]; |
| 767 |
} |
| 768 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle', true)) { |
| 769 |
$return['upload_columns'][] = [ |
| 770 |
'name' => 'windowsUser_personalTitle', |
| 771 |
'description' => _('Personal title'), |
| 772 |
'help' => 'personaltitle', |
| 773 |
'example' => _('Prof.'), |
| 774 |
]; |
| 775 |
} |
| 776 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecarLicense', true)) { |
| 777 |
$return['upload_columns'][] = [ |
| 778 |
'name' => 'windowsUser_carLicense', |
| 779 |
'description' => _('Car license'), |
| 780 |
'help' => 'carLicense', |
| 781 |
'example' => _('yes'), |
| 782 |
]; |
| 783 |
} |
| 784 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeNumber', true)) { |
| 785 |
$return['upload_columns'][] = [ |
| 786 |
'name' => 'windowsUser_employeeNumber', |
| 787 |
'description' => _('Employee number'), |
| 788 |
'help' => 'employeeNumber', |
| 789 |
'example' => '123456', |
| 790 |
]; |
| 791 |
} |
| 792 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 793 |
$return['upload_columns'][] = [ |
| 794 |
'name' => 'windowsUser_employeeType', |
| 795 |
'description' => _('Employee type'), |
| 796 |
'help' => 'employeeType', |
| 797 |
'example' => _('Temp'), |
| 798 |
]; |
| 799 |
} |
| 800 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 801 |
$return['upload_columns'][] = [ |
| 802 |
'name' => 'windowsUser_businessCategory', |
| 803 |
'description' => _('Business category'), |
| 804 |
'help' => 'businessCategoryList', |
| 805 |
'example' => _('Administration'), |
| 806 |
]; |
| 807 |
} |
| 808 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 809 |
$return['upload_columns'][] = [ |
| 810 |
'name' => 'windowsUser_department', |
| 811 |
'description' => _('Department'), |
| 812 |
'help' => 'department', |
| 813 |
'example' => _('Administration'), |
| 814 |
]; |
| 815 |
} |
| 816 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 817 |
$return['upload_columns'][] = [ |
| 818 |
'name' => 'windowsUser_departmentNumber', |
| 819 |
'description' => _('Department number'), |
| 820 |
'help' => 'departmentNumberList', |
| 821 |
'example' => 'A123', |
| 822 |
]; |
| 823 |
} |
| 824 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 825 |
$return['upload_columns'][] = [ |
| 826 |
'name' => 'windowsUser_ou', |
| 827 |
'description' => _('Organisational unit'), |
| 828 |
'help' => 'ouList', |
| 829 |
'example' => _('Administration'), |
| 830 |
]; |
| 831 |
} |
| 832 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 833 |
$return['upload_columns'][] = [ |
| 834 |
'name' => 'windowsUser_o', |
| 835 |
'description' => _('Organisation'), |
| 836 |
'help' => 'oList', |
| 837 |
'example' => _('YourCompany'), |
| 838 |
]; |
| 839 |
} |
| 840 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemanager', true)) { |
| 841 |
$return['upload_columns'][] = [ |
| 842 |
'name' => 'windowsUser_manager', |
| 843 |
'description' => _('Manager'), |
| 844 |
'help' => 'manager', |
| 845 |
'example' => _('uid=smiller,ou=People,dc=company,dc=com'), |
| 846 |
]; |
| 847 |
} |
| 848 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideWorkstations')) { |
| 849 |
$return['upload_columns'][] = [ |
| 850 |
'name' => 'windowsUser_workstations', |
| 851 |
'description' => _('Workstations'), |
| 852 |
'help' => 'workstations', |
| 853 |
'example' => 'PC01,PC02,PC03' |
| 854 |
]; |
| 855 |
} |
| 856 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath')) { |
| 857 |
$return['upload_columns'][] = [ |
| 858 |
'name' => 'windowsUser_profilePath', |
| 859 |
'description' => _('Profile path'), |
| 860 |
'help' => 'profilePath', |
| 861 |
'example' => _('\\\\server\\profiles\\smiller'), |
| 862 |
]; |
| 863 |
} |
| 864 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath')) { |
| 865 |
$return['upload_columns'][] = [ |
| 866 |
'name' => 'windowsUser_scriptPath', |
| 867 |
'description' => _('Logon script'), |
| 868 |
'help' => 'scriptPath', |
| 869 |
'example' => 'logon.bat', |
| 870 |
]; |
| 871 |
} |
| 872 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive')) { |
| 873 |
$return['upload_columns'][] = [ |
| 874 |
'name' => 'windowsUser_homeDrive', |
| 875 |
'description' => _('Home drive'), |
| 876 |
'help' => 'homeDrive', |
| 877 |
'example' => 'K:' |
| 878 |
]; |
| 879 |
} |
| 880 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory')) { |
| 881 |
$return['upload_columns'][] = [ |
| 882 |
'name' => 'windowsUser_homeDirectory', |
| 883 |
'description' => _('Home directory'), |
| 884 |
'help' => 'homeDirectory', |
| 885 |
'example' => _('\\\\server\\homes\\smiller') |
| 886 |
]; |
| 887 |
} |
| 888 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideRequireSmartcard')) { |
| 889 |
$return['upload_columns'][] = [ |
| 890 |
'name' => 'windowsUser_requireCard', |
| 891 |
'description' => _('Require smartcard'), |
| 892 |
'help' => 'requireCard', |
| 893 |
'example' => _('no'), |
| 894 |
'default' => _('no'), |
| 895 |
'values' => _('yes') . ', ' . _('no') |
| 896 |
]; |
| 897 |
} |
| 898 |
// profile options |
| 899 |
$profileContainer = new htmlResponsiveRow(); |
| 900 |
$profileContainer->add(new htmlResponsiveInputField(_('Common name'), 'windowsUser_cn', null, 'cn')); |
| 901 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 902 |
$profileContainer->add(new htmlResponsiveInputField(_('Display name'), 'windowsUser_displayName', null, 'displayName')); |
| 903 |
} |
| 904 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidestreetAddress')) { |
| 905 |
$profileContainer->add(new htmlResponsiveInputField(_('Street'), 'windowsUser_streetAddress', null, 'streetAddress')); |
| 906 |
} |
| 907 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox')) { |
| 908 |
$profileContainer->add(new htmlResponsiveInputField(_('Post office box'), 'windowsUser_postOfficeBox', null, 'postOfficeBox')); |
| 909 |
} |
| 910 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode')) { |
| 911 |
$profileContainer->add(new htmlResponsiveInputField(_('Postal code'), 'windowsUser_postalCode', null, 'postalCode')); |
| 912 |
} |
| 913 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidel')) { |
| 914 |
$profileContainer->add(new htmlResponsiveInputField(_('Location'), 'windowsUser_l', null, 'l')); |
| 915 |
} |
| 916 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidest')) { |
| 917 |
$profileContainer->add(new htmlResponsiveInputField(_('State'), 'windowsUser_st', null, 'st')); |
| 918 |
} |
| 919 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName')) { |
| 920 |
$profileContainer->add(new htmlResponsiveInputField(_('Office name'), 'windowsUser_physicalDeliveryOfficeName', null, 'physicalDeliveryOfficeName')); |
| 921 |
} |
| 922 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true)) { |
| 923 |
$profileContainer->add(new htmlResponsiveInputField(_('Room number'), 'windowsUser_roomnumber', null, 'roomnumber')); |
| 924 |
} |
| 925 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemail')) { |
| 926 |
$profileContainer->add(new htmlResponsiveInputField(_('Email address'), 'windowsUser_mail', null, 'mail')); |
| 927 |
} |
| 928 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMailbox')) { |
| 929 |
$profileContainer->add(new htmlResponsiveInputField(_('Email alias'), 'windowsUser_otherMailbox', null, 'otherMailboxList')); |
| 930 |
} |
| 931 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath')) { |
| 932 |
$profileContainer->add(new htmlResponsiveInputField(_('Logon script'), 'windowsUser_scriptPath', null, 'scriptPath')); |
| 933 |
} |
| 934 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath')) { |
| 935 |
$profileContainer->add(new htmlResponsiveInputField(_('Profile path'), 'windowsUser_profilePath', null, 'profilePath')); |
| 936 |
} |
| 937 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory')) { |
| 938 |
$profileContainer->add(new htmlResponsiveInputField(_('Home directory'), 'windowsUser_homeDirectory', null, 'homeDirectory')); |
| 939 |
} |
| 940 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 941 |
$profileContainer->add(new htmlResponsiveInputField(_('NIS domain'), 'windowsUser_msSFU30NisDomain', null, 'msSFU30NisDomain')); |
| 942 |
} |
| 943 |
$profileContainer->add(new htmlResponsiveInputField(_('Account expiration'), 'windowsUser_accountExpires', null, 'accountexpiresProfile')); |
| 944 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecompany', true)) { |
| 945 |
$profileContainer->add(new htmlResponsiveInputField(_('Company'), 'windowsUser_company', null, 'company')); |
| 946 |
} |
| 947 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 948 |
$profileContainer->add(new htmlResponsiveInputField(_('Department'), 'windowsUser_department', null, 'department')); |
| 949 |
} |
| 950 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 951 |
$profileContainer->add(new htmlResponsiveInputField(_('Department number'), 'windowsUser_departmentNumber', null, 'departmentNumberList')); |
| 952 |
} |
| 953 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 954 |
$profileContainer->add(new htmlResponsiveInputField(_('Organisational unit'), 'windowsUser_ou', null, 'ouList')); |
| 955 |
} |
| 956 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 957 |
$profileContainer->add(new htmlResponsiveInputField(_('Organisation'), 'windowsUser_o', null, 'oList')); |
| 958 |
} |
| 959 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 960 |
$profileContainer->add(new htmlResponsiveInputField(_('Job title'), 'windowsUser_title', null, 'title')); |
| 961 |
} |
| 962 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle', true)) { |
| 963 |
$profileContainer->add(new htmlResponsiveInputField(_('Personal title'), 'windowsUser_personaltitle', null, 'personaltitle')); |
| 964 |
} |
| 965 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 966 |
$profileContainer->add(new htmlResponsiveInputField(_('Employee type'), 'windowsUser_employeeType', null, 'employeeType')); |
| 967 |
} |
| 968 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 969 |
$profileContainer->add(new htmlResponsiveInputField(_('Business category'), 'windowsUser_businessCategory', null, 'businessCategory')); |
| 970 |
} |
| 971 |
$return['profile_options'] = $profileContainer; |
| 972 |
// profile mappings |
| 973 |
$return['profile_mappings'] = [ |
| 974 |
'windowsUser_cn' => 'cn', |
| 975 |
'windowsUser_streetAddress' => 'streetAddress', |
| 976 |
'windowsUser_company' => 'company', |
| 977 |
]; |
| 978 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 979 |
$return['profile_mappings']['windowsUser_displayName'] = 'displayName'; |
| 980 |
} |
| 981 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideWorkstations')) { |
| 982 |
$return['profile_mappings']['windowsUser_userWorkstations'] = 'userWorkstations'; |
| 983 |
} |
| 984 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 985 |
$return['profile_mappings']['windowsUser_msSFU30NisDomain'] = 'msSFU30NisDomain'; |
| 986 |
} |
| 987 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox')) { |
| 988 |
$return['profile_mappings']['windowsUser_postOfficeBox'] = 'postOfficeBox'; |
| 989 |
} |
| 990 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode')) { |
| 991 |
$return['profile_mappings']['windowsUser_postalCode'] = 'postalCode'; |
| 992 |
} |
| 993 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidel')) { |
| 994 |
$return['profile_mappings']['windowsUser_l'] = 'l'; |
| 995 |
} |
| 996 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidest')) { |
| 997 |
$return['profile_mappings']['windowsUser_st'] = 'st'; |
| 998 |
} |
| 999 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName')) { |
| 1000 |
$return['profile_mappings']['windowsUser_physicalDeliveryOfficeName'] = 'physicalDeliveryOfficeName'; |
| 1001 |
} |
| 1002 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemail')) { |
| 1003 |
$return['profile_mappings']['windowsUser_mail'] = 'mail'; |
| 1004 |
} |
| 1005 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath')) { |
| 1006 |
$return['profile_mappings']['windowsUser_scriptPath'] = 'scriptPath'; |
| 1007 |
} |
| 1008 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath')) { |
| 1009 |
$return['profile_mappings']['windowsUser_profilePath'] = 'profilePath'; |
| 1010 |
} |
| 1011 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory')) { |
| 1012 |
$return['profile_mappings']['windowsUser_homeDirectory'] = 'homeDirectory'; |
| 1013 |
} |
| 1014 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive')) { |
| 1015 |
$return['profile_mappings']['windowsUser_homeDrive'] = 'homeDrive'; |
| 1016 |
} |
| 1017 |
// profile checks |
| 1018 |
$return['profile_checks']['windowsUser_accountExpires'] = [ |
| 1019 |
'type' => 'ext_preg', |
| 1020 |
'regex' => 'digit', |
| 1021 |
'error_message' => $this->messages['accountexpires'][0]]; |
| 1022 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 1023 |
$return['profile_checks']['windowsUser_title'] = [ |
| 1024 |
'type' => 'ext_preg', |
| 1025 |
'regex' => 'title', |
| 1026 |
'error_message' => $this->messages['title'][0]]; |
| 1027 |
$return['profile_mappings']['windowsUser_title'] = 'title'; |
| 1028 |
} |
| 1029 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle', true)) { |
| 1030 |
$return['profile_checks']['windowsUser_personaltitle'] = [ |
| 1031 |
'type' => 'ext_preg', |
| 1032 |
'regex' => 'title', |
| 1033 |
'error_message' => $this->messages['personaltitle'][0]]; |
| 1034 |
$return['profile_mappings']['windowsUser_personaltitle'] = 'personaltitle'; |
| 1035 |
} |
| 1036 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 1037 |
$return['profile_checks']['windowsUser_employeeType'] = [ |
| 1038 |
'type' => 'ext_preg', |
| 1039 |
'regex' => 'employeeType', |
| 1040 |
'error_message' => $this->messages['employeeType'][0]]; |
| 1041 |
$return['profile_mappings']['windowsUser_employeeType'] = 'employeeType'; |
| 1042 |
} |
| 1043 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 1044 |
$return['profile_checks']['windowsUser_businessCategory'] = [ |
| 1045 |
'type' => 'ext_preg', |
| 1046 |
'regex' => 'businessCategory', |
| 1047 |
'error_message' => $this->messages['businessCategory'][0]]; |
| 1048 |
$return['profile_mappings']['windowsUser_businessCategory'] = 'businessCategory'; |
| 1049 |
} |
| 1050 |
// available PDF fields |
| 1051 |
$return['PDF_fields'] = [ |
| 1052 |
'userPrincipalName' => _('User name'), |
| 1053 |
'cn' => _('Common name'), |
| 1054 |
'givenName' => _('First name'), |
| 1055 |
'sn' => _('Last name'), |
| 1056 |
'deactivated' => _('Account is deactivated'), |
| 1057 |
'noExpire' => _('Password does not expire'), |
| 1058 |
'pwdMustChange' => _('Password change at next login'), |
| 1059 |
'groups' => _('Groups'), |
| 1060 |
'password' => _('Password'), |
| 1061 |
'accountExpires' => _('Account expiration date'), |
| 1062 |
]; |
| 1063 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 1064 |
$return['PDF_fields']['displayName'] = _('Display name'); |
| 1065 |
} |
| 1066 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideRequireSmartcard')) { |
| 1067 |
$return['PDF_fields']['requireCard'] = _('Require smartcard'); |
| 1068 |
} |
| 1069 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath')) { |
| 1070 |
$return['PDF_fields']['profilePath'] = _('Profile path'); |
| 1071 |
} |
| 1072 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath')) { |
| 1073 |
$return['PDF_fields']['scriptPath'] = _('Logon script'); |
| 1074 |
} |
| 1075 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive')) { |
| 1076 |
$return['PDF_fields']['homeDrive'] = _('Home drive'); |
| 1077 |
} |
| 1078 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory')) { |
| 1079 |
$return['PDF_fields']['homeDirectory'] = _('Home directory'); |
| 1080 |
} |
| 1081 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedescription')) { |
| 1082 |
$return['PDF_fields']['description'] = _('Description'); |
| 1083 |
} |
| 1084 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideinitials')) { |
| 1085 |
$return['PDF_fields']['initials'] = _('Initials'); |
| 1086 |
} |
| 1087 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidel')) { |
| 1088 |
$return['PDF_fields']['l'] = _('Location'); |
| 1089 |
} |
| 1090 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemail')) { |
| 1091 |
$return['PDF_fields']['mail'] = _('Email address'); |
| 1092 |
} |
| 1093 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMailbox')) { |
| 1094 |
$return['PDF_fields']['otherMailbox'] = _('Email alias'); |
| 1095 |
} |
| 1096 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherTelephone')) { |
| 1097 |
$return['PDF_fields']['otherTelephone'] = _('Other telephone numbers'); |
| 1098 |
} |
| 1099 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName')) { |
| 1100 |
$return['PDF_fields']['physicalDeliveryOfficeName'] = _('Office name'); |
| 1101 |
} |
| 1102 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true)) { |
| 1103 |
$return['PDF_fields']['roomnumber'] = _('Room number'); |
| 1104 |
} |
| 1105 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode')) { |
| 1106 |
$return['PDF_fields']['postalCode'] = _('Postal code'); |
| 1107 |
} |
| 1108 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox')) { |
| 1109 |
$return['PDF_fields']['postOfficeBox'] = _('Post office box'); |
| 1110 |
} |
| 1111 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidest')) { |
| 1112 |
$return['PDF_fields']['st'] = _('State'); |
| 1113 |
} |
| 1114 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidestreetAddress')) { |
| 1115 |
$return['PDF_fields']['streetAddress'] = _('Street'); |
| 1116 |
} |
| 1117 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetelephoneNumber')) { |
| 1118 |
$return['PDF_fields']['telephoneNumber'] = _('Telephone number'); |
| 1119 |
} |
| 1120 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideurl')) { |
| 1121 |
$return['PDF_fields']['url'] = _('Other web sites'); |
| 1122 |
} |
| 1123 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidewWWHomePage')) { |
| 1124 |
$return['PDF_fields']['wWWHomePage'] = _('Web site'); |
| 1125 |
} |
| 1126 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideWorkstations')) { |
| 1127 |
$return['PDF_fields']['userWorkstations'] = _('Workstations'); |
| 1128 |
} |
| 1129 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideproxyAddresses', true)) { |
| 1130 |
$return['PDF_fields']['proxyAddresses'] = _('Proxy-Addresses'); |
| 1131 |
} |
| 1132 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidefacsimileTelephoneNumber')) { |
| 1133 |
$return['PDF_fields']['facsimileTelephoneNumber'] = _('Fax number'); |
| 1134 |
} |
| 1135 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidesAMAccountName', true)) { |
| 1136 |
$return['PDF_fields']['sAMAccountName'] = _('User name (pre W2K)'); |
| 1137 |
} |
| 1138 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true)) { |
| 1139 |
$return['PDF_fields']['msSFU30Name'] = _('NIS name'); |
| 1140 |
} |
| 1141 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 1142 |
$return['PDF_fields']['msSFU30NisDomain'] = _('NIS domain'); |
| 1143 |
} |
| 1144 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepwdLastSet')) { |
| 1145 |
$return['PDF_fields']['pwdLastSet'] = _('Last password change'); |
| 1146 |
} |
| 1147 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepwdChangeRequired')) { |
| 1148 |
$return['PDF_fields']['msds-userpasswordexpirytimecomputed'] = _('Password expiration'); |
| 1149 |
} |
| 1150 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidelastLogonTimestamp')) { |
| 1151 |
$return['PDF_fields']['lastLogonTimestamp'] = _('Last login'); |
| 1152 |
} |
| 1153 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 1154 |
$return['PDF_fields']['title'] = _('Job title'); |
| 1155 |
} |
| 1156 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle', true)) { |
| 1157 |
$return['PDF_fields']['personaltitle'] = _('Personal title'); |
| 1158 |
} |
| 1159 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecarLicense', true)) { |
| 1160 |
$return['PDF_fields']['carLicense'] = _('Car license'); |
| 1161 |
} |
| 1162 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeNumber', true)) { |
| 1163 |
$return['PDF_fields']['employeeNumber'] = _('Employee number'); |
| 1164 |
} |
| 1165 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 1166 |
$return['PDF_fields']['employeeType'] = _('Employee type'); |
| 1167 |
} |
| 1168 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 1169 |
$return['PDF_fields']['businessCategory'] = _('Business category'); |
| 1170 |
} |
| 1171 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 1172 |
$return['PDF_fields']['department'] = _('Department'); |
| 1173 |
} |
| 1174 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 1175 |
$return['PDF_fields']['departmentNumber'] = _('Department number'); |
| 1176 |
} |
| 1177 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 1178 |
$return['PDF_fields']['ou'] = _('Organisational unit'); |
| 1179 |
} |
| 1180 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 1181 |
$return['PDF_fields']['o'] = _('Organisation'); |
| 1182 |
} |
| 1183 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemanager', true)) { |
| 1184 |
$return['PDF_fields']['manager'] = _('Manager'); |
| 1185 |
} |
| 1186 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecompany', true)) { |
| 1187 |
$return['PDF_fields']['company'] = _('Company'); |
| 1188 |
} |
| 1189 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepager', true)) { |
| 1190 |
$return['PDF_fields']['pager'] = _('Pager'); |
| 1191 |
} |
| 1192 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherPager', true)) { |
| 1193 |
$return['PDF_fields']['otherPager'] = _('Other pagers'); |
| 1194 |
} |
| 1195 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemobile', true)) { |
| 1196 |
$return['PDF_fields']['mobile'] = _('Mobile'); |
| 1197 |
} |
| 1198 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMobile', true)) { |
| 1199 |
$return['PDF_fields']['otherMobile'] = _('Other mobiles'); |
| 1200 |
} |
| 1201 |
// self-service search attributes |
| 1202 |
$return['selfServiceSearchAttributes'] = ['sAMAccountName', 'userPrincipalName', |
| 1203 |
'employeeNumber' |
| 1204 |
]; |
| 1205 |
// self-service field settings |
| 1206 |
$return['selfServiceFieldSettings'] = [ |
| 1207 |
'physicalDeliveryOfficeName' => _('Office name'), |
| 1208 |
'roomnumber' => _('Room number'), |
| 1209 |
'personaltitle' => _('Personal title'), |
| 1210 |
'telephoneNumber' => _('Telephone number'), |
| 1211 |
'facsimileTelephoneNumber' => _('Fax number'), |
| 1212 |
'wWWHomePage' => _('Web site'), |
| 1213 |
'streetAddress' => _('Street'), |
| 1214 |
'st' => _('State'), |
| 1215 |
'l' => _('Location'), |
| 1216 |
'postOfficeBox' => _('Post office box'), |
| 1217 |
'postalCode' => _('Postal code'), |
| 1218 |
'unicodePwd' => _('Password'), |
| 1219 |
'pwdLastSet' => _('Last password change (read-only)'), |
| 1220 |
'msds-userpasswordexpirytimecomputed' => _('Password expiration (read-only)'), |
| 1221 |
'accountExpires' => _('Account expiration date (read-only)'), |
| 1222 |
'department' => _('Department'), |
| 1223 |
'departmentNumber' => _('Department number'), |
| 1224 |
'proxyAddresses' => _('Proxy-Addresses (read-only)'), |
| 1225 |
'otherMailbox' => _('Email alias (read-only)'), |
| 1226 |
]; |
| 1227 |
// possible self-service read-only fields |
| 1228 |
$return['selfServiceReadOnlyFields'] = ['physicalDeliveryOfficeName', 'telephoneNumber', |
| 1229 |
'facsimileTelephoneNumber', 'wWWHomePage', 'streetAddress', 'st', 'l', 'postOfficeBox', |
| 1230 |
'departmentNumber', 'postalCode']; |
| 1231 |
return $return; |
| 1232 |
} |
| 1233 |
|
| 1234 |
/** |
| 1235 |
* {@inheritDoc} |
| 1236 |
*/ |
| 1237 |
public function init(string $base): void { |
| 1238 |
// call parent init |
| 1239 |
parent::init($base); |
| 1240 |
$this->groupList = []; |
| 1241 |
$this->groupList_orig = []; |
| 1242 |
} |
| 1243 |
|
| 1244 |
/** |
| 1245 |
* {@inheritDoc} |
| 1246 |
*/ |
| 1247 |
protected function load_Messages(): void { |
| 1248 |
$this->messages['userPrincipalName'][0] = ['ERROR', _('User name'), _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')]; |
| 1249 |
$this->messages['userPrincipalName'][1] = ['ERROR', _('Account %s:') . ' windowsUser_userPrincipalName', _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')]; |
| 1250 |
$this->messages['userPrincipalName'][2] = ['ERROR', _('User name already exists!')]; |
| 1251 |
$this->messages['userPrincipalName'][3] = ['WARN', _('Account %s:') . ' windowsUser_userPrincipalName', _('User name already exists!')]; |
| 1252 |
$this->messages['cn'][0] = ['ERROR', _('Common name'), _('Please enter a valid common name!')]; |
| 1253 |
$this->messages['cn'][1] = ['ERROR', _('Account %s:') . ' windowsUser_cn', _('Please enter a valid common name!')]; |
| 1254 |
$this->messages['cn'][2] = ['WARN', _('Common name already exists.')]; |
| 1255 |
$this->messages['cn'][3] = ['WARN', _('Account %s:') . ' windowsUser_cn', _('Common name already exists.')]; |
| 1256 |
$this->messages['sAMAccountName'][0] = ['ERROR', _('User name (pre W2K)'), _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')]; |
| 1257 |
$this->messages['sAMAccountName'][1] = ['ERROR', _('Account %s:') . ' windowsUser_sAMAccountName', _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')]; |
| 1258 |
$this->messages['displayName'][0] = ['ERROR', _('Display name'), _('Please enter a valid display name!')]; |
| 1259 |
$this->messages['displayName'][1] = ['ERROR', _('Account %s:') . ' windowsUser_displayName', _('Please enter a valid display name!')]; |
| 1260 |
$this->messages['givenName'][0] = ['ERROR', _('First name'), _('First name contains invalid characters!')]; |
| 1261 |
$this->messages['givenName'][1] = ['ERROR', _('Account %s:') . ' windowsUser_givenName', _('First name contains invalid characters!')]; |
| 1262 |
$this->messages['sn'][0] = ['ERROR', _('Last name'), _('Last name contains invalid characters or is empty!')]; |
| 1263 |
$this->messages['sn'][1] = ['ERROR', _('Account %s:') . ' windowsUser_sn', _('Last name contains invalid characters or is empty!')]; |
| 1264 |
$this->messages['telephoneNumber'][0] = ['ERROR', _('Telephone number'), _('Please enter a valid telephone number!')]; |
| 1265 |
$this->messages['telephoneNumber'][1] = ['ERROR', _('Account %s:') . ' windowsUser_telephone', _('Please enter a valid telephone number!')]; |
| 1266 |
$this->messages['facsimileTelephoneNumber'][0] = ['ERROR', _('Fax number'), _('Please enter a valid fax number!')]; |
| 1267 |
$this->messages['facsimileTelephoneNumber'][1] = ['ERROR', _('Account %s:') . ' windowsUser_facsimileTelephoneNumber', _('Please enter a valid fax number!')]; |
| 1268 |
$this->messages['otherTelephone'][0] = ['ERROR', _('Other telephone numbers'), _('Please enter a valid telephone number!')]; |
| 1269 |
$this->messages['otherTelephone'][1] = ['ERROR', _('Account %s:') . ' windowsUser_otherTelephone', _('Please enter a valid telephone number!')]; |
| 1270 |
$this->messages['pager'][0] = ['ERROR', _('Pager'), _('Please enter a valid telephone number!')]; |
| 1271 |
$this->messages['pager'][1] = ['ERROR', _('Account %s:') . ' windowsUser_pager', _('Please enter a valid telephone number!')]; |
| 1272 |
$this->messages['otherPager'][0] = ['ERROR', _('Other pagers'), _('Please enter a valid telephone number!')]; |
| 1273 |
$this->messages['otherPager'][1] = ['ERROR', _('Account %s:') . ' windowsUser_otherPager', _('Please enter a valid telephone number!')]; |
| 1274 |
$this->messages['mobile'][0] = ['ERROR', _('Mobile'), _('Please enter a valid telephone number!')]; |
| 1275 |
$this->messages['mobile'][1] = ['ERROR', _('Account %s:') . ' windowsUser_mobile', _('Please enter a valid telephone number!')]; |
| 1276 |
$this->messages['otherMobile'][0] = ['ERROR', _('Other mobiles'), _('Please enter a valid telephone number!')]; |
| 1277 |
$this->messages['otherMobile'][1] = ['ERROR', _('Account %s:') . ' windowsUser_otherMobile', _('Please enter a valid telephone number!')]; |
| 1278 |
$this->messages['postalCode'][0] = ['ERROR', _('Postal code'), _('Please enter a valid postal code!')]; |
| 1279 |
$this->messages['postalCode'][1] = ['ERROR', _('Account %s:') . ' windowsUser_postalCode', _('Please enter a valid postal code!')]; |
| 1280 |
$this->messages['mail'][0] = ['ERROR', _('Email address'), _('Please enter a valid email address!')]; |
| 1281 |
$this->messages['mail'][1] = ['ERROR', _('Account %s:') . ' windowsUser_mail', _('Please enter a valid email address!')]; |
| 1282 |
$this->messages['mail'][2] = ['WARN', _('Email address'), _('Email "%s" already in use.')]; |
| 1283 |
$this->messages['mail'][3] = ['WARN', _('Account %s:') . ' windowsUser_mail', _('Email "%s" already in use.')]; |
| 1284 |
$this->messages['otherMailbox'][0] = ['ERROR', _('Email alias'), _('Email alias is invalid!')]; |
| 1285 |
$this->messages['otherMailbox'][1] = ['ERROR', _('Account %s:') . ' windowsUser_otherMailbox', _('Email alias is invalid!')]; |
| 1286 |
$this->messages['otherMailbox'][2] = ['WARN', _('Email alias'), _('Email alias "%s" already in use.')]; |
| 1287 |
$this->messages['otherMailbox'][3] = ['WARN', _('Account %s:') . ' windowsUser_otherMailbox', _('Email alias "%s" already in use.')]; |
| 1288 |
$this->messages['profilePath'][0] = ['ERROR', _('Profile path'), _('Profile path is invalid!')]; |
| 1289 |
$this->messages['profilePath'][1] = ['ERROR', _('Account %s:') . ' windowsUser_profilePath', _('Profile path is invalid!')]; |
| 1290 |
$this->messages['scriptPath'][0] = ['ERROR', _('Logon script'), _('Logon script is invalid!')]; |
| 1291 |
$this->messages['scriptPath'][1] = ['ERROR', _('Account %s:') . ' windowsUser_scriptPath', _('Logon script is invalid!')]; |
| 1292 |
$this->messages['unicodePwd'][0] = ['ERROR', _('Password'), _('Please enter the same password in both password fields.')]; |
| 1293 |
$this->messages['unicodePwd'][1] = ['ERROR', _('Password'), _('Password contains invalid characters. Valid characters are:') . ' a-z, A-Z, 0-9 and #*,.;:_-+!%&/|?{[()]}=@$ §°!']; |
| 1294 |
$this->messages['unicodePwd'][2] = ['ERROR', _('Account %s:') . ' windowsUser_password', _('Password contains invalid characters. Valid characters are:') . ' a-z, A-Z, 0-9 and #*,.;:_-+!%&/|?{[()]}=@$ §°!']; |
| 1295 |
$this->messages['homeDrive'][0] = ['ERROR', _('Account %s:') . ' windowsUser_homeDrive', _('Please enter a valid drive letter.')]; |
| 1296 |
$this->messages['homeDirectory'][0] = ['ERROR', _('Home directory'), _('Homedirectory contains invalid characters.')]; |
| 1297 |
$this->messages['homeDirectory'][1] = ['ERROR', _('Account %s:') . ' windowsUser_homeDirectory', _('Homedirectory contains invalid characters.')]; |
| 1298 |
$this->messages['msSFU30Name'][0] = ['ERROR', _('NIS name'), _('NIS name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')]; |
| 1299 |
$this->messages['msSFU30Name'][1] = ['ERROR', _('Account %s:') . ' windowsUser_msSFU30Name', _('NIS name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !')]; |
| 1300 |
$this->messages['accountexpires'][0] = ['ERROR', _('Account expiration'), _('Please enter a number.')]; |
| 1301 |
$this->messages['accountexpires'][1] = ['ERROR', _('Account %s:') . ' windowsUser_accountExpires', _('Please enter a valid date in format DD-MM-YYYY.')]; |
| 1302 |
$this->messages['title'][0] = ['ERROR', _('Job title'), _('Please enter a valid job title!')]; |
| 1303 |
$this->messages['title'][1] = ['ERROR', _('Account %s:') . ' windowsUser_title', _('Please enter a valid job title!')]; |
| 1304 |
$this->messages['personaltitle'][0] = ['ERROR', _('Personal title'), _('Please enter a valid personal title.')]; |
| 1305 |
$this->messages['personaltitle'][1] = ['ERROR', _('Account %s:') . ' windowsUser_personalTitle', _('Please enter a valid personal title.')]; |
| 1306 |
$this->messages['employeeType'][0] = ['ERROR', _('Employee type'), _('Please enter a valid employee type!')]; |
| 1307 |
$this->messages['employeeType'][1] = ['ERROR', _('Account %s:') . ' windowsUser_employeeType', _('Please enter a valid employee type!')]; |
| 1308 |
$this->messages['businessCategory'][0] = ['ERROR', _('Business category'), _('Please enter a valid business category!')]; |
| 1309 |
$this->messages['businessCategory'][1] = ['ERROR', _('Account %s:') . ' windowsUser_businessCategory', _('Please enter a valid business category!')]; |
| 1310 |
$this->messages['manager'][0] = ['ERROR', _('Account %s:') . ' windowsUser_manager', _('This is not a valid DN!')]; |
| 1311 |
$this->messages['file'][0] = ['ERROR', _('No file selected.')]; |
| 1312 |
$this->messages['file'][1] = ['ERROR', _('Please upload a .jpg/.jpeg file.')]; |
| 1313 |
$this->messages['file'][2] = ['ERROR', _('Unable to process this file.')]; |
| 1314 |
$this->messages['file'][3] = ['ERROR', _('File is too large. Maximum allowed size is %s kB.')]; |
| 1315 |
$this->messages['workstations'][0] = ['ERROR', _('Workstations'), _('Please enter a comma separated list of host names!')]; |
| 1316 |
$this->messages['workstations'][1] = ['ERROR', _('Account %s:') . ' windowsUser_workstations', _('Please enter a comma separated list of host names!')]; |
| 1317 |
} |
| 1318 |
|
| 1319 |
/** |
| 1320 |
* {@inheritDoc} |
| 1321 |
*/ |
| 1322 |
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void { |
| 1323 |
parent::loadAttributesFromAccountCopy($ldapAttributes, array_merge(baseModule::ATTRIBUTES_TO_IGNORE_ON_COPY_DEFAULT, self::ATTRIBUTES_TO_IGNORE_ON_COPY)); |
| 1324 |
} |
| 1325 |
|
| 1326 |
/** |
| 1327 |
* {@inheritDoc} |
| 1328 |
*/ |
| 1329 |
public function load_attributes(array $attributes): void { |
| 1330 |
parent::load_attributes($attributes); |
| 1331 |
// get group memberships |
| 1332 |
$groupList = searchLDAPByAttribute('member', $this->getAccountContainer()->dn_orig, 'group', ['dn'], ['group']); |
| 1333 |
$this->groupList_orig = []; |
| 1334 |
for ($i = 0; $i < count($groupList); $i++) { |
| 1335 |
$this->groupList_orig[] = $groupList[$i]['dn']; |
| 1336 |
} |
| 1337 |
$this->groupList_orig = array_values(array_unique($this->groupList_orig)); |
| 1338 |
$this->groupList = $this->groupList_orig; |
| 1339 |
} |
| 1340 |
|
| 1341 |
/** |
| 1342 |
* {@inheritDoc} |
| 1343 |
*/ |
| 1344 |
public function save_attributes(): array { |
| 1345 |
// do not add securityPrincipal on existing accounts if it was not set before |
| 1346 |
if (!$this->getAccountContainer()->isNewAccount |
| 1347 |
&& in_array_ignore_case('user', $this->orig['objectClass']) |
| 1348 |
&& !in_array('securityPrincipal', $this->orig['objectClass']) |
| 1349 |
&& in_array('securityPrincipal', $this->attributes['objectClass'])) { |
| 1350 |
$this->attributes['objectClass'] = array_delete(['securityPrincipal'], $this->attributes['objectClass']); |
| 1351 |
} |
| 1352 |
$return = parent::save_attributes(); |
| 1353 |
// add information about clear text password and password status change |
| 1354 |
$return[$this->getAccountContainer()->dn_orig]['info']['userPasswordClearText'][0] = $this->clearTextPassword; |
| 1355 |
return $return; |
| 1356 |
} |
| 1357 |
|
| 1358 |
/** |
| 1359 |
* {@inheritdoc} |
| 1360 |
*/ |
| 1361 |
public function getWildcardTargetAttributeNames(): array { |
| 1362 |
return ['cn', 'displayName', 'mail', 'otherMailbox', |
| 1363 |
'profilePath', 'scriptPath', 'homeDirectory', 'userPrincipalName', |
| 1364 |
'sAMAccountName']; |
| 1365 |
} |
| 1366 |
|
| 1367 |
/** |
| 1368 |
* {@inheritDoc} |
| 1369 |
*/ |
| 1370 |
public function display_html_attributes(): htmlElement|array { |
| 1371 |
$this->initCache(); |
| 1372 |
$this->getAccountContainer()->replaceWildcardsInArray($this->getWildcardTargetAttributeNames(), $this->attributes); |
| 1373 |
$containerLeft = new htmlResponsiveRow(); |
| 1374 |
if ($this->getAccountContainer()->isNewAccount && !isset($this->attributes['useraccountcontrol'][0])) { |
| 1375 |
$this->attributes['useraccountcontrol'][0] = self::DEFAULT_ACCOUNT_CONTROL; |
| 1376 |
} |
| 1377 |
$containerLeft->add(new htmlSubTitle(_('General'))); |
| 1378 |
// user name |
| 1379 |
$userPrincipalName = ''; |
| 1380 |
$userPrincipalNameDomain = ''; |
| 1381 |
$domains = $this->getDomains(); |
| 1382 |
$domains[] = ''; |
| 1383 |
if (!empty($this->attributes['userPrincipalName'][0])) { |
| 1384 |
$parts = explode('@', $this->attributes['userPrincipalName'][0]); |
| 1385 |
$userPrincipalName = $parts[0]; |
| 1386 |
if (!empty($parts[1])) { |
| 1387 |
$userPrincipalNameDomain = $parts[1]; |
| 1388 |
if (!in_array($userPrincipalNameDomain, $domains)) { |
| 1389 |
$domains[] = $userPrincipalNameDomain; |
| 1390 |
} |
| 1391 |
} |
| 1392 |
} |
| 1393 |
$userPrincipalNameLabel = new htmlOutputText(_('User name')); |
| 1394 |
$userPrincipalNameLabel->setMarkAsRequired(true); |
| 1395 |
$containerLeft->addLabel($userPrincipalNameLabel); |
| 1396 |
$userPrincipalNameGroup = new htmlGroup(); |
| 1397 |
$userPrincipalNameGroup->addElement(new htmlInputField('userPrincipalName', $userPrincipalName, 15)); |
| 1398 |
$userPrincipalNameGroup->addElement(new htmlSelect('userPrincipalNameDomain', $domains, [$userPrincipalNameDomain])); |
| 1399 |
$userPrincipalNameGroup->addElement(new htmlHelpLink('userPrincipalName')); |
| 1400 |
$containerLeft->addField($userPrincipalNameGroup); |
| 1401 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidesAMAccountName', true)) { |
| 1402 |
$this->addSimpleInputTextField($containerLeft, 'sAMAccountName', _('User name (pre W2K)')); |
| 1403 |
} |
| 1404 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle', true)) { |
| 1405 |
$this->addSimpleInputTextField($containerLeft, 'personaltitle', _('Personal title')); |
| 1406 |
} |
| 1407 |
$this->addSimpleInputTextField($containerLeft, 'givenName', _('First name')); |
| 1408 |
$this->addSimpleInputTextField($containerLeft, 'sn', _('Last name')); |
| 1409 |
$this->addSimpleInputTextField($containerLeft, 'cn', _('Common name'), true); |
| 1410 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 1411 |
$this->addSimpleInputTextField($containerLeft, 'displayName', _('Display name')); |
| 1412 |
} |
| 1413 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideinitials')) { |
| 1414 |
$this->addSimpleInputTextField($containerLeft, 'initials', _('Initials')); |
| 1415 |
} |
| 1416 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedescription')) { |
| 1417 |
$this->addSimpleInputTextField($containerLeft, 'description', _('Description')); |
| 1418 |
} |
| 1419 |
// address area |
| 1420 |
$showStreetAddress = !$this->isBooleanConfigOptionSet('windowsUser_hidestreetAddress'); |
| 1421 |
$showPostOfficeBox = !$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox'); |
| 1422 |
$showPostalCode = !$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode'); |
| 1423 |
$showL = !$this->isBooleanConfigOptionSet('windowsUser_hidel'); |
| 1424 |
$showSt = !$this->isBooleanConfigOptionSet('windowsUser_hidest'); |
| 1425 |
$showPhysicalDeliveryOfficeName = !$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName'); |
| 1426 |
$showAddress = $showStreetAddress || $showPostOfficeBox || $showPostalCode || $showL || $showSt || $showPhysicalDeliveryOfficeName; |
| 1427 |
if ($showAddress) { |
| 1428 |
$containerLeft->add(new htmlSubTitle(_('Address'))); |
| 1429 |
} |
| 1430 |
if ($showStreetAddress) { |
| 1431 |
$this->addSimpleInputTextField($containerLeft, 'streetAddress', _('Street'), false, 20, true); |
| 1432 |
} |
| 1433 |
if ($showPostOfficeBox) { |
| 1434 |
$this->addSimpleInputTextField($containerLeft, 'postOfficeBox', _('Post office box')); |
| 1435 |
} |
| 1436 |
if ($showPostalCode) { |
| 1437 |
$this->addSimpleInputTextField($containerLeft, 'postalCode', _('Postal code')); |
| 1438 |
} |
| 1439 |
if ($showL) { |
| 1440 |
$this->addSimpleInputTextField($containerLeft, 'l', _('Location')); |
| 1441 |
} |
| 1442 |
if ($showSt) { |
| 1443 |
$this->addSimpleInputTextField($containerLeft, 'st', _('State')); |
| 1444 |
} |
| 1445 |
if ($showPhysicalDeliveryOfficeName) { |
| 1446 |
$this->addSimpleInputTextField($containerLeft, 'physicalDeliveryOfficeName', _('Office name')); |
| 1447 |
} |
| 1448 |
// contact data area |
| 1449 |
$showMail = !$this->isBooleanConfigOptionSet('windowsUser_hidemail'); |
| 1450 |
$showOtherMailbox = !$this->isBooleanConfigOptionSet('windowsUser_hideotherMailbox'); |
| 1451 |
$showProxyAddresses = !$this->isBooleanConfigOptionSet('windowsUser_hideproxyAddresses', true); |
| 1452 |
$showTelephoneNumber = !$this->isBooleanConfigOptionSet('windowsUser_hidetelephoneNumber'); |
| 1453 |
$showOtherTelephone = !$this->isBooleanConfigOptionSet('windowsUser_hideotherTelephone'); |
| 1454 |
$showMobile = !$this->isBooleanConfigOptionSet('windowsUser_hidemobile'); |
| 1455 |
$showOtherMobile = !$this->isBooleanConfigOptionSet('windowsUser_hideotherMobile', true); |
| 1456 |
$showPager = !$this->isBooleanConfigOptionSet('windowsUser_hidepager', true); |
| 1457 |
$showOtherPager = !$this->isBooleanConfigOptionSet('windowsUser_hideotherPager', true); |
| 1458 |
$showFacsimileTelephoneNumber = !$this->isBooleanConfigOptionSet('windowsUser_hidefacsimileTelephoneNumber'); |
| 1459 |
$showWWWHomePage = !$this->isBooleanConfigOptionSet('windowsUser_hidewWWHomePage'); |
| 1460 |
$showUrl = !$this->isBooleanConfigOptionSet('windowsUser_hideurl'); |
| 1461 |
$showContactData = $showMail || $showOtherMailbox || $showProxyAddresses || $showTelephoneNumber || $showOtherTelephone || $showMobile || |
| 1462 |
$showOtherMobile || $showPager || $showOtherPager || $showFacsimileTelephoneNumber || $showWWWHomePage || $showUrl; |
| 1463 |
if ($showContactData) { |
| 1464 |
$containerLeft->add(new htmlSubTitle(_('Contact data'))); |
| 1465 |
} |
| 1466 |
if ($showMail) { |
| 1467 |
$this->addSimpleInputTextField($containerLeft, 'mail', _('Email address')); |
| 1468 |
} |
| 1469 |
if ($showOtherMailbox) { |
| 1470 |
$this->addMultiValueInputTextField($containerLeft, 'otherMailbox', _('Email alias')); |
| 1471 |
} |
| 1472 |
if ($showProxyAddresses) { |
| 1473 |
$this->addMultiValueInputTextField($containerLeft, 'proxyAddresses', _('Proxy-Addresses')); |
| 1474 |
} |
| 1475 |
if ($showTelephoneNumber) { |
| 1476 |
$this->addSimpleInputTextField($containerLeft, 'telephoneNumber', _('Telephone number')); |
| 1477 |
} |
| 1478 |
if ($showOtherTelephone) { |
| 1479 |
$this->addMultiValueInputTextField($containerLeft, 'otherTelephone', _('Other telephone numbers')); |
| 1480 |
} |
| 1481 |
if ($showMobile) { |
| 1482 |
$this->addSimpleInputTextField($containerLeft, 'mobile', _('Mobile')); |
| 1483 |
} |
| 1484 |
if ($showOtherMobile) { |
| 1485 |
$this->addMultiValueInputTextField($containerLeft, 'otherMobile', _('Other mobiles')); |
| 1486 |
} |
| 1487 |
if ($showPager) { |
| 1488 |
$this->addSimpleInputTextField($containerLeft, 'pager', _('Pager')); |
| 1489 |
} |
| 1490 |
if ($showOtherPager) { |
| 1491 |
$this->addMultiValueInputTextField($containerLeft, 'otherPager', _('Other pagers')); |
| 1492 |
} |
| 1493 |
if ($showFacsimileTelephoneNumber) { |
| 1494 |
$this->addSimpleInputTextField($containerLeft, 'facsimileTelephoneNumber', _('Fax number')); |
| 1495 |
} |
| 1496 |
if ($showWWWHomePage) { |
| 1497 |
$this->addSimpleInputTextField($containerLeft, 'wWWHomePage', _('Web site')); |
| 1498 |
} |
| 1499 |
if ($showUrl) { |
| 1500 |
$this->addMultiValueInputTextField($containerLeft, 'url', _('Other web sites')); |
| 1501 |
} |
| 1502 |
// work details area |
| 1503 |
if ($this->manageWorkDetails()) { |
| 1504 |
$containerLeft->add(new htmlSubTitle(_('Work details'))); |
| 1505 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 1506 |
$this->addSimpleInputTextField($containerLeft, 'title', _('Job title'), false, null, false, array_slice($this->titleCache, 0, 300)); |
| 1507 |
} |
| 1508 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeNumber', true)) { |
| 1509 |
$this->addSimpleInputTextField($containerLeft, 'employeeNumber', _('Employee number')); |
| 1510 |
} |
| 1511 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 1512 |
$this->addSimpleInputTextField($containerLeft, 'employeeType', _('Employee type'), false, null, false, array_slice($this->employeeTypeCache, 0, 300)); |
| 1513 |
} |
| 1514 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true)) { |
| 1515 |
$this->addMultiValueInputTextField($containerLeft, 'roomnumber', _('Room number')); |
| 1516 |
} |
| 1517 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecarLicense', true)) { |
| 1518 |
$this->addSimpleInputTextField($containerLeft, 'carLicense', _('Car license')); |
| 1519 |
} |
| 1520 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 1521 |
$this->addMultiValueInputTextField($containerLeft, 'businessCategory', _('Business category'), false, null, false, array_slice($this->businessCategoryCache, 0, 300)); |
| 1522 |
} |
| 1523 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecompany', true)) { |
| 1524 |
$this->addSimpleInputTextField($containerLeft, 'company', _('Company')); |
| 1525 |
} |
| 1526 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 1527 |
$this->addSimpleInputTextField($containerLeft, 'department', _('Department'), false, null, false, array_slice($this->departmentCache, 0, 300)); |
| 1528 |
} |
| 1529 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 1530 |
$this->addMultiValueInputTextField($containerLeft, 'departmentNumber', _('Department number'), false, null, false, array_slice($this->departmentNumberCache, 0, 300)); |
| 1531 |
} |
| 1532 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 1533 |
$this->addMultiValueInputTextField($containerLeft, 'ou', _('Organisational unit'), false, null, false, array_slice($this->ouCache, 0, 300)); |
| 1534 |
} |
| 1535 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 1536 |
$this->addMultiValueInputTextField($containerLeft, 'o', _('Organisation'), false, null, false, array_slice($this->oCache, 0, 300)); |
| 1537 |
} |
| 1538 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemanager', true)) { |
| 1539 |
$containerLeft->addLabel(new htmlOutputText(_('Manager'))); |
| 1540 |
$managerGroup = new htmlGroup(); |
| 1541 |
$managerVal = (empty($this->attributes['manager'][0])) ? '-' : getAbstractDN($this->attributes['manager'][0]); |
| 1542 |
$managerGroup->addElement(new htmlOutputText($managerVal)); |
| 1543 |
$managerGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1544 |
$managerGroup->addElement(new htmlAccountPageButton(static::class, 'manager', 'change', _("Change"))); |
| 1545 |
$managerGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1546 |
$managerGroup->addElement(new htmlHelpLink('manager')); |
| 1547 |
$containerLeft->addField($managerGroup); |
| 1548 |
} |
| 1549 |
} |
| 1550 |
// account area |
| 1551 |
$containerLeft->add(new htmlSubTitle(_('Account'))); |
| 1552 |
// deactivated |
| 1553 |
$deactivated = windowsUser::isDeactivated($this->attributes); |
| 1554 |
$containerLeft->add(new htmlResponsiveInputCheckbox('deactivated', $deactivated, _("Account is deactivated"), 'deactivated')); |
| 1555 |
// password does not expire |
| 1556 |
$noExpire = windowsUser::isNeverExpiring($this->attributes); |
| 1557 |
$containerLeft->add(new htmlResponsiveInputCheckbox('noExpire', $noExpire, _("Password does not expire"), 'noExpire')); |
| 1558 |
// require smartcard |
| 1559 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideRequireSmartcard')) { |
| 1560 |
$requireCard = windowsUser::isSmartCardRequired($this->attributes); |
| 1561 |
$containerLeft->add(new htmlResponsiveInputCheckbox('requireCard', $requireCard, _("Require smartcard"), 'requireCard')); |
| 1562 |
} |
| 1563 |
// account expiration |
| 1564 |
$containerLeft->addLabel(new htmlOutputText(_('Account expiration date'))); |
| 1565 |
$accountExpiresGroup = new htmlGroup(); |
| 1566 |
$accountExpiresGroup->addElement(new htmlOutputText($this->formatAccountExpires())); |
| 1567 |
$accountExpiresGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1568 |
$accountExpiresGroup->addElement(new htmlAccountPageButton(static::class, 'accountexpires', 'edit', _('Change'))); |
| 1569 |
$accountExpiresGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1570 |
$accountExpiresGroup->addElement(new htmlHelpLink('accountexpires')); |
| 1571 |
$containerLeft->addField($accountExpiresGroup); |
| 1572 |
// last password change |
| 1573 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepwdLastSet')) { |
| 1574 |
$containerLeft->addLabel(new htmlOutputText(_('Last password change'))); |
| 1575 |
$pwdLastSetGroup = new htmlGroup(); |
| 1576 |
$pwdLastSetGroup->addElement(new htmlOutputText($this->formatPwdLastSet())); |
| 1577 |
$pwdLastSetGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1578 |
if (isset($this->attributes['pwdLastSet'][0]) && ($this->attributes['pwdLastSet'][0] === '0')) { |
| 1579 |
$pwdLastSetGroup->addElement(new htmlAccountPageButton(static::class, 'attributes', 'releasePasswordChange', _('Clear password expiration'))); |
| 1580 |
} |
| 1581 |
else { |
| 1582 |
$pwdLastSetGroup->addElement(new htmlAccountPageButton(static::class, 'attributes', 'forcePasswordChange', _('Force password change'))); |
| 1583 |
} |
| 1584 |
$pwdLastSetGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1585 |
$pwdLastSetGroup->addElement(new htmlHelpLink('pwdLastSet')); |
| 1586 |
$containerLeft->addField($pwdLastSetGroup); |
| 1587 |
} |
| 1588 |
// password change required |
| 1589 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepwdChangeRequired')) { |
| 1590 |
$containerLeft->addLabel(new htmlOutputText(_('Password expiration'))); |
| 1591 |
$containerLeft->addField(new htmlOutputText($this->formatPasswordExpires($this->attributes))); |
| 1592 |
} |
| 1593 |
// last login |
| 1594 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidelastLogonTimestamp')) { |
| 1595 |
$containerLeft->addLabel(new htmlOutputText(_('Last login'))); |
| 1596 |
$lastLogonTimestampGroup = new htmlGroup(); |
| 1597 |
$lastLogonTimestampGroup->addElement(new htmlOutputText($this->formatLastLogonTimestamp())); |
| 1598 |
$lastLogonTimestampGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1599 |
$lastLogonTimestampGroup->addElement(new htmlHelpLink('lastLogonTimestamp')); |
| 1600 |
$containerLeft->addField($lastLogonTimestampGroup); |
| 1601 |
} |
| 1602 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideWorkstations')) { |
| 1603 |
$containerLeft->addLabel(new htmlOutputText(_('Workstations'))); |
| 1604 |
$userWorkstationsGroup = new htmlGroup(); |
| 1605 |
$userWorkstationsGroup->addElement(new htmlAccountPageButton(static::class, 'userWorkstations', 'open', _('Edit workstations'))); |
| 1606 |
$userWorkstationsGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1607 |
$userWorkstationsGroup->addElement(new htmlHelpLink('userWorkstations')); |
| 1608 |
$containerLeft->addField($userWorkstationsGroup); |
| 1609 |
} |
| 1610 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidelogonHours')) { |
| 1611 |
$containerLeft->addLabel(new htmlOutputText(_('Logon hours'))); |
| 1612 |
$logonHoursGroup = new htmlGroup(); |
| 1613 |
$logonHoursGroup->addElement(new htmlAccountPageButton(static::class, 'logonHours', 'open', _('Edit'))); |
| 1614 |
$logonHoursGroup->addElement(new htmlSpacer('0.5rem', null)); |
| 1615 |
$logonHoursGroup->addElement(new htmlHelpLink('logonhours')); |
| 1616 |
$containerLeft->addField($logonHoursGroup); |
| 1617 |
} |
| 1618 |
// user profile area |
| 1619 |
$showProfilePath = !$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath'); |
| 1620 |
$showScriptPath = !$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath'); |
| 1621 |
$showHomeDrive = !$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive'); |
| 1622 |
$showHomeDirectory = !$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory'); |
| 1623 |
$showUserProfile = $showProfilePath || $showScriptPath || $showHomeDrive || $showHomeDirectory; |
| 1624 |
if ($showUserProfile) { |
| 1625 |
$containerLeft->add(new htmlSubTitle(_('User profile'))); |
| 1626 |
} |
| 1627 |
// profile path |
| 1628 |
if ($showProfilePath) { |
| 1629 |
$this->addSimpleInputTextField($containerLeft, 'profilePath', _('Profile path')); |
| 1630 |
} |
| 1631 |
// logon script |
| 1632 |
if ($showScriptPath) { |
| 1633 |
$this->addSimpleInputTextField($containerLeft, 'scriptPath', _('Logon script')); |
| 1634 |
} |
| 1635 |
// home drive |
| 1636 |
if ($showHomeDrive) { |
| 1637 |
$drives = ['-']; |
| 1638 |
for ($i = 90; $i > 67; $i--) { |
| 1639 |
$drives[] = chr($i) . ':'; |
| 1640 |
} |
| 1641 |
$selected = empty($this->attributes['homeDrive'][0]) ? ['-'] : [strtoupper($this->attributes['homeDrive'][0])]; |
| 1642 |
$containerLeft->add(new htmlResponsiveSelect('homeDrive', $drives, $selected, _('Home drive'), 'homeDrive')); |
| 1643 |
} |
| 1644 |
// home directory |
| 1645 |
if ($showHomeDirectory) { |
| 1646 |
$this->addSimpleInputTextField($containerLeft, 'homeDirectory', _('Home directory')); |
| 1647 |
} |
| 1648 |
|
| 1649 |
// NIS attributes |
| 1650 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true) || !$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 1651 |
$containerLeft->add(new htmlSubTitle(_('NIS'))); |
| 1652 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true)) { |
| 1653 |
$this->addSimpleInputTextField($containerLeft, 'msSFU30Name', _('NIS name')); |
| 1654 |
} |
| 1655 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 1656 |
$this->addSimpleInputTextField($containerLeft, 'msSFU30NisDomain', _('NIS domain')); |
| 1657 |
} |
| 1658 |
} |
| 1659 |
|
| 1660 |
$containerRight = new htmlResponsiveRow(); |
| 1661 |
// photo |
| 1662 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidejpegPhoto', true)) { |
| 1663 |
$photoFile = '../../graphics/user.svg'; |
| 1664 |
$noPhoto = true; |
| 1665 |
if (isset($this->attributes['jpegPhoto'][0])) { |
| 1666 |
$tempFilesManager = new LamTemporaryFilesManager(); |
| 1667 |
$jpegFileName = $tempFilesManager->registerTemporaryFile('.jpg'); |
| 1668 |
$outjpeg = $tempFilesManager->openTemporaryFileForWrite($jpegFileName); |
| 1669 |
fwrite($outjpeg, $this->attributes['jpegPhoto'][0]); |
| 1670 |
fclose($outjpeg); |
| 1671 |
$photoFile = $tempFilesManager->getResourceLink($jpegFileName); |
| 1672 |
$noPhoto = false; |
| 1673 |
} |
| 1674 |
$img = new htmlImage($photoFile); |
| 1675 |
$img->setCSSClasses(['photo']); |
| 1676 |
$img->enableLightbox(); |
| 1677 |
$containerRight->add($img); |
| 1678 |
$containerRight->addVerticalSpacer('0.5rem'); |
| 1679 |
if ($noPhoto) { |
| 1680 |
$containerRight->add(new htmlAccountPageButton(static::class, 'photo', 'open', _('Add photo'))); |
| 1681 |
} |
| 1682 |
else { |
| 1683 |
$containerRight->add(new htmlButton('delPhoto', _('Delete photo'))); |
| 1684 |
} |
| 1685 |
$containerRight->addVerticalSpacer('2rem'); |
| 1686 |
} |
| 1687 |
// thumbnail |
| 1688 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidethumbnailphoto', true)) { |
| 1689 |
$photoFile = '../../graphics/user.svg'; |
| 1690 |
$noPhoto = true; |
| 1691 |
if (isset($this->attributes['thumbnailphoto'][0])) { |
| 1692 |
$tempFilesManager = new LamTemporaryFilesManager(); |
| 1693 |
$jpegFileName = $tempFilesManager->registerTemporaryFile('.jpg'); |
| 1694 |
$outjpeg = $tempFilesManager->openTemporaryFileForWrite($jpegFileName); |
| 1695 |
fwrite($outjpeg, $this->attributes['thumbnailphoto'][0]); |
| 1696 |
fclose($outjpeg); |
| 1697 |
$photoFile = $tempFilesManager->getResourceLink($jpegFileName); |
| 1698 |
$noPhoto = false; |
| 1699 |
} |
| 1700 |
$img = new htmlImage($photoFile); |
| 1701 |
$img->setCSSClasses(['photo']); |
| 1702 |
$img->enableLightbox(); |
| 1703 |
$containerRight->add($img); |
| 1704 |
$containerRight->addVerticalSpacer('0.5rem'); |
| 1705 |
if ($noPhoto) { |
| 1706 |
$containerRight->add(new htmlAccountPageButton(static::class, 'thumbnailphoto', 'open', _('Add thumbnail'))); |
| 1707 |
} |
| 1708 |
else { |
| 1709 |
$containerRight->add(new htmlButton('delthumbnailphoto', _('Delete thumbnail'))); |
| 1710 |
} |
| 1711 |
$containerRight->addVerticalSpacer('2rem'); |
| 1712 |
} |
| 1713 |
// groups |
| 1714 |
$containerRight->add(new htmlSubTitle(_('Groups'))); |
| 1715 |
$containerRight->add(new htmlAccountPageButton(static::class, 'group', 'edit', _('Edit groups'))); |
| 1716 |
$containerRight->addVerticalSpacer('1rem'); |
| 1717 |
$groupsList = new htmlGroup(); |
| 1718 |
$groupNames = []; |
| 1719 |
if ($this->groupDisplayContainsDn()) { |
| 1720 |
usort($this->groupList, compareDN(...)); |
| 1721 |
} |
| 1722 |
foreach ($this->groupList as $groupDn) { |
| 1723 |
$groupCn = extractRDNValue($groupDn); |
| 1724 |
$groupNames[] = $this->formatGroupName($groupCn, $groupDn); |
| 1725 |
} |
| 1726 |
if (!$this->groupDisplayContainsDn()) { |
| 1727 |
natcasesort($groupNames); |
| 1728 |
} |
| 1729 |
foreach ($groupNames as $cn) { |
| 1730 |
$groupsList->addElement(new htmlOutputText($cn)); |
| 1731 |
$groupsList->addElement(new htmlLineBreak()); |
| 1732 |
} |
| 1733 |
$groupsListClass = $this->groupDisplayContainsDn() ? 'rightToLeftText' : ''; |
| 1734 |
$groupsListDiv = new htmlDiv(null, $groupsList, [$groupsListClass]); |
| 1735 |
$containerRight->add($groupsListDiv); |
| 1736 |
|
| 1737 |
$container = new htmlResponsiveRow(); |
| 1738 |
$container->add($containerLeft, 12, 12, 7); |
| 1739 |
$container->add(new htmlSpacer('1rem', null), 0, 0, 1); |
| 1740 |
$container->add($containerRight, 12, 12, 4); |
| 1741 |
return $container; |
| 1742 |
} |
| 1743 |
|
| 1744 |
/** |
| 1745 |
* Formats a group name for the display. |
| 1746 |
* |
| 1747 |
* @param string $cn common name |
| 1748 |
* @param string $dn DN |
| 1749 |
* @return string formatted name |
| 1750 |
*/ |
| 1751 |
private function formatGroupName(string $cn, string $dn): string { |
| 1752 |
$mode = empty($this->moduleSettings['windowsUser_displayGroups'][0]) ? 'DN' : $this->moduleSettings['windowsUser_displayGroups'][0]; |
| 1753 |
return match ($mode) { |
| 1754 |
self::DISPLAY_GROUPS_CN => $cn, |
| 1755 |
default => getAbstractDN($dn), |
| 1756 |
}; |
| 1757 |
} |
| 1758 |
|
| 1759 |
/** |
| 1760 |
* Returns if the group display name contains the DN. |
| 1761 |
* |
| 1762 |
* @return bool contains DN. |
| 1763 |
*/ |
| 1764 |
private function groupDisplayContainsDn(): bool { |
| 1765 |
$mode = empty($this->moduleSettings['windowsUser_displayGroups'][0]) ? 'DN' : $this->moduleSettings['windowsUser_displayGroups'][0]; |
| 1766 |
return ($mode == self::DISPLAY_GROUPS_DN); |
| 1767 |
} |
| 1768 |
|
| 1769 |
/** |
| 1770 |
* Returns if any of the work details attributes should be managed. |
| 1771 |
* |
| 1772 |
* @return bool has any work attributes to manage |
| 1773 |
*/ |
| 1774 |
private function manageWorkDetails(): bool { |
| 1775 |
$allHidden = $this->isBooleanConfigOptionSet('windowsUser_hidetitle', true) |
| 1776 |
&& $this->isBooleanConfigOptionSet('windowsUser_hidecarLicense', true) |
| 1777 |
&& $this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true) |
| 1778 |
&& $this->isBooleanConfigOptionSet('windowsUser_hideemployeeNumber', true) |
| 1779 |
&& $this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true) |
| 1780 |
&& $this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true) |
| 1781 |
&& $this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true) |
| 1782 |
&& $this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true) |
| 1783 |
&& $this->isBooleanConfigOptionSet('windowsUser_hideou', true) |
| 1784 |
&& $this->isBooleanConfigOptionSet('windowsUser_hideo', true) |
| 1785 |
&& $this->isBooleanConfigOptionSet('windowsUser_hidecompany', true) |
| 1786 |
&& $this->isBooleanConfigOptionSet('windowsUser_hidemanager', true); |
| 1787 |
return !$allHidden; |
| 1788 |
} |
| 1789 |
|
| 1790 |
/** |
| 1791 |
* {@inheritDoc} |
| 1792 |
*/ |
| 1793 |
public function process_attributes(): array { |
| 1794 |
$return = []; |
| 1795 |
$this->getAccountContainer()->replaceWildcardsInPOST($this->getWildcardTargetAttributeNames()); |
| 1796 |
// user name |
| 1797 |
$userPrincipalName = $_POST['userPrincipalName']; |
| 1798 |
if (!get_preg($userPrincipalName, 'username')) { |
| 1799 |
$return[] = $this->messages['userPrincipalName'][0]; |
| 1800 |
} |
| 1801 |
if (!empty($_POST['userPrincipalNameDomain'])) { |
| 1802 |
$userPrincipalName .= '@' . $_POST['userPrincipalNameDomain']; |
| 1803 |
} |
| 1804 |
$this->attributes['userPrincipalName'][0] = $userPrincipalName; |
| 1805 |
if ($this->getAccountContainer()->isNewAccount) { |
| 1806 |
$existingUsers = $this->getUserNames(); |
| 1807 |
if (array_key_exists($userPrincipalName, $existingUsers)) { |
| 1808 |
$return[] = $this->messages['userPrincipalName'][2]; |
| 1809 |
} |
| 1810 |
} |
| 1811 |
// cn |
| 1812 |
$this->attributes['cn'][0] = $_POST['cn']; |
| 1813 |
if (empty($this->attributes['cn'][0])) { |
| 1814 |
$cn = ''; |
| 1815 |
if (!empty($_POST['givenName'])) { |
| 1816 |
$cn = $_POST['givenName']; |
| 1817 |
} |
| 1818 |
if (!empty($_POST['sn'])) { |
| 1819 |
$cn .= ' ' . $_POST['sn']; |
| 1820 |
} |
| 1821 |
$this->attributes['cn'][0] = trim($cn); |
| 1822 |
} |
| 1823 |
if (!get_preg($this->attributes['cn'][0], 'cn')) { |
| 1824 |
$return[] = $this->messages['cn'][0]; |
| 1825 |
} |
| 1826 |
if ($this->getAccountContainer()->isNewAccount && !empty($this->attributes['cn'][0])) { |
| 1827 |
$existingCns = $this->getCns(); |
| 1828 |
if (array_key_exists($this->attributes['cn'][0], $existingCns)) { |
| 1829 |
$return[] = $this->messages['cn'][2]; |
| 1830 |
} |
| 1831 |
} |
| 1832 |
// sAMAccountName |
| 1833 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidesAMAccountName', true)) { |
| 1834 |
if ($this->getAccountContainer()->isNewAccount && !isset($this->attributes['sAMAccountName']) && empty($_POST['sAMAccountName'])) { |
| 1835 |
$this->attributes['sAMAccountName'][0] = $_POST['userPrincipalName']; |
| 1836 |
} |
| 1837 |
else { |
| 1838 |
$this->attributes['sAMAccountName'][0] = $_POST['sAMAccountName']; |
| 1839 |
} |
| 1840 |
if (!empty($this->attributes['sAMAccountName'][0]) && !get_preg($this->attributes['sAMAccountName'][0], 'username')) { |
| 1841 |
$return[] = $this->messages['sAMAccountName'][0]; |
| 1842 |
} |
| 1843 |
} |
| 1844 |
elseif ($this->getAccountContainer()->isNewAccount && !empty($_POST['userPrincipalName'])) { |
| 1845 |
// set sAMAccountName to username if attribute input field is not visible (W2012 requires this attribute) |
| 1846 |
$this->attributes['sAMAccountName'][0] = $_POST['userPrincipalName']; |
| 1847 |
} |
| 1848 |
// description |
| 1849 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedescription')) { |
| 1850 |
$this->attributes['description'][0] = $_POST['description']; |
| 1851 |
} |
| 1852 |
// display name |
| 1853 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 1854 |
$this->attributes['displayName'][0] = $_POST['displayName']; |
| 1855 |
if (!empty($this->attributes['displayName'][0]) && !get_preg($this->attributes['displayName'][0], 'realname')) { |
| 1856 |
$return[] = $this->messages['displayName'][0]; |
| 1857 |
} |
| 1858 |
if (empty($this->attributes['displayName'][0]) && !empty($this->attributes['cn'][0])) { |
| 1859 |
$this->attributes['displayName'][0] = $this->attributes['cn'][0]; |
| 1860 |
} |
| 1861 |
} |
| 1862 |
// first name |
| 1863 |
$this->attributes['givenName'][0] = $_POST['givenName']; |
| 1864 |
if (!empty($this->attributes['givenName'][0]) && !get_preg($_POST['givenName'], 'realname')) { |
| 1865 |
$return[] = $this->messages['givenName'][0]; |
| 1866 |
} |
| 1867 |
// initials |
| 1868 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideinitials')) { |
| 1869 |
$this->attributes['initials'][0] = $_POST['initials']; |
| 1870 |
} |
| 1871 |
// personal title |
| 1872 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle')) { |
| 1873 |
$this->processSimpleTextInput('personaltitle', $return, false, 'title'); |
| 1874 |
} |
| 1875 |
// location |
| 1876 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidel')) { |
| 1877 |
$this->attributes['l'][0] = $_POST['l']; |
| 1878 |
} |
| 1879 |
// email |
| 1880 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemail')) { |
| 1881 |
$this->attributes['mail'][0] = $_POST['mail']; |
| 1882 |
if (!empty($this->attributes['mail'][0]) && !get_preg($this->attributes['mail'][0], 'email')) { |
| 1883 |
$return[] = $this->messages['mail'][0]; |
| 1884 |
} |
| 1885 |
elseif (!empty($this->attributes['mail'][0]) && $this->getAccountContainer()->isNewAccount) { |
| 1886 |
$existingMailAccounts = searchLDAPByAttribute('mail', $this->attributes['mail'][0], 'user', ['mail'], ['user']); |
| 1887 |
if (!empty($existingMailAccounts)) { |
| 1888 |
$msg = $this->messages['mail'][2]; |
| 1889 |
$msg[] = [$this->attributes['mail'][0]]; |
| 1890 |
$return[] = $msg; |
| 1891 |
} |
| 1892 |
} |
| 1893 |
} |
| 1894 |
// email aliases |
| 1895 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMailbox')) { |
| 1896 |
$this->processMultiValueInputTextField('otherMailbox', $return, 'email'); |
| 1897 |
if (!empty($this->attributes['otherMailbox'][0]) && $this->getAccountContainer()->isNewAccount) { |
| 1898 |
foreach ($this->attributes['otherMailbox'] as $otherMailbox) { |
| 1899 |
$existingMailAccounts = searchLDAPByAttribute('otherMailbox', $otherMailbox, 'user', ['otherMailbox'], ['user']); |
| 1900 |
if (!empty($existingMailAccounts)) { |
| 1901 |
$msg = $this->messages['otherMailbox'][2]; |
| 1902 |
$msg[] = [$otherMailbox]; |
| 1903 |
$return[] = $msg; |
| 1904 |
} |
| 1905 |
} |
| 1906 |
} |
| 1907 |
} |
| 1908 |
// other telephones |
| 1909 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherTelephone')) { |
| 1910 |
$this->processMultiValueInputTextField('otherTelephone', $return, 'telephone'); |
| 1911 |
} |
| 1912 |
// fax number |
| 1913 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidefacsimileTelephoneNumber')) { |
| 1914 |
$this->attributes['facsimileTelephoneNumber'][0] = $_POST['facsimileTelephoneNumber']; |
| 1915 |
if (!get_preg($_POST['facsimileTelephoneNumber'], 'telephone')) { |
| 1916 |
$return[] = $this->messages['facsimileTelephoneNumber'][0]; |
| 1917 |
} |
| 1918 |
} |
| 1919 |
// office name |
| 1920 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName')) { |
| 1921 |
$this->attributes['physicalDeliveryOfficeName'][0] = $_POST['physicalDeliveryOfficeName']; |
| 1922 |
} |
| 1923 |
// postal code |
| 1924 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode')) { |
| 1925 |
$this->attributes['postalCode'][0] = $_POST['postalCode']; |
| 1926 |
if (!get_preg($_POST['postalCode'], 'postalCode')) { |
| 1927 |
$return[] = $this->messages['postalCode'][0]; |
| 1928 |
} |
| 1929 |
} |
| 1930 |
// post office box |
| 1931 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox')) { |
| 1932 |
$this->attributes['postOfficeBox'][0] = $_POST['postOfficeBox']; |
| 1933 |
} |
| 1934 |
// last name |
| 1935 |
$this->attributes['sn'][0] = $_POST['sn']; |
| 1936 |
if (!empty($this->attributes['sn'][0]) && !get_preg($_POST['sn'], 'realname')) { |
| 1937 |
$return[] = $this->messages['sn'][0]; |
| 1938 |
} |
| 1939 |
// state |
| 1940 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidest')) { |
| 1941 |
$this->attributes['st'][0] = $_POST['st']; |
| 1942 |
} |
| 1943 |
// street |
| 1944 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidestreetAddress')) { |
| 1945 |
$this->attributes['streetAddress'][0] = $_POST['streetAddress']; |
| 1946 |
} |
| 1947 |
// telephone |
| 1948 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetelephoneNumber')) { |
| 1949 |
$this->attributes['telephoneNumber'][0] = $_POST['telephoneNumber']; |
| 1950 |
if (!get_preg($_POST['telephoneNumber'], 'telephone')) { |
| 1951 |
$return[] = $this->messages['telephoneNumber'][0]; |
| 1952 |
} |
| 1953 |
} |
| 1954 |
// other websites |
| 1955 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideurl')) { |
| 1956 |
$this->processMultiValueInputTextField('url', $return); |
| 1957 |
} |
| 1958 |
// web site |
| 1959 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidewWWHomePage')) { |
| 1960 |
$this->attributes['wWWHomePage'][0] = $_POST['wWWHomePage']; |
| 1961 |
} |
| 1962 |
// password must be changed |
| 1963 |
if (isset($_POST['form_subpage_' . static::class . '_attributes_forcePasswordChange'])) { |
| 1964 |
$this->attributes['pwdLastSet'][0] = '0'; |
| 1965 |
} |
| 1966 |
elseif (isset($_POST['form_subpage_' . static::class . '_attributes_releasePasswordChange'])) { |
| 1967 |
if (isset($this->orig['pwdLastSet'][0]) && ($this->orig['pwdLastSet'][0] !== '0')) { |
| 1968 |
$this->attributes['pwdLastSet'][0] = $this->orig['pwdLastSet'][0]; |
| 1969 |
} |
| 1970 |
else { |
| 1971 |
$this->attributes['pwdLastSet'][0] = '-1'; |
| 1972 |
} |
| 1973 |
} |
| 1974 |
$this->pwdLastSet = null; |
| 1975 |
if (isset($this->attributes['unicodePwd'][0]) |
| 1976 |
&& (!isset($this->orig['unicodePwd'][0]) || ($this->orig['unicodePwd'][0] !== $this->attributes['unicodePwd'][0])) |
| 1977 |
&& ($this->attributes['pwdLastSet'][0] === '0')) { |
| 1978 |
// password changed and forced password change on the next login |
| 1979 |
// save pwdLastSet for postModifyActions |
| 1980 |
$this->pwdLastSet = '0'; |
| 1981 |
} |
| 1982 |
// deactivated |
| 1983 |
$deactivated = isset($_POST['deactivated']) && ($_POST['deactivated'] == 'on'); |
| 1984 |
windowsUser::setIsDeactivated($deactivated); |
| 1985 |
// no expire |
| 1986 |
$noExpire = isset($_POST['noExpire']) && ($_POST['noExpire'] == 'on'); |
| 1987 |
windowsUser::setIsNeverExpiring($this->attributes, $noExpire); |
| 1988 |
// smartcard required |
| 1989 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideRequireSmartcard')) { |
| 1990 |
$requireCard = isset($_POST['requireCard']) && ($_POST['requireCard'] == 'on'); |
| 1991 |
windowsUser::setIsSmartCardRequired($this->attributes, $requireCard); |
| 1992 |
} |
| 1993 |
// profile path |
| 1994 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath')) { |
| 1995 |
$this->attributes['profilePath'][0] = $_POST['profilePath']; |
| 1996 |
if (($this->attributes['profilePath'][0] != '') && !get_preg($this->attributes['profilePath'][0], 'UNC')) { |
| 1997 |
$return[] = $this->messages['profilePath'][0]; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
// logon script |
| 2001 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath')) { |
| 2002 |
$this->attributes['scriptPath'][0] = $_POST['scriptPath']; |
| 2003 |
if (($this->attributes['scriptPath'][0] != '') && (!get_preg($this->attributes['scriptPath'][0], 'logonscript'))) { |
| 2004 |
$return[] = $this->messages['scriptPath'][0]; |
| 2005 |
} |
| 2006 |
} |
| 2007 |
// home drive |
| 2008 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive')) { |
| 2009 |
$this->attributes['homeDrive'][0] = ($_POST['homeDrive'] === "-") ? '' : $_POST['homeDrive']; |
| 2010 |
} |
| 2011 |
// home directory |
| 2012 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory')) { |
| 2013 |
$this->attributes['homeDirectory'][0] = $_POST['homeDirectory']; |
| 2014 |
if (!empty($this->attributes['homeDrive'][0]) && !get_preg($this->attributes['homeDirectory'][0], 'UNC')) { |
| 2015 |
$return[] = $this->messages['homeDirectory'][0]; |
| 2016 |
} |
| 2017 |
} |
| 2018 |
// NIS name |
| 2019 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true)) { |
| 2020 |
if ($this->getAccountContainer()->isNewAccount && !isset($this->attributes['msSFU30Name']) && empty($_POST['msSFU30Name'])) { |
| 2021 |
$this->attributes['msSFU30Name'][0] = $_POST['userPrincipalName']; |
| 2022 |
} |
| 2023 |
else { |
| 2024 |
$this->attributes['msSFU30Name'][0] = $_POST['msSFU30Name']; |
| 2025 |
} |
| 2026 |
if (!empty($this->attributes['msSFU30Name'][0]) && !get_preg($this->attributes['msSFU30Name'][0], 'username')) { |
| 2027 |
$return[] = $this->messages['msSFU30Name'][0]; |
| 2028 |
} |
| 2029 |
} |
| 2030 |
// NIS domain |
| 2031 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true)) { |
| 2032 |
$this->attributes['msSFU30NisDomain'][0] = $_POST['msSFU30NisDomain']; |
| 2033 |
} |
| 2034 |
// title |
| 2035 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 2036 |
$this->attributes['title'][0] = $_POST['title']; |
| 2037 |
} |
| 2038 |
// room number |
| 2039 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true)) { |
| 2040 |
$this->processMultiValueInputTextField('roomnumber', $return); |
| 2041 |
} |
| 2042 |
// car license |
| 2043 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecarLicense', true)) { |
| 2044 |
$this->attributes['carLicense'][0] = $_POST['carLicense']; |
| 2045 |
} |
| 2046 |
// employee number |
| 2047 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeNumber', true)) { |
| 2048 |
$this->attributes['employeeNumber'][0] = $_POST['employeeNumber']; |
| 2049 |
} |
| 2050 |
// employee type |
| 2051 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 2052 |
$this->attributes['employeeType'][0] = $_POST['employeeType']; |
| 2053 |
} |
| 2054 |
// business category |
| 2055 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 2056 |
$this->processMultiValueInputTextField('businessCategory', $return, 'businessCategory'); |
| 2057 |
} |
| 2058 |
// department |
| 2059 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 2060 |
$this->attributes['department'][0] = $_POST['department']; |
| 2061 |
} |
| 2062 |
// department number |
| 2063 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 2064 |
$this->processMultiValueInputTextField('departmentNumber', $return); |
| 2065 |
} |
| 2066 |
// organizational unit |
| 2067 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 2068 |
$this->processMultiValueInputTextField('ou', $return); |
| 2069 |
} |
| 2070 |
// organisation |
| 2071 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 2072 |
$this->processMultiValueInputTextField('o', $return); |
| 2073 |
} |
| 2074 |
// Company |
| 2075 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecompany', true)) { |
| 2076 |
$this->attributes['company'][0] = $_POST['company']; |
| 2077 |
} |
| 2078 |
// Mobile |
| 2079 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemobile', true)) { |
| 2080 |
$this->attributes['mobile'][0] = $_POST['mobile']; |
| 2081 |
if (!get_preg($_POST['mobile'], 'telephone')) { |
| 2082 |
$return[] = $this->messages['mobile'][0]; |
| 2083 |
} |
| 2084 |
} |
| 2085 |
// Other mobiles |
| 2086 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMobile', true)) { |
| 2087 |
$this->processMultiValueInputTextField('otherMobile', $return, 'telephone'); |
| 2088 |
} |
| 2089 |
// Pager |
| 2090 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepager', true)) { |
| 2091 |
$this->attributes['pager'][0] = $_POST['pager']; |
| 2092 |
if (!get_preg($_POST['pager'], 'telephone')) { |
| 2093 |
$return[] = $this->messages['pager'][0]; |
| 2094 |
} |
| 2095 |
} |
| 2096 |
// Other pagers |
| 2097 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherPager', true)) { |
| 2098 |
$this->processMultiValueInputTextField('otherPager', $return, 'telephone'); |
| 2099 |
} |
| 2100 |
// Proxy-Addresses |
| 2101 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideproxyAddresses', true)) { |
| 2102 |
$this->processMultiValueInputTextField('proxyAddresses', $return); |
| 2103 |
} |
| 2104 |
// photo |
| 2105 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidejpegPhoto', true) |
| 2106 |
&& isset($_POST['delPhoto'])) { |
| 2107 |
unset($this->attributes['jpegPhoto']); |
| 2108 |
} |
| 2109 |
// thumbnail |
| 2110 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidethumbnailphoto', true) |
| 2111 |
&& isset($_POST['delthumbnailphoto'])) { |
| 2112 |
unset($this->attributes['thumbnailphoto']); |
| 2113 |
} |
| 2114 |
return $return; |
| 2115 |
} |
| 2116 |
|
| 2117 |
/** |
| 2118 |
* This function will create the meta HTML code to show a page to change account expiration. |
| 2119 |
* |
| 2120 |
* @return htmlElement meta HTML code |
| 2121 |
*/ |
| 2122 |
public function display_html_accountexpires(): htmlElement { |
| 2123 |
$return = new htmlResponsiveRow(); |
| 2124 |
$attr = 'accountexpires'; |
| 2125 |
$datetime = new DateTime('now', getTimeZone()); |
| 2126 |
$datetime->add(new DateInterval('P1Y')); |
| 2127 |
if (!empty($this->attributes[$attr][0]) && ($this->attributes[$attr][0] !== self::ACCOUNT_DOES_NOT_EXPIRE)) { |
| 2128 |
$datetime = windowsUser::getFileTime($this->attributes[$attr][0]); |
| 2129 |
} |
| 2130 |
$dateInput = new htmlResponsiveInputField(_('Account expiration date'), $attr, $datetime->format('Y-m-d'), 'accountexpires'); |
| 2131 |
$dateInput->showCalendar('Y-m-d'); |
| 2132 |
$return->add($dateInput); |
| 2133 |
|
| 2134 |
if ($this->getAccountContainer()->getAccountModule('shadowAccount') != null) { |
| 2135 |
$return->add(new htmlResponsiveInputCheckbox('syncShadow', false, _('Set also for Shadow'))); |
| 2136 |
} |
| 2137 |
if ($this->getAccountContainer()->getAccountModule('heimdalKerberos') != null) { |
| 2138 |
$return->add(new htmlResponsiveInputCheckbox('syncHeimdal', false, _('Set also for Kerberos'))); |
| 2139 |
} |
| 2140 |
if ($this->getAccountContainer()->getAccountModule('mitKerberos') != null) { |
| 2141 |
$return->add(new htmlResponsiveInputCheckbox('syncMIT', false, _('Set also for Kerberos'))); |
| 2142 |
} |
| 2143 |
if ($this->getAccountContainer()->getAccountModule('mitKerberosStructural') != null) { |
| 2144 |
$return->add(new htmlResponsiveInputCheckbox('syncMITStructural', false, _('Set also for Kerberos'))); |
| 2145 |
} |
| 2146 |
$return->addVerticalSpacer('2rem'); |
| 2147 |
$buttons = new htmlGroup(); |
| 2148 |
$buttons->addElement(new htmlAccountPageButton(static::class, 'attributes', 'change' . $attr, _('Change'))); |
| 2149 |
if (isset($this->attributes[$attr][0])) { |
| 2150 |
$buttons->addElement(new htmlSpacer('0.5rem', null)); |
| 2151 |
$buttons->addElement(new htmlAccountPageButton(static::class, 'attributes', 'del' . $attr, _('Remove'))); |
| 2152 |
} |
| 2153 |
$buttons->addElement(new htmlSpacer('0.5rem', null)); |
| 2154 |
$buttons->addElement(new htmlAccountPageButton(static::class, 'attributes', 'back' . $attr, _('Cancel'))); |
| 2155 |
$return->add($buttons, 12, 12, 12, 'text-center'); |
| 2156 |
return $return; |
| 2157 |
} |
| 2158 |
|
| 2159 |
/** |
| 2160 |
* Processes user input of the account expiration page. |
| 2161 |
* |
| 2162 |
* @return array<string|string[]>[] list of info/error messages |
| 2163 |
*/ |
| 2164 |
public function process_accountexpires(): array { |
| 2165 |
$return = []; |
| 2166 |
// find button name |
| 2167 |
$buttonName = ''; |
| 2168 |
$postKeys = array_keys($_POST); |
| 2169 |
for ($i = 0; $i < count($postKeys); $i++) { |
| 2170 |
if (str_contains($postKeys[$i], 'form_subpage_windowsUser_attributes_')) { |
| 2171 |
$buttonName = $postKeys[$i]; |
| 2172 |
} |
| 2173 |
} |
| 2174 |
if (($buttonName == '') || (str_contains($buttonName, '_back'))) { |
| 2175 |
return []; |
| 2176 |
} |
| 2177 |
$attr = 'accountexpires'; |
| 2178 |
// determine action |
| 2179 |
if (str_contains($buttonName, '_change')) { |
| 2180 |
$date = DateTime::createFromFormat('Y-m-d', $_POST['accountexpires'], new DateTimeZone('UTC')); |
| 2181 |
$year = (int) $date->format('Y'); |
| 2182 |
$month = (int) $date->format('m'); |
| 2183 |
$day = (int) $date->format('d'); |
| 2184 |
// set new time |
| 2185 |
$this->setExpirationDate($year, $month, $day); |
| 2186 |
// sync other modules |
| 2187 |
if (isset($_POST['syncShadow']) && ($_POST['syncShadow'] == 'on')) { |
| 2188 |
$this->getAccountContainer()->getAccountModule('shadowAccount')->setExpirationDate( |
| 2189 |
$year, $month, $day); |
| 2190 |
} |
| 2191 |
if (isset($_POST['syncHeimdal']) && ($_POST['syncHeimdal'] == 'on')) { |
| 2192 |
$this->getAccountContainer()->getAccountModule('heimdalKerberos')->setExpirationDate( |
| 2193 |
$year, $month, $day); |
| 2194 |
} |
| 2195 |
if (isset($_POST['syncMIT']) && ($_POST['syncMIT'] == 'on')) { |
| 2196 |
$this->getAccountContainer()->getAccountModule('mitKerberos')->setExpirationDate( |
| 2197 |
$year, $month, $day); |
| 2198 |
} |
| 2199 |
if (isset($_POST['syncMITStructural']) && ($_POST['syncMITStructural'] == 'on')) { |
| 2200 |
$this->getAccountContainer()->getAccountModule('mitKerberosStructural')->setExpirationDate( |
| 2201 |
$year, $month, $day); |
| 2202 |
} |
| 2203 |
} |
| 2204 |
elseif (str_contains($buttonName, '_del')) { |
| 2205 |
// remove attribute value |
| 2206 |
if (!isset($this->orig[$attr][0])) { |
| 2207 |
unset($this->attributes[$attr]); |
| 2208 |
} |
| 2209 |
else { |
| 2210 |
$this->attributes[$attr][0] = '0'; |
| 2211 |
} |
| 2212 |
// sync other modules |
| 2213 |
if (isset($_POST['syncShadow']) && ($_POST['syncShadow'] == 'on')) { |
| 2214 |
$this->getAccountContainer()->getAccountModule('shadowAccount')->setExpirationDate( |
| 2215 |
null, null, null); |
| 2216 |
} |
| 2217 |
if (isset($_POST['syncHeimdal']) && ($_POST['syncHeimdal'] == 'on')) { |
| 2218 |
$this->getAccountContainer()->getAccountModule('heimdalKerberos')->setExpirationDate( |
| 2219 |
null, null, null); |
| 2220 |
} |
| 2221 |
if (isset($_POST['syncMIT']) && ($_POST['syncMIT'] == 'on')) { |
| 2222 |
$this->getAccountContainer()->getAccountModule('mitKerberos')->setExpirationDate( |
| 2223 |
null, null, null); |
| 2224 |
} |
| 2225 |
if (isset($_POST['syncMITStructural']) && ($_POST['syncMITStructural'] == 'on')) { |
| 2226 |
$this->getAccountContainer()->getAccountModule('mitKerberosStructural')->setExpirationDate( |
| 2227 |
null, null, null); |
| 2228 |
} |
| 2229 |
} |
| 2230 |
return $return; |
| 2231 |
} |
| 2232 |
|
| 2233 |
/** |
| 2234 |
* Displays the group selection. |
| 2235 |
* |
| 2236 |
* @return htmlElement meta HTML code |
| 2237 |
*/ |
| 2238 |
public function display_html_group(): htmlElement { |
| 2239 |
$return = new htmlResponsiveRow(); |
| 2240 |
$return->add(new htmlSubTitle(_("Groups"))); |
| 2241 |
$groups = $this->findGroups(); |
| 2242 |
$groupDisplayContainsDn = $this->groupDisplayContainsDn(); |
| 2243 |
// sort by DN |
| 2244 |
if ($groupDisplayContainsDn) { |
| 2245 |
usort($groups, compareDN(...)); |
| 2246 |
} |
| 2247 |
|
| 2248 |
$selectedGroups = []; |
| 2249 |
// sort by DN |
| 2250 |
if ($groupDisplayContainsDn) { |
| 2251 |
usort($this->groupList, compareDN(...)); |
| 2252 |
} |
| 2253 |
for ($i = 0; $i < count($this->groupList); $i++) { |
| 2254 |
if (in_array($this->groupList[$i], $groups)) { |
| 2255 |
$groupDn = $this->groupList[$i]; |
| 2256 |
$groupCn = extractRDNValue($groupDn); |
| 2257 |
$displayName = $this->formatGroupName($groupCn, $groupDn); |
| 2258 |
$selectedGroups[$displayName] = $groupDn; |
| 2259 |
} |
| 2260 |
} |
| 2261 |
$availableGroups = []; |
| 2262 |
foreach ($groups as $dn) { |
| 2263 |
if (!in_array($dn, $this->groupList)) { |
| 2264 |
$groupCn = extractRDNValue($dn); |
| 2265 |
$displayName = $this->formatGroupName($groupCn, $dn); |
| 2266 |
$availableGroups[$displayName] = $dn; |
| 2267 |
} |
| 2268 |
} |
| 2269 |
|
| 2270 |
if (!$groupDisplayContainsDn) { |
| 2271 |
$selectedGroups = array_flip($selectedGroups); |
| 2272 |
natcasesort($selectedGroups); |
| 2273 |
$selectedGroups = array_flip($selectedGroups); |
| 2274 |
$availableGroups = array_flip($availableGroups); |
| 2275 |
natcasesort($availableGroups); |
| 2276 |
$availableGroups = array_flip($availableGroups); |
| 2277 |
} |
| 2278 |
|
| 2279 |
$this->addDoubleSelectionArea($return, _("Selected groups"), _("Available groups"), |
| 2280 |
$selectedGroups, [], $availableGroups, [], 'groups', $groupDisplayContainsDn, true); |
| 2281 |
|
| 2282 |
// sync options |
| 2283 |
$typeManager = new TypeManager(); |
| 2284 |
$syncTypes = $typeManager->getConfiguredTypesForScopes(['group', 'gon', 'user']); |
| 2285 |
$syncActive = false; |
| 2286 |
$syncGonActive = false; |
| 2287 |
$possibleGonSyncModules = ['groupOfNames', 'groupOfMembers', 'groupOfUniqueNames']; |
| 2288 |
foreach ($syncTypes as $syncType) { |
| 2289 |
$modules = $syncType->getModules(); |
| 2290 |
foreach ($possibleGonSyncModules as $possibleModule) { |
| 2291 |
if (in_array($possibleModule, $modules)) { |
| 2292 |
$syncGonActive = true; |
| 2293 |
break; |
| 2294 |
} |
| 2295 |
} |
| 2296 |
} |
| 2297 |
if (in_array('posixAccount', $this->getAccountContainer()->get_type()->getModules())) { |
| 2298 |
$syncActive = true; |
| 2299 |
} |
| 2300 |
$syncActive = $syncActive && !$this->isBooleanConfigOptionSet('windowsUser_syncGroups'); |
| 2301 |
if ($syncActive) { |
| 2302 |
$return->add(new htmlSubTitle(_('Sync groups'))); |
| 2303 |
$return->add(new htmlResponsiveInputCheckbox('syncDeleteGroups', true, _('Delete non-matching entries'))); |
| 2304 |
$return->addVerticalSpacer('2rem'); |
| 2305 |
$syncButtons = new htmlGroup(); |
| 2306 |
$u2wButton = new htmlAccountPageButton(static::class, 'group', 'syncU2W', _('Sync Unix to Windows')); |
| 2307 |
$syncButtons->addElement($u2wButton); |
| 2308 |
$syncButtons->addElement(new htmlSpacer('2rem', null)); |
| 2309 |
if ($syncGonActive) { |
| 2310 |
$g2wButton = new htmlAccountPageButton(static::class, 'group', 'syncG2W', _('Sync group of names to Windows')); |
| 2311 |
$syncButtons->addElement($g2wButton); |
| 2312 |
$syncButtons->addElement(new htmlSpacer('2rem', null)); |
| 2313 |
} |
| 2314 |
$return->add($syncButtons, 12, 12, 12, 'text-center'); |
| 2315 |
$return->addVerticalSpacer('2rem'); |
| 2316 |
} |
| 2317 |
|
| 2318 |
$backButton = new htmlAccountPageButton(static::class, 'attributes', 'back', _('Back')); |
| 2319 |
$return->add($backButton); |
| 2320 |
return $return; |
| 2321 |
} |
| 2322 |
|
| 2323 |
/** |
| 2324 |
* Processes user input of the group selection page. |
| 2325 |
* It checks if all input values are correct and updates the associated LDAP attributes. |
| 2326 |
* |
| 2327 |
* @return array<string|string[]>[] list of info/error messages |
| 2328 |
*/ |
| 2329 |
public function process_group(): array { |
| 2330 |
if (isset($_POST['groups_2']) && isset($_POST['groups_left'])) { // Add groups to list |
| 2331 |
// add new group |
| 2332 |
$this->groupList = @array_merge($this->groupList, $_POST['groups_2']); |
| 2333 |
} |
| 2334 |
elseif (isset($_POST['groups_1']) && isset($_POST['groups_right'])) { // remove groups from list |
| 2335 |
$this->groupList = array_delete($_POST['groups_1'], $this->groupList); |
| 2336 |
} |
| 2337 |
// sync Unix to Windows |
| 2338 |
if (isset($_POST['form_subpage_windowsUser_group_syncU2W'])) { |
| 2339 |
$this->manualSyncUnixToWindows(); |
| 2340 |
} |
| 2341 |
// sync group of names to Windows |
| 2342 |
if (isset($_POST['form_subpage_windowsUser_group_syncG2W'])) { |
| 2343 |
$this->manualSyncGonToWindows(); |
| 2344 |
} |
| 2345 |
return []; |
| 2346 |
} |
| 2347 |
|
| 2348 |
/** |
| 2349 |
* Syncs the Unix groups to Windows. |
| 2350 |
*/ |
| 2351 |
private function manualSyncUnixToWindows(): void { |
| 2352 |
$windowsGroups = $this->getGroupList(); |
| 2353 |
$unixGroups = $this->getAccountContainer()->getAccountModule('posixAccount')->getGroups(); |
| 2354 |
$allWindowsGroups = searchLDAPByAttribute('cn', '*', 'group', ['cn'], ['group']); |
| 2355 |
$dnToCn = []; |
| 2356 |
foreach ($allWindowsGroups as $windowsGroup) { |
| 2357 |
$dnToCn[$windowsGroup['dn']] = $windowsGroup['cn'][0]; |
| 2358 |
} |
| 2359 |
$cnToDn = array_flip($dnToCn); |
| 2360 |
$currentGroupNames = []; |
| 2361 |
foreach ($windowsGroups as $windowsGroup) { |
| 2362 |
$currentGroupNames[] = $dnToCn[$windowsGroup]; |
| 2363 |
} |
| 2364 |
$deleteNonMatching = isset($_POST['syncDeleteGroups']) && ($_POST['syncDeleteGroups'] == 'on'); |
| 2365 |
$namesToIgnore = []; |
| 2366 |
if (!empty($this->moduleSettings['windowsUser_syncGroupsExclusions'])) { |
| 2367 |
$namesToIgnore = $this->moduleSettings['windowsUser_syncGroupsExclusions']; |
| 2368 |
array_map(trim(...), $namesToIgnore); |
| 2369 |
} |
| 2370 |
foreach ($unixGroups as $unixGroup) { |
| 2371 |
if (in_array($unixGroup, $namesToIgnore)) { |
| 2372 |
continue; |
| 2373 |
} |
| 2374 |
if (!in_array($unixGroup, $currentGroupNames) && isset($cnToDn[$unixGroup])) { |
| 2375 |
$windowsGroups[] = $cnToDn[$unixGroup]; |
| 2376 |
} |
| 2377 |
} |
| 2378 |
if ($deleteNonMatching) { |
| 2379 |
foreach ($currentGroupNames as $currentGroupName) { |
| 2380 |
if (in_array($currentGroupName, $namesToIgnore)) { |
| 2381 |
continue; |
| 2382 |
} |
| 2383 |
if (!in_array($currentGroupName, $unixGroups)) { |
| 2384 |
foreach ($windowsGroups as $windowsGroup) { |
| 2385 |
if ($dnToCn[$windowsGroup] == $currentGroupName) { |
| 2386 |
$windowsGroups = array_delete([$windowsGroup], $windowsGroups); |
| 2387 |
break; |
| 2388 |
} |
| 2389 |
} |
| 2390 |
} |
| 2391 |
} |
| 2392 |
} |
| 2393 |
$this->groupList = $windowsGroups; |
| 2394 |
} |
| 2395 |
|
| 2396 |
/** |
| 2397 |
* Syncs the group of names to Windows. |
| 2398 |
*/ |
| 2399 |
private function manualSyncGonToWindows(): void { |
| 2400 |
$windowsGroups = $this->getGroupList(); |
| 2401 |
$gonGroupDns = $this->getAccountContainer()->getAccountModule('posixAccount')->getGroupOfNames(); |
| 2402 |
$allGons = $this->getAccountContainer()->getAccountModule('posixAccount')->findGroupOfNames(); |
| 2403 |
$gonGroups = []; |
| 2404 |
foreach ($gonGroupDns as $gonGroupDn) { |
| 2405 |
$gonGroups[] = $this->getAccountContainer()->getAccountModule('posixAccount')->getGonName($gonGroupDn, $allGons); |
| 2406 |
} |
| 2407 |
$allWindowsGroups = searchLDAPByAttribute('cn', '*', 'group', ['cn'], ['group']); |
| 2408 |
$dnToCn = []; |
| 2409 |
foreach ($allWindowsGroups as $windowsGroup) { |
| 2410 |
$dnToCn[$windowsGroup['dn']] = $windowsGroup['cn'][0]; |
| 2411 |
} |
| 2412 |
$cnToDn = array_flip($dnToCn); |
| 2413 |
$currentGroupNames = []; |
| 2414 |
foreach ($windowsGroups as $windowsGroup) { |
| 2415 |
$currentGroupNames[] = $dnToCn[$windowsGroup]; |
| 2416 |
} |
| 2417 |
$deleteNonMatching = isset($_POST['syncDeleteGroups']) && ($_POST['syncDeleteGroups'] == 'on'); |
| 2418 |
$namesToIgnore = []; |
| 2419 |
if (!empty($this->moduleSettings['windowsUser_syncGroupsExclusions'])) { |
| 2420 |
$namesToIgnore = $this->moduleSettings['windowsUser_syncGroupsExclusions']; |
| 2421 |
array_map(trim(...), $namesToIgnore); |
| 2422 |
} |
| 2423 |
foreach ($gonGroups as $gonGroup) { |
| 2424 |
if (in_array($gonGroup, $namesToIgnore)) { |
| 2425 |
continue; |
| 2426 |
} |
| 2427 |
if (!in_array($gonGroup, $currentGroupNames) && isset($cnToDn[$gonGroup])) { |
| 2428 |
$windowsGroups[] = $cnToDn[$gonGroup]; |
| 2429 |
} |
| 2430 |
} |
| 2431 |
if ($deleteNonMatching) { |
| 2432 |
foreach ($currentGroupNames as $currentGroupName) { |
| 2433 |
if (in_array($currentGroupName, $namesToIgnore)) { |
| 2434 |
continue; |
| 2435 |
} |
| 2436 |
if (!in_array($currentGroupName, $gonGroups)) { |
| 2437 |
foreach ($windowsGroups as $windowsGroup) { |
| 2438 |
if ($dnToCn[$windowsGroup] == $currentGroupName) { |
| 2439 |
$windowsGroups = array_delete([$windowsGroup], $windowsGroups); |
| 2440 |
break; |
| 2441 |
} |
| 2442 |
} |
| 2443 |
} |
| 2444 |
} |
| 2445 |
} |
| 2446 |
$this->groupList = $windowsGroups; |
| 2447 |
} |
| 2448 |
|
| 2449 |
/** |
| 2450 |
* Displays the photo upload page. |
| 2451 |
* |
| 2452 |
* @return htmlElement meta HTML code |
| 2453 |
*/ |
| 2454 |
public function display_html_photo(): htmlElement { |
| 2455 |
$container = new htmlResponsiveRow(); |
| 2456 |
if (empty($this->attributes['jpegPhoto'][0])) { |
| 2457 |
$container->add(new htmlSubTitle(_('Upload image'))); |
| 2458 |
$label = _('Photo file'); |
| 2459 |
$container->add(new htmlResponsiveInputFileUpload('photoFile', $label, 'photoUpload')); |
| 2460 |
$container->addVerticalSpacer('0.5rem'); |
| 2461 |
$container->addLabel(new htmlOutputText(' ', false)); |
| 2462 |
$container->addField(new htmlAccountPageButton(static::class, 'photo', 'upload', _('Upload'))); |
| 2463 |
$container->addVerticalSpacer('1rem'); |
| 2464 |
$webcamContent = new htmlResponsiveRow(); |
| 2465 |
$webcamContent->add(new htmlSubTitle(_('Use webcam'))); |
| 2466 |
$errorMessage = new htmlStatusMessage('ERROR', ''); |
| 2467 |
$errorMessage->setCSSClasses(['hidden', 'lam-webcam-message']); |
| 2468 |
$webcamContent->add($errorMessage); |
| 2469 |
$captureButton = new htmlButton('lam-webcam-capture', _('Start capture')); |
| 2470 |
$captureButton->setOnClick('window.lam.tools.webcam.capture(event);'); |
| 2471 |
$webcamContent->add($captureButton, 12, 12, 12, 'text-center'); |
| 2472 |
$video = new htmlVideo('lam-webcam-video'); |
| 2473 |
$video->setCSSClasses(['hidden']); |
| 2474 |
$webcamContent->add($video, 12, 12, 12, 'text-center'); |
| 2475 |
$webcamContent->addVerticalSpacer('0.5rem'); |
| 2476 |
$webcamUploadButton = new htmlButton('uploadWebcam', _('Upload')); |
| 2477 |
$webcamUploadButton->setCSSClasses(['btn-lam-webcam-upload', 'hidden']); |
| 2478 |
$webcamUploadButton->setOnClick('window.lam.tools.webcam.upload();'); |
| 2479 |
$webcamContent->add($webcamUploadButton, 12, 12, 12, 'text-center'); |
| 2480 |
$canvas = new htmlCanvas('lam-webcam-canvas'); |
| 2481 |
$canvas->setCSSClasses(['hidden']); |
| 2482 |
$webcamContent->add($canvas); |
| 2483 |
$webcamDiv = new htmlDiv('lam_webcam_div', $webcamContent, ['hidden']); |
| 2484 |
$container->add($webcamDiv); |
| 2485 |
$container->addVerticalSpacer('1rem'); |
| 2486 |
$container->add(new htmlAccountPageButton(static::class, 'attributes', 'back', _('Back'))); |
| 2487 |
} |
| 2488 |
else { |
| 2489 |
$container->add(new htmlSubTitle(_('Crop image'))); |
| 2490 |
$tempFilesManager = new LamTemporaryFilesManager(); |
| 2491 |
$jpegFileName = $tempFilesManager->registerTemporaryFile('.jpg'); |
| 2492 |
$handle = $tempFilesManager->openTemporaryFileForWrite($jpegFileName); |
| 2493 |
fwrite($handle, $this->attributes['jpegPhoto'][0]); |
| 2494 |
fclose($handle); |
| 2495 |
$photoFile = $tempFilesManager->getResourceLink($jpegFileName); |
| 2496 |
$img = new htmlImage($photoFile); |
| 2497 |
$img->setCSSClasses(['photo']); |
| 2498 |
$img->enableCropping(); |
| 2499 |
$container->add($img); |
| 2500 |
$container->addVerticalSpacer('2rem'); |
| 2501 |
$container->add(new htmlAccountPageButton(static::class, 'attributes', 'crop', _('Done'))); |
| 2502 |
} |
| 2503 |
return $container; |
| 2504 |
} |
| 2505 |
|
| 2506 |
/** |
| 2507 |
* Sets a new photo. |
| 2508 |
* |
| 2509 |
* @return array<string|string[]>[] error messages |
| 2510 |
*/ |
| 2511 |
public function process_photo(): array { |
| 2512 |
if (isset($_POST['form_subpage_' . static::class . '_attributes_back'])) { |
| 2513 |
return []; |
| 2514 |
} |
| 2515 |
if (isset($_POST['form_subpage_' . static::class . '_photo_upload']) || isset($_POST['webcamData'])) { |
| 2516 |
$maxSize = empty($this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]) ? 0 : intval($this->moduleSettings['windowsUser_jpegPhoto_maxSize'][0]); |
| 2517 |
return $this->uploadPhoto('jpegPhoto', $maxSize); |
| 2518 |
} |
| 2519 |
$messages = []; |
| 2520 |
if (isset($_POST['form_subpage_' . static::class . '_attributes_crop'])) { |
| 2521 |
try { |
| 2522 |
include_once __DIR__ . '/../imageutils.inc'; |
| 2523 |
$imageManipulator = ImageManipulationFactory::getImageManipulator($this->attributes['jpegPhoto'][0]); |
| 2524 |
$scaleFactor = $imageManipulator->getWidth() / intval($_POST['croppingDataWidth']); |
| 2525 |
$imageManipulator->crop( |
| 2526 |
(int) round(intval($_POST['croppingDataX']) * $scaleFactor), |
| 2527 |
(int) round(intval($_POST['croppingDataY']) * $scaleFactor), |
| 2528 |
(int) round($_POST['croppingDataSelectionWidth'] * $scaleFactor), |
| 2529 |
(int) round($_POST['croppingDataSelectionHeight'] * $scaleFactor) |
| 2530 |
); |
| 2531 |
// resize if maximum values specified |
| 2532 |
if (!empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) || !empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0])) { |
| 2533 |
$maxWidth = empty($this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]) ? $imageManipulator->getWidth() : $this->moduleSettings['windowsUser_jpegPhoto_maxWidth'][0]; |
| 2534 |
$maxHeight = empty($this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]) ? $imageManipulator->getHeight() : $this->moduleSettings['windowsUser_jpegPhoto_maxHeight'][0]; |
| 2535 |
$imageManipulator->thumbnail($maxWidth, $maxHeight); |
| 2536 |
} |
| 2537 |
$this->attributes['jpegPhoto'][0] = $imageManipulator->getImageData(); |
| 2538 |
} |
| 2539 |
catch (Exception $e) { |
| 2540 |
$msg = $this->messages['file'][2]; |
| 2541 |
$msg[] = htmlspecialchars($e->getMessage()); |
| 2542 |
$messages[] = $msg; |
| 2543 |
} |
| 2544 |
} |
| 2545 |
return $messages; |
| 2546 |
} |
| 2547 |
|
| 2548 |
/** |
| 2549 |
* Displays the thumbnail upload page. |
| 2550 |
* |
| 2551 |
* @return htmlElement meta HTML code |
| 2552 |
*/ |
| 2553 |
public function display_html_thumbnailphoto(): htmlElement { |
| 2554 |
$container = new htmlResponsiveRow(); |
| 2555 |
if (empty($this->attributes['thumbnailphoto'][0])) { |
| 2556 |
$container->add(new htmlSubTitle(_('Upload image'))); |
| 2557 |
$label = _('Thumbnail file'); |
| 2558 |
$container->add(new htmlResponsiveInputFileUpload('photoFile', $label, 'thumbnailphotoUpload')); |
| 2559 |
$container->addVerticalSpacer('0.5rem'); |
| 2560 |
$container->addLabel(new htmlOutputText(' ', false)); |
| 2561 |
$container->addField(new htmlAccountPageButton(static::class, 'thumbnailphoto', 'upload', _('Upload'))); |
| 2562 |
$container->addVerticalSpacer('1rem'); |
| 2563 |
$webcamContent = new htmlResponsiveRow(); |
| 2564 |
$webcamContent->add(new htmlSubTitle(_('Use webcam'))); |
| 2565 |
$errorMessage = new htmlStatusMessage('ERROR', ''); |
| 2566 |
$errorMessage->setCSSClasses(['hidden', 'lam-webcam-message']); |
| 2567 |
$webcamContent->add($errorMessage); |
| 2568 |
$captureButton = new htmlButton('lam-webcam-capture', _('Start capture')); |
| 2569 |
$captureButton->setOnClick('window.lam.tools.webcam.capture(event);'); |
| 2570 |
$webcamContent->add($captureButton, 12, 12, 12, 'text-center'); |
| 2571 |
$video = new htmlVideo('lam-webcam-video'); |
| 2572 |
$video->setCSSClasses(['hidden']); |
| 2573 |
$webcamContent->add($video, 12, 12, 12, 'text-center'); |
| 2574 |
$webcamContent->addVerticalSpacer('0.5rem'); |
| 2575 |
$webcamUploadButton = new htmlButton('uploadWebcam', _('Upload')); |
| 2576 |
$webcamUploadButton->setCSSClasses(['btn-lam-webcam-upload', 'hidden']); |
| 2577 |
$webcamUploadButton->setOnClick('window.lam.tools.webcam.upload();'); |
| 2578 |
$webcamContent->add($webcamUploadButton, 12, 12, 12, 'text-center'); |
| 2579 |
$canvas = new htmlCanvas('lam-webcam-canvas'); |
| 2580 |
$canvas->setCSSClasses(['hidden']); |
| 2581 |
$webcamContent->add($canvas); |
| 2582 |
$webcamDiv = new htmlDiv('lam_webcam_div', $webcamContent, ['hidden']); |
| 2583 |
$container->add($webcamDiv); |
| 2584 |
$container->addVerticalSpacer('1rem'); |
| 2585 |
$container->add(new htmlAccountPageButton(static::class, 'attributes', 'back', _('Back'))); |
| 2586 |
} |
| 2587 |
else { |
| 2588 |
$container->add(new htmlSubTitle(_('Crop image'))); |
| 2589 |
$tempFilesManager = new LamTemporaryFilesManager(); |
| 2590 |
$jpegFileName = $tempFilesManager->registerTemporaryFile('.jpg'); |
| 2591 |
$handle = $tempFilesManager->openTemporaryFileForWrite($jpegFileName); |
| 2592 |
fwrite($handle, $this->attributes['thumbnailphoto'][0]); |
| 2593 |
fclose($handle); |
| 2594 |
$photoFile = $tempFilesManager->getResourceLink($jpegFileName); |
| 2595 |
$img = new htmlImage($photoFile); |
| 2596 |
$img->setCSSClasses(['photo']); |
| 2597 |
$img->enableCropping(); |
| 2598 |
$container->add($img); |
| 2599 |
$container->addVerticalSpacer('2rem'); |
| 2600 |
$container->add(new htmlAccountPageButton(static::class, 'attributes', 'crop', _('Done'))); |
| 2601 |
} |
| 2602 |
return $container; |
| 2603 |
} |
| 2604 |
|
| 2605 |
/** |
| 2606 |
* Sets a new photo. |
| 2607 |
* |
| 2608 |
* @return array<string|string[]>[] error messages |
| 2609 |
*/ |
| 2610 |
public function process_thumbnailphoto(): array { |
| 2611 |
if (isset($_POST['form_subpage_' . static::class . '_attributes_back'])) { |
| 2612 |
return []; |
| 2613 |
} |
| 2614 |
if (isset($_POST['form_subpage_' . static::class . '_thumbnailphoto_upload']) || isset($_POST['webcamData'])) { |
| 2615 |
$maxSize = empty($this->moduleSettings['windowsUser_thumbnailphoto_maxSize'][0]) ? 0 : intval($this->moduleSettings['windowsUser_thumbnailphoto_maxSize'][0]); |
| 2616 |
return $this->uploadPhoto('thumbnailphoto', $maxSize); |
| 2617 |
} |
| 2618 |
$messages = []; |
| 2619 |
if (isset($_POST['form_subpage_' . static::class . '_attributes_crop'])) { |
| 2620 |
try { |
| 2621 |
include_once __DIR__ . '/../imageutils.inc'; |
| 2622 |
$imageManipulator = ImageManipulationFactory::getImageManipulator($this->attributes['thumbnailphoto'][0]); |
| 2623 |
$scaleFactor = $imageManipulator->getWidth() / intval($_POST['croppingDataWidth']); |
| 2624 |
$imageManipulator->crop( |
| 2625 |
(int) round(intval($_POST['croppingDataX']) * $scaleFactor), |
| 2626 |
(int) round(intval($_POST['croppingDataY']) * $scaleFactor), |
| 2627 |
(int) round($_POST['croppingDataSelectionWidth'] * $scaleFactor), |
| 2628 |
(int) round($_POST['croppingDataSelectionHeight'] * $scaleFactor) |
| 2629 |
); |
| 2630 |
// resize if maximum values specified |
| 2631 |
if (!empty($this->moduleSettings['windowsUser_thumbnailphoto_maxWidth'][0]) || !empty($this->moduleSettings['windowsUser_thumbnailphoto_maxHeight'][0])) { |
| 2632 |
$maxWidth = empty($this->moduleSettings['windowsUser_thumbnailphoto_maxWidth'][0]) ? $imageManipulator->getWidth() : $this->moduleSettings['windowsUser_thumbnailphoto_maxWidth'][0]; |
| 2633 |
$maxHeight = empty($this->moduleSettings['windowsUser_thumbnailphoto_maxHeight'][0]) ? $imageManipulator->getHeight() : $this->moduleSettings['windowsUser_thumbnailphoto_maxHeight'][0]; |
| 2634 |
$imageManipulator->thumbnail($maxWidth, $maxHeight); |
| 2635 |
} |
| 2636 |
$this->attributes['thumbnailphoto'][0] = $imageManipulator->getImageData(); |
| 2637 |
} |
| 2638 |
catch (Exception $e) { |
| 2639 |
$msg = $this->messages['file'][2]; |
| 2640 |
$msg[] = htmlspecialchars($e->getMessage()); |
| 2641 |
$messages[] = $msg; |
| 2642 |
} |
| 2643 |
} |
| 2644 |
return $messages; |
| 2645 |
} |
| 2646 |
|
| 2647 |
/** |
| 2648 |
* Uploads the photo/thumbnail file. |
| 2649 |
* |
| 2650 |
* @param string $attributeName attribute name |
| 2651 |
* @param int $maxSize maximum file size |
| 2652 |
* @return array<string|string[]>[] error messages if any |
| 2653 |
*/ |
| 2654 |
private function uploadPhoto(string $attributeName, int $maxSize): array { |
| 2655 |
$messages = []; |
| 2656 |
if ((empty($_FILES['photoFile']) || ($_FILES['photoFile']['size'] <= 0)) && empty($_POST['webcamData'])) { |
| 2657 |
$messages[] = $this->messages['file'][0]; |
| 2658 |
return $messages; |
| 2659 |
} |
| 2660 |
if (!empty($_FILES['photoFile']['tmp_name'])) { |
| 2661 |
$handle = fopen($_FILES['photoFile']['tmp_name'], "r"); |
| 2662 |
$data = fread($handle, 100000000); |
| 2663 |
fclose($handle); |
| 2664 |
if (($maxSize > 0) && (strlen($data) > (1024 * $maxSize))) { |
| 2665 |
$errMsg = $this->messages['file'][3]; |
| 2666 |
$errMsg[] = null; |
| 2667 |
$errMsg[] = [$maxSize]; |
| 2668 |
return [$errMsg]; |
| 2669 |
} |
| 2670 |
} |
| 2671 |
elseif (isset($_POST['webcamData'])) { |
| 2672 |
$data = $_POST['webcamData']; |
| 2673 |
$data = str_replace('data:image/png;base64,', '', $data); |
| 2674 |
$data = base64_decode($data); |
| 2675 |
} |
| 2676 |
else { |
| 2677 |
return []; |
| 2678 |
} |
| 2679 |
// convert to JPG |
| 2680 |
try { |
| 2681 |
include_once __DIR__ . '/../imageutils.inc'; |
| 2682 |
$imageManipulator = ImageManipulationFactory::getImageManipulator($data); |
| 2683 |
$imageManipulator->convertToJpeg(); |
| 2684 |
$data = $imageManipulator->getImageData(); |
| 2685 |
} |
| 2686 |
catch (Exception $e) { |
| 2687 |
$msg = $this->messages['file'][2]; |
| 2688 |
$msg[] = htmlspecialchars($e->getMessage()); |
| 2689 |
$messages[] = $msg; |
| 2690 |
return $messages; |
| 2691 |
} |
| 2692 |
$this->attributes[$attributeName][0] = $data; |
| 2693 |
return $messages; |
| 2694 |
} |
| 2695 |
|
| 2696 |
/** |
| 2697 |
* This function will create the meta HTML code to show a page to change the manager attribute. |
| 2698 |
* |
| 2699 |
* @return htmlElement HTML meta data |
| 2700 |
*/ |
| 2701 |
public function display_html_manager(): htmlElement { |
| 2702 |
$return = new htmlResponsiveRow(); |
| 2703 |
if (!isset($this->attributes['manager'])) { |
| 2704 |
$this->attributes['manager'] = []; |
| 2705 |
} |
| 2706 |
// show list of possible new managers |
| 2707 |
$options = []; |
| 2708 |
$filter = get_ldap_filter('user'); |
| 2709 |
$entries = searchLDAPByFilter('(|' . $filter . '(objectclass=organizationalRole))', ['dn'], ['user']); |
| 2710 |
for ($i = 0; $i < count($entries); $i++) { |
| 2711 |
$entries[$i] = $entries[$i]['dn']; |
| 2712 |
} |
| 2713 |
// sort by DN |
| 2714 |
usort($entries, compareDN(...)); |
| 2715 |
for ($i = 0; $i < count($entries); $i++) { |
| 2716 |
$options[getAbstractDN($entries[$i])] = $entries[$i]; |
| 2717 |
} |
| 2718 |
$selectedManager = []; |
| 2719 |
if (!empty($this->attributes['manager'][0])) { |
| 2720 |
$selectedManager[] = $this->attributes['manager'][0]; |
| 2721 |
} |
| 2722 |
$managerSelect = new htmlSelect('manager', $options, $selectedManager); |
| 2723 |
$managerSelect->setHasDescriptiveElements(true); |
| 2724 |
$managerSelect->setRightToLeftTextDirection(true); |
| 2725 |
$managerSelect->setSortElements(false); |
| 2726 |
$managerSelect->setTransformSingleSelect(false); |
| 2727 |
$return->add($managerSelect); |
| 2728 |
$filterGroup = new htmlGroup(); |
| 2729 |
$filterGroup->addElement(new htmlOutputText(_('Filter'))); |
| 2730 |
$filterInput = new htmlInputField('filter'); |
| 2731 |
$filterInput->filterSelectBox('manager'); |
| 2732 |
$filterInput->setCSSClasses(['max-width-10']); |
| 2733 |
$filterGroup->addElement($filterInput); |
| 2734 |
$filterGroup->addElement(new htmlHelpLink('filter')); |
| 2735 |
$return->add($filterGroup); |
| 2736 |
$return->addVerticalSpacer('2rem'); |
| 2737 |
$buttonTable = new htmlGroup(); |
| 2738 |
$buttonTable->addElement(new htmlAccountPageButton(static::class, 'attributes', 'setManager', _('Change'))); |
| 2739 |
$buttonTable->addElement(new htmlSpacer('0.5rem', null)); |
| 2740 |
$buttonTable->addElement(new htmlAccountPageButton(static::class, 'attributes', 'removeManager', _('Remove'))); |
| 2741 |
$buttonTable->addElement(new htmlSpacer('2rem', null)); |
| 2742 |
$buttonTable->addElement(new htmlAccountPageButton(static::class, 'attributes', 'cancelManager', _('Cancel'))); |
| 2743 |
$return->add($buttonTable); |
| 2744 |
return $return; |
| 2745 |
} |
| 2746 |
|
| 2747 |
/** |
| 2748 |
* Processes user input of the manager page. |
| 2749 |
* It checks if all input values are correct and updates the associated LDAP attributes. |
| 2750 |
* |
| 2751 |
* @return array<string|string[]>[] list of info/error messages |
| 2752 |
*/ |
| 2753 |
public function process_manager(): array { |
| 2754 |
$return = []; |
| 2755 |
if (isset($_POST['form_subpage_' . static::class . '_attributes_removeManager'])) { |
| 2756 |
if (!empty($this->attributes['manager'])) { |
| 2757 |
unset($this->attributes['manager']); |
| 2758 |
} |
| 2759 |
} |
| 2760 |
elseif (isset($_POST['form_subpage_' . static::class . '_attributes_setManager']) && isset($_POST['manager'])) { |
| 2761 |
$this->attributes['manager'][0] = $_POST['manager']; |
| 2762 |
} |
| 2763 |
return $return; |
| 2764 |
} |
| 2765 |
|
| 2766 |
/** |
| 2767 |
* This function will create the HTML page to edit the allowed workstations. |
| 2768 |
* |
| 2769 |
* @return htmlElement meta HTML code |
| 2770 |
*/ |
| 2771 |
public function display_html_userWorkstations(): htmlElement { |
| 2772 |
$return = new htmlResponsiveRow(); |
| 2773 |
if ($this->get_scope() == 'user') { |
| 2774 |
// Get list of all hosts. |
| 2775 |
$userWorkstations = []; |
| 2776 |
$availableUserWorkstations = []; |
| 2777 |
|
| 2778 |
$result = $this->getHostList(); |
| 2779 |
foreach ($result as $host) { |
| 2780 |
$availableUserWorkstations[] = str_replace("$", '', $host); |
| 2781 |
} |
| 2782 |
sort($availableUserWorkstations, SORT_STRING); |
| 2783 |
if (isset($this->attributes['userWorkstations'][0])) { |
| 2784 |
$wsAttr = str_replace(' ', '', $this->attributes['userWorkstations'][0]); |
| 2785 |
$userWorkstations = explode(',', $wsAttr); |
| 2786 |
} |
| 2787 |
$availableUserWorkstations = array_delete($userWorkstations, $availableUserWorkstations); |
| 2788 |
|
| 2789 |
$return->add(new htmlSubTitle(_("Allowed workstations"))); |
| 2790 |
|
| 2791 |
$userWorkstationsOptions = []; |
| 2792 |
foreach ($userWorkstations as $userWorkstation) { |
| 2793 |
$userWorkstationsOptions[$userWorkstation] = $userWorkstation; |
| 2794 |
} |
| 2795 |
$availableUserWorkstationsOptions = []; |
| 2796 |
foreach ($availableUserWorkstations as $availableUserWorkstation) { |
| 2797 |
$availableUserWorkstationsOptions[$availableUserWorkstation] = $availableUserWorkstation; |
| 2798 |
} |
| 2799 |
$this->addDoubleSelectionArea($return, _("Allowed workstations"), _("Available workstations"), $userWorkstationsOptions, [], $availableUserWorkstationsOptions, [], 'workstations', false, true); |
| 2800 |
|
| 2801 |
$return->addVerticalSpacer('2rem'); |
| 2802 |
|
| 2803 |
$backButton = new htmlAccountPageButton(static::class, 'attributes', 'back', _('Back')); |
| 2804 |
$return->add($backButton); |
| 2805 |
} |
| 2806 |
return $return; |
| 2807 |
} |
| 2808 |
|
| 2809 |
/** |
| 2810 |
* Processes user input of the workstation page. |
| 2811 |
* It checks if all input values are correct and updates the associated LDAP attributes. |
| 2812 |
* |
| 2813 |
* @return array<string|string[]>[] list of info/error messages |
| 2814 |
*/ |
| 2815 |
public function process_userWorkstations(): array { |
| 2816 |
// Load attributes |
| 2817 |
if (isset($_POST['workstations_2']) && isset($_POST['workstations_left'])) { // Add workstations to list |
| 2818 |
$workstations = []; |
| 2819 |
if (isset($this->attributes['userWorkstations'][0])) { |
| 2820 |
$temp = str_replace(' ', '', $this->attributes['userWorkstations'][0]); |
| 2821 |
$workstations = explode(',', $temp); |
| 2822 |
for ($i = 0; $i < count($workstations); $i++) { |
| 2823 |
if ($workstations[$i] === '') { |
| 2824 |
unset($workstations[$i]); |
| 2825 |
} |
| 2826 |
} |
| 2827 |
$workstations = array_values($workstations); |
| 2828 |
} |
| 2829 |
// Add new // Add workstations |
| 2830 |
$workstations = array_merge($workstations, $_POST['workstations_2']); |
| 2831 |
// remove doubles |
| 2832 |
$workstations = array_flip($workstations); |
| 2833 |
$workstations = array_unique($workstations); |
| 2834 |
$workstations = array_flip($workstations); |
| 2835 |
// sort workstations |
| 2836 |
sort($workstations); |
| 2837 |
// Recreate workstation string |
| 2838 |
$this->attributes['userWorkstations'][0] = $workstations[0]; |
| 2839 |
for ($i = 1; $i < count($workstations); $i++) { |
| 2840 |
$this->attributes['userWorkstations'][0] = $this->attributes['userWorkstations'][0] . "," . $workstations[$i]; |
| 2841 |
} |
| 2842 |
} |
| 2843 |
elseif (isset($_POST['workstations_1']) && isset($_POST['workstations_right'])) { // remove // Add workstations from list |
| 2844 |
// Put all workstations in array |
| 2845 |
$temp = str_replace(' ', '', $this->attributes['userWorkstations'][0]); |
| 2846 |
$workstations = explode(',', $temp); |
| 2847 |
for ($i = 0; $i < count($workstations); $i++) { |
| 2848 |
if ($workstations[$i] === '') { |
| 2849 |
unset($workstations[$i]); |
| 2850 |
} |
| 2851 |
} |
| 2852 |
$workstations = array_values($workstations); |
| 2853 |
// Remove unwanted workstations from array |
| 2854 |
$workstations = array_delete($_POST['workstations_1'], $workstations); |
| 2855 |
// Recreate workstation string |
| 2856 |
unset($this->attributes['userWorkstations'][0]); |
| 2857 |
if (count($workstations) > 0) { |
| 2858 |
$this->attributes['userWorkstations'][0] = $workstations[0]; |
| 2859 |
for ($i = 1; $i < count($workstations); $i++) { |
| 2860 |
$this->attributes['userWorkstations'][0] = $this->attributes['userWorkstations'][0] . "," . $workstations[$i]; |
| 2861 |
} |
| 2862 |
} |
| 2863 |
} |
| 2864 |
return []; |
| 2865 |
} |
| 2866 |
|
| 2867 |
/** |
| 2868 |
* This function will create the HTML page to edit logon hours. |
| 2869 |
* |
| 2870 |
* @return htmlElement meta HTML code |
| 2871 |
*/ |
| 2872 |
public function display_html_logonHours(): htmlElement { |
| 2873 |
$return = new htmlResponsiveRow(); |
| 2874 |
$timeZone = getTimeZoneOffsetHours(); |
| 2875 |
$titles = [_('Time'), _('Monday'), _('Tuesday'), _('Wednesday'), _('Thursday'), |
| 2876 |
_('Friday'), _('Saturday'), _('Sunday')]; |
| 2877 |
$data = []; |
| 2878 |
if (!isset($this->attributes['logonhours'][0]) || ($this->attributes['logonhours'][0] === '')) { |
| 2879 |
$this->attributes['logonhours'][0] = pack('H*', 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'); |
| 2880 |
} |
| 2881 |
// convert the existing logonHours string to a bit array |
| 2882 |
$logonHoursHex = unpack('H*', $this->attributes['logonhours'][0])[1]; |
| 2883 |
$logonHoursDual = ''; |
| 2884 |
for ($i = 0; $i < strlen($logonHoursHex); $i++) { |
| 2885 |
$logonHoursDual .= self::HEX2BIT_STRING[$logonHoursHex[$i]]; |
| 2886 |
} |
| 2887 |
// reverse bits low to high (1 is 0:00 Sunday, 2 is 1:00 Sunday, etc.) |
| 2888 |
$logonHours = ""; |
| 2889 |
for ($i = 0; $i < 21; $i++) { |
| 2890 |
$logonHours .= strrev(substr($logonHoursDual, $i * 8, 8)); |
| 2891 |
} |
| 2892 |
$hour = []; |
| 2893 |
for ($i = 0; $i < 24 * 7; $i++) { |
| 2894 |
$hour[$i] = substr($logonHours, $i, 1); |
| 2895 |
} |
| 2896 |
// display input |
| 2897 |
$boxes = []; |
| 2898 |
// dynamically place boxes depending on time zone |
| 2899 |
for ($i = 0; $i < 24 * 7; $i++) { |
| 2900 |
$hr = $i - $timeZone; |
| 2901 |
if ($hr < 0) { |
| 2902 |
$hr += 24 * 7; |
| 2903 |
} |
| 2904 |
elseif ($hr >= 24 * 7) { |
| 2905 |
$hr -= 24 * 7; |
| 2906 |
} |
| 2907 |
$checkbox = new htmlInputCheckbox('lh_' . $hr, ($hour[(int) $hr] === '1')); |
| 2908 |
$boxes[$i % 24][(int) floor($i / 24)] = $checkbox; |
| 2909 |
} |
| 2910 |
for ($h = 0; $h < 24; $h++) { |
| 2911 |
$hour = str_pad((string) $h, 2, '0', STR_PAD_LEFT); |
| 2912 |
$row = []; |
| 2913 |
$row[] = new htmlOutputText("$hour:00 - " . str_pad((string) ($h + 1), 2, '0', STR_PAD_LEFT) . ":00"); |
| 2914 |
for ($d = 1; $d < 7; $d++) { |
| 2915 |
$row[] = $boxes[$h][$d]; |
| 2916 |
} |
| 2917 |
$row[] = $boxes[$h][0]; // Sunday goes last |
| 2918 |
$data[] = $row; |
| 2919 |
} |
| 2920 |
$return->add(new htmlResponsiveTable($titles, $data)); |
| 2921 |
|
| 2922 |
$return->addVerticalSpacer('2rem'); |
| 2923 |
$return->addLabel(new htmlAccountPageButton(static::class, 'attributes', 'submit', _('Ok'))); |
| 2924 |
$return->addField(new htmlAccountPageButton(static::class, 'attributes', 'abort', _('Cancel'))); |
| 2925 |
return $return; |
| 2926 |
} |
| 2927 |
|
| 2928 |
/** |
| 2929 |
* Processes user input of the logon hours page. |
| 2930 |
* It checks if all input values are correct and updates the associated LDAP attributes. |
| 2931 |
* |
| 2932 |
* @return array<string|string[]>[] list of info/error messages |
| 2933 |
*/ |
| 2934 |
public function process_logonHours(): array { |
| 2935 |
if (isset($_POST['form_subpage_sambaSamAccount_attributes_abort'])) { |
| 2936 |
return []; |
| 2937 |
} |
| 2938 |
// set new logon hours |
| 2939 |
$logonHours = ''; |
| 2940 |
for ($i = 0; $i < 24 * 7; $i++) { |
| 2941 |
$logonHours .= isset($_POST['lh_' . $i]) ? '1' : '0'; |
| 2942 |
} |
| 2943 |
// reconstruct HEX string |
| 2944 |
$bitstring2hex = array_flip(self::HEX2BIT_STRING); |
| 2945 |
$logonHoursNew = ''; |
| 2946 |
for ($i = 0; $i < 21; $i++) { |
| 2947 |
$part = strrev(substr($logonHours, $i * 8, 8)); |
| 2948 |
$byte['hi'] = substr($part, 0, 4); |
| 2949 |
$byte['low'] = substr($part, 4, 4); |
| 2950 |
$hex = $bitstring2hex[$byte['hi']] . $bitstring2hex[$byte['low']]; |
| 2951 |
$logonHoursNew .= $hex; |
| 2952 |
} |
| 2953 |
$this->attributes['logonhours'][0] = pack('H*', $logonHoursNew); |
| 2954 |
return []; |
| 2955 |
} |
| 2956 |
|
| 2957 |
/** |
| 2958 |
* Returns a list of existing hosts. |
| 2959 |
* |
| 2960 |
* @return string[] host names |
| 2961 |
*/ |
| 2962 |
private function getHostList(): array { |
| 2963 |
if ($this->cachedHostList !== null) { |
| 2964 |
return $this->cachedHostList; |
| 2965 |
} |
| 2966 |
$this->cachedHostList = []; |
| 2967 |
$results = searchLDAPByAttribute('cn', '*', 'computer', ['cn'], ['host']); |
| 2968 |
foreach ($results as $result) { |
| 2969 |
$this->cachedHostList[] = $result['cn'][0]; |
| 2970 |
} |
| 2971 |
return $this->cachedHostList; |
| 2972 |
} |
| 2973 |
|
| 2974 |
/** |
| 2975 |
* {@inheritDoc} |
| 2976 |
*/ |
| 2977 |
public function postModifyActions(bool $newAccount, array $attributes): array { |
| 2978 |
$messages = []; |
| 2979 |
// set groups |
| 2980 |
$groups = $this->findGroups(); |
| 2981 |
$toAdd = array_values(array_diff($this->groupList, $this->groupList_orig)); |
| 2982 |
$toRem = array_values(array_diff($this->groupList_orig, $this->groupList)); |
| 2983 |
// add groups |
| 2984 |
for ($i = 0; $i < count($toAdd); $i++) { |
| 2985 |
if (in_array($toAdd[$i], $groups)) { |
| 2986 |
$success = @ldap_mod_add($_SESSION['ldap']->server(), $toAdd[$i], ['member' => [$this->getAccountContainer()->finalDN]]); |
| 2987 |
if (!$success) { |
| 2988 |
logNewMessage(LOG_ERR, 'Unable to add user ' . $this->getAccountContainer()->finalDN . ' to group: ' . $toAdd[$i] . ' (' . ldap_error($_SESSION['ldap']->server()) . ').'); |
| 2989 |
$messages[] = ['ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $toAdd[$i]), getDefaultLDAPErrorString($_SESSION['ldap']->server())]; |
| 2990 |
} |
| 2991 |
else { |
| 2992 |
logNewMessage(LOG_NOTICE, 'Added user ' . $this->getAccountContainer()->finalDN . ' to group: ' . $toAdd[$i]); |
| 2993 |
} |
| 2994 |
} |
| 2995 |
} |
| 2996 |
// remove groups |
| 2997 |
for ($i = 0; $i < count($toRem); $i++) { |
| 2998 |
if (in_array($toRem[$i], $groups)) { |
| 2999 |
// membership is removed with potentially new DN as Windows updates group automatically on user move |
| 3000 |
$success = @ldap_mod_del($_SESSION['ldap']->server(), $toRem[$i], ['member' => [$this->getAccountContainer()->finalDN]]); |
| 3001 |
if (!$success) { |
| 3002 |
logNewMessage(LOG_ERR, 'Unable to delete user ' . $this->getAccountContainer()->finalDN . ' from group: ' . $toRem[$i] . ' (' . ldap_error($_SESSION['ldap']->server()) . ').'); |
| 3003 |
$messages[] = ['ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $toRem[$i]), getDefaultLDAPErrorString($_SESSION['ldap']->server())]; |
| 3004 |
} |
| 3005 |
else { |
| 3006 |
logNewMessage(LOG_NOTICE, 'Removed user ' . $this->getAccountContainer()->finalDN . ' from group: ' . $toRem[$i]); |
| 3007 |
} |
| 3008 |
} |
| 3009 |
} |
| 3010 |
// force password change if needed |
| 3011 |
if ($this->pwdLastSet !== null) { |
| 3012 |
$attrs = ['pwdLastSet' => [$this->pwdLastSet]]; |
| 3013 |
$success = @ldap_modify($_SESSION['ldap']->server(), $this->getAccountContainer()->finalDN, $attrs); |
| 3014 |
if (!$success) { |
| 3015 |
logNewMessage(LOG_ERR, 'Unable to change pwdLastSet for ' . $this->getAccountContainer()->finalDN . ' (' . ldap_error($_SESSION['ldap']->server()) . ').'); |
| 3016 |
$messages[] = ['ERROR', sprintf(_('Was unable to modify attributes of DN: %s.'), $this->getAccountContainer()->finalDN), getDefaultLDAPErrorString($_SESSION['ldap']->server())]; |
| 3017 |
} |
| 3018 |
else { |
| 3019 |
logNewMessage(LOG_DEBUG, 'Set pwdLastSet to ' . $this->pwdLastSet . ' for ' . $this->getAccountContainer()->finalDN); |
| 3020 |
} |
| 3021 |
} |
| 3022 |
return $messages; |
| 3023 |
} |
| 3024 |
|
| 3025 |
/** |
| 3026 |
* {@inheritDoc} |
| 3027 |
*/ |
| 3028 |
public function build_uploadAccounts(array $rawAccounts, array $ids, array &$partialAccounts, array $selectedModules, ConfiguredType &$type): array { |
| 3029 |
$errors = []; |
| 3030 |
// get the list of existing groups |
| 3031 |
$groupList = $this->findGroups(); |
| 3032 |
$groupMap = []; |
| 3033 |
foreach ($groupList as $dn) { |
| 3034 |
$groupMap[extractRDNValue($dn)] = $dn; |
| 3035 |
} |
| 3036 |
$existingUsers = $this->getUserNames(); |
| 3037 |
$existingCns = $this->getCns(); |
| 3038 |
$existingMailAccounts = searchLDAPByAttribute(null, null, 'user', ['mail', 'otherMailbox'], ['user']); |
| 3039 |
$existingMails = []; |
| 3040 |
foreach ($existingMailAccounts as $existingMailAccount) { |
| 3041 |
if (!empty($existingMailAccount['mail'][0])) { |
| 3042 |
$existingMails[] = $existingMailAccount['mail'][0]; |
| 3043 |
} |
| 3044 |
if (!empty($existingMailAccount['othermailbox'][0])) { |
| 3045 |
$existingMails = array_merge($existingMails, $existingMailAccount['othermailbox']); |
| 3046 |
} |
| 3047 |
} |
| 3048 |
$booleanOptions = [_('yes') => true, _('no') => false]; |
| 3049 |
for ($i = 0; $i < count($rawAccounts); $i++) { |
| 3050 |
// add object class |
| 3051 |
if (!in_array('user', $partialAccounts[$i]['objectClass'])) { |
| 3052 |
$partialAccounts[$i]['objectClass'][] = 'user'; |
| 3053 |
} |
| 3054 |
// userPrincipalName |
| 3055 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_userPrincipalName']], 'username')) { |
| 3056 |
$partialAccounts[$i]['userPrincipalName'] = $rawAccounts[$i][$ids['windowsUser_userPrincipalName']]; |
| 3057 |
if (array_key_exists($partialAccounts[$i]['userPrincipalName'], $existingUsers)) { |
| 3058 |
$errMsg = $this->messages['userPrincipalName'][3]; |
| 3059 |
$errMsg[] = [$i]; |
| 3060 |
$errors[] = $errMsg; |
| 3061 |
} |
| 3062 |
} |
| 3063 |
else { |
| 3064 |
$errMsg = $this->messages['userPrincipalName'][1]; |
| 3065 |
$errMsg[] = [$i]; |
| 3066 |
$errors[] = $errMsg; |
| 3067 |
} |
| 3068 |
// first name |
| 3069 |
if ($rawAccounts[$i][$ids['windowsUser_firstName']] != "") { |
| 3070 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_firstName']], 'realname')) { |
| 3071 |
$partialAccounts[$i]['givenName'] = $rawAccounts[$i][$ids['windowsUser_firstName']]; |
| 3072 |
} |
| 3073 |
else { |
| 3074 |
$errMsg = $this->messages['givenName'][1]; |
| 3075 |
$errMsg[] = [$i]; |
| 3076 |
$errors[] = $errMsg; |
| 3077 |
} |
| 3078 |
} |
| 3079 |
// last name |
| 3080 |
if ($rawAccounts[$i][$ids['windowsUser_lastName']] != "") { |
| 3081 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_lastName']], 'realname')) { |
| 3082 |
$partialAccounts[$i]['sn'] = $rawAccounts[$i][$ids['windowsUser_lastName']]; |
| 3083 |
} |
| 3084 |
else { |
| 3085 |
$errMsg = $this->messages['sn'][1]; |
| 3086 |
$errMsg[] = [$i]; |
| 3087 |
$errors[] = $errMsg; |
| 3088 |
} |
| 3089 |
} |
| 3090 |
// personal title |
| 3091 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepersonaltitle', true)) { |
| 3092 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_personalTitle', |
| 3093 |
'personaltitle', 'title', $this->messages['personaltitle'][1], $errors); |
| 3094 |
} |
| 3095 |
// cn |
| 3096 |
if ($rawAccounts[$i][$ids['windowsUser_cn']] != "") { |
| 3097 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_cn']], 'cn')) { |
| 3098 |
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['windowsUser_cn']]; |
| 3099 |
if (array_key_exists($partialAccounts[$i]['cn'], $existingCns)) { |
| 3100 |
$errMsg = $this->messages['cn'][3]; |
| 3101 |
$errMsg[] = [$i]; |
| 3102 |
$errors[] = $errMsg; |
| 3103 |
} |
| 3104 |
} |
| 3105 |
else { |
| 3106 |
$errMsg = $this->messages['cn'][1]; |
| 3107 |
$errMsg[] = [$i]; |
| 3108 |
$errors[] = $errMsg; |
| 3109 |
} |
| 3110 |
} |
| 3111 |
else { |
| 3112 |
$cn = ''; |
| 3113 |
if (!empty($rawAccounts[$i][$ids['windowsUser_firstName']])) { |
| 3114 |
$cn = $rawAccounts[$i][$ids['windowsUser_firstName']]; |
| 3115 |
} |
| 3116 |
if (!empty($rawAccounts[$i][$ids['windowsUser_lastName']])) { |
| 3117 |
$cn .= ' ' . $rawAccounts[$i][$ids['windowsUser_lastName']]; |
| 3118 |
} |
| 3119 |
$cn = trim($cn); |
| 3120 |
if (!empty($cn)) { |
| 3121 |
$partialAccounts[$i]['cn'] = $cn; |
| 3122 |
} |
| 3123 |
} |
| 3124 |
// sAMAccountName |
| 3125 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidesAMAccountName', true)) { |
| 3126 |
if (!empty($rawAccounts[$i][$ids['windowsUser_sAMAccountName']])) { |
| 3127 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_sAMAccountName']], 'username')) { |
| 3128 |
$partialAccounts[$i]['sAMAccountName'] = $rawAccounts[$i][$ids['windowsUser_sAMAccountName']]; |
| 3129 |
} |
| 3130 |
else { |
| 3131 |
$errMsg = $this->messages['sAMAccountName'][1]; |
| 3132 |
$errMsg[] = [$i]; |
| 3133 |
$errors[] = $errMsg; |
| 3134 |
} |
| 3135 |
} |
| 3136 |
else { |
| 3137 |
$samUser = explode('@', $partialAccounts[$i]['userPrincipalName']); |
| 3138 |
$partialAccounts[$i]['sAMAccountName'] = $samUser[0]; |
| 3139 |
} |
| 3140 |
} |
| 3141 |
else { |
| 3142 |
// set sAMAccountName to username if not managed (W2012 requires it) |
| 3143 |
$parts = explode('@', $partialAccounts[$i]['userPrincipalName']); |
| 3144 |
$partialAccounts[$i]['sAMAccountName'] = $parts[0]; |
| 3145 |
} |
| 3146 |
// password |
| 3147 |
if ($rawAccounts[$i][$ids['windowsUser_password']] != "") { |
| 3148 |
$strengthResult = checkPasswordStrength($rawAccounts[$i][$ids['windowsUser_password']], [$rawAccounts[$i][$ids['windowsUser_userPrincipalName']]], []); |
| 3149 |
if (!$strengthResult->isValid()) { |
| 3150 |
$errors[] = ['ERROR', _('Account %s:') . ' windowsUser_password', $strengthResult->getTextMessage(), [$i]]; |
| 3151 |
} |
| 3152 |
elseif (!get_preg($rawAccounts[$i][$ids['windowsUser_password']], 'password')) { |
| 3153 |
$errMsg = $this->messages['unicodePwd'][2]; |
| 3154 |
$errMsg[2] = str_replace('%', '%%', $errMsg[2]); // double "%" because of later sprintf |
| 3155 |
$errMsg[] = [$i]; |
| 3156 |
$errors[] = $errMsg; |
| 3157 |
} |
| 3158 |
else { |
| 3159 |
$partialAccounts[$i]['unicodePwd'] = self::pwdAttributeValue($rawAccounts[$i][$ids['windowsUser_password']]); |
| 3160 |
$partialAccounts[$i]['INFO.userPasswordClearText'] = $rawAccounts[$i][$ids['windowsUser_password']]; // for custom scripts etc. |
| 3161 |
} |
| 3162 |
} |
| 3163 |
// display name |
| 3164 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedisplayName')) { |
| 3165 |
if ($rawAccounts[$i][$ids['windowsUser_displayName']] != "") { |
| 3166 |
$partialAccounts[$i]['displayName'] = $rawAccounts[$i][$ids['windowsUser_displayName']]; |
| 3167 |
} |
| 3168 |
elseif (!empty($partialAccounts[$i]['cn'])) { |
| 3169 |
$partialAccounts[$i]['displayName'] = $partialAccounts[$i]['cn']; |
| 3170 |
} |
| 3171 |
} |
| 3172 |
// initials |
| 3173 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideinitials')) { |
| 3174 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_initials', 'initials'); |
| 3175 |
} |
| 3176 |
// description |
| 3177 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedescription')) { |
| 3178 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_description', 'description'); |
| 3179 |
} |
| 3180 |
// street |
| 3181 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidestreetAddress')) { |
| 3182 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_streetAddress', 'streetAddress'); |
| 3183 |
} |
| 3184 |
// post office box |
| 3185 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostOfficeBox')) { |
| 3186 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_postOfficeBox', 'postOfficeBox'); |
| 3187 |
} |
| 3188 |
// postal code |
| 3189 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepostalCode')) { |
| 3190 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_postalCode', 'postalCode', |
| 3191 |
'postalCode', $this->messages['postalCode'][1], $errors); |
| 3192 |
} |
| 3193 |
// location |
| 3194 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidel')) { |
| 3195 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_l', 'l'); |
| 3196 |
} |
| 3197 |
// state |
| 3198 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidest')) { |
| 3199 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_state', 'st'); |
| 3200 |
} |
| 3201 |
// office name |
| 3202 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidephysicalDeliveryOfficeName')) { |
| 3203 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_officeName', 'physicalDeliveryOfficeName'); |
| 3204 |
} |
| 3205 |
// mail |
| 3206 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemail') && ($rawAccounts[$i][$ids['windowsUser_mail']] != "")) { |
| 3207 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_mail']], 'email')) { |
| 3208 |
$partialAccounts[$i]['mail'] = $rawAccounts[$i][$ids['windowsUser_mail']]; |
| 3209 |
if (in_array_ignore_case($partialAccounts[$i]['mail'], $existingMails)) { |
| 3210 |
$errMsg = $this->messages['mail'][3]; |
| 3211 |
$errMsg[] = [$i, $partialAccounts[$i]['mail']]; |
| 3212 |
$errors[] = $errMsg; |
| 3213 |
} |
| 3214 |
} |
| 3215 |
else { |
| 3216 |
$errMsg = $this->messages['mail'][1]; |
| 3217 |
$errMsg[] = [$i]; |
| 3218 |
$errors[] = $errMsg; |
| 3219 |
} |
| 3220 |
} |
| 3221 |
// mail aliases |
| 3222 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMailbox') && isset($ids['windowsUser_otherMailbox']) && ($rawAccounts[$i][$ids['windowsUser_otherMailbox']] != "")) { |
| 3223 |
$valueList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['windowsUser_otherMailbox']]); |
| 3224 |
$partialAccounts[$i]['otherMailbox'] = $valueList; |
| 3225 |
for ($x = 0; $x < count($valueList); $x++) { |
| 3226 |
if (!get_preg($valueList[$x], 'email')) { |
| 3227 |
$errMsg = $this->messages['otherMailbox'][1]; |
| 3228 |
$errMsg[] = [$i]; |
| 3229 |
$errors[] = $errMsg; |
| 3230 |
break; |
| 3231 |
} |
| 3232 |
if (in_array_ignore_case($valueList[$x], $existingMails)) { |
| 3233 |
$errMsg = $this->messages['otherMailbox'][3]; |
| 3234 |
$errMsg[] = [$i, $valueList[$x]]; |
| 3235 |
$errors[] = $errMsg; |
| 3236 |
} |
| 3237 |
} |
| 3238 |
} |
| 3239 |
// telephone |
| 3240 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetelephoneNumber')) { |
| 3241 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_telephoneNumber', 'telephoneNumber', |
| 3242 |
'telephone', $this->messages['telephoneNumber'][1], $errors); |
| 3243 |
} |
| 3244 |
// other telephone |
| 3245 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherTelephone')) { |
| 3246 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_otherTelephone', |
| 3247 |
'otherTelephone', 'telephone', $this->messages['otherTelephone'][1], $errors, '/;[ ]*/'); |
| 3248 |
} |
| 3249 |
// fax number |
| 3250 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidefacsimileTelephoneNumber')) { |
| 3251 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_facsimileTelephoneNumber', 'facsimileTelephoneNumber', |
| 3252 |
'telephone', $this->messages['facsimileTelephoneNumber'][1], $errors); |
| 3253 |
} |
| 3254 |
// website |
| 3255 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidewWWHomePage')) { |
| 3256 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_webSite', 'wWWHomePage'); |
| 3257 |
} |
| 3258 |
// other websites |
| 3259 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideurl')) { |
| 3260 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_otherWebSites', |
| 3261 |
'url', null, [], $errors, '/;[ ]*/'); |
| 3262 |
} |
| 3263 |
// user account control |
| 3264 |
$userAccountControlAttr['useraccountcontrol'][0] = (string) self::DEFAULT_ACCOUNT_CONTROL; |
| 3265 |
// deactivated |
| 3266 |
if ($rawAccounts[$i][$ids['windowsUser_deactivated']] != "") { |
| 3267 |
if (!isset($booleanOptions[$rawAccounts[$i][$ids['windowsUser_deactivated']]])) { |
| 3268 |
$errors[] = ['ERROR', sprintf(_('Account %s:'), $i) . ' windowsUser_deactivated', _('Please enter either yes or no.')]; |
| 3269 |
} |
| 3270 |
else { |
| 3271 |
windowsUser::setIsDeactivated($booleanOptions[$rawAccounts[$i][$ids['windowsUser_deactivated']]], $userAccountControlAttr); |
| 3272 |
} |
| 3273 |
} |
| 3274 |
// password does not expire |
| 3275 |
if ($rawAccounts[$i][$ids['windowsUser_noExpire']] != "") { |
| 3276 |
if (!isset($booleanOptions[$rawAccounts[$i][$ids['windowsUser_noExpire']]])) { |
| 3277 |
$errors[] = ['ERROR', sprintf(_('Account %s:'), $i) . ' windowsUser_noExpire', _('Please enter either yes or no.')]; |
| 3278 |
} |
| 3279 |
else { |
| 3280 |
windowsUser::setIsNeverExpiring($userAccountControlAttr, $booleanOptions[$rawAccounts[$i][$ids['windowsUser_noExpire']]]); |
| 3281 |
} |
| 3282 |
} |
| 3283 |
// account expiration |
| 3284 |
if (!empty($rawAccounts[$i][$ids['windowsUser_accountExpires']])) { |
| 3285 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_accountExpires']], 'date')) { |
| 3286 |
$dateParts = explode('-', $rawAccounts[$i][$ids['windowsUser_accountExpires']]); |
| 3287 |
$partialAccounts[$i]['accountexpires'] = $this->buildExpirationDate((int) $dateParts[2], (int) $dateParts[1], (int) $dateParts[0]); |
| 3288 |
} |
| 3289 |
else { |
| 3290 |
$errMsg = $this->messages['accountexpires'][1]; |
| 3291 |
$errMsg[] = [$i]; |
| 3292 |
$errors[] = $errMsg; |
| 3293 |
} |
| 3294 |
} |
| 3295 |
// require smartcard |
| 3296 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideRequireSmartcard') && ($rawAccounts[$i][$ids['windowsUser_requireCard']] != "")) { |
| 3297 |
if (!isset($booleanOptions[$rawAccounts[$i][$ids['windowsUser_requireCard']]])) { |
| 3298 |
$errors[] = ['ERROR', sprintf(_('Account %s:'), $i) . ' windowsUser_requireCard', _('Please enter either yes or no.')]; |
| 3299 |
} |
| 3300 |
else { |
| 3301 |
windowsUser::setIsSmartCardRequired($userAccountControlAttr, $booleanOptions[$rawAccounts[$i][$ids['windowsUser_requireCard']]]); |
| 3302 |
} |
| 3303 |
} |
| 3304 |
$partialAccounts[$i]['useraccountcontrol'][0] = $userAccountControlAttr['useraccountcontrol'][0]; |
| 3305 |
// end user account control |
| 3306 |
// password change at next login |
| 3307 |
if (($rawAccounts[$i][$ids['windowsUser_pwdMustChange']] != "") |
| 3308 |
&& !isset($booleanOptions[$rawAccounts[$i][$ids['windowsUser_pwdMustChange']]])) { |
| 3309 |
$errors[] = ['ERROR', sprintf(_('Account %s:'), $i) . ' windowsUser_pwdMustChange', _('Please enter either yes or no.')]; |
| 3310 |
// attribute must be set in postModify |
| 3311 |
} |
| 3312 |
// profile path |
| 3313 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideprofilePath') && ($rawAccounts[$i][$ids['windowsUser_profilePath']] != "")) { |
| 3314 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_profilePath']], 'UNC')) { |
| 3315 |
$partialAccounts[$i]['profilePath'] = $rawAccounts[$i][$ids['windowsUser_profilePath']]; |
| 3316 |
} |
| 3317 |
else { |
| 3318 |
$errMsg = $this->messages['profilePath'][1]; |
| 3319 |
$errMsg[] = [$i]; |
| 3320 |
$errors[] = $errMsg; |
| 3321 |
} |
| 3322 |
} |
| 3323 |
// logon script |
| 3324 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidescriptPath') && ($rawAccounts[$i][$ids['windowsUser_scriptPath']] != "")) { |
| 3325 |
if (get_preg($rawAccounts[$i][$ids['windowsUser_scriptPath']], 'logonscript')) { |
| 3326 |
$partialAccounts[$i]['scriptPath'] = $rawAccounts[$i][$ids['windowsUser_scriptPath']]; |
| 3327 |
} |
| 3328 |
else { |
| 3329 |
$errMsg = $this->messages['scriptPath'][1]; |
| 3330 |
$errMsg[] = [$i]; |
| 3331 |
$errors[] = $errMsg; |
| 3332 |
} |
| 3333 |
} |
| 3334 |
// home drive |
| 3335 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive') && (!empty($rawAccounts[$i][$ids['windowsUser_homeDrive']]))) { |
| 3336 |
if (preg_match("/[d-z]:/i", $rawAccounts[$i][$ids['windowsUser_homeDrive']])) { |
| 3337 |
$partialAccounts[$i]['homeDrive'] = strtoupper($rawAccounts[$i][$ids['windowsUser_homeDrive']]); |
| 3338 |
} |
| 3339 |
else { |
| 3340 |
$errMsg = $this->messages['homeDrive'][0]; |
| 3341 |
$errMsg[] = [$i]; |
| 3342 |
$errors[] = $errMsg; |
| 3343 |
} |
| 3344 |
} |
| 3345 |
// home directory |
| 3346 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDirectory') && ($rawAccounts[$i][$ids['windowsUser_homeDirectory']] != "")) { |
| 3347 |
if (empty($partialAccounts[$i]['homeDrive']) || get_preg($rawAccounts[$i][$ids['windowsUser_homeDirectory']], 'UNC')) { |
| 3348 |
$partialAccounts[$i]['homeDirectory'] = $rawAccounts[$i][$ids['windowsUser_homeDirectory']]; |
| 3349 |
} |
| 3350 |
else { |
| 3351 |
$errMsg = $this->messages['homeDirectory'][1]; |
| 3352 |
$errMsg[] = [$i]; |
| 3353 |
$errors[] = $errMsg; |
| 3354 |
} |
| 3355 |
} |
| 3356 |
// workstations |
| 3357 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_workstations', 'userWorkstations', |
| 3358 |
'workstations', $this->messages['workstations'][1], $errors); |
| 3359 |
// groups |
| 3360 |
if (isset($ids['windowsUser_groups']) && ($rawAccounts[$i][$ids['windowsUser_groups']] != "")) { |
| 3361 |
$valueList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['windowsUser_groups']]); |
| 3362 |
$invalidGroups = []; |
| 3363 |
foreach ($valueList as $group) { |
| 3364 |
if (!in_array($group, $groupList) && !isset($groupMap[$group])) { |
| 3365 |
$invalidGroups[] = $group; |
| 3366 |
} |
| 3367 |
} |
| 3368 |
if ($invalidGroups !== []) { |
| 3369 |
$errors[] = ['ERROR', sprintf(_('Account %s:'), $i) . ' windowsUser_groups', |
| 3370 |
_('LAM was unable to find a group with this name!') . '<br>' . htmlspecialchars(implode('; ', $invalidGroups))]; |
| 3371 |
} |
| 3372 |
} |
| 3373 |
// NIS name |
| 3374 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30Name', true)) { |
| 3375 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_msSFU30Name', 'msSFU30Name', |
| 3376 |
'username', $this->messages['msSFU30Name'][1], $errors); |
| 3377 |
} |
| 3378 |
// NIS domain |
| 3379 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemsSFU30NisDomain', true)) { |
| 3380 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_msSFU30NisDomain', 'msSFU30NisDomain'); |
| 3381 |
} |
| 3382 |
// title |
| 3383 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 3384 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_title', |
| 3385 |
'title', 'title', $this->messages['title'][1], $errors); |
| 3386 |
} |
| 3387 |
// room number |
| 3388 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber', true)) { |
| 3389 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_roomNumber', |
| 3390 |
'roomnumber', null, [], $errors, '/;[ ]*/'); |
| 3391 |
} |
| 3392 |
// carLicense |
| 3393 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecarLicense', true)) { |
| 3394 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_carLicense', 'carLicense'); |
| 3395 |
} |
| 3396 |
// employee number |
| 3397 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeNumber', true)) { |
| 3398 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_employeeNumber', 'employeeNumber'); |
| 3399 |
} |
| 3400 |
// employee type |
| 3401 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 3402 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_employeeType', |
| 3403 |
'employeeType', 'employeeType', $this->messages['employeeType'][1], $errors); |
| 3404 |
} |
| 3405 |
// business category |
| 3406 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 3407 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_businessCategory', |
| 3408 |
'businessCategory', 'businessCategory', $this->messages['businessCategory'][1], $errors, '/;[ ]*/'); |
| 3409 |
} |
| 3410 |
// departments |
| 3411 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 3412 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_department', |
| 3413 |
'department', null, [], $errors); |
| 3414 |
} |
| 3415 |
// department numbers |
| 3416 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 3417 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_departmentNumber', |
| 3418 |
'departmentNumber', null, [], $errors, '/;[ ]*/'); |
| 3419 |
} |
| 3420 |
// organisational unit |
| 3421 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 3422 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_ou', |
| 3423 |
'ou', null, [], $errors, '/;[ ]*/'); |
| 3424 |
} |
| 3425 |
// organisation |
| 3426 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 3427 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_o', |
| 3428 |
'o', null, [], $errors, '/;[ ]*/'); |
| 3429 |
} |
| 3430 |
// manager |
| 3431 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemanager', true)) { |
| 3432 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_manager', 'manager', 'dn', $this->messages['manager'][0], $errors); |
| 3433 |
} |
| 3434 |
// company |
| 3435 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidecompany', true)) { |
| 3436 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_company', 'company'); |
| 3437 |
} |
| 3438 |
// mobile |
| 3439 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidemobile', true)) { |
| 3440 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_mobile', 'mobile', |
| 3441 |
'telephone', $this->messages['mobile'][1], $errors); |
| 3442 |
} |
| 3443 |
// other mobile |
| 3444 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherMobile', true)) { |
| 3445 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_otherMobile', 'otherMobile', |
| 3446 |
'telephone', $this->messages['otherMobile'][1], $errors, '/;[ ]*/'); |
| 3447 |
} |
| 3448 |
// pager |
| 3449 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidepager', true)) { |
| 3450 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_pager', 'pager', |
| 3451 |
'telephone', $this->messages['pager'][1], $errors); |
| 3452 |
} |
| 3453 |
// other pager |
| 3454 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideotherPager', true)) { |
| 3455 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_otherPager', 'otherPager', |
| 3456 |
'telephone', $this->messages['otherPager'][1], $errors, '/;[ ]*/'); |
| 3457 |
} |
| 3458 |
// Proxy-Addresses |
| 3459 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideproxyAddresses', true)) { |
| 3460 |
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'windowsUser_proxyAddresses', 'proxyAddresses', |
| 3461 |
null, [], $errors, '/;[ ]*/'); |
| 3462 |
} |
| 3463 |
} |
| 3464 |
return $errors; |
| 3465 |
} |
| 3466 |
|
| 3467 |
/** |
| 3468 |
* {@inheritDoc} |
| 3469 |
*/ |
| 3470 |
public function doUploadPostActions(array &$data, array $ids, array $failed, array &$temp, array &$accounts, |
| 3471 |
array $selectedModules, ConfiguredType $type): array { |
| 3472 |
if (!checkIfWriteAccessIsAllowed($this->get_scope())) { |
| 3473 |
die(); |
| 3474 |
} |
| 3475 |
// on first call generate list of ldap operations |
| 3476 |
if (!isset($temp['counter'])) { |
| 3477 |
$groupList = $this->findGroups(); |
| 3478 |
$groupMap = []; |
| 3479 |
foreach ($groupList as $dn) { |
| 3480 |
$groupMap[extractRDNValue($dn)] = $dn; |
| 3481 |
} |
| 3482 |
$temp['groups'] = &$groupList; |
| 3483 |
$temp['groupMap'] = &$groupMap; |
| 3484 |
$temp['members'] = []; |
| 3485 |
$temp['memberCount'] = 0; |
| 3486 |
$temp['pwdChange'] = []; |
| 3487 |
$temp['pwdChangeCount'] = 0; |
| 3488 |
$groupCol = $ids['windowsUser_groups']; |
| 3489 |
$passwordChangeRequiredCol = $ids['windowsUser_pwdMustChange']; |
| 3490 |
for ($i = 0; $i < count($data); $i++) { |
| 3491 |
if (in_array($i, $failed)) { |
| 3492 |
continue; |
| 3493 |
} // ignore failed accounts |
| 3494 |
if ($data[$i][$groupCol] != "") { |
| 3495 |
$groups = preg_split('/;[ ]*/', $data[$i][$groupCol]); |
| 3496 |
for ($g = 0; $g < count($groups); $g++) { |
| 3497 |
if (in_array($groups[$g], $temp['groups'])) { |
| 3498 |
$temp['members'][$groups[$g]][] = $accounts[$i]['dn']; |
| 3499 |
} |
| 3500 |
elseif (isset($temp['groupMap'][$groups[$g]])) { |
| 3501 |
$temp['members'][$temp['groupMap'][$groups[$g]]][] = $accounts[$i]['dn']; |
| 3502 |
} |
| 3503 |
} |
| 3504 |
} |
| 3505 |
if (isset($data[$i][$passwordChangeRequiredCol]) && ($data[$i][$passwordChangeRequiredCol] == _('yes'))) { |
| 3506 |
$temp['pwdChange'][] = $accounts[$i]['dn']; |
| 3507 |
} |
| 3508 |
} |
| 3509 |
$temp['memberCount'] = count($temp['members']); |
| 3510 |
$temp['pwdChangeCount'] = count($temp['pwdChange']); |
| 3511 |
$temp['counter'] = $temp['memberCount'] + $temp['pwdChangeCount']; |
| 3512 |
return [ |
| 3513 |
'status' => 'inProgress', |
| 3514 |
'progress' => 0, |
| 3515 |
'errors' => [] |
| 3516 |
]; |
| 3517 |
} |
| 3518 |
// add users to groups |
| 3519 |
elseif (count($temp['members']) > 0) { |
| 3520 |
$keys = array_keys($temp['members']); |
| 3521 |
$group = $keys[0]; |
| 3522 |
$member = array_pop($temp['members'][$group]); |
| 3523 |
$success = @ldap_mod_add($_SESSION['ldap']->server(), $group, ['member' => $member]); |
| 3524 |
$errors = []; |
| 3525 |
if (!$success) { |
| 3526 |
$errors[] = [ |
| 3527 |
"ERROR", |
| 3528 |
_("LAM was unable to modify group memberships for group: %s"), |
| 3529 |
getDefaultLDAPErrorString($_SESSION['ldap']->server()), |
| 3530 |
[$group] |
| 3531 |
]; |
| 3532 |
} |
| 3533 |
if (count($temp['members'][$group]) === 0) { |
| 3534 |
unset($temp['members'][$group]); |
| 3535 |
} |
| 3536 |
$memberPercentage = (100 * ($temp['memberCount'] - count($temp['members']))) / $temp['counter']; |
| 3537 |
return [ |
| 3538 |
'status' => 'inProgress', |
| 3539 |
'progress' => $memberPercentage, |
| 3540 |
'errors' => $errors |
| 3541 |
]; |
| 3542 |
} |
| 3543 |
// force password change |
| 3544 |
elseif (count($temp['pwdChange']) > 0) { |
| 3545 |
$dn = array_pop($temp['pwdChange']); |
| 3546 |
$success = @ldap_mod_replace($_SESSION['ldap']->server(), $dn, ['pwdLastSet' => '0']); |
| 3547 |
$errors = []; |
| 3548 |
if (!$success) { |
| 3549 |
$errors[] = [ |
| 3550 |
"ERROR", |
| 3551 |
_("Was unable to modify attributes of DN: %s."), |
| 3552 |
getDefaultLDAPErrorString($_SESSION['ldap']->server()), |
| 3553 |
[$dn] |
| 3554 |
]; |
| 3555 |
} |
| 3556 |
$pwdPercentage = (100 * ($temp['memberCount'] + ($temp['pwdChangeCount'] - count($temp['pwdChange'])))) / $temp['counter']; |
| 3557 |
return [ |
| 3558 |
'status' => 'inProgress', |
| 3559 |
'progress' => $pwdPercentage, |
| 3560 |
'errors' => $errors |
| 3561 |
]; |
| 3562 |
} |
| 3563 |
// all modifications are done |
| 3564 |
else { |
| 3565 |
return [ |
| 3566 |
'status' => 'finished', |
| 3567 |
'progress' => 100, |
| 3568 |
'errors' => [] |
| 3569 |
]; |
| 3570 |
} |
| 3571 |
} |
| 3572 |
|
| 3573 |
/** |
| 3574 |
* {@inheritDoc} |
| 3575 |
*/ |
| 3576 |
public function get_pdfEntries(array $pdfKeys, string $typeId): array { |
| 3577 |
$return = []; |
| 3578 |
$this->addSimplePDFField($return, 'userPrincipalName', _('User name')); |
| 3579 |
$this->addSimplePDFField($return, 'cn', _('Common name')); |
| 3580 |
$this->addSimplePDFField($return, 'sAMAccountName', _('User name (pre W2K)')); |
| 3581 |
$this->addSimplePDFField($return, 'description', _('Description')); |
| 3582 |
$this->addSimplePDFField($return, 'displayName', _('Display name')); |
| 3583 |
$this->addSimplePDFField($return, 'personaltitle', _('Personal title')); |
| 3584 |
$this->addSimplePDFField($return, 'givenName', _('First name')); |
| 3585 |
$this->addSimplePDFField($return, 'initials', _('Initials')); |
| 3586 |
$this->addSimplePDFField($return, 'l', _('Location')); |
| 3587 |
$this->addSimplePDFField($return, 'mail', _('Email address')); |
| 3588 |
$this->addSimplePDFField($return, 'otherMailbox', _('Email alias')); |
| 3589 |
$this->addSimplePDFField($return, 'otherTelephone', _('Other telephone numbers')); |
| 3590 |
$this->addSimplePDFField($return, 'physicalDeliveryOfficeName', _('Office name')); |
| 3591 |
$this->addSimplePDFField($return, 'postalCode', _('Postal code')); |
| 3592 |
$this->addSimplePDFField($return, 'postOfficeBox', _('Post office box')); |
| 3593 |
$this->addSimplePDFField($return, 'sn', _('Last name')); |
| 3594 |
$this->addSimplePDFField($return, 'st', _('State')); |
| 3595 |
$this->addSimplePDFField($return, 'streetAddress', _('Street')); |
| 3596 |
$this->addSimplePDFField($return, 'telephoneNumber', _('Telephone number')); |
| 3597 |
$this->addSimplePDFField($return, 'facsimileTelephoneNumber', _('Fax number')); |
| 3598 |
$this->addSimplePDFField($return, 'company', _('Company')); |
| 3599 |
$this->addSimplePDFField($return, 'pager', _('Pager')); |
| 3600 |
$this->addSimplePDFField($return, 'otherPager', _('Other pagers')); |
| 3601 |
$this->addSimplePDFField($return, 'mobile', _('Mobile')); |
| 3602 |
$this->addSimplePDFField($return, 'otherMobile', _('Other mobiles')); |
| 3603 |
$this->addSimplePDFField($return, 'proxyAddresses', _('Proxy-Addresses')); |
| 3604 |
$this->addSimplePDFField($return, 'url', _('Other web sites')); |
| 3605 |
$this->addSimplePDFField($return, 'wWWHomePage', _('Web site')); |
| 3606 |
$this->addSimplePDFField($return, 'msSFU30Name', _('NIS name')); |
| 3607 |
$this->addSimplePDFField($return, 'msSFU30NisDomain', _('NIS domain')); |
| 3608 |
$this->addSimplePDFField($return, 'title', _('Job title')); |
| 3609 |
$this->addSimplePDFField($return, 'roomnumber', _('Room number')); |
| 3610 |
$this->addSimplePDFField($return, 'carLicense', _('Car license')); |
| 3611 |
$this->addSimplePDFField($return, 'employeeNumber', _('Employee number')); |
| 3612 |
$this->addSimplePDFField($return, 'employeeType', _('Employee type')); |
| 3613 |
$this->addSimplePDFField($return, 'businessCategory', _('Business category')); |
| 3614 |
$this->addSimplePDFField($return, 'department', _('Department')); |
| 3615 |
$this->addSimplePDFField($return, 'departmentNumber', _('Department number')); |
| 3616 |
$this->addSimplePDFField($return, 'ou', _('Organisational unit')); |
| 3617 |
$this->addSimplePDFField($return, 'o', _('Organisation')); |
| 3618 |
$this->addSimplePDFField($return, 'manager', _('Manager')); |
| 3619 |
$this->addSimplePDFField($return, 'userWorkstations', _('Workstations')); |
| 3620 |
$deactivated = _('no'); |
| 3621 |
if (windowsUser::isDeactivated($this->attributes)) { |
| 3622 |
$deactivated = _('yes'); |
| 3623 |
} |
| 3624 |
$this->addPDFKeyValue($return, 'deactivated', _('Account is deactivated'), $deactivated); |
| 3625 |
$noExpire = _('no'); |
| 3626 |
if (windowsUser::isNeverExpiring($this->attributes)) { |
| 3627 |
$noExpire = _('yes'); |
| 3628 |
} |
| 3629 |
$this->addPDFKeyValue($return, 'noExpire', _('Password does not expire'), $noExpire); |
| 3630 |
$this->addPDFKeyValue($return, 'accountExpires', _('Account expiration date'), $this->formatAccountExpires()); |
| 3631 |
$this->addPDFKeyValue($return, 'msds-userpasswordexpirytimecomputed', _('Password expiration'), $this->formatPasswordExpires($this->attributes)); |
| 3632 |
$requireCard = _('no'); |
| 3633 |
if (windowsUser::isSmartCardRequired($this->attributes)) { |
| 3634 |
$requireCard = _('yes'); |
| 3635 |
} |
| 3636 |
$this->addPDFKeyValue($return, 'requireCard', _('Require smartcard'), $requireCard); |
| 3637 |
$pwdMustChange = _('no'); |
| 3638 |
if (isset($this->attributes['pwdLastSet'][0]) && ($this->attributes['pwdLastSet'][0] === '0')) { |
| 3639 |
$pwdMustChange = _('yes'); |
| 3640 |
} |
| 3641 |
$this->addPDFKeyValue($return, 'pwdMustChange', _('Password change at next login'), $pwdMustChange); |
| 3642 |
$this->addSimplePDFField($return, 'profilePath', _('Profile path')); |
| 3643 |
$this->addSimplePDFField($return, 'scriptPath', _('Logon script')); |
| 3644 |
$this->addSimplePDFField($return, 'homeDirectory', _('Home directory')); |
| 3645 |
$this->addSimplePDFField($return, 'homeDrive', _('Home drive')); |
| 3646 |
$groups = []; |
| 3647 |
foreach ($this->groupList as $group) { |
| 3648 |
$groups[] = extractRDNValue($group); |
| 3649 |
} |
| 3650 |
$this->addPDFKeyValue($return, 'groups', _('Groups'), $groups); |
| 3651 |
// password |
| 3652 |
if ($this->clearTextPassword !== null) { |
| 3653 |
$this->addPDFKeyValue($return, 'password', _('Password'), $this->clearTextPassword); |
| 3654 |
} |
| 3655 |
elseif (isset($this->attributes['INFO.userPasswordClearText'])) { |
| 3656 |
$this->addPDFKeyValue($return, 'password', _('Password'), $this->attributes['INFO.userPasswordClearText']); |
| 3657 |
} |
| 3658 |
// last password change |
| 3659 |
$this->addPDFKeyValue($return, 'pwdLastSet', _('Last password change'), $this->formatPwdLastSet()); |
| 3660 |
// last login |
| 3661 |
$this->addPDFKeyValue($return, 'lastLogonTimestamp', _('Last login'), $this->formatLastLogonTimestamp()); |
| 3662 |
return $return; |
| 3663 |
} |
| 3664 |
|
| 3665 |
/** |
| 3666 |
* {@inheritDoc} |
| 3667 |
*/ |
| 3668 |
public function get_profileOptions(string $typeId): ?htmlResponsiveRow { |
| 3669 |
$return = parent::get_profileOptions($typeId); |
| 3670 |
// domain |
| 3671 |
$domains = $this->getDomains(); |
| 3672 |
$domains[] = ''; |
| 3673 |
$return->add(new htmlResponsiveSelect('windowsUser_userPrincipalNameDomain', $domains, [], _('Domain'), 'userPrincipalNameDomain')); |
| 3674 |
// group memberships |
| 3675 |
$groups = $this->findGroups(); |
| 3676 |
$groupOptions = []; |
| 3677 |
foreach ($groups as $dn) { |
| 3678 |
$groupOptions[extractRDNValue($dn)] = $dn; |
| 3679 |
} |
| 3680 |
$groupSelect = new htmlResponsiveSelect('windowsUser_groups', $groupOptions, [], _('Groups'), 'groups', 10); |
| 3681 |
$groupSelect->setHasDescriptiveElements(true); |
| 3682 |
$groupSelect->setMultiSelect(true); |
| 3683 |
$return->add($groupSelect); |
| 3684 |
// home drive |
| 3685 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidehomeDrive')) { |
| 3686 |
$drives = ['-']; |
| 3687 |
for ($i = 90; $i > 67; $i--) { |
| 3688 |
$drives[] = chr($i) . ':'; |
| 3689 |
} |
| 3690 |
$driveSelect = new htmlResponsiveSelect('windowsUser_homeDrive', $drives, ['-'], _('Home drive'), 'homeDrive'); |
| 3691 |
$return->add($driveSelect); |
| 3692 |
} |
| 3693 |
// force password change |
| 3694 |
$passwordChangeCheckbox = new htmlResponsiveInputCheckbox('windowsUser_pwdMustChange', true, _('Password change at next login'), 'pwdMustChange'); |
| 3695 |
$return->add($passwordChangeCheckbox); |
| 3696 |
// password does not expire |
| 3697 |
$passwordNoExpireCheckbox = new htmlResponsiveInputCheckbox('windowsUser_pwdNoExpire', false, _('Password does not expire'), 'noExpire'); |
| 3698 |
$return->add($passwordNoExpireCheckbox); |
| 3699 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideWorkstations')) { |
| 3700 |
// allowed workstations |
| 3701 |
$return->add(new htmlResponsiveInputField(_('Workstations'), 'windowsUser_userWorkstations', '', 'workstations')); |
| 3702 |
} |
| 3703 |
return $return; |
| 3704 |
} |
| 3705 |
|
| 3706 |
/** |
| 3707 |
* {@inheritDoc} |
| 3708 |
*/ |
| 3709 |
public function load_profile(array $profile): void { |
| 3710 |
// profile mappings in meta data |
| 3711 |
parent::load_profile($profile); |
| 3712 |
// load domain |
| 3713 |
if (isset($profile['windowsUser_userPrincipalNameDomain'][0])) { |
| 3714 |
$user = empty($this->attributes['userPrincipalName'][0]) ? '' : $this->attributes['userPrincipalName'][0]; |
| 3715 |
$userParts = explode('@', $user); |
| 3716 |
if (!empty($profile['windowsUser_userPrincipalNameDomain'][0])) { |
| 3717 |
$user = $userParts[0] . '@' . $profile['windowsUser_userPrincipalNameDomain'][0]; |
| 3718 |
} |
| 3719 |
$this->attributes['userPrincipalName'][0] = $user; |
| 3720 |
} |
| 3721 |
// load groups |
| 3722 |
if (!empty($profile['windowsUser_groups'][0])) { |
| 3723 |
$this->groupList = $profile['windowsUser_groups']; |
| 3724 |
} |
| 3725 |
// other mailboxes |
| 3726 |
if (!empty($profile['windowsUser_otherMailbox'][0])) { |
| 3727 |
$this->attributes['otherMailbox'] = preg_split('/;[ ]*/', $profile['windowsUser_otherMailbox'][0]); |
| 3728 |
} |
| 3729 |
// account expiration date |
| 3730 |
if (!empty($profile['windowsUser_accountExpires'][0]) && is_numeric($profile['windowsUser_accountExpires'][0])) { |
| 3731 |
$numDays = $profile['windowsUser_accountExpires'][0]; |
| 3732 |
$date = new DateTime('now', getTimeZone()); |
| 3733 |
$toAdd = new DateInterval('P' . $numDays . 'D'); |
| 3734 |
$dateTarget = $date->add($toAdd); |
| 3735 |
$this->setExpirationDate((int) $dateTarget->format('Y'), (int) $dateTarget->format('m'), (int) $dateTarget->format('d')); |
| 3736 |
} |
| 3737 |
// departments |
| 3738 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment') |
| 3739 |
&& isset($profile['windowsUser_department'][0]) |
| 3740 |
&& ($profile['windowsUser_department'][0] != '')) { |
| 3741 |
$departments = explode(';', $profile['windowsUser_department'][0]); |
| 3742 |
// remove extra spaces and set attributes |
| 3743 |
$this->attributes['department'] = array_map(trim(...), $departments); |
| 3744 |
} |
| 3745 |
// department numbers |
| 3746 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber') |
| 3747 |
&& !empty($profile['windowsUser_departmentNumber'][0])) { |
| 3748 |
$departmentNumbers = explode(';', $profile['windowsUser_departmentNumber'][0]); |
| 3749 |
// remove extra spaces and set attributes |
| 3750 |
$this->attributes['departmentNumber'] = array_map(trim(...), $departmentNumbers); |
| 3751 |
} |
| 3752 |
// organizational unit |
| 3753 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou') && isset($profile['windowsUser_ou'][0])) { |
| 3754 |
$oList = preg_split('/;[ ]*/', $profile['windowsUser_ou'][0]); |
| 3755 |
$this->attributes['ou'] = $oList; |
| 3756 |
} |
| 3757 |
// organisation |
| 3758 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo') && isset($profile['windowsUser_o'][0])) { |
| 3759 |
$oList = preg_split('/;[ ]*/', $profile['windowsUser_o'][0]); |
| 3760 |
$this->attributes['o'] = $oList; |
| 3761 |
} |
| 3762 |
// room number |
| 3763 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideroomnumber') && isset($profile['windowsUser_roomnumber'][0])) { |
| 3764 |
$this->attributes['roomnumber'] = preg_split('/;[ ]*/', $profile['windowsUser_roomnumber'][0]); |
| 3765 |
} |
| 3766 |
// no password expiration |
| 3767 |
if (isset($profile['windowsUser_pwdNoExpire'][0]) && ($profile['windowsUser_pwdNoExpire'][0] === "true")) { |
| 3768 |
if (!isset($this->attributes['useraccountcontrol'][0])) { |
| 3769 |
$this->attributes['useraccountcontrol'][0] = self::DEFAULT_ACCOUNT_CONTROL; |
| 3770 |
} |
| 3771 |
windowsUser::setIsNeverExpiring($this->attributes, true); |
| 3772 |
} |
| 3773 |
// force password change |
| 3774 |
if (isset($profile['windowsUser_pwdMustChange'][0]) && ($profile['windowsUser_pwdMustChange'][0] === "true")) { |
| 3775 |
$this->attributes['pwdLastSet'][0] = '0'; |
| 3776 |
} |
| 3777 |
elseif (isset($profile['windowsUser_pwdMustChange'][0]) && ($profile['windowsUser_pwdMustChange'][0] == "false")) { |
| 3778 |
if (isset($this->orig['pwdLastSet'][0]) && ($this->orig['pwdLastSet'][0] !== '0')) { |
| 3779 |
$this->attributes['pwdLastSet'][0] = $this->orig['pwdLastSet'][0]; |
| 3780 |
} |
| 3781 |
else { |
| 3782 |
$this->attributes['pwdLastSet'][0] = '-1'; |
| 3783 |
} |
| 3784 |
} |
| 3785 |
} |
| 3786 |
|
| 3787 |
/** |
| 3788 |
* {@inheritDoc} |
| 3789 |
*/ |
| 3790 |
public function getSelfServiceOptions(array $fields, array $attributes, bool $passwordChangeOnly, array $readOnlyFields): array { |
| 3791 |
$return = []; |
| 3792 |
if (in_array('unicodePwd', $fields)) { |
| 3793 |
$row = new htmlResponsiveRow(); |
| 3794 |
$pwd1 = new htmlResponsiveInputField($this->getSelfServiceLabel('unicodePwd', _('New password')), 'windowsUser_unicodePwd'); |
| 3795 |
$pwd1->setIsPassword(true, true); |
| 3796 |
$pwd1->setFieldSize(null); |
| 3797 |
$row->add($pwd1); |
| 3798 |
$pwd2 = new htmlResponsiveInputField(_('Reenter password'), 'windowsUser_unicodePwd2'); |
| 3799 |
$pwd2->setIsPassword(true); |
| 3800 |
$pwd2->setFieldSize(null); |
| 3801 |
$pwd2->setSameValueFieldID('windowsUser_unicodePwd'); |
| 3802 |
$row->add($pwd2); |
| 3803 |
$return['unicodePwd'] = $row; |
| 3804 |
} |
| 3805 |
if ($passwordChangeOnly) { |
| 3806 |
return $return; // only password fields as long no LDAP content can be read |
| 3807 |
} |
| 3808 |
$this->addSimpleSelfServiceTextField($return, 'personaltitle', _('Personal title'), $fields, $attributes, $readOnlyFields); |
| 3809 |
$this->addMultiValueSelfServiceTextField($return, 'roomnumber', _('Room number'), $fields, $attributes, $readOnlyFields); |
| 3810 |
$this->addSimpleSelfServiceTextField($return, 'physicalDeliveryOfficeName', _('Office name'), $fields, $attributes, $readOnlyFields); |
| 3811 |
$this->addSimpleSelfServiceTextField($return, 'telephoneNumber', _('Telephone number'), $fields, $attributes, $readOnlyFields); |
| 3812 |
$this->addSimpleSelfServiceTextField($return, 'facsimileTelephoneNumber', _('Fax number'), $fields, $attributes, $readOnlyFields); |
| 3813 |
$this->addSimpleSelfServiceTextField($return, 'wWWHomePage', _('Web site'), $fields, $attributes, $readOnlyFields); |
| 3814 |
if (isset($attributes['street'])) { |
| 3815 |
$attributes['streetAddress'] = $attributes['street']; |
| 3816 |
} |
| 3817 |
$this->addSimpleSelfServiceTextField($return, 'streetAddress', _('Street'), $fields, $attributes, $readOnlyFields, false, true); |
| 3818 |
$this->addSimpleSelfServiceTextField($return, 'st', _('State'), $fields, $attributes, $readOnlyFields); |
| 3819 |
$this->addSimpleSelfServiceTextField($return, 'l', _('Location'), $fields, $attributes, $readOnlyFields); |
| 3820 |
$this->addSimpleSelfServiceTextField($return, 'postOfficeBox', _('Post office box'), $fields, $attributes, $readOnlyFields); |
| 3821 |
$this->addSimpleSelfServiceTextField($return, 'postalCode', _('Postal code'), $fields, $attributes, $readOnlyFields); |
| 3822 |
$this->addSimpleSelfServiceTextField($return, 'department', _('Department'), $fields, $attributes, $readOnlyFields); |
| 3823 |
$this->addMultiValueSelfServiceTextField($return, 'departmentNumber', _('Department number'), $fields, $attributes, $readOnlyFields); |
| 3824 |
// last password change |
| 3825 |
$row = new htmlResponsiveRow(); |
| 3826 |
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('pwdLastSet', _('Last password change')))); |
| 3827 |
$row->addField(new htmlOutputText($this->formatPwdLastSet($attributes))); |
| 3828 |
$return['pwdLastSet'] = $row; |
| 3829 |
// password change required |
| 3830 |
$row = new htmlResponsiveRow(); |
| 3831 |
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('msds-userpasswordexpirytimecomputed', _('Password expiration')))); |
| 3832 |
$row->addField(new htmlOutputText($this->formatPasswordExpires($attributes))); |
| 3833 |
$return['msds-userpasswordexpirytimecomputed'] = $row; |
| 3834 |
// account expiration |
| 3835 |
$row = new htmlResponsiveRow(); |
| 3836 |
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('accountExpires', _('Account expiration date')))); |
| 3837 |
$row->addField(new htmlOutputText($this->formatAccountExpires($attributes))); |
| 3838 |
$return['accountExpires'] = $row; |
| 3839 |
if (in_array('proxyAddresses', $fields)) { |
| 3840 |
$proxyAddresses = []; |
| 3841 |
if (isset($attributes['proxyAddresses'])) { |
| 3842 |
$proxyAddresses = $attributes['proxyAddresses']; |
| 3843 |
} |
| 3844 |
array_map(htmlspecialchars(...), $proxyAddresses); |
| 3845 |
$row = new htmlResponsiveRow(); |
| 3846 |
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('proxyAddresses', _('Proxy-Addresses')))); |
| 3847 |
$row->addField(new htmlOutputText(implode('<br>', $proxyAddresses), false)); |
| 3848 |
$return['proxyAddresses'] = $row; |
| 3849 |
} |
| 3850 |
if (in_array('otherMailbox', $fields)) { |
| 3851 |
$otherMailbox = []; |
| 3852 |
if (isset($attributes['otherMailbox'])) { |
| 3853 |
$otherMailbox = $attributes['otherMailbox']; |
| 3854 |
} |
| 3855 |
array_map(htmlspecialchars(...), $otherMailbox); |
| 3856 |
$row = new htmlResponsiveRow(); |
| 3857 |
$row->addLabel(new htmlOutputText($this->getSelfServiceLabel('otherMailbox', _('Email alias')))); |
| 3858 |
$row->addField(new htmlOutputText(implode('<br>', $otherMailbox), false)); |
| 3859 |
$return['otherMailbox'] = $row; |
| 3860 |
} |
| 3861 |
return $return; |
| 3862 |
} |
| 3863 |
|
| 3864 |
/** |
| 3865 |
* {@inheritDoc} |
| 3866 |
*/ |
| 3867 |
public function checkSelfServiceOptions(array $fields, array $attributes, bool $passwordChangeOnly, array $readOnlyFields): array { |
| 3868 |
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []]; |
| 3869 |
if (in_array('unicodePwd', $fields) |
| 3870 |
&& isset($_POST['windowsUser_unicodePwd']) |
| 3871 |
&& ($_POST['windowsUser_unicodePwd'] != '')) { |
| 3872 |
if ($_POST['windowsUser_unicodePwd'] != $_POST['windowsUser_unicodePwd2']) { |
| 3873 |
$return['messages'][] = $this->messages['unicodePwd'][0]; |
| 3874 |
} |
| 3875 |
elseif (!get_preg($_POST['windowsUser_unicodePwd'], 'password')) { |
| 3876 |
$return['messages'][] = $this->messages['unicodePwd'][1]; |
| 3877 |
} |
| 3878 |
else { |
| 3879 |
$userName = empty($attributes['userPrincipalName'][0]) ? null : $attributes['userPrincipalName'][0]; |
| 3880 |
$additionalAttrs = []; |
| 3881 |
if (!empty($attributes['sn'][0])) { |
| 3882 |
$additionalAttrs[] = $attributes['sn'][0]; |
| 3883 |
} |
| 3884 |
if (!empty($attributes['givenName'][0])) { |
| 3885 |
$additionalAttrs[] = $attributes['givenName'][0]; |
| 3886 |
} |
| 3887 |
$pwdPolicyResult = checkPasswordStrength($_POST['windowsUser_unicodePwd'], $userName, $additionalAttrs); |
| 3888 |
if ($pwdPolicyResult->isValid()) { |
| 3889 |
$this->setSelfServicePassword($return); |
| 3890 |
$return['info']['userPasswordClearText'][0] = $_POST['windowsUser_unicodePwd']; |
| 3891 |
} |
| 3892 |
else { |
| 3893 |
$return['messages'][] = ['ERROR', $pwdPolicyResult->getTextMessage()]; |
| 3894 |
} |
| 3895 |
} |
| 3896 |
} |
| 3897 |
if ($passwordChangeOnly) { |
| 3898 |
return $return; // skip processing if only a password change is done |
| 3899 |
} |
| 3900 |
if (isset($attributes['street'])) { |
| 3901 |
$attributes['streetAddress'] = $attributes['street']; |
| 3902 |
} |
| 3903 |
$this->checkMultiValueSelfServiceTextField($return, 'roomnumber', $attributes, $fields, $readOnlyFields); |
| 3904 |
$this->checkSimpleSelfServiceTextField($return, 'personaltitle', $attributes, $fields, $readOnlyFields, 'title'); |
| 3905 |
$this->checkSimpleSelfServiceTextField($return, 'physicalDeliveryOfficeName', $attributes, $fields, $readOnlyFields); |
| 3906 |
$this->checkSimpleSelfServiceTextField($return, 'telephoneNumber', $attributes, $fields, $readOnlyFields, 'telephone'); |
| 3907 |
$this->checkSimpleSelfServiceTextField($return, 'facsimileTelephoneNumber', $attributes, $fields, $readOnlyFields, 'telephone'); |
| 3908 |
$this->checkSimpleSelfServiceTextField($return, 'wWWHomePage', $attributes, $fields, $readOnlyFields); |
| 3909 |
$this->checkSimpleSelfServiceTextField($return, 'streetAddress', $attributes, $fields, $readOnlyFields); |
| 3910 |
$this->checkSimpleSelfServiceTextField($return, 'st', $attributes, $fields, $readOnlyFields); |
| 3911 |
$this->checkSimpleSelfServiceTextField($return, 'l', $attributes, $fields, $readOnlyFields); |
| 3912 |
$this->checkSimpleSelfServiceTextField($return, 'postOfficeBox', $attributes, $fields, $readOnlyFields); |
| 3913 |
$this->checkSimpleSelfServiceTextField($return, 'postalCode', $attributes, $fields, $readOnlyFields, 'postalCode'); |
| 3914 |
$this->checkSimpleSelfServiceTextField($return, 'department', $attributes, $fields, $readOnlyFields); |
| 3915 |
$this->checkMultiValueSelfServiceTextField($return, 'departmentNumber', $attributes, $fields, $readOnlyFields); |
| 3916 |
return $return; |
| 3917 |
} |
| 3918 |
|
| 3919 |
/** |
| 3920 |
* Sets the user password in self-service. |
| 3921 |
* Since the change requires the old password we need to run ldapmodify for this task. |
| 3922 |
* |
| 3923 |
* @param array<string, array<string, string[]>|string[]> $return return value for checkSelfServiceOptions() (used to add message if any) |
| 3924 |
*/ |
| 3925 |
private function setSelfServicePassword(array &$return): void { |
| 3926 |
$newPasswordVal = self::pwdAttributeValue($_POST['windowsUser_unicodePwd']); |
| 3927 |
$oldPassword = lamDecrypt($_SESSION['selfService_clientPassword'], 'SelfService'); |
| 3928 |
$oldPasswordVal = self::pwdAttributeValue($oldPassword); |
| 3929 |
$dn = lamDecrypt($_SESSION['selfService_clientDN'], 'SelfService'); |
| 3930 |
$operation = [ |
| 3931 |
[ |
| 3932 |
'attrib' => 'unicodePwd', |
| 3933 |
'modtype' => LDAP_MODIFY_BATCH_REMOVE, |
| 3934 |
'values' => [$oldPasswordVal] |
| 3935 |
], |
| 3936 |
[ |
| 3937 |
'attrib' => 'unicodePwd', |
| 3938 |
'modtype' => LDAP_MODIFY_BATCH_ADD, |
| 3939 |
'values' => [$newPasswordVal] |
| 3940 |
] |
| 3941 |
]; |
| 3942 |
@ldap_modify_batch($_SESSION['ldapHandle']->getServer(), $dn, $operation); |
| 3943 |
$returnCode = ldap_errno($_SESSION['ldapHandle']->getServer()); |
| 3944 |
if ($returnCode !== 0) { |
| 3945 |
$outputMessages = htmlspecialchars(getExtendedLDAPErrorMessage($_SESSION['ldapHandle']->getServer())); |
| 3946 |
// Active Directory message translations |
| 3947 |
if ((str_contains($outputMessages, 'DSID-03190F80')) && (str_contains($outputMessages, 'unicodePwd'))) { |
| 3948 |
$outputMessages = _('Your password does not meet the password strength qualifications. Please retry with another one.') . '<br><br>' . $outputMessages; |
| 3949 |
} |
| 3950 |
logNewMessage(LOG_ERR, 'Changing user password failed: ' . $outputMessages); |
| 3951 |
$return['messages'][] = ['ERROR', _('Unable to change password.'), $outputMessages]; |
| 3952 |
} |
| 3953 |
else { |
| 3954 |
// update session password for next page load |
| 3955 |
$_SESSION['selfService_clientPasswordNew'] = $_POST['windowsUser_unicodePwd']; |
| 3956 |
if (isset($_SESSION['selfService_passwordExpired'])) { |
| 3957 |
unset($_SESSION['selfService_passwordExpired']); |
| 3958 |
} |
| 3959 |
$_SESSION['selfService_resetPasswordChangeOnly'] = true; |
| 3960 |
} |
| 3961 |
} |
| 3962 |
|
| 3963 |
/** |
| 3964 |
* {@inheritDoc} |
| 3965 |
*/ |
| 3966 |
public function managesPasswordAttributes(): bool { |
| 3967 |
return true; |
| 3968 |
} |
| 3969 |
|
| 3970 |
/** |
| 3971 |
* {@inheritDoc} |
| 3972 |
*/ |
| 3973 |
public function supportsForcePasswordChange(): bool { |
| 3974 |
return true; |
| 3975 |
} |
| 3976 |
|
| 3977 |
/** |
| 3978 |
* {@inheritDoc} |
| 3979 |
*/ |
| 3980 |
public function passwordChangeRequested(string $password, array $modules, bool $forcePasswordChange): array { |
| 3981 |
if (!in_array(static::class, $modules)) { |
| 3982 |
return []; |
| 3983 |
} |
| 3984 |
// check password strength |
| 3985 |
$user = empty($this->attributes['userPrincipalName'][0]) ? null : $this->attributes['userPrincipalName'][0]; |
| 3986 |
$additionalAttrs = []; |
| 3987 |
if (!empty($this->attributes['sn'][0])) { |
| 3988 |
$additionalAttrs[] = $this->attributes['sn'][0]; |
| 3989 |
} |
| 3990 |
if (!empty($this->attributes['givenName'][0])) { |
| 3991 |
$additionalAttrs[] = $this->attributes['givenName'][0]; |
| 3992 |
} |
| 3993 |
$checkResult = checkPasswordStrength($password, $user, $additionalAttrs); |
| 3994 |
if (!$checkResult->isValid()) { |
| 3995 |
return [['ERROR', $checkResult->getTextMessage()]]; |
| 3996 |
} |
| 3997 |
// set new password |
| 3998 |
$pwdBin = self::pwdAttributeValue($password); |
| 3999 |
$this->orig['unicodePwd'][0] = 'unknown'; |
| 4000 |
$this->attributes['unicodePwd'][0] = $pwdBin; |
| 4001 |
$this->attributes['pwdLastSet'][0] = '-1'; |
| 4002 |
if ($forcePasswordChange) { |
| 4003 |
$this->attributes['pwdLastSet'][0] = '0'; |
| 4004 |
} |
| 4005 |
$this->clearTextPassword = $password; |
| 4006 |
return []; |
| 4007 |
} |
| 4008 |
|
| 4009 |
/** |
| 4010 |
* Creates the LDAP password value. |
| 4011 |
* |
| 4012 |
* @param string $password password |
| 4013 |
*/ |
| 4014 |
public static function pwdAttributeValue(string $password): string { |
| 4015 |
return convertUtf8ToUtf16Le('"' . $password . '"'); |
| 4016 |
} |
| 4017 |
|
| 4018 |
/** |
| 4019 |
* Returns if the account is currently deactivated. |
| 4020 |
* |
| 4021 |
* @param array<string, string[]|string> $attrs LDAP attributes |
| 4022 |
* @return bool is deactivated |
| 4023 |
*/ |
| 4024 |
public static function isDeactivated(array $attrs): bool { |
| 4025 |
$myAttrs = array_change_key_case($attrs); |
| 4026 |
if (!isset($myAttrs['useraccountcontrol'][0])) { |
| 4027 |
return false; |
| 4028 |
} |
| 4029 |
return (intval($myAttrs['useraccountcontrol'][0]) & self::AC_ACCOUNT_DISABLED) === self::AC_ACCOUNT_DISABLED; |
| 4030 |
} |
| 4031 |
|
| 4032 |
/** |
| 4033 |
* Returns if the account is currently deactivated. |
| 4034 |
* |
| 4035 |
* @param array<string, string[]|string> $attrs LDAP attributes |
| 4036 |
* @return DateTime|false false or locked till |
| 4037 |
*/ |
| 4038 |
public static function getPasswordLocked(array $attrs): DateTime|false { |
| 4039 |
if (empty($attrs['lockouttime'][0])) { |
| 4040 |
return false; |
| 4041 |
} |
| 4042 |
$lockoutDuration = self::getDomainLockoutDuration(); |
| 4043 |
if (empty($lockoutDuration) || ($lockoutDuration > -1)) { |
| 4044 |
return false; |
| 4045 |
} |
| 4046 |
$lockoutDurationSeconds = substr($lockoutDuration, 0, -7); |
| 4047 |
$lockoutTime = self::getFileTime($attrs['lockouttime'][0]); |
| 4048 |
$unlockTime = clone $lockoutTime; |
| 4049 |
$unlockTime->add(new DateInterval('PT' . abs((int) $lockoutDurationSeconds) . 'S')); |
| 4050 |
$now = new DateTime('now', getTimeZone()); |
| 4051 |
if ($unlockTime > $now) { |
| 4052 |
$unlockTime->setTimezone(getTimeZone()); |
| 4053 |
return $unlockTime; |
| 4054 |
} |
| 4055 |
return false; |
| 4056 |
} |
| 4057 |
|
| 4058 |
/** |
| 4059 |
* Returns the domain lockout duration for this DN. |
| 4060 |
* |
| 4061 |
* @return string|null lockout duration |
| 4062 |
*/ |
| 4063 |
private static function getDomainLockoutDuration(): ?string { |
| 4064 |
if (!isset($_SESSION['windowsUser_cacheDomainLockoutDuration'])) { |
| 4065 |
$lockoutValue = self::getDomainPolicyAttribute('lockoutduration'); |
| 4066 |
$lockoutValue = $lockoutValue[0] ?? null; |
| 4067 |
$_SESSION['windowsUser_cacheDomainLockoutDuration'] = $lockoutValue; |
| 4068 |
} |
| 4069 |
return $_SESSION['windowsUser_cacheDomainLockoutDuration']; |
| 4070 |
} |
| 4071 |
|
| 4072 |
/** |
| 4073 |
* Returns the value of a domain policy attribute. |
| 4074 |
* |
| 4075 |
* @param string $attributeName attribute name |
| 4076 |
* @return string[] value |
| 4077 |
*/ |
| 4078 |
public static function getDomainPolicyAttribute(string $attributeName): array { |
| 4079 |
$attributeName = strtolower($attributeName); |
| 4080 |
$rootDSE = ldapGetDN("", ['defaultnamingcontext']); |
| 4081 |
if (empty($rootDSE['defaultnamingcontext'][0])) { |
| 4082 |
return []; |
| 4083 |
} |
| 4084 |
$namingContext = $rootDSE['defaultnamingcontext'][0]; |
| 4085 |
$policyOptions = ldapGetDN($namingContext, [$attributeName]); |
| 4086 |
if (!isset($policyOptions[$attributeName])) { |
| 4087 |
return []; |
| 4088 |
} |
| 4089 |
return $policyOptions[$attributeName]; |
| 4090 |
} |
| 4091 |
|
| 4092 |
/** |
| 4093 |
* Unlocks the user password. This resets 'lockoutTime' to 0. |
| 4094 |
* |
| 4095 |
* @param array<string, array<string>|string>|null $attributes LDAP attributes |
| 4096 |
*/ |
| 4097 |
public function unlockPassword(?array &$attributes = null): void { |
| 4098 |
if ($attributes === null) { |
| 4099 |
$attributes = &$this->attributes; |
| 4100 |
} |
| 4101 |
if (!empty($attributes['lockouttime'][0])) { |
| 4102 |
$attributes['lockouttime'][0] = '0'; |
| 4103 |
} |
| 4104 |
} |
| 4105 |
|
| 4106 |
/** |
| 4107 |
* Sets if the account is currently deactivated. |
| 4108 |
* |
| 4109 |
* @param bool $deactivated is deactivated |
| 4110 |
* @param array<string, array<string>|string>|null $attrs LDAP attributes to modify (default $this->attributes) |
| 4111 |
*/ |
| 4112 |
public function setIsDeactivated(bool $deactivated, ?array &$attrs = null): void { |
| 4113 |
if ($attrs === null) { |
| 4114 |
$attrs = &$this->attributes; |
| 4115 |
} |
| 4116 |
foreach ($attrs as $key => $value) { |
| 4117 |
if (strtolower($key) === 'useraccountcontrol') { |
| 4118 |
if ($deactivated) { |
| 4119 |
$attrs[$key][0] = (string) (intval($value[0]) | self::AC_ACCOUNT_DISABLED); |
| 4120 |
} |
| 4121 |
elseif ((intval($value[0]) & self::AC_ACCOUNT_DISABLED) !== 0) { |
| 4122 |
$attrs[$key][0] = (string) (intval($value[0]) - self::AC_ACCOUNT_DISABLED); |
| 4123 |
} |
| 4124 |
} |
| 4125 |
} |
| 4126 |
} |
| 4127 |
|
| 4128 |
/** |
| 4129 |
* Returns if the account requires a smartcard to login. |
| 4130 |
* |
| 4131 |
* @param array<string, string[]|string> $attrs LDAP attributes |
| 4132 |
* @return bool requires a smartcard |
| 4133 |
*/ |
| 4134 |
public static function isSmartCardRequired(array $attrs): bool { |
| 4135 |
if (!isset($attrs['useraccountcontrol'][0])) { |
| 4136 |
return false; |
| 4137 |
} |
| 4138 |
return (intval($attrs['useraccountcontrol'][0]) & self::AC_SMARTCARD_REQUIRED) === self::AC_SMARTCARD_REQUIRED; |
| 4139 |
} |
| 4140 |
|
| 4141 |
/** |
| 4142 |
* Sets if the account requires a smartcard to login. |
| 4143 |
* |
| 4144 |
* @param array<string, string[]|string> $attrs LDAP attributes to modify |
| 4145 |
* @param bool $requireCard requires a smartcard |
| 4146 |
*/ |
| 4147 |
public static function setIsSmartCardRequired(array &$attrs, bool $requireCard): void { |
| 4148 |
foreach ($attrs as $key => $value) { |
| 4149 |
if (strtolower($key) === 'useraccountcontrol') { |
| 4150 |
if ($requireCard) { |
| 4151 |
$attrs[$key][0] = (string) (intval($value[0]) | self::AC_SMARTCARD_REQUIRED); |
| 4152 |
} |
| 4153 |
elseif ((intval($value[0]) & self::AC_SMARTCARD_REQUIRED) !== 0) { |
| 4154 |
$attrs[$key][0] = (string) (intval($value[0]) - self::AC_SMARTCARD_REQUIRED); |
| 4155 |
} |
| 4156 |
} |
| 4157 |
} |
| 4158 |
} |
| 4159 |
|
| 4160 |
/** |
| 4161 |
* Returns if the account never expires. |
| 4162 |
* |
| 4163 |
* @param array<string, string[]|string> $attrs LDAP attributes |
| 4164 |
* @return bool never expires |
| 4165 |
*/ |
| 4166 |
public static function isNeverExpiring(array $attrs): bool { |
| 4167 |
if (!isset($attrs['useraccountcontrol'][0])) { |
| 4168 |
return false; |
| 4169 |
} |
| 4170 |
return (intval($attrs['useraccountcontrol'][0]) & self::AC_PWD_NEVER_EXPIRES) === self::AC_PWD_NEVER_EXPIRES; |
| 4171 |
} |
| 4172 |
|
| 4173 |
/** |
| 4174 |
* Sets if the account never expires. |
| 4175 |
* |
| 4176 |
* @param array<string, string[]|string> $attrs LDAP attributes to modify |
| 4177 |
* @param bool $neverExpires never expires |
| 4178 |
*/ |
| 4179 |
public static function setIsNeverExpiring(array &$attrs, bool $neverExpires): void { |
| 4180 |
foreach ($attrs as $key => $value) { |
| 4181 |
if (strtolower($key) === 'useraccountcontrol') { |
| 4182 |
if ($neverExpires) { |
| 4183 |
$attrs[$key][0] = (string) (intval($value[0]) | self::AC_PWD_NEVER_EXPIRES); |
| 4184 |
} |
| 4185 |
elseif ((intval($value[0]) & self::AC_PWD_NEVER_EXPIRES) !== 0) { |
| 4186 |
$attrs[$key][0] = (string) (intval($value[0]) - self::AC_PWD_NEVER_EXPIRES); |
| 4187 |
} |
| 4188 |
} |
| 4189 |
} |
| 4190 |
} |
| 4191 |
|
| 4192 |
/** |
| 4193 |
* Finds all existing groups. |
| 4194 |
* |
| 4195 |
* @return string[] group DNs |
| 4196 |
*/ |
| 4197 |
private function findGroups(): array { |
| 4198 |
if ($this->groupCache != null) { |
| 4199 |
return $this->groupCache; |
| 4200 |
} |
| 4201 |
$return = []; |
| 4202 |
$types = ['group']; |
| 4203 |
$results = searchLDAPByFilter('(objectClass=group)', ['dn'], $types); |
| 4204 |
$count = count($results); |
| 4205 |
for ($i = 0; $i < $count; $i++) { |
| 4206 |
if (isset($results[$i]['dn'])) { |
| 4207 |
$return[] = $results[$i]['dn']; |
| 4208 |
} |
| 4209 |
} |
| 4210 |
$this->groupCache = $return; |
| 4211 |
return $return; |
| 4212 |
} |
| 4213 |
|
| 4214 |
/** |
| 4215 |
* Gets the list of possible domains from the config setting. |
| 4216 |
* |
| 4217 |
* @return string[] domain list |
| 4218 |
*/ |
| 4219 |
private function getDomains(): array { |
| 4220 |
$domains = []; |
| 4221 |
if (!empty($this->moduleSettings['windowsUser_domains'])) { |
| 4222 |
foreach ($this->moduleSettings['windowsUser_domains'] as $domain) { |
| 4223 |
$domain = trim(str_replace('@', '', $domain)); |
| 4224 |
if (!empty($domain)) { |
| 4225 |
$domains[] = $domain; |
| 4226 |
} |
| 4227 |
} |
| 4228 |
} |
| 4229 |
return array_values(array_unique($domains)); |
| 4230 |
} |
| 4231 |
|
| 4232 |
/** |
| 4233 |
* Returns a list of all usernames in LDAP. |
| 4234 |
* |
| 4235 |
* @return array<string, string> user names |
| 4236 |
*/ |
| 4237 |
private function getUserNames(): array { |
| 4238 |
if ($this->cachedUserNameList !== null) { |
| 4239 |
return $this->cachedUserNameList; |
| 4240 |
} |
| 4241 |
$this->cachedUserNameList = []; |
| 4242 |
$attrs = ['userPrincipalName']; |
| 4243 |
$filter = '(&(objectClass=user)(userPrincipalName=*))'; |
| 4244 |
$typeManager = new TypeManager(); |
| 4245 |
$typesUser = $typeManager->getConfiguredTypesForScope('user'); |
| 4246 |
$suffixes = []; |
| 4247 |
foreach ($typesUser as $type) { |
| 4248 |
$suffixes[] = $type->getSuffix(); |
| 4249 |
} |
| 4250 |
$suffixes = array_unique($suffixes); |
| 4251 |
foreach ($suffixes as $suffix) { |
| 4252 |
$result = searchLDAP($suffix, $filter, $attrs); |
| 4253 |
foreach ($result as $resultEntry) { |
| 4254 |
$this->cachedUserNameList[$resultEntry['userprincipalname'][0]] = $resultEntry['dn']; |
| 4255 |
} |
| 4256 |
} |
| 4257 |
return $this->cachedUserNameList; |
| 4258 |
} |
| 4259 |
|
| 4260 |
/** |
| 4261 |
* Returns a list of all CNs in LDAP. |
| 4262 |
* |
| 4263 |
* @return array<string, string> CN list |
| 4264 |
*/ |
| 4265 |
private function getCns(): array { |
| 4266 |
if ($this->cachedCnList != null) { |
| 4267 |
return $this->cachedCnList; |
| 4268 |
} |
| 4269 |
$this->cachedCnList = []; |
| 4270 |
$attrs = ['cn']; |
| 4271 |
$filter = '(&(objectClass=user)(cn=*))'; |
| 4272 |
$typeManager = new TypeManager(); |
| 4273 |
$typesUser = $typeManager->getConfiguredTypesForScope('user'); |
| 4274 |
$suffixes = []; |
| 4275 |
foreach ($typesUser as $type) { |
| 4276 |
$suffixes[] = $type->getSuffix(); |
| 4277 |
} |
| 4278 |
$suffixes = array_unique($suffixes); |
| 4279 |
foreach ($suffixes as $suffix) { |
| 4280 |
$result = searchLDAP($suffix, $filter, $attrs); |
| 4281 |
foreach ($result as $resultEntry) { |
| 4282 |
$this->cachedCnList[$resultEntry['cn'][0]] = $resultEntry['dn']; |
| 4283 |
} |
| 4284 |
} |
| 4285 |
return $this->cachedCnList; |
| 4286 |
} |
| 4287 |
|
| 4288 |
/** |
| 4289 |
* Returns the formatted value for last password change. |
| 4290 |
* |
| 4291 |
* @param array<string, string[]|string>|null $attributes user attributes ($this->attributes if null) |
| 4292 |
* @return string last password change or " - " |
| 4293 |
*/ |
| 4294 |
private function formatPwdLastSet(?array $attributes = null): string { |
| 4295 |
if ($attributes == null) { |
| 4296 |
$attributes = &$this->attributes; |
| 4297 |
} |
| 4298 |
if (!empty($attributes['pwdlastset'][0])) { |
| 4299 |
return $this->formatFileTime($attributes['pwdlastset'][0]); |
| 4300 |
} |
| 4301 |
elseif (empty($attributes['pwdLastSet'][0])) { |
| 4302 |
return ' - '; |
| 4303 |
} |
| 4304 |
return $this->formatFileTime($attributes['pwdLastSet'][0]); |
| 4305 |
} |
| 4306 |
|
| 4307 |
/** |
| 4308 |
* Returns the formatted value for last login. |
| 4309 |
* |
| 4310 |
* @return string last login or " - " |
| 4311 |
*/ |
| 4312 |
private function formatLastLogonTimestamp(): string { |
| 4313 |
if (empty($this->attributes['lastLogonTimestamp'][0])) { |
| 4314 |
return ' - '; |
| 4315 |
} |
| 4316 |
return $this->formatFileTime($this->attributes['lastLogonTimestamp'][0]); |
| 4317 |
} |
| 4318 |
|
| 4319 |
/** |
| 4320 |
* Returns the formatted value for the account expiration date. |
| 4321 |
* |
| 4322 |
* @param array<string, string[]|string>|null $attributes user attributes ($this->attributes if null) |
| 4323 |
* @return string date or - |
| 4324 |
*/ |
| 4325 |
private function formatAccountExpires(?array $attributes = null): string { |
| 4326 |
if ($attributes === null) { |
| 4327 |
$attributes = &$this->attributes; |
| 4328 |
} |
| 4329 |
if (empty($attributes['accountexpires'][0]) |
| 4330 |
|| ($attributes['accountexpires'][0] === self::ACCOUNT_DOES_NOT_EXPIRE)) { |
| 4331 |
return ' - '; |
| 4332 |
} |
| 4333 |
return $this->formatFileTime($attributes['accountexpires'][0]); |
| 4334 |
} |
| 4335 |
|
| 4336 |
/** |
| 4337 |
* Returns the formatted value for the password expiration date. |
| 4338 |
* |
| 4339 |
* @param array<string, string[]|string>|null $attributes user attributes ($this->attributes if null) |
| 4340 |
* @return string date or - |
| 4341 |
*/ |
| 4342 |
private function formatPasswordExpires(?array $attributes = null): string { |
| 4343 |
if ($attributes === null) { |
| 4344 |
$attributes = &$this->attributes; |
| 4345 |
} |
| 4346 |
if (empty($attributes['msds-userpasswordexpirytimecomputed'][0]) |
| 4347 |
|| ($attributes['msds-userpasswordexpirytimecomputed'][0] === self::ACCOUNT_DOES_NOT_EXPIRE)) { |
| 4348 |
return ' - '; |
| 4349 |
} |
| 4350 |
return $this->formatFileTime($attributes['msds-userpasswordexpirytimecomputed'][0]); |
| 4351 |
} |
| 4352 |
|
| 4353 |
/** |
| 4354 |
* Formats a value in file time (100 ns since 1601-01-01). |
| 4355 |
* |
| 4356 |
* @param string $value time value |
| 4357 |
* @return string formatted value |
| 4358 |
*/ |
| 4359 |
private function formatFileTime(string $value): string { |
| 4360 |
if (empty($value) || ($value === '-1')) { |
| 4361 |
return ''; |
| 4362 |
} |
| 4363 |
$seconds = substr($value, 0, -7); |
| 4364 |
$time = new DateTime('1601-01-01', new DateTimeZone('UTC')); |
| 4365 |
$time->add(new DateInterval('PT' . $seconds . 'S')); |
| 4366 |
$time->setTimezone(getTimeZone()); |
| 4367 |
return $time->format('Y-m-d H:i:s'); |
| 4368 |
} |
| 4369 |
|
| 4370 |
/** |
| 4371 |
* Returns a value in file time (100 ns since 1601-01-01). |
| 4372 |
* |
| 4373 |
* @param string $value time value as int |
| 4374 |
* @return DateTime|null time value |
| 4375 |
*/ |
| 4376 |
public static function getFileTime($value): ?DateTime { |
| 4377 |
if (empty($value) || !get_preg($value, 'digit')) { |
| 4378 |
return null; |
| 4379 |
} |
| 4380 |
$seconds = substr($value, 0, -7); |
| 4381 |
$time = new DateTime('1601-01-01', new DateTimeZone('UTC')); |
| 4382 |
$time->add(new DateInterval('PT' . $seconds . 'S')); |
| 4383 |
$time->setTimezone(getTimeZone()); |
| 4384 |
return $time; |
| 4385 |
} |
| 4386 |
|
| 4387 |
/** |
| 4388 |
* Sets the expiration date of this account. |
| 4389 |
* If all parameters are null, the expiration date will be removed. |
| 4390 |
* |
| 4391 |
* @param int|null $year year (e.g. 2040) |
| 4392 |
* @param int|null $month month (e.g. 8) |
| 4393 |
* @param int|null $day day (e.g. 27) |
| 4394 |
*/ |
| 4395 |
public function setExpirationDate(?int $year, ?int $month, ?int $day): void { |
| 4396 |
if (($year === null) && ($month === null) && ($day === null)) { |
| 4397 |
unset($this->attributes['accountexpires']); |
| 4398 |
return; |
| 4399 |
} |
| 4400 |
$this->attributes['accountexpires'][0] = $this->buildExpirationDate($year, $month, $day); |
| 4401 |
} |
| 4402 |
|
| 4403 |
/** |
| 4404 |
* Builds the value for the expiration date. |
| 4405 |
* |
| 4406 |
* @param int $year year |
| 4407 |
* @param int $month month |
| 4408 |
* @param int $day day |
| 4409 |
* @return string date value |
| 4410 |
*/ |
| 4411 |
private function buildExpirationDate(int $year, int $month, int $day): string { |
| 4412 |
$timeBase = new DateTime('1601-01-01', getTimeZone()); |
| 4413 |
$time = new DateTime("$year-$month-$day", getTimeZone()); |
| 4414 |
$timeDiff = $time->diff($timeBase); |
| 4415 |
$days = (int) $timeDiff->format('%a'); |
| 4416 |
$seconds = $days * 24 * 3600 - ($time->getOffset()); |
| 4417 |
return $seconds . '0000000'; |
| 4418 |
} |
| 4419 |
|
| 4420 |
/** |
| 4421 |
* {@inheritDoc} |
| 4422 |
*/ |
| 4423 |
public function get_configOptions(array $scopes, array $allScopes): htmlElement|array { |
| 4424 |
$typeManager = new TypeManager($_SESSION['conf_config']); |
| 4425 |
// configuration options |
| 4426 |
$configContainer = new htmlResponsiveRow(); |
| 4427 |
$configContainer->add(new htmlResponsiveInputTextarea('windowsUser_domains', '', 30, 3, _('Domains'), 'domains')); |
| 4428 |
$displayOptions = [ |
| 4429 |
'dn' => self::DISPLAY_GROUPS_DN, |
| 4430 |
'cn' => self::DISPLAY_GROUPS_CN, |
| 4431 |
]; |
| 4432 |
$groupDisplaySelect = new htmlResponsiveSelect('windowsUser_displayGroups', $displayOptions, [], _('Display format'), 'displayGroups'); |
| 4433 |
$groupDisplaySelect->setHasDescriptiveElements(true); |
| 4434 |
$configContainer->add($groupDisplaySelect); |
| 4435 |
$configHiddenGroup = new htmlGroup(); |
| 4436 |
$configHiddenGroup->addElement(new htmlOutputText(_('Hidden options'))); |
| 4437 |
$configHiddenGroup->addElement(new htmlHelpLink('hiddenOptions')); |
| 4438 |
$configContainer->add($configHiddenGroup); |
| 4439 |
$hiddenOptions = []; |
| 4440 |
$hiddenOptions[_('Personal title')] = ['windowsUser_hidepersonaltitle', true]; |
| 4441 |
$hiddenOptions[_('Display name')] = ['windowsUser_hidedisplayName', false]; |
| 4442 |
$hiddenOptions[_('Proxy-Addresses')] = ['windowsUser_hideproxyAddresses', true]; |
| 4443 |
$hiddenOptions[_('Fax number')] = ['windowsUser_hidefacsimileTelephoneNumber', false]; |
| 4444 |
$hiddenOptions[_('Mobile')] = ['windowsUser_hidemobile', false]; |
| 4445 |
$hiddenOptions[_('Other mobiles')] = ['windowsUser_hideotherMobile', true]; |
| 4446 |
$hiddenOptions[_('Pager')] = ['windowsUser_hidepager', true]; |
| 4447 |
$hiddenOptions[_('Other pagers')] = ['windowsUser_hideotherPager', true]; |
| 4448 |
$hiddenOptions[_('User name (pre W2K)')] = ['windowsUser_hidesAMAccountName', true]; |
| 4449 |
$hiddenOptions[_('NIS name')] = ['windowsUser_hidemsSFU30Name', true]; |
| 4450 |
$hiddenOptions[_('NIS domain')] = ['windowsUser_hidemsSFU30NisDomain', true]; |
| 4451 |
$hiddenOptions[_('Last password change')] = ['windowsUser_hidepwdLastSet', false]; |
| 4452 |
$hiddenOptions[_('Password expiration')] = ['windowsUser_hidepwdChangeRequired', false]; |
| 4453 |
$hiddenOptions[_('Last login')] = ['windowsUser_hidelastLogonTimestamp', false]; |
| 4454 |
$hiddenOptions[_('Logon hours')] = ['windowsUser_hidelogonHours', false]; |
| 4455 |
$hiddenOptions[_('Workstations')] = ['windowsUser_hideWorkstations', false]; |
| 4456 |
$hiddenOptions[_('Photo')] = ['windowsUser_hidejpegPhoto', true]; |
| 4457 |
$hiddenOptions[_('Thumbnail')] = ['windowsUser_hidethumbnailphoto', true]; |
| 4458 |
$hiddenOptions[_('Job title')] = ['windowsUser_hidetitle', true]; |
| 4459 |
$hiddenOptions[_('Room number')] = ['windowsUser_hideroomnumber', true]; |
| 4460 |
$hiddenOptions[_('Car license')] = ['windowsUser_hidecarLicense', true]; |
| 4461 |
$hiddenOptions[_('Employee number')] = ['windowsUser_hideemployeeNumber', true]; |
| 4462 |
$hiddenOptions[_('Employee type')] = ['windowsUser_hideemployeeType', true]; |
| 4463 |
$hiddenOptions[_('Business category')] = ['windowsUser_hidebusinessCategory', true]; |
| 4464 |
$hiddenOptions[_('Company')] = ['windowsUser_hidecompany', true]; |
| 4465 |
$hiddenOptions[_('Department')] = ['windowsUser_hidedepartment', true]; |
| 4466 |
$hiddenOptions[_('Department number')] = ['windowsUser_hidedepartmentNumber', true]; |
| 4467 |
$hiddenOptions[_('Organisational unit')] = ['windowsUser_hideou', true]; |
| 4468 |
$hiddenOptions[_('Organisation')] = ['windowsUser_hideo', true]; |
| 4469 |
$hiddenOptions[_('Manager')] = ['windowsUser_hidemanager', true]; |
| 4470 |
$hiddenOptions[_('Profile path')] = ['windowsUser_hideprofilePath', false]; |
| 4471 |
$hiddenOptions[_('Logon script')] = ['windowsUser_hidescriptPath', false]; |
| 4472 |
$hiddenOptions[_('Home drive')] = ['windowsUser_hidehomeDrive', false]; |
| 4473 |
$hiddenOptions[_('Home directory')] = ['windowsUser_hidehomeDirectory', false]; |
| 4474 |
$hiddenOptions[_('Initials')] = ['windowsUser_hideinitials', false]; |
| 4475 |
$hiddenOptions[_('Description')] = ['windowsUser_hidedescription', false]; |
| 4476 |
$hiddenOptions[_('Street')] = ['windowsUser_hidestreetAddress', false]; |
| 4477 |
$hiddenOptions[_('Post office box')] = ['windowsUser_hidepostOfficeBox', false]; |
| 4478 |
$hiddenOptions[_('Postal code')] = ['windowsUser_hidepostalCode', false]; |
| 4479 |
$hiddenOptions[_('Location')] = ['windowsUser_hidel', false]; |
| 4480 |
$hiddenOptions[_('State')] = ['windowsUser_hidest', false]; |
| 4481 |
$hiddenOptions[_('Office name')] = ['windowsUser_hidephysicalDeliveryOfficeName', false]; |
| 4482 |
$hiddenOptions[_('Email address')] = ['windowsUser_hidemail', false]; |
| 4483 |
$hiddenOptions[_('Email alias')] = ['windowsUser_hideotherMailbox', false]; |
| 4484 |
$hiddenOptions[_('Telephone number')] = ['windowsUser_hidetelephoneNumber', false]; |
| 4485 |
$hiddenOptions[_('Other telephone numbers')] = ['windowsUser_hideotherTelephone', false]; |
| 4486 |
$hiddenOptions[_('Web site')] = ['windowsUser_hidewWWHomePage', false]; |
| 4487 |
$hiddenOptions[_('Other web sites')] = ['windowsUser_hideurl', false]; |
| 4488 |
$hiddenOptions[_('Require smartcard')] = ['windowsUser_hideRequireSmartcard', false]; |
| 4489 |
ksort($hiddenOptions); |
| 4490 |
foreach ($hiddenOptions as $hiddenOptionLabel => $hiddenOption) { |
| 4491 |
$configContainer->add(new htmlResponsiveInputCheckbox($hiddenOption[0], $hiddenOption[1], $hiddenOptionLabel, null, true), 12, 4); |
| 4492 |
} |
| 4493 |
$syncTypes = $typeManager->getConfiguredTypesForScopes(['group', 'gon', 'user']); |
| 4494 |
$syncActive = false; |
| 4495 |
$possibleSyncModules = ['groupOfNames', 'groupOfMembers', 'groupOfUniqueNames', 'posixAccount']; |
| 4496 |
foreach ($syncTypes as $syncType) { |
| 4497 |
$modules = $syncType->getModules(); |
| 4498 |
foreach ($possibleSyncModules as $possibleModule) { |
| 4499 |
if (in_array($possibleModule, $modules)) { |
| 4500 |
$syncActive = true; |
| 4501 |
break; |
| 4502 |
} |
| 4503 |
} |
| 4504 |
} |
| 4505 |
if ($syncActive) { |
| 4506 |
$syncGroupsCheckbox = new htmlResponsiveInputCheckbox('windowsUser_syncGroups', false, _('Sync groups'), null, true); |
| 4507 |
$syncGroupsCheckbox->setTableRowsToHide(['windowsUser_syncGroupsExclusions']); |
| 4508 |
$configContainer->add($syncGroupsCheckbox, 12, 4); |
| 4509 |
$configContainer->addVerticalSpacer('2rem'); |
| 4510 |
$configContainer->add(new htmlResponsiveInputTextarea('windowsUser_syncGroupsExclusions', '', 20, 4, _('Exclude from group sync'), 'excludeFromGroupSync')); |
| 4511 |
} |
| 4512 |
$advancedOptions = new htmlResponsiveRow(); |
| 4513 |
$advancedOptions->add(new htmlSubTitle(_('Photo'))); |
| 4514 |
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'windowsUser_jpegPhoto_maxWidth', null, 'crop')); |
| 4515 |
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'windowsUser_jpegPhoto_maxHeight', null, 'crop')); |
| 4516 |
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'windowsUser_jpegPhoto_maxSize')); |
| 4517 |
$advancedOptions->add(new htmlSubTitle(_('Thumbnail'))); |
| 4518 |
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum width (px)'), 'windowsUser_thumbnailphoto_maxWidth', '96', 'crop')); |
| 4519 |
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum height (px)'), 'windowsUser_thumbnailphoto_maxHeight', '96', 'crop')); |
| 4520 |
$advancedOptions->add(new htmlResponsiveInputField(_('Maximum file size (kB)'), 'windowsUser_thumbnailphoto_maxSize')); |
| 4521 |
$advancedOptionsAccordion = new htmlAccordion('windowsUserAdvancedOptions', [_('Advanced options') => $advancedOptions], false); |
| 4522 |
$configContainer->add($advancedOptionsAccordion); |
| 4523 |
return $configContainer; |
| 4524 |
} |
| 4525 |
|
| 4526 |
/** |
| 4527 |
* Loads cached data from LDAP such as departmets etc. |
| 4528 |
*/ |
| 4529 |
private function initCache(): void { |
| 4530 |
if ($this->departmentCache != null) { |
| 4531 |
return; |
| 4532 |
} |
| 4533 |
$attrs = []; |
| 4534 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartment', true)) { |
| 4535 |
$attrs[] = 'department'; |
| 4536 |
} |
| 4537 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidedepartmentNumber', true)) { |
| 4538 |
$attrs[] = 'departmentNumber'; |
| 4539 |
} |
| 4540 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideou', true)) { |
| 4541 |
$attrs[] = 'ou'; |
| 4542 |
} |
| 4543 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideo', true)) { |
| 4544 |
$attrs[] = 'o'; |
| 4545 |
} |
| 4546 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidetitle', true)) { |
| 4547 |
$attrs[] = 'title'; |
| 4548 |
} |
| 4549 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hideemployeeType', true)) { |
| 4550 |
$attrs[] = 'employeeType'; |
| 4551 |
} |
| 4552 |
if (!$this->isBooleanConfigOptionSet('windowsUser_hidebusinessCategory', true)) { |
| 4553 |
$attrs[] = 'businessCategory'; |
| 4554 |
} |
| 4555 |
$departments = []; |
| 4556 |
$departmentNumbers = []; |
| 4557 |
$ous = []; |
| 4558 |
$os = []; |
| 4559 |
$titles = []; |
| 4560 |
$employeeTypes = []; |
| 4561 |
$businessCategories = []; |
| 4562 |
if ($attrs !== []) { |
| 4563 |
$result = searchLDAPByFilter('(objectClass=user)', $attrs, [$this->get_scope()]); |
| 4564 |
foreach ($result as $attributes) { |
| 4565 |
if (isset($attributes['department'])) { |
| 4566 |
foreach ($attributes['department'] as $val) { |
| 4567 |
$departments[] = $val; |
| 4568 |
} |
| 4569 |
} |
| 4570 |
if (isset($attributes['departmentnumber'])) { |
| 4571 |
foreach ($attributes['departmentnumber'] as $val) { |
| 4572 |
$departmentNumbers[] = $val; |
| 4573 |
} |
| 4574 |
} |
| 4575 |
if (isset($attributes['ou'])) { |
| 4576 |
foreach ($attributes['ou'] as $val) { |
| 4577 |
$ous[] = $val; |
| 4578 |
} |
| 4579 |
} |
| 4580 |
if (isset($attributes['o'])) { |
| 4581 |
foreach ($attributes['o'] as $val) { |
| 4582 |
$os[] = $val; |
| 4583 |
} |
| 4584 |
} |
| 4585 |
if (isset($attributes['title'])) { |
| 4586 |
foreach ($attributes['title'] as $val) { |
| 4587 |
$titles[] = $val; |
| 4588 |
} |
| 4589 |
} |
| 4590 |
if (isset($attributes['employeetype'])) { |
| 4591 |
foreach ($attributes['employeetype'] as $val) { |
| 4592 |
$employeeTypes[] = $val; |
| 4593 |
} |
| 4594 |
} |
| 4595 |
if (isset($attributes['businesscategory'])) { |
| 4596 |
foreach ($attributes['businesscategory'] as $val) { |
| 4597 |
$businessCategories[] = $val; |
| 4598 |
} |
| 4599 |
} |
| 4600 |
} |
| 4601 |
} |
| 4602 |
$this->departmentCache = array_values(array_unique($departments)); |
| 4603 |
$this->departmentNumberCache = array_values(array_unique($departmentNumbers)); |
| 4604 |
$this->oCache = array_values(array_unique($os)); |
| 4605 |
$this->ouCache = array_values(array_unique($ous)); |
| 4606 |
$this->titleCache = array_values(array_unique($titles)); |
| 4607 |
$this->employeeTypeCache = array_values(array_unique($employeeTypes)); |
| 4608 |
$this->businessCategoryCache = array_values(array_unique($businessCategories)); |
| 4609 |
} |
| 4610 |
|
| 4611 |
/** |
| 4612 |
* {@inheritDoc} |
| 4613 |
*/ |
| 4614 |
public function getSupportedJobs(LAMConfig $config): array { |
| 4615 |
return [ |
| 4616 |
new WindowsPasswordNotifyJob(), |
| 4617 |
new WindowsAccountExpirationCleanupJob(), |
| 4618 |
new WindowsAccountExpirationNotifyJob(), |
| 4619 |
new WindowsManagedGroupsNotifyJob() |
| 4620 |
]; |
| 4621 |
} |
| 4622 |
|
| 4623 |
/** |
| 4624 |
* {@inheritdoc} |
| 4625 |
*/ |
| 4626 |
public function getWildCardReplacements(): array { |
| 4627 |
$replacements = []; |
| 4628 |
// personal title |
| 4629 |
if (!empty($_POST['personaltitle'])) { |
| 4630 |
$replacements['personaltitle'] = $_POST['personaltitle']; |
| 4631 |
} |
| 4632 |
elseif (!empty($this->attributes['personaltitle'][0])) { |
| 4633 |
$replacements['personaltitle'] = $this->attributes['personaltitle'][0]; |
| 4634 |
} |
| 4635 |
// first name |
| 4636 |
if (!empty($_POST['givenName'])) { |
| 4637 |
$replacements['firstname'] = $_POST['givenName']; |
| 4638 |
} |
| 4639 |
elseif (!empty($this->attributes['givenName'][0])) { |
| 4640 |
$replacements['firstname'] = $this->attributes['givenName'][0]; |
| 4641 |
} |
| 4642 |
// last name |
| 4643 |
if (!empty($_POST['sn'])) { |
| 4644 |
$replacements['lastname'] = $_POST['sn']; |
| 4645 |
} |
| 4646 |
elseif (!empty($this->attributes['sn'][0])) { |
| 4647 |
$replacements['lastname'] = $this->attributes['sn'][0]; |
| 4648 |
} |
| 4649 |
// user name |
| 4650 |
if (!empty($_POST['userPrincipalName'])) { |
| 4651 |
$replacements['user'] = $_POST['userPrincipalName']; |
| 4652 |
} |
| 4653 |
elseif (!empty($this->attributes['userPrincipalName'][0])) { |
| 4654 |
$userParts = explode('@', $this->attributes['userPrincipalName'][0]); |
| 4655 |
if ((count($userParts) === 2) && !empty($userParts[0])) { |
| 4656 |
$replacements['user'] = $userParts[0]; |
| 4657 |
} |
| 4658 |
} |
| 4659 |
// cn |
| 4660 |
if (!empty($_POST['cn_0'])) { |
| 4661 |
$replacements['commonname'] = $_POST['cn_0']; |
| 4662 |
} |
| 4663 |
elseif (!empty($this->attributes['cn'][0])) { |
| 4664 |
$replacements['commonname'] = $this->attributes['cn'][0]; |
| 4665 |
} |
| 4666 |
// mail |
| 4667 |
if (!empty($_POST['mail_0'])) { |
| 4668 |
$replacements['email'] = $_POST['mail_0']; |
| 4669 |
} |
| 4670 |
elseif (!empty($this->attributes['mail'][0])) { |
| 4671 |
$replacements['email'] = $this->attributes['mail'][0]; |
| 4672 |
} |
| 4673 |
return $replacements; |
| 4674 |
} |
| 4675 |
|
| 4676 |
/** |
| 4677 |
* Returns if the given account is expired. |
| 4678 |
* |
| 4679 |
* @param array<string, string[]|string> $attrs LDAP attributes |
| 4680 |
* @return bool expired |
| 4681 |
*/ |
| 4682 |
public static function isAccountExpired(array $attrs): bool { |
| 4683 |
$attrs = array_change_key_case($attrs); |
| 4684 |
if (empty($attrs['accountexpires'][0])) { |
| 4685 |
return false; |
| 4686 |
} |
| 4687 |
$value = $attrs['accountexpires'][0]; |
| 4688 |
if ($value < 1) { |
| 4689 |
return false; |
| 4690 |
} |
| 4691 |
$seconds = substr($value, 0, -7); |
| 4692 |
$time = new DateTime('1601-01-01', new DateTimeZone('UTC')); |
| 4693 |
$time->add(new DateInterval('PT' . $seconds . 'S')); |
| 4694 |
$now = new DateTime('now', getTimeZone()); |
| 4695 |
return ($time < $now); |
| 4696 |
} |
| 4697 |
|
| 4698 |
/** |
| 4699 |
* Returns the list of groups. |
| 4700 |
* |
| 4701 |
* @return string[] DNs of Windows groups |
| 4702 |
*/ |
| 4703 |
public function getGroupList(): array { |
| 4704 |
return $this->groupList; |
| 4705 |
} |
| 4706 |
|
| 4707 |
/** |
| 4708 |
* @inheritDoc |
| 4709 |
*/ |
| 4710 |
public function supportsPasswordQuickChangePage(): bool { |
| 4711 |
return true; |
| 4712 |
} |
| 4713 |
|
| 4714 |
/** |
| 4715 |
* @inheritDoc |
| 4716 |
*/ |
| 4717 |
public function addPasswordQuickChangeAccountDetails(htmlResponsiveRow $row): void { |
| 4718 |
if (!empty($this->attributes['userPrincipalName'][0])) { |
| 4719 |
$row->addLabel(new htmlOutputText(_('User name'))); |
| 4720 |
$row->addField(new htmlOutputText($this->attributes['userPrincipalName'][0])); |
| 4721 |
} |
| 4722 |
$nameParts = []; |
| 4723 |
if (isset($this->attributes['givenName'][0])) { |
| 4724 |
$nameParts[] = $this->attributes['givenName'][0]; |
| 4725 |
} |
| 4726 |
if (isset($this->attributes['sn'][0])) { |
| 4727 |
$nameParts[] = $this->attributes['sn'][0]; |
| 4728 |
} |
| 4729 |
if (!empty($nameParts)) { |
| 4730 |
$row->addLabel(new htmlOutputText(_('Full name'))); |
| 4731 |
$row->addField(new htmlOutputText(implode(' ', $nameParts))); |
| 4732 |
} |
| 4733 |
if (!empty($this->attributes['mail'][0])) { |
| 4734 |
$row->addLabel(new htmlOutputText(_('Email address'))); |
| 4735 |
$row->addField(new htmlOutputText($this->attributes['mail'][0])); |
| 4736 |
} |
| 4737 |
if (!empty($this->attributes['telephoneNumber'][0])) { |
| 4738 |
$row->addLabel(new htmlOutputText(_('Telephone number'))); |
| 4739 |
$row->addField(new htmlOutputText($this->attributes['telephoneNumber'][0])); |
| 4740 |
} |
| 4741 |
} |
| 4742 |
|
| 4743 |
/** |
| 4744 |
* @inheritDoc |
| 4745 |
*/ |
| 4746 |
public function getPasswordQuickChangeOptions(bool $forcePasswordChangeByDefault): array { |
| 4747 |
if (!in_array_ignore_case('user', $this->attributes['objectClass'])) { |
| 4748 |
return []; |
| 4749 |
} |
| 4750 |
return [ |
| 4751 |
new PasswordQuickChangeOption('syncWindows', _('Change Windows password')) |
| 4752 |
]; |
| 4753 |
} |
| 4754 |
|
| 4755 |
/** |
| 4756 |
* @inheritDoc |
| 4757 |
*/ |
| 4758 |
public function getPasswordQuickChangeChanges(string $password): array { |
| 4759 |
$attrs = []; |
| 4760 |
if (isset($_POST['syncWindows'])) { |
| 4761 |
$attrs['unicodePwd'][0] = self::pwdAttributeValue($password); |
| 4762 |
} |
| 4763 |
return $attrs; |
| 4764 |
} |
| 4765 |
|
| 4766 |
/** |
| 4767 |
* @inheritDoc |
| 4768 |
*/ |
| 4769 |
public function getPasswordQuickChangePasswordStrengthUserName(): ?string { |
| 4770 |
return $this->attributes['userPrincipalName'][0] ?? null; |
| 4771 |
} |
| 4772 |
|
| 4773 |
/** |
| 4774 |
* @inheritDoc |
| 4775 |
*/ |
| 4776 |
public function getPasswordQuickChangePasswordStrengthAttributes(): array { |
| 4777 |
$values = []; |
| 4778 |
if (isset($this->attributes['sn'][0])) { |
| 4779 |
$values[] = $this->attributes['sn'][0]; |
| 4780 |
} |
| 4781 |
if (isset($this->attributes['givenName'][0])) { |
| 4782 |
$values[] = $this->attributes['givenName'][0]; |
| 4783 |
} |
| 4784 |
return $values; |
| 4785 |
} |
| 4786 |
|
| 4787 |
/** |
| 4788 |
* @inheritDoc |
| 4789 |
*/ |
| 4790 |
public function getPasswordQuickChangeIsPasswordInHistory(string $password): bool { |
| 4791 |
return false; |
| 4792 |
} |
| 4793 |
|
| 4794 |
/** |
| 4795 |
* @inheritDoc |
| 4796 |
*/ |
| 4797 |
public function getAccountStatusDetails(ConfiguredType $type, ?array &$attributes): array { |
| 4798 |
if ($attributes === null) { |
| 4799 |
$attributes = $this->attributes; |
| 4800 |
} |
| 4801 |
$details = []; |
| 4802 |
if (self::isDeactivated($attributes)) { |
| 4803 |
$details[] = AccountStatusDetails::newLocked(_('Deactivated'), self::STATUS_ACCOUNT_LOCKED); |
| 4804 |
} |
| 4805 |
$passwordLockedTime = self::getPasswordLocked($attributes); |
| 4806 |
if ($passwordLockedTime !== false) { |
| 4807 |
$details[] = AccountStatusDetails::newLocked(_('Locked till') . ' ' . $passwordLockedTime->format('Y-m-d H:i:s'), self::STATUS_PASSWORD_LOCKED); |
| 4808 |
} |
| 4809 |
if (self::isAccountExpired($attributes)) { |
| 4810 |
$details[] = AccountStatusDetails::newExpired(_('Account is expired'), self::STATUS_ACCOUNT_EXPIRED); |
| 4811 |
} |
| 4812 |
return $details; |
| 4813 |
} |
| 4814 |
|
| 4815 |
/** |
| 4816 |
* @inheritDoc |
| 4817 |
*/ |
| 4818 |
public function getAccountStatusRequiredAttributes(ConfiguredType $type): array { |
| 4819 |
return ['useraccountcontrol', 'lockouttime', 'accountexpires']; |
| 4820 |
} |
| 4821 |
|
| 4822 |
/** |
| 4823 |
* @inheritDoc |
| 4824 |
*/ |
| 4825 |
public function getAccountStatusPossibleLockOptions(ConfiguredType $type, ?array &$attributes): array { |
| 4826 |
if ($attributes === null) { |
| 4827 |
$attributes = $this->attributes; |
| 4828 |
} |
| 4829 |
$options = []; |
| 4830 |
if (!self::isDeactivated($attributes)) { |
| 4831 |
$options[] = AccountStatusDetails::newLocked(_('Deactivated'), self::STATUS_ACCOUNT_LOCKED); |
| 4832 |
} |
| 4833 |
return $options; |
| 4834 |
} |
| 4835 |
|
| 4836 |
/** |
| 4837 |
* @inheritDoc |
| 4838 |
*/ |
| 4839 |
public function accountStatusPerformLock(ConfiguredType $type, ?array &$attributes, array $lockIds): void { |
| 4840 |
if ($attributes === null) { |
| 4841 |
$attributes = &$this->attributes; |
| 4842 |
} |
| 4843 |
if (in_array(self::STATUS_ACCOUNT_LOCKED, $lockIds)) { |
| 4844 |
self::setIsDeactivated(true, $attributes); |
| 4845 |
} |
| 4846 |
} |
| 4847 |
|
| 4848 |
/** |
| 4849 |
* @inheritDoc |
| 4850 |
*/ |
| 4851 |
public function accountStatusPerformUnlock(ConfiguredType $type, ?array &$attributes, array $lockIds): void { |
| 4852 |
if ($attributes === null) { |
| 4853 |
$attributes = &$this->attributes; |
| 4854 |
} |
| 4855 |
if (in_array(self::STATUS_ACCOUNT_LOCKED, $lockIds)) { |
| 4856 |
self::setIsDeactivated(false, $attributes); |
| 4857 |
} |
| 4858 |
if (in_array(self::STATUS_ACCOUNT_EXPIRED, $lockIds)) { |
| 4859 |
$attributes['accountexpires'][0] = '0'; |
| 4860 |
} |
| 4861 |
if (in_array(self::STATUS_PASSWORD_LOCKED, $lockIds)) { |
| 4862 |
self::unlockPassword($attributes); |
| 4863 |
} |
| 4864 |
} |
| 4865 |
|
| 4866 |
/** |
| 4867 |
* @inheritDoc |
| 4868 |
*/ |
| 4869 |
public function getListAttributeDescriptions(ConfiguredType $type): array { |
| 4870 |
return [ |
| 4871 |
'userprincipalname' => _('User name'), |
| 4872 |
'cn' => _('Common name'), |
| 4873 |
'displayname' => _('Display name'), |
| 4874 |
'givenname' => _('First name'), |
| 4875 |
'sn' => _('Last name'), |
| 4876 |
'mail' => _('Email address'), |
| 4877 |
'accountexpires' => _('Account expiration date'), |
| 4878 |
'whencreated' => _('Creation time'), |
| 4879 |
'whenchanged' => _('Change date'), |
| 4880 |
'personaltitle' => _('Personal title'), |
| 4881 |
'roomnumber' => _('Room number'), |
| 4882 |
'jpegphoto' => _('Photo'), |
| 4883 |
'thumbnailphoto' => _('Thumbnail'), |
| 4884 |
'memberof' => _('Member of'), |
| 4885 |
'memberof_count' => _('Membership count'), |
| 4886 |
]; |
| 4887 |
} |
| 4888 |
|
| 4889 |
/** |
| 4890 |
* @inheritDoc |
| 4891 |
*/ |
| 4892 |
public function getListRenderFunction(string $attributeName, ConfiguredType $type): ?callable { |
| 4893 |
if ($attributeName === 'mail') { |
| 4894 |
return function(array $entry, string $attribute): htmlElement { |
| 4895 |
$group = new htmlGroup(); |
| 4896 |
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) { |
| 4897 |
for ($i = 0; $i < count($entry[$attribute]); $i++) { |
| 4898 |
if ($i > 0) { |
| 4899 |
$group->addElement(new htmlOutputText(", ")); |
| 4900 |
} |
| 4901 |
$group->addElement(new htmlLink($entry[$attribute][$i], "mailto:" . $entry[$attribute][$i])); |
| 4902 |
} |
| 4903 |
} |
| 4904 |
return $group; |
| 4905 |
}; |
| 4906 |
} |
| 4907 |
elseif (($attributeName === 'jpegphoto') || ($attributeName === 'thumbnailphoto')) { |
| 4908 |
return function(array $entry, string $attribute): htmlElement { |
| 4909 |
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) { |
| 4910 |
if (strlen($entry[$attribute][0]) < 100) { |
| 4911 |
// looks like we have read broken binary data, reread photo |
| 4912 |
$result = @ldap_read($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*", [$attribute], 0, 0, 0, LDAP_DEREF_NEVER); |
| 4913 |
if ($result) { |
| 4914 |
$tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result); |
| 4915 |
if ($tempEntry) { |
| 4916 |
$binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute); |
| 4917 |
$entry[$attribute] = $binData; |
| 4918 |
} |
| 4919 |
} |
| 4920 |
} |
| 4921 |
$tempFilesManager = new LamTemporaryFilesManager(); |
| 4922 |
$jpegFileName = $tempFilesManager->registerTemporaryFile('.jpg'); |
| 4923 |
$handle = $tempFilesManager->openTemporaryFileForWrite($jpegFileName); |
| 4924 |
fwrite($handle, $entry[$attribute][0]); |
| 4925 |
fclose($handle); |
| 4926 |
$photoFile = $tempFilesManager->getResourceLink($jpegFileName); |
| 4927 |
$image = new htmlImage($photoFile); |
| 4928 |
$image->enableLightbox(); |
| 4929 |
$image->setCSSClasses(['thumbnail']); |
| 4930 |
return $image; |
| 4931 |
} |
| 4932 |
return new htmlGroup(); |
| 4933 |
}; |
| 4934 |
} |
| 4935 |
elseif ($attributeName === 'accountexpires') { |
| 4936 |
return fn(array $entry, string $attribute): htmlElement => new htmlOutputText($this->formatAccountExpires($entry)); |
| 4937 |
} |
| 4938 |
elseif (($attributeName === 'whencreated') || ($attributeName === 'whenchanged')) { |
| 4939 |
return function(array $entry, string $attribute): htmlElement { |
| 4940 |
$value = ' - '; |
| 4941 |
if (!empty($entry[$attribute][0])) { |
| 4942 |
$value = formatLDAPTimestamp($entry[$attribute][0]); |
| 4943 |
} |
| 4944 |
return new htmlOutputText($value); |
| 4945 |
}; |
| 4946 |
} |
| 4947 |
elseif (in_array($attributeName, ['manager', 'memberof'])) { |
| 4948 |
return $this->listRenderDnList(...); |
| 4949 |
} |
| 4950 |
elseif ($attributeName === 'memberof_count') { |
| 4951 |
return function(array $entry, string $attribute): htmlElement { |
| 4952 |
$count = 0; |
| 4953 |
$realAttributeName = str_replace('_count', '', $attribute); |
| 4954 |
$values = &$entry[$realAttributeName]; |
| 4955 |
if (!empty($values)) { |
| 4956 |
$count = count($values); |
| 4957 |
} |
| 4958 |
return new htmlOutputText((string) $count); |
| 4959 |
}; |
| 4960 |
} |
| 4961 |
return null; |
| 4962 |
} |
| 4963 |
|
| 4964 |
} |
| 4965 |
|
| 4966 |
if (interface_exists('\LAM\JOB\Job', false)) { |
| 4967 |
|
| 4968 |
include_once __DIR__ . '/../passwordExpirationJob.inc'; |
| 4969 |
|
| 4970 |
/** |
| 4971 |
* Job to notify users about password expiration. |
| 4972 |
* |
| 4973 |
* @package jobs |
| 4974 |
*/ |
| 4975 |
class WindowsPasswordNotifyJob extends PasswordExpirationJob { |
| 4976 |
|
| 4977 |
/** |
| 4978 |
* {@inheritDoc} |
| 4979 |
*/ |
| 4980 |
public function getAlias(): string { |
| 4981 |
return _('Windows') . ': ' . _('Notify users about password expiration'); |
| 4982 |
} |
| 4983 |
|
| 4984 |
/** |
| 4985 |
* {@inheritDoc} |
| 4986 |
*/ |
| 4987 |
protected function findUsers(string $jobID, array $options): array { |
| 4988 |
// read users |
| 4989 |
$sysattrs = [$_SESSION['cfgMain']->getMailAttribute(), 'accountexpires', 'useraccountcontrol', 'msds-userpasswordexpirytimecomputed']; |
| 4990 |
$attrs = $this->getAttrWildcards($jobID, $options); |
| 4991 |
$attrs = array_values(array_unique(array_merge($attrs, $sysattrs))); |
| 4992 |
return searchLDAPByFilter('(&(' . $_SESSION['cfgMain']->getMailAttribute() . '=*))', $attrs, ['user']); |
| 4993 |
} |
| 4994 |
|
| 4995 |
/** |
| 4996 |
* {@inheritDoc} |
| 4997 |
*/ |
| 4998 |
protected function checkSingleUser(string $jobID, array $options, PDO $pdo, DateTime $now, array $policyOptions, array $user, bool $isDryRun): void { |
| 4999 |
$dn = $user['dn']; |
| 5000 |
// skip if the password does not expire at all |
| 5001 |
if (windowsUser::isNeverExpiring($user)) { |
| 5002 |
$this->jobResultLog->logDebug($dn . ' does not expire.'); |
| 5003 |
return; |
| 5004 |
} |
| 5005 |
// skip if the password does not expire |
| 5006 |
if (empty($user['msds-userpasswordexpirytimecomputed'][0]) |
| 5007 |
|| ($user['msds-userpasswordexpirytimecomputed'][0] === windowsUser::ACCOUNT_DOES_NOT_EXPIRE)) { |
| 5008 |
$this->jobResultLog->logDebug($dn . ': password does not expire.'); |
| 5009 |
return; |
| 5010 |
} |
| 5011 |
// skip if the account itself is expired |
| 5012 |
if (!empty($user['accountexpires'][0])) { |
| 5013 |
$accountExpiration = windowsUser::getFileTime($user['accountexpires'][0]); |
| 5014 |
if ($accountExpiration <= $now) { |
| 5015 |
$this->jobResultLog->logDebug($dn . ' already expired'); |
| 5016 |
return; |
| 5017 |
} |
| 5018 |
} |
| 5019 |
// skip if the account is deactivated |
| 5020 |
if (windowsUser::isDeactivated($user)) { |
| 5021 |
$this->jobResultLog->logDebug($dn . ' is deactivated.'); |
| 5022 |
return; |
| 5023 |
} |
| 5024 |
$passwordExpirationDate = windowsUser::getFileTime($user['msds-userpasswordexpirytimecomputed'][0]); |
| 5025 |
if ($passwordExpirationDate === null) { |
| 5026 |
$this->jobResultLog->logWarning('Invalid expiration value ' . $user['msds-userpasswordexpirytimecomputed'][0]); |
| 5027 |
return; |
| 5028 |
} |
| 5029 |
$this->jobResultLog->logDebug("Password expires on " . $passwordExpirationDate->format('Y-m-d')); |
| 5030 |
$numDaysToWarn = $options[$this->getConfigPrefix() . '_mailNotificationPeriod' . $jobID][0]; |
| 5031 |
$this->jobResultLog->logDebug("Number of days before warning " . $numDaysToWarn); |
| 5032 |
$this->jobResultLog->logDebug("Expiration raw value: " . $user['msds-userpasswordexpirytimecomputed'][0]); |
| 5033 |
// skip already expired accounts |
| 5034 |
if ($passwordExpirationDate <= $now) { |
| 5035 |
$this->jobResultLog->logDebug($dn . ': password already expired'); |
| 5036 |
return; |
| 5037 |
} |
| 5038 |
// calculate time of notification |
| 5039 |
$notifyTime = clone $passwordExpirationDate; |
| 5040 |
$notifyTime->sub(new DateInterval('P' . $numDaysToWarn . 'D')); |
| 5041 |
$notifyTime->setTimeZone(getTimeZone()); |
| 5042 |
$this->jobResultLog->logDebug("Password notification on " . $notifyTime->format('Y-m-d H:i')); |
| 5043 |
// skip if notification is in the future |
| 5044 |
if ($notifyTime > $now) { |
| 5045 |
$this->jobResultLog->logDebug($dn . ' does not need notification yet.'); |
| 5046 |
return; |
| 5047 |
} |
| 5048 |
$dbLastChange = $this->getDBLastPwdChangeTime($jobID, $pdo, $dn); |
| 5049 |
// skip entries where mail was already sent |
| 5050 |
if ($dbLastChange == $user['msds-userpasswordexpirytimecomputed'][0]) { |
| 5051 |
$this->jobResultLog->logDebug($dn . ' was already notified.'); |
| 5052 |
return; |
| 5053 |
} |
| 5054 |
if ($isDryRun) { |
| 5055 |
// no action for dry run |
| 5056 |
$this->jobResultLog->logInfo('Not sending email to ' . $dn . ' because of dry run.'); |
| 5057 |
return; |
| 5058 |
} |
| 5059 |
// send email |
| 5060 |
$success = $this->sendMail($options, $jobID, $user, $passwordExpirationDate); |
| 5061 |
// update DB if mail was sent successfully |
| 5062 |
if ($success) { |
| 5063 |
$this->setDBLastPwdChangeTime($jobID, $pdo, $dn, $user['msds-userpasswordexpirytimecomputed'][0]); |
| 5064 |
} |
| 5065 |
} |
| 5066 |
|
| 5067 |
} |
| 5068 |
|
| 5069 |
/** |
| 5070 |
* Job to notify users about their managed groups. |
| 5071 |
* |
| 5072 |
* @package jobs |
| 5073 |
*/ |
| 5074 |
class WindowsManagedGroupsNotifyJob extends PasswordExpirationJob { |
| 5075 |
|
| 5076 |
private const MANAGED_GROUPS = 'LAM_MANAGED_GROUPS'; |
| 5077 |
private const PERIOD_MONTHLY = 'MONTHLY'; |
| 5078 |
private const PERIOD_QUARTERLY = 'QUARTERLY'; |
| 5079 |
private const PERIOD_HALF_YEARLY = 'HALF_YEARLY'; |
| 5080 |
private const PERIOD_YEARLY = 'YEARLY'; |
| 5081 |
|
| 5082 |
/** |
| 5083 |
* {@inheritDoc} |
| 5084 |
*/ |
| 5085 |
public function getAlias(): string { |
| 5086 |
return _('Windows') . ': ' . _('Notify users about their managed groups'); |
| 5087 |
} |
| 5088 |
|
| 5089 |
/** |
| 5090 |
* {@inheritDoc} |
| 5091 |
*/ |
| 5092 |
public function getDescription(): string { |
| 5093 |
return _('This will send each user a summary of the managed groups and their members.'); |
| 5094 |
} |
| 5095 |
|
| 5096 |
/** |
| 5097 |
* {@inheritDoc} |
| 5098 |
*/ |
| 5099 |
public function getConfigOptions(string $jobID): htmlResponsiveRow { |
| 5100 |
$prefix = $this->getConfigPrefix(); |
| 5101 |
$container = new htmlResponsiveRow(); |
| 5102 |
$container->add(new htmlResponsiveInputField(_('From address'), $prefix . '_mailFrom' . $jobID, null, '800', true)); |
| 5103 |
$container->add(new htmlResponsiveInputField(_('Reply-to address'), $prefix . '_mailReplyTo' . $jobID, null, '801')); |
| 5104 |
$container->add(new htmlResponsiveInputField(_('CC address'), $prefix . '_mailCC' . $jobID, null, '805')); |
| 5105 |
$container->add(new htmlResponsiveInputField(_('BCC address'), $prefix . '_mailBCC' . $jobID, null, '806')); |
| 5106 |
$container->add(new htmlResponsiveInputField(_('Subject'), $prefix . '_mailSubject' . $jobID, null, '802')); |
| 5107 |
$container->add(new htmlResponsiveInputCheckbox($prefix . '_mailIsHTML' . $jobID, false, _('HTML format'), '553')); |
| 5108 |
$container->add(new htmlResponsiveInputTextarea($prefix . '_mailtext' . $jobID, '', 50, 4, _('Text'), '810')); |
| 5109 |
$periodOptions = [ |
| 5110 |
_('Monthly') => self::PERIOD_MONTHLY, |
| 5111 |
_('Quarterly') => self::PERIOD_QUARTERLY, |
| 5112 |
_('Half-yearly') => self::PERIOD_HALF_YEARLY, |
| 5113 |
_('Yearly') => self::PERIOD_YEARLY, |
| 5114 |
]; |
| 5115 |
$periodSelect = new htmlResponsiveSelect($prefix . '_period' . $jobID, $periodOptions, [], _('Period'), '811'); |
| 5116 |
$periodSelect->setHasDescriptiveElements(true); |
| 5117 |
$periodSelect->setSortElements(false); |
| 5118 |
$container->add($periodSelect); |
| 5119 |
return $container; |
| 5120 |
} |
| 5121 |
|
| 5122 |
/** |
| 5123 |
* {@inheritDoc} |
| 5124 |
*/ |
| 5125 |
public function checkConfigOptions(string $jobID, array $options): array { |
| 5126 |
$prefix = $this->getConfigPrefix(); |
| 5127 |
$errors = []; |
| 5128 |
// from address |
| 5129 |
if (empty($options[$prefix . '_mailFrom' . $jobID][0]) |
| 5130 |
|| (!get_preg($options[$prefix . '_mailFrom' . $jobID][0], 'email') && !get_preg($options[$prefix . '_mailFrom' . $jobID][0], 'emailWithName'))) { |
| 5131 |
$errors[] = ['ERROR', _('Please enter a valid email address!'), _('From address')]; |
| 5132 |
} |
| 5133 |
// reply-to |
| 5134 |
if (!empty($options[$prefix . '_mailReplyTo' . $jobID][0]) |
| 5135 |
&& !get_preg($options[$prefix . '_mailReplyTo' . $jobID][0], 'email') |
| 5136 |
&& !get_preg($options[$prefix . '_mailReplyTo' . $jobID][0], 'emailWithName')) { |
| 5137 |
$errors[] = ['ERROR', _('Please enter a valid email address!'), _('Reply-to address')]; |
| 5138 |
} |
| 5139 |
// CC address |
| 5140 |
if (!empty($options[$prefix . '_mailCC' . $jobID][0]) |
| 5141 |
&& !get_preg($options[$prefix . '_mailCC' . $jobID][0], 'email') |
| 5142 |
&& !get_preg($options[$prefix . '_mailCC' . $jobID][0], 'emailWithName')) { |
| 5143 |
$errors[] = ['ERROR', _('Please enter a valid email address!'), _('CC address')]; |
| 5144 |
} |
| 5145 |
// BCC address |
| 5146 |
if (!empty($options[$prefix . '_mailBCC' . $jobID][0]) |
| 5147 |
&& !get_preg($options[$prefix . '_mailBCC' . $jobID][0], 'email') |
| 5148 |
&& !get_preg($options[$prefix . '_mailBCC' . $jobID][0], 'emailWithName')) { |
| 5149 |
$errors[] = ['ERROR', _('Please enter a valid email address!'), _('BCC address')]; |
| 5150 |
} |
| 5151 |
// text |
| 5152 |
$mailText = implode('', $options[$prefix . '_mailtext' . $jobID]); |
| 5153 |
if (empty($mailText)) { |
| 5154 |
$errors[] = ['ERROR', _('Please set a email text.')]; |
| 5155 |
} |
| 5156 |
if (!str_contains($mailText, '@@' . self::MANAGED_GROUPS . '@@')) { |
| 5157 |
$errors[] = ['ERROR', _('Please add the wildcard for the list of managed groups.'), '@@' . self::MANAGED_GROUPS . '@@']; |
| 5158 |
} |
| 5159 |
return $errors; |
| 5160 |
} |
| 5161 |
|
| 5162 |
/** |
| 5163 |
* @inheritDoc |
| 5164 |
*/ |
| 5165 |
protected function getPolicyOptions(): array { |
| 5166 |
return []; |
| 5167 |
} |
| 5168 |
|
| 5169 |
/** |
| 5170 |
* {@inheritDoc} |
| 5171 |
*/ |
| 5172 |
protected function findUsers(string $jobID, array $options): array { |
| 5173 |
// read users |
| 5174 |
$sysAttrs = ['managedObjects', $_SESSION['cfgMain']->getMailAttribute()]; |
| 5175 |
$attrs = $this->getAttrWildcards($jobID, $options); |
| 5176 |
$attrs = array_values(array_unique(array_merge($attrs, $sysAttrs))); |
| 5177 |
$users = searchLDAPByFilter('(&(' . $_SESSION['cfgMain']->getMailAttribute() . '=*)(managedObjects=*))', $attrs, ['user']); |
| 5178 |
$groups = searchLDAPByFilter('(managedBy=*)', ['cn', 'member'], ['group']); |
| 5179 |
$groupByDn = []; |
| 5180 |
foreach ($groups as $group) { |
| 5181 |
$groupByDn[$group['dn']] = $group; |
| 5182 |
} |
| 5183 |
unset($groups); |
| 5184 |
foreach ($users as $index => $user) { |
| 5185 |
$managedObjectDns = $user['managedobjects']; |
| 5186 |
$managedGroups = []; |
| 5187 |
foreach ($managedObjectDns as $managedObjectDn) { |
| 5188 |
if (array_key_exists($managedObjectDn, $groupByDn)) { |
| 5189 |
$managedGroups[] = $groupByDn[$managedObjectDn]; |
| 5190 |
} |
| 5191 |
} |
| 5192 |
$users[$index][strtolower(self::MANAGED_GROUPS)] = $managedGroups; |
| 5193 |
} |
| 5194 |
return $users; |
| 5195 |
} |
| 5196 |
|
| 5197 |
/** |
| 5198 |
* {@inheritDoc} |
| 5199 |
*/ |
| 5200 |
public function execute(string $jobID, array $options, PDO $pdo, bool $isDryRun, JobResultLog $resultLog): void { |
| 5201 |
$this->jobResultLog = &$resultLog; |
| 5202 |
$this->jobResultLog->logDebug("Configuration options:"); |
| 5203 |
foreach ($options as $key => $value) { |
| 5204 |
if (!str_contains($key, $jobID)) { |
| 5205 |
continue; |
| 5206 |
} |
| 5207 |
$this->jobResultLog->logDebug($key . ': ' . implode(', ', $value)); |
| 5208 |
} |
| 5209 |
$now = new DateTime('now', getTimeZone()); |
| 5210 |
$baseDate = $this->getBaseDate($now); |
| 5211 |
$monthInterval = $this->getMonthInterval($options, $jobID); |
| 5212 |
if (!$this->shouldRun($pdo, $jobID, $baseDate, $monthInterval)) { |
| 5213 |
$this->jobResultLog->logDebug('No run needed yet'); |
| 5214 |
return; |
| 5215 |
} |
| 5216 |
$userResults = $this->findUsers($jobID, $options); |
| 5217 |
$this->jobResultLog->logDebug("Found " . count($userResults) . " users to send an email."); |
| 5218 |
$isHTML = (!empty($options[$this->getConfigPrefix() . '_mailIsHTML' . $jobID][0]) && ($options[$this->getConfigPrefix() . '_mailIsHTML' . $jobID][0] == 'true')); |
| 5219 |
foreach ($userResults as $user) { |
| 5220 |
if (empty($user[strtolower(self::MANAGED_GROUPS)])) { |
| 5221 |
continue; |
| 5222 |
} |
| 5223 |
$user[strtolower(self::MANAGED_GROUPS)][0] = $this->formatGroups($user[strtolower(self::MANAGED_GROUPS)], $isHTML); |
| 5224 |
if ($isDryRun) { |
| 5225 |
// no action for dry run |
| 5226 |
$this->jobResultLog->logInfo("Managed groups text for " . $user['dn'] . ":\n" . $user[strtolower(self::MANAGED_GROUPS)][0]); |
| 5227 |
$this->jobResultLog->logInfo('Not sending email to ' . $user['dn'] . ' because of dry run.'); |
| 5228 |
continue; |
| 5229 |
} |
| 5230 |
// send email |
| 5231 |
$this->sendMail($options, $jobID, $user, null); |
| 5232 |
} |
| 5233 |
if (!$isDryRun) { |
| 5234 |
$this->setDBLastPwdChangeTime($jobID, $pdo, $jobID, self::getLastEffectiveExecutionDate($baseDate, $monthInterval, $this->jobResultLog)->format('Y-m-d')); |
| 5235 |
} |
| 5236 |
} |
| 5237 |
|
| 5238 |
/** |
| 5239 |
* Returns if the job should run. |
| 5240 |
* |
| 5241 |
* @param PDO $pdo PDO |
| 5242 |
* @param string $jobId job id |
| 5243 |
* @param DateTime $baseDate base date |
| 5244 |
* @param int $monthInterval month interval |
| 5245 |
* @return bool should run |
| 5246 |
*/ |
| 5247 |
private function shouldRun(PDO $pdo, string $jobId, DateTime $baseDate, int $monthInterval): bool { |
| 5248 |
$dbLastChange = $this->getDBLastPwdChangeTime($jobId, $pdo, $jobId); |
| 5249 |
if (empty($dbLastChange)) { |
| 5250 |
return true; |
| 5251 |
} |
| 5252 |
$this->jobResultLog->logDebug('Base date: ' . $baseDate->format('Y-m-d')); |
| 5253 |
$effectiveDate = self::getLastEffectiveExecutionDate($baseDate, $monthInterval, $this->jobResultLog); |
| 5254 |
$dbLastChangeDate = DateTime::createFromFormat('Y-m-d', $dbLastChange, getTimeZone()); |
| 5255 |
$this->jobResultLog->logDebug('Last run date: ' . $dbLastChangeDate->format('Y-m-d')); |
| 5256 |
return $effectiveDate > $dbLastChangeDate; |
| 5257 |
} |
| 5258 |
|
| 5259 |
/** |
| 5260 |
* Returns the month interval. |
| 5261 |
* |
| 5262 |
* @param array<string, string[]> $options config options |
| 5263 |
* @param string $jobId job id |
| 5264 |
* @return int interval |
| 5265 |
*/ |
| 5266 |
private function getMonthInterval(array $options, string $jobId): int { |
| 5267 |
return match ($options[$this->getConfigPrefix() . '_period' . $jobId][0]) { |
| 5268 |
self::PERIOD_HALF_YEARLY => 6, |
| 5269 |
self::PERIOD_QUARTERLY => 3, |
| 5270 |
self::PERIOD_MONTHLY => 1, |
| 5271 |
default => 12, |
| 5272 |
}; |
| 5273 |
} |
| 5274 |
|
| 5275 |
/** |
| 5276 |
* Returns the base date (first of month) for the current date. |
| 5277 |
* |
| 5278 |
* @param DateTime $currentDate current date |
| 5279 |
* @return DateTime base date |
| 5280 |
*/ |
| 5281 |
private function getBaseDate(DateTime $currentDate): DateTime { |
| 5282 |
$baseDateText = $currentDate->format('Y-m-') . '1'; |
| 5283 |
return DateTime::createFromFormat('Y-m-d', $baseDateText, getTimeZone()); |
| 5284 |
} |
| 5285 |
|
| 5286 |
/** |
| 5287 |
* Returns the last effective execution date. |
| 5288 |
* |
| 5289 |
* @param DateTime $baseDate base date |
| 5290 |
* @param int $monthInterval number of months in interval |
| 5291 |
* @param JobResultLog $resultLog result log |
| 5292 |
* @return DateTime date |
| 5293 |
*/ |
| 5294 |
public static function getLastEffectiveExecutionDate(DateTime $baseDate, int $monthInterval, JobResultLog $resultLog): DateTime { |
| 5295 |
$month = $baseDate->format('m'); |
| 5296 |
$monthIndex = $month - 1; |
| 5297 |
while (($monthIndex % $monthInterval) !== 0) { |
| 5298 |
$monthIndex--; |
| 5299 |
} |
| 5300 |
$month = $monthIndex + 1; |
| 5301 |
$effectiveDateString = $baseDate->format('Y-') . $month . '-1'; |
| 5302 |
$effectiveDate = DateTime::createFromFormat('Y-m-d', $effectiveDateString, getTimeZone()); |
| 5303 |
$resultLog->logDebug("Effective date: " . $effectiveDate->format('Y-m-d')); |
| 5304 |
return $effectiveDate; |
| 5305 |
} |
| 5306 |
|
| 5307 |
/** |
| 5308 |
* {@inheritDoc} |
| 5309 |
*/ |
| 5310 |
protected function checkSingleUser(string $jobID, array $options, PDO $pdo, DateTime $now, array $policyOptions, array $user, bool $isDryRun): void { |
| 5311 |
// not used |
| 5312 |
} |
| 5313 |
|
| 5314 |
/** |
| 5315 |
* Formats the managed groups. |
| 5316 |
* |
| 5317 |
* @param array<string, string[]|string>[] $managedGroups managed groups |
| 5318 |
* @param bool $isHTML HTML email |
| 5319 |
* @return string formatted text |
| 5320 |
*/ |
| 5321 |
private function formatGroups(array $managedGroups, bool $isHTML): string { |
| 5322 |
$text = ''; |
| 5323 |
foreach ($managedGroups as $managedGroup) { |
| 5324 |
if ($isHTML) { |
| 5325 |
$text .= '<br><b>' . $managedGroup['cn'][0] . '</b><br>'; |
| 5326 |
} |
| 5327 |
else { |
| 5328 |
$text .= "\r\n" . $managedGroup['cn'][0] . "\r\n\r\n"; |
| 5329 |
} |
| 5330 |
if (empty($managedGroup['member'])) { |
| 5331 |
continue; |
| 5332 |
} |
| 5333 |
foreach ($managedGroup['member'] as $member) { |
| 5334 |
$member = getAbstractDN($member); |
| 5335 |
if ($isHTML) { |
| 5336 |
$text .= ' ' . $member . '<br>'; |
| 5337 |
} |
| 5338 |
else { |
| 5339 |
$text .= " " . $member . "\r\n"; |
| 5340 |
} |
| 5341 |
} |
| 5342 |
} |
| 5343 |
return $text; |
| 5344 |
} |
| 5345 |
|
| 5346 |
} |
| 5347 |
|
| 5348 |
/** |
| 5349 |
* Job to notify users about account expiration. |
| 5350 |
* |
| 5351 |
* @package jobs |
| 5352 |
*/ |
| 5353 |
class WindowsAccountExpirationNotifyJob extends PasswordExpirationJob { |
| 5354 |
|
| 5355 |
/** |
| 5356 |
* {@inheritDoc} |
| 5357 |
*/ |
| 5358 |
public function getAlias(): string { |
| 5359 |
return _('Windows') . ': ' . _('Notify users about account expiration'); |
| 5360 |
} |
| 5361 |
|
| 5362 |
/** |
| 5363 |
* {@inheritDoc} |
| 5364 |
*/ |
| 5365 |
public function getDescription(): string { |
| 5366 |
return _('This job sends out emails to inform your users that their account will expire soon.'); |
| 5367 |
} |
| 5368 |
|
| 5369 |
/** |
| 5370 |
* {@inheritDoc} |
| 5371 |
*/ |
| 5372 |
protected function findUsers(string $jobID, array $options): array { |
| 5373 |
// read users |
| 5374 |
$sysattrs = [$_SESSION['cfgMain']->getMailAttribute(), 'accountexpires', 'useraccountcontrol']; |
| 5375 |
$attrs = $this->getAttrWildcards($jobID, $options); |
| 5376 |
$attrs = array_values(array_unique(array_merge($attrs, $sysattrs))); |
| 5377 |
return searchLDAPByFilter('(&(accountexpires=*)(!(accountexpires=0))(' . $_SESSION['cfgMain']->getMailAttribute() . '=*))', $attrs, ['user']); |
| 5378 |
} |
| 5379 |
|
| 5380 |
/** |
| 5381 |
* {@inheritDoc} |
| 5382 |
*/ |
| 5383 |
protected function checkSingleUser(string $jobID, array $options, PDO $pdo, DateTime $now, array $policyOptions, array $user, bool $isDryRun): void { |
| 5384 |
$dn = $user['dn']; |
| 5385 |
// skip if account is deactivated |
| 5386 |
if (windowsUser::isDeactivated($user)) { |
| 5387 |
$this->jobResultLog->logDebug($dn . ' is deactivated.'); |
| 5388 |
return; |
| 5389 |
} |
| 5390 |
// skip if account itself is expired |
| 5391 |
if (!empty($user['accountexpires'][0])) { |
| 5392 |
$accountExpiration = windowsUser::getFileTime($user['accountexpires'][0]); |
| 5393 |
if ($accountExpiration <= $now) { |
| 5394 |
$this->jobResultLog->logDebug($dn . ' already expired'); |
| 5395 |
return; |
| 5396 |
} |
| 5397 |
} |
| 5398 |
// get time when account expires |
| 5399 |
$expirationTime = windowsUser::getFileTime($user['accountexpires'][0]); |
| 5400 |
$this->jobResultLog->logDebug("Account expiration on " . $expirationTime->format('Y-m-d')); |
| 5401 |
$numDaysToWarn = $options[$this->getConfigPrefix() . '_mailNotificationPeriod' . $jobID][0]; |
| 5402 |
$this->jobResultLog->logDebug("Number of days before warning " . $numDaysToWarn); |
| 5403 |
// calculate time of notification |
| 5404 |
$notifyTime = clone $expirationTime; |
| 5405 |
$notifyTime->sub(new DateInterval('P' . $numDaysToWarn . 'D')); |
| 5406 |
$notifyTime->setTimeZone(getTimeZone()); |
| 5407 |
$this->jobResultLog->logDebug("Account expiration notification on " . $notifyTime->format('Y-m-d H:i')); |
| 5408 |
// skip if notification is in the future |
| 5409 |
if ($notifyTime > $now) { |
| 5410 |
$this->jobResultLog->logDebug($dn . ' does not need notification yet.'); |
| 5411 |
return; |
| 5412 |
} |
| 5413 |
$dbLastChange = $this->getDBLastPwdChangeTime($jobID, $pdo, $dn); |
| 5414 |
// skip entries where mail was already sent |
| 5415 |
if ($dbLastChange == $user['accountexpires'][0]) { |
| 5416 |
$this->jobResultLog->logDebug($dn . ' was already notified.'); |
| 5417 |
return; |
| 5418 |
} |
| 5419 |
if ($isDryRun) { |
| 5420 |
// no action for dry run |
| 5421 |
$this->jobResultLog->logInfo('Not sending email to ' . $dn . ' because of dry run.'); |
| 5422 |
return; |
| 5423 |
} |
| 5424 |
// send email |
| 5425 |
$success = $this->sendMail($options, $jobID, $user, $expirationTime); |
| 5426 |
// update DB if mail was sent successfully |
| 5427 |
if ($success) { |
| 5428 |
$this->setDBLastPwdChangeTime($jobID, $pdo, $dn, $user['accountexpires'][0]); |
| 5429 |
} |
| 5430 |
} |
| 5431 |
|
| 5432 |
} |
| 5433 |
|
| 5434 |
/** |
| 5435 |
* Job to delete or move users on account expiration. |
| 5436 |
* |
| 5437 |
* @package jobs |
| 5438 |
*/ |
| 5439 |
class WindowsAccountExpirationCleanupJob extends AccountExpirationCleanupJob { |
| 5440 |
|
| 5441 |
/** |
| 5442 |
* {@inheritDoc} |
| 5443 |
*/ |
| 5444 |
public function getAlias(): string { |
| 5445 |
return _('Windows') . ': ' . _('Cleanup expired user accounts'); |
| 5446 |
} |
| 5447 |
|
| 5448 |
/** |
| 5449 |
* {@inheritDoc} |
| 5450 |
*/ |
| 5451 |
public function getDescription(): string { |
| 5452 |
return _('This job deletes or moves user accounts when they expire.'); |
| 5453 |
} |
| 5454 |
|
| 5455 |
/** |
| 5456 |
* {@inheritDoc} |
| 5457 |
*/ |
| 5458 |
protected function findUsers(string $jobID, array $options): array { |
| 5459 |
// read users |
| 5460 |
$attrs = ['accountexpires']; |
| 5461 |
return searchLDAPByFilter('(accountexpires=*)', $attrs, ['user']); |
| 5462 |
} |
| 5463 |
|
| 5464 |
/** |
| 5465 |
* {@inheritDoc} |
| 5466 |
*/ |
| 5467 |
protected function checkSingleUser(string $jobID, array $options, PDO $pdo, DateTime $now, array $policyOptions, array $user, bool $isDryRun): void { |
| 5468 |
$seconds = substr($user['accountexpires'][0], 0, -7); |
| 5469 |
$expireTime = new DateTime('1601-01-01', new DateTimeZone('UTC')); |
| 5470 |
$expireTime->add(new DateInterval('PT' . $seconds . 'S')); |
| 5471 |
$expireTime->setTimezone(getTimeZone()); |
| 5472 |
$this->jobResultLog->logDebug("Expiration on " . $expireTime->format('Y-m-d')); |
| 5473 |
$delay = 0; |
| 5474 |
if (!empty($options[$this->getConfigPrefix() . '_delay' . $jobID][0])) { |
| 5475 |
$delay = $options[$this->getConfigPrefix() . '_delay' . $jobID][0]; |
| 5476 |
} |
| 5477 |
$actionTime = clone $expireTime; |
| 5478 |
if ($delay != 0) { |
| 5479 |
$actionTime->add(new DateInterval('P' . $delay . 'D')); |
| 5480 |
} |
| 5481 |
$actionTime->setTimeZone(getTimeZone()); |
| 5482 |
$this->jobResultLog->logDebug("Action time on " . $actionTime->format('Y-m-d')); |
| 5483 |
if ($actionTime <= $now) { |
| 5484 |
$this->performAction($jobID, $options, $user, $isDryRun); |
| 5485 |
} |
| 5486 |
} |
| 5487 |
|
| 5488 |
} |
| 5489 |
|
| 5490 |
} |