Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f8a3ae882 | ||
|
|
cbd9830143 |
No files matched your search
+15
-1
@@ -6,6 +6,19 @@ All notable changes to Flypaper are documented in this file. The format follows
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [0.5.2] - 2026-11-17
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Dashboard, Top 10 „Strategien“: strategies are grouped by base type, so `html-drip` with any drip speed
|
||||||
|
is one row „Endlose Webseite“; the old name `drip` counts as the same. Only `head`, `link` and `repeat` stay
|
||||||
|
separate rows and show small badges („Schnellstart“, „Links“, „Wiederholer“). The drip parameters moved to the
|
||||||
|
tooltip and the expanded row.
|
||||||
|
- Columns are now catches, **median hold time per catch** and total. The bar and the default sort use the median
|
||||||
|
(rows with fewer than 5 catches are greyed out, marked „wenige Daten“ and listed last).
|
||||||
|
- Clicking a row filters the catch list on all variants of the group. The catch list, filter chip and
|
||||||
|
expanded row show name plus badges. Old `?strategie=` links still work.
|
||||||
|
|
||||||
## [0.5.1] - 2026-11-17
|
## [0.5.1] - 2026-11-17
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
@@ -184,7 +197,8 @@ First release.
|
|||||||
- Unraid Docker template; when started as root, the container hands `/data` to its app user
|
- Unraid Docker template; when started as root, the container hands `/data` to its app user
|
||||||
and drops privileges.
|
and drops privileges.
|
||||||
|
|
||||||
[Unreleased]: https://gitea.anticarnist.de/Tom/Flypaper/compare/v0.5.1...main
|
[Unreleased]: https://gitea.anticarnist.de/Tom/Flypaper/compare/v0.5.2...main
|
||||||
|
[0.5.2]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.5.2
|
||||||
[0.5.1]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.5.1
|
[0.5.1]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.5.1
|
||||||
[0.5.0]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.5.0
|
[0.5.0]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.5.0
|
||||||
[0.4.0]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.4.0
|
[0.4.0]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.4.0
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ public sealed record DashboardData(
|
|||||||
TimeSpan TotalHoldTime,
|
TimeSpan TotalHoldTime,
|
||||||
IReadOnlyList<TopEntry> TopIps,
|
IReadOnlyList<TopEntry> TopIps,
|
||||||
IReadOnlyList<TopEntry> TopTargets,
|
IReadOnlyList<TopEntry> TopTargets,
|
||||||
IReadOnlyList<TopEntry> TopStrategies,
|
IReadOnlyList<StrategySample> StrategyCatches,
|
||||||
IReadOnlyList<TopEntry> TopCountries,
|
IReadOnlyList<TopEntry> TopCountries,
|
||||||
IReadOnlyList<TopEntry> TopProviders,
|
IReadOnlyList<TopEntry> TopProviders,
|
||||||
IReadOnlyDictionary<string, int> CatchesByCountry);
|
IReadOnlyDictionary<string, int> CatchesByCountry);
|
||||||
|
|
||||||
public sealed record TopEntry(string Key, int Count, TimeSpan HoldTime, string? Label = null);
|
public sealed record TopEntry(string Key, int Count, TimeSpan HoldTime, string? Label = null, TimeSpan? MedianHold = null);
|
||||||
|
|
||||||
|
public sealed record StrategySample(string Strategy, long DurationMs);
|
||||||
@@ -42,7 +42,7 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
|
|||||||
TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, ct)),
|
TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, 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),
|
||||||
await TopAsync(catches.GroupBy(e => e.Strategy), ct),
|
await catches.Select(e => new StrategySample(e.Strategy, e.DurationMs)).ToListAsync(ct),
|
||||||
countries
|
countries
|
||||||
.Take(TopCount)
|
.Take(TopCount)
|
||||||
.Select(x => new TopEntry(x.Key, x.Count, TimeSpan.FromMilliseconds(x.DurationMs), x.Name))
|
.Select(x => new TopEntry(x.Key, x.Count, TimeSpan.FromMilliseconds(x.DurationMs), x.Name))
|
||||||
@@ -107,7 +107,19 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
|
|||||||
|
|
||||||
if (filter.Strategy is { } strategy)
|
if (filter.Strategy is { } strategy)
|
||||||
{
|
{
|
||||||
events = events.Where(e => e.Strategy == strategy);
|
var bases = strategy.Bases;
|
||||||
|
events = events.Where(e => bases.Any(name => e.Strategy == name || EF.Functions.Like(e.Strategy, name + " %", "\\")));
|
||||||
|
foreach (var flag in strategy.With)
|
||||||
|
{
|
||||||
|
var pattern = $"% {flag} %";
|
||||||
|
events = events.Where(e => EF.Functions.Like(" " + e.Strategy + " ", pattern, "\\"));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var flag in strategy.Without)
|
||||||
|
{
|
||||||
|
var pattern = $"% {flag} %";
|
||||||
|
events = events.Where(e => !EF.Functions.Like(" " + e.Strategy + " ", pattern, "\\"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(filter.Search))
|
if (!string.IsNullOrWhiteSpace(filter.Search))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public sealed record RecentFilter(
|
|||||||
long? Asn = null,
|
long? Asn = null,
|
||||||
string? Ip = null,
|
string? Ip = null,
|
||||||
string? Target = null,
|
string? Target = null,
|
||||||
string? Strategy = null,
|
StrategyMatch? Strategy = null,
|
||||||
string? Search = null,
|
string? Search = null,
|
||||||
int Limit = RecentFilter.DefaultLimit,
|
int Limit = RecentFilter.DefaultLimit,
|
||||||
IReadOnlyList<string>? SearchStrategies = null)
|
IReadOnlyList<string>? SearchStrategies = null)
|
||||||
@@ -22,3 +22,5 @@ public sealed record RecentFilter(
|
|||||||
public sealed record RecentCatches(IReadOnlyList<TrapEventEntity> Items, int Total, IReadOnlyList<CountryOption> Countries);
|
public sealed record RecentCatches(IReadOnlyList<TrapEventEntity> Items, int Total, IReadOnlyList<CountryOption> Countries);
|
||||||
|
|
||||||
public sealed record CountryOption(string Code, string? Name);
|
public sealed record CountryOption(string Code, string? Name);
|
||||||
|
|
||||||
|
public sealed record StrategyMatch(IReadOnlyList<string> Bases, IReadOnlyList<string> With, IReadOnlyList<string> Without);
|
||||||
@@ -2,6 +2,7 @@ using System.Globalization;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using Flypaper.Core.Models;
|
using Flypaper.Core.Models;
|
||||||
using Flypaper.Storage.Dashboard;
|
using Flypaper.Storage.Dashboard;
|
||||||
|
using Flypaper.Web.Components.Shared;
|
||||||
|
|
||||||
namespace Flypaper.Web.Components.Pages.Dashboard;
|
namespace Flypaper.Web.Components.Pages.Dashboard;
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ public sealed record DashboardFilter(
|
|||||||
Asn(provider) is { } asn ? $"AS{asn.ToString(CultureInfo.InvariantCulture)}" : null,
|
Asn(provider) is { } asn ? $"AS{asn.ToString(CultureInfo.InvariantCulture)}" : null,
|
||||||
IPAddress.TryParse(Clean(ip), out var address) ? address.ToString() : null,
|
IPAddress.TryParse(Clean(ip), out var address) ? address.ToString() : null,
|
||||||
Clean(ziel),
|
Clean(ziel),
|
||||||
Clean(strategie),
|
Clean(strategie) is { } strategy ? StrategyNames.GroupKey(strategy) : null,
|
||||||
Clean(q),
|
Clean(q),
|
||||||
parsedLimit);
|
parsedLimit);
|
||||||
}
|
}
|
||||||
@@ -70,7 +71,7 @@ public sealed record DashboardFilter(
|
|||||||
Asn(Provider),
|
Asn(Provider),
|
||||||
Ip,
|
Ip,
|
||||||
Ziel,
|
Ziel,
|
||||||
Strategie,
|
StrategyNames.Group(Strategie),
|
||||||
Q,
|
Q,
|
||||||
Limit);
|
Limit);
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
@foreach (var tab in tabs)
|
@foreach (var tab in tabs)
|
||||||
{
|
{
|
||||||
<div role="tabpanel" id="panel-@tab.Id" aria-labelledby="tab-@tab.Id" tabindex="0" hidden="@(tab != tabs[0])">
|
<div role="tabpanel" id="panel-@tab.Id" aria-labelledby="tab-@tab.Id" tabindex="0" hidden="@(tab != tabs[0])">
|
||||||
<TopTable KeyLabel="@tab.KeyLabel" Entries="tab.Entries" ShowFlags="tab.ShowFlags" KeyFormatter="tab.KeyFormatter" LabelFormatter="tab.LabelFormatter" TitleFormatter="tab.TitleFormatter"
|
<TopTable KeyLabel="@tab.KeyLabel" Entries="tab.Entries" ShowFlags="tab.ShowFlags" KeyFormatter="tab.KeyFormatter" LabelFormatter="tab.LabelFormatter" TitleFormatter="tab.TitleFormatter" BadgesFormatter="tab.BadgesFormatter"
|
||||||
Href="entry => TopFilter(tab, entry).Href()" IsActive="entry => tab.Current(_filter) == entry.Key" />
|
Href="entry => TopFilter(tab, entry).Href()" IsActive="entry => tab.Current(_filter) == entry.Key" />
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -199,6 +199,10 @@
|
|||||||
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
|
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
|
||||||
<div class="extra extra-all strategy-info">
|
<div class="extra extra-all strategy-info">
|
||||||
<strong>@strategy.DisplayName</strong>
|
<strong>@strategy.DisplayName</strong>
|
||||||
|
@foreach (var badge in strategy.Badges)
|
||||||
|
{
|
||||||
|
<span class="badge">@badge</span>
|
||||||
|
}
|
||||||
@if (strategy.Explanation is not null)
|
@if (strategy.Explanation is not null)
|
||||||
{
|
{
|
||||||
<div>@strategy.Explanation</div>
|
<div>@strategy.Explanation</div>
|
||||||
@@ -213,7 +217,7 @@
|
|||||||
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
|
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
|
||||||
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
|
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
|
||||||
</td>
|
</td>
|
||||||
<td class="c-strategy" title="@strategy.Tooltip">@strategy.DisplayName</td>
|
<td class="c-strategy" title="@strategy.Tooltip">@strategy.DisplayName@foreach (var badge in strategy.Badges){<span class="badge">@badge</span>}</td>
|
||||||
<td class="c-agent" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
<td class="c-agent" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
||||||
<td class="c-duration num">@duration</td>
|
<td class="c-duration num">@duration</td>
|
||||||
<td class="c-bytes num">@bytes</td>
|
<td class="c-bytes num">@bytes</td>
|
||||||
@@ -282,7 +286,7 @@
|
|||||||
new("providers", "Provider", "Provider", data.TopProviders, f => f.Provider, (f, key) => f with { Provider = key }),
|
new("providers", "Provider", "Provider", data.TopProviders, f => f.Provider, (f, key) => f with { Provider = key }),
|
||||||
new("ips", "IPs", "IP", data.TopIps, f => f.Ip, (f, key) => f with { Ip = key }),
|
new("ips", "IPs", "IP", data.TopIps, f => f.Ip, (f, key) => f with { Ip = key }),
|
||||||
new("targets", "Ziele", "Ziel", data.TopTargets, f => f.Ziel, (f, key) => f with { Ziel = key }, KeyFormatter: Formatting.Target),
|
new("targets", "Ziele", "Ziel", data.TopTargets, f => f.Ziel, (f, key) => f with { Ziel = key }, KeyFormatter: Formatting.Target),
|
||||||
new("strategies", "Strategien", "Strategie", data.TopStrategies, f => f.Strategie, (f, key) => f with { Strategie = key }, KeyFormatter: StrategyNames.Summary, LabelFormatter: (key, _) => StrategyNames.Display(key), TitleFormatter: key => StrategyNames.Describe(key).Tooltip)
|
new("strategies", "Strategien", "Strategie", StrategyNames.Rank(data.StrategyCatches, 10), f => f.Strategie, (f, key) => f with { Strategie = key }, KeyFormatter: _ => "", LabelFormatter: (key, _) => StrategyNames.Display(key), TitleFormatter: key => StrategyNames.Describe(key).Tooltip, BadgesFormatter: key => StrategyNames.Describe(key).Badges)
|
||||||
];
|
];
|
||||||
|
|
||||||
private DashboardFilter TopFilter(TopTab tab, TopEntry entry) =>
|
private DashboardFilter TopFilter(TopTab tab, TopEntry entry) =>
|
||||||
@@ -326,7 +330,8 @@
|
|||||||
|
|
||||||
if (_filter.Strategie is { } strategie)
|
if (_filter.Strategie is { } strategie)
|
||||||
{
|
{
|
||||||
yield return ($"Strategie: {StrategyNames.Display(strategie)}", reset with { Strategie = null });
|
var badges = StrategyNames.Describe(strategie).Badges;
|
||||||
|
yield return ($"Strategie: {StrategyNames.Display(strategie)}{(badges.Count == 0 ? "" : $" ({string.Join(", ", badges)})")}", reset with { Strategie = null });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_filter.Q is { } q)
|
if (_filter.Q is { } q)
|
||||||
@@ -357,5 +362,6 @@
|
|||||||
bool ShowFlags = false,
|
bool ShowFlags = false,
|
||||||
Func<string?, string?>? KeyFormatter = null,
|
Func<string?, string?>? KeyFormatter = null,
|
||||||
Func<string?, string?, string?>? LabelFormatter = null,
|
Func<string?, string?, string?>? LabelFormatter = null,
|
||||||
Func<string?, string?>? TitleFormatter = null);
|
Func<string?, string?>? TitleFormatter = null,
|
||||||
|
Func<string?, IReadOnlyList<string>>? BadgesFormatter = null);
|
||||||
}
|
}
|
||||||
@@ -1,25 +1,40 @@
|
|||||||
@using System.Globalization
|
@using System.Globalization
|
||||||
@using Flypaper.Storage.Dashboard
|
@using Flypaper.Storage.Dashboard
|
||||||
|
@using Flypaper.Web.Components.Shared
|
||||||
|
|
||||||
|
@{
|
||||||
|
var byMedian = Entries.Any(entry => entry.MedianHold is not null);
|
||||||
|
var barMax = byMedian
|
||||||
|
? Entries.Where(entry => entry.Count >= StrategyNames.MinCatches).Select(entry => entry.MedianHold!.Value.TotalMilliseconds).DefaultIfEmpty(0).Max()
|
||||||
|
: Entries.Count == 0 ? 0 : Entries[0].Count;
|
||||||
|
}
|
||||||
@if (Entries.Count == 0)
|
@if (Entries.Count == 0)
|
||||||
{
|
{
|
||||||
<p class="empty">Noch keine Einträge.</p>
|
<p class="empty">Noch keine Einträge.</p>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<table class="top-table">
|
<table class="top-table @(byMedian ? "by-median" : null)">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col />
|
<col />
|
||||||
<col class="share" />
|
<col class="share" />
|
||||||
<col class="count" />
|
<col class="count" />
|
||||||
|
@if (byMedian)
|
||||||
|
{
|
||||||
<col class="hold" />
|
<col class="hold" />
|
||||||
|
}
|
||||||
|
<col class="hold sum" />
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>@KeyLabel</th>
|
<th>@KeyLabel</th>
|
||||||
<th><span class="sr-only">Anteil</span></th>
|
<th><span class="sr-only">Anteil</span></th>
|
||||||
<th class="num">Fänge</th>
|
<th class="num">Fänge</th>
|
||||||
<th class="num">Haltezeit</th>
|
@if (byMedian)
|
||||||
|
{
|
||||||
|
<th class="num" title="Mittlere Haltezeit pro Fang (Median): Einzelne Dauerhalter verfälschen sie nicht">Median</th>
|
||||||
|
}
|
||||||
|
<th class="num sum">@(byMedian ? "Summe" : "Haltezeit")</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -27,10 +42,18 @@ else
|
|||||||
{
|
{
|
||||||
var key = KeyFormatter?.Invoke(entry.Key) ?? entry.Key;
|
var key = KeyFormatter?.Invoke(entry.Key) ?? entry.Key;
|
||||||
var label = LabelFormatter is null ? entry.Label : LabelFormatter(entry.Key, entry.Label);
|
var label = LabelFormatter is null ? entry.Label : LabelFormatter(entry.Key, entry.Label);
|
||||||
var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture);
|
var value = byMedian ? entry.MedianHold!.Value.TotalMilliseconds : entry.Count;
|
||||||
|
var share = (barMax == 0 ? 0 : Math.Min(100, value * 100.0 / barMax)).ToString("0.#", CultureInfo.InvariantCulture);
|
||||||
|
var sparse = byMedian && entry.Count < StrategyNames.MinCatches;
|
||||||
|
var badges = BadgesFormatter?.Invoke(entry.Key) ?? [];
|
||||||
var active = IsActive(entry);
|
var active = IsActive(entry);
|
||||||
var title = TitleFormatter?.Invoke(entry.Key) ?? (label is null ? key : $"{label} · {key}");
|
var title = TitleFormatter?.Invoke(entry.Key) ?? (label is null ? key : $"{label} · {key}");
|
||||||
<tr data-href="@Href(entry)" class="@(active ? "active" : null)">
|
if (sparse)
|
||||||
|
{
|
||||||
|
title += $"\nNur {entry.Count} {(entry.Count == 1 ? "Fang" : "Fänge")}: wenig aussagekräftig";
|
||||||
|
}
|
||||||
|
|
||||||
|
<tr data-href="@Href(entry)" class="@(active ? "active" : null) @(sparse ? "sparse" : null)">
|
||||||
<td class="clip" title="@title">
|
<td class="clip" title="@title">
|
||||||
<a href="@Href(entry)" aria-current="@(active ? "true" : null)" title="@(active ? $"Filter {title} entfernen" : $"Fänge filtern: {title}")">
|
<a href="@Href(entry)" aria-current="@(active ? "true" : null)" title="@(active ? $"Filter {title} entfernen" : $"Fänge filtern: {title}")">
|
||||||
@if (ShowFlags)
|
@if (ShowFlags)
|
||||||
@@ -40,6 +63,14 @@ else
|
|||||||
@if (label is not null)
|
@if (label is not null)
|
||||||
{
|
{
|
||||||
<span class="top-label">@label</span>
|
<span class="top-label">@label</span>
|
||||||
|
@foreach (var badge in badges)
|
||||||
|
{
|
||||||
|
<span class="badge">@badge</span>
|
||||||
|
}
|
||||||
|
@if (sparse)
|
||||||
|
{
|
||||||
|
<span class="badge sparse-note">wenige Daten</span>
|
||||||
|
}
|
||||||
@if (key.Length > 0)
|
@if (key.Length > 0)
|
||||||
{
|
{
|
||||||
<span class="top-key mono">@key</span>
|
<span class="top-key mono">@key</span>
|
||||||
@@ -53,11 +84,19 @@ else
|
|||||||
</td>
|
</td>
|
||||||
<td><span class="share-bar" style="--share: @(share)%"></span></td>
|
<td><span class="share-bar" style="--share: @(share)%"></span></td>
|
||||||
<td class="num">@Formatting.Number(entry.Count)</td>
|
<td class="num">@Formatting.Number(entry.Count)</td>
|
||||||
<td class="num">@Formatting.Duration(entry.HoldTime)</td>
|
@if (byMedian)
|
||||||
|
{
|
||||||
|
<td class="num">@Formatting.Duration(entry.MedianHold!.Value)</td>
|
||||||
|
}
|
||||||
|
<td class="num sum">@Formatting.Duration(entry.HoldTime)</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@if (byMedian)
|
||||||
|
{
|
||||||
|
<p class="top-note">Balken = Median Haltezeit pro Fang. Unter @StrategyNames.MinCatches Fängen wenig aussagekräftig, diese Zeilen stehen am Ende.</p>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@@ -73,6 +112,8 @@ else
|
|||||||
|
|
||||||
[Parameter] public Func<string?, string?>? TitleFormatter { get; set; }
|
[Parameter] public Func<string?, string?>? TitleFormatter { get; set; }
|
||||||
|
|
||||||
|
[Parameter] public Func<string?, IReadOnlyList<string>>? BadgesFormatter { get; set; }
|
||||||
|
|
||||||
[Parameter, EditorRequired] public required Func<TopEntry, string> Href { get; set; }
|
[Parameter, EditorRequired] public required Func<TopEntry, string> Href { get; set; }
|
||||||
|
|
||||||
[Parameter, EditorRequired] public required Func<TopEntry, bool> IsActive { get; set; }
|
[Parameter, EditorRequired] public required Func<TopEntry, bool> IsActive { get; set; }
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Flypaper.Storage.Dashboard;
|
||||||
|
|
||||||
namespace Flypaper.Web.Components.Shared;
|
namespace Flypaper.Web.Components.Shared;
|
||||||
|
|
||||||
public sealed record StrategyInfo(string Raw, string BaseName, string DisplayName, string? Explanation, IReadOnlyList<string> Details)
|
public sealed record StrategyInfo(string Raw, string BaseName, string DisplayName, string? Explanation, IReadOnlyList<string> Details, IReadOnlyList<string> Flags)
|
||||||
{
|
{
|
||||||
|
public string GroupKey => string.Join(' ', [BaseName, .. Flags]);
|
||||||
|
|
||||||
|
public IReadOnlyList<string> Badges => Flags.Select(StrategyNames.BadgeLabel).ToList();
|
||||||
|
|
||||||
public string Tooltip
|
public string Tooltip
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -44,16 +49,45 @@ public static partial class StrategyNames
|
|||||||
["robots-bait"] = ("Köder aus der robots.txt", "Ein Pfad, der in der robots.txt als verboten steht, aber ins Link-Labyrinth führt. Wer dort landet, hat das Verbot gelesen und ignoriert. Er wird mindestens 24 Stunden festgehalten.")
|
["robots-bait"] = ("Köder aus der robots.txt", "Ein Pfad, der in der robots.txt als verboten steht, aber ins Link-Labyrinth führt. Wer dort landet, hat das Verbot gelesen und ignoriert. Er wird mindestens 24 Stunden festgehalten.")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly Dictionary<string, string> Aliases = new(StringComparer.Ordinal)
|
||||||
|
{
|
||||||
|
["drip"] = "html-drip"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly string[] VariantFlags = ["head", "link", "repeat"];
|
||||||
|
|
||||||
|
private static readonly HashSet<string> LinkedByDesign = new(StringComparer.Ordinal) { "maze-drip", "index-drip", "robots-bait" };
|
||||||
|
|
||||||
|
public const int MinCatches = 5;
|
||||||
|
|
||||||
|
public static string BadgeLabel(string flag) => flag switch
|
||||||
|
{
|
||||||
|
"head" => "Schnellstart",
|
||||||
|
"link" => "Links",
|
||||||
|
"repeat" => "Wiederholer",
|
||||||
|
_ => flag
|
||||||
|
};
|
||||||
|
|
||||||
public static StrategyInfo Describe(string? strategy)
|
public static StrategyInfo Describe(string? strategy)
|
||||||
{
|
{
|
||||||
var raw = strategy?.Trim() ?? "";
|
var raw = strategy?.Trim() ?? "";
|
||||||
var tokens = raw.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
var tokens = raw.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (tokens.Length == 0)
|
if (tokens.Length == 0)
|
||||||
{
|
{
|
||||||
return new StrategyInfo(raw, raw, raw, null, []);
|
return new StrategyInfo(raw, raw, raw, null, [], []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var baseName = Aliases.GetValueOrDefault(tokens[0], tokens[0]);
|
||||||
|
var flags = VariantFlags
|
||||||
|
.Where(flag => tokens.Skip(1).Contains(flag) && !(flag == "link" && LinkedByDesign.Contains(baseName)))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
var details = new List<string>();
|
var details = new List<string>();
|
||||||
|
if (baseName != tokens[0])
|
||||||
|
{
|
||||||
|
details.Add($"früherer Name von {Known[baseName].Name}");
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 1; i < tokens.Length; i++)
|
for (var i = 1; i < tokens.Length; i++)
|
||||||
{
|
{
|
||||||
var token = tokens[i];
|
var token = tokens[i];
|
||||||
@@ -71,6 +105,10 @@ public static partial class StrategyNames
|
|||||||
: $"alle {bytes} Byte ein Link");
|
: $"alle {bytes} Byte ein Link");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
else if (token is "head" or "link")
|
||||||
|
{
|
||||||
|
details.Add(token == "head" ? "schneller Start: erste Bytes sofort" : "enthält Links");
|
||||||
|
}
|
||||||
else if (token == "repeat")
|
else if (token == "repeat")
|
||||||
{
|
{
|
||||||
details.Add("Wiederholer: darf länger festgehalten werden");
|
details.Add("Wiederholer: darf länger festgehalten werden");
|
||||||
@@ -81,22 +119,58 @@ public static partial class StrategyNames
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Known.TryGetValue(tokens[0], out var known)
|
return Known.TryGetValue(baseName, out var known)
|
||||||
? new StrategyInfo(raw, tokens[0], known.Name, known.Explanation, details)
|
? new StrategyInfo(raw, baseName, known.Name, known.Explanation, details, flags)
|
||||||
: new StrategyInfo(raw, tokens[0], tokens[0], null, details);
|
: new StrategyInfo(raw, baseName, baseName, null, details, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Display(string? strategy) => Describe(strategy).DisplayName;
|
public static string Display(string? strategy) => Describe(strategy).DisplayName;
|
||||||
|
|
||||||
public static string Summary(string? strategy) =>
|
public static string GroupKey(string? strategy) => Describe(strategy).GroupKey;
|
||||||
string.Join(" · ", Describe(strategy).Details.Where(detail => detail.StartsWith("tröpfelt", StringComparison.Ordinal) || detail.StartsWith("Wiederholer", StringComparison.Ordinal)).Select(detail => detail.Split(':')[0]));
|
|
||||||
|
public static StrategyMatch? Group(string? strategy)
|
||||||
|
{
|
||||||
|
var info = Describe(strategy);
|
||||||
|
if (info.BaseName.Length == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bases = Aliases.Where(pair => pair.Value == info.BaseName).Select(pair => pair.Key).Prepend(info.BaseName).ToList();
|
||||||
|
var variableFlags = VariantFlags.Where(flag => !(flag == "link" && LinkedByDesign.Contains(info.BaseName)));
|
||||||
|
return new StrategyMatch(bases, info.Flags, variableFlags.Except(info.Flags).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IReadOnlyList<TopEntry> Rank(IEnumerable<StrategySample> samples, int take)
|
||||||
|
{
|
||||||
|
var groups = samples
|
||||||
|
.GroupBy(sample => GroupKey(sample.Strategy))
|
||||||
|
.Select(group =>
|
||||||
|
{
|
||||||
|
var durations = group.Select(sample => sample.DurationMs).Order().ToList();
|
||||||
|
var middle = durations.Count / 2;
|
||||||
|
var median = durations.Count % 2 == 1 ? durations[middle] : (durations[middle - 1] + durations[middle]) / 2d;
|
||||||
|
return new TopEntry(group.Key, durations.Count, TimeSpan.FromMilliseconds(durations.Sum()), MedianHold: TimeSpan.FromMilliseconds(median));
|
||||||
|
});
|
||||||
|
|
||||||
|
return groups
|
||||||
|
.OrderBy(entry => entry.Count < MinCatches)
|
||||||
|
.ThenByDescending(entry => entry.MedianHold)
|
||||||
|
.ThenByDescending(entry => entry.Count)
|
||||||
|
.Take(take)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public static IReadOnlyList<string> Matching(string? search)
|
public static IReadOnlyList<string> Matching(string? search)
|
||||||
{
|
{
|
||||||
var term = search?.Trim();
|
var term = search?.Trim();
|
||||||
return string.IsNullOrEmpty(term)
|
if (string.IsNullOrEmpty(term))
|
||||||
? []
|
{
|
||||||
: Known.Where(pair => pair.Value.Name.Contains(term, StringComparison.CurrentCultureIgnoreCase)).Select(pair => pair.Key).ToList();
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var keys = Known.Where(pair => pair.Value.Name.Contains(term, StringComparison.CurrentCultureIgnoreCase)).Select(pair => pair.Key).ToList();
|
||||||
|
return [.. keys, .. Aliases.Where(pair => keys.Contains(pair.Value)).Select(pair => pair.Key)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string Range(string min, string max) => min == max ? Number(min) : $"{Number(min)}–{Number(max)}";
|
private static string Range(string min, string max) => min == max ? Number(min) : $"{Number(min)}–{Number(max)}";
|
||||||
|
|||||||
@@ -266,6 +266,33 @@ code {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 6px;
|
||||||
|
padding: 0 6px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: color-mix(in srgb, var(--text) 8%, transparent);
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 17px;
|
||||||
|
white-space: nowrap;
|
||||||
|
vertical-align: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-table tr.sparse td {
|
||||||
|
opacity: 0.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-note {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-table.by-median .count {
|
||||||
|
width: 52px;
|
||||||
|
}
|
||||||
|
|
||||||
.top-table tr[data-href] {
|
.top-table tr[data-href] {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@@ -1017,6 +1044,18 @@ button.danger {
|
|||||||
width: 84px;
|
width: 84px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.top-table.by-median .sum {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-table.by-median .count {
|
||||||
|
width: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-table.by-median .clip {
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
.nav .brand {
|
.nav .brand {
|
||||||
margin-right: 4px;
|
margin-right: 4px;
|
||||||
font-size: 0;
|
font-size: 0;
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
using System.Net;
|
||||||
using Flypaper.Core.Models;
|
using Flypaper.Core.Models;
|
||||||
|
using Flypaper.Storage.Entities;
|
||||||
|
using Flypaper.Web.Components.Shared;
|
||||||
using Flypaper.Storage.Dashboard;
|
using Flypaper.Storage.Dashboard;
|
||||||
using Flypaper.Tests.Fakes;
|
using Flypaper.Tests.Fakes;
|
||||||
using Flypaper.Tests.Mcp;
|
using Flypaper.Tests.Mcp;
|
||||||
@@ -47,19 +50,42 @@ public sealed class RecentCatchesTests : IDisposable
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task Matches_strategy_exactly()
|
public async Task Matches_strategy_exactly()
|
||||||
{
|
{
|
||||||
var recent = await _queries.GetRecentAsync(new RecentFilter(Strategy: "env-drip"));
|
var recent = await _queries.GetRecentAsync(new RecentFilter(Strategy: StrategyNames.Group("env-drip")));
|
||||||
|
|
||||||
recent.Total.ShouldBe(2);
|
recent.Total.ShouldBe(2);
|
||||||
recent.Items.ShouldAllBe(e => e.Strategy == "env-drip");
|
recent.Items.ShouldAllBe(e => e.Strategy == "env-drip");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Dashboard_ranks_strategies_among_catches()
|
public async Task Dashboard_lists_strategy_durations_among_catches()
|
||||||
{
|
{
|
||||||
var data = await _queries.GetAsync();
|
var data = await _queries.GetAsync();
|
||||||
|
|
||||||
data.TopStrategies.Select(s => (s.Key, s.Count)).ShouldBe([("html-drip", 4), ("env-drip", 1)]);
|
data.StrategyCatches.Count.ShouldBe(5);
|
||||||
data.TopStrategies[1].HoldTime.ShouldBe(TimeSpan.FromHours(1));
|
data.StrategyCatches.Count(s => s.Strategy == "env-drip").ShouldBe(1);
|
||||||
|
data.StrategyCatches.Single(s => s.Strategy == "env-drip").DurationMs.ShouldBe(3_600_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Strategy_group_matches_all_variants_of_the_base_type_and_its_old_name()
|
||||||
|
{
|
||||||
|
await using (var db = _data.Factory.CreateDbContext())
|
||||||
|
{
|
||||||
|
foreach (var strategy in new[] { "drip", "html-drip 50-500ms 1-640B", "html-drip 5-20ms 1-64B head 1024B", "html-drip 50-500ms 1-1024B repeat", "html-drip 50-500ms 1-64B head 1024B repeat" })
|
||||||
|
{
|
||||||
|
db.TrapEvents.Add(TrapEventEntity.From(new TrapEvent(Guid.NewGuid(), TrapProtocol.Http, IPAddress.Parse("192.0.2.1"), strategy, McpTestData.Now, McpTestData.Now, 0, TrapOutcome.ClientAborted, null, null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task<IReadOnlyList<string>> Find(string group) =>
|
||||||
|
(await _queries.GetRecentAsync(new RecentFilter(Strategy: StrategyNames.Group(group)))).Items.Select(e => e.Strategy).OrderBy(s => s).ToList();
|
||||||
|
|
||||||
|
(await Find("html-drip")).Where(s => s != "html-drip").ShouldBe(["drip", "html-drip 50-500ms 1-640B"]);
|
||||||
|
(await Find("html-drip head")).ShouldBe(["html-drip 5-20ms 1-64B head 1024B"]);
|
||||||
|
(await Find("html-drip repeat")).ShouldBe(["html-drip 50-500ms 1-1024B repeat"]);
|
||||||
|
(await Find("html-drip head repeat")).ShouldBe(["html-drip 50-500ms 1-64B head 1024B repeat"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|||||||
@@ -13,7 +13,11 @@ public sealed class DashboardFilterTests
|
|||||||
var filter = DashboardFilter.Parse("24h", "Abgelehnt", "hk", "as4134", " 203.0.113.9 ", "GET /.env", " env-drip ", " wp ", "100");
|
var filter = DashboardFilter.Parse("24h", "Abgelehnt", "hk", "as4134", " 203.0.113.9 ", "GET /.env", " env-drip ", " wp ", "100");
|
||||||
|
|
||||||
filter.ShouldBe(new DashboardFilter("24h", "abgelehnt", "HK", "AS4134", "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
|
filter.ShouldBe(new DashboardFilter("24h", "abgelehnt", "HK", "AS4134", "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
|
||||||
filter.ToRecentFilter().ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", "env-drip", "wp", 100));
|
var recent = filter.ToRecentFilter();
|
||||||
|
recent.ShouldBe(new RecentFilter(TimeSpan.FromHours(24), TrapOutcome.Rejected, "HK", 4134, "203.0.113.9", "GET /.env", recent.Strategy, "wp", 100));
|
||||||
|
recent.Strategy!.Bases.ShouldBe(["env-drip"]);
|
||||||
|
recent.Strategy.With.ShouldBeEmpty();
|
||||||
|
recent.Strategy.Without.ShouldBe(["head", "link", "repeat"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -44,8 +48,8 @@ public sealed class DashboardFilterTests
|
|||||||
public void Builds_links_without_defaults_and_with_escaping()
|
public void Builds_links_without_defaults_and_with_escaping()
|
||||||
{
|
{
|
||||||
new DashboardFilter().Href().ShouldBe("/#faenge");
|
new DashboardFilter().Href().ShouldBe("/#faenge");
|
||||||
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Strategie: "html-drip 50-500ms 1-1024B", Limit: 100).Href("f50")
|
new DashboardFilter(Land: "CN", Ziel: "GET example.com/a&b", Strategie: "html-drip head", Limit: 100).Href("f50")
|
||||||
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&strategie=html-drip%2050-500ms%201-1024B&limit=100#f50");
|
.ShouldBe("/?land=CN&ziel=GET%20example.com%2Fa%26b&strategie=html-drip%20head&limit=100#f50");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -58,6 +62,13 @@ public sealed class DashboardFilterTests
|
|||||||
.ShouldBe(filter);
|
.ShouldBe(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("html-drip 50-500ms 1-1024B", "html-drip")]
|
||||||
|
[InlineData("drip", "html-drip")]
|
||||||
|
[InlineData("html-drip 50-500ms 1-64B head 1024B", "html-drip head")]
|
||||||
|
public void Normalizes_strategy_links_to_the_group(string strategy, string expected) =>
|
||||||
|
DashboardFilter.Parse(null, null, null, null, null, null, strategy, null, null).Strategie.ShouldBe(expected);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Doubles_the_limit_up_to_the_maximum()
|
public void Doubles_the_limit_up_to_the_maximum()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Flypaper.Core.Strategies;
|
using Flypaper.Core.Strategies;
|
||||||
|
using Flypaper.Storage.Dashboard;
|
||||||
using Flypaper.Web.Components.Shared;
|
using Flypaper.Web.Components.Shared;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
|
|
||||||
@@ -63,4 +64,44 @@ public sealed class StrategyNamesTests
|
|||||||
StrategyNames.Matching("").ShouldBeEmpty();
|
StrategyNames.Matching("").ShouldBeEmpty();
|
||||||
StrategyNames.Matching("nichts").ShouldBeEmpty();
|
StrategyNames.Matching("nichts").ShouldBeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Groups_variants_by_base_type_and_shows_only_content_differences_as_badges()
|
||||||
|
{
|
||||||
|
StrategyNames.Describe("html-drip 50-500ms 1-1024B").GroupKey.ShouldBe("html-drip");
|
||||||
|
StrategyNames.Describe("html-drip 50-500ms 1-640B").GroupKey.ShouldBe("html-drip");
|
||||||
|
var variant = StrategyNames.Describe("html-drip 5-20ms 1-64B head 1024B repeat");
|
||||||
|
variant.GroupKey.ShouldBe("html-drip head repeat");
|
||||||
|
variant.Badges.ShouldBe(["Schnellstart", "Wiederholer"]);
|
||||||
|
StrategyNames.Describe("maze-drip 50-500ms 1-1024B head 1024B link 160B").Badges.ShouldBe(["Schnellstart"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Treats_drip_as_the_old_name_of_the_endless_page()
|
||||||
|
{
|
||||||
|
var info = StrategyNames.Describe("drip");
|
||||||
|
|
||||||
|
info.DisplayName.ShouldBe("Endlose Webseite");
|
||||||
|
info.GroupKey.ShouldBe("html-drip");
|
||||||
|
StrategyNames.Matching("endlose webseite").ShouldBe(["html-drip", "drip"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Ranks_groups_by_median_and_sinks_groups_with_few_catches()
|
||||||
|
{
|
||||||
|
var samples = new List<StrategySample>();
|
||||||
|
samples.AddRange(Enumerable.Repeat(new StrategySample("html-drip 50-500ms 1-1024B", 10_000), 3));
|
||||||
|
samples.AddRange(Enumerable.Repeat(new StrategySample("html-drip 50-500ms 1-640B", 20_000), 2));
|
||||||
|
samples.Add(new StrategySample("drip", 1_000_000));
|
||||||
|
samples.AddRange(Enumerable.Repeat(new StrategySample("env-drip 50-500ms 1-1024B", 30_000), 5));
|
||||||
|
samples.Add(new StrategySample("text-drip", 500_000_000));
|
||||||
|
|
||||||
|
var ranked = StrategyNames.Rank(samples, 10);
|
||||||
|
|
||||||
|
ranked.Select(r => r.Key).ShouldBe(["env-drip", "html-drip", "text-drip"]);
|
||||||
|
ranked[0].MedianHold.ShouldBe(TimeSpan.FromSeconds(30));
|
||||||
|
ranked[1].Count.ShouldBe(6);
|
||||||
|
ranked[1].MedianHold.ShouldBe(TimeSpan.FromSeconds(15));
|
||||||
|
ranked[1].HoldTime.ShouldBe(TimeSpan.FromMilliseconds(1_070_000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user