Remove trap paths and known hosts: catch everything on the trap port
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b9f2b0443c
commit
9a56fc5b48
31 files changed
+335
-462
No files matched your search
@@ -3,21 +3,17 @@ using System.Globalization;
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public sealed record RuntimeSettings(
|
||||
IReadOnlyList<string> TrapPaths,
|
||||
int MaxConnections,
|
||||
int MaxConnectionsPerIp,
|
||||
TimeSpan MaxHoldDuration,
|
||||
IReadOnlyList<string> ExtraKnownHosts,
|
||||
int RetentionDays,
|
||||
bool IgnorePrivateNetworks)
|
||||
{
|
||||
public IReadOnlyDictionary<string, string> ToConfiguration() => new Dictionary<string, string>
|
||||
{
|
||||
[SettingKeys.TrapPaths] = SettingsList.Join(TrapPaths),
|
||||
[SettingKeys.MaxConnections] = MaxConnections.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.MaxConnectionsPerIp] = MaxConnectionsPerIp.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.MaxHoldDuration] = MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture),
|
||||
[SettingKeys.ExtraKnownHosts] = SettingsList.Join(ExtraKnownHosts),
|
||||
[SettingKeys.RetentionDays] = RetentionDays.ToString(CultureInfo.InvariantCulture),
|
||||
[SettingKeys.IgnorePrivateNetworks] = IgnorePrivateNetworks ? "true" : "false"
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public sealed record RuntimeSettingsInput(
|
||||
string? TrapPaths,
|
||||
string? MaxConnections,
|
||||
string? MaxConnectionsPerIp,
|
||||
string? MaxHoldDuration,
|
||||
string? ExtraKnownHosts,
|
||||
string? RetentionDays,
|
||||
bool IgnorePrivateNetworks);
|
||||
@@ -1,28 +1,19 @@
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public static partial class RuntimeSettingsParser
|
||||
public static class RuntimeSettingsParser
|
||||
{
|
||||
private const int MaxListEntries = 500;
|
||||
private const int MaxPathLength = 256;
|
||||
private const int MaxHostLength = 253;
|
||||
private const int MaxLimit = 100_000;
|
||||
private const int MaxRetentionDays = 3650;
|
||||
|
||||
private static readonly TimeSpan MinHold = TimeSpan.FromSeconds(1);
|
||||
private static readonly TimeSpan MaxHold = TimeSpan.FromDays(7);
|
||||
|
||||
[GeneratedRegex(@"^(\*\.)?[A-Za-z0-9]([A-Za-z0-9.\-]*[A-Za-z0-9])?$")]
|
||||
private static partial Regex HostPattern();
|
||||
|
||||
public static RuntimeSettingsParseResult Parse(RuntimeSettingsInput input)
|
||||
{
|
||||
var errors = new Dictionary<string, string>();
|
||||
|
||||
var paths = ParseList(input.TrapPaths, nameof(input.TrapPaths), ValidatePath, errors);
|
||||
var hosts = ParseList(input.ExtraKnownHosts, nameof(input.ExtraKnownHosts), ValidateHost, errors);
|
||||
var hold = ParseTimeSpan(input.MaxHoldDuration, nameof(input.MaxHoldDuration), MinHold, MaxHold, errors);
|
||||
var maxConnections = ParseInt(input.MaxConnections, nameof(input.MaxConnections), 1, MaxLimit, errors);
|
||||
var perIp = ParseInt(input.MaxConnectionsPerIp, nameof(input.MaxConnectionsPerIp), 1, MaxLimit, errors);
|
||||
@@ -40,80 +31,14 @@ public static partial class RuntimeSettingsParser
|
||||
}
|
||||
|
||||
var settings = new RuntimeSettings(
|
||||
paths!,
|
||||
maxConnections!.Value,
|
||||
perIp!.Value,
|
||||
hold!.Value,
|
||||
hosts!,
|
||||
retention!.Value,
|
||||
input.IgnorePrivateNetworks);
|
||||
return new RuntimeSettingsParseResult(settings, errors);
|
||||
}
|
||||
|
||||
private static string[]? ParseList(
|
||||
string? raw,
|
||||
string field,
|
||||
Func<string, string?> validate,
|
||||
Dictionary<string, string> errors)
|
||||
{
|
||||
var lines = (raw ?? string.Empty)
|
||||
.Split(['\r', '\n'], StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (lines.Length > MaxListEntries)
|
||||
{
|
||||
errors[field] = $"Höchstens {MaxListEntries} Einträge.";
|
||||
return null;
|
||||
}
|
||||
|
||||
var problems = new List<string>();
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (validate(lines[i]) is { } problem)
|
||||
{
|
||||
problems.Add($"„{lines[i]}“: {problem}");
|
||||
}
|
||||
}
|
||||
|
||||
if (problems.Count > 0)
|
||||
{
|
||||
errors[field] = string.Join(" ", problems.Take(3)) + (problems.Count > 3 ? $" (+{problems.Count - 3} weitere)" : "");
|
||||
return null;
|
||||
}
|
||||
|
||||
return lines.Distinct(StringComparer.Ordinal).ToArray();
|
||||
}
|
||||
|
||||
private static string? ValidatePath(string path)
|
||||
{
|
||||
if (path[0] != '/')
|
||||
{
|
||||
return "muss mit / beginnen.";
|
||||
}
|
||||
|
||||
if (path.Length > MaxPathLength)
|
||||
{
|
||||
return $"höchstens {MaxPathLength} Zeichen.";
|
||||
}
|
||||
|
||||
if (path.Any(char.IsWhiteSpace))
|
||||
{
|
||||
return "darf keine Leerzeichen enthalten.";
|
||||
}
|
||||
|
||||
var star = path.IndexOf('*');
|
||||
return star >= 0 && star != path.Length - 1 ? "* ist nur am Ende erlaubt." : null;
|
||||
}
|
||||
|
||||
private static string? ValidateHost(string host)
|
||||
{
|
||||
if (host.Length > MaxHostLength)
|
||||
{
|
||||
return $"höchstens {MaxHostLength} Zeichen.";
|
||||
}
|
||||
|
||||
return HostPattern().IsMatch(host) ? null : "ungültiger Hostname (nur Name, ohne Schema, Port oder Pfad; Wildcard als *.beispiel.de).";
|
||||
}
|
||||
|
||||
private static TimeSpan? ParseTimeSpan(
|
||||
string? raw,
|
||||
string field,
|
||||
|
||||
@@ -5,8 +5,6 @@ public static class SettingKeys
|
||||
public const string MaxConnections = "Flypaper:MaxConnections";
|
||||
public const string MaxConnectionsPerIp = "Flypaper:MaxConnectionsPerIp";
|
||||
public const string MaxHoldDuration = "Flypaper:MaxHoldDuration";
|
||||
public const string TrapPaths = "Flypaper:Http:TrapPathsOverride";
|
||||
public const string ExtraKnownHosts = "Flypaper:Http:ExtraKnownHosts";
|
||||
public const string IgnorePrivateNetworks = "Flypaper:IgnorePrivateNetworks";
|
||||
public const string RetentionDays = "Flypaper:Retention:Days";
|
||||
|
||||
@@ -15,8 +13,6 @@ public static class SettingKeys
|
||||
MaxConnections,
|
||||
MaxConnectionsPerIp,
|
||||
MaxHoldDuration,
|
||||
TrapPaths,
|
||||
ExtraKnownHosts,
|
||||
IgnorePrivateNetworks,
|
||||
RetentionDays
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
namespace Flypaper.Core.Settings;
|
||||
|
||||
public static class SettingsList
|
||||
{
|
||||
private static readonly char[] Separators = ['\r', '\n'];
|
||||
|
||||
public static string[] Split(string? value) =>
|
||||
value is null
|
||||
? []
|
||||
: value.Split(Separators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
public static string Join(IEnumerable<string> items) => string.Join('\n', items);
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using Flypaper.Core.Settings;
|
||||
using Flypaper.Http.Matching;
|
||||
using Flypaper.Http.Middleware;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Http;
|
||||
@@ -16,20 +14,18 @@ public static class FlypaperHttpExtensions
|
||||
{
|
||||
private static readonly string[] DefaultTrustedProxies = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fc00::/7"];
|
||||
|
||||
private static readonly string[] RemovedSettings =
|
||||
[
|
||||
"Flypaper:Http:KnownHosts",
|
||||
"Flypaper:Http:TrapPaths",
|
||||
"Flypaper:Http:ExtraKnownHosts",
|
||||
"Flypaper:Http:TrapPathsOverride"
|
||||
];
|
||||
|
||||
public static IServiceCollection AddFlypaperHttp(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.Configure<HttpTrapOptions>(configuration.GetSection(HttpTrapOptions.SectionName));
|
||||
services.Configure<PortOptions>(configuration.GetSection(PortOptions.SectionName));
|
||||
services.PostConfigure<HttpTrapOptions>(options =>
|
||||
{
|
||||
if (options.TrapPathsOverride is not null)
|
||||
{
|
||||
options.TrapPaths = SettingsList.Split(options.TrapPathsOverride);
|
||||
}
|
||||
|
||||
options.KnownHosts = options.KnownHosts.Concat(SettingsList.Split(options.ExtraKnownHosts)).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
});
|
||||
services.TryAddSingleton<TrapMatcher>();
|
||||
|
||||
services.AddOptions<ForwardedHeadersOptions>()
|
||||
.Configure<IOptions<HttpTrapOptions>>((forwarded, trap) =>
|
||||
@@ -55,6 +51,16 @@ public static class FlypaperHttpExtensions
|
||||
return app;
|
||||
}
|
||||
|
||||
public static void WarnAboutRemovedSettings(IConfiguration configuration, ILogger logger)
|
||||
{
|
||||
foreach (var key in RemovedSettings.Where(key => configuration.GetSection(key).Exists()))
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Setting {Key} is set but no longer has any effect: every request on the trap port is caught",
|
||||
key.Replace(":", "__", StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
|
||||
private static int HostBits(string address) =>
|
||||
IPAddress.Parse(address).AddressFamily == AddressFamily.InterNetworkV6 ? 128 : 32;
|
||||
}
|
||||
@@ -6,13 +6,5 @@ public sealed class HttpTrapOptions
|
||||
|
||||
public const string HealthPath = "/health";
|
||||
|
||||
public string[] KnownHosts { get; set; } = [];
|
||||
|
||||
public string[] TrapPaths { get; set; } = [];
|
||||
|
||||
public string[] TrustedProxies { get; set; } = [];
|
||||
|
||||
public string? TrapPathsOverride { get; set; }
|
||||
|
||||
public string? ExtraKnownHosts { get; set; }
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Flypaper.Http.Matching;
|
||||
|
||||
public enum TrapMatch
|
||||
{
|
||||
None,
|
||||
UnknownHost,
|
||||
TrapPath
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Http.Matching;
|
||||
|
||||
public sealed class TrapMatcher : IDisposable
|
||||
{
|
||||
private readonly IDisposable? _subscription;
|
||||
private volatile Snapshot _snapshot;
|
||||
|
||||
public TrapMatcher(IOptionsMonitor<HttpTrapOptions> options)
|
||||
{
|
||||
_snapshot = new Snapshot(options.CurrentValue);
|
||||
_subscription = options.OnChange(updated => _snapshot = new Snapshot(updated));
|
||||
}
|
||||
|
||||
public TrapMatch Match(string? host, string? path)
|
||||
{
|
||||
var snapshot = _snapshot;
|
||||
if (!snapshot.IsKnownHost(host))
|
||||
{
|
||||
return TrapMatch.UnknownHost;
|
||||
}
|
||||
|
||||
return snapshot.IsTrapPath(path ?? "/") ? TrapMatch.TrapPath : TrapMatch.None;
|
||||
}
|
||||
|
||||
public void Dispose() => _subscription?.Dispose();
|
||||
|
||||
private sealed class Snapshot
|
||||
{
|
||||
private readonly HashSet<string> _hosts = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<string> _hostSuffixes = [];
|
||||
private readonly HashSet<string> _paths = new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly List<string> _pathPrefixes = [];
|
||||
|
||||
public Snapshot(HttpTrapOptions options)
|
||||
{
|
||||
foreach (var host in options.KnownHosts.Where(h => !string.IsNullOrWhiteSpace(h)))
|
||||
{
|
||||
if (host.StartsWith("*.", StringComparison.Ordinal))
|
||||
{
|
||||
_hostSuffixes.Add(host[1..]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_hosts.Add(host);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var path in options.TrapPaths.Where(p => !string.IsNullOrWhiteSpace(p)))
|
||||
{
|
||||
if (path.EndsWith('*'))
|
||||
{
|
||||
_pathPrefixes.Add(path[..^1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_paths.Add(TrimTrailingSlash(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsKnownHost(string? host) =>
|
||||
!string.IsNullOrEmpty(host)
|
||||
&& (_hosts.Contains(host)
|
||||
|| _hostSuffixes.Any(suffix => host.EndsWith(suffix, StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
public bool IsTrapPath(string path) =>
|
||||
_paths.Contains(TrimTrailingSlash(path))
|
||||
|| _pathPrefixes.Any(prefix => path.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
private static string TrimTrailingSlash(string path) => path.Length > 1 ? path.TrimEnd('/') : path;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using Flypaper.Core.Abstractions;
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Core.Networking;
|
||||
using Flypaper.Core.Runtime;
|
||||
using Flypaper.Http.Matching;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
||||
@@ -13,7 +12,6 @@ namespace Flypaper.Http.Middleware;
|
||||
|
||||
internal sealed class FlypaperMiddleware(
|
||||
RequestDelegate next,
|
||||
TrapMatcher matcher,
|
||||
TrapRunner runner,
|
||||
IOptions<PortOptions> ports,
|
||||
TimeProvider timeProvider)
|
||||
@@ -27,11 +25,6 @@ internal sealed class FlypaperMiddleware(
|
||||
}
|
||||
|
||||
var request = context.Request;
|
||||
if (matcher.Match(request.Host.Host, request.Path.Value) == TrapMatch.None)
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
var session = new TrapSession(
|
||||
Guid.NewGuid(),
|
||||
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Flypaper.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Flypaper.Storage.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlypaperDbContext))]
|
||||
[Migration("20261115175305_RemoveTrapPathSettings")]
|
||||
partial class RemoveTrapPathSettings
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "10.0.15");
|
||||
|
||||
modelBuilder.Entity("Flypaper.Storage.Entities.McpTokenEntity", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime?>("LastUsedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("McpTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Flypaper.Storage.Entities.SettingEntity", b =>
|
||||
{
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Key");
|
||||
|
||||
b.ToTable("Settings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Flypaper.Storage.Entities.TrapEventEntity", b =>
|
||||
{
|
||||
b.Property<long>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long?>("Asn")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("BytesSent")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("City")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("ClientInfo")
|
||||
.HasMaxLength(2048)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Country")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("CountryCode")
|
||||
.HasMaxLength(2)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<long>("DurationMs")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("EndedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Outcome")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Protocol")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Provider")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("RemoteIp")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<Guid>("SessionId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("StartedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Strategy")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Target")
|
||||
.HasMaxLength(2048)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("Asn");
|
||||
|
||||
b.HasIndex("CountryCode");
|
||||
|
||||
b.HasIndex("RemoteIp");
|
||||
|
||||
b.HasIndex("StartedAt");
|
||||
|
||||
b.ToTable("TrapEvents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Flypaper.Storage.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class RemoveTrapPathSettings : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("DELETE FROM \"Settings\" WHERE \"Key\" IN ('Flypaper:Http:ExtraKnownHosts', 'Flypaper:Http:TrapPathsOverride');");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,12 @@ namespace Flypaper.Web.Components.Pages.Settings;
|
||||
|
||||
public sealed class SettingsModel
|
||||
{
|
||||
public string? TrapPaths { get; set; }
|
||||
|
||||
public string? MaxConnections { get; set; }
|
||||
|
||||
public string? MaxConnectionsPerIp { get; set; }
|
||||
|
||||
public string? MaxHoldDuration { get; set; }
|
||||
|
||||
public string? ExtraKnownHosts { get; set; }
|
||||
|
||||
public string? RetentionDays { get; set; }
|
||||
|
||||
public bool IgnorePrivateNetworks { get; set; }
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
@using Microsoft.Data.Sqlite
|
||||
@using Microsoft.Extensions.Options
|
||||
@inject IOptionsMonitor<FlypaperOptions> Core
|
||||
@inject IOptionsMonitor<HttpTrapOptions> Http
|
||||
@inject IOptionsMonitor<RetentionOptions> Retention
|
||||
@inject IConfiguration Configuration
|
||||
@inject RuntimeSettingsStore Store
|
||||
@@ -39,14 +38,6 @@ else if (Saved == "reset")
|
||||
<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>
|
||||
<InputTextArea id="trap-paths" @bind-Value="Model!.TrapPaths" rows="10" class="mono" />
|
||||
<FieldError Errors="_errors" Field="@nameof(SettingsModel.TrapPaths)" />
|
||||
|
||||
<label for="hosts">Bekannte Hosts <span class="muted">(einer pro Zeile, z. B. beispiel.de oder *.beispiel.de; werden auf dem Fallen-Port nur bei Fallenpfaden gefangen, sonst 404)</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="hold">Maximale Haltedauer <span class="muted">(hh:mm:ss)</span></label>
|
||||
@@ -100,8 +91,7 @@ else if (Saved == "reset")
|
||||
<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>Vertrauenswürdige Proxies</th><td class="mono">@(Configuration.GetSection("Flypaper:Http:TrustedProxies").Get<string[]>()?.Where(p => !string.IsNullOrWhiteSpace(p)).ToArray() is { Length: > 0 } proxies ? string.Join(", ", proxies) : "private Netze (Standard)")</td></tr>
|
||||
<tr><th>Admin-Passwort</th><td>@(Admin.UsesEnvironmentPassword ? "per Umgebungsvariable" : "im Dashboard festgelegt")</td></tr>
|
||||
<tr><th>Ports</th><td class="mono">Falle @Ports.Value.Trap, Dashboard @Ports.Value.Dashboard</td></tr>
|
||||
</tbody>
|
||||
@@ -129,11 +119,9 @@ else if (Saved == "reset")
|
||||
private async Task Save()
|
||||
{
|
||||
var result = RuntimeSettingsParser.Parse(new RuntimeSettingsInput(
|
||||
Model!.TrapPaths,
|
||||
Model.MaxConnections,
|
||||
Model!.MaxConnections,
|
||||
Model.MaxConnectionsPerIp,
|
||||
Model.MaxHoldDuration,
|
||||
Model.ExtraKnownHosts,
|
||||
Model.RetentionDays,
|
||||
Model.IgnorePrivateNetworks));
|
||||
|
||||
@@ -156,11 +144,8 @@ else if (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)),
|
||||
MaxHoldDuration = core.MaxHoldDuration.ToString("c", CultureInfo.InvariantCulture),
|
||||
MaxConnections = core.MaxConnections.ToString(CultureInfo.InvariantCulture),
|
||||
MaxConnectionsPerIp = core.MaxConnectionsPerIp.ToString(CultureInfo.InvariantCulture),
|
||||
|
||||
@@ -55,6 +55,7 @@ builder.Services.AddAuthorizationBuilder()
|
||||
var app = builder.Build();
|
||||
|
||||
app.Logger.LogInformation("Flypaper {Version} starting", AppVersion.Current);
|
||||
FlypaperHttpExtensions.WarnAboutRemovedSettings(app.Configuration, app.Logger);
|
||||
await app.Services.MigrateFlypaperDatabaseAsync();
|
||||
|
||||
app.UseFlypaper();
|
||||
|
||||
@@ -23,24 +23,7 @@
|
||||
"MaxConnectionsPerIp": 10,
|
||||
"MaxHoldDuration": "01:00:00",
|
||||
"Http": {
|
||||
"KnownHosts": [],
|
||||
"TrustedProxies": [],
|
||||
"TrapPaths": [
|
||||
"/.env",
|
||||
"/.env.*",
|
||||
"/.git/*",
|
||||
"/.aws/*",
|
||||
"/.DS_Store",
|
||||
"/wp-login.php",
|
||||
"/wp-admin/*",
|
||||
"/xmlrpc.php",
|
||||
"/phpmyadmin/*",
|
||||
"/vendor/phpunit/*",
|
||||
"/server-status",
|
||||
"/actuator/*",
|
||||
"/cgi-bin/*",
|
||||
"/boaform/*"
|
||||
]
|
||||
"TrustedProxies": []
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user