Piattaforme: istanza unica dopo lo spostamento dei dati, avvio sicuro del contenitore, rilascio con prove e immagine, accesso senza reindirizzamenti esterni (pkg-1, pkg-2, pkg-3, pkg-4, pkg-5, pkg-6, websec-2, web-8, websec-3)
Registro di casa 192.168.30.23:3000 (HTTP) nel modello Unraid, in compose e nel rilascio con buildx; profilo seccomp fuori da /dati. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
36 files changed
+1683
-152
No files matched your search
@@ -1,20 +1,34 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Febe.Desktop.Core;
|
||||
|
||||
/// <summary>
|
||||
/// «Avvia Febe all'accensione del computer» (spec §12): the value <c>Febe</c> under
|
||||
/// <c>HKCU\Software\Microsoft\Windows\CurrentVersion\Run</c>, per user, no administrator rights. Febe then starts with
|
||||
/// <c>--nascosto</c>: only the icon in the notification area, the window stays closed.
|
||||
/// «Avvia Febe all'accensione del computer» (spec §12): a value under <c>HKCU\Software\Microsoft\Windows\CurrentVersion\Run</c>,
|
||||
/// per user, no administrator rights. Febe then starts with <c>--nascosto</c>: only the icon in the notification area,
|
||||
/// the window stays closed. Each Febe has its own value: <c>Febe</c> for the usual one (Data folder recorded or
|
||||
/// default), <c>Febe-…</c> with <c>--dati</c> for one started on a Data folder of its own (a second account), so the
|
||||
/// switch of one never starts, shows or removes the other.
|
||||
/// </summary>
|
||||
public static class Autostart
|
||||
{
|
||||
/// <summary>The registry key, under HKEY_CURRENT_USER.</summary>
|
||||
public const string RunKey = @"Software\Microsoft\Windows\CurrentVersion\Run";
|
||||
|
||||
/// <summary>The name of the value.</summary>
|
||||
/// <summary>The name of the value of the usual Febe.</summary>
|
||||
public const string ValueName = "Febe";
|
||||
|
||||
/// <summary>The command written in the value: the quoted executable and <c>--nascosto</c>.</summary>
|
||||
public static string Command(string executable)
|
||||
/// <summary>
|
||||
/// The name of the value: <see cref="ValueName"/> without a Data folder of its own, otherwise «Febe-» and the
|
||||
/// identity of the folder (the same as the single-instance guard, so the same folder always has the same value).
|
||||
/// </summary>
|
||||
public static string ValueNameFor(string? fixedDataFolder) =>
|
||||
fixedDataFolder is null ? ValueName : InstanceIdentity.For(fixedDataFolder);
|
||||
|
||||
/// <summary>
|
||||
/// The command written in the value: the quoted executable, <c>--nascosto</c> and, for a Febe started with
|
||||
/// <c>--dati</c>, the same Data folder.
|
||||
/// </summary>
|
||||
public static string Command(string executable, string? fixedDataFolder = null)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(executable);
|
||||
if (executable.Contains('"', StringComparison.Ordinal))
|
||||
@@ -22,43 +36,150 @@ public static class Autostart
|
||||
throw new ArgumentException("Percorso dell'eseguibile non valido.", nameof(executable));
|
||||
}
|
||||
|
||||
return $"\"{executable}\" --nascosto";
|
||||
if (fixedDataFolder is null)
|
||||
{
|
||||
return $"\"{executable}\" --nascosto";
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(fixedDataFolder) || fixedDataFolder.Contains('"', StringComparison.Ordinal))
|
||||
{
|
||||
throw new ArgumentException("Percorso della cartella dei dati non valido.", nameof(fixedDataFolder));
|
||||
}
|
||||
|
||||
return $"\"{executable}\" --nascosto --dati {Quote(fixedDataFolder)}";
|
||||
}
|
||||
|
||||
/// <summary>True when <paramref name="value"/> starts this executable (a value left by another copy of Febe is not ours).</summary>
|
||||
public static bool PointsTo(string? value, string executable)
|
||||
/// <summary>
|
||||
/// True when <paramref name="value"/> starts this executable on this Data folder: <paramref name="fixedDataFolder"/>
|
||||
/// for a Febe started with <c>--dati</c>, none for the usual one. A value left by another copy of Febe, or written
|
||||
/// for another Data folder, is not ours.
|
||||
/// </summary>
|
||||
public static bool PointsTo(string? value, string executable, string? fixedDataFolder = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value) || string.IsNullOrWhiteSpace(executable))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var text = value.Trim();
|
||||
string target;
|
||||
if (text.StartsWith('"'))
|
||||
var arguments = Split(value.Trim());
|
||||
if (arguments is not [var target, .. var rest] || !SamePath(target, executable))
|
||||
{
|
||||
var end = text.IndexOf('"', 1);
|
||||
if (end < 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
string? dataFolder = null;
|
||||
for (var i = 0; i < rest.Count; i++)
|
||||
{
|
||||
if (string.Equals(rest[i], "--dati", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
if (i + 1 >= rest.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dataFolder = rest[++i];
|
||||
}
|
||||
}
|
||||
|
||||
return fixedDataFolder is null ? dataFolder is null : dataFolder is not null && SamePath(dataFolder, fixedDataFolder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The words of a command line as Windows programs read them: blanks separate, quotes group, backslashes are plain
|
||||
/// except before a quote (2n backslashes and a quote: n backslashes and a quote that groups; 2n+1: n and a literal
|
||||
/// quote). Null for an unfinished quote.
|
||||
/// </summary>
|
||||
internal static List<string>? Split(string commandLine)
|
||||
{
|
||||
var words = new List<string>();
|
||||
var word = new StringBuilder();
|
||||
var inWord = false;
|
||||
var quoted = false;
|
||||
for (var i = 0; i < commandLine.Length; i++)
|
||||
{
|
||||
var c = commandLine[i];
|
||||
if (c == '\\')
|
||||
{
|
||||
var start = i;
|
||||
while (i < commandLine.Length && commandLine[i] == '\\')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
var count = i - start;
|
||||
if (i < commandLine.Length && commandLine[i] == '"')
|
||||
{
|
||||
word.Append('\\', count / 2);
|
||||
if (count % 2 == 1)
|
||||
{
|
||||
word.Append('"');
|
||||
}
|
||||
else
|
||||
{
|
||||
quoted = !quoted;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
word.Append('\\', count);
|
||||
i--;
|
||||
}
|
||||
|
||||
inWord = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
target = text[1..end];
|
||||
}
|
||||
else
|
||||
{
|
||||
var space = text.IndexOf(' ', StringComparison.Ordinal);
|
||||
target = space < 0 ? text : text[..space];
|
||||
if (c == '"')
|
||||
{
|
||||
quoted = !quoted;
|
||||
inWord = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!quoted && char.IsWhiteSpace(c))
|
||||
{
|
||||
if (inWord)
|
||||
{
|
||||
words.Add(word.ToString());
|
||||
word.Clear();
|
||||
inWord = false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
word.Append(c);
|
||||
inWord = true;
|
||||
}
|
||||
|
||||
return string.Equals(Normalize(target), Normalize(executable), StringComparison.OrdinalIgnoreCase);
|
||||
if (quoted)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (inWord)
|
||||
{
|
||||
words.Add(word.ToString());
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
/// <summary>A quoted argument: backslashes before the closing quote are doubled (<c>"D:\\"</c> reads back as <c>D:\</c>).</summary>
|
||||
private static string Quote(string argument)
|
||||
{
|
||||
var trailing = argument.Length - argument.TrimEnd('\\').Length;
|
||||
return "\"" + argument + new string('\\', trailing) + "\"";
|
||||
}
|
||||
|
||||
private static bool SamePath(string a, string b) =>
|
||||
string.Equals(Normalize(a), Normalize(b), StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static string Normalize(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Path.GetFullPath(path);
|
||||
return Path.TrimEndingDirectorySeparator(Path.GetFullPath(path));
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or NotSupportedException or PathTooLongException)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user