Restructure solution into folders and fix persistence issues
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
37987a394a
commit
7c39cb5562
62 files changed
+219
-151
No files matched your search
@@ -0,0 +1,16 @@
|
||||
namespace Flypaper.Web.Components.Pages.Settings;
|
||||
|
||||
public sealed class SettingsModel
|
||||
{
|
||||
public string? TrapPaths { get; set; }
|
||||
|
||||
public string? DripInterval { get; set; }
|
||||
|
||||
public string? MaxConnections { get; set; }
|
||||
|
||||
public string? MaxConnectionsPerIp { get; set; }
|
||||
|
||||
public string? MaxHoldDuration { get; set; }
|
||||
|
||||
public string? ExtraKnownHosts { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
@page "/settings"
|
||||
@using Flypaper.Core
|
||||
@using Flypaper.Core.Settings
|
||||
@using Flypaper.Core.Strategies
|
||||
@using Flypaper.Http
|
||||
@using Flypaper.Storage.Settings
|
||||
@using Flypaper.Web.Auth
|
||||
@using System.Globalization
|
||||
@using Microsoft.Data.Sqlite
|
||||
@using Microsoft.Extensions.Options
|
||||
@inject IOptionsMonitor<FlypaperOptions> Core
|
||||
@inject IOptionsMonitor<DripOptions> Drip
|
||||
@inject IOptionsMonitor<HttpTrapOptions> Http
|
||||
@inject IConfiguration Configuration
|
||||
@inject RuntimeSettingsStore Store
|
||||
@inject AdminAuthenticator Admin
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<PageTitle>Flypaper · Einstellungen</PageTitle>
|
||||
|
||||
<header class="top">
|
||||
<h1>Einstellungen</h1>
|
||||
@if (_hasOverrides)
|
||||
{
|
||||
<span class="badge">Überschrieben</span>
|
||||
}
|
||||
</header>
|
||||
|
||||
@if (Saved == "1")
|
||||
{
|
||||
<div class="banner ok">Gespeichert. Die Änderungen gelten sofort.</div>
|
||||
}
|
||||
else if (Saved == "reset")
|
||||
{
|
||||
<div class="banner ok">Auf Standard zurückgesetzt.</div>
|
||||
}
|
||||
|
||||
<EditForm Model="Model" FormName="settings" OnSubmit="Save" class="card form">
|
||||
<h2>Anpassbar</h2>
|
||||
|
||||
<label for="trap-paths">Fallenpfade <span class="muted">(einer pro Zeile, mit / am Anfang, * am Ende als Präfix)</span></label>
|
||||
<InputTextArea id="trap-paths" @bind-Value="Model!.TrapPaths" rows="10" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.TrapPaths)" />
|
||||
|
||||
<label for="hosts">Zusätzliche bekannte Hosts <span class="muted">(einer pro Zeile, z. B. beispiel.de oder *.beispiel.de)</span></label>
|
||||
<InputTextArea id="hosts" @bind-Value="Model!.ExtraKnownHosts" rows="4" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.ExtraKnownHosts)" />
|
||||
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label for="drip">Tröpfel-Intervall <span class="muted">(hh:mm:ss)</span></label>
|
||||
<InputText id="drip" @bind-Value="Model!.DripInterval" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.DripInterval)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="hold">Maximale Haltedauer <span class="muted">(hh:mm:ss)</span></label>
|
||||
<InputText id="hold" @bind-Value="Model!.MaxHoldDuration" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.MaxHoldDuration)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="max">Max. Verbindungen gesamt</label>
|
||||
<InputText id="max" @bind-Value="Model!.MaxConnections" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.MaxConnections)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="per-ip">Max. Verbindungen pro IP</label>
|
||||
<InputText id="per-ip" @bind-Value="Model!.MaxConnectionsPerIp" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.MaxConnectionsPerIp)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button type="submit">Speichern</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<EditForm Model="_resetModel" FormName="reset" OnSubmit="Reset" class="card form">
|
||||
<h2>Standard</h2>
|
||||
<p class="muted">Löscht alle gespeicherten Änderungen. Danach gelten wieder die Werte aus Umgebungsvariablen und appsettings.</p>
|
||||
<div class="actions">
|
||||
<button type="submit" class="secondary" disabled="@(!_hasOverrides)" onclick="return confirm('Gespeicherte Einstellungen wirklich löschen?')">Auf Standard zurücksetzen</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<section class="card">
|
||||
<h2>Nur per Umgebungsvariable</h2>
|
||||
<p class="muted">Gelten ab Containerstart und lassen sich hier nicht ändern.</p>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th>Datenbank</th><td class="mono">@DatabasePath</td></tr>
|
||||
<tr><th>Bekannte Hosts</th><td class="mono">@Format(Configuration.GetSection("Flypaper:Http:KnownHosts").Get<string[]>())</td></tr>
|
||||
<tr><th>Vertrauenswürdige Proxies</th><td class="mono">@Format(Configuration.GetSection("Flypaper:Http:TrustedProxies").Get<string[]>())</td></tr>
|
||||
<tr><th>Admin-Passwort</th><td>@(Admin.IsConfigured ? "gesetzt" : "nicht gesetzt")</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private readonly object _resetModel = new();
|
||||
private IReadOnlyDictionary<string, string> _errors = new Dictionary<string, string>();
|
||||
private bool _hasOverrides;
|
||||
|
||||
[SupplyParameterFromForm(FormName = "settings")] private SettingsModel? Model { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "saved")] private string? Saved { get; set; }
|
||||
|
||||
private string DatabasePath =>
|
||||
new SqliteConnectionStringBuilder(Configuration.GetConnectionString("Flypaper") ?? "Data Source=flypaper.db").DataSource;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
Model ??= CurrentValues();
|
||||
_hasOverrides = await Store.HasOverridesAsync();
|
||||
}
|
||||
|
||||
private async Task Save()
|
||||
{
|
||||
var result = RuntimeSettingsParser.Parse(new RuntimeSettingsInput(
|
||||
Model!.TrapPaths,
|
||||
Model.DripInterval,
|
||||
Model.MaxConnections,
|
||||
Model.MaxConnectionsPerIp,
|
||||
Model.MaxHoldDuration,
|
||||
Model.ExtraKnownHosts));
|
||||
|
||||
if (result.Settings is null)
|
||||
{
|
||||
_errors = result.Errors;
|
||||
return;
|
||||
}
|
||||
|
||||
await Store.SaveAsync(result.Settings);
|
||||
Navigation.NavigateTo("/settings?saved=1");
|
||||
}
|
||||
|
||||
private async Task Reset()
|
||||
{
|
||||
await Store.ResetAsync();
|
||||
Navigation.NavigateTo("/settings?saved=reset");
|
||||
}
|
||||
|
||||
private SettingsModel CurrentValues()
|
||||
{
|
||||
var core = Core.CurrentValue;
|
||||
var http = Http.CurrentValue;
|
||||
return new SettingsModel
|
||||
{
|
||||
TrapPaths = SettingsList.Join(http.TrapPaths),
|
||||
ExtraKnownHosts = SettingsList.Join(SettingsList.Split(http.ExtraKnownHosts)),
|
||||
DripInterval = Drip.CurrentValue.Interval.ToString("c", CultureInfo.InvariantCulture),
|
||||
MaxHoldDuration = core.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture),
|
||||
MaxConnections = core.MaxConnections.ToString(CultureInfo.InvariantCulture),
|
||||
MaxConnectionsPerIp = core.MaxConnectionsPerIp.ToString(CultureInfo.InvariantCulture)
|
||||
};
|
||||
}
|
||||
|
||||
private static string Format(string[]? values) => values is { Length: > 0 } ? string.Join(", ", values) : "–";
|
||||
}
|
||||
Reference in new issue
Block a user