refactoring

This commit is contained in:
Roland Gruber 2025-07-29 07:49:14 +02:00
parent 9a065cebb5
commit 6c589065ad
12 changed files with 34 additions and 27 deletions

View file

@ -671,13 +671,16 @@ function getRequiredExtensions() {
* meta HTML code. This allows to have a common design for all module pages. * meta HTML code. This allows to have a common design for all module pages.
* *
* @param string|null $module Name of account module * @param string|null $module Name of account module
* @param htmlElement|htmlElement[] $input htmlElement or array of htmlElement elements * @param htmlElement|htmlElement[]|null $input htmlElement or array of htmlElement elements
* @param array $values List of values which override the defaults in $input (name => value) * @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed * @param boolean $restricted If true then no buttons will be displayed
* @param string|null $scope Account type * @param string|null $scope Account type
* @return array List of input field names and their type (name => type) * @return array List of input field names and their type (name => type)
*/ */
function parseHtml($module, $input, $values, $restricted, $scope) { function parseHtml($module, $input, $values, $restricted, $scope) {
if ($input === null) {
return [];
}
if ($input instanceof htmlElement) { if ($input instanceof htmlElement) {
return $input->generateHTML($module, $input, $values, $restricted, $scope); return $input->generateHTML($module, $input, $values, $restricted, $scope);
} }

View file

@ -911,7 +911,7 @@ class fixed_ip extends baseModule {
*/ */
public function getListRenderFunction(string $attributeName): ?callable { public function getListRenderFunction(string $attributeName): ?callable {
if ($attributeName === 'fixed_ips') { if ($attributeName === 'fixed_ips') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
// find all fixed addresses: // find all fixed addresses:
$entries = searchLDAP($entry['dn'], 'objectClass=dhcpHost', ['dhcpstatements', 'dhcphwaddress', 'cn']); $entries = searchLDAP($entry['dn'], 'objectClass=dhcpHost', ['dhcpstatements', 'dhcphwaddress', 'cn']);
if (count($entries) > 0) { if (count($entries) > 0) {
@ -959,7 +959,7 @@ class fixed_ip extends baseModule {
} }
return $group; return $group;
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -411,7 +411,7 @@ class imapAccess extends baseModule {
/** /**
* Creates the mailbox for a user. * Creates the mailbox for a user.
* *
* @param Horde_Imap_Client_Socket $client IMAP client * @param Client $client IMAP client
* @param string $userName user name * @param string $userName user name
* @param string $email_domain email domain * @param string $email_domain email domain
* @return array error messages * @return array error messages
@ -452,7 +452,7 @@ class imapAccess extends baseModule {
/** /**
* Sets the mailbox quota for a user. * Sets the mailbox quota for a user.
* *
* @param Horde_Imap_Client_Socket $client IMAP client * @param Client $client IMAP client
* @param string $userName user name * @param string $userName user name
* @param string $email_domain email domain * @param string $email_domain email domain
* @param string $quota mailbox quota * @param string $quota mailbox quota
@ -927,27 +927,31 @@ class imapAccess extends baseModule {
/** /**
* Returns if the mailbox exists. * Returns if the mailbox exists.
* *
* @param $client IMAP client * @param Client $client IMAP client
* @param string $path mailbox path * @param string $path mailbox path
* @return bool is existing * @return bool is existing
*/ */
private function isMailboxExisting($client, string $path): bool { private function isMailboxExisting($client, string $path): bool {
$list = $client->getConnection()->folders($path); $list = $client->getConnection()->folders($path);
return ($list !== null) && is_array($list->data()) && (count($list->data()) >= 1); return is_array($list->data()) && (count($list->data()) >= 1);
} }
/** /**
* Returns the quota data for the user. * Returns the quota data for the user.
* *
* @param $client IMAP client * @param Client $client IMAP client
* @param string $user user name * @param string $user user name
* @return array array with keys QUOTA_USAGE and QUOTA_LIMIT * @return array array with keys QUOTA_USAGE and QUOTA_LIMIT
*/ */
private function getQuota($client, string $user): array { private function getQuota($client, string $user): array {
$user = $client->getConnection()->escapeString($user); $connection = $client->getConnection();
if (!($connection instanceof ImapProtocol)) {
return [];
}
$user = $connection->escapeString($user);
$quota_values = []; $quota_values = [];
try { try {
$quota = $client->getConnection()->requestAndResponse('GETQUOTA', [$user]); $quota = $connection->requestAndResponse('GETQUOTA', [$user]);
$quota = $quota->data(); $quota = $quota->data();
if (isset($quota[0][2][0]) && ($quota[0][2][0] === 'STORAGE')) { if (isset($quota[0][2][0]) && ($quota[0][2][0] === 'STORAGE')) {
$quota_values = [ $quota_values = [

View file

@ -4138,7 +4138,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
}; };
} }
elseif ($attributeName === 'jpegphoto') { elseif ($attributeName === 'jpegphoto') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) { if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) {
if (strlen($entry[$attribute][0]) < 100) { if (strlen($entry[$attribute][0]) < 100) {
// looks like we have read broken binary data, reread photo // looks like we have read broken binary data, reread photo
@ -4162,7 +4162,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
$image->setCSSClasses(['thumbnail']); $image->setCSSClasses(['thumbnail']);
return $image; return $image;
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -820,7 +820,7 @@ class range extends baseModule {
*/ */
public function getListRenderFunction(string $attributeName): ?callable { public function getListRenderFunction(string $attributeName): ?callable {
if ($attributeName === 'dhcprange') { if ($attributeName === 'dhcprange') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (!empty($entry[$attribute][0])) { if (!empty($entry[$attribute][0])) {
$table = new htmlTable(); $table = new htmlTable();
$table->setCSSClasses(['nowrap']); $table->setCSSClasses(['nowrap']);
@ -861,7 +861,7 @@ class range extends baseModule {
} }
return $table; return $table;
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -3089,7 +3089,7 @@ class sambaSamAccount extends baseModule implements passwordService, AccountStat
*/ */
public function getListRenderFunction(string $attributeName): ?callable { public function getListRenderFunction(string $attributeName): ?callable {
if ($attributeName === 'sambakickofftime') { if ($attributeName === 'sambakickofftime') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (!empty($entry[$attribute][0])) { if (!empty($entry[$attribute][0])) {
if ($entry[$attribute][0] > 2147483648) { if ($entry[$attribute][0] > 2147483648) {
return new htmlOutputText(""); return new htmlOutputText("");
@ -3099,7 +3099,7 @@ class sambaSamAccount extends baseModule implements passwordService, AccountStat
return new htmlOutputText($date->format('d.m.Y')); return new htmlOutputText($date->format('d.m.Y'));
} }
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -1036,12 +1036,12 @@ class shadowAccount extends baseModule implements passwordService, AccountStatus
*/ */
public function getListRenderFunction(string $attributeName): ?callable { public function getListRenderFunction(string $attributeName): ?callable {
if (($attributeName === 'shadowexpire') || ($attributeName === 'shadowlastchange')) { if (($attributeName === 'shadowexpire') || ($attributeName === 'shadowlastchange')) {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (!empty($entry[$attribute][0])) { if (!empty($entry[$attribute][0])) {
$time = new DateTime('@' . $entry[$attribute][0] * 24 * 3600, getTimeZone()); $time = new DateTime('@' . $entry[$attribute][0] * 24 * 3600, getTimeZone());
return new htmlOutputText($time->format('d.m.Y')); return new htmlOutputText($time->format('d.m.Y'));
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -1126,7 +1126,7 @@ class windowsGroup extends baseModule {
}; };
} }
elseif (($attributeName === 'managedby') || ($attributeName === 'member')) { elseif (($attributeName === 'managedby') || ($attributeName === 'member')) {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (!empty($entry[$attribute][0])) { if (!empty($entry[$attribute][0])) {
$typeManager = new TypeManager(); $typeManager = new TypeManager();
$values = $entry[$attribute]; $values = $entry[$attribute];
@ -1149,7 +1149,7 @@ class windowsGroup extends baseModule {
} }
return new htmlDiv(null, new htmlOutputText(implode('<br>', $values), false), ['rightToLeftText']); return new htmlDiv(null, new htmlOutputText(implode('<br>', $values), false), ['rightToLeftText']);
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -414,7 +414,7 @@ class windowsHost extends baseModule {
}; };
} }
elseif ($attributeName === 'managedby') { elseif ($attributeName === 'managedby') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (!empty($entry[$attribute][0])) { if (!empty($entry[$attribute][0])) {
$value = $entry[$attribute][0]; $value = $entry[$attribute][0];
$typeManager = new TypeManager(); $typeManager = new TypeManager();
@ -431,7 +431,7 @@ class windowsHost extends baseModule {
} }
return new htmlDiv(null, new htmlOutputText($value, false), ['rightToLeftText']); return new htmlDiv(null, new htmlOutputText($value, false), ['rightToLeftText']);
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -4808,7 +4808,7 @@ class windowsUser extends baseModule implements passwordService, AccountStatusPr
}; };
} }
elseif (($attributeName === 'jpegphoto') || ($attributeName === 'thumbnailphoto')) { elseif (($attributeName === 'jpegphoto') || ($attributeName === 'thumbnailphoto')) {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) { if (isset($entry[$attribute][0]) && ($entry[$attribute][0] !== '')) {
if (strlen($entry[$attribute][0]) < 100) { if (strlen($entry[$attribute][0]) < 100) {
// looks like we have read broken binary data, reread photo // looks like we have read broken binary data, reread photo
@ -4832,7 +4832,7 @@ class windowsUser extends baseModule implements passwordService, AccountStatusPr
$image->setCSSClasses(['thumbnail']); $image->setCSSClasses(['thumbnail']);
return $image; return $image;
} }
return null; return new htmlGroup();
}; };
} }
elseif ($attributeName === 'accountexpires') { elseif ($attributeName === 'accountexpires') {
@ -4848,7 +4848,7 @@ class windowsUser extends baseModule implements passwordService, AccountStatusPr
}; };
} }
elseif ($attributeName === 'manager') { elseif ($attributeName === 'manager') {
return function(array $entry, string $attribute): ?htmlElement { return function(array $entry, string $attribute): htmlElement {
if (!empty($entry[$attribute][0])) { if (!empty($entry[$attribute][0])) {
$value = $entry[$attribute][0]; $value = $entry[$attribute][0];
$typeManager = new TypeManager(); $typeManager = new TypeManager();
@ -4865,7 +4865,7 @@ class windowsUser extends baseModule implements passwordService, AccountStatusPr
} }
return new htmlDiv(null, new htmlOutputText($value, false), ['rightToLeftText']); return new htmlDiv(null, new htmlOutputText($value, false), ['rightToLeftText']);
} }
return null; return new htmlGroup();
}; };
} }
return null; return null;

View file

@ -6,6 +6,7 @@ use \htmlStatusMessage;
use \htmlSubTitle; use \htmlSubTitle;
use \htmlOutputText; use \htmlOutputText;
use \htmlImage; use \htmlImage;
use LAM\SCHEMA\ObjectClass;
use function \LAM\SCHEMA\get_schema_objectclasses; use function \LAM\SCHEMA\get_schema_objectclasses;
use function \LAM\SCHEMA\get_cached_schema; use function \LAM\SCHEMA\get_cached_schema;
/* /*

View file

@ -15,7 +15,6 @@ parameters:
analyseAndScan: analyseAndScan:
- */lists/changePassword.php - */lists/changePassword.php
ignoreErrors: ignoreErrors:
- '#.* on an unknown class .*#'
- '#.* has invalid type .*#' - '#.* has invalid type .*#'
- '#Function [a-zA-Z0-9\\_-]+ not found.#' - '#Function [a-zA-Z0-9\\_-]+ not found.#'
- '#Used function [a-zA-Z0-9\\_-]+ not found.#' - '#Used function [a-zA-Z0-9\\_-]+ not found.#'