From 7c39cb5562fbc8f9f023c9709eb21327b0b3446b Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 14 Nov 2026 14:10:24 +0100 Subject: [PATCH] Restructure solution into folders and fix persistence issues Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 3 +- .../{ => Abstractions}/IConnectionGovernor.cs | 5 ++- .../{ => Abstractions}/ITarpitStrategy.cs | 4 +- .../{ => Abstractions}/ITrapChannel.cs | 4 +- .../{ => Abstractions}/ITrapEventSink.cs | 4 +- ...xtensions.cs => FlypaperCoreExtensions.cs} | 7 ++-- src/Flypaper.Core/{ => Models}/TrapContext.cs | 2 +- src/Flypaper.Core/{ => Models}/TrapEvent.cs | 2 +- src/Flypaper.Core/{ => Models}/TrapOutcome.cs | 2 +- .../{ => Models}/TrapProtocol.cs | 2 +- src/Flypaper.Core/Models/TrapSession.cs | 8 ++++ .../{ => Runtime}/ConnectionGovernor.cs | 8 ++-- .../{ => Runtime}/CountingTrapChannel.cs | 5 ++- src/Flypaper.Core/{ => Runtime}/TrapRunner.cs | 4 +- .../{ => Settings}/RuntimeSettings.cs | 2 +- .../{ => Settings}/RuntimeSettingsInput.cs | 4 +- .../Settings/RuntimeSettingsParseResult.cs | 3 ++ .../{ => Settings}/RuntimeSettingsParser.cs | 2 +- .../{ => Settings}/SettingKeys.cs | 2 +- .../{ => Settings}/SettingsList.cs | 2 +- src/Flypaper.Core/Strategies/DripStrategy.cs | 2 + src/Flypaper.Core/TrapSession.cs | 5 --- src/Flypaper.Http/FlypaperHttpExtensions.cs | 4 +- src/Flypaper.Http/HttpTrapChannel.cs | 3 +- src/Flypaper.Http/{ => Matching}/TrapMatch.cs | 2 +- .../{ => Matching}/TrapMatcher.cs | 2 +- .../{ => Middleware}/FlypaperMiddleware.cs | 10 +++-- .../{ => Middleware}/RealIpMiddleware.cs | 2 +- .../{ => Dashboard}/DashboardData.cs | 4 +- .../{ => Dashboard}/DashboardQueries.cs | 14 ++----- .../{ => Entities}/SettingEntity.cs | 2 +- .../{ => Entities}/TrapEventEntity.cs | 6 +-- .../{ => Events}/ChannelTrapEventSink.cs | 5 ++- .../{ => Events}/TrapEventWriter.cs | 5 ++- src/Flypaper.Storage/FlypaperDbContext.cs | 4 ++ .../FlypaperStorageExtensions.cs | 7 +++- .../{ => Settings}/DbConfigurationProvider.cs | 27 ++++++++----- .../{ => Settings}/DbConfigurationSource.cs | 4 +- .../{ => Settings}/RuntimeSettingsStore.cs | 26 ++++++++++--- src/Flypaper.Storage/UtcDateTimeConverter.cs | 7 ++++ src/Flypaper.Web/Components/App.razor | 5 +-- .../DashboardPage.razor} | 18 +++------ .../Pages/{ => Dashboard}/TopTable.razor | 5 +-- src/Flypaper.Web/Components/Pages/Error.razor | 39 ++++++------------- src/Flypaper.Web/Components/Pages/Login.razor | 1 - .../Components/Pages/NotFound.razor | 10 +++-- .../Pages/{ => Settings}/SettingsModel.cs | 2 +- .../SettingsPage.razor} | 5 ++- src/Flypaper.Web/Components/Routes.razor | 3 +- .../{Pages => Shared}/FieldError.razor | 0 .../Components/Shared/Formatting.cs | 12 ++++++ src/Flypaper.Web/Components/_Imports.razor | 7 +--- src/Flypaper.Web/Program.cs | 7 ++++ .../{ => Core}/ConnectionGovernorTests.cs | 5 ++- .../{ => Core}/DripStrategyTests.cs | 5 ++- .../{ => Core}/RuntimeSettingsParserTests.cs | 4 +- .../{ => Core}/TrapRunnerTests.cs | 6 ++- .../{ => Fakes}/FakeTrapChannel.cs | 5 ++- .../Flypaper.Tests/{ => Fakes}/TestOptions.cs | 2 +- .../{ => Http}/ForwardedHeadersTests.cs | 3 +- .../{ => Http}/TrapMatcherTests.cs | 4 +- .../{ => Storage}/SettingsOverrideTests.cs | 6 ++- 62 files changed, 219 insertions(+), 151 deletions(-) rename src/Flypaper.Core/{ => Abstractions}/IConnectionGovernor.cs (62%) rename src/Flypaper.Core/{ => Abstractions}/ITarpitStrategy.cs (71%) rename src/Flypaper.Core/{ => Abstractions}/ITrapChannel.cs (68%) rename src/Flypaper.Core/{ => Abstractions}/ITrapEventSink.cs (53%) rename src/Flypaper.Core/{ServiceCollectionExtensions.cs => FlypaperCoreExtensions.cs} (78%) rename src/Flypaper.Core/{ => Models}/TrapContext.cs (76%) rename src/Flypaper.Core/{ => Models}/TrapEvent.cs (91%) rename src/Flypaper.Core/{ => Models}/TrapOutcome.cs (73%) rename src/Flypaper.Core/{ => Models}/TrapProtocol.cs (60%) create mode 100644 src/Flypaper.Core/Models/TrapSession.cs rename src/Flypaper.Core/{ => Runtime}/ConnectionGovernor.cs (89%) rename src/Flypaper.Core/{ => Runtime}/CountingTrapChannel.cs (81%) rename src/Flypaper.Core/{ => Runtime}/TrapRunner.cs (97%) rename src/Flypaper.Core/{ => Settings}/RuntimeSettings.cs (96%) rename src/Flypaper.Core/{ => Settings}/RuntimeSettingsInput.cs (59%) create mode 100644 src/Flypaper.Core/Settings/RuntimeSettingsParseResult.cs rename src/Flypaper.Core/{ => Settings}/RuntimeSettingsParser.cs (99%) rename src/Flypaper.Core/{ => Settings}/SettingKeys.cs (95%) rename src/Flypaper.Core/{ => Settings}/SettingsList.cs (93%) delete mode 100644 src/Flypaper.Core/TrapSession.cs rename src/Flypaper.Http/{ => Matching}/TrapMatch.cs (66%) rename src/Flypaper.Http/{ => Matching}/TrapMatcher.cs (98%) rename src/Flypaper.Http/{ => Middleware}/FlypaperMiddleware.cs (90%) rename src/Flypaper.Http/{ => Middleware}/RealIpMiddleware.cs (96%) rename src/Flypaper.Storage/{ => Dashboard}/DashboardData.cs (82%) rename src/Flypaper.Storage/{ => Dashboard}/DashboardQueries.cs (80%) rename src/Flypaper.Storage/{ => Entities}/SettingEntity.cs (78%) rename src/Flypaper.Storage/{ => Entities}/TrapEventEntity.cs (90%) rename src/Flypaper.Storage/{ => Events}/ChannelTrapEventSink.cs (84%) rename src/Flypaper.Storage/{ => Events}/TrapEventWriter.cs (92%) rename src/Flypaper.Storage/{ => Settings}/DbConfigurationProvider.cs (64%) rename src/Flypaper.Storage/{ => Settings}/DbConfigurationSource.cs (76%) rename src/Flypaper.Storage/{ => Settings}/RuntimeSettingsStore.cs (59%) create mode 100644 src/Flypaper.Storage/UtcDateTimeConverter.cs rename src/Flypaper.Web/Components/Pages/{Home.razor => Dashboard/DashboardPage.razor} (82%) rename src/Flypaper.Web/Components/Pages/{ => Dashboard}/TopTable.razor (91%) rename src/Flypaper.Web/Components/Pages/{ => Settings}/SettingsModel.cs (86%) rename src/Flypaper.Web/Components/Pages/{Settings.razor => Settings/SettingsPage.razor} (99%) rename src/Flypaper.Web/Components/{Pages => Shared}/FieldError.razor (100%) create mode 100644 src/Flypaper.Web/Components/Shared/Formatting.cs rename test/Flypaper.Tests/{ => Core}/ConnectionGovernorTests.cs (95%) rename test/Flypaper.Tests/{ => Core}/DripStrategyTests.cs (94%) rename test/Flypaper.Tests/{ => Core}/RuntimeSettingsParserTests.cs (98%) rename test/Flypaper.Tests/{ => Core}/TrapRunnerTests.cs (95%) rename test/Flypaper.Tests/{ => Fakes}/FakeTrapChannel.cs (84%) rename test/Flypaper.Tests/{ => Fakes}/TestOptions.cs (90%) rename test/Flypaper.Tests/{ => Http}/ForwardedHeadersTests.cs (97%) rename test/Flypaper.Tests/{ => Http}/TrapMatcherTests.cs (93%) rename test/Flypaper.Tests/{ => Storage}/SettingsOverrideTests.cs (97%) diff --git a/Dockerfile b/Dockerfile index e14706d..85ffb19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,8 @@ WORKDIR /app RUN mkdir /data && chown $APP_UID /data ENV ASPNETCORE_HTTP_PORTS=8080 \ - ConnectionStrings__Flypaper="Data Source=/data/flypaper.db" + ConnectionStrings__Flypaper="Data Source=/data/flypaper.db" \ + Flypaper__DataProtection__KeysPath=/data/keys COPY --from=build /app . diff --git a/src/Flypaper.Core/IConnectionGovernor.cs b/src/Flypaper.Core/Abstractions/IConnectionGovernor.cs similarity index 62% rename from src/Flypaper.Core/IConnectionGovernor.cs rename to src/Flypaper.Core/Abstractions/IConnectionGovernor.cs index 3d3d254..044512f 100644 --- a/src/Flypaper.Core/IConnectionGovernor.cs +++ b/src/Flypaper.Core/Abstractions/IConnectionGovernor.cs @@ -1,8 +1,11 @@ using System.Diagnostics.CodeAnalysis; +using Flypaper.Core.Models; -namespace Flypaper.Core; +namespace Flypaper.Core.Abstractions; public interface IConnectionGovernor { + int ActiveConnections { get; } + bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease); } diff --git a/src/Flypaper.Core/ITarpitStrategy.cs b/src/Flypaper.Core/Abstractions/ITarpitStrategy.cs similarity index 71% rename from src/Flypaper.Core/ITarpitStrategy.cs rename to src/Flypaper.Core/Abstractions/ITarpitStrategy.cs index a5dd7b0..b6ec86d 100644 --- a/src/Flypaper.Core/ITarpitStrategy.cs +++ b/src/Flypaper.Core/Abstractions/ITarpitStrategy.cs @@ -1,4 +1,6 @@ -namespace Flypaper.Core; +using Flypaper.Core.Models; + +namespace Flypaper.Core.Abstractions; public interface ITarpitStrategy { diff --git a/src/Flypaper.Core/ITrapChannel.cs b/src/Flypaper.Core/Abstractions/ITrapChannel.cs similarity index 68% rename from src/Flypaper.Core/ITrapChannel.cs rename to src/Flypaper.Core/Abstractions/ITrapChannel.cs index 2262e99..fe8082f 100644 --- a/src/Flypaper.Core/ITrapChannel.cs +++ b/src/Flypaper.Core/Abstractions/ITrapChannel.cs @@ -1,4 +1,6 @@ -namespace Flypaper.Core; +using Flypaper.Core.Models; + +namespace Flypaper.Core.Abstractions; public interface ITrapChannel { diff --git a/src/Flypaper.Core/ITrapEventSink.cs b/src/Flypaper.Core/Abstractions/ITrapEventSink.cs similarity index 53% rename from src/Flypaper.Core/ITrapEventSink.cs rename to src/Flypaper.Core/Abstractions/ITrapEventSink.cs index ecaa48c..bda121d 100644 --- a/src/Flypaper.Core/ITrapEventSink.cs +++ b/src/Flypaper.Core/Abstractions/ITrapEventSink.cs @@ -1,4 +1,6 @@ -namespace Flypaper.Core; +using Flypaper.Core.Models; + +namespace Flypaper.Core.Abstractions; public interface ITrapEventSink { diff --git a/src/Flypaper.Core/ServiceCollectionExtensions.cs b/src/Flypaper.Core/FlypaperCoreExtensions.cs similarity index 78% rename from src/Flypaper.Core/ServiceCollectionExtensions.cs rename to src/Flypaper.Core/FlypaperCoreExtensions.cs index 6d0d2f8..244d143 100644 --- a/src/Flypaper.Core/ServiceCollectionExtensions.cs +++ b/src/Flypaper.Core/FlypaperCoreExtensions.cs @@ -1,3 +1,5 @@ +using Flypaper.Core.Abstractions; +using Flypaper.Core.Runtime; using Flypaper.Core.Strategies; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -5,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions; namespace Flypaper.Core; -public static class ServiceCollectionExtensions +public static class FlypaperCoreExtensions { public static IServiceCollection AddFlypaperCore(this IServiceCollection services, IConfiguration configuration) { @@ -13,8 +15,7 @@ public static class ServiceCollectionExtensions services.Configure(configuration.GetSection(DripOptions.SectionName)); services.TryAddSingleton(TimeProvider.System); - services.TryAddSingleton(); - services.TryAddSingleton(sp => sp.GetRequiredService()); + services.TryAddSingleton(); services.TryAddEnumerable(ServiceDescriptor.Singleton()); services.TryAddSingleton(); diff --git a/src/Flypaper.Core/TrapContext.cs b/src/Flypaper.Core/Models/TrapContext.cs similarity index 76% rename from src/Flypaper.Core/TrapContext.cs rename to src/Flypaper.Core/Models/TrapContext.cs index ad08e12..7324083 100644 --- a/src/Flypaper.Core/TrapContext.cs +++ b/src/Flypaper.Core/Models/TrapContext.cs @@ -1,3 +1,3 @@ -namespace Flypaper.Core; +namespace Flypaper.Core.Models; public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null); diff --git a/src/Flypaper.Core/TrapEvent.cs b/src/Flypaper.Core/Models/TrapEvent.cs similarity index 91% rename from src/Flypaper.Core/TrapEvent.cs rename to src/Flypaper.Core/Models/TrapEvent.cs index f1f9a34..7b77a9a 100644 --- a/src/Flypaper.Core/TrapEvent.cs +++ b/src/Flypaper.Core/Models/TrapEvent.cs @@ -1,6 +1,6 @@ using System.Net; -namespace Flypaper.Core; +namespace Flypaper.Core.Models; public sealed record TrapEvent( Guid SessionId, diff --git a/src/Flypaper.Core/TrapOutcome.cs b/src/Flypaper.Core/Models/TrapOutcome.cs similarity index 73% rename from src/Flypaper.Core/TrapOutcome.cs rename to src/Flypaper.Core/Models/TrapOutcome.cs index fc8418a..03be942 100644 --- a/src/Flypaper.Core/TrapOutcome.cs +++ b/src/Flypaper.Core/Models/TrapOutcome.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Core; +namespace Flypaper.Core.Models; public enum TrapOutcome { diff --git a/src/Flypaper.Core/TrapProtocol.cs b/src/Flypaper.Core/Models/TrapProtocol.cs similarity index 60% rename from src/Flypaper.Core/TrapProtocol.cs rename to src/Flypaper.Core/Models/TrapProtocol.cs index f0da43a..e49fd5c 100644 --- a/src/Flypaper.Core/TrapProtocol.cs +++ b/src/Flypaper.Core/Models/TrapProtocol.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Core; +namespace Flypaper.Core.Models; public enum TrapProtocol { diff --git a/src/Flypaper.Core/Models/TrapSession.cs b/src/Flypaper.Core/Models/TrapSession.cs new file mode 100644 index 0000000..23de6c1 --- /dev/null +++ b/src/Flypaper.Core/Models/TrapSession.cs @@ -0,0 +1,8 @@ +using System.Net; + +namespace Flypaper.Core.Models; + +public sealed record TrapSession(Guid Id, TrapProtocol Protocol, IPAddress RemoteIp, DateTimeOffset StartedAt) +{ + public IPAddress RemoteIp { get; init; } = RemoteIp.IsIPv4MappedToIPv6 ? RemoteIp.MapToIPv4() : RemoteIp; +} diff --git a/src/Flypaper.Core/ConnectionGovernor.cs b/src/Flypaper.Core/Runtime/ConnectionGovernor.cs similarity index 89% rename from src/Flypaper.Core/ConnectionGovernor.cs rename to src/Flypaper.Core/Runtime/ConnectionGovernor.cs index 6e15cdc..1b29535 100644 --- a/src/Flypaper.Core/ConnectionGovernor.cs +++ b/src/Flypaper.Core/Runtime/ConnectionGovernor.cs @@ -1,8 +1,10 @@ using System.Diagnostics.CodeAnalysis; using System.Net; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; using Microsoft.Extensions.Options; -namespace Flypaper.Core; +namespace Flypaper.Core.Runtime; public sealed class ConnectionGovernor(IOptionsMonitor options) : IConnectionGovernor { @@ -23,7 +25,7 @@ public sealed class ConnectionGovernor(IOptionsMonitor options) public bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease) { - var ip = Normalize(session.RemoteIp); + var ip = session.RemoteIp; var limits = options.CurrentValue; lock (_gate) @@ -55,8 +57,6 @@ public sealed class ConnectionGovernor(IOptionsMonitor options) } } - private static IPAddress Normalize(IPAddress ip) => ip.IsIPv4MappedToIPv6 ? ip.MapToIPv4() : ip; - private sealed class Lease(ConnectionGovernor owner, IPAddress ip) : IDisposable { private int _disposed; diff --git a/src/Flypaper.Core/CountingTrapChannel.cs b/src/Flypaper.Core/Runtime/CountingTrapChannel.cs similarity index 81% rename from src/Flypaper.Core/CountingTrapChannel.cs rename to src/Flypaper.Core/Runtime/CountingTrapChannel.cs index ff655a9..ece9e57 100644 --- a/src/Flypaper.Core/CountingTrapChannel.cs +++ b/src/Flypaper.Core/Runtime/CountingTrapChannel.cs @@ -1,4 +1,7 @@ -namespace Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; + +namespace Flypaper.Core.Runtime; internal sealed class CountingTrapChannel(ITrapChannel inner) : ITrapChannel { diff --git a/src/Flypaper.Core/TrapRunner.cs b/src/Flypaper.Core/Runtime/TrapRunner.cs similarity index 97% rename from src/Flypaper.Core/TrapRunner.cs rename to src/Flypaper.Core/Runtime/TrapRunner.cs index 0999158..44e4519 100644 --- a/src/Flypaper.Core/TrapRunner.cs +++ b/src/Flypaper.Core/Runtime/TrapRunner.cs @@ -1,8 +1,10 @@ using System.Net; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Flypaper.Core; +namespace Flypaper.Core.Runtime; public sealed partial class TrapRunner( IConnectionGovernor governor, diff --git a/src/Flypaper.Core/RuntimeSettings.cs b/src/Flypaper.Core/Settings/RuntimeSettings.cs similarity index 96% rename from src/Flypaper.Core/RuntimeSettings.cs rename to src/Flypaper.Core/Settings/RuntimeSettings.cs index c32aae1..7691ce3 100644 --- a/src/Flypaper.Core/RuntimeSettings.cs +++ b/src/Flypaper.Core/Settings/RuntimeSettings.cs @@ -1,6 +1,6 @@ using System.Globalization; -namespace Flypaper.Core; +namespace Flypaper.Core.Settings; public sealed record RuntimeSettings( IReadOnlyList TrapPaths, diff --git a/src/Flypaper.Core/RuntimeSettingsInput.cs b/src/Flypaper.Core/Settings/RuntimeSettingsInput.cs similarity index 59% rename from src/Flypaper.Core/RuntimeSettingsInput.cs rename to src/Flypaper.Core/Settings/RuntimeSettingsInput.cs index b9b4e60..c63be5c 100644 --- a/src/Flypaper.Core/RuntimeSettingsInput.cs +++ b/src/Flypaper.Core/Settings/RuntimeSettingsInput.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Core; +namespace Flypaper.Core.Settings; public sealed record RuntimeSettingsInput( string? TrapPaths, @@ -7,5 +7,3 @@ public sealed record RuntimeSettingsInput( string? MaxConnectionsPerIp, string? MaxHoldDuration, string? ExtraKnownHosts); - -public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary Errors); diff --git a/src/Flypaper.Core/Settings/RuntimeSettingsParseResult.cs b/src/Flypaper.Core/Settings/RuntimeSettingsParseResult.cs new file mode 100644 index 0000000..e06d7b9 --- /dev/null +++ b/src/Flypaper.Core/Settings/RuntimeSettingsParseResult.cs @@ -0,0 +1,3 @@ +namespace Flypaper.Core.Settings; + +public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary Errors); diff --git a/src/Flypaper.Core/RuntimeSettingsParser.cs b/src/Flypaper.Core/Settings/RuntimeSettingsParser.cs similarity index 99% rename from src/Flypaper.Core/RuntimeSettingsParser.cs rename to src/Flypaper.Core/Settings/RuntimeSettingsParser.cs index b808720..a442959 100644 --- a/src/Flypaper.Core/RuntimeSettingsParser.cs +++ b/src/Flypaper.Core/Settings/RuntimeSettingsParser.cs @@ -1,7 +1,7 @@ using System.Globalization; using System.Text.RegularExpressions; -namespace Flypaper.Core; +namespace Flypaper.Core.Settings; public static partial class RuntimeSettingsParser { diff --git a/src/Flypaper.Core/SettingKeys.cs b/src/Flypaper.Core/Settings/SettingKeys.cs similarity index 95% rename from src/Flypaper.Core/SettingKeys.cs rename to src/Flypaper.Core/Settings/SettingKeys.cs index 13c1e05..d6130f1 100644 --- a/src/Flypaper.Core/SettingKeys.cs +++ b/src/Flypaper.Core/Settings/SettingKeys.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Core; +namespace Flypaper.Core.Settings; public static class SettingKeys { diff --git a/src/Flypaper.Core/SettingsList.cs b/src/Flypaper.Core/Settings/SettingsList.cs similarity index 93% rename from src/Flypaper.Core/SettingsList.cs rename to src/Flypaper.Core/Settings/SettingsList.cs index 49f9b01..2f95315 100644 --- a/src/Flypaper.Core/SettingsList.cs +++ b/src/Flypaper.Core/Settings/SettingsList.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Core; +namespace Flypaper.Core.Settings; public static class SettingsList { diff --git a/src/Flypaper.Core/Strategies/DripStrategy.cs b/src/Flypaper.Core/Strategies/DripStrategy.cs index 46ee530..71ad995 100644 --- a/src/Flypaper.Core/Strategies/DripStrategy.cs +++ b/src/Flypaper.Core/Strategies/DripStrategy.cs @@ -1,3 +1,5 @@ +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; using Microsoft.Extensions.Options; namespace Flypaper.Core.Strategies; diff --git a/src/Flypaper.Core/TrapSession.cs b/src/Flypaper.Core/TrapSession.cs deleted file mode 100644 index d08892d..0000000 --- a/src/Flypaper.Core/TrapSession.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System.Net; - -namespace Flypaper.Core; - -public sealed record TrapSession(Guid Id, TrapProtocol Protocol, IPAddress RemoteIp, DateTimeOffset StartedAt); diff --git a/src/Flypaper.Http/FlypaperHttpExtensions.cs b/src/Flypaper.Http/FlypaperHttpExtensions.cs index e2dda3c..50d3294 100644 --- a/src/Flypaper.Http/FlypaperHttpExtensions.cs +++ b/src/Flypaper.Http/FlypaperHttpExtensions.cs @@ -1,6 +1,8 @@ using System.Net; using System.Net.Sockets; -using Flypaper.Core; +using Flypaper.Core.Settings; +using Flypaper.Http.Matching; +using Flypaper.Http.Middleware; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; diff --git a/src/Flypaper.Http/HttpTrapChannel.cs b/src/Flypaper.Http/HttpTrapChannel.cs index 1c481fd..1d55edb 100644 --- a/src/Flypaper.Http/HttpTrapChannel.cs +++ b/src/Flypaper.Http/HttpTrapChannel.cs @@ -1,4 +1,5 @@ -using Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; using Microsoft.AspNetCore.Http; namespace Flypaper.Http; diff --git a/src/Flypaper.Http/TrapMatch.cs b/src/Flypaper.Http/Matching/TrapMatch.cs similarity index 66% rename from src/Flypaper.Http/TrapMatch.cs rename to src/Flypaper.Http/Matching/TrapMatch.cs index 65044b3..87ced41 100644 --- a/src/Flypaper.Http/TrapMatch.cs +++ b/src/Flypaper.Http/Matching/TrapMatch.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Http; +namespace Flypaper.Http.Matching; public enum TrapMatch { diff --git a/src/Flypaper.Http/TrapMatcher.cs b/src/Flypaper.Http/Matching/TrapMatcher.cs similarity index 98% rename from src/Flypaper.Http/TrapMatcher.cs rename to src/Flypaper.Http/Matching/TrapMatcher.cs index 55d78c6..94218c9 100644 --- a/src/Flypaper.Http/TrapMatcher.cs +++ b/src/Flypaper.Http/Matching/TrapMatcher.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Options; -namespace Flypaper.Http; +namespace Flypaper.Http.Matching; public sealed class TrapMatcher : IDisposable { diff --git a/src/Flypaper.Http/FlypaperMiddleware.cs b/src/Flypaper.Http/Middleware/FlypaperMiddleware.cs similarity index 90% rename from src/Flypaper.Http/FlypaperMiddleware.cs rename to src/Flypaper.Http/Middleware/FlypaperMiddleware.cs index a5dc2f9..3419d66 100644 --- a/src/Flypaper.Http/FlypaperMiddleware.cs +++ b/src/Flypaper.Http/Middleware/FlypaperMiddleware.cs @@ -1,10 +1,13 @@ using System.Net; -using Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; +using Flypaper.Core.Runtime; +using Flypaper.Http.Matching; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Core.Features; -namespace Flypaper.Http; +namespace Flypaper.Http.Middleware; internal sealed class FlypaperMiddleware( RequestDelegate next, @@ -21,11 +24,10 @@ internal sealed class FlypaperMiddleware( return; } - var remoteIp = context.Connection.RemoteIpAddress ?? IPAddress.None; var session = new TrapSession( Guid.NewGuid(), TrapProtocol.Http, - remoteIp.IsIPv4MappedToIPv6 ? remoteIp.MapToIPv4() : remoteIp, + context.Connection.RemoteIpAddress ?? IPAddress.None, timeProvider.GetUtcNow()); var trapContext = new TrapContext( diff --git a/src/Flypaper.Http/RealIpMiddleware.cs b/src/Flypaper.Http/Middleware/RealIpMiddleware.cs similarity index 96% rename from src/Flypaper.Http/RealIpMiddleware.cs rename to src/Flypaper.Http/Middleware/RealIpMiddleware.cs index e69b97c..c57fc8e 100644 --- a/src/Flypaper.Http/RealIpMiddleware.cs +++ b/src/Flypaper.Http/Middleware/RealIpMiddleware.cs @@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; -namespace Flypaper.Http; +namespace Flypaper.Http.Middleware; internal sealed class RealIpMiddleware(RequestDelegate next, IOptions options) { diff --git a/src/Flypaper.Storage/DashboardData.cs b/src/Flypaper.Storage/Dashboard/DashboardData.cs similarity index 82% rename from src/Flypaper.Storage/DashboardData.cs rename to src/Flypaper.Storage/Dashboard/DashboardData.cs index 986743b..24b7d78 100644 --- a/src/Flypaper.Storage/DashboardData.cs +++ b/src/Flypaper.Storage/Dashboard/DashboardData.cs @@ -1,4 +1,6 @@ -namespace Flypaper.Storage; +using Flypaper.Storage.Entities; + +namespace Flypaper.Storage.Dashboard; public sealed record DashboardData( int TotalCatches, diff --git a/src/Flypaper.Storage/DashboardQueries.cs b/src/Flypaper.Storage/Dashboard/DashboardQueries.cs similarity index 80% rename from src/Flypaper.Storage/DashboardQueries.cs rename to src/Flypaper.Storage/Dashboard/DashboardQueries.cs index 924426b..65ce009 100644 --- a/src/Flypaper.Storage/DashboardQueries.cs +++ b/src/Flypaper.Storage/Dashboard/DashboardQueries.cs @@ -1,7 +1,8 @@ -using Flypaper.Core; +using Flypaper.Core.Models; +using Flypaper.Storage.Entities; using Microsoft.EntityFrameworkCore; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Dashboard; public sealed class DashboardQueries(IDbContextFactory dbContextFactory, TimeProvider timeProvider) { @@ -15,20 +16,13 @@ public sealed class DashboardQueries(IDbContextFactory dbCont var catches = events.Where(e => e.Outcome != TrapOutcome.Rejected); var since = timeProvider.GetUtcNow().UtcDateTime.AddHours(-24); - var recent = await events.OrderByDescending(e => e.Id).Take(RecentCount).ToListAsync(ct); - foreach (var trapEvent in recent) - { - trapEvent.StartedAt = DateTime.SpecifyKind(trapEvent.StartedAt, DateTimeKind.Utc); - trapEvent.EndedAt = DateTime.SpecifyKind(trapEvent.EndedAt, DateTimeKind.Utc); - } - return new DashboardData( await catches.CountAsync(ct), await catches.CountAsync(e => e.StartedAt >= since, ct), await events.CountAsync(e => e.Outcome == TrapOutcome.Rejected, ct), await events.Select(e => e.RemoteIp).Distinct().CountAsync(ct), TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, ct)), - recent, + await events.OrderByDescending(e => e.Id).Take(RecentCount).ToListAsync(ct), await TopAsync(catches.GroupBy(e => e.RemoteIp), ct), await TopAsync(catches.Where(e => e.Target != null).GroupBy(e => e.Target!), ct)); } diff --git a/src/Flypaper.Storage/SettingEntity.cs b/src/Flypaper.Storage/Entities/SettingEntity.cs similarity index 78% rename from src/Flypaper.Storage/SettingEntity.cs rename to src/Flypaper.Storage/Entities/SettingEntity.cs index b4f0f91..c0a7c9f 100644 --- a/src/Flypaper.Storage/SettingEntity.cs +++ b/src/Flypaper.Storage/Entities/SettingEntity.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Storage; +namespace Flypaper.Storage.Entities; public sealed class SettingEntity { diff --git a/src/Flypaper.Storage/TrapEventEntity.cs b/src/Flypaper.Storage/Entities/TrapEventEntity.cs similarity index 90% rename from src/Flypaper.Storage/TrapEventEntity.cs rename to src/Flypaper.Storage/Entities/TrapEventEntity.cs index 70bc75b..6ae283d 100644 --- a/src/Flypaper.Storage/TrapEventEntity.cs +++ b/src/Flypaper.Storage/Entities/TrapEventEntity.cs @@ -1,6 +1,6 @@ -using Flypaper.Core; +using Flypaper.Core.Models; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Entities; public sealed class TrapEventEntity { @@ -44,5 +44,5 @@ public sealed class TrapEventEntity }; private static string? Truncate(string? value, int maxLength) => - value is { Length: > 0 } && value.Length > maxLength ? value[..maxLength] : value; + value?.Length > maxLength ? value[..maxLength] : value; } diff --git a/src/Flypaper.Storage/ChannelTrapEventSink.cs b/src/Flypaper.Storage/Events/ChannelTrapEventSink.cs similarity index 84% rename from src/Flypaper.Storage/ChannelTrapEventSink.cs rename to src/Flypaper.Storage/Events/ChannelTrapEventSink.cs index eb9e4e7..fa0f6d5 100644 --- a/src/Flypaper.Storage/ChannelTrapEventSink.cs +++ b/src/Flypaper.Storage/Events/ChannelTrapEventSink.cs @@ -1,7 +1,8 @@ using System.Threading.Channels; -using Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Events; public sealed class ChannelTrapEventSink : ITrapEventSink { diff --git a/src/Flypaper.Storage/TrapEventWriter.cs b/src/Flypaper.Storage/Events/TrapEventWriter.cs similarity index 92% rename from src/Flypaper.Storage/TrapEventWriter.cs rename to src/Flypaper.Storage/Events/TrapEventWriter.cs index 984e20a..a0b1350 100644 --- a/src/Flypaper.Storage/TrapEventWriter.cs +++ b/src/Flypaper.Storage/Events/TrapEventWriter.cs @@ -1,9 +1,10 @@ -using Flypaper.Core; +using Flypaper.Core.Models; +using Flypaper.Storage.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Events; internal sealed class TrapEventWriter( ChannelTrapEventSink sink, diff --git a/src/Flypaper.Storage/FlypaperDbContext.cs b/src/Flypaper.Storage/FlypaperDbContext.cs index 8ce402b..d3d39d2 100644 --- a/src/Flypaper.Storage/FlypaperDbContext.cs +++ b/src/Flypaper.Storage/FlypaperDbContext.cs @@ -1,3 +1,4 @@ +using Flypaper.Storage.Entities; using Microsoft.EntityFrameworkCore; namespace Flypaper.Storage; @@ -10,6 +11,9 @@ public sealed class FlypaperDbContext(DbContextOptions option public DbSet Settings => Set(); + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) => + configurationBuilder.Properties().HaveConversion(); + protected override void OnModelCreating(ModelBuilder modelBuilder) { var trapEvent = modelBuilder.Entity(); diff --git a/src/Flypaper.Storage/FlypaperStorageExtensions.cs b/src/Flypaper.Storage/FlypaperStorageExtensions.cs index a07fb52..4e3dcc7 100644 --- a/src/Flypaper.Storage/FlypaperStorageExtensions.cs +++ b/src/Flypaper.Storage/FlypaperStorageExtensions.cs @@ -1,4 +1,7 @@ -using Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Storage.Dashboard; +using Flypaper.Storage.Events; +using Flypaper.Storage.Settings; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -39,6 +42,6 @@ public static class FlypaperStorageExtensions await db.Database.MigrateAsync(ct); } - services.GetService()?.Reload(); + services.GetService()?.TryReload(); } } diff --git a/src/Flypaper.Storage/DbConfigurationProvider.cs b/src/Flypaper.Storage/Settings/DbConfigurationProvider.cs similarity index 64% rename from src/Flypaper.Storage/DbConfigurationProvider.cs rename to src/Flypaper.Storage/Settings/DbConfigurationProvider.cs index 73e6c66..45e354d 100644 --- a/src/Flypaper.Storage/DbConfigurationProvider.cs +++ b/src/Flypaper.Storage/Settings/DbConfigurationProvider.cs @@ -1,22 +1,27 @@ -using Flypaper.Core; +using Flypaper.Core.Settings; using Microsoft.Data.Sqlite; using Microsoft.Extensions.Configuration; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Settings; internal sealed class DbConfigurationProvider(string connectionString) : ConfigurationProvider { - public override void Load() => Data = Read(); + public override void Load() => Data = TryRead() ?? new Dictionary(StringComparer.OrdinalIgnoreCase); - public void Reload() + public bool TryReload() { - Load(); + if (TryRead() is not { } data) + { + return false; + } + + Data = data; OnReload(); + return true; } - private Dictionary Read() + private Dictionary? TryRead() { - var data = new Dictionary(StringComparer.OrdinalIgnoreCase); var builder = new SqliteConnectionStringBuilder(connectionString) { Mode = SqliteOpenMode.ReadOnly }; try @@ -26,6 +31,8 @@ internal sealed class DbConfigurationProvider(string connectionString) : Configu using var command = connection.CreateCommand(); command.CommandText = "SELECT \"Key\", \"Value\" FROM \"Settings\""; using var reader = command.ExecuteReader(); + + var data = new Dictionary(StringComparer.OrdinalIgnoreCase); while (reader.Read()) { var key = reader.GetString(0); @@ -34,12 +41,12 @@ internal sealed class DbConfigurationProvider(string connectionString) : Configu data[key] = reader.GetString(1); } } + + return data; } catch (SqliteException) { - data.Clear(); + return null; } - - return data; } } diff --git a/src/Flypaper.Storage/DbConfigurationSource.cs b/src/Flypaper.Storage/Settings/DbConfigurationSource.cs similarity index 76% rename from src/Flypaper.Storage/DbConfigurationSource.cs rename to src/Flypaper.Storage/Settings/DbConfigurationSource.cs index c32f821..781fd2b 100644 --- a/src/Flypaper.Storage/DbConfigurationSource.cs +++ b/src/Flypaper.Storage/Settings/DbConfigurationSource.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Configuration; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Settings; public sealed class DbConfigurationSource(string connectionString) : IConfigurationSource { @@ -9,5 +9,5 @@ public sealed class DbConfigurationSource(string connectionString) : IConfigurat public IConfigurationProvider Build(IConfigurationBuilder builder) => _provider = new DbConfigurationProvider(connectionString); - public void Reload() => _provider?.Reload(); + public bool TryReload() => _provider?.TryReload() ?? false; } diff --git a/src/Flypaper.Storage/RuntimeSettingsStore.cs b/src/Flypaper.Storage/Settings/RuntimeSettingsStore.cs similarity index 59% rename from src/Flypaper.Storage/RuntimeSettingsStore.cs rename to src/Flypaper.Storage/Settings/RuntimeSettingsStore.cs index 1ea23f0..b6416b4 100644 --- a/src/Flypaper.Storage/RuntimeSettingsStore.cs +++ b/src/Flypaper.Storage/Settings/RuntimeSettingsStore.cs @@ -1,9 +1,14 @@ -using Flypaper.Core; +using Flypaper.Core.Settings; +using Flypaper.Storage.Entities; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; -namespace Flypaper.Storage; +namespace Flypaper.Storage.Settings; -public sealed class RuntimeSettingsStore(IDbContextFactory dbContextFactory, DbConfigurationSource source) +public sealed partial class RuntimeSettingsStore( + IDbContextFactory dbContextFactory, + DbConfigurationSource source, + ILogger logger) { public async Task SaveAsync(RuntimeSettings settings, CancellationToken ct = default) { @@ -13,14 +18,14 @@ public sealed class RuntimeSettingsStore(IDbContextFactory db db.Settings.AddRange(settings.ToConfiguration().Select(pair => new SettingEntity { Key = pair.Key, Value = pair.Value })); await db.SaveChangesAsync(ct); await transaction.CommitAsync(ct); - source.Reload(); + Reload(); } public async Task ResetAsync(CancellationToken ct = default) { await using var db = await dbContextFactory.CreateDbContextAsync(ct); await db.Settings.ExecuteDeleteAsync(ct); - source.Reload(); + Reload(); } public async Task HasOverridesAsync(CancellationToken ct = default) @@ -28,4 +33,15 @@ public sealed class RuntimeSettingsStore(IDbContextFactory db await using var db = await dbContextFactory.CreateDbContextAsync(ct); return await db.Settings.AnyAsync(ct); } + + private void Reload() + { + if (!source.TryReload()) + { + LogReloadFailed(); + } + } + + [LoggerMessage(Level = LogLevel.Warning, Message = "Settings were saved but could not be reloaded from the database; previous values stay active")] + private partial void LogReloadFailed(); } diff --git a/src/Flypaper.Storage/UtcDateTimeConverter.cs b/src/Flypaper.Storage/UtcDateTimeConverter.cs new file mode 100644 index 0000000..aeb78be --- /dev/null +++ b/src/Flypaper.Storage/UtcDateTimeConverter.cs @@ -0,0 +1,7 @@ +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Flypaper.Storage; + +internal sealed class UtcDateTimeConverter() : ValueConverter( + value => value.Kind == DateTimeKind.Utc ? value : value.ToUniversalTime(), + value => DateTime.SpecifyKind(value, DateTimeKind.Utc)); diff --git a/src/Flypaper.Web/Components/App.razor b/src/Flypaper.Web/Components/App.razor index 8716efd..a1828d0 100644 --- a/src/Flypaper.Web/Components/App.razor +++ b/src/Flypaper.Web/Components/App.razor @@ -1,14 +1,11 @@ - + - - - diff --git a/src/Flypaper.Web/Components/Pages/Home.razor b/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor similarity index 82% rename from src/Flypaper.Web/Components/Pages/Home.razor rename to src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor index 32e77c1..487aae5 100644 --- a/src/Flypaper.Web/Components/Pages/Home.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor @@ -1,8 +1,8 @@ @page "/" -@using Flypaper.Core -@using Flypaper.Storage +@using Flypaper.Core.Abstractions +@using Flypaper.Storage.Dashboard @inject DashboardQueries Queries -@inject ConnectionGovernor Governor +@inject IConnectionGovernor Governor Flypaper @@ -21,7 +21,7 @@
Letzte 24 h@data.CatchesLast24Hours.ToString("N0")
Aktiv@Governor.ActiveConnections.ToString("N0")
Eindeutige IPs@data.UniqueIps.ToString("N0")
-
Haltezeit gesamt@FormatDuration(data.TotalHoldTime)
+
Haltezeit gesamt@Formatting.Duration(data.TotalHoldTime)
Abgelehnt@data.Rejected.ToString("N0")
@@ -59,7 +59,7 @@ @trapEvent.RemoteIp @trapEvent.Target @trapEvent.ClientInfo - @FormatDuration(TimeSpan.FromMilliseconds(trapEvent.DurationMs)) + @Formatting.Duration(TimeSpan.FromMilliseconds(trapEvent.DurationMs)) @trapEvent.BytesSent.ToString("N0") @trapEvent.Outcome @@ -80,12 +80,4 @@ _data = await Queries.GetAsync(); _loadedAt = DateTime.Now; } - - internal static string FormatDuration(TimeSpan duration) => duration switch - { - { TotalDays: >= 1 } => $"{(int)duration.TotalDays} d {duration.Hours} h", - { TotalHours: >= 1 } => $"{duration.Hours} h {duration.Minutes} min", - { TotalMinutes: >= 1 } => $"{duration.Minutes} min {duration.Seconds} s", - _ => $"{duration.TotalSeconds:0.0} s" - }; } diff --git a/src/Flypaper.Web/Components/Pages/TopTable.razor b/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor similarity index 91% rename from src/Flypaper.Web/Components/Pages/TopTable.razor rename to src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor index a6e7e2a..5704f0e 100644 --- a/src/Flypaper.Web/Components/Pages/TopTable.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor @@ -1,5 +1,4 @@ -@using Flypaper.Storage - +@using Flypaper.Storage.Dashboard

@Title

@if (Entries.Count == 0) @@ -22,7 +21,7 @@ @entry.Key @entry.Count.ToString("N0") - @Home.FormatDuration(entry.HoldTime) + @Formatting.Duration(entry.HoldTime) } diff --git a/src/Flypaper.Web/Components/Pages/Error.razor b/src/Flypaper.Web/Components/Pages/Error.razor index 576cc2d..2bf3cff 100644 --- a/src/Flypaper.Web/Components/Pages/Error.razor +++ b/src/Flypaper.Web/Components/Pages/Error.razor @@ -1,36 +1,21 @@ -@page "/Error" +@page "/Error" +@layout EmptyLayout +@attribute [AllowAnonymous] @using System.Diagnostics -Error +Flypaper · Fehler -

Error.

-

An error occurred while processing your request.

- -@if (ShowRequestId) +

Fehler

+

Bei der Verarbeitung der Anfrage ist ein Fehler aufgetreten.

+@if (!string.IsNullOrEmpty(_requestId)) { -

- Request ID: @RequestId -

+

Request-ID: @_requestId

} -

Development Mode

-

- Swapping to Development environment will display more detailed information about the error that occurred. -

-

- The Development environment shouldn't be enabled for deployed applications. - It can result in displaying sensitive information from exceptions to end users. - For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development - and restarting the app. -

+@code { + private string? _requestId; -@code{ - [CascadingParameter] - private HttpContext? HttpContext { get; set; } + [CascadingParameter] private HttpContext? HttpContext { get; set; } - private string? RequestId { get; set; } - private bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - - protected override void OnInitialized() => - RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; + protected override void OnInitialized() => _requestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier; } diff --git a/src/Flypaper.Web/Components/Pages/Login.razor b/src/Flypaper.Web/Components/Pages/Login.razor index c5269f5..54b17e3 100644 --- a/src/Flypaper.Web/Components/Pages/Login.razor +++ b/src/Flypaper.Web/Components/Pages/Login.razor @@ -2,7 +2,6 @@ @layout EmptyLayout @attribute [AllowAnonymous] @using Flypaper.Web.Auth -@using Microsoft.AspNetCore.Authorization @inject AdminAuthenticator Admin Flypaper · Anmelden diff --git a/src/Flypaper.Web/Components/Pages/NotFound.razor b/src/Flypaper.Web/Components/Pages/NotFound.razor index d8067ce..26c6df2 100644 --- a/src/Flypaper.Web/Components/Pages/NotFound.razor +++ b/src/Flypaper.Web/Components/Pages/NotFound.razor @@ -1,6 +1,8 @@ -@page "/not-found" +@page "/not-found" @layout EmptyLayout -@attribute [Microsoft.AspNetCore.Authorization.AllowAnonymous] +@attribute [AllowAnonymous] -

Not Found

-

Sorry, the content you are looking for does not exist.

\ No newline at end of file +Flypaper · Nicht gefunden + +

Nicht gefunden

+

Diese Seite gibt es nicht. Zum Dashboard

diff --git a/src/Flypaper.Web/Components/Pages/SettingsModel.cs b/src/Flypaper.Web/Components/Pages/Settings/SettingsModel.cs similarity index 86% rename from src/Flypaper.Web/Components/Pages/SettingsModel.cs rename to src/Flypaper.Web/Components/Pages/Settings/SettingsModel.cs index 23d7d0a..18a9d9c 100644 --- a/src/Flypaper.Web/Components/Pages/SettingsModel.cs +++ b/src/Flypaper.Web/Components/Pages/Settings/SettingsModel.cs @@ -1,4 +1,4 @@ -namespace Flypaper.Web.Components.Pages; +namespace Flypaper.Web.Components.Pages.Settings; public sealed class SettingsModel { diff --git a/src/Flypaper.Web/Components/Pages/Settings.razor b/src/Flypaper.Web/Components/Pages/Settings/SettingsPage.razor similarity index 99% rename from src/Flypaper.Web/Components/Pages/Settings.razor rename to src/Flypaper.Web/Components/Pages/Settings/SettingsPage.razor index 913d348..15eb946 100644 --- a/src/Flypaper.Web/Components/Pages/Settings.razor +++ b/src/Flypaper.Web/Components/Pages/Settings/SettingsPage.razor @@ -1,10 +1,11 @@ @page "/settings" -@using System.Globalization @using Flypaper.Core +@using Flypaper.Core.Settings @using Flypaper.Core.Strategies @using Flypaper.Http -@using Flypaper.Storage +@using Flypaper.Storage.Settings @using Flypaper.Web.Auth +@using System.Globalization @using Microsoft.Data.Sqlite @using Microsoft.Extensions.Options @inject IOptionsMonitor Core diff --git a/src/Flypaper.Web/Components/Routes.razor b/src/Flypaper.Web/Components/Routes.razor index 105855d..c73b27a 100644 --- a/src/Flypaper.Web/Components/Routes.razor +++ b/src/Flypaper.Web/Components/Routes.razor @@ -1,6 +1,5 @@ - + - diff --git a/src/Flypaper.Web/Components/Pages/FieldError.razor b/src/Flypaper.Web/Components/Shared/FieldError.razor similarity index 100% rename from src/Flypaper.Web/Components/Pages/FieldError.razor rename to src/Flypaper.Web/Components/Shared/FieldError.razor diff --git a/src/Flypaper.Web/Components/Shared/Formatting.cs b/src/Flypaper.Web/Components/Shared/Formatting.cs new file mode 100644 index 0000000..d51f289 --- /dev/null +++ b/src/Flypaper.Web/Components/Shared/Formatting.cs @@ -0,0 +1,12 @@ +namespace Flypaper.Web.Components.Shared; + +public static class Formatting +{ + public static string Duration(TimeSpan duration) => duration switch + { + { TotalDays: >= 1 } => $"{(int)duration.TotalDays} d {duration.Hours} h", + { TotalHours: >= 1 } => $"{duration.Hours} h {duration.Minutes} min", + { TotalMinutes: >= 1 } => $"{duration.Minutes} min {duration.Seconds} s", + _ => $"{duration.TotalSeconds:0.0} s" + }; +} diff --git a/src/Flypaper.Web/Components/_Imports.razor b/src/Flypaper.Web/Components/_Imports.razor index 3a3a828..a1e9451 100644 --- a/src/Flypaper.Web/Components/_Imports.razor +++ b/src/Flypaper.Web/Components/_Imports.razor @@ -1,11 +1,8 @@ -@using System.Net.Http -@using System.Net.Http.Json +@using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Components.Forms @using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Web -@using static Microsoft.AspNetCore.Components.Web.RenderMode -@using Microsoft.AspNetCore.Components.Web.Virtualization -@using Microsoft.JSInterop @using Flypaper.Web @using Flypaper.Web.Components @using Flypaper.Web.Components.Layout +@using Flypaper.Web.Components.Shared diff --git a/src/Flypaper.Web/Program.cs b/src/Flypaper.Web/Program.cs index b9e71de..65d51b8 100644 --- a/src/Flypaper.Web/Program.cs +++ b/src/Flypaper.Web/Program.cs @@ -5,6 +5,7 @@ using Flypaper.Web.Auth; using Flypaper.Web.Components; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.DataProtection; var builder = WebApplication.CreateBuilder(args); @@ -15,6 +16,12 @@ builder.Services.AddRazorComponents(); builder.Services.AddFlypaperCore(builder.Configuration); builder.Services.AddFlypaperHttp(builder.Configuration); +var dataProtection = builder.Services.AddDataProtection().SetApplicationName("Flypaper"); +if (builder.Configuration["Flypaper:DataProtection:KeysPath"] is { Length: > 0 } keysPath) +{ + dataProtection.PersistKeysToFileSystem(new DirectoryInfo(keysPath)); +} + builder.Services.Configure(builder.Configuration.GetSection(AdminOptions.SectionName)); builder.Services.AddSingleton(); builder.Services diff --git a/test/Flypaper.Tests/ConnectionGovernorTests.cs b/test/Flypaper.Tests/Core/ConnectionGovernorTests.cs similarity index 95% rename from test/Flypaper.Tests/ConnectionGovernorTests.cs rename to test/Flypaper.Tests/Core/ConnectionGovernorTests.cs index e0981d6..e4460b7 100644 --- a/test/Flypaper.Tests/ConnectionGovernorTests.cs +++ b/test/Flypaper.Tests/Core/ConnectionGovernorTests.cs @@ -1,8 +1,11 @@ using System.Net; using Flypaper.Core; +using Flypaper.Core.Models; +using Flypaper.Core.Runtime; +using Flypaper.Tests.Fakes; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Core; public sealed class ConnectionGovernorTests { diff --git a/test/Flypaper.Tests/DripStrategyTests.cs b/test/Flypaper.Tests/Core/DripStrategyTests.cs similarity index 94% rename from test/Flypaper.Tests/DripStrategyTests.cs rename to test/Flypaper.Tests/Core/DripStrategyTests.cs index 010702a..999ed95 100644 --- a/test/Flypaper.Tests/DripStrategyTests.cs +++ b/test/Flypaper.Tests/Core/DripStrategyTests.cs @@ -1,8 +1,9 @@ -using Flypaper.Core; +using Flypaper.Core.Models; using Flypaper.Core.Strategies; +using Flypaper.Tests.Fakes; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Core; public sealed class DripStrategyTests { diff --git a/test/Flypaper.Tests/RuntimeSettingsParserTests.cs b/test/Flypaper.Tests/Core/RuntimeSettingsParserTests.cs similarity index 98% rename from test/Flypaper.Tests/RuntimeSettingsParserTests.cs rename to test/Flypaper.Tests/Core/RuntimeSettingsParserTests.cs index ed54900..57756a2 100644 --- a/test/Flypaper.Tests/RuntimeSettingsParserTests.cs +++ b/test/Flypaper.Tests/Core/RuntimeSettingsParserTests.cs @@ -1,7 +1,7 @@ -using Flypaper.Core; +using Flypaper.Core.Settings; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Core; public sealed class RuntimeSettingsParserTests { diff --git a/test/Flypaper.Tests/TrapRunnerTests.cs b/test/Flypaper.Tests/Core/TrapRunnerTests.cs similarity index 95% rename from test/Flypaper.Tests/TrapRunnerTests.cs rename to test/Flypaper.Tests/Core/TrapRunnerTests.cs index af73739..746ae72 100644 --- a/test/Flypaper.Tests/TrapRunnerTests.cs +++ b/test/Flypaper.Tests/Core/TrapRunnerTests.cs @@ -1,11 +1,15 @@ using System.Net; using Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; +using Flypaper.Core.Runtime; using Flypaper.Core.Strategies; +using Flypaper.Tests.Fakes; using Microsoft.Extensions.Logging.Abstractions; using NSubstitute; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Core; public sealed class TrapRunnerTests { diff --git a/test/Flypaper.Tests/FakeTrapChannel.cs b/test/Flypaper.Tests/Fakes/FakeTrapChannel.cs similarity index 84% rename from test/Flypaper.Tests/FakeTrapChannel.cs rename to test/Flypaper.Tests/Fakes/FakeTrapChannel.cs index 7d50060..d4e1f50 100644 --- a/test/Flypaper.Tests/FakeTrapChannel.cs +++ b/test/Flypaper.Tests/Fakes/FakeTrapChannel.cs @@ -1,8 +1,9 @@ using System.Collections.Concurrent; using System.Net; -using Flypaper.Core; +using Flypaper.Core.Abstractions; +using Flypaper.Core.Models; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Fakes; internal sealed class FakeTrapChannel : ITrapChannel { diff --git a/test/Flypaper.Tests/TestOptions.cs b/test/Flypaper.Tests/Fakes/TestOptions.cs similarity index 90% rename from test/Flypaper.Tests/TestOptions.cs rename to test/Flypaper.Tests/Fakes/TestOptions.cs index bad9f54..efc40c4 100644 --- a/test/Flypaper.Tests/TestOptions.cs +++ b/test/Flypaper.Tests/Fakes/TestOptions.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Options; using NSubstitute; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Fakes; internal static class TestOptions { diff --git a/test/Flypaper.Tests/ForwardedHeadersTests.cs b/test/Flypaper.Tests/Http/ForwardedHeadersTests.cs similarity index 97% rename from test/Flypaper.Tests/ForwardedHeadersTests.cs rename to test/Flypaper.Tests/Http/ForwardedHeadersTests.cs index 318caad..c761a3f 100644 --- a/test/Flypaper.Tests/ForwardedHeadersTests.cs +++ b/test/Flypaper.Tests/Http/ForwardedHeadersTests.cs @@ -1,5 +1,6 @@ using System.Net; using Flypaper.Core; +using Flypaper.Core.Abstractions; using Flypaper.Http; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; @@ -8,7 +9,7 @@ using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Http; public sealed class ForwardedHeadersTests { diff --git a/test/Flypaper.Tests/TrapMatcherTests.cs b/test/Flypaper.Tests/Http/TrapMatcherTests.cs similarity index 93% rename from test/Flypaper.Tests/TrapMatcherTests.cs rename to test/Flypaper.Tests/Http/TrapMatcherTests.cs index 7eb38d6..a72fc6e 100644 --- a/test/Flypaper.Tests/TrapMatcherTests.cs +++ b/test/Flypaper.Tests/Http/TrapMatcherTests.cs @@ -1,7 +1,9 @@ using Flypaper.Http; +using Flypaper.Http.Matching; +using Flypaper.Tests.Fakes; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Http; public sealed class TrapMatcherTests { diff --git a/test/Flypaper.Tests/SettingsOverrideTests.cs b/test/Flypaper.Tests/Storage/SettingsOverrideTests.cs similarity index 97% rename from test/Flypaper.Tests/SettingsOverrideTests.cs rename to test/Flypaper.Tests/Storage/SettingsOverrideTests.cs index be30ee3..8929a6a 100644 --- a/test/Flypaper.Tests/SettingsOverrideTests.cs +++ b/test/Flypaper.Tests/Storage/SettingsOverrideTests.cs @@ -1,7 +1,11 @@ using Flypaper.Core; +using Flypaper.Core.Settings; using Flypaper.Core.Strategies; using Flypaper.Http; +using Flypaper.Http.Matching; using Flypaper.Storage; +using Flypaper.Storage.Entities; +using Flypaper.Storage.Settings; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -10,7 +14,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Shouldly; -namespace Flypaper.Tests; +namespace Flypaper.Tests.Storage; public sealed class SettingsOverrideTests : IDisposable {