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
+221
-153
No files matched your search
+2
-1
@@ -17,7 +17,8 @@ WORKDIR /app
|
|||||||
RUN mkdir /data && chown $APP_UID /data
|
RUN mkdir /data && chown $APP_UID /data
|
||||||
|
|
||||||
ENV ASPNETCORE_HTTP_PORTS=8080 \
|
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 .
|
COPY --from=build /app .
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -1,8 +1,11 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Abstractions;
|
||||||
|
|
||||||
public interface IConnectionGovernor
|
public interface IConnectionGovernor
|
||||||
{
|
{
|
||||||
|
int ActiveConnections { get; }
|
||||||
|
|
||||||
bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease);
|
bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease);
|
||||||
}
|
}
|
||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
namespace Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
|
|
||||||
|
namespace Flypaper.Core.Abstractions;
|
||||||
|
|
||||||
public interface ITarpitStrategy
|
public interface ITarpitStrategy
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
|
|
||||||
|
namespace Flypaper.Core.Abstractions;
|
||||||
|
|
||||||
public interface ITrapChannel
|
public interface ITrapChannel
|
||||||
{
|
{
|
||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
namespace Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
|
|
||||||
|
namespace Flypaper.Core.Abstractions;
|
||||||
|
|
||||||
public interface ITrapEventSink
|
public interface ITrapEventSink
|
||||||
{
|
{
|
||||||
+4
-3
@@ -1,3 +1,5 @@
|
|||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Flypaper.Core.Runtime;
|
||||||
using Flypaper.Core.Strategies;
|
using Flypaper.Core.Strategies;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -5,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core;
|
||||||
|
|
||||||
public static class ServiceCollectionExtensions
|
public static class FlypaperCoreExtensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddFlypaperCore(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddFlypaperCore(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
@@ -13,8 +15,7 @@ public static class ServiceCollectionExtensions
|
|||||||
services.Configure<DripOptions>(configuration.GetSection(DripOptions.SectionName));
|
services.Configure<DripOptions>(configuration.GetSection(DripOptions.SectionName));
|
||||||
|
|
||||||
services.TryAddSingleton(TimeProvider.System);
|
services.TryAddSingleton(TimeProvider.System);
|
||||||
services.TryAddSingleton<ConnectionGovernor>();
|
services.TryAddSingleton<IConnectionGovernor, ConnectionGovernor>();
|
||||||
services.TryAddSingleton<IConnectionGovernor>(sp => sp.GetRequiredService<ConnectionGovernor>());
|
|
||||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, DripStrategy>());
|
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, DripStrategy>());
|
||||||
services.TryAddSingleton<TrapRunner>();
|
services.TryAddSingleton<TrapRunner>();
|
||||||
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Models;
|
||||||
|
|
||||||
public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null);
|
public sealed record TrapContext(TrapSession Session, string? Target = null, string? ClientInfo = null);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Models;
|
||||||
|
|
||||||
public sealed record TrapEvent(
|
public sealed record TrapEvent(
|
||||||
Guid SessionId,
|
Guid SessionId,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Models;
|
||||||
|
|
||||||
public enum TrapOutcome
|
public enum TrapOutcome
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Models;
|
||||||
|
|
||||||
public enum TrapProtocol
|
public enum TrapProtocol
|
||||||
{
|
{
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
+4
-4
@@ -1,8 +1,10 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Runtime;
|
||||||
|
|
||||||
public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options) : IConnectionGovernor
|
public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options) : IConnectionGovernor
|
||||||
{
|
{
|
||||||
@@ -23,7 +25,7 @@ public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options)
|
|||||||
|
|
||||||
public bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease)
|
public bool TryAcquire(TrapSession session, [NotNullWhen(true)] out IDisposable? lease)
|
||||||
{
|
{
|
||||||
var ip = Normalize(session.RemoteIp);
|
var ip = session.RemoteIp;
|
||||||
var limits = options.CurrentValue;
|
var limits = options.CurrentValue;
|
||||||
|
|
||||||
lock (_gate)
|
lock (_gate)
|
||||||
@@ -55,8 +57,6 @@ public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> options)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IPAddress Normalize(IPAddress ip) => ip.IsIPv4MappedToIPv6 ? ip.MapToIPv4() : ip;
|
|
||||||
|
|
||||||
private sealed class Lease(ConnectionGovernor owner, IPAddress ip) : IDisposable
|
private sealed class Lease(ConnectionGovernor owner, IPAddress ip) : IDisposable
|
||||||
{
|
{
|
||||||
private int _disposed;
|
private int _disposed;
|
||||||
+4
-1
@@ -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
|
internal sealed class CountingTrapChannel(ITrapChannel inner) : ITrapChannel
|
||||||
{
|
{
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Runtime;
|
||||||
|
|
||||||
public sealed partial class TrapRunner(
|
public sealed partial class TrapRunner(
|
||||||
IConnectionGovernor governor,
|
IConnectionGovernor governor,
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Settings;
|
||||||
|
|
||||||
public sealed record RuntimeSettings(
|
public sealed record RuntimeSettings(
|
||||||
IReadOnlyList<string> TrapPaths,
|
IReadOnlyList<string> TrapPaths,
|
||||||
+1
-3
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Settings;
|
||||||
|
|
||||||
public sealed record RuntimeSettingsInput(
|
public sealed record RuntimeSettingsInput(
|
||||||
string? TrapPaths,
|
string? TrapPaths,
|
||||||
@@ -7,5 +7,3 @@ public sealed record RuntimeSettingsInput(
|
|||||||
string? MaxConnectionsPerIp,
|
string? MaxConnectionsPerIp,
|
||||||
string? MaxHoldDuration,
|
string? MaxHoldDuration,
|
||||||
string? ExtraKnownHosts);
|
string? ExtraKnownHosts);
|
||||||
|
|
||||||
public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Flypaper.Core.Settings;
|
||||||
|
|
||||||
|
public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary<string, string> Errors);
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Settings;
|
||||||
|
|
||||||
public static partial class RuntimeSettingsParser
|
public static partial class RuntimeSettingsParser
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Settings;
|
||||||
|
|
||||||
public static class SettingKeys
|
public static class SettingKeys
|
||||||
{
|
{
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Core;
|
namespace Flypaper.Core.Settings;
|
||||||
|
|
||||||
public static class SettingsList
|
public static class SettingsList
|
||||||
{
|
{
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Flypaper.Core.Strategies;
|
namespace Flypaper.Core.Strategies;
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
using System.Net;
|
|
||||||
|
|
||||||
namespace Flypaper.Core;
|
|
||||||
|
|
||||||
public sealed record TrapSession(Guid Id, TrapProtocol Protocol, IPAddress RemoteIp, DateTimeOffset StartedAt);
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
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.Builder;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Flypaper.Http;
|
namespace Flypaper.Http;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Http;
|
namespace Flypaper.Http.Matching;
|
||||||
|
|
||||||
public enum TrapMatch
|
public enum TrapMatch
|
||||||
{
|
{
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Flypaper.Http;
|
namespace Flypaper.Http.Matching;
|
||||||
|
|
||||||
public sealed class TrapMatcher : IDisposable
|
public sealed class TrapMatcher : IDisposable
|
||||||
{
|
{
|
||||||
+6
-4
@@ -1,10 +1,13 @@
|
|||||||
using System.Net;
|
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;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
|
||||||
|
|
||||||
namespace Flypaper.Http;
|
namespace Flypaper.Http.Middleware;
|
||||||
|
|
||||||
internal sealed class FlypaperMiddleware(
|
internal sealed class FlypaperMiddleware(
|
||||||
RequestDelegate next,
|
RequestDelegate next,
|
||||||
@@ -21,11 +24,10 @@ internal sealed class FlypaperMiddleware(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var remoteIp = context.Connection.RemoteIpAddress ?? IPAddress.None;
|
|
||||||
var session = new TrapSession(
|
var session = new TrapSession(
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
TrapProtocol.Http,
|
TrapProtocol.Http,
|
||||||
remoteIp.IsIPv4MappedToIPv6 ? remoteIp.MapToIPv4() : remoteIp,
|
context.Connection.RemoteIpAddress ?? IPAddress.None,
|
||||||
timeProvider.GetUtcNow());
|
timeProvider.GetUtcNow());
|
||||||
|
|
||||||
var trapContext = new TrapContext(
|
var trapContext = new TrapContext(
|
||||||
+1
-1
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Builder;
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Flypaper.Http;
|
namespace Flypaper.Http.Middleware;
|
||||||
|
|
||||||
internal sealed class RealIpMiddleware(RequestDelegate next, IOptions<ForwardedHeadersOptions> options)
|
internal sealed class RealIpMiddleware(RequestDelegate next, IOptions<ForwardedHeadersOptions> options)
|
||||||
{
|
{
|
||||||
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
namespace Flypaper.Storage;
|
using Flypaper.Storage.Entities;
|
||||||
|
|
||||||
|
namespace Flypaper.Storage.Dashboard;
|
||||||
|
|
||||||
public sealed record DashboardData(
|
public sealed record DashboardData(
|
||||||
int TotalCatches,
|
int TotalCatches,
|
||||||
+4
-10
@@ -1,7 +1,8 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
|
using Flypaper.Storage.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Dashboard;
|
||||||
|
|
||||||
public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbContextFactory, TimeProvider timeProvider)
|
public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbContextFactory, TimeProvider timeProvider)
|
||||||
{
|
{
|
||||||
@@ -15,20 +16,13 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
|
|||||||
var catches = events.Where(e => e.Outcome != TrapOutcome.Rejected);
|
var catches = events.Where(e => e.Outcome != TrapOutcome.Rejected);
|
||||||
var since = timeProvider.GetUtcNow().UtcDateTime.AddHours(-24);
|
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(
|
return new DashboardData(
|
||||||
await catches.CountAsync(ct),
|
await catches.CountAsync(ct),
|
||||||
await catches.CountAsync(e => e.StartedAt >= since, ct),
|
await catches.CountAsync(e => e.StartedAt >= since, ct),
|
||||||
await events.CountAsync(e => e.Outcome == TrapOutcome.Rejected, ct),
|
await events.CountAsync(e => e.Outcome == TrapOutcome.Rejected, ct),
|
||||||
await events.Select(e => e.RemoteIp).Distinct().CountAsync(ct),
|
await events.Select(e => e.RemoteIp).Distinct().CountAsync(ct),
|
||||||
TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, 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.GroupBy(e => e.RemoteIp), ct),
|
||||||
await TopAsync(catches.Where(e => e.Target != null).GroupBy(e => e.Target!), ct));
|
await TopAsync(catches.Where(e => e.Target != null).GroupBy(e => e.Target!), ct));
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Entities;
|
||||||
|
|
||||||
public sealed class SettingEntity
|
public sealed class SettingEntity
|
||||||
{
|
{
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Entities;
|
||||||
|
|
||||||
public sealed class TrapEventEntity
|
public sealed class TrapEventEntity
|
||||||
{
|
{
|
||||||
@@ -44,5 +44,5 @@ public sealed class TrapEventEntity
|
|||||||
};
|
};
|
||||||
|
|
||||||
private static string? Truncate(string? value, int maxLength) =>
|
private static string? Truncate(string? value, int maxLength) =>
|
||||||
value is { Length: > 0 } && value.Length > maxLength ? value[..maxLength] : value;
|
value?.Length > maxLength ? value[..maxLength] : value;
|
||||||
}
|
}
|
||||||
+3
-2
@@ -1,7 +1,8 @@
|
|||||||
using System.Threading.Channels;
|
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
|
public sealed class ChannelTrapEventSink : ITrapEventSink
|
||||||
{
|
{
|
||||||
+3
-2
@@ -1,9 +1,10 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
|
using Flypaper.Storage.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Events;
|
||||||
|
|
||||||
internal sealed class TrapEventWriter(
|
internal sealed class TrapEventWriter(
|
||||||
ChannelTrapEventSink sink,
|
ChannelTrapEventSink sink,
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Flypaper.Storage.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage;
|
||||||
@@ -10,6 +11,9 @@ public sealed class FlypaperDbContext(DbContextOptions<FlypaperDbContext> option
|
|||||||
|
|
||||||
public DbSet<SettingEntity> Settings => Set<SettingEntity>();
|
public DbSet<SettingEntity> Settings => Set<SettingEntity>();
|
||||||
|
|
||||||
|
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) =>
|
||||||
|
configurationBuilder.Properties<DateTime>().HaveConversion<UtcDateTimeConverter>();
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
var trapEvent = modelBuilder.Entity<TrapEventEntity>();
|
var trapEvent = modelBuilder.Entity<TrapEventEntity>();
|
||||||
|
|||||||
@@ -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.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -39,6 +42,6 @@ public static class FlypaperStorageExtensions
|
|||||||
await db.Database.MigrateAsync(ct);
|
await db.Database.MigrateAsync(ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
services.GetService<DbConfigurationSource>()?.Reload();
|
services.GetService<DbConfigurationSource>()?.TryReload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+20
-13
@@ -1,22 +1,27 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Settings;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Settings;
|
||||||
|
|
||||||
internal sealed class DbConfigurationProvider(string connectionString) : ConfigurationProvider
|
internal sealed class DbConfigurationProvider(string connectionString) : ConfigurationProvider
|
||||||
{
|
{
|
||||||
public override void Load() => Data = Read();
|
public override void Load() => Data = TryRead() ?? new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
public void Reload()
|
public bool TryReload()
|
||||||
{
|
{
|
||||||
Load();
|
if (TryRead() is not { } data)
|
||||||
OnReload();
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, string?> Read()
|
Data = data;
|
||||||
|
OnReload();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, string?>? TryRead()
|
||||||
{
|
{
|
||||||
var data = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
var builder = new SqliteConnectionStringBuilder(connectionString) { Mode = SqliteOpenMode.ReadOnly };
|
var builder = new SqliteConnectionStringBuilder(connectionString) { Mode = SqliteOpenMode.ReadOnly };
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -26,6 +31,8 @@ internal sealed class DbConfigurationProvider(string connectionString) : Configu
|
|||||||
using var command = connection.CreateCommand();
|
using var command = connection.CreateCommand();
|
||||||
command.CommandText = "SELECT \"Key\", \"Value\" FROM \"Settings\"";
|
command.CommandText = "SELECT \"Key\", \"Value\" FROM \"Settings\"";
|
||||||
using var reader = command.ExecuteReader();
|
using var reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
var data = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
var key = reader.GetString(0);
|
var key = reader.GetString(0);
|
||||||
@@ -34,12 +41,12 @@ internal sealed class DbConfigurationProvider(string connectionString) : Configu
|
|||||||
data[key] = reader.GetString(1);
|
data[key] = reader.GetString(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (SqliteException)
|
|
||||||
{
|
|
||||||
data.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
catch (SqliteException)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Settings;
|
||||||
|
|
||||||
public sealed class DbConfigurationSource(string connectionString) : IConfigurationSource
|
public sealed class DbConfigurationSource(string connectionString) : IConfigurationSource
|
||||||
{
|
{
|
||||||
@@ -9,5 +9,5 @@ public sealed class DbConfigurationSource(string connectionString) : IConfigurat
|
|||||||
public IConfigurationProvider Build(IConfigurationBuilder builder) =>
|
public IConfigurationProvider Build(IConfigurationBuilder builder) =>
|
||||||
_provider = new DbConfigurationProvider(connectionString);
|
_provider = new DbConfigurationProvider(connectionString);
|
||||||
|
|
||||||
public void Reload() => _provider?.Reload();
|
public bool TryReload() => _provider?.TryReload() ?? false;
|
||||||
}
|
}
|
||||||
+21
-5
@@ -1,9 +1,14 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Settings;
|
||||||
|
using Flypaper.Storage.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Flypaper.Storage;
|
namespace Flypaper.Storage.Settings;
|
||||||
|
|
||||||
public sealed class RuntimeSettingsStore(IDbContextFactory<FlypaperDbContext> dbContextFactory, DbConfigurationSource source)
|
public sealed partial class RuntimeSettingsStore(
|
||||||
|
IDbContextFactory<FlypaperDbContext> dbContextFactory,
|
||||||
|
DbConfigurationSource source,
|
||||||
|
ILogger<RuntimeSettingsStore> logger)
|
||||||
{
|
{
|
||||||
public async Task SaveAsync(RuntimeSettings settings, CancellationToken ct = default)
|
public async Task SaveAsync(RuntimeSettings settings, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
@@ -13,14 +18,14 @@ public sealed class RuntimeSettingsStore(IDbContextFactory<FlypaperDbContext> db
|
|||||||
db.Settings.AddRange(settings.ToConfiguration().Select(pair => new SettingEntity { Key = pair.Key, Value = pair.Value }));
|
db.Settings.AddRange(settings.ToConfiguration().Select(pair => new SettingEntity { Key = pair.Key, Value = pair.Value }));
|
||||||
await db.SaveChangesAsync(ct);
|
await db.SaveChangesAsync(ct);
|
||||||
await transaction.CommitAsync(ct);
|
await transaction.CommitAsync(ct);
|
||||||
source.Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ResetAsync(CancellationToken ct = default)
|
public async Task ResetAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
||||||
await db.Settings.ExecuteDeleteAsync(ct);
|
await db.Settings.ExecuteDeleteAsync(ct);
|
||||||
source.Reload();
|
Reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> HasOverridesAsync(CancellationToken ct = default)
|
public async Task<bool> HasOverridesAsync(CancellationToken ct = default)
|
||||||
@@ -28,4 +33,15 @@ public sealed class RuntimeSettingsStore(IDbContextFactory<FlypaperDbContext> db
|
|||||||
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
||||||
return await db.Settings.AnyAsync(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();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace Flypaper.Storage;
|
||||||
|
|
||||||
|
internal sealed class UtcDateTimeConverter() : ValueConverter<DateTime, DateTime>(
|
||||||
|
value => value.Kind == DateTimeKind.Utc ? value : value.ToUniversalTime(),
|
||||||
|
value => DateTime.SpecifyKind(value, DateTimeKind.Utc));
|
||||||
@@ -1,14 +1,11 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
<ResourcePreloader />
|
|
||||||
<link rel="stylesheet" href="@Assets["app.css"]" />
|
<link rel="stylesheet" href="@Assets["app.css"]" />
|
||||||
<link rel="stylesheet" href="@Assets["Flypaper.Web.styles.css"]" />
|
|
||||||
<ImportMap />
|
|
||||||
<HeadOutlet />
|
<HeadOutlet />
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
+5
-13
@@ -1,8 +1,8 @@
|
|||||||
@page "/"
|
@page "/"
|
||||||
@using Flypaper.Core
|
@using Flypaper.Core.Abstractions
|
||||||
@using Flypaper.Storage
|
@using Flypaper.Storage.Dashboard
|
||||||
@inject DashboardQueries Queries
|
@inject DashboardQueries Queries
|
||||||
@inject ConnectionGovernor Governor
|
@inject IConnectionGovernor Governor
|
||||||
|
|
||||||
<PageTitle>Flypaper</PageTitle>
|
<PageTitle>Flypaper</PageTitle>
|
||||||
<HeadContent>
|
<HeadContent>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<div class="metric"><span class="label">Letzte 24 h</span><span class="value">@data.CatchesLast24Hours.ToString("N0")</span></div>
|
<div class="metric"><span class="label">Letzte 24 h</span><span class="value">@data.CatchesLast24Hours.ToString("N0")</span></div>
|
||||||
<div class="metric"><span class="label">Aktiv</span><span class="value">@Governor.ActiveConnections.ToString("N0")</span></div>
|
<div class="metric"><span class="label">Aktiv</span><span class="value">@Governor.ActiveConnections.ToString("N0")</span></div>
|
||||||
<div class="metric"><span class="label">Eindeutige IPs</span><span class="value">@data.UniqueIps.ToString("N0")</span></div>
|
<div class="metric"><span class="label">Eindeutige IPs</span><span class="value">@data.UniqueIps.ToString("N0")</span></div>
|
||||||
<div class="metric"><span class="label">Haltezeit gesamt</span><span class="value">@FormatDuration(data.TotalHoldTime)</span></div>
|
<div class="metric"><span class="label">Haltezeit gesamt</span><span class="value">@Formatting.Duration(data.TotalHoldTime)</span></div>
|
||||||
<div class="metric"><span class="label">Abgelehnt</span><span class="value">@data.Rejected.ToString("N0")</span></div>
|
<div class="metric"><span class="label">Abgelehnt</span><span class="value">@data.Rejected.ToString("N0")</span></div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<td class="mono">@trapEvent.RemoteIp</td>
|
<td class="mono">@trapEvent.RemoteIp</td>
|
||||||
<td class="mono clip" title="@trapEvent.Target">@trapEvent.Target</td>
|
<td class="mono clip" title="@trapEvent.Target">@trapEvent.Target</td>
|
||||||
<td class="clip" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
<td class="clip" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
||||||
<td class="num">@FormatDuration(TimeSpan.FromMilliseconds(trapEvent.DurationMs))</td>
|
<td class="num">@Formatting.Duration(TimeSpan.FromMilliseconds(trapEvent.DurationMs))</td>
|
||||||
<td class="num">@trapEvent.BytesSent.ToString("N0")</td>
|
<td class="num">@trapEvent.BytesSent.ToString("N0")</td>
|
||||||
<td><span class="outcome @trapEvent.Outcome.ToString().ToLowerInvariant()">@trapEvent.Outcome</span></td>
|
<td><span class="outcome @trapEvent.Outcome.ToString().ToLowerInvariant()">@trapEvent.Outcome</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -80,12 +80,4 @@
|
|||||||
_data = await Queries.GetAsync();
|
_data = await Queries.GetAsync();
|
||||||
_loadedAt = DateTime.Now;
|
_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"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
+2
-3
@@ -1,5 +1,4 @@
|
|||||||
@using Flypaper.Storage
|
@using Flypaper.Storage.Dashboard
|
||||||
|
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<h2>@Title</h2>
|
<h2>@Title</h2>
|
||||||
@if (Entries.Count == 0)
|
@if (Entries.Count == 0)
|
||||||
@@ -22,7 +21,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="mono clip" title="@entry.Key">@entry.Key</td>
|
<td class="mono clip" title="@entry.Key">@entry.Key</td>
|
||||||
<td class="num">@entry.Count.ToString("N0")</td>
|
<td class="num">@entry.Count.ToString("N0")</td>
|
||||||
<td class="num">@Home.FormatDuration(entry.HoldTime)</td>
|
<td class="num">@Formatting.Duration(entry.HoldTime)</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -1,36 +1,21 @@
|
|||||||
@page "/Error"
|
@page "/Error"
|
||||||
|
@layout EmptyLayout
|
||||||
|
@attribute [AllowAnonymous]
|
||||||
@using System.Diagnostics
|
@using System.Diagnostics
|
||||||
|
|
||||||
<PageTitle>Error</PageTitle>
|
<PageTitle>Flypaper · Fehler</PageTitle>
|
||||||
|
|
||||||
<h1 class="text-danger">Error.</h1>
|
<h1 class="login-title">Fehler</h1>
|
||||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
<p>Bei der Verarbeitung der Anfrage ist ein Fehler aufgetreten.</p>
|
||||||
|
@if (!string.IsNullOrEmpty(_requestId))
|
||||||
@if (ShowRequestId)
|
|
||||||
{
|
{
|
||||||
<p>
|
<p class="muted">Request-ID: <code>@_requestId</code></p>
|
||||||
<strong>Request ID:</strong> <code>@RequestId</code>
|
|
||||||
</p>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<h3>Development Mode</h3>
|
|
||||||
<p>
|
|
||||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
|
||||||
It can result in displaying sensitive information from exceptions to end users.
|
|
||||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
|
||||||
and restarting the app.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[CascadingParameter]
|
private string? _requestId;
|
||||||
private HttpContext? HttpContext { get; set; }
|
|
||||||
|
|
||||||
private string? RequestId { get; set; }
|
[CascadingParameter] private HttpContext? HttpContext { get; set; }
|
||||||
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
|
||||||
|
|
||||||
protected override void OnInitialized() =>
|
protected override void OnInitialized() => _requestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
|
||||||
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
@layout EmptyLayout
|
@layout EmptyLayout
|
||||||
@attribute [AllowAnonymous]
|
@attribute [AllowAnonymous]
|
||||||
@using Flypaper.Web.Auth
|
@using Flypaper.Web.Auth
|
||||||
@using Microsoft.AspNetCore.Authorization
|
|
||||||
@inject AdminAuthenticator Admin
|
@inject AdminAuthenticator Admin
|
||||||
|
|
||||||
<PageTitle>Flypaper · Anmelden</PageTitle>
|
<PageTitle>Flypaper · Anmelden</PageTitle>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
@page "/not-found"
|
@page "/not-found"
|
||||||
@layout EmptyLayout
|
@layout EmptyLayout
|
||||||
@attribute [Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
@attribute [AllowAnonymous]
|
||||||
|
|
||||||
<h3>Not Found</h3>
|
<PageTitle>Flypaper · Nicht gefunden</PageTitle>
|
||||||
<p>Sorry, the content you are looking for does not exist.</p>
|
|
||||||
|
<h1 class="login-title">Nicht gefunden</h1>
|
||||||
|
<p class="muted">Diese Seite gibt es nicht. <a href="/">Zum Dashboard</a></p>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
namespace Flypaper.Web.Components.Pages;
|
namespace Flypaper.Web.Components.Pages.Settings;
|
||||||
|
|
||||||
public sealed class SettingsModel
|
public sealed class SettingsModel
|
||||||
{
|
{
|
||||||
+3
-2
@@ -1,10 +1,11 @@
|
|||||||
@page "/settings"
|
@page "/settings"
|
||||||
@using System.Globalization
|
|
||||||
@using Flypaper.Core
|
@using Flypaper.Core
|
||||||
|
@using Flypaper.Core.Settings
|
||||||
@using Flypaper.Core.Strategies
|
@using Flypaper.Core.Strategies
|
||||||
@using Flypaper.Http
|
@using Flypaper.Http
|
||||||
@using Flypaper.Storage
|
@using Flypaper.Storage.Settings
|
||||||
@using Flypaper.Web.Auth
|
@using Flypaper.Web.Auth
|
||||||
|
@using System.Globalization
|
||||||
@using Microsoft.Data.Sqlite
|
@using Microsoft.Data.Sqlite
|
||||||
@using Microsoft.Extensions.Options
|
@using Microsoft.Extensions.Options
|
||||||
@inject IOptionsMonitor<FlypaperOptions> Core
|
@inject IOptionsMonitor<FlypaperOptions> Core
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
|
<Router AppAssembly="typeof(Program).Assembly" NotFoundPage="typeof(Pages.NotFound)">
|
||||||
<Found Context="routeData">
|
<Found Context="routeData">
|
||||||
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
|
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
|
||||||
<FocusOnNavigate RouteData="routeData" Selector="h1" />
|
|
||||||
</Found>
|
</Found>
|
||||||
</Router>
|
</Router>
|
||||||
File renamed without changes.
@@ -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"
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
@using System.Net.Http
|
@using Microsoft.AspNetCore.Authorization
|
||||||
@using System.Net.Http.Json
|
|
||||||
@using Microsoft.AspNetCore.Components.Forms
|
@using Microsoft.AspNetCore.Components.Forms
|
||||||
@using Microsoft.AspNetCore.Components.Routing
|
@using Microsoft.AspNetCore.Components.Routing
|
||||||
@using Microsoft.AspNetCore.Components.Web
|
@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
|
||||||
@using Flypaper.Web.Components
|
@using Flypaper.Web.Components
|
||||||
@using Flypaper.Web.Components.Layout
|
@using Flypaper.Web.Components.Layout
|
||||||
|
@using Flypaper.Web.Components.Shared
|
||||||
@@ -5,6 +5,7 @@ using Flypaper.Web.Auth;
|
|||||||
using Flypaper.Web.Components;
|
using Flypaper.Web.Components;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -15,6 +16,12 @@ builder.Services.AddRazorComponents();
|
|||||||
builder.Services.AddFlypaperCore(builder.Configuration);
|
builder.Services.AddFlypaperCore(builder.Configuration);
|
||||||
builder.Services.AddFlypaperHttp(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<AdminOptions>(builder.Configuration.GetSection(AdminOptions.SectionName));
|
builder.Services.Configure<AdminOptions>(builder.Configuration.GetSection(AdminOptions.SectionName));
|
||||||
builder.Services.AddSingleton<AdminAuthenticator>();
|
builder.Services.AddSingleton<AdminAuthenticator>();
|
||||||
builder.Services
|
builder.Services
|
||||||
|
|||||||
+4
-1
@@ -1,8 +1,11 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Flypaper.Core;
|
using Flypaper.Core;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
|
using Flypaper.Core.Runtime;
|
||||||
|
using Flypaper.Tests.Fakes;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Core;
|
||||||
|
|
||||||
public sealed class ConnectionGovernorTests
|
public sealed class ConnectionGovernorTests
|
||||||
{
|
{
|
||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Models;
|
||||||
using Flypaper.Core.Strategies;
|
using Flypaper.Core.Strategies;
|
||||||
|
using Flypaper.Tests.Fakes;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Core;
|
||||||
|
|
||||||
public sealed class DripStrategyTests
|
public sealed class DripStrategyTests
|
||||||
{
|
{
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core.Settings;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Core;
|
||||||
|
|
||||||
public sealed class RuntimeSettingsParserTests
|
public sealed class RuntimeSettingsParserTests
|
||||||
{
|
{
|
||||||
+5
-1
@@ -1,11 +1,15 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Flypaper.Core;
|
using Flypaper.Core;
|
||||||
|
using Flypaper.Core.Abstractions;
|
||||||
|
using Flypaper.Core.Models;
|
||||||
|
using Flypaper.Core.Runtime;
|
||||||
using Flypaper.Core.Strategies;
|
using Flypaper.Core.Strategies;
|
||||||
|
using Flypaper.Tests.Fakes;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Core;
|
||||||
|
|
||||||
public sealed class TrapRunnerTests
|
public sealed class TrapRunnerTests
|
||||||
{
|
{
|
||||||
+3
-2
@@ -1,8 +1,9 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Net;
|
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
|
internal sealed class FakeTrapChannel : ITrapChannel
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Fakes;
|
||||||
|
|
||||||
internal static class TestOptions
|
internal static class TestOptions
|
||||||
{
|
{
|
||||||
+2
-1
@@ -1,5 +1,6 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Flypaper.Core;
|
using Flypaper.Core;
|
||||||
|
using Flypaper.Core.Abstractions;
|
||||||
using Flypaper.Http;
|
using Flypaper.Http;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@@ -8,7 +9,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Http;
|
||||||
|
|
||||||
public sealed class ForwardedHeadersTests
|
public sealed class ForwardedHeadersTests
|
||||||
{
|
{
|
||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
using Flypaper.Http;
|
using Flypaper.Http;
|
||||||
|
using Flypaper.Http.Matching;
|
||||||
|
using Flypaper.Tests.Fakes;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Http;
|
||||||
|
|
||||||
public sealed class TrapMatcherTests
|
public sealed class TrapMatcherTests
|
||||||
{
|
{
|
||||||
+5
-1
@@ -1,7 +1,11 @@
|
|||||||
using Flypaper.Core;
|
using Flypaper.Core;
|
||||||
|
using Flypaper.Core.Settings;
|
||||||
using Flypaper.Core.Strategies;
|
using Flypaper.Core.Strategies;
|
||||||
using Flypaper.Http;
|
using Flypaper.Http;
|
||||||
|
using Flypaper.Http.Matching;
|
||||||
using Flypaper.Storage;
|
using Flypaper.Storage;
|
||||||
|
using Flypaper.Storage.Entities;
|
||||||
|
using Flypaper.Storage.Settings;
|
||||||
using Microsoft.Data.Sqlite;
|
using Microsoft.Data.Sqlite;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -10,7 +14,7 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
namespace Flypaper.Tests;
|
namespace Flypaper.Tests.Storage;
|
||||||
|
|
||||||
public sealed class SettingsOverrideTests : IDisposable
|
public sealed class SettingsOverrideTests : IDisposable
|
||||||
{
|
{
|
||||||
Reference in new issue
Block a user