Add trap logging, dashboard, EF migrations and Dockerfile
This commit is contained in:
1 parent
f9161f48e7
commit
b561924efa
26 files changed
+784
-62
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ public static class ServiceCollectionExtensions
|
||||
services.Configure<DripOptions>(configuration.GetSection(DripOptions.SectionName));
|
||||
|
||||
services.TryAddSingleton(TimeProvider.System);
|
||||
services.TryAddSingleton<IConnectionGovernor, ConnectionGovernor>();
|
||||
services.TryAddSingleton<ConnectionGovernor>();
|
||||
services.TryAddSingleton<IConnectionGovernor>(sp => sp.GetRequiredService<ConnectionGovernor>());
|
||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<ITarpitStrategy, DripStrategy>());
|
||||
services.TryAddSingleton<TrapRunner>();
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System.Net;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Flypaper.Core;
|
||||
|
||||
public sealed class TrapRunner(
|
||||
public sealed partial class TrapRunner(
|
||||
IConnectionGovernor governor,
|
||||
IEnumerable<ITarpitStrategy> strategies,
|
||||
ITrapEventSink sink,
|
||||
IOptions<FlypaperOptions> options,
|
||||
TimeProvider timeProvider)
|
||||
TimeProvider timeProvider,
|
||||
ILogger<TrapRunner> logger)
|
||||
{
|
||||
public async Task<TrapOutcome> RunAsync(
|
||||
TrapContext context,
|
||||
@@ -52,7 +55,7 @@ public sealed class TrapRunner(
|
||||
private void Publish(TrapContext context, string strategy, long bytesSent, TrapOutcome outcome)
|
||||
{
|
||||
var session = context.Session;
|
||||
sink.Publish(new TrapEvent(
|
||||
var trapEvent = new TrapEvent(
|
||||
session.Id,
|
||||
session.Protocol,
|
||||
session.RemoteIp,
|
||||
@@ -62,6 +65,36 @@ public sealed class TrapRunner(
|
||||
bytesSent,
|
||||
outcome,
|
||||
context.Target,
|
||||
context.ClientInfo));
|
||||
context.ClientInfo);
|
||||
|
||||
if (outcome == TrapOutcome.Rejected)
|
||||
{
|
||||
LogRejected(trapEvent.RemoteIp, trapEvent.Target, trapEvent.ClientInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogTrapped(
|
||||
trapEvent.RemoteIp,
|
||||
trapEvent.Target,
|
||||
trapEvent.Duration.TotalSeconds,
|
||||
trapEvent.BytesSent,
|
||||
trapEvent.Outcome,
|
||||
trapEvent.ClientInfo);
|
||||
}
|
||||
|
||||
sink.Publish(trapEvent);
|
||||
}
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Information,
|
||||
Message = "Trapped {RemoteIp} {Target} {DurationSeconds:F1}s {BytesSent}B {Outcome} \"{UserAgent}\"")]
|
||||
private partial void LogTrapped(
|
||||
IPAddress remoteIp,
|
||||
string? target,
|
||||
double durationSeconds,
|
||||
long bytesSent,
|
||||
TrapOutcome outcome,
|
||||
string? userAgent);
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Information, Message = "Rejected {RemoteIp} {Target} \"{UserAgent}\"")]
|
||||
private partial void LogRejected(IPAddress remoteIp, string? target, string? userAgent);
|
||||
}
|
||||
Reference in new issue
Block a user