refactoring

This commit is contained in:
Roland Gruber 2025-07-25 07:54:20 +02:00
parent 781e93702f
commit 419afce791
4 changed files with 43 additions and 64 deletions

View file

@ -3,7 +3,7 @@
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2010 - 2011 Pavel Pozdniak
2010 - 2024 Roland Gruber
2010 - 2025 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
@ -28,7 +28,9 @@
* @author Roland Gruber
*/
use Webklex\PHPIMAP\Client;
use Webklex\PHPIMAP\ClientManager;
use Webklex\PHPIMAP\Connection\Protocols\ImapProtocol;
/**
* Manages mailboxes on an IMAP server.
@ -612,7 +614,7 @@ class imapAccess extends baseModule {
/**
* Returns the admin password.
*
* @return String password
* @return string|null password
*/
private function getAdminPassword() {
//perform admin password
@ -668,10 +670,10 @@ class imapAccess extends baseModule {
*
* @param string $user user name
* @param string $password password
* @return Horde_Imap_Client_Socket IMAP client
* @return Client IMAP client
* @throws LAMException error during connect
*/
private function connect($user, $password) {
private function connect($user, $password): Client {
include_once __DIR__ . '/../3rdParty/composer/autoload.php';
$encryptionType = $this->moduleSettings['ImapAccess_ImapServerEncriptionProtocol'][0];
if (strrpos($this->moduleSettings['ImapAccess_ImapServerAddress'][0], ":")) {
@ -963,15 +965,18 @@ class imapAccess extends baseModule {
/**
* Sets the quota for a user.
*
* @param $client client
* @param Client $client client
* @param string $user user name
* @param string $value quota value
* @return bool successful
* @throws LAMException error setting quota
*/
private function runSetQuotaCommand($client, string $user, string $value): void {
$user = $client->getConnection()->escapeString($user);
$result = $client->getConnection()->requestAndResponse('SETQUOTA', [$user, '(STORAGE ' . $value . ')']);
$connection = $client->getConnection();
if (!($connection instanceof ImapProtocol)) {
throw new LAMException(null);
}
$user = $connection->escapeString($user);
$result = $connection->requestAndResponse('SETQUOTA', [$user, '(STORAGE ' . $value . ')']);
$result = $result->data();
if (isset($result[0][0]) && ($result[0][0] === 'OK')) {
return;
@ -984,19 +989,23 @@ class imapAccess extends baseModule {
/**
* Deletes a mailbox on the server.
*
* @param $client client
* @param $user user
* @param Client $client client
* @param string $user user
* @throws LAMException error deleting mailbox
*/
private function deleteMailbox($client, $user): void {
$userEscaped = $client->getConnection()->escapeString($user);
$adminUser = $client->getConnection()->escapeString($this->getAdminUser());
$result = $client->getConnection()->requestAndResponse('SETACL', [$userEscaped, $adminUser, '+c']);
$connection = $client->getConnection();
if (!($connection instanceof ImapProtocol)) {
throw new LAMException(null);
}
$userEscaped = $connection->escapeString($user);
$adminUser = $connection->escapeString($this->getAdminUser());
$result = $connection->requestAndResponse('SETACL', [$userEscaped, $adminUser, '+c']);
$result = $result->data();
if (!isset($result[0][0]) || ($result[0][0] !== 'OK')) {
throw new LAMException(null);
}
$result = $client->getConnection()->deleteFolder($user);
$result = $connection->deleteFolder($user);
if (!$result->successful()) {
throw new LAMException(null);
}

View file

@ -1166,7 +1166,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
}
// set K5KEY password for new users
if (!empty($this->moduleSettings['posixAccount_pwdHash'][0]) && ($this->moduleSettings['posixAccount_pwdHash'][0] === 'K5KEY')) {
$this->attributes[$this->getPasswordAttrName()][0] = pwd_hash('x', true, $this->moduleSettings['posixAccount_pwdHash'][0]);
$this->attributes['userpassword'][0] = pwd_hash('x', true, $this->moduleSettings['posixAccount_pwdHash'][0]);
}
}
}
@ -1179,9 +1179,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
}
/**
* Returns the HTML meta data for the main account page.
*
* @return array HTML meta data
* {@inheritDoc}
*/
function display_html_attributes() {
$this->initCache();
@ -1691,6 +1689,9 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
$data = str_replace('data:image/png;base64,', '', $data);
$data = base64_decode($data);
}
else {
return $messages;
}
// convert to JPG
try {
include_once __DIR__ . '/../imageutils.inc';
@ -1717,7 +1718,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
/**
* Displays the photo upload page.
*
* @return array meta HTML code
* @return htmlElement meta HTML code
*/
public function display_html_photo() {
$container = new htmlResponsiveRow();
@ -1799,7 +1800,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
// sort by DN
usort($entries, 'compareDN');
for ($i = 0; $i < count($entries); $i++) {
if (!isset($this->attributes['manager']) || !in_array($entries[$i], $this->attributes['manager'])) {
if (!in_array($entries[$i], $this->attributes['manager'])) {
$options[getAbstractDN($entries[$i])] = $entries[$i];
}
}
@ -1829,10 +1830,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
}
$return->add(new htmlSubTitle(_('Manager')));
// show existing managers
$managerTemp = [];
if (isset($this->attributes['manager'])) {
$managerTemp = $this->attributes['manager'];
}
// sort by DN
usort($managerTemp, 'compareDN');
$managers = [];
@ -1895,7 +1893,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
/**
* Displays the certificate upload page.
*
* @return array meta HTML code
* @return htmlElement meta HTML code
*/
function display_html_userCertificate() {
$container = new htmlResponsiveRow();
@ -2951,10 +2949,10 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
}
/**
* Returns the Java Script functions to manage the photo.
* Returns the JavaScript functions to manage the photo.
*
* @param boolean $readOnly content is read-only
* @return htmlJavaScript JS block
* @return htmlElement JS block
*/
private function getSelfServicePhotoJS($readOnly) {
if ($readOnly) {
@ -3031,7 +3029,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
* Returns the meta HTML code to display the certificate area.
* This also includes the file upload.
*
* @return htmlTable certificate content
* @return htmlGroup certificate content
* @throws LAMException
*/
private function getSelfServiceUserCertificates() {
@ -3149,21 +3147,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
}
/**
* Checks if all input values are correct and returns the LDAP attributes which should be changed.
* <br>Return values:
* <br>messages: array of parameters to create status messages
* <br>add: array of attributes to add
* <br>del: array of attributes to remove
* <br>mod: array of attributes to modify
* <br>info: array of values with informational value (e.g. to be used later by pre/postModify actions)
*
* Calling this method does not require the existence of an enclosing {@link accountContainer}.
*
* @param string $fields input fields
* @param array $attributes LDAP attributes
* @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
* @param array $readOnlyFields list of read-only fields
* @return array messages and attributes (array('messages' => [], 'add' => array('mail' => array('test@test.com')), 'del' => [], 'mod' => [], 'info' => []))
* {@inheritDoc}
*/
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];
@ -3350,9 +3334,9 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
/**
* Resizes the given image data to the settings provided.
*
* @param array $data binary image data
* @param string $data binary image data
* @param array $settings settings
* @return array binary image data
* @return string binary image data
*/
private function resizeAndConvertImage($data, $settings) {
include_once __DIR__ . '/../imageutils.inc';
@ -4140,7 +4124,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
*/
public function getListRenderFunction(string $attributeName): ?callable {
if (($attributeName === 'mail') || ($attributeName === 'rfc822mailbox')) {
return function(array $entry, string $attribute): ?htmlElement {
return function(array $entry, string $attribute): htmlElement {
$group = new htmlGroup();
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
for ($i = 0; $i < count($entry[$attribute]); $i++) {

View file

@ -2,7 +2,7 @@
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2024 Roland Gruber
Copyright (C) 2013 - 2025 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
@ -436,7 +436,7 @@ class kolabSharedFolder extends baseModule {
*/
public function getListRenderFunction(string $attributeName): ?callable {
if ($attributeName === 'mail') {
return function(array $entry, string $attribute): ?htmlElement {
return function(array $entry, string $attribute): htmlElement {
$group = new htmlGroup();
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
for ($i = 0; $i < count($entry[$attribute]); $i++) {

View file

@ -7,7 +7,7 @@ use LAM\PDF\PDFTableRow;
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2024 Roland Gruber
Copyright (C) 2004 - 2025 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
@ -774,21 +774,7 @@ class kolabUser extends baseModule {
}
/**
* Checks if all input values are correct and returns the LDAP attributes which should be changed.
* <br>Return values:
* <br>messages: array of parameters to create status messages
* <br>add: array of attributes to add
* <br>del: array of attributes to remove
* <br>mod: array of attributes to modify
* <br>info: array of values with informational value (e.g. to be used later by pre/postModify actions)
*
* Calling this method does not require the existence of an enclosing {@link accountContainer}.
*
* @param string $fields input fields
* @param array $attributes LDAP attributes
* @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
* @param array $readOnlyFields list of read-only fields
* @return array messages and attributes (array('messages' => [], 'add' => array('mail' => array('test@test.com')), 'del' => [], 'mod' => [], 'info' => []))
* {@inheritDoc}
*/
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];