rework FileDir::makePathfield() is mode is 'dropdown' to show all directories correctly (depth limited); fixes #1044

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-07-07 15:28:50 +02:00
parent c8183fbbbf
commit f1ad8b6cfd

View File

@@ -287,19 +287,19 @@ class FileDir
fclose($index_html_handler); fclose($index_html_handler);
if ($logger !== null) { if ($logger !== null) {
$logger->logAction( $logger->logAction(
FroxlorLogger::CRON_ACTION, FroxlorLogger::CRON_ACTION,
LOG_NOTICE, LOG_NOTICE,
'Creating \'index.' . Settings::Get('system.index_file_extension') . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath) 'Creating \'index.' . Settings::Get('system.index_file_extension') . '\' for Customer \'' . $template['customer_login'] . '\' based on template in directory ' . escapeshellarg($indexhtmlpath)
); );
} }
} else { } else {
$destination = self::makeCorrectDir($destination); $destination = self::makeCorrectDir($destination);
if ($logger !== null) { if ($logger !== null) {
$logger->logAction( $logger->logAction(
FroxlorLogger::CRON_ACTION, FroxlorLogger::CRON_ACTION,
LOG_NOTICE, LOG_NOTICE,
'Running: cp -a ' . Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination) 'Running: cp -a ' . Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)
); );
} }
self::safe_exec('cp -a ' . Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination)); self::safe_exec('cp -a ' . Froxlor::getInstallDir() . '/templates/misc/standardcustomer/* ' . escapeshellarg($destination));
} }
@@ -447,34 +447,23 @@ class FileDir
natcasesort($dirList); natcasesort($dirList);
if (sizeof($dirList) > 0) { if (sizeof($dirList) > 0) {
if (sizeof($dirList) <= 100) { $_field = [];
$_field = []; foreach ($dirList as $dir) {
foreach ($dirList as $dir) { if (strpos($dir, $path) === 0) {
if (strpos($dir, $path) === 0) { $dir = substr($dir, strlen($path));
$dir = substr($dir, strlen($path)); // docroot cut off of current directory == empty -> directory is the docroot
// docroot cut off of current directory == empty -> directory is the docroot if (empty($dir)) {
if (empty($dir)) { $dir = '/';
$dir = '/';
}
$dir = self::makeCorrectDir($dir);
} }
$_field[$dir] = $dir; $dir = self::makeCorrectDir($dir);
} }
$field = [ $_field[$dir] = $dir;
'type' => 'select',
'select_var' => $_field,
'selected' => $value
];
} else {
// remove starting slash we added
// for the Dropdown, #225
$value = substr($value, 1);
$field = [
'type' => 'text',
'value' => htmlspecialchars($value),
'note' => lng('panel.toomanydirs')
];
} }
$field = [
'type' => 'select',
'select_var' => $_field,
'selected' => $value
];
} else { } else {
$field = [ $field = [
'type' => 'hidden', 'type' => 'hidden',
@@ -525,25 +514,31 @@ class FileDir
$filter = function ($file, $key, $iterator) use ($exclude) { $filter = function ($file, $key, $iterator) use ($exclude) {
if (in_array($file->getFilename(), $exclude)) { if (in_array($file->getFilename(), $exclude)) {
return false; return false;
} elseif (substr($file->getFilename(), 0, 1) == '.') {
// also hide hidden folders
return false;
} }
return true; return true;
}; };
// create RecursiveIteratorIterator // create RecursiveIteratorIterator
$its = new RecursiveIteratorIterator(new RecursiveCallbackFilterIterator(new RecursiveDirectoryIterator( $its = new \RecursiveIteratorIterator(
$path, new \RecursiveCallbackFilterIterator(
RecursiveDirectoryIterator::SKIP_DOTS new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS),
), $filter)); $filter
),
\RecursiveIteratorIterator::LEAVES_ONLY,
\RecursiveIteratorIterator::CATCH_GET_CHILD
);
// we can limit the recursion-depth, but will it be helpful or // we can limit the recursion-depth, but will it be helpful or
// will people start asking "why do I only see 2 subdirectories, i want to use /a/b/c" // will people start asking "why do I only see 2 subdirectories, i want to use /a/b/c"
// let's keep this in mind and see whether it will be useful // let's keep this in mind and see whether it will be useful
// @TODO $its->setMaxDepth(2);
// $its->setMaxDepth(2);
// check every file // check every file
foreach ($its as $fullFileName => $it) { foreach ($its as $fullFileName => $it) {
if ($it->isDir() && (fileowner($fullFileName) == $uid || filegroup($fullFileName) == $gid)) { if ($it->isDir() && (fileowner($fullFileName) == $uid || filegroup($fullFileName) == $gid)) {
$_fileList[] = self::makeCorrectDir(dirname($fullFileName)); $_fileList[] = self::makeCorrectDir($fullFileName);
} }
} }
$_fileList[] = $path; $_fileList[] = $path;
@@ -634,9 +629,9 @@ class FileDir
// Fetch all quota in the desired partition // Fetch all quota in the desired partition
$repquota = []; $repquota = [];
exec( exec(
Settings::Get('system.diskquota_repquota_path') . " " . $repquota_params . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')), Settings::Get('system.diskquota_repquota_path') . " " . $repquota_params . " " . escapeshellarg(Settings::Get('system.diskquota_customer_partition')),
$repquota $repquota
); );
$usedquota = []; $usedquota = [];
foreach ($repquota as $tmpquota) { foreach ($repquota as $tmpquota) {