refactoring

This commit is contained in:
Roland Gruber 2024-12-10 19:55:57 +01:00
parent 2325055f36
commit cfc8be9f7f
4 changed files with 82 additions and 137 deletions

View file

@ -126,7 +126,7 @@ class ObjectClass extends SchemaItem {
case '(':
break;
case 'NAME':
if ($strings[$i + 1] != "(") {
if ($strings[$i + 1] !== "(") {
do {
$i++;
if (($this->name === null) || (strlen($this->name) == 0)) {
@ -174,7 +174,7 @@ class ObjectClass extends SchemaItem {
$this->is_obsolete = TRUE;
break;
case 'SUP':
if ($strings[$i + 1] != "(") {
if ($strings[$i + 1] !== "(") {
$i++;
$this->sup_classes[] = preg_replace("/'/", "", $strings[$i]);
}
@ -182,7 +182,7 @@ class ObjectClass extends SchemaItem {
$i++;
do {
$i++;
if ($strings[$i] != "$") {
if ($strings[$i] !== "$") {
$this->sup_classes[] = preg_replace("/'/", "", $strings[$i]);
}
}
@ -205,14 +205,14 @@ class ObjectClass extends SchemaItem {
$this->must_attrs[] = $attr;
do {
$i++;
if ($strings[$i] != "$") {
if ($strings[$i] !== "$") {
$attr = new ObjectClassAttribute($strings[$i], $this->name);
$this->must_attrs[] = $attr;
}
}
while (!preg_match('/\)+\)?/', $strings[$i + 1]));
}
elseif ($strings[$i + 1] != "(") {
elseif ($strings[$i + 1] !== "(") {
$i++;
$attr = new ObjectClassAttribute($strings[$i], $this->name);
$this->must_attrs[] = $attr;
@ -221,7 +221,7 @@ class ObjectClass extends SchemaItem {
$i++;
do {
$i++;
if ($strings[$i] != "$") {
if ($strings[$i] !== "$") {
$attr = new ObjectClassAttribute($strings[$i], $this->name);
$this->must_attrs[] = $attr;
}
@ -237,14 +237,14 @@ class ObjectClass extends SchemaItem {
$this->may_attrs[] = $attr;
do {
$i++;
if ($strings[$i] != "$") {
if ($strings[$i] !== "$") {
$attr = new ObjectClassAttribute($strings[$i], $this->name);
$this->may_attrs[] = $attr;
}
}
while (!preg_match('/\)+\)?/', $strings[$i + 1]));
}
elseif ($strings[$i + 1] != "(") {
elseif ($strings[$i + 1] !== "(") {
$i++;
$attr = new ObjectClassAttribute($strings[$i], $this->name);
$this->may_attrs[] = $attr;
@ -253,7 +253,7 @@ class ObjectClass extends SchemaItem {
$i++;
do {
$i++;
if ($strings[$i] != "$") {
if ($strings[$i] !== "$") {
$attr = new ObjectClassAttribute($strings[$i], $this->name);
$this->may_attrs[] = $attr;
}
@ -594,7 +594,7 @@ class AttributeType extends SchemaItem {
case '(':
break;
case 'NAME':
if ($strings[$i + 1] != "(") {
if ($strings[$i + 1] !== "(") {
do {
$i++;
if (($this->name === null) || (strlen($this->name) == 0)) {
@ -621,7 +621,7 @@ class AttributeType extends SchemaItem {
}
while (!preg_match("/\'$/", $strings[$i]));
// add alias names for this attribute
while ($strings[++$i] != ")") {
while ($strings[++$i] !== ")") {
$alias = $strings[$i];
$alias = preg_replace("/^\'/", "", $alias);
$alias = preg_replace("/\'$/", "", $alias);
@ -633,7 +633,7 @@ class AttributeType extends SchemaItem {
do {
$i++;
if (strlen($this->description) == 0) {
$this->description = $this->description . $strings[$i];
$this->description .= $strings[$i];
}
else {
$this->description = $this->description . " " . $strings[$i];
@ -665,18 +665,13 @@ class AttributeType extends SchemaItem {
$this->syntax = $strings[$i];
$this->syntax_oid = preg_replace("/{\d+}$/", "", $this->syntax);
// does this SYNTAX string specify a max length (ie, 1.2.3.4{16})
if (preg_match("/{(\d+)}$/", $this->syntax, $this->max_length)) {
$this->max_length = $this->max_length[1];
}
else {
$this->max_length = null;
}
if ($i < count($strings) - 1 && $strings[$i + 1] == "{") {
$this->max_length = preg_match("/{(\d+)}$/", $this->syntax, $this->max_length) ? $this->max_length[1] : null;
if ($i < count($strings) - 1 && $strings[$i + 1] === "{") {
do {
$i++;
$this->name .= " " . $strings[$i];
}
while ($strings[$i] != "}");
while ($strings[$i] !== "}");
}
break;
case 'SINGLE-VALUE':
@ -1022,7 +1017,7 @@ class Syntax extends SchemaItem {
do {
$i++;
if (strlen($this->description) == 0) {
$this->description = $this->description . $strings[$i];
$this->description .= $strings[$i];
}
else {
$this->description = $this->description . " " . $strings[$i];
@ -1078,7 +1073,7 @@ class MatchingRule extends SchemaItem {
case '(':
break;
case 'NAME':
if ($strings[$i + 1] != "(") {
if ($strings[$i + 1] !== "(") {
do {
$i++;
if (strlen($this->name) == 0) {
@ -1114,7 +1109,7 @@ class MatchingRule extends SchemaItem {
do {
$i++;
if (strlen($this->description) == 0) {
$this->description = $this->description . $strings[$i];
$this->description .= $strings[$i];
}
else {
$this->description = $this->description . " " . $strings[$i];
@ -1212,10 +1207,10 @@ class MatchingRuleUse extends SchemaItem {
case '(':
break;
case 'NAME':
if ($strings[$i + 1] != "(") {
if ($strings[$i + 1] !== "(") {
do {
$i++;
if (!isset($this->name) || strlen($this->name) == 0) {
if ($this->name === null || strlen($this->name) == 0) {
$this->name = $strings[$i];
}
else {
@ -1245,7 +1240,7 @@ class MatchingRuleUse extends SchemaItem {
$this->name = preg_replace("/\'$/", "", $this->name);
break;
case 'APPLIES':
if ($strings[$i + 1] != "(") {
if ($strings[$i + 1] !== "(") {
// has a single attribute name
$i++;
$this->used_by_attrs = [$strings[$i]];
@ -1254,7 +1249,7 @@ class MatchingRuleUse extends SchemaItem {
else {
// has multiple attribute names
$i++;
while ($strings[$i] != ")") {
while ($strings[$i] !== ")") {
$i++;
$new_attr = $strings[$i];
$new_attr = preg_replace("/^\'/", "", $new_attr);
@ -1430,19 +1425,13 @@ function _get_raw_schema($schema_to_fetch, $dn = '') {
LDAP_DEREF_ALWAYS);
// Were we not able to fetch the schema from the $schema_dn?
if ($schema_search !== false) {
$schema_entries = @ldap_get_entries($ds, $schema_search);
}
else {
$schema_entries = [];
}
$schema_entries = $schema_search !== false ? @ldap_get_entries($ds, $schema_search) : [];
if ($schema_search === false ||
0 == @ldap_count_entries($ds, $schema_search) ||
!isset($schema_entries[0][$schema_to_fetch])) {
if ($debug) {
echo "Did not find the schema with (objectClass=*). Attempting with (objetClass=subschema)\n";
}
// Try again with a different filter (some servers require (objectClass=subschema) like M-Vault)
$schema_search = @ldap_read($ds, $schema_dn, '(objectClass=subschema)',
[$schema_to_fetch], 0, 0, 0,
@ -1450,7 +1439,6 @@ function _get_raw_schema($schema_to_fetch, $dn = '') {
if ($schema_search !== false) {
$schema_entries = @ldap_get_entries($ds, $schema_search);
}
// Still didn't get it?
if ($schema_search === false ||
0 == @ldap_count_entries($ds, $schema_search) ||
@ -1462,18 +1450,14 @@ function _get_raw_schema($schema_to_fetch, $dn = '') {
unset($schema_dn);
$schema_search = null;
}
else {
if ($debug) {
elseif ($debug) {
echo "Found the schema at DN: $schema_dn (with objectClass=subschema).\n";
}
}
}
else {
if ($debug) {
elseif ($debug) {
echo "Found the schema at DN: $schema_dn (with objectClass=*).\n";
}
}
}
// Second chance: If the DN or Root DSE didn't give us the subschemaSubentry, ie $schema_search
// is still null, use some common subSchemaSubentry DNs as a work-around.
@ -1687,7 +1671,7 @@ function get_schema_objectclasses($dn = null, $use_cache = true): array {
function get_schema_objectclass($oclass_name, $dn = null, $use_cache = true) {
$oclass_name = strtolower($oclass_name);
$oclasses = get_schema_objectclasses($dn, $use_cache);
if (!$oclasses) {
if ($oclasses === []) {
return false;
}
return $oclasses[$oclass_name] ?? false;
@ -1817,7 +1801,7 @@ function add_aliases_to_attrs(&$attrs) {
// go back and add data from aliased attributeTypes
foreach ($attrs as $attr) {
$aliases = $attr->getAliases();
if (is_array($aliases) && count($aliases) > 0) {
if (is_array($aliases) && ($aliases !== [])) {
// foreach of the attribute's aliases, create a new entry in the attrs array
// with its name set to the alias name, and all other data copied
foreach ($aliases as $alias_attr_name) {
@ -2050,7 +2034,7 @@ function get_schema_syntaxes($dn = null, $use_cache = true) {
foreach ($raw_syntaxes as $syntax_string) {
$syntax = new Syntax($syntax_string);
$key = strtolower(trim($syntax->getOID()));
if (!$key) {
if ($key === '') {
continue;
}
$syntaxes[$key] = $syntax;
@ -2080,7 +2064,7 @@ function get_schema_syntaxes($dn = null, $use_cache = true) {
*/
function cached_schema_available($schema_type) {
// Check config to make sure session-based caching is enabled.
if (!SCHEMA_SESSION_CACHE_ENABLED) {
if (SCHEMA_SESSION_CACHE_ENABLED === 0) {
return false;
}
@ -2114,7 +2098,7 @@ function cached_schema_available($schema_type) {
*/
function get_cached_schema($schema_type) {
// Check config to make sure session-based caching is enabled.
if (!SCHEMA_SESSION_CACHE_ENABLED) {
if (SCHEMA_SESSION_CACHE_ENABLED === 0) {
return false;
}
@ -2146,7 +2130,7 @@ function get_cached_schema($schema_type) {
*/
function set_cached_schema($schema_type, $schema_items) {
// Check config to make sure session-based caching is enabled.
if (!SCHEMA_SESSION_CACHE_ENABLED) {
if (SCHEMA_SESSION_CACHE_ENABLED === 0) {
return false;
}
@ -2166,7 +2150,7 @@ function set_cached_schema($schema_type, $schema_items) {
* fetch it from the server.
*/
function set_schema_cache_unavailable() {
if (!SCHEMA_SESSION_CACHE_ENABLED) {
if (SCHEMA_SESSION_CACHE_ENABLED === 0) {
return false;
}
$_SESSION['schema']['unavailable'] = true;

View file

@ -28,11 +28,11 @@
*/
/** configuration options */
include_once('config.inc');
include_once(__DIR__ . '/config.inc');
/** ldap connection */
include_once('ldap.inc');
include_once(__DIR__ . '/ldap.inc');
/** common functions */
include_once('account.inc');
include_once(__DIR__ . '/account.inc');
// check client IP address
checkClientIP();
@ -167,7 +167,7 @@ function checkClientIP() {
}
$allowedHosts = explode(",", $allowedHosts);
$grantAccess = false;
for ($i = 0; $i < sizeof($allowedHosts); $i++) {
for ($i = 0; $i < count($allowedHosts); $i++) {
$host = $allowedHosts[$i];
$ipRegex = '/^[0-9a-z\\.:\\*]+$/i';
if (!preg_match($ipRegex, $host)) {
@ -222,7 +222,7 @@ function logoffAndBackToLoginPage(): void {
$page = 'selfServiceLogin.php';
$pageSuffix = '?expired=yes&scope=' . $scope . '&name=' . $name;
}
for ($i = 0; $i < sizeof($paths); $i++) {
for ($i = 0; $i < count($paths); $i++) {
if (file_exists($paths[$i] . $page)) {
$page = $paths[$i] . $page;
break;
@ -349,10 +349,7 @@ function checkIfPasswordChangeIsAllowed() {
if (!isset($_SESSION['config'])) {
return false;
}
if ($_SESSION['config']->getAccessLevel() >= LAMConfig::ACCESS_PASSWORD_CHANGE) {
return true;
}
return false;
return $_SESSION['config']->getAccessLevel() >= LAMConfig::ACCESS_PASSWORD_CHANGE;
}
/**
@ -432,7 +429,7 @@ function checkPasswordStrength($password, $userNames, $otherUserAttrs) {
if (preg_match("/[A-Z]/", $password[$i])) {
$upper++;
}
if (preg_match("/[0-9]/", $password[$i])) {
if (preg_match("/\\d/", $password[$i])) {
$numeric++;
}
if (preg_match("/[^a-z0-9]/i", $password[$i])) {
@ -561,7 +558,7 @@ function checkPwdWithExternalPasswordService($cfg, $password) {
curl_setopt($curl, CURLOPT_URL, $url);
$results = curl_exec($curl);
$code = curl_errno($curl);
if ($code) {
if ($code !== 0) {
logNewMessage(LOG_ERR, 'Error calling the external password service at ' . $url
. '. ' . curl_error($curl));
return true;

View file

@ -35,11 +35,11 @@ use function LAM\PERSISTENCE\dbTableExists;
*/
/** modules */
include_once "modules.inc";
include_once __DIR__ . "/modules.inc";
/** account types */
include_once "types.inc";
include_once __DIR__ . "/types.inc";
/** 2-factor */
include_once '2factor.inc';
include_once __DIR__ . '/2factor.inc';
/**
* Returns if this is a LAM Pro installation.
@ -60,7 +60,7 @@ function isLAMProVersion() {
function getSelfServiceSearchAttributes($scope) {
$return = [];
$modules = getAvailableModules($scope);
for ($i = 0; $i < sizeof($modules); $i++) {
for ($i = 0; $i < count($modules); $i++) {
$m = moduleCache::getModule($modules[$i], $scope);
$attributes = $m->getSelfServiceSearchAttributes();
$return = array_merge($return, $attributes);
@ -78,10 +78,10 @@ function getSelfServiceSearchAttributes($scope) {
function getSelfServiceFieldSettings($scope) {
$return = [];
$modules = getAvailableModules($scope);
for ($i = 0; $i < sizeof($modules); $i++) {
for ($i = 0; $i < count($modules); $i++) {
$m = moduleCache::getModule($modules[$i], $scope);
$settings = $m->getSelfServiceFields();
if (sizeof($settings) > 0) {
if (count($settings) > 0) {
$return[$modules[$i]] = $settings;
}
}
@ -107,14 +107,14 @@ function getSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOnly
}
$m = moduleCache::getModule($module, $scope);
$modReadOnlyFields = [];
for ($r = 0; $r < sizeof($readOnlyFields); $r++) {
for ($r = 0; $r < count($readOnlyFields); $r++) {
$parts = explode('_', $readOnlyFields[$r]);
if ($parts[0] == $module) {
$modReadOnlyFields[] = $parts[1];
}
}
$code = $m->getSelfServiceOptions($fields[$module], $attributes, $passwordChangeOnly, $modReadOnlyFields);
if (sizeof($code) > 0) {
if (count($code) > 0) {
$return[$module] = $code;
}
}
@ -134,32 +134,32 @@ function getSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOnly
function checkSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];
$modules = getAvailableModules($scope);
for ($i = 0; $i < sizeof($modules); $i++) {
for ($i = 0; $i < count($modules); $i++) {
if (!isset($fields[$modules[$i]])) {
continue;
}
$m = moduleCache::getModule($modules[$i], $scope);
$modReadOnlyFields = [];
for ($r = 0; $r < sizeof($readOnlyFields); $r++) {
for ($r = 0; $r < count($readOnlyFields); $r++) {
$parts = explode('_', $readOnlyFields[$r]);
if ($parts[0] == $modules[$i]) {
$modReadOnlyFields[] = $parts[1];
}
}
$result = $m->checkSelfServiceOptions($fields[$modules[$i]], $attributes, $passwordChangeOnly, $modReadOnlyFields);
if (sizeof($result['messages']) > 0) {
if (count($result['messages']) > 0) {
$return['messages'] = array_merge($result['messages'], $return['messages']);
}
if (sizeof($result['add']) > 0) {
if (count($result['add']) > 0) {
$return['add'] = array_merge($result['add'], $return['add']);
}
if (sizeof($result['del']) > 0) {
if (count($result['del']) > 0) {
$return['del'] = array_merge($result['del'], $return['del']);
}
if (sizeof($result['mod']) > 0) {
if (count($result['mod']) > 0) {
$return['mod'] = array_merge($result['mod'], $return['mod']);
}
if (sizeof($result['info']) > 0) {
if (count($result['info']) > 0) {
$return['info'] = array_merge($result['info'], $return['info']);
}
}
@ -176,7 +176,7 @@ function checkSelfServiceOptions($scope, $fields, $attributes, $passwordChangeOn
function getSelfServiceSettings($scope, $profile) {
$return = [];
$modules = getAvailableModules($scope);
for ($i = 0; $i < sizeof($modules); $i++) {
for ($i = 0; $i < count($modules); $i++) {
$m = moduleCache::getModule($modules[$i], $scope);
$return[$modules[$i]] = $m->getSelfServiceSettings($profile);
}
@ -194,7 +194,7 @@ function getSelfServiceSettings($scope, $profile) {
function checkSelfServiceSettings($scope, &$options, &$profile) {
$return = [];
$modules = getAvailableModules($scope);
for ($i = 0; $i < sizeof($modules); $i++) {
for ($i = 0; $i < count($modules); $i++) {
$m = moduleCache::getModule($modules[$i], $scope);
$errors = $m->checkSelfServiceSettings($options, $profile);
$return = array_merge($return, $errors);
@ -266,7 +266,7 @@ class SelfServicePersistence {
}
catch (PDOException $e) {
logNewMessage(LOG_ERR, _('Unable to connect to configuration database.') . ' ' . $e->getMessage());
throw new LAMException(_('Unable to connect to configuration database.'));
throw new LAMException(_('Unable to connect to configuration database.'), null, $e);
}
}
else {
@ -282,7 +282,7 @@ class SelfServicePersistence {
public function getProfiles(): array {
$profiles = $this->strategy->getProfiles();
ksort($profiles);
foreach ($profiles as $key => $value) {
foreach (array_keys($profiles) as $key) {
sort($profiles[$key]);
}
return $profiles;
@ -472,7 +472,7 @@ class SelfServicePersistenceStrategyFileSystem implements SelfServicePersistence
}
$profile = new selfServiceProfile();
$file = __DIR__ . "/../config/selfService/" . $name . "." . $scope;
if (is_file($file) === True) {
if (is_file($file)) {
$file = @fopen($file, "r");
if ($file) {
$data = fread($file, 10000000);
@ -506,7 +506,7 @@ class SelfServicePersistenceStrategyFileSystem implements SelfServicePersistence
$file = @fopen($path, "w");
if ($file) {
// write settings to file
fputs($file, json_encode($profile->export()));
fwrite($file, json_encode($profile->export()));
// close file
fclose($file);
@chmod($path, 0600);
@ -664,25 +664,25 @@ class SelfServicePersistenceStrategyPdo implements SelfServicePersistenceStrateg
class selfServiceProfile {
/** server address */
public $serverURL;
public $serverURL = "localhost";
/** use TLS */
public $useTLS;
public $useTLS = false;
/** LDAP suffix */
public $LDAPSuffix;
public $LDAPSuffix = "dc=my-domain,dc=com";
/** LDAP user DN*/
public $LDAPUser;
public $LDAPUser = "";
/** LDAP password */
public $LDAPPassword;
public $LDAPPassword = "";
/** use bind user also for read/modify operations */
public $useForAllOperations;
public $useForAllOperations = false;
/** LDAP search attribute */
public $searchAttribute;
public $searchAttribute = "uid";
/**
* @var string|null login handler ID
@ -690,13 +690,13 @@ class selfServiceProfile {
public ?string $loginHandler = SelfServiceUserPasswordLoginHandler::ID;
/** header for self service pages */
public $pageHeader;
public $pageHeader = '<p><a href="https://www.ldap-account-manager.org/" target="new_window"><img alt="help" class="align-middle" src="../../graphics/logo24.png" style="height:24px; width:24px" /> LDAP Account Manager </a></p><p>&nbsp;</p>';
/** base color */
public $baseColor = '#fffde2';
/** list of additional CSS links (separated by \n) */
public $additionalCSS;
public $additionalCSS = '';
/** describing text for user login */
public $loginCaption;
@ -705,13 +705,13 @@ class selfServiceProfile {
public $loginFooter;
/** label for password input */
public $passwordLabel;
public $passwordLabel = '';
/** describing text for search attribute */
public $loginAttributeText;
/** additional LDAP filter for accounts */
public $additionalLDAPFilter;
public $additionalLDAPFilter = '';
/** describing text for self service main page */
public $mainPageText;
@ -731,13 +731,13 @@ class selfServiceProfile {
/**
* List of fields that are set in read-only mode.
*/
public $readOnlyFields;
public $readOnlyFields = [];
/** List of override values for field labels: array(<field ID> => label) */
public $relabelFields;
public $relabelFields = [];
/** configuration settings of modules */
public $moduleSettings;
public $moduleSettings = [];
/** language for self service */
public $language = 'en_GB.utf8';
@ -814,22 +814,8 @@ class selfServiceProfile {
* Constructor
*/
public function __construct() {
// set default values
$this->serverURL = "localhost";
$this->useTLS = false;
$this->LDAPSuffix = "dc=my-domain,dc=com";
$this->LDAPUser = "";
$this->LDAPPassword = "";
$this->useForAllOperations = false;
$this->searchAttribute = "uid";
$this->additionalLDAPFilter = '';
$this->loginHandler = '';
$this->pageHeader = '<p><a href="https://www.ldap-account-manager.org/" target="new_window"><img alt="help" class="align-middle" src="../../graphics/logo24.png" style="height:24px; width:24px" /> LDAP Account Manager </a></p><p>&nbsp;</p>';
$this->additionalCSS = '';
$this->baseColor = '#fffde2';
$this->loginCaption = '<b>' . _("Welcome to LAM self service. Please enter your user name and password.") . '</b>';
$this->loginAttributeText = _('User name');
$this->passwordLabel = '';
$this->mainPageText = "<h1>LAM self service</h1>\n" . _("Here you can change your personal settings.");
$this->inputFields = [
['name' => _('Personal data'),
@ -839,28 +825,6 @@ class selfServiceProfile {
['name' => _('Password'),
'fields' => ['posixAccount_password']]
];
$this->readOnlyFields = [];
$this->relabelFields = [];
$this->moduleSettings = [];
$this->language = 'en_GB.utf8';
$this->enforceLanguage = true;
$this->followReferrals = 0;
$this->timeZone = 'Europe/London';
$this->twoFactorAuthentication = TwoFactorProviderService::TWO_FACTOR_NONE;
$this->twoFactorAuthenticationURL = 'https://localhost';
$this->twoFactorAuthenticationInsecure = false;
$this->twoFactorAuthenticationLabel = null;
$this->twoFactorAuthenticationOptional = false;
$this->twoFactorAuthenticationCaption = '';
$this->twoFactorAuthenticationClientId = '';
$this->twoFactorAuthenticationSecretKey = '';
$this->twoFactorAuthenticationAttribute = 'uid';
$this->twoFactorAuthenticationDomain = '';
$this->captchaProvider = '-';
$this->reCaptchaSiteKey = '';
$this->reCaptchaSecretKey = '';
$this->captchaOnLogin = false;
$this->baseUrl = '';
}
/**
@ -1078,7 +1042,7 @@ class SelfServiceUserPasswordLoginHandler implements SelfServiceLoginHandler {
*/
function addLoginFields(htmlResponsiveRow $content): void {
// user name
$userNameVal = !empty($_POST['username']) ? $_POST['username'] : '';
$userNameVal = empty($_POST['username']) ? '' : $_POST['username'];
$userField = new htmlResponsiveInputField($this->profile->loginAttributeText, 'username', $userNameVal);
$userField->setCSSClasses(['lam-initial-focus']);
$content->add($userField);
@ -1087,7 +1051,7 @@ class SelfServiceUserPasswordLoginHandler implements SelfServiceLoginHandler {
if (!empty($this->profile->passwordLabel)) {
$passwordText = $this->profile->passwordLabel;
}
$passwordVal = !empty($_POST['password']) ? $_POST['password'] : '';
$passwordVal = empty($_POST['password']) ? '' : $_POST['password'];
$passwordField = new htmlResponsiveInputField($passwordText, 'password', $passwordVal);
$passwordField->setIsPassword(true);
$content->add($passwordField);
@ -1162,7 +1126,7 @@ class SelfServiceHttpAuthLoginHandler implements SelfServiceLoginHandler {
// user name
$userLabel = new htmlLabel('username', $this->profile->loginAttributeText);
$content->addLabel($userLabel);
$userName = !empty($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '-';
$userName = empty($_SERVER['PHP_AUTH_USER']) ? '-' : $_SERVER['PHP_AUTH_USER'];
$userField = new htmlOutputText($userName);
$content->addField($userField);
// password field
@ -1315,7 +1279,7 @@ class SelfService2FaLoginHandler implements SelfServiceLoginHandler {
}
$info = $entries;
cleanLDAPResult($info);
if (sizeof($info) === 1) {
if (count($info) === 1) {
$userDN = $info[0]['dn'];
$_SESSION['selfService_clientDN'] = lamEncrypt($userDN, 'SelfService');
return;

View file

@ -67,7 +67,7 @@ function StatusMessage($MessageTyp, $MessageHeadline, $MessageText = '', $Messag
}
$format = "<div " . $class . ">\n<table>\n<tr>\n<td>" . $MessageHeadline . $MessageText . "</td>\n</tr>\n</table>\n</div>\n";
if (is_array($MessageVariables)) {
if (sizeof($MessageVariables) > 0) {
if ($MessageVariables !== []) {
array_unshift($MessageVariables, $format);
$output = call_user_func_array('sprintf', $MessageVariables);
}