diff --git a/README.md b/README.md index 294f493..c58329b 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,9 @@ http://127.0.0.1:8088 - ZIP erstellen, ZIP/TAR(.gz/.bz2/.xz) entpacken (mit Schutz gegen Pfade außerhalb des Ziels) - Prüfsummen (MD5, SHA-256) und Dateivergleich - Unraid: physischer Ort (disk/cache-Pool) und freier Speicher, „Unraid-Rechte reparieren“ (nobody:users, 777/666) -- Wurzelordner (z. B. `/mnt/user`) können nicht gelöscht, verschoben oder in den Rechten geändert werden +- Optional „Ganzes System (ab /)“ in den Einstellungen: zeigt zusätzlich das komplette Dateisystem +- Wurzelordner, Ordner direkt unter `/` (z. B. `/boot`, `/etc`, `/usr`) und Mountpunkte unter `/mnt` können nicht + gelöscht, verschoben oder in den Rechten geändert werden; `/proc`, `/sys`, `/dev` und `/run` werden nur angezeigt Tastatur: Pfeiltasten, Enter, Backspace (hoch), Alt+←/→, Entf, F2, Strg+A/C/X/V, Strg+F, Strg+Shift+N, Esc. Dateien aus der Zwischenablage des eigenen Rechners werden mit Strg+V hochgeladen. diff --git a/build-plugin.sh b/build-plugin.sh index d3026e7..f5c7094 100755 --- a/build-plugin.sh +++ b/build-plugin.sh @@ -5,7 +5,7 @@ set -eu export COPYFILE_DISABLE=1 PLUGIN="u-navigator" -VERSION="2026.11.21.r004" +VERSION="2026.11.21.r005" PKG_DIR="packages" WORK_DIR=".plugin-build" PKG_NAME="${PLUGIN}-${VERSION}.tgz" diff --git a/packages/u-navigator-2026.11.21.r005.tgz b/packages/u-navigator-2026.11.21.r005.tgz new file mode 100644 index 0000000..fa1026e Binary files /dev/null and b/packages/u-navigator-2026.11.21.r005.tgz differ diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/common.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/common.php index b349805..7967bf7 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/common.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/common.php @@ -4,6 +4,9 @@ const UNAV_DEFAULT_ROOT = '/mnt/user'; const UNAV_JOB_DIR = '/tmp/u-navigator/jobs'; const UNAV_SETTINGS_FILE = '/boot/config/plugins/u-navigator/settings.json'; const UNAV_MAX_FAVORITES = 50; +const UNAV_SYSTEM_ROOT = '/'; +// Kernel/virtual filesystems: never walked recursively (endless or device files). +const UNAV_PSEUDO_FS = ['/proc', '/sys', '/dev', '/run']; function unav_settings_file(): string { return getenv('U_NAV_SETTINGS_FILE') ?: UNAV_SETTINGS_FILE; @@ -23,6 +26,7 @@ function unav_settings(): array { 'readOnly' => true, 'debug' => false, 'thumbnails' => true, + 'systemRoot' => false, 'favorites' => [], ]; $file = unav_settings_file(); @@ -37,6 +41,7 @@ function unav_settings(): array { 'readOnly' => filter_var($settings['readOnly'] ?? $defaults['readOnly'], FILTER_VALIDATE_BOOLEAN), 'debug' => filter_var($settings['debug'] ?? $defaults['debug'], FILTER_VALIDATE_BOOLEAN), 'thumbnails' => filter_var($settings['thumbnails'] ?? $defaults['thumbnails'], FILTER_VALIDATE_BOOLEAN), + 'systemRoot' => filter_var($settings['systemRoot'] ?? $defaults['systemRoot'], FILTER_VALIDATE_BOOLEAN), 'favorites' => unav_clean_favorites($settings['favorites'] ?? [], false), ]); } @@ -84,6 +89,7 @@ function unav_settings_write(array $settings): array { 'readOnly' => filter_var($settings['readOnly'] ?? $current['readOnly'], FILTER_VALIDATE_BOOLEAN), 'debug' => filter_var($settings['debug'] ?? $current['debug'], FILTER_VALIDATE_BOOLEAN), 'thumbnails' => filter_var($settings['thumbnails'] ?? $current['thumbnails'], FILTER_VALIDATE_BOOLEAN), + 'systemRoot' => filter_var($settings['systemRoot'] ?? $current['systemRoot'], FILTER_VALIDATE_BOOLEAN), 'favorites' => array_key_exists('favorites', $settings) ? unav_clean_favorites($settings['favorites'], true) : $current['favorites'], @@ -94,14 +100,39 @@ function unav_settings_write(array $settings): array { unav_error(500, 'Could not create settings directory'); } file_put_contents($file, json_encode($next, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX); + unav_roots(true); return $next; } -function unav_roots(): array { - $configured = getenv('U_NAV_ROOTS') ?: UNAV_DEFAULT_ROOT; - $roots = array_values(array_filter(array_map('trim', explode(',', $configured)))); +function unav_default_root(): string { + return getenv('U_NAV_DEFAULT_ROOT') ?: UNAV_DEFAULT_ROOT; +} + +// U_NAV_ROOTS (if set) fixes the roots; otherwise the user shares, plus "/" when the +// "whole system" setting is enabled. +function unav_roots_from_env(): bool { + return (string)getenv('U_NAV_ROOTS') !== ''; +} + +function unav_roots(bool $reset = false): array { + static $cache = null; + if ($reset) { + $cache = null; + return []; + } + if ($cache !== null) { + return $cache; + } + if (unav_roots_from_env()) { + $roots = array_values(array_filter(array_map('trim', explode(',', (string)getenv('U_NAV_ROOTS'))))); + } else { + $roots = [unav_default_root()]; + if (unav_settings()['systemRoot']) { + $roots[] = UNAV_SYSTEM_ROOT; + } + } if (!$roots) { - $roots = [UNAV_DEFAULT_ROOT]; + $roots = [unav_default_root()]; } $resolved = []; @@ -119,9 +150,45 @@ function unav_roots(): array { if (!$resolved) { unav_error(500, 'No usable U-Navigator root found'); } + $cache = $resolved; return $resolved; } +// Joins a directory and a name without producing "//name" when the directory is "/". +function unav_join(string $dir, string $name): string { + return rtrim($dir, '/') . '/' . ltrim($name, '/'); +} + +function unav_is_pseudo_fs(string $path): bool { + foreach (UNAV_PSEUDO_FS as $pseudo) { + if ($path === $pseudo || str_starts_with($path, $pseudo . '/')) { + return true; + } + } + return false; +} + +// Reading files below /proc, /sys, /dev or /run can block forever or return endless data. +function unav_assert_not_pseudo_fs(string $path): void { + if (unav_is_pseudo_fs($path)) { + unav_error(400, 'Files in /proc, /sys, /dev and /run cannot be opened here'); + } +} + +// Roots, top-level system folders (/boot, /etc, /usr, ...) and Unraid mount points +// (/mnt/user, /mnt/disk1, /mnt/cache, ...) must never be moved, deleted or re-permissioned. +function unav_is_protected(string $real): bool { + if (unav_is_root($real)) { + return true; + } + $trimmed = rtrim($real, '/'); + if ($trimmed === '' || dirname($trimmed) === '/') { + return true; + } + $mnt = unav_mnt_dir(); + return $trimmed === $mnt || dirname($trimmed) === $mnt || unav_is_pseudo_fs($trimmed); +} + function unav_read_only(): bool { $env = getenv('U_NAV_READ_ONLY'); if ($env === '1') { @@ -170,8 +237,8 @@ function unav_is_root(string $real): bool { // Destructive operations must never act on a configured root itself (e.g. /mnt/user). function unav_assert_not_root(string $real): void { - if (unav_is_root($real)) { - unav_error(403, 'Root folders cannot be moved, deleted or changed'); + if (unav_is_protected($real)) { + unav_error(403, 'Wurzel- und Systemordner können nicht verschoben, gelöscht oder in den Rechten geändert werden'); } } @@ -206,7 +273,7 @@ function unav_destination_path(?string $input): array { unav_error(404, 'Destination parent not found'); } $root = unav_root_for_real($parentReal); - return ['root' => $root, 'path' => $parentReal . '/' . basename($candidate)]; + return ['root' => $root, 'path' => unav_join($parentReal, basename($candidate))]; } function unav_assert_writable(): void { @@ -243,7 +310,7 @@ function unav_copy_recursive(string $source, string $destination): void { if ($entry === '.' || $entry === '..') { continue; } - unav_copy_recursive($source . '/' . $entry, $destination . '/' . $entry); + unav_copy_recursive(unav_join($source, $entry), unav_join($destination, $entry)); } return; } @@ -267,7 +334,7 @@ function unav_delete_recursive(string $path): void { if ($entry === '.' || $entry === '..') { continue; } - unav_delete_recursive($path . '/' . $entry); + unav_delete_recursive(unav_join($path, $entry)); } if (!rmdir($path)) { unav_error(500, 'Could not remove source directory after move'); @@ -379,7 +446,7 @@ function unav_unique_path(string $path): string { // "Datei (2).txt" continues with "Datei (3).txt" instead of "Datei (2) (2).txt". $stem = preg_replace('/ \(\d+\)$/', '', $stem); for ($i = 2; $i < 10000; $i++) { - $candidate = $dir . '/' . $stem . ' (' . $i . ')' . $ext; + $candidate = rtrim($dir, '/') . '/' . $stem . ' (' . $i . ')' . $ext; if (!file_exists($candidate) && !is_link($candidate)) { return $candidate; } diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/config.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/config.php index ed899ee..14e68ae 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/config.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/config.php @@ -6,6 +6,8 @@ function unav_config_payload(array $settings): array { 'readOnly' => unav_read_only(), 'debug' => $settings['debug'], 'thumbnails' => $settings['thumbnails'], + 'systemRoot' => $settings['systemRoot'], + 'rootsFromEnv' => unav_roots_from_env(), 'favorites' => $settings['favorites'], 'roots' => unav_roots(), 'thumbnailSupport' => function_exists('imagecreatefromstring'), diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/download.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/download.php index 6d2416b..3dba6d9 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/download.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/download.php @@ -4,7 +4,9 @@ require_once __DIR__ . '/common.php'; $paths = unav_download_paths(); $items = []; foreach ($paths as $path) { - $items[] = unav_existing_path($path); + $item = unav_existing_path($path); + unav_assert_not_pseudo_fs($item['path']); + $items[] = $item; } if (count($items) === 1 && is_file($items[0]['path']) && !is_link($items[0]['path'])) { @@ -94,7 +96,7 @@ function unav_zip_add_path(ZipArchive $zip, string $path, string $zipPath): void if ($entry === '.' || $entry === '..') { continue; } - unav_zip_add_path($zip, $real . '/' . $entry, $zipPath . '/' . unav_zip_safe_name($entry)); + unav_zip_add_path($zip, unav_join($real, $entry), $zipPath . '/' . unav_zip_safe_name($entry)); } } diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job.php index 0b572ed..54a089a 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job.php @@ -58,6 +58,11 @@ if ($action === 'compress') { if (in_array($action, ['move', 'delete', 'permissions', 'fixperms'], true)) { unav_assert_not_root($job['source']); } +foreach ($job['sources'] ?? [$job['source']] as $path) { + if (unav_is_pseudo_fs($path)) { + unav_error(400, 'System pseudo filesystems (/proc, /sys, /dev, /run) are not supported for this action'); + } +} switch ($action) { case 'move': diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job_worker.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job_worker.php index f05dd1e..16a0406 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job_worker.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/job_worker.php @@ -107,7 +107,7 @@ function unav_worker_guard(array $job): void { throw new RuntimeException('Destination parent not found'); } unav_worker_assert_inside_root($parentReal); - $destinationPath = $parentReal . '/' . basename($destination); + $destinationPath = unav_join($parentReal, basename($destination)); $exists = file_exists($destinationPath) || is_link($destinationPath); if ($exists && ($job['conflict'] ?? 'fail') !== 'overwrite') { throw new RuntimeException('Destination already exists'); @@ -136,8 +136,8 @@ function unav_worker_guard_source(string $source): string { function unav_worker_assert_not_root(string $path): void { $real = realpath($path); - if ($real !== false && unav_is_root($real)) { - throw new RuntimeException('Root folders cannot be moved, deleted or changed'); + if ($real !== false && unav_is_protected($real)) { + throw new RuntimeException('Wurzel- und Systemordner können nicht verschoben, gelöscht oder in den Rechten geändert werden'); } } @@ -210,6 +210,9 @@ function unav_worker_copy(string $source, string $destination, array &$job, stri if (is_link($source)) { throw new RuntimeException('Copying symlinks is not allowed'); } + if (unav_is_pseudo_fs($source)) { + return; + } if (is_dir($source)) { if (!mkdir($destination, 0777, true) && !is_dir($destination)) { throw new RuntimeException('Could not create destination directory'); @@ -218,7 +221,7 @@ function unav_worker_copy(string $source, string $destination, array &$job, stri if ($entry === '.' || $entry === '..') { continue; } - unav_worker_copy($source . '/' . $entry, $destination . '/' . $entry, $job, $label); + unav_worker_copy(unav_join($source, $entry), unav_join($destination, $entry), $job, $label); } @chmod($destination, fileperms($source) & 07777); @touch($destination, filemtime($source) ?: time()); @@ -282,7 +285,7 @@ function unav_worker_delete(string $path, ?array &$job = null): void { if ($entry === '.' || $entry === '..') { continue; } - unav_worker_delete($path . '/' . $entry, $job); + unav_worker_delete(unav_join($path, $entry), $job); } if (!rmdir($path)) { throw new RuntimeException('Could not delete directory ' . basename($path)); @@ -291,7 +294,7 @@ function unav_worker_delete(string $path, ?array &$job = null): void { } function unav_worker_size_recursive(string $path): array { - if (is_link($path)) { + if (is_link($path) || unav_is_pseudo_fs($path)) { return ['size' => 0, 'files' => 0, 'directories' => 0]; } if (is_file($path)) { @@ -306,7 +309,7 @@ function unav_worker_size_recursive(string $path): array { if ($entry === '.' || $entry === '..') { continue; } - $child = unav_worker_size_recursive($path . '/' . $entry); + $child = unav_worker_size_recursive(unav_join($path, $entry)); $total['size'] += $child['size']; $total['files'] += $child['files']; $total['directories'] += $child['directories']; @@ -358,7 +361,7 @@ function unav_worker_permissions_apply(string $path, ?string $mode, ?string $own if ($entry === '.' || $entry === '..') { continue; } - unav_worker_permissions_apply($path . '/' . $entry, $mode, $owner, $group, true, $job, $count); + unav_worker_permissions_apply(unav_join($path, $entry), $mode, $owner, $group, true, $job, $count); } } @@ -377,7 +380,7 @@ function unav_worker_fixperms(array &$job): void { } foreach (scandir($path) ?: [] as $entry) { if ($entry !== '.' && $entry !== '..') { - $walk($path . '/' . $entry); + $walk(unav_join($path, $entry)); } } }; @@ -413,7 +416,7 @@ function unav_worker_search(array &$job): void { if ($name === '.' || $name === '..') { continue; } - $path = $dir . '/' . $name; + $path = unav_join($dir, $name); $isLink = is_link($path); $isDir = !$isLink && is_dir($path); $job['result']['scanned']++; @@ -430,7 +433,7 @@ function unav_worker_search(array &$job): void { return; } } - if ($isDir) { + if ($isDir && !unav_is_pseudo_fs($path)) { $stack[] = $path; } } @@ -512,7 +515,7 @@ function unav_worker_extract(array &$job): void { throw new RuntimeException('Destination parent not found'); } unav_worker_assert_inside_root($parent); - $destination = $parent . '/' . basename($destination); + $destination = unav_join($parent, basename($destination)); if (file_exists($destination) || is_link($destination)) { throw new RuntimeException('Destination already exists'); } @@ -652,7 +655,7 @@ function unav_worker_compress(array &$job): void { throw new RuntimeException('Destination parent not found'); } unav_worker_assert_inside_root($parent); - $destination = $parent . '/' . basename($destination); + $destination = unav_join($parent, basename($destination)); if (file_exists($destination)) { throw new RuntimeException('Destination already exists'); } @@ -708,14 +711,14 @@ function unav_worker_compress(array &$job): void { } function unav_worker_zip_add(ZipArchive $zip, string $path, string $name, array &$job): void { - if (is_link($path)) { + if (is_link($path) || unav_is_pseudo_fs($path)) { return; } if (is_dir($path)) { $zip->addEmptyDir($name); foreach (scandir($path) ?: [] as $entry) { if ($entry !== '.' && $entry !== '..') { - unav_worker_zip_add($zip, $path . '/' . $entry, $name . '/' . $entry, $job); + unav_worker_zip_add($zip, unav_join($path, $entry), $name . '/' . $entry, $job); } } return; diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/list.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/list.php index 1cecac3..e3a4fc7 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/list.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/list.php @@ -11,17 +11,17 @@ foreach (scandir($resolved['path']) ?: [] as $name) { if ($name === '.' || $name === '..') { continue; } - $full = $resolved['path'] . '/' . $name; + $full = unav_join($resolved['path'], $name); $type = is_link($full) ? 'symlink' : (is_dir($full) ? 'directory' : (is_file($full) ? 'file' : 'other')); - $ownerId = fileowner($full); - $groupId = filegroup($full); - $perms = fileperms($full); + $ownerId = @fileowner($full); + $groupId = @filegroup($full); + $perms = @fileperms($full); $entries[] = [ 'name' => $name, 'path' => $full, 'type' => $type, - 'size' => is_file($full) ? filesize($full) : 0, - 'modifiedAt' => date(DATE_ATOM, filemtime($full) ?: time()), + 'size' => is_file($full) ? (@filesize($full) ?: 0) : 0, + 'modifiedAt' => date(DATE_ATOM, @filemtime($full) ?: (@lstat($full)['mtime'] ?? time())), 'owner' => unav_owner_name($ownerId), 'ownerId' => $ownerId, 'group' => unav_group_name($groupId), diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/mkdir.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/mkdir.php index 0dc1047..4a848b7 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/mkdir.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/mkdir.php @@ -14,7 +14,7 @@ $name = trim((string)($data['name'] ?? '')); if (!unav_valid_name($name)) { unav_error(400, 'Ungültiger Ordnername'); } -$path = $parent['path'] . '/' . $name; +$path = unav_join($parent['path'], $name); if (file_exists($path) || is_link($path)) { unav_error(409, 'Destination already exists'); } diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/preview.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/preview.php index eba0afb..55f64d7 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/preview.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/preview.php @@ -4,6 +4,7 @@ require_once __DIR__ . '/common.php'; const UNAV_TEXT_PREVIEW_MAX_BYTES = 1048576; $resolved = unav_existing_path($_GET['path'] ?? null); +unav_assert_not_pseudo_fs($resolved['path']); if (!is_file($resolved['path'])) { unav_error(400, 'Preview target must be a file'); } diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/thumb.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/thumb.php index ff8e9a7..2b36778 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/thumb.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/thumb.php @@ -7,6 +7,7 @@ const UNAV_THUMB_MAX_BYTES = 52428800; $resolved = unav_existing_path($_GET['path'] ?? null); $path = $resolved['path']; +unav_assert_not_pseudo_fs($path); $size = max(32, min(512, (int)($_GET['size'] ?? 192))); if (!is_file($path) || !preg_match('/\.(jpe?g|png|gif|webp)$/i', $path)) { unav_error(415, 'No thumbnail for this file type'); diff --git a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/upload.php b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/upload.php index 8176498..14219c4 100644 --- a/plugin-root/usr/local/emhttp/plugins/u-navigator/api/upload.php +++ b/plugin-root/usr/local/emhttp/plugins/u-navigator/api/upload.php @@ -105,13 +105,13 @@ function unav_prepare_upload_destination(string $targetPath, string $relativeNam $safeName = unav_upload_safe_relative_path($relativeName); $relativeParent = dirname($safeName); if ($relativeParent !== '.') { - $parentCandidate = $targetPath . '/' . $relativeParent; + $parentCandidate = unav_join($targetPath, $relativeParent); unav_root_for_real($targetPath); if (!is_dir($parentCandidate) && !mkdir($parentCandidate, 0777, true) && !is_dir($parentCandidate)) { unav_error(500, 'Could not create upload directory'); } } - $destination = unav_destination_path($targetPath . '/' . $safeName); + $destination = unav_destination_path(unav_join($targetPath, $safeName)); if (file_exists($destination['path'])) { if (!$overwrite) { unav_error(409, 'Destination already exists'); diff --git a/server/public/app.js b/server/public/app.js index 2cbc1f0..9c969fa 100644 --- a/server/public/app.js +++ b/server/public/app.js @@ -830,7 +830,18 @@ function renderProperties(body) { `; if (entry.type === 'directory') { - ensureDirectorySize(entry); + if (isSystemRootPath(entry.path)) { + if (!state.sizeResults.has(entry.path) && !state.sizeJobs.has(entry.path)) { + const sizeCell = body.querySelectorAll('dd')[3]; + sizeCell.innerHTML = ''; + sizeCell.querySelector('button').addEventListener('click', () => { + ensureDirectorySize(entry); + updatePropertiesWindows(); + }); + } + } else { + ensureDirectorySize(entry); + } } ensureStorageInfo(entry.path); } @@ -1305,6 +1316,13 @@ function renderSettingsPanel() { + `; if (!existing) { @@ -1329,6 +1347,27 @@ function renderSettingsPanel() { panel.querySelector('[data-setting="thumbnails"]').addEventListener('change', (event) => { saveSettings({ thumbnails: event.currentTarget.checked }); }); + panel.querySelector('[data-setting="systemRoot"]').addEventListener('change', async (event) => { + const input = event.currentTarget; + if (input.checked) { + const confirmed = await showConfirmDialog( + 'Ganzes System anzeigen', + 'Der Navigator zeigt dann zusätzlich das komplette Dateisystem ab "/" – mit Root-Rechten.', + 'Ordner direkt unter "/", /boot und die Mountpunkte unter /mnt bleiben vor Löschen, Verschieben und Rechteänderungen geschützt. Alles darunter lässt sich bei aktivem Schreibzugriff ändern – auch Systemdateien. /proc, /sys, /dev und /run werden nur angezeigt.', + { confirmLabel: 'Aktivieren', danger: true } + ); + if (!confirmed) { + input.checked = false; + return; + } + } + await saveSettings({ systemRoot: input.checked }); + if (!input.checked) { + for (const win of state.windows.filter((item) => item.kind === 'explorer' && !rootForPath(item.data.path))) { + loadExplorer(win, state.config.roots[0].path); + } + } + }); settingsButton.classList.add('active'); settingsButton.setAttribute('aria-expanded', 'true'); } @@ -1340,6 +1379,7 @@ async function saveSettings(changes) { body.set('readOnly', readOnly ? '1' : '0'); body.set('debug', debug ? '1' : '0'); body.set('thumbnails', (changes.thumbnails ?? state.config.thumbnails) ? '1' : '0'); + body.set('systemRoot', (changes.systemRoot ?? state.config.systemRoot) ? '1' : '0'); appendCsrf(body); try { state.config = await api(apiUrl('config.php'), { @@ -3051,7 +3091,7 @@ function windowTitle(win) { function parentPath(value) { const parts = String(value || '').split('/').filter(Boolean); - if (parts.length <= 1) return value; + if (parts.length <= 1) return '/'; return `/${parts.slice(0, -1).join('/')}`; } @@ -3101,6 +3141,11 @@ function formatBytes(bytes) { return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`; } +// Outside the user shares (system root) a size scan can wake every disk, so it only runs on request. +function isSystemRootPath(path) { + return normalizePath(rootForPath(path)?.path || '') === '/'; +} + function directorySizeLabel(entry) { const result = state.sizeResults.get(entry.path); if (!result) { diff --git a/tests/php/api_test.php b/tests/php/api_test.php index 3d8ee11..70e62e9 100644 --- a/tests/php/api_test.php +++ b/tests/php/api_test.php @@ -20,7 +20,7 @@ file_put_contents($mnt . '/cache/media/movies/b.mkv', 'y'); file_put_contents($outside . '/secret.txt', 'secret'); $env = [ - 'U_NAV_ROOTS' => $user, + 'U_NAV_DEFAULT_ROOT' => $user, 'U_NAV_READ_ONLY' => '0', 'U_NAV_SETTINGS_FILE' => $base . '/settings.json', 'U_NAV_JOB_DIR' => $base . '/jobs', @@ -179,6 +179,21 @@ check('raw svg is sandboxed', (bool)preg_grep('/^Content-Security-Policy: sandbo $r = call('POST', 'config.php', ['favorites' => json_encode([$share, $outside, $share . '/missing'])]); check('favorites keep only folders inside roots', ($r['json']['favorites'] ?? null) === [$share], json_encode($r['json']['favorites'] ?? null)); +// whole system root (opt-in) +$r = call('GET', 'list.php?path=/'); +check('system root is hidden by default', $r['status'] === 403); +$r = call('POST', 'config.php', ['systemRoot' => '1']); +check('system root can be enabled', ($r['json']['systemRoot'] ?? null) === true && in_array('/', array_column($r['json']['roots'] ?? [], 'path'), true)); +$r = call('GET', 'list.php?path=/'); +check('system root lists /', $r['status'] === 200 && in_array('usr', array_column($r['json']['entries'] ?? [], 'name'), true), $r['status'] . ' ' . substr($r['body'], 0, 300)); +$r = job('size', ['source' => '/dev']); +check('pseudo filesystems are rejected for jobs', $r['status'] === 400); +$r = call('GET', 'download.php?path=' . urlencode('/dev/null')); +check('pseudo filesystem files cannot be downloaded', $r['status'] === 400); +$r = job('copy', ['source' => $share . '/alpha.txt', 'destination' => $share . '/alpha-sys.txt']); +check('shares still work with system root', ($r['json']['status'] ?? '') === 'completed'); +call('POST', 'config.php', ['systemRoot' => '0']); + // cancellation (worker in-process with a pre-set cancel marker) require_once $apiDir . '/job_worker.php'; $big = $share . '/big.bin'; @@ -188,6 +203,14 @@ unav_job_write(['id' => $jobId, 'type' => 'copy', 'status' => 'queued', 'source' touch(unav_job_cancel_path($jobId)); unav_run_job($jobId); $cancelled = unav_job_read($jobId); +putenv('U_NAV_SETTINGS_FILE=' . $base . '/settings-system.json'); +file_put_contents($base . '/settings-system.json', json_encode(['systemRoot' => true])); +unav_roots(true); +check('top-level system folders are protected', unav_is_protected('/usr') && unav_is_protected('/boot') && unav_is_protected('/') && !unav_is_protected('/usr/local')); +check('Unraid mount points are protected', unav_is_protected($mnt . '/disk1') && unav_is_protected($user) && unav_is_protected($mnt) && !unav_is_protected($share)); +check('pseudo filesystems are protected', unav_is_protected('/proc/1') && unav_is_pseudo_fs('/sys/kernel') && !unav_is_pseudo_fs('/system')); +putenv('U_NAV_SETTINGS_FILE=' . $base . '/settings.json'); +unav_roots(true); check('cancelled copy leaves nothing behind', $cancelled['status'] === 'cancelled' && !file_exists($share . '/big-copy.bin') && !glob($share . '/.u-nav-*'), json_encode($cancelled)); echo "\n$count checks, $failures failed\n"; diff --git a/u-navigator.plg b/u-navigator.plg index cc7f911..f5909da 100644 --- a/u-navigator.plg +++ b/u-navigator.plg @@ -1,7 +1,7 @@ - + @@ -18,6 +18,7 @@ &description; ### &version; +- Option „Ganzes System (ab /)“ in den Einstellungen; Systemordner, /boot und Mountpunkte bleiben geschützt. - Folgt dem Unraid-Theme (black/gray dunkel, white/azure hell) statt nur der Systemeinstellung. - Neuer Ordner, Tastaturbedienung, Kopieren/Ausschneiden/Einfügen, Zurück/Vorwärts, anklickbare Pfadleiste. - Filter und rekursive Suche, Favoriten, Vorschaubilder, Nebeneinander-Ansicht, Statusleiste mit freiem Speicher. @@ -28,7 +29,7 @@ https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package; -39df497b7df11629b3e857c896c48bfc +c0dd54cb308a2de3542429300705ecde diff --git a/u-navigator.plg.in b/u-navigator.plg.in index e500cd2..07db4af 100644 --- a/u-navigator.plg.in +++ b/u-navigator.plg.in @@ -18,6 +18,7 @@ &description; ### &version; +- Option „Ganzes System (ab /)“ in den Einstellungen; Systemordner, /boot und Mountpunkte bleiben geschützt. - Folgt dem Unraid-Theme (black/gray dunkel, white/azure hell) statt nur der Systemeinstellung. - Neuer Ordner, Tastaturbedienung, Kopieren/Ausschneiden/Einfügen, Zurück/Vorwärts, anklickbare Pfadleiste. - Filter und rekursive Suche, Favoriten, Vorschaubilder, Nebeneinander-Ansicht, Statusleiste mit freiem Speicher.