Add data management, randomized HTML drip and public README
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3671019e60
commit
f5d8ca7484
46 files changed
+1601
-172
No files matched your search
@@ -0,0 +1,11 @@
|
||||
namespace Flypaper.Web.Components.Pages.Settings;
|
||||
|
||||
public sealed class DeletePrivateModel
|
||||
{
|
||||
public bool Confirmed { get; set; }
|
||||
}
|
||||
|
||||
public sealed class DeleteAllModel
|
||||
{
|
||||
public string? Confirmation { get; set; }
|
||||
}
|
||||
@@ -4,8 +4,6 @@ public sealed class SettingsModel
|
||||
{
|
||||
public string? TrapPaths { get; set; }
|
||||
|
||||
public string? DripInterval { get; set; }
|
||||
|
||||
public string? MaxConnections { get; set; }
|
||||
|
||||
public string? MaxConnectionsPerIp { get; set; }
|
||||
@@ -13,4 +11,8 @@ public sealed class SettingsModel
|
||||
public string? MaxHoldDuration { get; set; }
|
||||
|
||||
public string? ExtraKnownHosts { get; set; }
|
||||
|
||||
public string? RetentionDays { get; set; }
|
||||
|
||||
public bool IgnorePrivateNetworks { get; set; }
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
@page "/settings"
|
||||
@using Flypaper.Core
|
||||
@using Flypaper.Core.Settings
|
||||
@using Flypaper.Core.Strategies
|
||||
@using Flypaper.Http
|
||||
@using Flypaper.Storage.Maintenance
|
||||
@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 IOptionsMonitor<RetentionOptions> Retention
|
||||
@inject IConfiguration Configuration
|
||||
@inject RuntimeSettingsStore Store
|
||||
@inject AdminAuthenticator Admin
|
||||
@@ -35,7 +35,7 @@ else if (Saved == "reset")
|
||||
<div class="banner ok">Auf Standard zurückgesetzt.</div>
|
||||
}
|
||||
|
||||
<EditForm Model="Model" FormName="settings" OnSubmit="Save" class="card form">
|
||||
<EditForm Model="Model" FormName="settings" OnSubmit="Save" action="/settings" 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>
|
||||
@@ -47,11 +47,6 @@ else if (Saved == "reset")
|
||||
<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" />
|
||||
@@ -67,14 +62,24 @@ else if (Saved == "reset")
|
||||
<InputText id="per-ip" @bind-Value="Model!.MaxConnectionsPerIp" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.MaxConnectionsPerIp)" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="retention">Fänge aufbewahren <span class="muted">(Tage, 0 = unbegrenzt)</span></label>
|
||||
<InputText id="retention" @bind-Value="Model!.RetentionDays" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.RetentionDays)" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="check">
|
||||
<InputCheckbox @bind-Value="Model!.IgnorePrivateNetworks" />
|
||||
Fänge aus privaten Netzen nicht speichern <span class="muted">(die Falle greift trotzdem)</span>
|
||||
</label>
|
||||
|
||||
<div class="actions">
|
||||
<button type="submit">Speichern</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<EditForm Model="_resetModel" FormName="reset" OnSubmit="Reset" class="card form">
|
||||
<EditForm Model="_resetModel" FormName="reset" OnSubmit="Reset" action="/settings" 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">
|
||||
@@ -82,6 +87,8 @@ else if (Saved == "reset")
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<TrapDataSection />
|
||||
|
||||
<section class="card">
|
||||
<h2>Nur per Umgebungsvariable</h2>
|
||||
<p class="muted">Gelten ab Containerstart und lassen sich hier nicht ändern.</p>
|
||||
@@ -117,11 +124,12 @@ else if (Saved == "reset")
|
||||
{
|
||||
var result = RuntimeSettingsParser.Parse(new RuntimeSettingsInput(
|
||||
Model!.TrapPaths,
|
||||
Model.DripInterval,
|
||||
Model.MaxConnections,
|
||||
Model.MaxConnectionsPerIp,
|
||||
Model.MaxHoldDuration,
|
||||
Model.ExtraKnownHosts));
|
||||
Model.ExtraKnownHosts,
|
||||
Model.RetentionDays,
|
||||
Model.IgnorePrivateNetworks));
|
||||
|
||||
if (result.Settings is null)
|
||||
{
|
||||
@@ -147,10 +155,11 @@ else if (Saved == "reset")
|
||||
{
|
||||
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)
|
||||
MaxConnectionsPerIp = core.MaxConnectionsPerIp.ToString(CultureInfo.InvariantCulture),
|
||||
RetentionDays = Retention.CurrentValue.Days.ToString(CultureInfo.InvariantCulture),
|
||||
IgnorePrivateNetworks = core.IgnorePrivateNetworks
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
@using Flypaper.Storage.Maintenance
|
||||
@inject TrapDataMaintenance Maintenance
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<section class="card form">
|
||||
<h2>Daten</h2>
|
||||
|
||||
@if (Deleted is { } deleted)
|
||||
{
|
||||
<div class="banner ok">@deleted.ToString("N0") @(deleted == 1 ? "Fang" : "Fänge") gelöscht.</div>
|
||||
}
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr><th>Fänge</th><td>@_stats?.Count.ToString("N0")</td></tr>
|
||||
<tr><th>Ältester Fang</th><td>@(_stats?.Oldest?.ToLocalTime().ToString("dd.MM.yyyy HH:mm") ?? "–")</td></tr>
|
||||
<tr><th>Größe der Datenbank</th><td>@Formatting.Bytes(_stats?.DatabaseBytes)</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="muted">Einstellungen und GeoIP-Dateien bleiben beim Löschen erhalten.</p>
|
||||
|
||||
<EditForm Model="DeletePrivate" FormName="delete-private" OnSubmit="DeletePrivateAsync" action="/settings" class="danger-zone">
|
||||
<h3>Fänge aus privaten Netzen löschen</h3>
|
||||
<p class="muted">Loopback, 10/8, 172.16/12, 192.168/16, Link-Local und ULA, zum Beispiel lokale Testaufrufe.</p>
|
||||
<label class="check">
|
||||
<InputCheckbox @bind-Value="DeletePrivate!.Confirmed" />
|
||||
Ich bin sicher
|
||||
</label>
|
||||
<FieldError Errors="_errors" Field="@nameof(DeletePrivateModel.Confirmed)" />
|
||||
<div class="actions">
|
||||
<button type="submit" class="secondary">Private Fänge löschen</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
|
||||
<EditForm Model="DeleteAll" FormName="delete-all" OnSubmit="DeleteAllAsync" action="/settings" class="danger-zone">
|
||||
<h3>Alle Fänge löschen</h3>
|
||||
<label for="delete-all-confirmation">Zum Bestätigen <strong>LÖSCHEN</strong> eingeben</label>
|
||||
<InputText id="delete-all-confirmation" @bind-Value="DeleteAll!.Confirmation" autocomplete="off" />
|
||||
<FieldError Errors="_errors" Field="@nameof(DeleteAllModel.Confirmation)" />
|
||||
<div class="actions">
|
||||
<button type="submit" class="danger">Alle Fänge löschen</button>
|
||||
</div>
|
||||
</EditForm>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private const string ConfirmationWord = "LÖSCHEN";
|
||||
|
||||
private TrapDataStats? _stats;
|
||||
private Dictionary<string, string> _errors = [];
|
||||
|
||||
[SupplyParameterFromForm(FormName = "delete-private")] private DeletePrivateModel? DeletePrivate { get; set; }
|
||||
|
||||
[SupplyParameterFromForm(FormName = "delete-all")] private DeleteAllModel? DeleteAll { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "deleted")] private int? Deleted { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
DeletePrivate ??= new DeletePrivateModel();
|
||||
DeleteAll ??= new DeleteAllModel();
|
||||
_stats = await Maintenance.GetStatsAsync();
|
||||
}
|
||||
|
||||
private async Task DeletePrivateAsync()
|
||||
{
|
||||
if (!DeletePrivate!.Confirmed)
|
||||
{
|
||||
_errors[nameof(DeletePrivateModel.Confirmed)] = "Bitte bestätigen.";
|
||||
return;
|
||||
}
|
||||
|
||||
await FinishAsync(await Maintenance.DeletePrivateAsync());
|
||||
}
|
||||
|
||||
private async Task DeleteAllAsync()
|
||||
{
|
||||
if (DeleteAll!.Confirmation?.Trim() != ConfirmationWord)
|
||||
{
|
||||
_errors[nameof(DeleteAllModel.Confirmation)] = $"Bitte genau {ConfirmationWord} eingeben.";
|
||||
return;
|
||||
}
|
||||
|
||||
await FinishAsync(await Maintenance.DeleteAllAsync());
|
||||
}
|
||||
|
||||
private async Task FinishAsync(int deleted)
|
||||
{
|
||||
if (deleted > 0)
|
||||
{
|
||||
await Maintenance.VacuumAsync();
|
||||
}
|
||||
|
||||
Navigation.NavigateTo($"/settings?deleted={deleted}");
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,14 @@ public static class Formatting
|
||||
? string.Concat(countryCode.ToUpperInvariant().Select(c => char.ConvertFromUtf32(0x1F1E6 + c - 'A')))
|
||||
: "";
|
||||
|
||||
public static string Bytes(long? bytes) => bytes switch
|
||||
{
|
||||
null => "–",
|
||||
>= 1024 * 1024 * 1024 => $"{bytes / (1024d * 1024 * 1024):0.0} GB",
|
||||
>= 1024 * 1024 => $"{bytes / (1024d * 1024):0.0} MB",
|
||||
>= 1024 => $"{bytes / 1024d:0} KB",
|
||||
_ => $"{bytes} B"
|
||||
};
|
||||
|
||||
public static string? Provider(long? asn, string? provider) => asn is null ? provider : $"AS{asn} {provider}".TrimEnd();
|
||||
}
|
||||
Reference in new issue
Block a user