feat: .env-Varianten und Kopien mit Zusatzendung im Editor
.env, .env.local, .env.production, app.env usw. gelten immer als Text. Zusatzendungen wie .example, .sample, .dist, .bak, .orig, .local werden bei der Typerkennung abgeschnitten (nginx.conf.sample, config.yml.dist). Gleiche Regeln in preview.php und app.js. Paket 2026.11.21.r007. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ca0d5aaae
commit
0117670ede
7 files changed
+46
-5
No files matched your search
+1
-1
@@ -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"
|
||||
|
||||
Binary file not shown.
@@ -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',
|
||||
|
||||
+15
-2
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+3
-2
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE PLUGIN [
|
||||
<!ENTITY name "u-navigator">
|
||||
<!ENTITY author "Michael Roll">
|
||||
<!ENTITY version "2026.11.21.r006">
|
||||
<!ENTITY version "2026.11.21.r007">
|
||||
<!ENTITY package "&name;-&version;.tgz">
|
||||
<!ENTITY pluginURL "https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/u-navigator.plg">
|
||||
<!ENTITY support "https://git.casaderoll.de/michael/Unraid-Navigator">
|
||||
@@ -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 @@
|
||||
|
||||
<FILE Name="/boot/config/plugins/&name;/&package;">
|
||||
<URL>https://git.casaderoll.de/michael/Unraid-Navigator/raw/branch/main/packages/&package;</URL>
|
||||
<MD5>2caa35c0a8a86448b9546255f9c3c5ca</MD5>
|
||||
<MD5>1342db80ec4fe1fce75021d2c3dcd80b</MD5>
|
||||
</FILE>
|
||||
|
||||
<FILE Run="/bin/bash">
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user