mirror of
https://github.com/LDAPAccountManager/lam.git
synced 2025-10-03 09:49:16 +02:00
refactoring
This commit is contained in:
parent
2adae535e2
commit
68a26ab851
3 changed files with 63 additions and 48 deletions
|
@ -1748,8 +1748,8 @@ class moduleCache {
|
|||
/**
|
||||
* Returns a new/cached module with the given name and scope.
|
||||
*
|
||||
* @param String $name module name
|
||||
* @param String $scope module scope (e.g. user)
|
||||
* @param string $name module name
|
||||
* @param string|null $scope module scope (e.g. user)
|
||||
* @return null|baseModule module object
|
||||
*/
|
||||
public static function getModule($name, $scope): ?object {
|
||||
|
|
|
@ -3,17 +3,20 @@
|
|||
namespace LAM\CONFIG;
|
||||
|
||||
use htmlJavaScript;
|
||||
use \moduleCache;
|
||||
use \htmlSpacer;
|
||||
use \htmlTable;
|
||||
use \htmlButton;
|
||||
use \htmlResponsiveRow;
|
||||
use \htmlSubTitle;
|
||||
use LAM\TYPES\TypeManager;
|
||||
use LAMConfig;
|
||||
use moduleCache;
|
||||
use htmlSpacer;
|
||||
use htmlTable;
|
||||
use htmlButton;
|
||||
use htmlResponsiveRow;
|
||||
use htmlSubTitle;
|
||||
use function LAM\TYPES\getTypes;
|
||||
|
||||
/*
|
||||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2009 - 2024 Roland Gruber
|
||||
Copyright (C) 2009 - 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
|
||||
|
@ -70,6 +73,9 @@ if (isset($_POST['cancelSettings'])) {
|
|||
}
|
||||
|
||||
$conf = &$_SESSION['conf_config'];
|
||||
if (!($conf instanceof LAMConfig)) {
|
||||
die();
|
||||
}
|
||||
|
||||
$errorsToDisplay = checkInput();
|
||||
|
||||
|
@ -105,8 +111,6 @@ if ((isset($_POST['saveSettings']) || isset($_POST['editmodules'])
|
|||
}
|
||||
}
|
||||
|
||||
$allTypes = \LAM\TYPES\getTypes();
|
||||
|
||||
echo $_SESSION['header'];
|
||||
printHeaderContents(_("LDAP Account Manager Configuration"), '../..');
|
||||
echo "</head><body>\n";
|
||||
|
@ -130,7 +134,7 @@ printConfigurationPageTabs(ConfigurationPageTab::MODULE_SETTINGS);
|
|||
|
||||
|
||||
// module settings
|
||||
$typeManager = new \LAM\TYPES\TypeManager($conf);
|
||||
$typeManager = new TypeManager($conf);
|
||||
$types = $typeManager->getConfiguredTypes();
|
||||
|
||||
// get list of scopes of modules
|
||||
|
@ -156,19 +160,22 @@ for ($i = 0; $i < count($modules); $i++) {
|
|||
continue;
|
||||
}
|
||||
$module = moduleCache::getModule($modules[$i], null);
|
||||
if ($module === null) {
|
||||
continue;
|
||||
}
|
||||
$iconImage = $module->getIcon();
|
||||
if (($iconImage != null) && !(str_starts_with($iconImage, 'http')) && !(str_starts_with($iconImage, '/'))) {
|
||||
$iconImage = '../../graphics/' . $iconImage;
|
||||
}
|
||||
$row = new htmlResponsiveRow();
|
||||
$row->add(new htmlSubTitle(getModuleAlias($modules[$i], null), $iconImage, null, true), 12);
|
||||
$row->add(new htmlSubTitle($module->get_alias(), $iconImage, null, true));
|
||||
if (is_array($options[$modules[$i]])) {
|
||||
foreach ($options[$modules[$i]] as $option) {
|
||||
$row->add($option, 12);
|
||||
$row->add($option);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$row->add($options[$modules[$i]], 12);
|
||||
$row->add($options[$modules[$i]]);
|
||||
}
|
||||
$configTypes = parseHtml($modules[$i], $row, $old_options, false, null);
|
||||
$_SESSION['conf_types'] = array_merge($configTypes, $_SESSION['conf_types']);
|
||||
|
@ -210,7 +217,10 @@ function checkInput(): array {
|
|||
return [];
|
||||
}
|
||||
$conf = &$_SESSION['conf_config'];
|
||||
$typeManager = new \LAM\TYPES\TypeManager($conf);
|
||||
if (!($conf instanceof LAMConfig)) {
|
||||
return [];
|
||||
}
|
||||
$typeManager = new TypeManager($conf);
|
||||
$types = $typeManager->getConfiguredTypes();
|
||||
|
||||
// check module options
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
<?php
|
||||
namespace LAM\DELETE;
|
||||
use \htmlGroup;
|
||||
use accountContainer;
|
||||
use DateTime;
|
||||
use htmlGroup;
|
||||
use htmlJavaScript;
|
||||
use \htmlResponsiveRow;
|
||||
use \htmlButton;
|
||||
use \htmlSpacer;
|
||||
use \htmlHiddenInput;
|
||||
use \htmlOutputText;
|
||||
use \htmlStatusMessage;
|
||||
use htmlResponsiveRow;
|
||||
use htmlButton;
|
||||
use htmlSpacer;
|
||||
use htmlHiddenInput;
|
||||
use htmlOutputText;
|
||||
use htmlStatusMessage;
|
||||
use LAM\TYPES\TypeManager;
|
||||
use moduleCache;
|
||||
|
||||
/*
|
||||
|
||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||
Copyright (C) 2003 - 2006 Tilo Lutz
|
||||
Copyright (C) 2007 - 2023 Roland Gruber
|
||||
Copyright (C) 2007 - 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
|
||||
|
@ -83,7 +88,7 @@ foreach ($_SESSION as $key => $value) {
|
|||
}
|
||||
}
|
||||
|
||||
$typeManager = new \LAM\TYPES\TypeManager();
|
||||
$typeManager = new TypeManager();
|
||||
|
||||
if (isset($_POST['type']) && ($typeManager->getConfiguredType($_POST['type']) === null)) {
|
||||
logNewMessage(LOG_ERR, 'Invalid type: ' . $_POST['type']);
|
||||
|
@ -109,42 +114,45 @@ if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
|
|||
$users[] = substr($dn, $start, $end-$start);
|
||||
}
|
||||
|
||||
$sessionKey = $sessionAccountPrefix . (new \DateTime('now', getTimeZone()))->getTimestamp() . generateRandomText();
|
||||
$sessionKey = $sessionAccountPrefix . (new DateTime('now', getTimeZone()))->getTimestamp() . generateRandomText();
|
||||
//load account
|
||||
$_SESSION[$sessionKey] = new \accountContainer($type, $sessionKey);
|
||||
$_SESSION[$sessionKey] = new accountContainer($type, $sessionKey);
|
||||
// Show HTML Page
|
||||
include __DIR__ . '/../lib/adminHeader.inc';
|
||||
echo "<div class=\"smallPaddingContent\">";
|
||||
echo "<br>\n";
|
||||
echo "<form action=\"delete.php\" method=\"post\">\n";
|
||||
$container = new htmlResponsiveRow();
|
||||
$container->add(new htmlOutputText(_("Do you really want to remove the following accounts?")), 12);
|
||||
$container->add(new htmlOutputText(_("Do you really want to remove the following accounts?")));
|
||||
$container->addVerticalSpacer('2rem');
|
||||
$userCount = count($users);
|
||||
for ($i = 0; $i < $userCount; $i++) {
|
||||
$container->addLabel(new htmlOutputText(_("Account name:")));
|
||||
$container->addField(new htmlOutputText($users[$i]));
|
||||
$container->addLabel(new htmlOutputText(_('DN') . ':'));
|
||||
$container->addField(new htmlOutputText($_SESSION['delete_dn'][$i]));
|
||||
$container->addField(new htmlOutputText((string) $_SESSION['delete_dn'][$i]));
|
||||
$_SESSION[$sessionKey]->load_account($_SESSION['delete_dn'][$i]);
|
||||
if (!$_SESSION[$sessionKey]->hasOnlyVirtualChildren()) {
|
||||
$childCount = getChildCount($_SESSION['delete_dn'][$i]);
|
||||
if ($childCount > 0) {
|
||||
$container->addLabel(new htmlOutputText(_('Number of child entries') . ':'));
|
||||
$container->addField(new htmlOutputText($childCount));
|
||||
$container->addField(new htmlOutputText((string) $childCount));
|
||||
}
|
||||
}
|
||||
$container->addVerticalSpacer('0.5rem');
|
||||
}
|
||||
addSecurityTokenToMetaHTML($container);
|
||||
$container->add(new htmlHiddenInput('type', $type->getId()), 12);
|
||||
$container->add(new htmlHiddenInput('type', $type->getId()));
|
||||
$container->addVerticalSpacer('1rem');
|
||||
parseHtml(null, $container, [], false, $type->getScope());
|
||||
// Print delete rows from modules
|
||||
$modules = $_SESSION['config']->get_AccountModules($type->getId());
|
||||
$values = [];
|
||||
foreach ($modules as $module) {
|
||||
$module = \moduleCache::getModule($module, $type->getScope());
|
||||
$module = moduleCache::getModule($module, $type->getScope());
|
||||
if ($module === null) {
|
||||
continue;
|
||||
}
|
||||
parseHtml($module::class, $module->display_html_delete(), $values, true, $type->getScope());
|
||||
}
|
||||
$buttonContainer = new htmlResponsiveRow();
|
||||
|
@ -156,7 +164,7 @@ if (isset($_GET['type']) && isset($_SESSION['delete_dn'])) {
|
|||
$buttonGroup->addElement(new htmlSpacer('0.5rem', null));
|
||||
$cancelButton = new htmlButton('cancel', _('Cancel'));
|
||||
$buttonGroup->addElement($cancelButton);
|
||||
$buttonContainer->add($buttonGroup, 12);
|
||||
$buttonContainer->add($buttonGroup);
|
||||
$buttonContainer->addVerticalSpacer('1rem');
|
||||
parseHtml(null, $buttonContainer, [], false, $type->getScope());
|
||||
echo "</form>\n";
|
||||
|
@ -180,8 +188,8 @@ elseif (isset($_POST['cancelAllOk'])) {
|
|||
if (isset($_POST['delete'])) {
|
||||
$typeId = $_POST['type'];
|
||||
$type = $typeManager->getConfiguredType($typeId);
|
||||
if (!checkIfDeleteEntriesIsAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
|
||||
logNewMessage(LOG_ERR, 'User tried to delete entries of forbidden type '. $type->getId());
|
||||
if (($type === null) || !checkIfDeleteEntriesIsAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
|
||||
logNewMessage(LOG_ERR, 'User tried to delete entries of forbidden type '. $typeId);
|
||||
die();
|
||||
}
|
||||
// Show HTML Page
|
||||
|
@ -190,15 +198,15 @@ if (isset($_POST['delete'])) {
|
|||
echo "<div class=\"smallPaddingContent\"><br>\n";
|
||||
$container = new htmlResponsiveRow();
|
||||
addSecurityTokenToMetaHTML($container);
|
||||
$container->add(new htmlHiddenInput('type', $type->getId()), 12);
|
||||
$container->add(new htmlHiddenInput('type', $type->getId()));
|
||||
|
||||
$sessionKey = $sessionAccountPrefix . (new \DateTime('now', getTimeZone()))->getTimestamp() . generateRandomText();
|
||||
$_SESSION[$sessionKey] = new \accountContainer($type, $sessionKey);
|
||||
$sessionKey = $sessionAccountPrefix . (new DateTime('now', getTimeZone()))->getTimestamp() . generateRandomText();
|
||||
$_SESSION[$sessionKey] = new accountContainer($type, $sessionKey);
|
||||
// Delete dns
|
||||
$allOk = true;
|
||||
$allErrors = [];
|
||||
foreach ($_SESSION['delete_dn'] as $deleteDN) {
|
||||
// Set to true if an real error has happened
|
||||
// Set to true if a real error has happened
|
||||
$stopProcessing = false;
|
||||
// First load DN.
|
||||
$_SESSION[$sessionKey]->load_account($deleteDN);
|
||||
|
@ -313,22 +321,19 @@ if (isset($_POST['delete'])) {
|
|||
}
|
||||
}
|
||||
if (!$stopProcessing) {
|
||||
$container->add(new htmlOutputText(sprintf(_('Deleted DN: %s'), $deleteDN)), 12);
|
||||
foreach ($errors as $error) {
|
||||
$container->add(htmlStatusMessage::fromParamArray($error), 12);
|
||||
}
|
||||
$container->add(new htmlOutputText(sprintf(_('Deleted DN: %s'), $deleteDN)));
|
||||
}
|
||||
else {
|
||||
$container->add(new htmlOutputText(sprintf(_('Error while deleting DN: %s'), $deleteDN)), 12);
|
||||
foreach ($errors as $error) {
|
||||
$container->add(htmlStatusMessage::fromParamArray($error), 12);
|
||||
$container->add(new htmlOutputText(sprintf(_('Error while deleting DN: %s'), $deleteDN)));
|
||||
}
|
||||
foreach ($errors as $error) {
|
||||
$container->add(htmlStatusMessage::fromParamArray($error));
|
||||
}
|
||||
$allErrors = [...$allErrors, ...$errors];
|
||||
}
|
||||
$container->addVerticalSpacer('2rem');
|
||||
$buttonName = $allOk ? 'cancelAllOk' : 'cancel';
|
||||
$container->add(new htmlButton($buttonName, _('Back to list')), 12);
|
||||
$container->add(new htmlButton($buttonName, _('Back to list')));
|
||||
$container->addVerticalSpacer('1rem');
|
||||
if ($allOk) {
|
||||
$_SESSION['listRedirectMessages'] = $allErrors;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue