Restructure solution into folders and fix persistence issues

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-11-14 14:10:24 +01:00
1 parent 37987a394a
commit 7c39cb5562
62 files changed
+219 -151

No files matched your search

@@ -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);
}
@@ -1,4 +1,6 @@
namespace Flypaper.Core;
using Flypaper.Core.Models;
namespace Flypaper.Core.Abstractions;
public interface ITarpitStrategy
{
@@ -1,4 +1,6 @@
namespace Flypaper.Core;
using Flypaper.Core.Models;
namespace Flypaper.Core.Abstractions;
public interface ITrapChannel
{
@@ -1,4 +1,6 @@
namespace Flypaper.Core;
using Flypaper.Core.Models;
namespace Flypaper.Core.Abstractions;
public interface ITrapEventSink
{
@@ -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<DripOptions>(configuration.GetSection(DripOptions.SectionName));
services.TryAddSingleton(TimeProvider.System);
services.TryAddSingleton<ConnectionGovernor>();
services.TryAddSingleton<IConnectionGovernor>(sp => sp.GetRequiredService<ConnectionGovernor>());
services.TryAddSingleton<IConnectionGovernor, ConnectionGovernor>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, DripStrategy>());
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);
@@ -1,6 +1,6 @@
using System.Net;
namespace Flypaper.Core;
namespace Flypaper.Core.Models;
public sealed record TrapEvent(
Guid SessionId,
@@ -1,4 +1,4 @@
namespace Flypaper.Core;
namespace Flypaper.Core.Models;
public enum TrapOutcome
{
@@ -1,4 +1,4 @@
namespace Flypaper.Core;
namespace Flypaper.Core.Models;
public enum TrapProtocol
{
+8
View File
@@ -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;
}
@@ -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<FlypaperOptions> options) : IConnectionGovernor
{
@@ -23,7 +25,7 @@ public sealed class ConnectionGovernor(IOptionsMonitor<FlypaperOptions> 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<FlypaperOptions> options)
}
}
private static IPAddress Normalize(IPAddress ip) => ip.IsIPv4MappedToIPv6 ? ip.MapToIPv4() : ip;
private sealed class Lease(ConnectionGovernor owner, IPAddress ip) : IDisposable
{
private int _disposed;
@@ -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
{
@@ -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,
@@ -1,6 +1,6 @@
using System.Globalization;
namespace Flypaper.Core;
namespace Flypaper.Core.Settings;
public sealed record RuntimeSettings(
IReadOnlyList<string> TrapPaths,
@@ -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<string, string> Errors);
@@ -0,0 +1,3 @@
namespace Flypaper.Core.Settings;
public sealed record RuntimeSettingsParseResult(RuntimeSettings? Settings, IReadOnlyDictionary<string, string> Errors);
@@ -1,7 +1,7 @@
using System.Globalization;
using System.Text.RegularExpressions;
namespace Flypaper.Core;
namespace Flypaper.Core.Settings;
public static partial class RuntimeSettingsParser
{
@@ -1,4 +1,4 @@
namespace Flypaper.Core;
namespace Flypaper.Core.Settings;
public static class SettingKeys
{
@@ -1,4 +1,4 @@
namespace Flypaper.Core;
namespace Flypaper.Core.Settings;
public static class SettingsList
{
@@ -1,3 +1,5 @@
using Flypaper.Core.Abstractions;
using Flypaper.Core.Models;
using Microsoft.Extensions.Options;
namespace Flypaper.Core.Strategies;
-5
View File
@@ -1,5 +0,0 @@
using System.Net;
namespace Flypaper.Core;
public sealed record TrapSession(Guid Id, TrapProtocol Protocol, IPAddress RemoteIp, DateTimeOffset StartedAt);
+3 -1
View File
@@ -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;
+2 -1
View File
@@ -1,4 +1,5 @@
using Flypaper.Core;
using Flypaper.Core.Abstractions;
using Flypaper.Core.Models;
using Microsoft.AspNetCore.Http;
namespace Flypaper.Http;
@@ -1,4 +1,4 @@
namespace Flypaper.Http;
namespace Flypaper.Http.Matching;
public enum TrapMatch
{
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Options;
namespace Flypaper.Http;
namespace Flypaper.Http.Matching;
public sealed class TrapMatcher : IDisposable
{
@@ -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(
@@ -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<ForwardedHeadersOptions> options)
{
@@ -1,4 +1,6 @@
namespace Flypaper.Storage;
using Flypaper.Storage.Entities;
namespace Flypaper.Storage.Dashboard;
public sealed record DashboardData(
int TotalCatches,
@@ -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<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 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));
}
@@ -1,4 +1,4 @@
namespace Flypaper.Storage;
namespace Flypaper.Storage.Entities;
public sealed class SettingEntity
{
@@ -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;
}
@@ -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
{
@@ -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,
@@ -1,3 +1,4 @@
using Flypaper.Storage.Entities;
using Microsoft.EntityFrameworkCore;
namespace Flypaper.Storage;
@@ -10,6 +11,9 @@ public sealed class FlypaperDbContext(DbContextOptions<FlypaperDbContext> option
public DbSet<SettingEntity> Settings => Set<SettingEntity>();
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) =>
configurationBuilder.Properties<DateTime>().HaveConversion<UtcDateTimeConverter>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
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.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -39,6 +42,6 @@ public static class FlypaperStorageExtensions
await db.Database.MigrateAsync(ct);
}
services.GetService<DbConfigurationSource>()?.Reload();
services.GetService<DbConfigurationSource>()?.TryReload();
}
}
@@ -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<string, string?>(StringComparer.OrdinalIgnoreCase);
public void Reload()
public bool TryReload()
{
Load();
if (TryRead() is not { } data)
{
return false;
}
Data = data;
OnReload();
return true;
}
private Dictionary<string, string?> Read()
private Dictionary<string, string?>? TryRead()
{
var data = new Dictionary<string, string?>(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<string, string?>(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;
}
}
@@ -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;
}
@@ -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<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)
{
@@ -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 }));
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<bool> HasOverridesAsync(CancellationToken ct = default)
@@ -28,4 +33,15 @@ public sealed class RuntimeSettingsStore(IDbContextFactory<FlypaperDbContext> 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();
}
@@ -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 -4
View File
@@ -1,14 +1,11 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<ResourcePreloader />
<link rel="stylesheet" href="@Assets["app.css"]" />
<link rel="stylesheet" href="@Assets["Flypaper.Web.styles.css"]" />
<ImportMap />
<HeadOutlet />
</head>
@@ -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
<PageTitle>Flypaper</PageTitle>
<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">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">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>
</section>
@@ -59,7 +59,7 @@
<td class="mono">@trapEvent.RemoteIp</td>
<td class="mono clip" title="@trapEvent.Target">@trapEvent.Target</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><span class="outcome @trapEvent.Outcome.ToString().ToLowerInvariant()">@trapEvent.Outcome</span></td>
</tr>
@@ -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"
};
}
@@ -1,5 +1,4 @@
@using Flypaper.Storage
@using Flypaper.Storage.Dashboard
<section class="card">
<h2>@Title</h2>
@if (Entries.Count == 0)
@@ -22,7 +21,7 @@
<tr>
<td class="mono clip" title="@entry.Key">@entry.Key</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>
}
</tbody>
+12 -27
View File
@@ -1,36 +1,21 @@
@page "/Error"
@page "/Error"
@layout EmptyLayout
@attribute [AllowAnonymous]
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<PageTitle>Flypaper · Fehler</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
<h1 class="login-title">Fehler</h1>
<p>Bei der Verarbeitung der Anfrage ist ein Fehler aufgetreten.</p>
@if (!string.IsNullOrEmpty(_requestId))
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
<p class="muted">Request-ID: <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 {
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;
}
@@ -2,7 +2,6 @@
@layout EmptyLayout
@attribute [AllowAnonymous]
@using Flypaper.Web.Auth
@using Microsoft.AspNetCore.Authorization
@inject AdminAuthenticator Admin
<PageTitle>Flypaper · Anmelden</PageTitle>
@@ -1,6 +1,8 @@
@page "/not-found"
@page "/not-found"
@layout EmptyLayout
@attribute [Microsoft.AspNetCore.Authorization.AllowAnonymous]
@attribute [AllowAnonymous]
<h3>Not Found</h3>
<p>Sorry, the content you are looking for does not exist.</p>
<PageTitle>Flypaper · Nicht gefunden</PageTitle>
<h1 class="login-title">Nicht gefunden</h1>
<p class="muted">Diese Seite gibt es nicht. <a href="/">Zum Dashboard</a></p>
@@ -1,4 +1,4 @@
namespace Flypaper.Web.Components.Pages;
namespace Flypaper.Web.Components.Pages.Settings;
public sealed class SettingsModel
{
@@ -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<FlypaperOptions> Core
+1 -2
View File
@@ -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">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
</Router>
@@ -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"
};
}
+2 -5
View File
@@ -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
+7
View File
@@ -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<AdminOptions>(builder.Configuration.GetSection(AdminOptions.SectionName));
builder.Services.AddSingleton<AdminAuthenticator>();
builder.Services