diff --git a/build-plugin.sh b/build-plugin.sh index 5833607..87c38b4 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.r006" +VERSION="2026.11.21.r007" PKG_DIR="packages" WORK_DIR=".plugin-build" PKG_NAME="${PLUGIN}-${VERSION}.tgz" diff --git a/packages/u-navigator-2026.11.21.r007.tgz b/packages/u-navigator-2026.11.21.r007.tgz new file mode 100644 index 0000000..8b022e6 Binary files /dev/null and b/packages/u-navigator-2026.11.21.r007.tgz differ 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 3083c75..aa353d6 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 @@ -3,6 +3,12 @@ require_once __DIR__ . '/common.php'; const UNAV_TEXT_PREVIEW_MAX_BYTES = 1048576; +// Copies and variants keep the type of the real file: ".env.local", "nginx.conf.sample", +// "config.yml.dist", "settings.json.bak" … are matched without their trailing suffix. +const UNAV_VARIANT_SUFFIXES = ['example', 'sample', 'dist', 'template', 'default', 'defaults', 'local', 'bak', 'backup', + 'orig', 'old', 'new', 'save', 'saved', 'tmp', 'disabled', 'off', 'prev', 'last', 'production', 'prod', 'staging', + 'development', 'dev', 'test', 'testing', 'ci']; + $resolved = unav_existing_path($_GET['path'] ?? null); unav_assert_not_pseudo_fs($resolved['path']); if (!is_file($resolved['path'])) { @@ -160,6 +166,20 @@ function unav_write_all($handle, string $content): bool { } function unav_preview_type(string $extension, string $name): ?string { + $lower = strtolower($name); + // .env, .env.local, .env.production, app.env … + if (preg_match('/(^\.?env($|\.))|(\.env($|\.))/', $lower)) { + return 'text'; + } + $type = unav_preview_type_exact($extension, $name); + while ($type === null && preg_match('/^(.+)\.([a-z0-9_-]+)$/', $lower, $match) && in_array($match[2], UNAV_VARIANT_SUFFIXES, true)) { + $lower = $match[1]; + $type = unav_preview_type_exact(strtolower(pathinfo($lower, PATHINFO_EXTENSION)), $lower); + } + return $type; +} + +function unav_preview_type_exact(string $extension, string $name): ?string { $base = strtolower($name); $textNames = ['dockerfile', 'containerfile', 'makefile', 'gnumakefile', 'vagrantfile', 'gemfile', 'rakefile', 'procfile', 'jenkinsfile', 'caddyfile', 'brewfile', 'go', 'hosts', 'fstab', 'crontab', 'exports', 'passwd', 'group', 'shells', diff --git a/server/public/app.js b/server/public/app.js index eb142f7..2181ba6 100644 --- a/server/public/app.js +++ b/server/public/app.js @@ -3156,11 +3156,24 @@ function extensionOf(name) { return index >= 0 ? value.slice(index + 1).toLowerCase() : ''; } +// Same rules as unav_preview_type() in api/preview.php. +const variantSuffixes = new Set(['example', 'sample', 'dist', 'template', 'default', 'defaults', 'local', 'bak', 'backup', + 'orig', 'old', 'new', 'save', 'saved', 'tmp', 'disabled', 'off', 'prev', 'last', 'production', 'prod', 'staging', + 'development', 'dev', 'test', 'testing', 'ci']); + function isPreviewable(entry) { if (entry?.type !== 'file') return false; - const name = String(entry.name || entry.path || '').toLowerCase(); + let name = String(entry.name || entry.path || '').toLowerCase(); + // .env, .env.local, .env.production, app.env … + if (/(^\.?env($|\.))|(\.env($|\.))/.test(name)) return true; // Files without an extension (e.g. /boot/config/go) are checked by the server for text content. - return previewFilenames.has(name) || previewExtensions.has(extensionOf(name)) || !name.slice(1).includes('.'); + if (!name.slice(1).includes('.')) return true; + for (;;) { + if (previewFilenames.has(name) || previewExtensions.has(extensionOf(name))) return true; + const suffix = extensionOf(name); + if (!variantSuffixes.has(suffix) || name.length <= suffix.length + 1) return false; + name = name.slice(0, -(suffix.length + 1)); + } } function joinPath(parent, name) { diff --git a/tests/php/api_test.php b/tests/php/api_test.php index f729fa0..74aa39e 100644 --- a/tests/php/api_test.php +++ b/tests/php/api_test.php @@ -197,6 +197,12 @@ check('windows-1252 is written back in its encoding', $r['status'] === 200 && fi $r = call('POST', 'preview.php?path=' . urlencode($share . '/latin.cfg'), ['content' => "€ ok, ✓ nicht\r\n", 'revision' => $r['json']['revision']]); check('characters outside windows-1252 are refused', $r['status'] === 422 && file_get_contents($share . '/latin.cfg') === "Gr\xfc\xdfe=2\r\n"); +foreach (['.env', '.env.local', '.env.production', 'app.env', 'nginx.conf.sample', 'config.yml.dist', 'settings.json.bak'] as $variant) { + file_put_contents($share . '/' . $variant, "KEY=1\n"); + $r = call('GET', 'preview.php?path=' . urlencode($share . '/' . $variant)); + check("$variant is editable", ($r['json']['editable'] ?? false) === true, (string)$r['status']); +} + // whole system root (opt-in) $r = call('GET', 'list.php?path=/'); check('system root is hidden by default', $r['status'] === 403); diff --git a/u-navigator.plg b/u-navigator.plg index 7fd4ea0..d402038 100644 --- a/u-navigator.plg +++ b/u-navigator.plg @@ -1,7 +1,7 @@ - + @@ -18,6 +18,7 @@ &description; ### &version; +- .env-Varianten (.env.local, .env.production …) und Kopien wie nginx.conf.sample, config.yml.dist, *.bak sind bearbeitbar. - Editor: Zeilennummern, Zeile/Spalte, Auto-Einrückung, Tab/Umschalt+Tab, Strg+G, Prüfung von JSON und YAML vor dem Speichern. - Über 200 Textformate bearbeitbar, Dateien ohne Endung (z. B. /boot/config/go) werden erkannt; Windows-1252 und CRLF bleiben erhalten. - Option „Ganzes System (ab /)“ in den Einstellungen; Systemordner, /boot und Mountpunkte bleiben geschützt. @@ -31,7 +32,7 @@ https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package; -2caa35c0a8a86448b9546255f9c3c5ca +1342db80ec4fe1fce75021d2c3dcd80b diff --git a/u-navigator.plg.in b/u-navigator.plg.in index 165b2b2..9299b41 100644 --- a/u-navigator.plg.in +++ b/u-navigator.plg.in @@ -18,6 +18,7 @@ &description; ### &version; +- .env-Varianten (.env.local, .env.production …) und Kopien wie nginx.conf.sample, config.yml.dist, *.bak sind bearbeitbar. - Editor: Zeilennummern, Zeile/Spalte, Auto-Einrückung, Tab/Umschalt+Tab, Strg+G, Prüfung von JSON und YAML vor dem Speichern. - Über 200 Textformate bearbeitbar, Dateien ohne Endung (z. B. /boot/config/go) werden erkannt; Windows-1252 und CRLF bleiben erhalten. - Option „Ganzes System (ab /)“ in den Einstellungen; Systemordner, /boot und Mountpunkte bleiben geschützt.