From c33ea7abfbd13386c4198f2b0b48450d04c48b8e Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 29 Oct 2023 20:14:51 +0100 Subject: [PATCH] refactoring --- lam/templates/config/confImportExport.php | 32 +-- lam/templates/config/conflogin.php | 20 +- lam/templates/config/confmain.php | 246 +++++++++++----------- lam/templates/config/confmodules.php | 48 ++--- lam/templates/config/confsave.php | 6 +- lam/templates/config/conftypes.php | 56 ++--- lam/templates/config/index.php | 16 +- lam/templates/config/mainlogin.php | 16 +- lam/templates/config/mainmanage.php | 199 ++++++++--------- lam/templates/config/moduleSettings.php | 16 +- lam/templates/config/profmanage.php | 46 ++-- 11 files changed, 358 insertions(+), 343 deletions(-) diff --git a/lam/templates/config/confImportExport.php b/lam/templates/config/confImportExport.php index f59348705..c33531a17 100644 --- a/lam/templates/config/confImportExport.php +++ b/lam/templates/config/confImportExport.php @@ -19,7 +19,7 @@ /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2020 - 2022 Roland Gruber + Copyright (C) 2020 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -123,7 +123,7 @@ menu @@ -161,22 +161,22 @@ function showLoginDialog($message = null): void { $content = new htmlResponsiveRow(); $loginContent = new htmlResponsiveRow(); - $loginContent->setCSSClasses(array('maxrow fullwidth roundedShadowBox spacing5')); + $loginContent->setCSSClasses(['maxrow fullwidth roundedShadowBox spacing5']); if ($message !== null) { $loginContent->add($message, 12); } $pwdInput = new htmlResponsiveInputField(_("Master password"), 'password', '', '236'); $pwdInput->setIsPassword(true); - $pwdInput->setCSSClasses(array('lam-initial-focus')); + $pwdInput->setCSSClasses(['lam-initial-focus']); $loginContent->add($pwdInput, 12); $loginContent->addLabel(new htmlOutputText(' ', false)); $loginButton = new htmlButton('submitLogin', _("Ok")); - $loginButton->setCSSClasses(array('lam-primary')); + $loginButton->setCSSClasses(['lam-primary']); $loginContent->addField($loginButton); $content->add($loginContent, 12); - parseHtml(null, $content, array(), false, null); + parseHtml(null, $content, [], false, null); renderBackLink(); } @@ -188,7 +188,7 @@ function renderBackLink(): void { $content->addVerticalSpacer('2rem'); $content->add(new htmlLink(_('Back to login'), '../login.php'), 12); $content->addVerticalSpacer('1rem'); - parseHtml(null, $content, array(), false, null); + parseHtml(null, $content, [], false, null); } /** @@ -215,13 +215,13 @@ function displayImportExport(): void { $content->add(new htmlSubTitle(_('Export')), 12); $exportButton = new htmlButton('exportConfig', _('Export')); - $exportButton->setCSSClasses(array('lam-primary')); + $exportButton->setCSSClasses(['lam-primary']); $content->add($exportButton); $content->add(new htmlSubTitle(_('Import')), 12); renderImportPart($content); - parseHtml(null, $content, array(), false, null); + parseHtml(null, $content, [], false, null); renderBackLink(); } @@ -232,7 +232,7 @@ function displayImportExport(): void { */ function renderImportPart($content): void { $validUpload = false; - $importSteps = array(); + $importSteps = []; if (isset($_POST['importConfig'])) { try { if (empty($_FILES['import-file']['tmp_name'])) { @@ -254,7 +254,7 @@ function renderImportPart($content): void { if ($handle === false) { throw new LAMException(_('Unable to read import file.')); } - $data = fread($handle, 100000000); + $data = fread($handle, 100_000_000); if ($data === false) { throw new LAMException(_('Unable to read import file.')); } @@ -279,7 +279,7 @@ function renderImportPart($content): void { if (!isset($_POST['importConfigConfirm']) && !$validUpload) { $content->add(new htmlInputFileUpload('import-file'), 12); $submitButton = new htmlButton('importConfig', _('Submit')); - $submitButton->setCSSClasses(array('lam-secondary')); + $submitButton->setCSSClasses(['lam-secondary']); $content->add($submitButton); } elseif (isset($_POST['importConfig'])) { @@ -288,8 +288,8 @@ function renderImportPart($content): void { $stepKey = 'step_' . $importStep->getKey(); $stepCheckbox = new htmlResponsiveInputCheckbox($stepKey, true, $importStep->getLabel()); $stepCheckbox->setLabelAfterCheckbox(); - $stepCheckbox->setCSSClasses(array('bold')); - $subStepIds = array(); + $stepCheckbox->setCSSClasses(['bold']); + $subStepIds = []; $content->add($stepCheckbox); $content->addVerticalSpacer('0.3rem'); foreach ($importStep->getSubSteps() as $subStep) { @@ -304,7 +304,7 @@ function renderImportPart($content): void { } $buttonGroup = new htmlGroup(); $importButton = new htmlButton('importConfigConfirm', _('Import')); - $importButton->setCSSClasses(array('lam-secondary')); + $importButton->setCSSClasses(['lam-secondary']); $buttonGroup->addElement($importButton); $buttonGroup->addElement(new htmlButton('importCancel', _('Cancel'))); $content->add($buttonGroup); @@ -315,7 +315,7 @@ function renderImportPart($content): void { if ($handle === false) { throw new LAMException(_('Unable to read import file.')); } - $data = fread($handle, 100000000); + $data = fread($handle, 100_000_000); if ($data === false) { throw new LAMException(_('Unable to read import file.')); } diff --git a/lam/templates/config/conflogin.php b/lam/templates/config/conflogin.php index 0560107bf..a534cd039 100644 --- a/lam/templates/config/conflogin.php +++ b/lam/templates/config/conflogin.php @@ -15,7 +15,7 @@ /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2003 - 2021 Roland Gruber + Copyright (C) 2003 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,7 +49,7 @@ // start session if (isFileBasedSession()) { - session_save_path(dirname(__FILE__) . '/../../sess'); + session_save_path(__DIR__ . '/../../sess'); } lam_start_session(); session_regenerate_id(true); @@ -65,13 +65,13 @@ // remove settings from session $sessionKeys = array_keys($_SESSION); for ($i = 0; $i < sizeof($sessionKeys); $i++) { - if (substr($sessionKeys[$i], 0, 5) == "conf_") unset($_SESSION[$sessionKeys[$i]]); + if (str_starts_with($sessionKeys[$i], "conf_")) unset($_SESSION[$sessionKeys[$i]]); } echo $_SESSION['header']; $serverProfilePersistenceManager = new ServerProfilePersistenceManager(); -$files = array(); +$files = []; try { $files = $serverProfilePersistenceManager->getProfiles(); } @@ -101,7 +101,7 @@ menu @@ -133,7 +133,7 @@ $box->add(new htmlOutputText(_("Please enter your password to change the server preferences:")), 12); $box->addVerticalSpacer('1.5rem'); $conf = new LAMCfgMain(); - $selectedProfile = array(); + $selectedProfile = []; $profilesExisting = false; $profiles = $files; if (!empty($_COOKIE["lam_default_profile"]) && in_array($_COOKIE["lam_default_profile"], $files)) { @@ -145,11 +145,11 @@ $box->add(new htmlResponsiveSelect('filename', $profiles, $selectedProfile, _('Profile name')), 12); $passwordInput = new htmlResponsiveInputField(_('Password'), 'passwd', '', '200'); $passwordInput->setIsPassword(true); - $passwordInput->setCSSClasses(array('lam-initial-focus')); + $passwordInput->setCSSClasses(['lam-initial-focus']); $box->add($passwordInput, 12); $box->addVerticalSpacer('1rem'); $button = new htmlButton('submit', _("Ok")); - $button->setCSSClasses(array('lam-primary')); + $button->setCSSClasses(['lam-primary']); $box->addLabel($button); $box->add(new htmlOutputText(''), 0, 6); $box->addVerticalSpacer('1.5rem'); @@ -160,7 +160,7 @@ $box->add($manageLink, 12, 12, 12, 'text-center'); $boxDiv = new htmlDiv(null, $box); - $boxDiv->setCSSClasses(array('roundedShadowBox', 'limitWidth', 'text-center')); + $boxDiv->setCSSClasses(['roundedShadowBox', 'limitWidth', 'text-center']); $row->add($boxDiv, 12); // back link @@ -168,7 +168,7 @@ $backLink = new htmlLink(_("Back to login"), '../login.php'); $row->add($backLink, 12, 12, 12, 'text-left'); - parseHtml(null, new htmlDiv(null, $row, array('centeredTable')), array(), false, 'user'); + parseHtml(null, new htmlDiv(null, $row, ['centeredTable']), [], false, 'user'); ?> diff --git a/lam/templates/config/confmain.php b/lam/templates/config/confmain.php index 80be3046d..03a5551fe 100644 --- a/lam/templates/config/confmain.php +++ b/lam/templates/config/confmain.php @@ -105,7 +105,7 @@ if ((!isset($_SESSION['conf_isAuthenticated']) || !($_SESSION['conf_isAuthenticated'] === $conf->getName())) && !$conf->check_Passwd($passwd)) { $sessionKeys = array_keys($_SESSION); for ($i = 0; $i < sizeof($sessionKeys); $i++) { - if (substr($sessionKeys[$i], 0, 5) == "conf_") { + if (str_starts_with($sessionKeys[$i], "conf_")) { unset($_SESSION[$sessionKeys[$i]]); } } @@ -122,7 +122,7 @@ exit; } -$errorsToDisplay = array(); +$errorsToDisplay = []; if (isset($_SESSION['conf_messages']) && is_array($_SESSION['conf_messages'])) { $errorsToDisplay = array_merge($errorsToDisplay, $_SESSION['conf_messages']); unset($_SESSION['conf_messages']); @@ -203,16 +203,22 @@ $urlInput->setRequired(true); $row->add($urlInput, 12); // use TLS -$tlsOptions = array(_("yes") => 'yes', _("no") => 'no'); -$tlsSelect = new htmlResponsiveSelect('useTLS', $tlsOptions, array($conf->getUseTLS()), _("Activate TLS"), '201'); +$tlsOptions = [_("yes") => 'yes', _("no") => 'no']; +$tlsSelect = new htmlResponsiveSelect('useTLS', $tlsOptions, [$conf->getUseTLS()], _("Activate TLS"), '201'); $tlsSelect->setHasDescriptiveElements(true); $row->add($tlsSelect, 12); // LDAP search limit -$searchLimitOptions = array( -'-' => 0, 100 => 100, 500 => 500, -1000 => 1000, 5000 => 5000, 10000 => 10000, -50000 => 50000, 100000 => 100000); -$limitSelect = new htmlResponsiveSelect('searchLimit', $searchLimitOptions, array($conf->get_searchLimit()), _("LDAP search limit"), '222'); +$searchLimitOptions = [ + '-' => 0, + 100 => 100, + 500 => 500, + 1000 => 1000, + 5000 => 5000, + 10000 => 10000, + 50000 => 50000, + 100000 => 100000 +]; +$limitSelect = new htmlResponsiveSelect('searchLimit', $searchLimitOptions, [$conf->get_searchLimit()], _("LDAP search limit"), '222'); $limitSelect->setHasDescriptiveElements(true); $row->add($limitSelect, 12); // DN part to hide @@ -221,32 +227,32 @@ // access level is only visible in Pro version if (isLAMProVersion()) { - $accessOptions = array( - _('Write access') => LAMConfig::ACCESS_ALL, - _('Change passwords') => LAMConfig::ACCESS_PASSWORD_CHANGE, - _('Read-only') => LAMConfig::ACCESS_READ_ONLY - ); - $accessSelect = new htmlResponsiveSelect('accessLevel', $accessOptions, array($conf->getAccessLevel()), _("Access level"), '215'); + $accessOptions = [ + _('Write access') => LAMConfig::ACCESS_ALL, + _('Change passwords') => LAMConfig::ACCESS_PASSWORD_CHANGE, + _('Read-only') => LAMConfig::ACCESS_READ_ONLY + ]; + $accessSelect = new htmlResponsiveSelect('accessLevel', $accessOptions, [$conf->getAccessLevel()], _("Access level"), '215'); $accessSelect->setHasDescriptiveElements(true); $row->add($accessSelect, 12); } $row->addVerticalSpacer('1rem'); // login method -$loginOptions = array( - _('Fixed list') => LAMConfig::LOGIN_LIST, - _('LDAP search') => LAMConfig::LOGIN_SEARCH -); -$loginSelect = new htmlResponsiveSelect('loginMethod', $loginOptions, array($conf->getLoginMethod()), _("Login method"), '220'); +$loginOptions = [ + _('Fixed list') => LAMConfig::LOGIN_LIST, + _('LDAP search') => LAMConfig::LOGIN_SEARCH +]; +$loginSelect = new htmlResponsiveSelect('loginMethod', $loginOptions, [$conf->getLoginMethod()], _("Login method"), '220'); $loginSelect->setHasDescriptiveElements(true); -$loginSelect->setTableRowsToHide(array( - LAMConfig::LOGIN_LIST => array('loginSearchSuffix', 'loginSearchFilter', 'loginSearchDN', 'loginSearchPassword', 'httpAuthentication'), - LAMConfig::LOGIN_SEARCH => array('admins') -)); -$loginSelect->setTableRowsToShow(array( - LAMConfig::LOGIN_LIST => array('admins'), - LAMConfig::LOGIN_SEARCH => array('loginSearchSuffix', 'loginSearchFilter', 'loginSearchDN', 'loginSearchPassword', 'httpAuthentication') -)); +$loginSelect->setTableRowsToHide([ + LAMConfig::LOGIN_LIST => ['loginSearchSuffix', 'loginSearchFilter', 'loginSearchDN', 'loginSearchPassword', 'httpAuthentication'], + LAMConfig::LOGIN_SEARCH => ['admins'] +]); +$loginSelect->setTableRowsToShow([ + LAMConfig::LOGIN_LIST => ['admins'], + LAMConfig::LOGIN_SEARCH => ['loginSearchSuffix', 'loginSearchFilter', 'loginSearchDN', 'loginSearchPassword', 'httpAuthentication'] +]); $row->add($loginSelect); // admin list $adminText = implode("\n", explode(";", $conf->get_Adminstring())); @@ -289,7 +295,7 @@ $advancedOptionsContent->add(new htmlResponsiveInputCheckbox('hidePasswordPromptForExpiredPasswords', $hidePasswordPromptForExpiredPasswords, _('Hide password prompt for expired password'), '291'), 12); // build advanced options box -$advancedOptions = new htmlAccordion('advancedOptions_server', array(_('Advanced options') => $advancedOptionsContent), false); +$advancedOptions = new htmlAccordion('advancedOptions_server', [_('Advanced options') => $advancedOptionsContent], false); $advancedOptions->colspan = 15; $row->add($advancedOptions, 12); @@ -299,13 +305,13 @@ $row->add(new htmlSubTitle(_("Language settings"), '../../graphics/language.svg', null, true), 12); // read available languages $possibleLanguages = getLanguages(); -$defaultLanguage = array('en_GB.utf8'); +$defaultLanguage = ['en_GB.utf8']; if (!empty($possibleLanguages)) { - $languages = array(); + $languages = []; foreach ($possibleLanguages as $lang) { $languages[$lang->description] = $lang->code; - if (strpos($conf->get_defaultLanguage(), $lang->code) === 0) { - $defaultLanguage = array($lang->code); + if (str_starts_with($conf->get_defaultLanguage(), $lang->code)) { + $defaultLanguage = [$lang->code]; } } $languageSelect = new htmlResponsiveSelect('lang', $languages, $defaultLanguage, _("Default language"), '209'); @@ -315,19 +321,19 @@ else { $row->add(new htmlStatusMessage('ERROR', "Unable to load available languages. Setting English as default language."), 12); } -$timezones = array(); +$timezones = []; $timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::AFRICA)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::AMERICA)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::ANTARCTICA)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::ARCTIC)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::ASIA)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::ATLANTIC)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::AUSTRALIA)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::EUROPE)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::INDIAN)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::PACIFIC)); -$timezones = array_merge($timezones, DateTimeZone::listIdentifiers(DateTimeZone::UTC)); -$row->add(new htmlResponsiveSelect('timeZone', $timezones, array($conf->getTimeZone()), _('Time zone'), '213'), 12); +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::AMERICA)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::ANTARCTICA)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::ARCTIC)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::ASIA)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::ATLANTIC)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::AUSTRALIA)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::EUROPE)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::INDIAN)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::PACIFIC)]; +$timezones = [...$timezones, ...DateTimeZone::listIdentifiers(DateTimeZone::UTC)]; +$row->add(new htmlResponsiveSelect('timeZone', $timezones, [$conf->getTimeZone()], _('Time zone'), '213'), 12); $row->addVerticalSpacer('2rem'); @@ -343,7 +349,7 @@ continue; } $hideableTools++; - $toolClass = get_class($tool); + $toolClass = $tool::class; if ($toolClass === false) { continue; } @@ -357,12 +363,12 @@ for ($i = $hideableTools % 3; $i < 3; $i++) { $row->add(new htmlOutputText(''), 0, 4); } -$toolConfigOptionTypes = array(); +$toolConfigOptionTypes = []; foreach ($tools as $tool) { $toolConfigContent = $tool->getConfigOptions($toolSettings); if ($toolConfigContent !== null) { ob_start(); - $optionTypes = parseHtml(null, $tool->getConfigOptions($toolSettings), array(), true, 'user'); + $optionTypes = parseHtml(null, $tool->getConfigOptions($toolSettings), [], true, 'user'); ob_end_clean(); $toolConfigOptionTypes = array_merge($toolConfigOptionTypes, $optionTypes); $row->addVerticalSpacer('1rem'); @@ -396,12 +402,12 @@ } $row->add(new htmlResponsiveInputCheckbox('pwdResetForcePasswordChange', $pwdResetForcePasswordChange , _('Force password change by default'), '283'), 12); - $pwdResetDefaultPasswordOutputOptions = array( - _('Display on screen') => LAMConfig::PWDRESET_DEFAULT_SCREEN, - _('Send via mail') => LAMConfig::PWDRESET_DEFAULT_MAIL, - _('Both') => LAMConfig::PWDRESET_DEFAULT_BOTH - ); - $pwdResetDefaultPasswordOutputSelect = new htmlResponsiveSelect('pwdResetDefaultPasswordOutput', $pwdResetDefaultPasswordOutputOptions, array($conf->getPwdResetDefaultPasswordOutput()), _("Default password output"), '282'); + $pwdResetDefaultPasswordOutputOptions = [ + _('Display on screen') => LAMConfig::PWDRESET_DEFAULT_SCREEN, + _('Send via mail') => LAMConfig::PWDRESET_DEFAULT_MAIL, + _('Both') => LAMConfig::PWDRESET_DEFAULT_BOTH + ]; + $pwdResetDefaultPasswordOutputSelect = new htmlResponsiveSelect('pwdResetDefaultPasswordOutput', $pwdResetDefaultPasswordOutputOptions, [$conf->getPwdResetDefaultPasswordOutput()], _("Default password output"), '282'); $pwdResetDefaultPasswordOutputSelect->setHasDescriptiveElements(true); $row->add($pwdResetDefaultPasswordOutputSelect, 12); @@ -456,7 +462,7 @@ $row->addLabel($lamdaemonRightsLabel, 12, 6); $chmod = $conf->get_scriptRights(); $rightsTable = new htmlTable(); -$rightsTable->setCSSClasses(array('padding5')); +$rightsTable->setCSSClasses(['padding5']); $rightsTable->addElement(new htmlOutputText('')); $rightsTable->addElement(new htmlOutputText(_("Read"))); $rightsTable->addElement(new htmlOutputText(_("Write"))); @@ -481,55 +487,59 @@ $row->add(new htmlSubTitle(_("Security settings"), '../../graphics/locked.svg', null, true), 12); // password policy override $row->add(new htmlSubTitle(_("Global password policy override"), '../../graphics/locked.svg')); -$optionsPwdLength = array(''); +$optionsPwdLength = ['']; for ($i = 1; $i <= 50; $i++) { $optionsPwdLength[] = $i; } -$row->add(new htmlResponsiveSelect('pwdPolicyMinLength', $optionsPwdLength, array($conf->getPwdPolicyMinLength()), _('Minimum password length'), '242')); -$row->add(new htmlResponsiveSelect('pwdPolicyMinLowercase', $optionsPwdLength, array($conf->getpwdPolicyMinLowercase()), _('Minimum lowercase characters'), '242')); -$row->add(new htmlResponsiveSelect('pwdPolicyMinUppercase', $optionsPwdLength, array($conf->getPwdPolicyMinUppercase()), _('Minimum uppercase characters'), '242')); -$row->add(new htmlResponsiveSelect('pwdPolicyMinNumeric', $optionsPwdLength, array($conf->getPwdPolicyMinNumeric()), _('Minimum numeric characters'), '242')); -$row->add(new htmlResponsiveSelect('pwdPolicyMinSymbolic', $optionsPwdLength, array($conf->getPwdPolicyMinSymbolic()), _('Minimum symbolic characters'), '242')); +$row->add(new htmlResponsiveSelect('pwdPolicyMinLength', $optionsPwdLength, [$conf->getPwdPolicyMinLength()], _('Minimum password length'), '242')); +$row->add(new htmlResponsiveSelect('pwdPolicyMinLowercase', $optionsPwdLength, [$conf->getpwdPolicyMinLowercase()], _('Minimum lowercase characters'), '242')); +$row->add(new htmlResponsiveSelect('pwdPolicyMinUppercase', $optionsPwdLength, [$conf->getPwdPolicyMinUppercase()], _('Minimum uppercase characters'), '242')); +$row->add(new htmlResponsiveSelect('pwdPolicyMinNumeric', $optionsPwdLength, [$conf->getPwdPolicyMinNumeric()], _('Minimum numeric characters'), '242')); +$row->add(new htmlResponsiveSelect('pwdPolicyMinSymbolic', $optionsPwdLength, [$conf->getPwdPolicyMinSymbolic()], _('Minimum symbolic characters'), '242')); // 2factor authentication if (extension_loaded('curl')) { $row->add(new htmlSubTitle(_("2-factor authentication"), '../../graphics/locked.svg'), 12); - $twoFactorOptions = array( - _('None') => TwoFactorProviderService::TWO_FACTOR_NONE, - 'privacyIDEA' => TwoFactorProviderService::TWO_FACTOR_PRIVACYIDEA, - 'YubiKey' => TwoFactorProviderService::TWO_FACTOR_YUBICO, - 'Duo' => TwoFactorProviderService::TWO_FACTOR_DUO, - 'Okta' => TwoFactorProviderService::TWO_FACTOR_OKTA, - 'OpenId' => TwoFactorProviderService::TWO_FACTOR_OPENID, - 'WebAuthn' => TwoFactorProviderService::TWO_FACTOR_WEBAUTHN - ); - $twoFactorSelect = new htmlResponsiveSelect('twoFactor', $twoFactorOptions, array($conf->getTwoFactorAuthentication()), _('Provider'), '514'); + $twoFactorOptions = [ + _('None') => TwoFactorProviderService::TWO_FACTOR_NONE, + 'privacyIDEA' => TwoFactorProviderService::TWO_FACTOR_PRIVACYIDEA, + 'YubiKey' => TwoFactorProviderService::TWO_FACTOR_YUBICO, + 'Duo' => TwoFactorProviderService::TWO_FACTOR_DUO, + 'Okta' => TwoFactorProviderService::TWO_FACTOR_OKTA, + 'OpenId' => TwoFactorProviderService::TWO_FACTOR_OPENID, + 'WebAuthn' => TwoFactorProviderService::TWO_FACTOR_WEBAUTHN + ]; + $twoFactorSelect = new htmlResponsiveSelect('twoFactor', $twoFactorOptions, [$conf->getTwoFactorAuthentication()], _('Provider'), '514'); $twoFactorSelect->setHasDescriptiveElements(true); - $twoFactorSelect->setTableRowsToHide(array( - TwoFactorProviderService::TWO_FACTOR_NONE => array('twoFactorURL', 'twoFactorURLs', 'twoFactorInsecure', 'twoFactorLabel', - 'twoFactorOptional', 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute', 'twoFactorDomain', - 'twoFactorAllowToRememberDeviceOptions'), - TwoFactorProviderService::TWO_FACTOR_PRIVACYIDEA => array('twoFactorURLs', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorDomain'), - TwoFactorProviderService::TWO_FACTOR_YUBICO => array('twoFactorURL', 'twoFactorAttribute', 'twoFactorDomain'), - TwoFactorProviderService::TWO_FACTOR_DUO => array('twoFactorURLs', 'twoFactorOptional', 'twoFactorInsecure', 'twoFactorLabel', 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'), - TwoFactorProviderService::TWO_FACTOR_OKTA => array('twoFactorURLs', 'twoFactorOptional', 'twoFactorInsecure', 'twoFactorLabel', 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'), - TwoFactorProviderService::TWO_FACTOR_OPENID => array('twoFactorURLs', 'twoFactorOptional', 'twoFactorInsecure', 'twoFactorLabel', 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'), - TwoFactorProviderService::TWO_FACTOR_WEBAUTHN => array('twoFactorURL', 'twoFactorURLs', 'twoFactorInsecure', 'twoFactorLabel', - 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute'), - )); - $twoFactorSelect->setTableRowsToShow(array( - TwoFactorProviderService::TWO_FACTOR_PRIVACYIDEA => array('twoFactorURL', 'twoFactorInsecure', 'twoFactorLabel', - 'twoFactorOptional', 'twoFactorCaption', 'twoFactorAttribute', 'twoFactorAllowToRememberDeviceOptions'), - TwoFactorProviderService::TWO_FACTOR_YUBICO => array('twoFactorURLs', 'twoFactorInsecure', 'twoFactorLabel', - 'twoFactorOptional', 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAllowToRememberDeviceOptions'), - TwoFactorProviderService::TWO_FACTOR_DUO => array('twoFactorURL', 'twoFactorLabel', - 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute'), - TwoFactorProviderService::TWO_FACTOR_OKTA => array('twoFactorURL', 'twoFactorCaption', - 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute'), - TwoFactorProviderService::TWO_FACTOR_OPENID => array('twoFactorURL', 'twoFactorCaption', - 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute'), - TwoFactorProviderService::TWO_FACTOR_WEBAUTHN => array('twoFactorDomain', 'twoFactorOptional', 'twoFactorAllowToRememberDeviceOptions') - )); + $twoFactorSelect->setTableRowsToHide([ + TwoFactorProviderService::TWO_FACTOR_NONE => ['twoFactorURL', 'twoFactorURLs', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorOptional', 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute', + 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'], + TwoFactorProviderService::TWO_FACTOR_PRIVACYIDEA => ['twoFactorURLs', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorDomain'], + TwoFactorProviderService::TWO_FACTOR_YUBICO => ['twoFactorURL', 'twoFactorAttribute', 'twoFactorDomain'], + TwoFactorProviderService::TWO_FACTOR_DUO => ['twoFactorURLs', 'twoFactorOptional', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'], + TwoFactorProviderService::TWO_FACTOR_OKTA => ['twoFactorURLs', 'twoFactorOptional', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'], + TwoFactorProviderService::TWO_FACTOR_OPENID => ['twoFactorURLs', 'twoFactorOptional', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorDomain', 'twoFactorAllowToRememberDeviceOptions'], + TwoFactorProviderService::TWO_FACTOR_WEBAUTHN => ['twoFactorURL', 'twoFactorURLs', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute'] + ]); + $twoFactorSelect->setTableRowsToShow([ + TwoFactorProviderService::TWO_FACTOR_PRIVACYIDEA => ['twoFactorURL', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorOptional', 'twoFactorCaption', 'twoFactorAttribute', 'twoFactorAllowToRememberDeviceOptions'], + TwoFactorProviderService::TWO_FACTOR_YUBICO => ['twoFactorURLs', 'twoFactorInsecure', 'twoFactorLabel', + 'twoFactorOptional', 'twoFactorCaption', 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAllowToRememberDeviceOptions'], + TwoFactorProviderService::TWO_FACTOR_DUO => ['twoFactorURL', 'twoFactorLabel', 'twoFactorCaption', + 'twoFactorClientId', 'twoFactorSecretKey', 'twoFactorAttribute'], + TwoFactorProviderService::TWO_FACTOR_OKTA => ['twoFactorURL', 'twoFactorCaption', 'twoFactorClientId', + 'twoFactorSecretKey', 'twoFactorAttribute'], + TwoFactorProviderService::TWO_FACTOR_OPENID => ['twoFactorURL', 'twoFactorCaption', 'twoFactorClientId', + 'twoFactorSecretKey', 'twoFactorAttribute'], + TwoFactorProviderService::TWO_FACTOR_WEBAUTHN => ['twoFactorDomain', 'twoFactorOptional', + 'twoFactorAllowToRememberDeviceOptions'] + ]); $row->add($twoFactorSelect); $twoFactorAttribute = new htmlResponsiveInputField(_("User name attribute"), 'twoFactorAttribute', $conf->getTwoFactorAuthenticationAttribute(), '528'); $row->add($twoFactorAttribute); @@ -557,7 +567,7 @@ $rememberDeviceRow->setId('twoFactorAllowToRememberDeviceOptions'); $twoFactorAllowToRememberDeviceChecked = ($conf->getTwoFactorAllowToRememberDevice() === 'true'); $twoFactorAllowToRememberDevice = new htmlResponsiveInputCheckbox('twoFactorAllowToRememberDevice', $twoFactorAllowToRememberDeviceChecked, _('Allow remembering device'), '530'); - $twoFactorAllowToRememberDevice->setTableRowsToShow(array('twoFactorAllowToRememberDeviceExtraOptions')); + $twoFactorAllowToRememberDevice->setTableRowsToShow(['twoFactorAllowToRememberDeviceExtraOptions']); $rememberDeviceRow->add($twoFactorAllowToRememberDevice); $rememberDeviceExtraRow = new htmlResponsiveRow(); $rememberDeviceExtraRow->setId('twoFactorAllowToRememberDeviceExtraOptions'); @@ -582,19 +592,19 @@ $row->addVerticalSpacer('2rem'); -parseHtml(null, $row, array(), false, 'user'); +parseHtml(null, $row, [], false, 'user'); echo ""; $buttonContainer = new htmlTable(); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); $saveButton = new htmlButton('saveSettings', _('Save')); -$saveButton->setCSSClasses(array('lam-primary')); +$saveButton->setCSSClasses(['lam-primary']); $buttonContainer->addElement($saveButton); $cancelButton = new htmlButton('cancelSettings', _('Cancel')); $buttonContainer->addElement($cancelButton, true); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); -parseHtml(null, $buttonContainer, array(), false, 'user'); +parseHtml(null, $buttonContainer, [], false, 'user'); ?> @@ -612,14 +622,14 @@ function checkInput(): array { $conf = &$_SESSION['conf_config']; // check new preferences - $errors = array(); + $errors = []; if (!$conf->set_ServerURL($_POST['serverurl'])) { - $errors[] = array("ERROR", _("Server address is invalid!")); + $errors[] = ["ERROR", _("Server address is invalid!")]; } $conf->setServerDisplayName($_POST['serverDisplayName']); $conf->setUseTLS($_POST['useTLS']); - if ((strpos($_POST['serverurl'], 'ldaps://') !== false) && ($_POST['useTLS'] == 'yes')) { - $errors[] = array("ERROR", _('You cannot use SSL and TLS encryption at the same time. Please use either "ldaps://" or TLS.')); + if ((str_contains($_POST['serverurl'], 'ldaps://')) && ($_POST['useTLS'] == 'yes')) { + $errors[] = ["ERROR", _('You cannot use SSL and TLS encryption at the same time. Please use either "ldaps://" or TLS.')]; } if (isset($_POST['followReferrals']) && ($_POST['followReferrals'] == 'on')) { $conf->setFollowReferrals('true'); @@ -669,13 +679,13 @@ function checkInput(): array { } $conf->setPwdResetDefaultPasswordOutput($_POST['pwdResetDefaultPasswordOutput']); if (!$conf->setLamProMailFrom($_POST['pwdResetMail_from'])) { - $errors[] = array("ERROR", _("From address for password mails is invalid."), htmlspecialchars($_POST['pwdResetMail_from'])); + $errors[] = ["ERROR", _("From address for password mails is invalid."), htmlspecialchars($_POST['pwdResetMail_from'])]; } if (!empty($_POST['pwdResetMail_subject']) && empty($_POST['pwdResetMail_from'])) { - $errors[] = array("ERROR", _("From address for password mails is invalid."), htmlspecialchars($_POST['pwdResetMail_from'])); + $errors[] = ["ERROR", _("From address for password mails is invalid."), htmlspecialchars($_POST['pwdResetMail_from'])]; } if (!$conf->setLamProMailReplyTo($_POST['pwdResetMail_replyTo'])) { - $errors[] = array("ERROR", _("Reply-to address for password mails is invalid."), htmlspecialchars($_POST['pwdResetMail_replyTo'])); + $errors[] = ["ERROR", _("Reply-to address for password mails is invalid."), htmlspecialchars($_POST['pwdResetMail_replyTo'])]; } $conf->setLamProMailSubject($_POST['pwdResetMail_subject']); if (isset($_POST['pwdResetMail_isHTML']) && ($_POST['pwdResetMail_isHTML'] == 'on')) { @@ -694,7 +704,7 @@ function checkInput(): array { } $adminText = $_POST['admins']; $adminText = explode("\n", $adminText); - $adminTextNew = array(); + $adminTextNew = []; for ($i = 0; $i < sizeof($adminText); $i++) { if (trim($adminText[$i]) == "") { continue; @@ -708,7 +718,7 @@ function checkInput(): array { $conf->setLoginSearchDN($_POST['loginSearchDN']); if ($_POST['loginMethod'] == LAMConfig::LOGIN_SEARCH) { // check only if search method if (!$conf->setLoginSearchDN($_POST['loginSearchDN'])) { - $errors[] = array("ERROR", _("Please enter a valid bind user.")); + $errors[] = ["ERROR", _("Please enter a valid bind user.")]; } } if (isset($_POST['httpAuthentication']) && ($_POST['httpAuthentication'] == 'on')) { @@ -718,17 +728,17 @@ function checkInput(): array { $conf->setHttpAuthentication('false'); } if (!$conf->set_Adminstring(implode(";", $adminTextNew))) { - $errors[] = array("ERROR", _("List of admin users is empty or invalid!")); + $errors[] = ["ERROR", _("List of admin users is empty or invalid!")]; } if (!$conf->set_defaultLanguage($_POST['lang'])) { - $errors[] = array("ERROR", _("Language is not defined!")); + $errors[] = ["ERROR", _("Language is not defined!")]; } $conf->setTimeZone($_POST['timeZone']); if (!$conf->set_scriptpath($_POST['scriptpath'])) { - $errors[] = array("ERROR", _("Script path is invalid!")); + $errors[] = ["ERROR", _("Script path is invalid!")]; } if (!$conf->set_scriptservers($_POST['scriptservers'])) { - $errors[] = array("ERROR", _("Script server is invalid!")); + $errors[] = ["ERROR", _("Script server is invalid!")]; } $chmodOwner = 0; $chmodGroup = 0; @@ -762,7 +772,7 @@ function checkInput(): array { } $chmod = $chmodOwner . $chmodGroup . $chmodOther; if (!$conf->set_scriptrights($chmod)) { - $errors[] = array("ERROR", _("Script rights are invalid!")); + $errors[] = ["ERROR", _("Script rights are invalid!")]; } $conf->setScriptUserName($_POST['scriptuser']); $conf->setScriptSSHKey($_POST['scriptkey']); @@ -774,7 +784,7 @@ function checkInput(): array { $remote->loadKey($conf->getScriptSSHKey(), $conf->getScriptSSHKeyPassword()); } catch (\LAMException $e) { - $errors[] = array('ERROR', _('SSH key file'), $e->getTitle()); + $errors[] = ['ERROR', _('SSH key file'), $e->getTitle()]; } } // tool settings @@ -784,7 +794,7 @@ function checkInput(): array { $toolSettings[$key] = implode(LAMConfig::LINE_SEPARATOR, $value); } foreach ($tools as $tool) { - $toolClass = get_class($tool); + $toolClass = $tool::class; if ($toolClass === false) { continue; } @@ -825,7 +835,7 @@ function checkInput(): array { $conf->setTwoFactorAuthenticationInsecure(isset($_POST['twoFactorInsecure']) && ($_POST['twoFactorInsecure'] === 'on')); $conf->setTwoFactorAuthenticationLabel($_POST['twoFactorLabel']); $conf->setTwoFactorAuthenticationOptional(isset($_POST['twoFactorOptional']) && ($_POST['twoFactorOptional'] === 'on')); - $conf->setTwoFactorAuthenticationCaption(str_replace(array("\r", "\n"), array('', ''), $_POST['twoFactorCaption'])); + $conf->setTwoFactorAuthenticationCaption(str_replace(["\r", "\n"], ['', ''], $_POST['twoFactorCaption'])); $twoFactorAllowToRememberDevice = (isset($_POST['twoFactorAllowToRememberDevice']) && ($_POST['twoFactorAllowToRememberDevice'] === 'on')) ? 'true' : 'false'; $conf->setTwoFactorAllowToRememberDevice($twoFactorAllowToRememberDevice); $conf->setTwoFactorRememberDeviceDuration(unformatShortFormatToSeconds($_POST['twoFactorRememberDeviceDuration'])); @@ -834,7 +844,7 @@ function checkInput(): array { // check if password was changed if (isset($_POST['passwd1']) && ($_POST['passwd1'] != '')) { if ($_POST['passwd1'] != $_POST['passwd2']) { - $errors[] = array("ERROR", _("Passwords are different!")); + $errors[] = ["ERROR", _("Passwords are different!")]; } else { // set new password diff --git a/lam/templates/config/confmodules.php b/lam/templates/config/confmodules.php index cf86d9fd0..b2de067a4 100644 --- a/lam/templates/config/confmodules.php +++ b/lam/templates/config/confmodules.php @@ -15,7 +15,7 @@ use \htmlGroup; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2022 Roland Gruber + Copyright (C) 2004 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -140,19 +140,19 @@ $container->add($legendContainer, 12); $container->add(new htmlHiddenInput('postAvailable', 'yes'), 12); -parseHtml(null, $container, array(), false, 'user'); +parseHtml(null, $container, [], false, 'user'); echo ""; $buttonContainer = new htmlTable(); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); $saveButton = new htmlButton('saveSettings', _('Save')); -$saveButton->setCSSClasses(array('lam-primary')); +$saveButton->setCSSClasses(['lam-primary']); $buttonContainer->addElement($saveButton); $cancelButton = new htmlButton('cancelSettings', _('Cancel')); $buttonContainer->addElement($cancelButton, true); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); -parseHtml(null, $buttonContainer, array(), false, 'user'); +parseHtml(null, $buttonContainer, [], false, 'user'); if ((sizeof($errorsToDisplay) == 0) && isset($_POST['scrollPositionTop']) && isset($_POST['scrollPositionLeft'])) { // scroll to last position @@ -179,14 +179,14 @@ function config_showAccountModules($type, &$container): void { // account modules $available = getAvailableModules($type->getScope(), true); $selected = $type->getModules(); - $sortedAvailable = array(); + $sortedAvailable = []; for ($i = 0; $i < sizeof($available); $i++) { $sortedAvailable[$available[$i]] = getModuleAlias($available[$i], $type->getScope()); } natcasesort($sortedAvailable); // build options for selected and available modules - $selOptions = array(); + $selOptions = []; for ($i = 0; $i < sizeof($selected); $i++) { if (in_array($selected[$i], $available)) { // selected modules must be available if (is_base_module($selected[$i], $type->getScope())) { // mark base modules @@ -197,7 +197,7 @@ function config_showAccountModules($type, &$container): void { } } } - $availOptions = array(); + $availOptions = []; foreach ($sortedAvailable as $key => $value) { if (! in_array($key, $selected)) { // display non-selected modules if (is_base_module($key, $type->getScope())) { // mark base modules @@ -220,12 +220,12 @@ function config_showAccountModules($type, &$container): void { $container->addVerticalSpacer('1rem'); // selected modules if (sizeof($selOptions) > 0) { - $listElements = array(); + $listElements = []; foreach ($selOptions as $key => $value) { $el = new htmlTable('100%'); $mod = new $value($type->getScope()); $availModImage = new htmlImage('../../graphics/' . $mod->getIcon()); - $availModImage->setCSSClasses(array('size16', 'margin-right5-mobile-only')); + $availModImage->setCSSClasses(['size16', 'margin-right5-mobile-only']); $el->addElement($availModImage); $el->addElement(new htmlOutputText($key)); $delButton = new htmlButton('del_' . $type->getId() . '_' . $value, 'del.svg', true); @@ -235,7 +235,7 @@ function config_showAccountModules($type, &$container): void { } $selSortable = new htmlSortableList($listElements, $type->getId() . '_selected'); $selSortable->alignment = htmlElement::ALIGN_TOP; - $selSortable->setCSSClasses(array('module-list')); + $selSortable->setCSSClasses(['module-list']); $selSortable->setOnUpdate('function() {updateModulePositions(\'positions_' . $type->getId() . '\', \'' . $type->getId() . '_selected' . '\');}'); $container->add($selSortable, 12, 6); } @@ -251,7 +251,7 @@ function config_showAccountModules($type, &$container): void { foreach ($availOptions as $text => $key) { $mod = new $key($type->getScope()); $availModImage = new htmlImage('../../graphics/' . $mod->getIcon()); - $availModImage->setCSSClasses(array('size16', 'margin10')); + $availModImage->setCSSClasses(['size16', 'margin10']); $availTable->addElement($availModImage); $availTable->addElement(new htmlOutputText($text)); $addButton = new htmlButton('add_' . $type->getId() . '_' . $key, 'add.svg', true); @@ -260,10 +260,10 @@ function config_showAccountModules($type, &$container): void { } $availDiv = new htmlDiv(null, $availTable); $availDiv->alignment = htmlElement::ALIGN_TOP; - $availDiv->setCSSClasses(array('confModList')); + $availDiv->setCSSClasses(['confModList']); $container->add($availDiv, 12, 6); } - $positions = array(); + $positions = []; for ($i = 0; $i < sizeof($selOptions); $i++) { $positions[] = $i; } @@ -279,9 +279,9 @@ function config_showAccountModules($type, &$container): void { */ function checkInput(): array { if (!isset($_POST['postAvailable'])) { - return array(); + return []; } - $errors = array(); + $errors = []; $conf = &$_SESSION['conf_config']; $typeSettings = $conf->get_typeSettings(); $typeManager = new \LAM\TYPES\TypeManager($conf); @@ -290,9 +290,9 @@ function checkInput(): array { $scope = $type->getScope(); $typeId = $type->getId(); $available = getAvailableModules($scope, true); - $selected_temp = (isset($typeSettings['modules_' . $typeId])) ? $typeSettings['modules_' . $typeId] : ''; + $selected_temp = $typeSettings['modules_' . $typeId] ?? ''; $selected_temp = explode(',', $selected_temp); - $selected = array(); + $selected = []; // only use available modules as selected for ($i = 0; $i < sizeof($selected_temp); $i++) { if (in_array($selected_temp[$i], $available)) { @@ -303,14 +303,14 @@ function checkInput(): array { $sorting = $_POST['positions_' . $typeId]; if (!empty($sorting)) { $sorting = explode(',', $sorting); - $sortTmp = array(); + $sortTmp = []; foreach ($sorting as $pos) { $sortTmp[] = $selected[intval($pos)]; } $selected = $sortTmp; } // remove modules from selection - $new_selected = array(); + $new_selected = []; for ($i = 0; $i < sizeof($selected); $i++) { if (!isset($_POST['del_' . $typeId . '_' . $selected[$i]])) { $new_selected[] = $selected[$i]; @@ -330,16 +330,16 @@ function checkInput(): array { $depends = check_module_depends($selected, getModulesDependencies($scope)); if ($depends !== false) { for ($i = 0; $i < sizeof($depends); $i++) { - $errors[] = array('ERROR', $type->getAlias(), _("Unsolved dependency:") . ' ' . - $depends[$i][0] . " (" . $depends[$i][1] . ")"); + $errors[] = ['ERROR', $type->getAlias(), _("Unsolved dependency:") . ' ' . + $depends[$i][0] . " (" . $depends[$i][1] . ")"]; } } // check conflicts $conflicts = check_module_conflicts($selected, getModulesDependencies($scope)); if ($conflicts !== false) { for ($i = 0; $i < sizeof($conflicts); $i++) { - $errors[] = array('ERROR', $type->getAlias(), _("Conflicting module:") . ' ' . - $conflicts[$i][0] . " (" . $conflicts[$i][1] . ")"); + $errors[] = ['ERROR', $type->getAlias(), _("Conflicting module:") . ' ' . + $conflicts[$i][0] . " (" . $conflicts[$i][1] . ")"]; } } // check for base module @@ -350,7 +350,7 @@ function checkInput(): array { } } if ($baseCount != 1) { - $errors[] = array('ERROR', $type->getAlias(), _("No or more than one base module selected!")); + $errors[] = ['ERROR', $type->getAlias(), _("No or more than one base module selected!")]; } } $conf->set_typeSettings($typeSettings); diff --git a/lam/templates/config/confsave.php b/lam/templates/config/confsave.php index daecbc0b5..6b95518eb 100644 --- a/lam/templates/config/confsave.php +++ b/lam/templates/config/confsave.php @@ -73,17 +73,17 @@ try { $serverProfilePersistenceManager->saveProfile($conf, $confName); $scriptTag = new htmlJavaScript('window.lam.dialog.showSuccessMessageAndRedirect("' . _("Your settings were successfully saved.") . '", "' . htmlspecialchars($confName) . '", "' . _('Ok') . '", "../login.php")'); - parseHtml(null, $scriptTag, array(), false, null); + parseHtml(null, $scriptTag, [], false, null); } catch (LAMException $e) { $scriptTag = new htmlJavaScript('window.lam.dialog.showErrorMessageAndRedirect("' . htmlspecialchars($e->getTitle()) . '", "' . htmlspecialchars($e->getMessage()) . '", "' . _('Ok') . '", "../login.php")'); - parseHtml(null, $scriptTag, array(), false, null); + parseHtml(null, $scriptTag, [], false, null); } finally { // remove settings from session $sessionKeys = array_keys($_SESSION); for ($i = 0; $i < sizeof($sessionKeys); $i++) { - if (substr($sessionKeys[$i], 0, 5) == "conf_") { + if (str_starts_with($sessionKeys[$i], "conf_")) { unset($_SESSION[$sessionKeys[$i]]); } } diff --git a/lam/templates/config/conftypes.php b/lam/templates/config/conftypes.php index 6c10f0cbb..8bf21c62d 100644 --- a/lam/templates/config/conftypes.php +++ b/lam/templates/config/conftypes.php @@ -14,7 +14,7 @@ use \htmlResponsiveInputField; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2004 - 2022 Roland Gruber + Copyright (C) 2004 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -121,12 +121,12 @@ $allScopes = \LAM\TYPES\getTypes(); $typeManager = new \LAM\TYPES\TypeManager($conf); $activeTypes = $typeManager->getConfiguredTypes(); -$activeScopes = array(); +$activeScopes = []; foreach ($activeTypes as $activeType) { $activeScopes[] = $activeType->getScope(); } $activeScopes = array_unique($activeScopes); -$availableScopes = array(); +$availableScopes = []; foreach ($allScopes as $scope) { $scopeObj = new $scope(null); if (!in_array($scope, $activeScopes) || $scopeObj->supportsMultipleConfigs()) { @@ -166,18 +166,18 @@ $availableDescriptionRow->add(new htmlOutputText($availableScope->getDescription()), 10, 10, 10, 'responsiveField'); $button = new htmlButton('add_' . $availableScope->getScope(), 'add.svg', true); $button->setTitle(_("Add")); - $button->setCSSClasses(array('size16')); + $button->setCSSClasses(['size16']); $availableDescriptionRow->add($button, 2, 2, 2, 'responsiveField'); $row->addField($availableDescriptionRow); $row->addVerticalSpacer('1rem'); } $row->addVerticalSpacer('2rem'); } -parseHtml(null, $row, array(), false, 'user'); +parseHtml(null, $row, [], false, 'user'); $container = new htmlResponsiveRow(); -$_SESSION['conftypes_optionTypes'] = array(); +$_SESSION['conftypes_optionTypes'] = []; // show active types if (sizeof($activeTypes) > 0) { $container->add(new htmlSubTitle(_("Active account types")), 12); @@ -198,21 +198,21 @@ if ($index > 0) { $upButton = new htmlButton('moveup_'. $activeType->getId(), 'up.svg', true); $upButton->setTitle(_("Up")); - $upButton->setCSSClasses(array('size16')); + $upButton->setCSSClasses(['size16']); $buttons->addElement($upButton); } if ($index < (sizeof($activeTypes) - 1)) { $upButton = new htmlButton('movedown_'. $activeType->getId(), 'down.svg', true); $upButton->setTitle(_("Down")); - $upButton->setCSSClasses(array('size16')); + $upButton->setCSSClasses(['size16']); $buttons->addElement($upButton); } // delete button $delButton = new htmlButton('rem_'. $activeType->getId(), 'del.svg', true); $delButton->setTitle(_("Remove this account type")); - $delButton->setCSSClasses(array('size16')); + $delButton->setCSSClasses(['size16']); $buttons->addElement($delButton); - $buttonsDiv = new htmlDiv(null, $buttons, array('text-right')); + $buttonsDiv = new htmlDiv(null, $buttons, ['text-right']); $descriptionRow->add($buttonsDiv, 12, 12, 3, 'responsiveLabel'); $container->addField($descriptionRow); $container->addVerticalSpacer('0.5rem'); @@ -255,7 +255,7 @@ } // save option types to session ob_start(); - $typeConfigOptionTypes = parseHtml(null, $typeConfigOptions, array(), true, 'user'); + $typeConfigOptionTypes = parseHtml(null, $typeConfigOptions, [], true, 'user'); ob_end_clean(); $_SESSION['conftypes_optionTypes'] = array_merge($_SESSION['conftypes_optionTypes'], $typeConfigOptionTypes); } @@ -268,7 +268,7 @@ $isReadOnly = $typeSettings['readOnly_' . $activeType->getId()]; } $readOnly = new htmlResponsiveInputCheckbox('readOnly_' . $activeType->getId(), $isReadOnly, _('Read-only'), '265'); - $readOnly->setElementsToDisable(array('hideNewButton_' . $activeType->getId(), 'hideDeleteButton_' . $activeType->getId())); + $readOnly->setElementsToDisable(['hideNewButton_' . $activeType->getId(), 'hideDeleteButton_' . $activeType->getId()]); $advancedOptions->add($readOnly, 12); } // hidden type @@ -298,7 +298,7 @@ } } -$dynamicTypeOptions = array(); +$dynamicTypeOptions = []; foreach ($_SESSION['conftypes_optionTypes'] as $key => $value) { if (isset($typeSettings[$key])) { $dynamicTypeOptions[$key] = explode(LAMConfig::LINE_SEPARATOR, $typeSettings[$key]); @@ -313,12 +313,12 @@ $buttonContainer = new htmlTable(); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); $saveButton = new htmlButton('saveSettings', _('Save')); -$saveButton->setCSSClasses(array('lam-primary')); +$saveButton->setCSSClasses(['lam-primary']); $buttonContainer->addElement($saveButton); $cancelButton = new htmlButton('cancelSettings', _('Cancel')); $buttonContainer->addElement($cancelButton, true); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); -parseHtml(null, $buttonContainer, array(), false, 'user'); +parseHtml(null, $buttonContainer, [], false, 'user'); echo "\n"; echo "\n"; @@ -332,9 +332,9 @@ */ function checkInput(): array { if (!isset($_POST['postAvailable'])) { - return array(); + return []; } - $errors = array(); + $errors = []; $conf = &$_SESSION['conf_config']; $typeManager = new \LAM\TYPES\TypeManager($conf); $typeSettings = $conf->get_typeSettings(); @@ -343,7 +343,7 @@ function checkInput(): array { for ($i = 0; $i < sizeof($postKeys); $i++) { $key = $postKeys[$i]; // check if remove button was pressed - if (substr($key, 0, 4) == "rem_") { + if (str_starts_with($key, "rem_")) { $type = substr($key, 4); $accountTypes = array_flip($accountTypes); unset($accountTypes[$type]); @@ -351,7 +351,7 @@ function checkInput(): array { $accountTypes = array_values($accountTypes); } // check if up button was pressed - elseif (substr($key, 0, 7) == "moveup_") { + elseif (str_starts_with($key, "moveup_")) { $type = substr($key, 7); $pos = array_search($type, $accountTypes); $temp = $accountTypes[$pos - 1]; @@ -359,7 +359,7 @@ function checkInput(): array { $accountTypes[$pos] = $temp; } // check if down button was pressed - elseif (substr($key, 0, 9) == "movedown_") { + elseif (str_starts_with($key, "movedown_")) { $type = substr($key, 9); $pos = array_search($type, $accountTypes); $temp = $accountTypes[$pos + 1]; @@ -367,19 +367,19 @@ function checkInput(): array { $accountTypes[$pos] = $temp; } // set suffixes - elseif (substr($key, 0, 7) == "suffix_") { + elseif (str_starts_with($key, "suffix_")) { $typeSettings[$key] = trim($_POST[$key]); $type = $typeManager->getConfiguredType(substr($postKeys[$i], 7)); if (strlen($_POST[$key]) < 1) { - $errors[] = array("ERROR", _("LDAP Suffix is invalid!"), $type->getAlias()); + $errors[] = ["ERROR", _("LDAP Suffix is invalid!"), $type->getAlias()]; } } // set attributes - elseif (substr($key, 0, 5) == "attr_") { + elseif (str_starts_with($key, "attr_")) { $typeSettings[$key] = $_POST[$key]; $type = $typeManager->getConfiguredType(substr($postKeys[$i], 5)); if (!is_string($_POST[$key]) || !preg_match("/^((#[^:;]+)|([^:;]*:[^:;]+))(;((#[^:;]+)|([^:;]*:[^:;]+)))*$/", $_POST[$key])) { - $errors[] = array("ERROR", _("List attributes are invalid!"), $type->getAlias()); + $errors[] = ["ERROR", _("List attributes are invalid!"), $type->getAlias()]; } } // set filter @@ -387,7 +387,7 @@ function checkInput(): array { $typeSettings[$key] = $_POST[$key]; } // set custom label - elseif (strpos($key, 'customLabel_') === 0) { + elseif (str_starts_with($key, 'customLabel_')) { $typeSettings[$key] = $_POST[$key]; } } @@ -421,7 +421,7 @@ function checkInput(): array { // new type foreach ($_POST as $key => $value) { // check if add button was pressed - if (substr($key, 0, 4) == "add_") { + if (str_starts_with($key, "add_")) { $scope = substr($key, 4); $accountTypes[] = $typeManager->generateNewTypeId($scope); } @@ -434,10 +434,10 @@ function checkInput(): array { $conf->set_typeSettings($typeSettings); $conf->set_ActiveTypes($accountTypes); // check for duplicate type aliases - $aliasNames = array(); + $aliasNames = []; foreach ($typeManager->getConfiguredTypes() as $type) { if (in_array($type->getAlias(), $aliasNames)) { - $errors[] = array('ERROR', _('Please set a unique label for the account types.'), htmlspecialchars($type->getAlias())); + $errors[] = ['ERROR', _('Please set a unique label for the account types.'), htmlspecialchars($type->getAlias())]; } $aliasNames[] = $type->getAlias(); } diff --git a/lam/templates/config/index.php b/lam/templates/config/index.php index 07721847e..1ad702c2a 100644 --- a/lam/templates/config/index.php +++ b/lam/templates/config/index.php @@ -5,7 +5,7 @@ /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2003 - 2022 Roland Gruber + Copyright (C) 2003 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -66,7 +66,7 @@ menu @@ -83,21 +83,21 @@ setCSSClasses(array('maxrow fullwidth roundedShadowBox spacing5')); + $topContent->setCSSClasses(['maxrow fullwidth roundedShadowBox spacing5']); $mainCfgLink = new htmlLink(_("Edit general settings"), 'mainlogin.php', '../../graphics/configure.svg'); - $mainCfgLink->setCSSClasses(array('lam-margin-large display-as-block icon-big')); + $mainCfgLink->setCSSClasses(['lam-margin-large display-as-block icon-big']); $topContent->add($mainCfgLink, 12); $cfgLink = new htmlLink(_("Edit server profiles"), 'conflogin.php', '../../graphics/world.svg'); - $cfgLink->setCSSClasses(array('lam-margin-large display-as-block icon-big')); + $cfgLink->setCSSClasses(['lam-margin-large display-as-block icon-big']); $topContent->add($cfgLink, 12); if (isLAMProVersion()) { $selfServiceLink = new htmlLink(_("Edit self service"), '../selfService/adminLogin.php', '../../graphics/people.svg'); - $selfServiceLink->setCSSClasses(array('lam-margin-large display-as-block icon-big')); + $selfServiceLink->setCSSClasses(['lam-margin-large display-as-block icon-big']); $topContent->add($selfServiceLink, 12); } $topContent->addVerticalSpacer('1rem'); $importExportLink = new htmlLink(_("Import and export configuration"), 'confImportExport.php', '../../graphics/export.svg'); - $importExportLink->setCSSClasses(array('lam-margin-large display-as-block icon-big')); + $importExportLink->setCSSClasses(['lam-margin-large display-as-block icon-big']); $topContent->add($importExportLink, 12); $content->add($topContent, 12); $content->addVerticalSpacer('4rem'); @@ -114,7 +114,7 @@ $content->add(new htmlLink(_("Back to login"), '../login.php'), 12); $content->addVerticalSpacer('2rem'); - parseHtml(null, $content, array(), true, null); + parseHtml(null, $content, [], true, null); ?> diff --git a/lam/templates/config/mainlogin.php b/lam/templates/config/mainlogin.php index 092975524..1c1f6df5c 100644 --- a/lam/templates/config/mainlogin.php +++ b/lam/templates/config/mainlogin.php @@ -39,7 +39,7 @@ // start session if (isFileBasedSession()) { - session_save_path(dirname(__FILE__) . '/../../sess'); + session_save_path(__DIR__ . '/../../sess'); } lam_start_session(); session_regenerate_id(true); @@ -87,7 +87,7 @@ menu @@ -141,26 +141,26 @@ $passwordField = new htmlInputField('passwd'); $passwordField->setFieldSize(15); $passwordField->setIsPassword(true); - $passwordField->setCSSClasses(array('lam-initial-focus')); + $passwordField->setCSSClasses(['lam-initial-focus']); $passwordGroup->addElement($passwordField); $passwordGroup->addElement(new htmlHelpLink('236')); $passwordDiv = new htmlDiv(null, $passwordGroup); - $passwordDiv->setCSSClasses(array('nowrap')); + $passwordDiv->setCSSClasses(['nowrap']); $row = new htmlResponsiveRow($label, $passwordDiv); $group->addElement($row); // button $group->addElement($spacer); $okButton = new htmlButton('submit', _("Ok")); - $okButton->setCSSClasses(array('lam-primary')); + $okButton->setCSSClasses(['lam-primary']); $row = new htmlResponsiveRow(); $row->add($okButton, 12); - $row->setCSSClasses(array('')); + $row->setCSSClasses(['']); $group->addElement($row); $div = new htmlDiv(null, $group); - $div->setCSSClasses(array('centeredTable')); + $div->setCSSClasses(['centeredTable']); - parseHtml(null, $div, array(), false, 'user'); + parseHtml(null, $div, [], false, 'user'); ?> diff --git a/lam/templates/config/mainmanage.php b/lam/templates/config/mainmanage.php index 43c70dda3..2ae2db4d6 100644 --- a/lam/templates/config/mainmanage.php +++ b/lam/templates/config/mainmanage.php @@ -112,7 +112,7 @@ menu @@ -130,8 +130,8 @@ // include all JavaScript files printJsIncludes('../..'); -$errors = array(); -$messages = array(); +$errors = []; +$messages = []; // check if submit button was pressed if (isset($_POST['submitFormData'])) { if (extension_loaded('PDO')) { @@ -274,7 +274,7 @@ $cfg->passwordMustNotContainUser = isset($_POST['passwordMustNotContainUser']) && ($_POST['passwordMustNotContainUser'] == 'on') ? 'true' : 'false'; if (function_exists('curl_init')) { $cfg->externalPwdCheckUrl = $_POST['externalPwdCheckUrl']; - if (!empty($cfg->externalPwdCheckUrl) && (strpos($cfg->externalPwdCheckUrl, '{SHA1PREFIX}') === false)) { + if (!empty($cfg->externalPwdCheckUrl) && (!str_contains($cfg->externalPwdCheckUrl, '{SHA1PREFIX}'))) { $errors[] = _('The URL for the external password check is invalid.'); } } @@ -288,7 +288,7 @@ $errors[] = _('Unable to create temporary file.'); } else { - $data = fread($handle, 10000000); + $data = fread($handle, 10_000_000); if ($data === false) { $errors[] = _('Unable to create temporary file.'); } @@ -310,7 +310,7 @@ $messages[] = _('You might need to restart your webserver for changes to take effect.'); } if (isset($_POST['sslCaCertImport'])) { - $matches = array(); + $matches = []; if (preg_match('/^ldaps:\\/\\/([a-zA-Z0-9_\\.-]+)(:([0-9]+))?$/', $_POST['serverurl'], $matches)) { $port = '636'; if (isset($matches[3]) && !empty($matches[3])) { @@ -329,7 +329,7 @@ } } foreach ($_POST as $key => $value) { - if (strpos($key, 'deleteCert_') === 0) { + if (str_starts_with($key, 'deleteCert_')) { $index = substr($key, strlen('deleteCert_')); $cfg->deleteSSLCaCert($index); } @@ -350,7 +350,7 @@ $cfg->save(); if (sizeof($errors) == 0) { $scriptTag = new htmlJavaScript('window.lam.dialog.showSuccessMessageAndRedirect("' . _("Your settings were successfully saved.") . '", "", "' . _('Ok') . '", "../login.php")'); - parseHtml(null, $scriptTag, array(), false, null); + parseHtml(null, $scriptTag, [], false, null); echo ''; exit(); } @@ -380,23 +380,23 @@ // database if (extension_loaded('PDO')) { $row->add(new htmlSubTitle(_('Configuration storage')), 12); - $storageProviders = array( - _('Local file system') => LAMCfgMain::DATABASE_FILE_SYSTEM - ); + $storageProviders = [ + _('Local file system') => LAMCfgMain::DATABASE_FILE_SYSTEM + ]; if (in_array('mysql', PDO::getAvailableDrivers())) { $storageProviders['MySQL'] = LAMCfgMain::DATABASE_MYSQL; } - $storageProviderSelect = new htmlResponsiveSelect('configDatabaseType', $storageProviders, array($cfg->configDatabaseType), _('Database type'), '293'); + $storageProviderSelect = new htmlResponsiveSelect('configDatabaseType', $storageProviders, [$cfg->configDatabaseType], _('Database type'), '293'); $storageProviderSelect->setHasDescriptiveElements(true); - $dbRowsToShow = array( - LAMCfgMain::DATABASE_FILE_SYSTEM => array(), - LAMCfgMain::DATABASE_MYSQL => array('configDatabaseServer', 'configDatabasePort', 'configDatabaseName', 'configDatabaseUser', 'configDatabasePassword') - ); + $dbRowsToShow = [ + LAMCfgMain::DATABASE_FILE_SYSTEM => [], + LAMCfgMain::DATABASE_MYSQL => ['configDatabaseServer', 'configDatabasePort', 'configDatabaseName', 'configDatabaseUser', 'configDatabasePassword'] + ]; $storageProviderSelect->setTableRowsToShow($dbRowsToShow); - $dbRowsToHide = array( - LAMCfgMain::DATABASE_FILE_SYSTEM => array('configDatabaseServer', 'configDatabasePort', 'configDatabaseName', 'configDatabaseUser', 'configDatabasePassword'), - LAMCfgMain::DATABASE_MYSQL => array() - ); + $dbRowsToHide = [ + LAMCfgMain::DATABASE_FILE_SYSTEM => ['configDatabaseServer', 'configDatabasePort', 'configDatabaseName', 'configDatabaseUser', 'configDatabasePassword'], + LAMCfgMain::DATABASE_MYSQL => [] + ]; $storageProviderSelect->setTableRowsToHide($dbRowsToHide); $row->add($storageProviderSelect, 12); $dbHost = new htmlResponsiveInputField(_('Database host'), 'configDatabaseServer', $cfg->configDatabaseServer, '273'); @@ -420,23 +420,23 @@ if (isLAMProVersion()) { $row->add(new htmlSubTitle(_('Licence')), 12); $row->add(new htmlResponsiveInputTextarea('license', implode("\n", $cfg->getLicenseLines()), '30', '10', _('Licence'), '287'), 12); - $warningOptions = array( - _('Screen') => LAMCfgMain::LICENSE_WARNING_SCREEN, - _('Email') => LAMCfgMain::LICENSE_WARNING_EMAIL, - _('Both') => LAMCfgMain::LICENSE_WARNING_ALL, - _('None') => LAMCfgMain::LICENSE_WARNING_NONE, - ); - $warningTypeSelect = new htmlResponsiveSelect('licenseWarningType', $warningOptions, array($cfg->getLicenseWarningType()), _('Expiration warning'), '288'); + $warningOptions = [ + _('Screen') => LAMCfgMain::LICENSE_WARNING_SCREEN, + _('Email') => LAMCfgMain::LICENSE_WARNING_EMAIL, + _('Both') => LAMCfgMain::LICENSE_WARNING_ALL, + _('None') => LAMCfgMain::LICENSE_WARNING_NONE + ]; + $warningTypeSelect = new htmlResponsiveSelect('licenseWarningType', $warningOptions, [$cfg->getLicenseWarningType()], _('Expiration warning'), '288'); $warningTypeSelect->setHasDescriptiveElements(true); $warningTypeSelect->setSortElements(false); - $warningTypeSelect->setTableRowsToHide(array( - LAMCfgMain::LICENSE_WARNING_SCREEN => array('licenseEmailFrom', 'licenseEmailTo'), - LAMCfgMain::LICENSE_WARNING_NONE => array('licenseEmailFrom', 'licenseEmailTo'), - )); - $warningTypeSelect->setTableRowsToShow(array( - LAMCfgMain::LICENSE_WARNING_EMAIL => array('licenseEmailFrom', 'licenseEmailTo'), - LAMCfgMain::LICENSE_WARNING_ALL => array('licenseEmailFrom', 'licenseEmailTo'), - )); + $warningTypeSelect->setTableRowsToHide([ + LAMCfgMain::LICENSE_WARNING_SCREEN => ['licenseEmailFrom', 'licenseEmailTo'], + LAMCfgMain::LICENSE_WARNING_NONE => ['licenseEmailFrom', 'licenseEmailTo'] + ]); + $warningTypeSelect->setTableRowsToShow([ + LAMCfgMain::LICENSE_WARNING_EMAIL => ['licenseEmailFrom', 'licenseEmailTo'], + LAMCfgMain::LICENSE_WARNING_ALL => ['licenseEmailFrom', 'licenseEmailTo'] + ]); $row->add($warningTypeSelect, 12); $licenseFrom = new htmlResponsiveInputField(_('From address'), 'licenseEmailFrom', $cfg->licenseEmailFrom, '289'); $licenseFrom->setRequired(true); @@ -450,8 +450,8 @@ // security settings $row->add(new htmlSubTitle(_("Security settings")), 12); - $options = array(5, 10, 20, 30, 60, 90, 120, 240); - $row->add(new htmlResponsiveSelect('sessionTimeout', $options, array($cfg->sessionTimeout), _("Session timeout"), '238')); + $options = [5, 10, 20, 30, 60, 90, 120, 240]; + $row->add(new htmlResponsiveSelect('sessionTimeout', $options, [$cfg->sessionTimeout], _("Session timeout"), '238')); $hideLoginErrorDetails = ($cfg->hideLoginErrorDetails === 'true'); $row->add(new htmlResponsiveInputCheckbox('hideLoginErrorDetails', $hideLoginErrorDetails, _('Hide LDAP details on failed login'), '257')); $row->add(new htmlResponsiveInputTextarea('allowedHosts', implode("\n", explode(",", $cfg->allowedHosts)), '30', '7', _("Allowed hosts"), '241')); @@ -475,7 +475,7 @@ $sslDownloadBtn = new htmlLink('', $temporaryFilesManager->getDownloadLink($sslFileName), '../../graphics/save.svg'); $sslDownloadBtn->setTargetWindow('_blank'); $sslDownloadBtn->setTitle(_('Download CA certificates')); - $sslDownloadBtn->setCSSClasses(array('icon')); + $sslDownloadBtn->setCSSClasses(['icon']); $sslDelSaveGroup->addElement($sslDownloadBtn); $sslDeleteBtn = new htmlButton('sslCaCertDelete', 'del.svg', true); $sslDeleteBtn->setTitle(_('Delete all CA certificates')); @@ -498,48 +498,48 @@ $sslCerts = $cfg->getSSLCaCertificates(); if (sizeof($sslCerts) > 0) { - $certsTitles = array(_('Common name'), _('Valid to'), _('Serial number'), _('Delete')); - $certsData = array(); + $certsTitles = [_('Common name'), _('Valid to'), _('Serial number'), _('Delete')]; + $certsData = []; for ($i = 0; $i < sizeof($sslCerts); $i++) { - $serial = isset($sslCerts[$i]['serialNumber']) ? $sslCerts[$i]['serialNumber'] : ''; - $validTo = isset($sslCerts[$i]['validTo_time_t']) ? $sslCerts[$i]['validTo_time_t'] : ''; + $serial = $sslCerts[$i]['serialNumber'] ?? ''; + $validTo = $sslCerts[$i]['validTo_time_t'] ?? ''; if (get_preg($validTo, 'digit')) { $date = DateTime::createFromFormat('U', $validTo, new DateTimeZone('UTC')); if ($date !== false) { $validTo = $date->format('Y-m-d'); } } - $cn = isset($sslCerts[$i]['subject']['CN']) ? $sslCerts[$i]['subject']['CN'] : ''; + $cn = $sslCerts[$i]['subject']['CN'] ?? ''; $delBtn = new htmlButton('deleteCert_' . $i, 'del.svg', true); - $certsData[] = array( - new htmlOutputText($cn), - new htmlDiv(null, new htmlOutputText($validTo), array('nowrap')), - new htmlOutputText($serial), - $delBtn - ); + $certsData[] = [ + new htmlOutputText($cn), + new htmlDiv(null, new htmlOutputText($validTo), ['nowrap']), + new htmlOutputText($serial), + $delBtn + ]; } $certsTable = new htmlResponsiveTable($certsTitles, $certsData); - $certsTable->setCSSClasses(array('text-left')); + $certsTable->setCSSClasses(['text-left']); $row->add($certsTable, 12); } // password policy $row->add(new htmlSubTitle(_("Password policy")), 12); - $optionsPwdLength = array(); + $optionsPwdLength = []; for ($i = 0; $i <= 50; $i++) { $optionsPwdLength[] = $i; } - $options4 = array(0, 1, 2, 3, 4); - $row->add(new htmlResponsiveSelect('passwordMinLength', $optionsPwdLength, array($cfg->passwordMinLength), _('Minimum password length'), '242'), 12); + $options4 = [0, 1, 2, 3, 4]; + $row->add(new htmlResponsiveSelect('passwordMinLength', $optionsPwdLength, [$cfg->passwordMinLength], _('Minimum password length'), '242'), 12); $row->addVerticalSpacer('1rem'); - $row->add(new htmlResponsiveSelect('passwordMinLower', $optionsPwdLength, array($cfg->passwordMinLower), _('Minimum lowercase characters'), '242'), 12); - $row->add(new htmlResponsiveSelect('passwordMinUpper', $optionsPwdLength, array($cfg->passwordMinUpper), _('Minimum uppercase characters'), '242'), 12); - $row->add(new htmlResponsiveSelect('passwordMinNumeric', $optionsPwdLength, array($cfg->passwordMinNumeric), _('Minimum numeric characters'), '242'), 12); - $row->add(new htmlResponsiveSelect('passwordMinSymbol', $optionsPwdLength, array($cfg->passwordMinSymbol), _('Minimum symbolic characters'), '242'), 12); - $row->add(new htmlResponsiveSelect('passwordMinClasses', $options4, array($cfg->passwordMinClasses), _('Minimum character classes'), '242'), 12); + $row->add(new htmlResponsiveSelect('passwordMinLower', $optionsPwdLength, [$cfg->passwordMinLower], _('Minimum lowercase characters'), '242'), 12); + $row->add(new htmlResponsiveSelect('passwordMinUpper', $optionsPwdLength, [$cfg->passwordMinUpper], _('Minimum uppercase characters'), '242'), 12); + $row->add(new htmlResponsiveSelect('passwordMinNumeric', $optionsPwdLength, [$cfg->passwordMinNumeric], _('Minimum numeric characters'), '242'), 12); + $row->add(new htmlResponsiveSelect('passwordMinSymbol', $optionsPwdLength, [$cfg->passwordMinSymbol], _('Minimum symbolic characters'), '242'), 12); + $row->add(new htmlResponsiveSelect('passwordMinClasses', $options4, [$cfg->passwordMinClasses], _('Minimum character classes'), '242'), 12); $row->addVerticalSpacer('1rem'); - $rulesCountOptions = array(_('all') => '-1', '3' => '3', '4' => '4'); - $rulesCountSelect = new htmlResponsiveSelect('passwordRulesCount', $rulesCountOptions, array($cfg->checkedRulesCount), _('Number of rules that must match'), '246'); + $rulesCountOptions = [_('all') => '-1', '3' => '3', '4' => '4']; + $rulesCountSelect = new htmlResponsiveSelect('passwordRulesCount', $rulesCountOptions, [$cfg->checkedRulesCount], _('Number of rules that must match'), '246'); $rulesCountSelect->setHasDescriptiveElements(true); $row->add($rulesCountSelect, 12); $passwordMustNotContainUser = ($cfg->passwordMustNotContainUser === 'true'); @@ -553,16 +553,21 @@ // logging $row->add(new htmlSubTitle(_("Logging")), 12); - $levelOptions = array(_("Debug") => LOG_DEBUG, _("Notice") => LOG_NOTICE, _("Warning") => LOG_WARNING, _("Error") => LOG_ERR); - $levelSelect = new htmlResponsiveSelect('logLevel', $levelOptions, array($cfg->logLevel), _("Log level"), '239'); + $levelOptions = [ + _("Debug") => LOG_DEBUG, + _("Notice") => LOG_NOTICE, + _("Warning") => LOG_WARNING, + _("Error") => LOG_ERR + ]; + $levelSelect = new htmlResponsiveSelect('logLevel', $levelOptions, [$cfg->logLevel], _("Log level"), '239'); $levelSelect->setHasDescriptiveElements(true); $row->add($levelSelect, 12); - $destinationOptions = array( - _("No logging") => "none", - _("System logging") => "syslog", - _("File") => 'file', - _("Remote") => 'remote', - ); + $destinationOptions = [ + _("No logging") => "none", + _("System logging") => "syslog", + _("File") => 'file', + _("Remote") => 'remote' + ]; $destinationSelected = 'file'; $destinationPath = $cfg->logDestination; $destinationRemote = ''; @@ -572,33 +577,33 @@ } elseif ($cfg->logDestination == 'SYSLOG') { $destinationSelected = 'syslog'; $destinationPath = ''; - } elseif (strpos($cfg->logDestination, 'REMOTE') === 0) { + } elseif (str_starts_with($cfg->logDestination, 'REMOTE')) { $destinationSelected = 'remote'; $remoteParts = explode(':', $cfg->logDestination, 2); $destinationRemote = empty($remoteParts[1]) ? '' : $remoteParts[1]; $destinationPath = ''; } - $logDestinationSelect = new htmlResponsiveSelect('logDestination', $destinationOptions, array($destinationSelected), _("Log destination"), '240'); - $logDestinationSelect->setTableRowsToHide(array( - 'none' => array('logFile', 'logRemote'), - 'syslog' => array('logFile', 'logRemote'), - 'remote' => array('logFile'), - 'file' => array('logRemote'), - )); - $logDestinationSelect->setTableRowsToShow(array( - 'file' => array('logFile'), - 'remote' => array('logRemote'), - )); + $logDestinationSelect = new htmlResponsiveSelect('logDestination', $destinationOptions, [$destinationSelected], _("Log destination"), '240'); + $logDestinationSelect->setTableRowsToHide([ + 'none' => ['logFile', 'logRemote'], + 'syslog' => ['logFile', 'logRemote'], + 'remote' => ['logFile'], + 'file' => ['logRemote'] + ]); + $logDestinationSelect->setTableRowsToShow([ + 'file' => ['logFile'], + 'remote' => ['logRemote'] + ]); $logDestinationSelect->setHasDescriptiveElements(true); $row->add($logDestinationSelect, 12); $row->add(new htmlResponsiveInputField(_('File'), 'logFile', $destinationPath), 12); $row->add(new htmlResponsiveInputField(_('Remote server'), 'logRemote', $destinationRemote, '251'), 12); - $errorLogOptions = array( - _('PHP system setting') => LAMCfgMain::ERROR_REPORTING_SYSTEM, - _('default') => LAMCfgMain::ERROR_REPORTING_DEFAULT, - _('all') => LAMCfgMain::ERROR_REPORTING_ALL - ); - $errorLogSelect = new htmlResponsiveSelect('errorReporting', $errorLogOptions, array($cfg->errorReporting), _('PHP error reporting'), '244'); + $errorLogOptions = [ + _('PHP system setting') => LAMCfgMain::ERROR_REPORTING_SYSTEM, + _('default') => LAMCfgMain::ERROR_REPORTING_DEFAULT, + _('all') => LAMCfgMain::ERROR_REPORTING_ALL + ]; + $errorLogSelect = new htmlResponsiveSelect('errorReporting', $errorLogOptions, [$cfg->errorReporting], _('PHP error reporting'), '244'); $errorLogSelect->setHasDescriptiveElements(true); $row->add($errorLogSelect); @@ -612,13 +617,13 @@ $mailPassword = new htmlResponsiveInputField(_("Password"), 'mailPassword', $cfg->mailPassword, '255'); $mailPassword->setIsPassword(true); $row->add($mailPassword); - $mailEncryptionOptions = array( - 'TLS' => LAMCfgMain::SMTP_TLS, - 'SSL' => LAMCfgMain::SMTP_SSL, - _('None') => LAMCfgMain::SMTP_NONE, - ); + $mailEncryptionOptions = [ + 'TLS' => LAMCfgMain::SMTP_TLS, + 'SSL' => LAMCfgMain::SMTP_SSL, + _('None') => LAMCfgMain::SMTP_NONE + ]; $selectedMailEncryption = empty($cfg->mailEncryption) ? LAMCfgMain::SMTP_TLS : $cfg->mailEncryption; - $mailEncryptionSelect = new htmlResponsiveSelect('mailEncryption', $mailEncryptionOptions, array($selectedMailEncryption), _('Encryption protocol'), '256'); + $mailEncryptionSelect = new htmlResponsiveSelect('mailEncryption', $mailEncryptionOptions, [$selectedMailEncryption], _('Encryption protocol'), '256'); $mailEncryptionSelect->setHasDescriptiveElements(true); $row->add($mailEncryptionSelect); addSecurityTokenToSession(false); @@ -642,11 +647,11 @@ $row->add($webauthnSearchField, 12); $row->addVerticalSpacer('0.5rem'); $row->add(new htmlButton('webauthn_search', _('Search')), 12, 12, 12, 'text-center'); - $resultDiv = new htmlDiv('webauthn_results', new htmlOutputText(''), array('lam-webauthn-results', 'text-left')); + $resultDiv = new htmlDiv('webauthn_results', new htmlOutputText(''), ['lam-webauthn-results', 'text-left']); addSecurityTokenToSession(false); $resultDiv->addDataAttribute('sec_token_value', getSecurityTokenValue()); $row->add($resultDiv); - $confirmationDiv = new htmlDiv('webauthnDeleteConfirm', new htmlOutputText(_('Do you really want to remove this device?')), array('hidden')); + $confirmationDiv = new htmlDiv('webauthnDeleteConfirm', new htmlOutputText(_('Do you really want to remove this device?')), ['hidden']); $row->add($confirmationDiv); } } @@ -671,7 +676,7 @@ if ($cfg->isWritable()) { $buttonTable = new htmlTable(); $saveButton = new htmlButton('submit', _("Save")); - $saveButton->setCSSClasses(array('lam-primary')); + $saveButton->setCSSClasses(['lam-primary']); $buttonTable->addElement($saveButton); $buttonTable->addElement(new htmlSpacer('0.5rem', null)); $buttonTable->addElement(new htmlButton('cancel', _("Cancel"))); @@ -680,8 +685,8 @@ } $box = new htmlDiv(null, $row); - $box->setCSSClasses(array('roundedShadowBox')); - parseHtml(null, $box, array(), false, 'user'); + $box->setCSSClasses(['roundedShadowBox']); + parseHtml(null, $box, [], false, 'user'); /** diff --git a/lam/templates/config/moduleSettings.php b/lam/templates/config/moduleSettings.php index 0cd31ac14..c2212ce33 100644 --- a/lam/templates/config/moduleSettings.php +++ b/lam/templates/config/moduleSettings.php @@ -9,7 +9,7 @@ /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2009 - 2022 Roland Gruber + Copyright (C) 2009 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -131,7 +131,7 @@ $types = $typeManager->getConfiguredTypes(); // get list of scopes of modules -$scopes = array(); +$scopes = []; foreach ($types as $type) { $mods = $conf->get_AccountModules($type->getId()); for ($i = 0; $i < sizeof($mods); $i++) { @@ -147,7 +147,7 @@ // display module boxes $modules = array_keys($options); -$_SESSION['conf_types'] = array(); +$_SESSION['conf_types'] = []; for ($i = 0; $i < sizeof($modules); $i++) { if (empty($options[$modules[$i]])) { continue; @@ -155,7 +155,7 @@ $module = moduleCache::getModule($modules[$i], null); $iconImage = $module->getIcon(); if ($iconImage != null) { - if (!(strpos($iconImage, 'http') === 0) && !(strpos($iconImage, '/') === 0)) { + if (!(str_starts_with($iconImage, 'http')) && !(str_starts_with($iconImage, '/'))) { $iconImage = '../../graphics/' . $iconImage; } } @@ -181,12 +181,12 @@ $buttonContainer = new htmlTable(); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); $saveButton = new htmlButton('saveSettings', _('Save')); -$saveButton->setCSSClasses(array('lam-primary')); +$saveButton->setCSSClasses(['lam-primary']); $buttonContainer->addElement($saveButton); $cancelButton = new htmlButton('cancelSettings', _('Cancel')); $buttonContainer->addElement($cancelButton, true); $buttonContainer->addElement(new htmlSpacer(null, '10px'), true); -parseHtml(null, $buttonContainer, array(), false, null); +parseHtml(null, $buttonContainer, [], false, null); if ((sizeof($errorsToDisplay) == 0) && isset($_POST['scrollPositionTop']) && isset($_POST['scrollPositionLeft'])) { // scroll to last position @@ -210,7 +210,7 @@ */ function checkInput(): array { if (!isset($_POST['postAvailable'])) { - return array(); + return []; } $conf = &$_SESSION['conf_config']; $typeManager = new \LAM\TYPES\TypeManager($conf); @@ -221,7 +221,7 @@ function checkInput(): array { $options = extractConfigOptionsFromPOST($_SESSION['conf_types']); // get list of scopes of modules - $scopes = array(); + $scopes = []; foreach ($types as $type) { $mods = $conf->get_AccountModules($type->getId()); for ($i = 0; $i < sizeof($mods); $i++) { diff --git a/lam/templates/config/profmanage.php b/lam/templates/config/profmanage.php index 5bd6f7e48..155155027 100644 --- a/lam/templates/config/profmanage.php +++ b/lam/templates/config/profmanage.php @@ -19,7 +19,7 @@ /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2003 - 2022 Roland Gruber + Copyright (C) 2003 - 2023 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -62,7 +62,7 @@ $cfg = new LAMCfgMain(); $serverProfilePersistenceManager = new ServerProfilePersistenceManager(); -$files = array(); +$files = []; try { $files = $serverProfilePersistenceManager->getProfiles(); } @@ -84,7 +84,7 @@ $serverProfilePersistenceManager->createProfileFromTemplate($_POST['addprofile'], $_POST['addTemplate'], $_POST['addpassword']); $_SESSION['conf_isAuthenticated'] = $_POST['addprofile']; $_SESSION['conf_config'] = $serverProfilePersistenceManager->loadProfile($_POST['addprofile']); - $_SESSION['conf_messages'][] = array('INFO', _("Created new profile."), $_POST['addprofile']); + $_SESSION['conf_messages'][] = ['INFO', _("Created new profile."), $_POST['addprofile']]; metaRefresh('confmain.php'); exit; } catch (LAMException $e) { @@ -113,7 +113,7 @@ $serverProfilePersistenceManager->deleteProfile($_POST['delfilename']); // update default profile setting if needed if ($cfg->default == $_POST['delfilename']) { - $filesNew = array_delete(array($_POST['delfilename']), $files); + $filesNew = array_delete([$_POST['delfilename']], $files); if (sizeof($filesNew) > 0) { sort($filesNew); $cfg->default = $filesNew[0]; @@ -183,7 +183,7 @@ menu @@ -233,25 +233,25 @@ $profileNewPwd2->setIsPassword(true); $profileNewPwd2->setSameValueFieldID('addpassword'); $box->add($profileNewPwd2); -$existing = array(); +$existing = []; foreach ($files as $file) { $existing[$file] = $file; } -$builtIn = array(); +$builtIn = []; foreach ($serverProfilePersistenceManager->getConfigTemplates() as $file) { $builtIn[$file] = $file . '.sample'; } -$templates = array( - _('Built-in templates') => $builtIn, - _('Existing server profiles') => $existing, -); -$addTemplateSelect = new htmlResponsiveSelect('addTemplate', $templates, array('unix.sample'), _('Template'), '267'); +$templates = [ + _('Built-in templates') => $builtIn, + _('Existing server profiles') => $existing +]; +$addTemplateSelect = new htmlResponsiveSelect('addTemplate', $templates, ['unix.sample'], _('Template'), '267'); $addTemplateSelect->setContainsOptgroups(true); $addTemplateSelect->setHasDescriptiveElements(true); $box->add($addTemplateSelect, 12); $box->addVerticalSpacer('0.5rem'); $newProfileButton = new htmlButton('btnAddProfile', _('Add')); -$newProfileButton->setCSSClasses(array('lam-primary')); +$newProfileButton->setCSSClasses(['lam-primary']); $newProfileButton->setOnClick("document.getElementById('action').value = 'add';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Add profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); @@ -260,12 +260,12 @@ // rename profile $box->add(new htmlSubTitle(_("Rename profile"))); -$box->add(new htmlResponsiveSelect('oldfilename', $files, array(), _('Profile name'), '231'), 12); +$box->add(new htmlResponsiveSelect('oldfilename', $files, [], _('Profile name'), '231'), 12); $oldProfileInput = new htmlResponsiveInputField(_('New profile name'), 'renfilename'); $box->add($oldProfileInput); $box->addVerticalSpacer('0.5rem'); $renameProfileButton = new htmlButton('btnRenameProfile', _('Rename')); -$renameProfileButton->setCSSClasses(array('lam-secondary')); +$renameProfileButton->setCSSClasses(['lam-secondary']); $renameProfileButton->setOnClick("document.getElementById('action').value = 'rename';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Rename profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); @@ -274,10 +274,10 @@ // delete profile $box->add(new htmlSubTitle(_("Delete profile")), 12); -$box->add(new htmlResponsiveSelect('delfilename', $files, array(), _('Profile name'), '232'), 12); +$box->add(new htmlResponsiveSelect('delfilename', $files, [], _('Profile name'), '232'), 12); $box->addVerticalSpacer('0.5rem'); $deleteProfileButton = new htmlButton('btnDeleteProfile', _('Delete')); -$deleteProfileButton->setCSSClasses(array('lam-danger')); +$deleteProfileButton->setCSSClasses(['lam-danger']); $deleteProfileButton->setOnClick("document.getElementById('action').value = 'delete';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Delete profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); @@ -286,7 +286,7 @@ // set password $box->add(new htmlSubTitle(_("Set profile password")), 12); -$box->add(new htmlResponsiveSelect('setprofile', $files, array(), _('Profile name'), '233'), 12); +$box->add(new htmlResponsiveSelect('setprofile', $files, [], _('Profile name'), '233'), 12); $profileSetPwd1 = new htmlResponsiveInputField(_("Profile password"), 'setpassword'); $profileSetPwd1->setIsPassword(true); $box->add($profileSetPwd1); @@ -296,7 +296,7 @@ $box->add($profileSetPwd2); $box->addVerticalSpacer('0.5rem'); $setPasswordProfileButton = new htmlButton('btnSetPasswordProfile', _('Set profile password')); -$setPasswordProfileButton->setCSSClasses(array('lam-secondary')); +$setPasswordProfileButton->setCSSClasses(['lam-secondary']); $setPasswordProfileButton->setOnClick("document.getElementById('action').value = 'setpass';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Set profile password") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); @@ -308,10 +308,10 @@ $conf = new LAMCfgMain(); $defaultProfile = $conf->default; $box->add(new htmlSubTitle(_("Change default profile"))); -$box->add(new htmlResponsiveSelect('defaultfilename', $files, array($defaultProfile), _('Profile name'), '234'), 12); +$box->add(new htmlResponsiveSelect('defaultfilename', $files, [$defaultProfile], _('Profile name'), '234'), 12); $box->addVerticalSpacer('0.5rem'); $defaultProfileButton = new htmlButton('btnDefaultProfile', _('Ok')); -$defaultProfileButton->setCSSClasses(array('lam-secondary')); +$defaultProfileButton->setCSSClasses(['lam-secondary']); $defaultProfileButton->setOnClick("document.getElementById('action').value = 'setdefault';" . "window.lam.dialog.requestPasswordAndSendForm('" . _("Change default profile") . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'passwd', 'profileForm');"); @@ -319,7 +319,7 @@ $box->add(new htmlOutputText(''), 0, 6); $boxDiv = new htmlDiv(null, $box); -$boxDiv->setCSSClasses(array('roundedShadowBox', 'limitWidth')); +$boxDiv->setCSSClasses(['roundedShadowBox', 'limitWidth']); $row->add($boxDiv); $row->add(new htmlHiddenInput('action', 'none')); @@ -328,7 +328,7 @@ $backLink = new htmlLink(_("Back to profile login"), 'conflogin.php'); $row->add($backLink, 12, 12, 12, 'text-left'); -parseHtml('', new htmlDiv(null, $row, array('centeredTable')), array(), false, 'user'); +parseHtml('', new htmlDiv(null, $row, ['centeredTable']), [], false, 'user'); ?>