mirror of
https://github.com/LDAPAccountManager/lam.git
synced 2025-10-03 09:49:16 +02:00
refactoring
This commit is contained in:
parent
781e93702f
commit
419afce791
4 changed files with 43 additions and 64 deletions
|
@ -3,7 +3,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) 2010 - 2011 Pavel Pozdniak
|
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
|
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
|
||||||
|
@ -28,7 +28,9 @@
|
||||||
* @author Roland Gruber
|
* @author Roland Gruber
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Webklex\PHPIMAP\Client;
|
||||||
use Webklex\PHPIMAP\ClientManager;
|
use Webklex\PHPIMAP\ClientManager;
|
||||||
|
use Webklex\PHPIMAP\Connection\Protocols\ImapProtocol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages mailboxes on an IMAP server.
|
* Manages mailboxes on an IMAP server.
|
||||||
|
@ -612,7 +614,7 @@ class imapAccess extends baseModule {
|
||||||
/**
|
/**
|
||||||
* Returns the admin password.
|
* Returns the admin password.
|
||||||
*
|
*
|
||||||
* @return String password
|
* @return string|null password
|
||||||
*/
|
*/
|
||||||
private function getAdminPassword() {
|
private function getAdminPassword() {
|
||||||
//perform admin password
|
//perform admin password
|
||||||
|
@ -668,10 +670,10 @@ class imapAccess extends baseModule {
|
||||||
*
|
*
|
||||||
* @param string $user user name
|
* @param string $user user name
|
||||||
* @param string $password password
|
* @param string $password password
|
||||||
* @return Horde_Imap_Client_Socket IMAP client
|
* @return Client IMAP client
|
||||||
* @throws LAMException error during connect
|
* @throws LAMException error during connect
|
||||||
*/
|
*/
|
||||||
private function connect($user, $password) {
|
private function connect($user, $password): Client {
|
||||||
include_once __DIR__ . '/../3rdParty/composer/autoload.php';
|
include_once __DIR__ . '/../3rdParty/composer/autoload.php';
|
||||||
$encryptionType = $this->moduleSettings['ImapAccess_ImapServerEncriptionProtocol'][0];
|
$encryptionType = $this->moduleSettings['ImapAccess_ImapServerEncriptionProtocol'][0];
|
||||||
if (strrpos($this->moduleSettings['ImapAccess_ImapServerAddress'][0], ":")) {
|
if (strrpos($this->moduleSettings['ImapAccess_ImapServerAddress'][0], ":")) {
|
||||||
|
@ -963,15 +965,18 @@ class imapAccess extends baseModule {
|
||||||
/**
|
/**
|
||||||
* Sets the quota for a user.
|
* Sets the quota for a user.
|
||||||
*
|
*
|
||||||
* @param $client client
|
* @param Client $client client
|
||||||
* @param string $user user name
|
* @param string $user user name
|
||||||
* @param string $value quota value
|
* @param string $value quota value
|
||||||
* @return bool successful
|
|
||||||
* @throws LAMException error setting quota
|
* @throws LAMException error setting quota
|
||||||
*/
|
*/
|
||||||
private function runSetQuotaCommand($client, string $user, string $value): void {
|
private function runSetQuotaCommand($client, string $user, string $value): void {
|
||||||
$user = $client->getConnection()->escapeString($user);
|
$connection = $client->getConnection();
|
||||||
$result = $client->getConnection()->requestAndResponse('SETQUOTA', [$user, '(STORAGE ' . $value . ')']);
|
if (!($connection instanceof ImapProtocol)) {
|
||||||
|
throw new LAMException(null);
|
||||||
|
}
|
||||||
|
$user = $connection->escapeString($user);
|
||||||
|
$result = $connection->requestAndResponse('SETQUOTA', [$user, '(STORAGE ' . $value . ')']);
|
||||||
$result = $result->data();
|
$result = $result->data();
|
||||||
if (isset($result[0][0]) && ($result[0][0] === 'OK')) {
|
if (isset($result[0][0]) && ($result[0][0] === 'OK')) {
|
||||||
return;
|
return;
|
||||||
|
@ -984,19 +989,23 @@ class imapAccess extends baseModule {
|
||||||
/**
|
/**
|
||||||
* Deletes a mailbox on the server.
|
* Deletes a mailbox on the server.
|
||||||
*
|
*
|
||||||
* @param $client client
|
* @param Client $client client
|
||||||
* @param $user user
|
* @param string $user user
|
||||||
* @throws LAMException error deleting mailbox
|
* @throws LAMException error deleting mailbox
|
||||||
*/
|
*/
|
||||||
private function deleteMailbox($client, $user): void {
|
private function deleteMailbox($client, $user): void {
|
||||||
$userEscaped = $client->getConnection()->escapeString($user);
|
$connection = $client->getConnection();
|
||||||
$adminUser = $client->getConnection()->escapeString($this->getAdminUser());
|
if (!($connection instanceof ImapProtocol)) {
|
||||||
$result = $client->getConnection()->requestAndResponse('SETACL', [$userEscaped, $adminUser, '+c']);
|
throw new LAMException(null);
|
||||||
|
}
|
||||||
|
$userEscaped = $connection->escapeString($user);
|
||||||
|
$adminUser = $connection->escapeString($this->getAdminUser());
|
||||||
|
$result = $connection->requestAndResponse('SETACL', [$userEscaped, $adminUser, '+c']);
|
||||||
$result = $result->data();
|
$result = $result->data();
|
||||||
if (!isset($result[0][0]) || ($result[0][0] !== 'OK')) {
|
if (!isset($result[0][0]) || ($result[0][0] !== 'OK')) {
|
||||||
throw new LAMException(null);
|
throw new LAMException(null);
|
||||||
}
|
}
|
||||||
$result = $client->getConnection()->deleteFolder($user);
|
$result = $connection->deleteFolder($user);
|
||||||
if (!$result->successful()) {
|
if (!$result->successful()) {
|
||||||
throw new LAMException(null);
|
throw new LAMException(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1166,7 +1166,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
}
|
}
|
||||||
// set K5KEY password for new users
|
// set K5KEY password for new users
|
||||||
if (!empty($this->moduleSettings['posixAccount_pwdHash'][0]) && ($this->moduleSettings['posixAccount_pwdHash'][0] === 'K5KEY')) {
|
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.
|
* {@inheritDoc}
|
||||||
*
|
|
||||||
* @return array HTML meta data
|
|
||||||
*/
|
*/
|
||||||
function display_html_attributes() {
|
function display_html_attributes() {
|
||||||
$this->initCache();
|
$this->initCache();
|
||||||
|
@ -1691,6 +1689,9 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
$data = str_replace('data:image/png;base64,', '', $data);
|
$data = str_replace('data:image/png;base64,', '', $data);
|
||||||
$data = base64_decode($data);
|
$data = base64_decode($data);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return $messages;
|
||||||
|
}
|
||||||
// convert to JPG
|
// convert to JPG
|
||||||
try {
|
try {
|
||||||
include_once __DIR__ . '/../imageutils.inc';
|
include_once __DIR__ . '/../imageutils.inc';
|
||||||
|
@ -1717,7 +1718,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
/**
|
/**
|
||||||
* Displays the photo upload page.
|
* Displays the photo upload page.
|
||||||
*
|
*
|
||||||
* @return array meta HTML code
|
* @return htmlElement meta HTML code
|
||||||
*/
|
*/
|
||||||
public function display_html_photo() {
|
public function display_html_photo() {
|
||||||
$container = new htmlResponsiveRow();
|
$container = new htmlResponsiveRow();
|
||||||
|
@ -1799,7 +1800,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
// sort by DN
|
// sort by DN
|
||||||
usort($entries, 'compareDN');
|
usort($entries, 'compareDN');
|
||||||
for ($i = 0; $i < count($entries); $i++) {
|
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];
|
$options[getAbstractDN($entries[$i])] = $entries[$i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1829,10 +1830,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
}
|
}
|
||||||
$return->add(new htmlSubTitle(_('Manager')));
|
$return->add(new htmlSubTitle(_('Manager')));
|
||||||
// show existing managers
|
// show existing managers
|
||||||
$managerTemp = [];
|
|
||||||
if (isset($this->attributes['manager'])) {
|
|
||||||
$managerTemp = $this->attributes['manager'];
|
$managerTemp = $this->attributes['manager'];
|
||||||
}
|
|
||||||
// sort by DN
|
// sort by DN
|
||||||
usort($managerTemp, 'compareDN');
|
usort($managerTemp, 'compareDN');
|
||||||
$managers = [];
|
$managers = [];
|
||||||
|
@ -1895,7 +1893,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
/**
|
/**
|
||||||
* Displays the certificate upload page.
|
* Displays the certificate upload page.
|
||||||
*
|
*
|
||||||
* @return array meta HTML code
|
* @return htmlElement meta HTML code
|
||||||
*/
|
*/
|
||||||
function display_html_userCertificate() {
|
function display_html_userCertificate() {
|
||||||
$container = new htmlResponsiveRow();
|
$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
|
* @param boolean $readOnly content is read-only
|
||||||
* @return htmlJavaScript JS block
|
* @return htmlElement JS block
|
||||||
*/
|
*/
|
||||||
private function getSelfServicePhotoJS($readOnly) {
|
private function getSelfServicePhotoJS($readOnly) {
|
||||||
if ($readOnly) {
|
if ($readOnly) {
|
||||||
|
@ -3031,7 +3029,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
* Returns the meta HTML code to display the certificate area.
|
* Returns the meta HTML code to display the certificate area.
|
||||||
* This also includes the file upload.
|
* This also includes the file upload.
|
||||||
*
|
*
|
||||||
* @return htmlTable certificate content
|
* @return htmlGroup certificate content
|
||||||
* @throws LAMException
|
* @throws LAMException
|
||||||
*/
|
*/
|
||||||
private function getSelfServiceUserCertificates() {
|
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.
|
* {@inheritDoc}
|
||||||
* <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' => []))
|
|
||||||
*/
|
*/
|
||||||
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
|
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
|
||||||
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];
|
$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.
|
* 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
|
* @param array $settings settings
|
||||||
* @return array binary image data
|
* @return string binary image data
|
||||||
*/
|
*/
|
||||||
private function resizeAndConvertImage($data, $settings) {
|
private function resizeAndConvertImage($data, $settings) {
|
||||||
include_once __DIR__ . '/../imageutils.inc';
|
include_once __DIR__ . '/../imageutils.inc';
|
||||||
|
@ -4140,7 +4124,7 @@ class inetOrgPerson extends baseModule implements passwordService, AccountStatus
|
||||||
*/
|
*/
|
||||||
public function getListRenderFunction(string $attributeName): ?callable {
|
public function getListRenderFunction(string $attributeName): ?callable {
|
||||||
if (($attributeName === 'mail') || ($attributeName === 'rfc822mailbox')) {
|
if (($attributeName === 'mail') || ($attributeName === 'rfc822mailbox')) {
|
||||||
return function(array $entry, string $attribute): ?htmlElement {
|
return function(array $entry, string $attribute): htmlElement {
|
||||||
$group = new htmlGroup();
|
$group = new htmlGroup();
|
||||||
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
|
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
|
||||||
for ($i = 0; $i < count($entry[$attribute]); $i++) {
|
for ($i = 0; $i < count($entry[$attribute]); $i++) {
|
||||||
|
|
|
@ -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) 2013 - 2024 Roland Gruber
|
Copyright (C) 2013 - 2025 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
|
||||||
|
@ -436,7 +436,7 @@ class kolabSharedFolder extends baseModule {
|
||||||
*/
|
*/
|
||||||
public function getListRenderFunction(string $attributeName): ?callable {
|
public function getListRenderFunction(string $attributeName): ?callable {
|
||||||
if ($attributeName === 'mail') {
|
if ($attributeName === 'mail') {
|
||||||
return function(array $entry, string $attribute): ?htmlElement {
|
return function(array $entry, string $attribute): htmlElement {
|
||||||
$group = new htmlGroup();
|
$group = new htmlGroup();
|
||||||
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
|
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
|
||||||
for ($i = 0; $i < count($entry[$attribute]); $i++) {
|
for ($i = 0; $i < count($entry[$attribute]); $i++) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use LAM\PDF\PDFTableRow;
|
||||||
/*
|
/*
|
||||||
|
|
||||||
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) 2004 - 2024 Roland Gruber
|
Copyright (C) 2004 - 2025 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
|
||||||
|
@ -774,21 +774,7 @@ class kolabUser extends baseModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if all input values are correct and returns the LDAP attributes which should be changed.
|
* {@inheritDoc}
|
||||||
* <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' => []))
|
|
||||||
*/
|
*/
|
||||||
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
|
function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
|
||||||
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];
|
$return = ['messages' => [], 'add' => [], 'del' => [], 'mod' => [], 'info' => []];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue