refactoring

This commit is contained in:
Roland Gruber 2023-10-30 20:42:56 +01:00
parent c997d79be9
commit d611abedb4
8 changed files with 75 additions and 75 deletions

View file

@ -11,7 +11,7 @@ use htmlStatusMessage;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) 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 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 it under the terms of the GNU General Public License as published by
@ -79,7 +79,7 @@ if (isset($_POST['changePassword'])) {
} }
// check password strength // check password strength
$userDn = $_SESSION['ldap']->getUserName(); $userDn = $_SESSION['ldap']->getUserName();
$additionalAttrs = array(); $additionalAttrs = [];
$rdnAttr = extractRDNAttribute($userDn); $rdnAttr = extractRDNAttribute($userDn);
$userName = null; $userName = null;
if ($rdnAttr === 'uid') { if ($rdnAttr === 'uid') {
@ -139,7 +139,7 @@ function printContent($message = null, $showPasswordInputs = true): void {
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
} }
parseHtml(null, $container, array(), false, 'user'); parseHtml(null, $container, [], false, 'user');
echo "</form><br>\n"; echo "</form><br>\n";
echo "</div>\n"; echo "</div>\n";

View file

@ -11,7 +11,7 @@ use \htmlStatusMessage;
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz Copyright (C) 2003 - 2006 Tilo Lutz
Copyright (C) 2007 - 2022 Roland Gruber Copyright (C) 2007 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -76,7 +76,7 @@ if (!empty($_POST)) {
$sessionAccountPrefix = 'deleteContainer'; $sessionAccountPrefix = 'deleteContainer';
foreach ($_SESSION as $key => $value) { foreach ($_SESSION as $key => $value) {
if (strpos($key, $sessionAccountPrefix) === 0) { if (str_starts_with($key, $sessionAccountPrefix)) {
unset($_SESSION[$key]); unset($_SESSION[$key]);
logNewMessage(LOG_NOTICE, "del " . $key); logNewMessage(LOG_NOTICE, "del " . $key);
} }
@ -101,7 +101,7 @@ if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
die(); die();
} }
// Create account list // Create account list
$users = array(); $users = [];
foreach ($_SESSION['delete_dn'] as $dn) { foreach ($_SESSION['delete_dn'] as $dn) {
$start = strpos ($dn, "=")+1; $start = strpos ($dn, "=")+1;
$end = strpos ($dn, ","); $end = strpos ($dn, ",");
@ -137,26 +137,26 @@ if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
$container->add(new htmlHiddenInput('type', $type->getId()), 12); $container->add(new htmlHiddenInput('type', $type->getId()), 12);
$container->addVerticalSpacer('1rem'); $container->addVerticalSpacer('1rem');
parseHtml(null, $container, array(), false, $type->getScope()); parseHtml(null, $container, [], false, $type->getScope());
// Print delete rows from modules // Print delete rows from modules
$modules = $_SESSION['config']->get_AccountModules($type->getId()); $modules = $_SESSION['config']->get_AccountModules($type->getId());
$values = array(); $values = [];
foreach ($modules as $module) { foreach ($modules as $module) {
$module = \moduleCache::getModule($module, $type->getScope()); $module = \moduleCache::getModule($module, $type->getScope());
parseHtml(get_class($module), $module->display_html_delete(), $values, true, $type->getScope()); parseHtml($module::class, $module->display_html_delete(), $values, true, $type->getScope());
} }
$buttonContainer = new htmlResponsiveRow(); $buttonContainer = new htmlResponsiveRow();
$buttonContainer->addVerticalSpacer('1rem'); $buttonContainer->addVerticalSpacer('1rem');
$buttonGroup = new htmlGroup(); $buttonGroup = new htmlGroup();
$delButton = new htmlButton('delete', _('Delete')); $delButton = new htmlButton('delete', _('Delete'));
$delButton->setCSSClasses(array('lam-danger')); $delButton->setCSSClasses(['lam-danger']);
$buttonGroup->addElement($delButton); $buttonGroup->addElement($delButton);
$buttonGroup->addElement(new htmlSpacer('0.5rem', null)); $buttonGroup->addElement(new htmlSpacer('0.5rem', null));
$cancelButton = new htmlButton('cancel', _('Cancel')); $cancelButton = new htmlButton('cancel', _('Cancel'));
$buttonGroup->addElement($cancelButton); $buttonGroup->addElement($cancelButton);
$buttonContainer->add($buttonGroup, 12); $buttonContainer->add($buttonGroup, 12);
$buttonContainer->addVerticalSpacer('1rem'); $buttonContainer->addVerticalSpacer('1rem');
parseHtml(null, $buttonContainer, array(), false, $type->getScope()); parseHtml(null, $buttonContainer, [], false, $type->getScope());
echo "</form>\n"; echo "</form>\n";
echo "</div>\n"; echo "</div>\n";
include '../lib/adminFooter.inc'; include '../lib/adminFooter.inc';
@ -194,7 +194,7 @@ if (isset($_POST['delete'])) {
$_SESSION[$sessionKey] = new \accountContainer($type, $sessionKey); $_SESSION[$sessionKey] = new \accountContainer($type, $sessionKey);
// Delete dns // Delete dns
$allOk = true; $allOk = true;
$allErrors = array(); $allErrors = [];
foreach ($_SESSION['delete_dn'] as $deleteDN) { foreach ($_SESSION['delete_dn'] as $deleteDN) {
// Set to true if an real error has happened // Set to true if an real error has happened
$stopProcessing = false; $stopProcessing = false;
@ -203,8 +203,8 @@ if (isset($_POST['delete'])) {
// get commands and changes of each attribute // get commands and changes of each attribute
$moduleNames = array_keys($_SESSION[$sessionKey]->getAccountModules()); $moduleNames = array_keys($_SESSION[$sessionKey]->getAccountModules());
$modules = $_SESSION[$sessionKey]->getAccountModules(); $modules = $_SESSION[$sessionKey]->getAccountModules();
$attributes = array(); $attributes = [];
$errors = array(); $errors = [];
// predelete actions // predelete actions
foreach ($moduleNames as $singlemodule) { foreach ($moduleNames as $singlemodule) {
$success = true; $success = true;
@ -258,7 +258,7 @@ if (isset($_POST['delete'])) {
if (isset($attributes[$dn]['modify'])) { if (isset($attributes[$dn]['modify'])) {
$success = ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes[$dn]['modify']); $success = ldap_mod_replace($_SESSION['ldap']->server(), $dn, $attributes[$dn]['modify']);
if (!$success) { if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to modify attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server())); $errors[] = ['ERROR', sprintf(_('Was unable to modify attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server())];
$stopProcessing = true; $stopProcessing = true;
$allOk = false; $allOk = false;
} }
@ -267,7 +267,7 @@ if (isset($_POST['delete'])) {
if (isset($attributes[$dn]['add']) && !$stopProcessing) { if (isset($attributes[$dn]['add']) && !$stopProcessing) {
$success = ldap_mod_add($_SESSION['ldap']->server(), $dn, $attributes[$dn]['add']); $success = ldap_mod_add($_SESSION['ldap']->server(), $dn, $attributes[$dn]['add']);
if (!$success) { if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server())); $errors[] = ['ERROR', sprintf(_('Was unable to add attributes to DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server())];
$stopProcessing = true; $stopProcessing = true;
$allOk = false; $allOk = false;
} }
@ -276,7 +276,7 @@ if (isset($_POST['delete'])) {
if (isset($attributes[$dn]['remove']) && !$stopProcessing) { if (isset($attributes[$dn]['remove']) && !$stopProcessing) {
$success = ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes[$dn]['remove']); $success = ldap_mod_del($_SESSION['ldap']->server(), $dn, $attributes[$dn]['remove']);
if (!$success) { if (!$success) {
$errors[] = array ('ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server())); $errors[] = ['ERROR', sprintf(_('Was unable to remove attributes from DN: %s.'), $dn), getDefaultLDAPErrorString($_SESSION['ldap']->server())];
$stopProcessing = true; $stopProcessing = true;
$allOk = false; $allOk = false;
} }
@ -322,13 +322,13 @@ if (isset($_POST['delete'])) {
$container->add(htmlStatusMessage::fromParamArray($error), 12); $container->add(htmlStatusMessage::fromParamArray($error), 12);
} }
} }
$allErrors = array_merge($allErrors, $errors); $allErrors = [...$allErrors, ...$errors];
} }
$container->addVerticalSpacer('2rem'); $container->addVerticalSpacer('2rem');
$buttonName = $allOk ? 'cancelAllOk' : 'cancel'; $buttonName = $allOk ? 'cancelAllOk' : 'cancel';
$container->add(new htmlButton($buttonName, _('Back to list')), 12); $container->add(new htmlButton($buttonName, _('Back to list')), 12);
$container->addVerticalSpacer('1rem'); $container->addVerticalSpacer('1rem');
parseHtml(null, $container, array(), false, $type->getScope()); parseHtml(null, $container, [], false, $type->getScope());
echo "</div>\n"; echo "</div>\n";
echo "</form>\n"; echo "</form>\n";
?> ?>
@ -354,6 +354,6 @@ if (isset($_POST['delete'])) {
* @return integer number of children * @return integer number of children
*/ */
function getChildCount($dn) { function getChildCount($dn) {
$entries = searchLDAP($dn, 'objectClass=*', array('dn')); $entries = searchLDAP($dn, 'objectClass=*', ['dn']);
return (sizeof($entries) - 1); return (sizeof($entries) - 1);
} }

View file

@ -4,7 +4,7 @@ namespace LAM\HELP;
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner Copyright (C) 2003 - 2006 Michael Duergner
2008 - 2022 Roland Gruber 2008 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -113,7 +113,7 @@ if (!isset($_GET['HelpNumber'])) {
exit; exit;
} }
$helpEntry = array(); $helpEntry = [];
// module help // module help
if (isset($_GET['module']) && !($_GET['module'] == 'main') && !($_GET['module'] == '')) { if (isset($_GET['module']) && !($_GET['module'] == 'main') && !($_GET['module'] == '')) {
@ -132,7 +132,7 @@ if (isset($_GET['module']) && !($_GET['module'] == 'main') && !($_GET['module']
$helpEntry = getHelp($moduleName, $_GET['HelpNumber'], $scope); $helpEntry = getHelp($moduleName, $_GET['HelpNumber'], $scope);
} }
if (!$helpEntry) { if (!$helpEntry) {
$variables = array(htmlspecialchars($_GET['HelpNumber']), htmlspecialchars($moduleName)); $variables = [htmlspecialchars($_GET['HelpNumber']), htmlspecialchars($moduleName)];
$errorMessage = _("Sorry the help id '%s' is not available for the module '%s'."); $errorMessage = _("Sorry the help id '%s' is not available for the module '%s'.");
echoHTMLHead(); echoHTMLHead();
statusMessage("ERROR", "", $errorMessage, $variables); statusMessage("ERROR", "", $errorMessage, $variables);
@ -144,7 +144,7 @@ if (isset($_GET['module']) && !($_GET['module'] == 'main') && !($_GET['module']
else { else {
/* If submitted help number is not in help/help.inc print error message */ /* If submitted help number is not in help/help.inc print error message */
if (!array_key_exists($_GET['HelpNumber'], $helpArray)) { if (!array_key_exists($_GET['HelpNumber'], $helpArray)) {
$variables = array(htmlspecialchars($_GET['HelpNumber'])); $variables = [htmlspecialchars($_GET['HelpNumber'])];
$errorMessage = _("Sorry this help number ({bold}%s{endbold}) is not available."); $errorMessage = _("Sorry this help number ({bold}%s{endbold}) is not available.");
echoHTMLHead(); echoHTMLHead();
statusMessage("ERROR", "", $errorMessage, $variables); statusMessage("ERROR", "", $errorMessage, $variables);

View file

@ -2,7 +2,7 @@
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) 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 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 it under the terms of the GNU General Public License as published by
@ -51,7 +51,7 @@ if (!empty($_POST)) {
} }
// check if user already pressed button // check if user already pressed button
$failedDNs = array(); $failedDNs = [];
if (isset($_POST['add_suff']) || isset($_POST['cancel'])) { if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
if (isset($_POST['add_suff'])) { if (isset($_POST['add_suff'])) {
$newSuffixes = $_POST['new_suff']; $newSuffixes = $_POST['new_suff'];
@ -61,7 +61,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
// add entries // add entries
foreach ($newSuffixes as $newSuffix) { foreach ($newSuffixes as $newSuffix) {
// check if entry is already present // check if entry is already present
$info = @ldap_read($_SESSION['ldap']->server(), $newSuffix, "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER); $info = @ldap_read($_SESSION['ldap']->server(), $newSuffix, "objectclass=*", ['dn'], 0, 0, 0, LDAP_DEREF_NEVER);
$res = false; $res = false;
if ($info !== false) { if ($info !== false) {
$res = ldap_get_entries($_SESSION['ldap']->server(), $info); $res = ldap_get_entries($_SESSION['ldap']->server(), $info);
@ -76,7 +76,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
array_shift($tmp); array_shift($tmp);
$end = implode(",", $tmp); $end = implode(",", $tmp);
if ($name[0] != "ou") { // add root entry if ($name[0] != "ou") { // add root entry
$attr = array(); $attr = [];
$attr[$name[0]] = $name[1]; $attr[$name[0]] = $name[1];
$attr['objectClass'] = 'organization'; $attr['objectClass'] = 'organization';
$dn = $suff; $dn = $suff;
@ -87,7 +87,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
} }
else { // add organizational unit else { // add organizational unit
$name = $name[1]; $name = $name[1];
$attr = array(); $attr = [];
$attr['objectClass'] = "organizationalunit"; $attr['objectClass'] = "organizationalunit";
$attr['ou'] = $name; $attr['ou'] = $name;
$dn = $suff; $dn = $suff;
@ -95,7 +95,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
// check if we have to add parent entries // check if we have to add parent entries
if (ldap_errno($_SESSION['ldap']->server()) == 32) { if (ldap_errno($_SESSION['ldap']->server()) == 32) {
$dnParts = explode(",", $suff); $dnParts = explode(",", $suff);
$subsuffs = array(); $subsuffs = [];
// make list of subsuffixes // make list of subsuffixes
$dnPartsCount = sizeof($dnParts); $dnPartsCount = sizeof($dnParts);
for ($k = 0; $k < $dnPartsCount; $k++) { for ($k = 0; $k < $dnPartsCount; $k++) {
@ -112,7 +112,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
$subsuffCount = sizeof($subsuffs); $subsuffCount = sizeof($subsuffs);
for ($k = $subsuffCount - 1; $k >= 0; $k--) { for ($k = $subsuffCount - 1; $k >= 0; $k--) {
// check if subsuffix is present // check if subsuffix is present
$info = @ldap_read($_SESSION['ldap']->server(), $subsuffs[$k], "objectclass=*", array('dn'), 0, 0, 0, LDAP_DEREF_NEVER); $info = @ldap_read($_SESSION['ldap']->server(), $subsuffs[$k], "objectclass=*", ['dn'], 0, 0, 0, LDAP_DEREF_NEVER);
$res = false; $res = false;
if ($info !== false) { if ($info !== false) {
$res = ldap_get_entries($_SESSION['ldap']->server(), $info); $res = ldap_get_entries($_SESSION['ldap']->server(), $info);
@ -121,7 +121,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
$suffarray = explode(",", $subsuffs[$k]); $suffarray = explode(",", $subsuffs[$k]);
$headarray = explode("=", $suffarray[0]); $headarray = explode("=", $suffarray[0]);
if ($headarray[0] == "ou") { // add ou entry if ($headarray[0] == "ou") { // add ou entry
$attr = array(); $attr = [];
$attr['objectClass'] = 'organizationalunit'; $attr['objectClass'] = 'organizationalunit';
$attr['ou'] = $headarray[1]; $attr['ou'] = $headarray[1];
$dn = $subsuffs[$k]; $dn = $subsuffs[$k];
@ -131,7 +131,7 @@ if (isset($_POST['add_suff']) || isset($_POST['cancel'])) {
} }
} }
else { // add root entry else { // add root entry
$attr = array(); $attr = [];
$attr['objectClass'][] = 'organization'; $attr['objectClass'][] = 'organization';
$attr[$headarray[0]] = $headarray[1]; $attr[$headarray[0]] = $headarray[1];
if ($headarray[0] == "dc") { if ($headarray[0] == "dc") {
@ -204,7 +204,7 @@ include __DIR__ . '/../lib/adminHeader.inc';
$container->add($buttonContainer, 12); $container->add($buttonContainer, 12);
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, 'user'); parseHtml(null, $container, [], false, 'user');
echo "</form><br>\n"; echo "</form><br>\n";
echo "</div>\n"; echo "</div>\n";

View file

@ -81,7 +81,7 @@ lam_start_session();
session_regenerate_id(true); session_regenerate_id(true);
$serverProfilePersistenceManager = new ServerProfilePersistenceManager(); $serverProfilePersistenceManager = new ServerProfilePersistenceManager();
$profiles = array(); $profiles = [];
try { try {
$profiles = $serverProfilePersistenceManager->getProfiles(); $profiles = $serverProfilePersistenceManager->getProfiles();
} catch (LAMException $e) { } catch (LAMException $e) {
@ -146,7 +146,7 @@ $possibleLanguages = getLanguages();
$encoding = 'UTF-8'; $encoding = 'UTF-8';
if (isset($_COOKIE['lam_last_language'])) { if (isset($_COOKIE['lam_last_language'])) {
foreach ($possibleLanguages as $lang) { foreach ($possibleLanguages as $lang) {
if (strpos($_COOKIE['lam_last_language'], $lang->code) === 0) { if (str_starts_with($_COOKIE['lam_last_language'], $lang->code)) {
$_SESSION['language'] = $lang->code; $_SESSION['language'] = $lang->code;
$encoding = $lang->encoding; $encoding = $lang->encoding;
break; break;
@ -156,7 +156,7 @@ if (isset($_COOKIE['lam_last_language'])) {
elseif (!empty($_SESSION["config"])) { elseif (!empty($_SESSION["config"])) {
$defaultLang = $_SESSION["config"]->get_defaultLanguage(); $defaultLang = $_SESSION["config"]->get_defaultLanguage();
foreach ($possibleLanguages as $lang) { foreach ($possibleLanguages as $lang) {
if (strpos($defaultLang, $lang->code) === 0) { if (str_starts_with($defaultLang, $lang->code)) {
$_SESSION['language'] = $lang->code; $_SESSION['language'] = $lang->code;
$encoding = $lang->encoding; $encoding = $lang->encoding;
break; break;
@ -168,7 +168,7 @@ else {
} }
if (isset($_POST['language'])) { if (isset($_POST['language'])) {
foreach ($possibleLanguages as $lang) { foreach ($possibleLanguages as $lang) {
if (strpos($_POST['language'], $lang->code) === 0) { if (str_starts_with($_POST['language'], $lang->code)) {
$_SESSION['language'] = $lang->code; $_SESSION['language'] = $lang->code;
$encoding = $lang->encoding; $encoding = $lang->encoding;
break; break;
@ -182,9 +182,9 @@ $_SESSION['header'] .= "<meta name=\"robots\" content=\"noindex, nofollow\">\n";
$_SESSION['header'] .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . $encoding . "\">\n"; $_SESSION['header'] .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . $encoding . "\">\n";
$_SESSION['header'] .= "<meta http-equiv=\"pragma\" content=\"no-cache\">\n <meta http-equiv=\"cache-control\" content=\"no-cache\">"; $_SESSION['header'] .= "<meta http-equiv=\"pragma\" content=\"no-cache\">\n <meta http-equiv=\"cache-control\" content=\"no-cache\">";
$manifestBaseUrl = getCallingURL(); $manifestBaseUrl = getCallingURL();
if (strpos($manifestBaseUrl, '/templates/login.php') !== false) { if (str_contains($manifestBaseUrl, '/templates/login.php')) {
$manifestBaseUrl = substr($manifestBaseUrl, 0, strpos($manifestBaseUrl, '/templates/login.php')); $manifestBaseUrl = substr($manifestBaseUrl, 0, strpos($manifestBaseUrl, '/templates/login.php'));
$urlMatches = array(); $urlMatches = [];
if (preg_match('/^http(s)?:\\/\\/[^\\/]+(\\/.*)$/m', $manifestBaseUrl, $urlMatches)) { if (preg_match('/^http(s)?:\\/\\/[^\\/]+(\\/.*)$/m', $manifestBaseUrl, $urlMatches)) {
$manifestBaseUrl = htmlspecialchars($urlMatches[2]); $manifestBaseUrl = htmlspecialchars($urlMatches[2]);
$_SESSION['header'] .= '<link rel="manifest" href="' . $manifestBaseUrl . '/templates/manifest.php" crossorigin="use-credentials">'; $_SESSION['header'] .= '<link rel="manifest" href="' . $manifestBaseUrl . '/templates/manifest.php" crossorigin="use-credentials">';
@ -273,7 +273,7 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
$row->addLabel(new htmlLabel('username', _("User name"))); $row->addLabel(new htmlLabel('username', _("User name")));
if ($config_object->getLoginMethod() == LAMConfig::LOGIN_LIST) { if ($config_object->getLoginMethod() == LAMConfig::LOGIN_LIST) {
$admins = $config_object->get_Admins(); $admins = $config_object->get_Admins();
$adminList = array(); $adminList = [];
foreach ($admins as $admin) { foreach ($admins as $admin) {
$text = explode(",", $admin); $text = explode(",", $admin);
$text = explode("=", $text[0]); $text = explode("=", $text[0]);
@ -284,22 +284,22 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
$adminList[$text[0]] = $admin; $adminList[$text[0]] = $admin;
} }
} }
$selectedAdmin = array(); $selectedAdmin = [];
if (isset($_POST['username']) && in_array($_POST['username'], $adminList)) { if (isset($_POST['username']) && in_array($_POST['username'], $adminList)) {
$selectedAdmin = array($_POST['username']); $selectedAdmin = [$_POST['username']];
} }
$userSelect = new htmlSelect('username', $adminList, $selectedAdmin); $userSelect = new htmlSelect('username', $adminList, $selectedAdmin);
$userSelect->setHasDescriptiveElements(true); $userSelect->setHasDescriptiveElements(true);
$userSelect->setTransformSingleSelect(false); $userSelect->setTransformSingleSelect(false);
if (empty($_COOKIE['lam_login_name'])) { if (empty($_COOKIE['lam_login_name'])) {
$userSelect->setCSSClasses(array('lam-initial-focus')); $userSelect->setCSSClasses(['lam-initial-focus']);
} }
$row->addField(new htmlDiv(null, $userSelect)); $row->addField(new htmlDiv(null, $userSelect));
} }
else { else {
if ($config_object->getHttpAuthentication() == 'true') { if ($config_object->getHttpAuthentication() == 'true') {
$httpAuth = new htmlDiv(null, new htmlOutputText($_SERVER['PHP_AUTH_USER'] . '&nbsp;', false)); $httpAuth = new htmlDiv(null, new htmlOutputText($_SERVER['PHP_AUTH_USER'] . '&nbsp;', false));
$httpAuth->setCSSClasses(array('text-left', 'margin3')); $httpAuth->setCSSClasses(['text-left', 'margin3']);
$row->addField($httpAuth); $row->addField($httpAuth);
} }
else { else {
@ -309,7 +309,7 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
} }
$userNameInput = new htmlInputField('username', $user); $userNameInput = new htmlInputField('username', $user);
if (empty($_COOKIE['lam_login_name'])) { if (empty($_COOKIE['lam_login_name'])) {
$userNameInput->setCSSClasses(array('lam-initial-focus')); $userNameInput->setCSSClasses(['lam-initial-focus']);
} }
$userInput = new htmlDiv(null, $userNameInput); $userInput = new htmlDiv(null, $userNameInput);
$row->addField($userInput); $row->addField($userInput);
@ -319,25 +319,25 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
$row->addLabel(new htmlLabel('passwd', _("Password"))); $row->addLabel(new htmlLabel('passwd', _("Password")));
if (($config_object->getLoginMethod() == LAMConfig::LOGIN_SEARCH) && ($config_object->getHttpAuthentication() == 'true')) { if (($config_object->getLoginMethod() == LAMConfig::LOGIN_SEARCH) && ($config_object->getHttpAuthentication() == 'true')) {
$passwordInputFake = new htmlDiv(null, new htmlOutputText('**********')); $passwordInputFake = new htmlDiv(null, new htmlOutputText('**********'));
$passwordInputFake->setCSSClasses(array('text-left', 'margin3')); $passwordInputFake->setCSSClasses(['text-left', 'margin3']);
$row->addField($passwordInputFake); $row->addField($passwordInputFake);
} }
else { else {
$passwordInput = new htmlInputField('passwd'); $passwordInput = new htmlInputField('passwd');
$passwordInput->setIsPassword(true); $passwordInput->setIsPassword(true);
if (($config_object->getLoginMethod() == LAMConfig::LOGIN_SEARCH) && !empty($_COOKIE['lam_login_name'])) { if (($config_object->getLoginMethod() == LAMConfig::LOGIN_SEARCH) && !empty($_COOKIE['lam_login_name'])) {
$passwordInput->setCSSClasses(array('lam-initial-focus')); $passwordInput->setCSSClasses(['lam-initial-focus']);
} }
$row->addField($passwordInput); $row->addField($passwordInput);
} }
// language // language
$row->addLabel(new htmlLabel('language', _("Language"))); $row->addLabel(new htmlLabel('language', _("Language")));
$possibleLanguages = getLanguages(); $possibleLanguages = getLanguages();
$languageList = array(); $languageList = [];
$defaultLanguage = array(); $defaultLanguage = [];
foreach ($possibleLanguages as $lang) { foreach ($possibleLanguages as $lang) {
$languageList[$lang->description] = $lang->code; $languageList[$lang->description] = $lang->code;
if (strpos(trim($_SESSION["language"]), $lang->code) === 0) { if (str_starts_with(trim($_SESSION["language"]), $lang->code)) {
$defaultLanguage[] = $lang->code; $defaultLanguage[] = $lang->code;
} }
} }
@ -356,16 +356,16 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
$rememberGroup->addElement(new htmlSpacer('1px', null)); $rememberGroup->addElement(new htmlSpacer('1px', null));
$rememberGroup->addElement(new htmlOutputText(_('Remember user name'))); $rememberGroup->addElement(new htmlOutputText(_('Remember user name')));
$rememberDiv = new htmlDiv(null, $rememberGroup); $rememberDiv = new htmlDiv(null, $rememberGroup);
$rememberDiv->setCSSClasses(array('text-left', 'margin3')); $rememberDiv->setCSSClasses(['text-left', 'margin3']);
$row->add($rememberDiv, 12, 6, 6); $row->add($rememberDiv, 12, 6, 6);
} }
// login button // login button
$row->add(new htmlSpacer(null, '20px'), 12); $row->add(new htmlSpacer(null, '20px'), 12);
$loginButton = new htmlButton('checklogin', _("Login")); $loginButton = new htmlButton('checklogin', _("Login"));
$loginButton->setCSSClasses(array('lam-primary')); $loginButton->setCSSClasses(['lam-primary']);
$row->add($loginButton); $row->add($loginButton);
parseHtml(null, $row, array(), false, 'user'); parseHtml(null, $row, [], false, 'user');
?> ?>
</form> </form>
</td> </td>
@ -386,7 +386,7 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
$extraMessage = new htmlStatusMessage('INFO', $extraMessage); $extraMessage = new htmlStatusMessage('INFO', $extraMessage);
$row->add($extraMessage, 12); $row->add($extraMessage, 12);
} }
parseHtml(null, $row, array(), false, 'user'); parseHtml(null, $row, [], false, 'user');
?> ?>
<hr class="margin20"> <hr class="margin20">
</td> </td>
@ -399,13 +399,13 @@ function display_LoginPage(?LAMLicenseValidator $licenseValidator, ?string $erro
$row->addLabel(new htmlOutputText(_("LDAP server"))); $row->addLabel(new htmlOutputText(_("LDAP server")));
$serverUrl = new htmlOutputText($config_object->getServerDisplayNameGUI()); $serverUrl = new htmlOutputText($config_object->getServerDisplayNameGUI());
$serverUrlDiv = new htmlDiv(null, $serverUrl); $serverUrlDiv = new htmlDiv(null, $serverUrl);
$serverUrlDiv->setCSSClasses(array('text-left', 'margin3')); $serverUrlDiv->setCSSClasses(['text-left', 'margin3']);
$row->addField($serverUrlDiv); $row->addField($serverUrlDiv);
$profileSelect = new htmlResponsiveSelect('profile', $profiles, array($_SESSION['config']->getName()), _("Server profile")); $profileSelect = new htmlResponsiveSelect('profile', $profiles, [$_SESSION['config']->getName()], _("Server profile"));
$profileSelect->setOnchangeEvent('loginProfileChanged(this)'); $profileSelect->setOnchangeEvent('loginProfileChanged(this)');
$row->add($profileSelect); $row->add($profileSelect);
parseHtml(null, $row, array(), true, 'user'); parseHtml(null, $row, [], true, 'user');
?> ?>
</form> </form>
</td> </td>
@ -476,7 +476,7 @@ function displayLoginHeader() : void {
<span class="padding0"><?php echo _("LAM configuration") ?></span> <span class="padding0"><?php echo _("LAM configuration") ?></span>
</a> </a>
<?php <?php
if (is_dir(dirname(__FILE__) . '/../docs/manual')) { if (is_dir(__DIR__ . '/../docs/manual')) {
?> ?>
<a class="lam-menu-entry" target="_blank" href="../docs/manual/index.html"> <a class="lam-menu-entry" target="_blank" href="../docs/manual/index.html">
<span class="padding0"><?php echo _("Help") ?></span> <span class="padding0"><?php echo _("Help") ?></span>
@ -541,7 +541,7 @@ if (isset($_POST['checklogin'])) {
$searchLDAP = new Ldap($_SESSION['config']); $searchLDAP = new Ldap($_SESSION['config']);
try { try {
$searchLDAP->connect($searchDN, $searchPassword, true); $searchLDAP->connect($searchDN, $searchPassword, true);
$searchResult = ldap_search($searchLDAP->server(), $_SESSION['config']->getLoginSearchSuffix(), $searchFilter, array('dn'), 0, 0, 0, LDAP_DEREF_NEVER); $searchResult = ldap_search($searchLDAP->server(), $_SESSION['config']->getLoginSearchSuffix(), $searchFilter, ['dn'], 0, 0, 0, LDAP_DEREF_NEVER);
if ($searchResult) { if ($searchResult) {
$searchInfo = ldap_get_entries($searchLDAP->server(), $searchResult); $searchInfo = ldap_get_entries($searchLDAP->server(), $searchResult);
if ($searchInfo !== false) { if ($searchInfo !== false) {

View file

@ -69,7 +69,7 @@ catch (Exception $e) {
logNewMessage(LOG_ERR, 'Unable to get 2-factor serials for ' . $user . ' ' . $e->getMessage()); logNewMessage(LOG_ERR, 'Unable to get 2-factor serials for ' . $user . ' ' . $e->getMessage());
printHeader(); printHeader();
$scriptTag = new htmlJavaScript('window.lam.dialog.showErrorMessageAndRedirect("' . _("Unable to start 2-factor authentication.") . '", "", "' . _('Ok') . '", "login.php")'); $scriptTag = new htmlJavaScript('window.lam.dialog.showErrorMessageAndRedirect("' . _("Unable to start 2-factor authentication.") . '", "", "' . _('Ok') . '", "login.php")');
parseHtml(null, $scriptTag, array(), false, null); parseHtml(null, $scriptTag, [], false, null);
printFooter(); printFooter();
die(); die();
} }
@ -95,7 +95,7 @@ if (empty($serials) && $config->getTwoFactorAuthenticationOptional()) {
if (empty($serials)) { if (empty($serials)) {
printHeader(); printHeader();
$scriptTag = new htmlJavaScript('window.lam.dialog.showErrorMessageAndRedirect("' . _("Unable to start 2-factor authentication because no tokens were found.") . '", "", "' . _('Ok') . '", "login.php")'); $scriptTag = new htmlJavaScript('window.lam.dialog.showErrorMessageAndRedirect("' . _("Unable to start 2-factor authentication because no tokens were found.") . '", "", "' . _('Ok') . '", "login.php")');
parseHtml(null, $scriptTag, array(), false, null); parseHtml(null, $scriptTag, [], false, null);
printFooter(); printFooter();
die(); die();
} }
@ -104,8 +104,8 @@ if (isset($_POST['submit']) || isset($_POST['sig_response']) // WebAuthn
|| (isset($_GET['state']) && isset($_GET['code'])) // Okta || (isset($_GET['state']) && isset($_GET['code'])) // Okta
|| (isset($_GET['state']) && isset($_GET['duo_code'])) // Duo || (isset($_GET['state']) && isset($_GET['duo_code'])) // Duo
|| (isset($_GET['session_state']) && isset($_GET['redirect_uri']))) { // OpenID || (isset($_GET['session_state']) && isset($_GET['redirect_uri']))) { // OpenID
$twoFactorInput = isset($_POST['2factor']) ? $_POST['2factor'] : null; $twoFactorInput = $_POST['2factor'] ?? null;
$serial = isset($_POST['serial']) ? $_POST['serial'] : null; $serial = $_POST['serial'] ?? null;
if (!$provider->hasCustomInputForm() && (empty($twoFactorInput) || !in_array($serial, $serials))) { if (!$provider->hasCustomInputForm() && (empty($twoFactorInput) || !in_array($serial, $serials))) {
$errorMessage = sprintf(_('Please enter "%s".'), $twoFactorLabel); $errorMessage = sprintf(_('Please enter "%s".'), $twoFactorLabel);
header("HTTP/1.1 403 Forbidden"); header("HTTP/1.1 403 Forbidden");
@ -216,23 +216,23 @@ echo $config->getTwoFactorAuthenticationCaption();
$row->add(new htmlSpacer('1em', '1em')); $row->add(new htmlSpacer('1em', '1em'));
if ($provider->supportsToRememberDevice()) { if ($provider->supportsToRememberDevice()) {
$remember = new htmlResponsiveInputCheckbox('rememberDevice', false, _('Remember device'), '560'); $remember = new htmlResponsiveInputCheckbox('rememberDevice', false, _('Remember device'), '560');
$remember->setCSSClasses(array('lam-save-selection')); $remember->setCSSClasses(['lam-save-selection']);
$row->add($remember); $row->add($remember);
$row->add(new htmlSpacer('0.5em', '0.5em')); $row->add(new htmlSpacer('0.5em', '0.5em'));
} }
if ($provider->isShowSubmitButton()) { if ($provider->isShowSubmitButton()) {
$submit = new htmlButton('submit', _("Submit")); $submit = new htmlButton('submit', _("Submit"));
$submit->setCSSClasses(array('fullwidth')); $submit->setCSSClasses(['fullwidth']);
$row->add($submit, 12, 12, 12, 'fullwidth'); $row->add($submit, 12, 12, 12, 'fullwidth');
$row->add(new htmlSpacer('0.5em', '0.5em')); $row->add(new htmlSpacer('0.5em', '0.5em'));
} }
$logout = new htmlButton('logout', _("Cancel")); $logout = new htmlButton('logout', _("Cancel"));
$logout->setCSSClasses(array('fullwidth')); $logout->setCSSClasses(['fullwidth']);
$row->add($logout); $row->add($logout);
$group->addElement($row); $group->addElement($row);
addSecurityTokenToMetaHTML($group); addSecurityTokenToMetaHTML($group);
parseHtml(null, $group, array(), false, 'user'); parseHtml(null, $group, [], false, 'user');
?> ?>
</div> </div>

View file

@ -9,7 +9,7 @@ use LAMException;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) 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 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 it under the terms of the GNU General Public License as published by
@ -59,7 +59,7 @@ $conf = $_SESSION['config'];
// check if user password is not expired // check if user password is not expired
if (!$conf->isHidePasswordPromptForExpiredPasswords()) { if (!$conf->isHidePasswordPromptForExpiredPasswords()) {
$userDn = $_SESSION['ldap']->getUserName(); $userDn = $_SESSION['ldap']->getUserName();
$userData = ldapGetDN($userDn, array('*', '+', 'pwdReset', 'passwordExpirationTime')); $userData = ldapGetDN($userDn, ['*', '+', 'pwdReset', 'passwordExpirationTime']);
$ldapErrorCode = ldap_errno($_SESSION['ldap']->server()); $ldapErrorCode = ldap_errno($_SESSION['ldap']->server());
logNewMessage(LOG_DEBUG, 'Expired password check: Reading ' . $userDn . ' with return code ' . $ldapErrorCode . ' and data: ' . print_r($userData, true)); logNewMessage(LOG_DEBUG, 'Expired password check: Reading ' . $userDn . ' with return code ' . $ldapErrorCode . ' and data: ' . print_r($userData, true));
if (($ldapErrorCode != 32) && ($ldapErrorCode != 34)) { if (($ldapErrorCode != 32) && ($ldapErrorCode != 34)) {
@ -73,12 +73,12 @@ if (!$conf->isHidePasswordPromptForExpiredPasswords()) {
} }
// check if all suffixes in conf-file exist // check if all suffixes in conf-file exist
$new_suffs = array(); $new_suffs = [];
// get list of active types // get list of active types
$typeManager = new TypeManager(); $typeManager = new TypeManager();
$types = $typeManager->getConfiguredTypes(); $types = $typeManager->getConfiguredTypes();
foreach ($types as $type) { foreach ($types as $type) {
$info = @ldap_read($_SESSION['ldap']->server(), $type->getSuffix(), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER); $info = @ldap_read($_SESSION['ldap']->server(), $type->getSuffix(), "(objectClass=*)", ['objectClass'], 0, 0, 0, LDAP_DEREF_NEVER);
if (($info === false) && !in_array($type->getSuffix(), $new_suffs)) { if (($info === false) && !in_array($type->getSuffix(), $new_suffs)) {
$new_suffs[] = $type->getSuffix(); $new_suffs[] = $type->getSuffix();
continue; continue;

View file

@ -3,7 +3,7 @@ namespace LAM\PWA;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2019 - 2022 Roland Gruber Copyright (C) 2019 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -38,9 +38,9 @@ if (!headers_sent()) {
} }
$baseUrl = getCallingURL(); $baseUrl = getCallingURL();
if (strpos($baseUrl, '/templates/manifest.php') !== false) { if (str_contains($baseUrl, '/templates/manifest.php')) {
$baseUrl = substr($baseUrl, 0, strpos($baseUrl, '/templates/manifest.php')); $baseUrl = substr($baseUrl, 0, strpos($baseUrl, '/templates/manifest.php'));
$urlMatches = array(); $urlMatches = [];
if (preg_match('/http(s)?:\\/\\/[^\\/]+(\\/.*)$/m', $baseUrl, $urlMatches)) { if (preg_match('/http(s)?:\\/\\/[^\\/]+(\\/.*)$/m', $baseUrl, $urlMatches)) {
$baseUrl = htmlspecialchars($urlMatches[2]); $baseUrl = htmlspecialchars($urlMatches[2]);
} }