refactoring

This commit is contained in:
Roland Gruber 2025-07-15 16:50:47 +02:00
parent c86e146874
commit d9bced28b4
5 changed files with 37 additions and 24 deletions

View file

@ -1,12 +1,11 @@
<?php <?php
namespace LAM\UPLOAD; namespace LAM\UPLOAD;
use htmlForm; use htmlForm;
use \htmlStatusMessage; use htmlStatusMessage;
use \htmlLink; use htmlOutputText;
use \htmlOutputText; use htmlButton;
use \htmlButton; use htmlHiddenInput;
use \htmlHiddenInput; use htmlResponsiveRow;
use \htmlResponsiveRow;
use LAM\TYPES\TypeManager; use LAM\TYPES\TypeManager;
use LamTemporaryFilesManager; use LamTemporaryFilesManager;
@ -112,6 +111,10 @@ include __DIR__ . '/../../lib/adminHeader.inc';
$typeId = htmlspecialchars($_POST['typeId']); $typeId = htmlspecialchars($_POST['typeId']);
$typeManager = new TypeManager(); $typeManager = new TypeManager();
$type = $typeManager->getConfiguredType($typeId); $type = $typeManager->getConfiguredType($typeId);
if ($type === null) {
logNewMessage(LOG_ERR, 'User tried to access invalid upload type: ' . $typeId);
die();
}
// check if account type is ok // check if account type is ok
if ($type->isHidden()) { if ($type->isHidden()) {
@ -215,7 +218,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// if input data is invalid just display error messages (max 50) // if input data is invalid just display error messages (max 50)
if ($errors !== []) { if ($errors !== []) {
foreach ($errors as $error) { foreach ($errors as $error) {
$container->add(new htmlStatusMessage("ERROR", $error[0], $error[1]), 12); $container->add(new htmlStatusMessage("ERROR", $error[0], $error[1]));
} }
$container->addVerticalSpacer('2rem'); $container->addVerticalSpacer('2rem');
massPrintBackButton($type->getId(), $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
@ -250,7 +253,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// print errors if DN could not be built // print errors if DN could not be built
if ($errors !== []) { if ($errors !== []) {
foreach ($errors as $error) { foreach ($errors as $error) {
$container->add(new htmlStatusMessage("ERROR", $error[0], $error[1], $error[2]), 12); $container->add(new htmlStatusMessage("ERROR", $error[0], $error[1], $error[2]));
} }
} }
else { else {
@ -278,7 +281,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
} }
// show links for upload and LDIF export // show links for upload and LDIF export
$container->addVerticalSpacer('2rem'); $container->addVerticalSpacer('2rem');
$container->add(new htmlOutputText(_("LAM has checked your input and is now ready to create the accounts.")), 12); $container->add(new htmlOutputText(_("LAM has checked your input and is now ready to create the accounts.")));
$container->addVerticalSpacer('3rem'); $container->addVerticalSpacer('3rem');
$formRow = new htmlResponsiveRow(); $formRow = new htmlResponsiveRow();
$uploadButton = new htmlButton('upload', _("Upload accounts to LDAP")); $uploadButton = new htmlButton('upload', _("Upload accounts to LDAP"));
@ -301,7 +304,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
} }
} }
else { else {
$container->add(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')), 12); $container->add(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')));
$container->addVerticalSpacer('2rem'); $container->addVerticalSpacer('2rem');
massPrintBackButton($type->getId(), $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
@ -318,19 +321,19 @@ include __DIR__ . '/../../lib/adminFooter.inc';
* @param string[] $selectedModules selected modules for upload * @param string[] $selectedModules selected modules for upload
* @param htmlResponsiveRow $container table container * @param htmlResponsiveRow $container table container
*/ */
function massPrintBackButton(string $typeId, array $selectedModules, htmlResponsiveRow &$container): void { function massPrintBackButton(string $typeId, array $selectedModules, htmlResponsiveRow $container): void {
$row = new htmlResponsiveRow(); $row = new htmlResponsiveRow();
$backButton = new htmlButton('submit', _('Back')); $backButton = new htmlButton('submit', _('Back'));
$row->add($backButton, 12); $row->add($backButton);
$row->add(new htmlHiddenInput('type', $typeId), 12); $row->add(new htmlHiddenInput('type', $typeId));
$createPDF = 0; $createPDF = '0';
if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) {
$createPDF = 1; $createPDF = '1';
} }
$row->add(new htmlHiddenInput('createPDF', $createPDF), 12); $row->add(new htmlHiddenInput('createPDF', $createPDF));
$row->add(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure']), 12); $row->add(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure']));
foreach ($selectedModules as $selectedModule) { foreach ($selectedModules as $selectedModule) {
$row->add(new htmlHiddenInput($typeId . '___' . $selectedModule, 'on'), 12); $row->add(new htmlHiddenInput($typeId . '___' . $selectedModule, 'on'));
} }
addSecurityTokenToMetaHTML($row); addSecurityTokenToMetaHTML($row);
$container->add(new htmlForm('backform', 'masscreate.php', $row)); $container->add(new htmlForm('backform', 'masscreate.php', $row));

View file

@ -3,7 +3,7 @@ namespace LAM\UPLOAD;
/* /*
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
@ -24,6 +24,7 @@ namespace LAM\UPLOAD;
use htmlDiv; use htmlDiv;
use htmlJavaScript; use htmlJavaScript;
use htmlResponsiveRow; use htmlResponsiveRow;
use LAM\TYPES\TypeManager;
/** /**
* Creates LDAP accounts for file upload. * Creates LDAP accounts for file upload.
@ -69,8 +70,12 @@ setlanguage();
include __DIR__ . '/../../lib/adminHeader.inc'; include __DIR__ . '/../../lib/adminHeader.inc';
$typeId = htmlspecialchars($_SESSION['mass_typeId']); $typeId = htmlspecialchars($_SESSION['mass_typeId']);
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new TypeManager();
$type = $typeManager->getConfiguredType($typeId); $type = $typeManager->getConfiguredType($typeId);
if ($type === null) {
logNewMessage(LOG_ERR, 'User tried to access invalid upload type: ' . $typeId);
die();
}
// check if account type is ok // check if account type is ok
if ($type->isHidden()) { if ($type->isHidden()) {

View file

@ -26,7 +26,7 @@ use \moduleCache;
/* /*
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
@ -404,11 +404,14 @@ function showMainPage(\LAM\TYPES\ConfiguredType $type, array $selectedModules):
$data = []; $data = [];
$row->addVerticalSpacer('2rem'); $row->addVerticalSpacer('2rem');
$module = moduleCache::getModule($moduleName, $scope); $module = moduleCache::getModule($moduleName, $scope);
if ($module === null) {
continue;
}
$icon = $module->getIcon(); $icon = $module->getIcon();
if (!(str_starts_with($icon, 'http')) && !(str_starts_with($icon, '/'))) { if (!(str_starts_with($icon, 'http')) && !(str_starts_with($icon, '/'))) {
$icon = '../../graphics/' . $icon; $icon = '../../graphics/' . $icon;
} }
$moduleTitle = new htmlSubTitle(getModuleAlias($moduleName, $scope), $icon); $moduleTitle = new htmlSubTitle($module->get_alias(), $icon);
$moduleTitle->colspan = 20; $moduleTitle->colspan = 20;
$row->add($moduleTitle, 12); $row->add($moduleTitle, 12);
foreach ($columns[$moduleName] as $column) { foreach ($columns[$moduleName] as $column) {

View file

@ -8,7 +8,7 @@ parameters:
- lam/templates - lam/templates
fileExtensions: fileExtensions:
- php - php
- lib - inc
excludePaths: excludePaths:
analyseAndScan: analyseAndScan:
- */3rdParty/* - */3rdParty/*
@ -48,3 +48,5 @@ parameters:
- '#Binary operation .* between .* and .* results in an error.#' - '#Binary operation .* between .* and .* results in an error.#'
- '#Parameter \#. .* of (function|method) .* expects .*, mixed given.#' - '#Parameter \#. .* of (function|method) .* expects .*, mixed given.#'
- '#Cannot access property .* on mixed#' - '#Cannot access property .* on mixed#'
- '#.* function lamEncrypt expects string.*#'
- '#.*class htmlHiddenInput constructor expects string, mixed given.*#'

View file

@ -20,7 +20,7 @@ use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
return RectorConfig::configure() return RectorConfig::configure()
->withParallel(240, 6) ->withParallel(240, 2)
->withPaths([ ->withPaths([
__DIR__ . '/lam/help', __DIR__ . '/lam/help',
__DIR__ . '/lam/lib', __DIR__ . '/lam/lib',