Add explanation rules for catches, editable over MCP
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4086fa3da3
commit
2437880013
37 files changed
+1867
-37
No files matched your search
@@ -4,6 +4,7 @@
|
||||
<nav class="nav">
|
||||
<a href="/" class="brand"><span class="brand-mark" aria-hidden="true"></span>Flypaper</a>
|
||||
<NavLink href="/" Match="NavLinkMatch.All">Dashboard</NavLink>
|
||||
<NavLink href="/erklaerungen">Erklärungen</NavLink>
|
||||
<NavLink href="/settings">Einstellungen</NavLink>
|
||||
<form method="post" action="/auth/logout" class="logout">
|
||||
<AntiforgeryToken />
|
||||
|
||||
@@ -15,7 +15,8 @@ public sealed record DashboardFilter(
|
||||
string? Ziel = null,
|
||||
string? Strategie = null,
|
||||
string? Q = null,
|
||||
int Limit = RecentFilter.DefaultLimit)
|
||||
int Limit = RecentFilter.DefaultLimit,
|
||||
string? Erklaerung = null)
|
||||
{
|
||||
public const string Anchor = "faenge";
|
||||
|
||||
@@ -24,6 +25,8 @@ public sealed record DashboardFilter(
|
||||
public static readonly IReadOnlyList<(string Value, string Label)> Outcomes =
|
||||
[("", "Alle"), ("aufgegeben", "Aufgegeben"), ("zeitlimit", "Zeitlimit"), ("abgelehnt", "Abgelehnt")];
|
||||
|
||||
public static readonly IReadOnlyList<(string Value, string Label)> Explanations = [("", "Alle"), ("ohne", "Ohne Erklärung")];
|
||||
|
||||
public bool IsEmpty => this with { Limit = RecentFilter.DefaultLimit } == new DashboardFilter();
|
||||
|
||||
public static DashboardFilter Parse(
|
||||
@@ -35,7 +38,8 @@ public sealed record DashboardFilter(
|
||||
string? ziel,
|
||||
string? strategie,
|
||||
string? q,
|
||||
string? limit)
|
||||
string? limit,
|
||||
string? erklaerung = null)
|
||||
{
|
||||
var parsedLimit = int.TryParse(limit, NumberStyles.None, CultureInfo.InvariantCulture, out var value)
|
||||
? Math.Clamp(value, 1, RecentFilter.MaxLimit)
|
||||
@@ -50,7 +54,8 @@ public sealed record DashboardFilter(
|
||||
Clean(ziel),
|
||||
Clean(strategie) is { } strategy ? StrategyNames.GroupKey(strategy) : null,
|
||||
Clean(q),
|
||||
parsedLimit);
|
||||
parsedLimit,
|
||||
Known(Explanations, erklaerung));
|
||||
}
|
||||
|
||||
public RecentFilter ToRecentFilter() => new(
|
||||
@@ -73,7 +78,8 @@ public sealed record DashboardFilter(
|
||||
Ziel,
|
||||
StrategyNames.Group(Strategie),
|
||||
Q,
|
||||
Limit);
|
||||
Limit,
|
||||
Unexplained: Erklaerung == "ohne");
|
||||
|
||||
public int NextLimit => Math.Min(Limit * 2, RecentFilter.MaxLimit);
|
||||
|
||||
@@ -88,6 +94,7 @@ public sealed record DashboardFilter(
|
||||
Add(parts, "ziel", Ziel);
|
||||
Add(parts, "strategie", Strategie);
|
||||
Add(parts, "q", Q);
|
||||
Add(parts, "erklaerung", Erklaerung);
|
||||
if (Limit != RecentFilter.DefaultLimit)
|
||||
{
|
||||
Add(parts, "limit", Limit.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
@using Microsoft.Extensions.Options
|
||||
@using Flypaper.Storage.Dashboard
|
||||
@using Flypaper.Storage.Entities
|
||||
@using Flypaper.Storage.Explanations
|
||||
@inject DashboardQueries Queries
|
||||
@inject ExplanationRuleStore Explanations
|
||||
@inject IConnectionGovernor Governor
|
||||
@inject IOptions<PortOptions> Ports
|
||||
|
||||
@@ -125,6 +127,15 @@
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Erklärung</span>
|
||||
<select name="erklaerung" data-autosubmit>
|
||||
@foreach (var (value, label) in DashboardFilter.Explanations)
|
||||
{
|
||||
<option value="@value" selected="@(value == (_filter.Erklaerung ?? ""))">@label</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label class="filter-search">
|
||||
<span>Suche</span>
|
||||
<input type="search" name="q" value="@_filter.Q" placeholder="IP, Provider, Ziel, Strategie, User-Agent" />
|
||||
@@ -179,6 +190,7 @@
|
||||
var duration = Formatting.Duration(TimeSpan.FromMilliseconds(trapEvent.DurationMs));
|
||||
var bytes = Formatting.Number(trapEvent.BytesSent);
|
||||
var strategy = StrategyNames.Describe(trapEvent.Strategy);
|
||||
var explanation = _rules.Explain(trapEvent);
|
||||
<tr id="f@(index)" data-expand="event:@trapEvent.Id" tabindex="0" aria-expanded="false" class="@(trapEvent.Outcome == TrapOutcome.Rejected ? "rejected" : null)">
|
||||
<td class="c-time"><span class="c-date">@started.ToString("dd.MM.") </span>@started.ToString("HH:mm:ss")</td>
|
||||
<td class="c-ip mono" title="@trapEvent.RemoteIp">@trapEvent.RemoteIp</td>
|
||||
@@ -199,6 +211,25 @@
|
||||
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
|
||||
<div class="extra extra-all">Herkunft: @(trapEvent.CountryCode is { } code ? $"{Formatting.Flag(code)} {code} · {Origin(trapEvent)}" : "–")</div>
|
||||
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
|
||||
<div class="extra extra-all explain">
|
||||
<strong>Was ist passiert?</strong>
|
||||
@if (explanation.Target is { } targetRule)
|
||||
{
|
||||
<p>@targetRule.Text</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="muted">Unbekanntes Ziel</p>
|
||||
}
|
||||
@if (explanation.Client is { } clientRule)
|
||||
{
|
||||
<p>@clientRule.Text</p>
|
||||
}
|
||||
@if (explanation.Outcome is { } outcomeRule)
|
||||
{
|
||||
<p>@outcomeRule.Text</p>
|
||||
}
|
||||
</div>
|
||||
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
|
||||
</td>
|
||||
<td class="c-strategy" title="@strategy.Tooltip">@strategy.DisplayName@foreach (var badge in strategy.Badges){<span class="badge">@badge</span>}</td>
|
||||
@@ -236,6 +267,7 @@
|
||||
private DashboardData? _data;
|
||||
private RecentCatches? _recent;
|
||||
private DashboardFilter _filter = new();
|
||||
private RuleSet _rules = RuleSet.Empty;
|
||||
private DateTime _loadedAt;
|
||||
|
||||
[SupplyParameterFromQuery(Name = "zeit")] public string? Zeit { get; set; }
|
||||
@@ -256,9 +288,12 @@
|
||||
|
||||
[SupplyParameterFromQuery(Name = "limit")] public string? Limit { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "erklaerung")] public string? Erklaerung { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_filter = DashboardFilter.Parse(Zeit, Ausgang, Land, Provider, Ip, Ziel, Strategie, Q, Limit);
|
||||
_filter = DashboardFilter.Parse(Zeit, Ausgang, Land, Provider, Ip, Ziel, Strategie, Q, Limit, Erklaerung);
|
||||
_rules = await Explanations.GetRuleSetAsync();
|
||||
_data = await Queries.GetAsync();
|
||||
_recent = await Queries.GetRecentAsync(_filter.ToRecentFilter() with { SearchStrategies = StrategyNames.Matching(_filter.Q) });
|
||||
_loadedAt = DateTime.Now;
|
||||
@@ -318,6 +353,11 @@
|
||||
yield return ($"Strategie: {StrategyNames.Display(strategie)}{(badges.Count == 0 ? "" : $" ({string.Join(", ", badges)})")}", reset with { Strategie = null });
|
||||
}
|
||||
|
||||
if (_filter.Erklaerung is { } erklaerung)
|
||||
{
|
||||
yield return ($"Erklärung: {DashboardFilter.Explanations.First(e => e.Value == erklaerung).Label}", reset with { Erklaerung = null });
|
||||
}
|
||||
|
||||
if (_filter.Q is { } q)
|
||||
{
|
||||
yield return ($"Suche: „{q}“", reset with { Q = null });
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
@page "/erklaerungen"
|
||||
@using Flypaper.Storage.Entities
|
||||
@using Flypaper.Storage.Explanations
|
||||
@inject ExplanationRuleStore Store
|
||||
@inject ExplanationQueries Queries
|
||||
|
||||
<PageTitle>Flypaper · Erklärungen</PageTitle>
|
||||
|
||||
<header class="page-head">
|
||||
<h1>Erklärungen</h1>
|
||||
<p>Regeln, die in der Fang-Liste erklären, was ein Bot wollte. Neue Regeln legt eine KI per MCP an. Änderungen gelten sofort, auch für alte Fänge.</p>
|
||||
</header>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<h2>Regeln <span class="count">· @_rules.Count</span></h2>
|
||||
<span class="hint"><a href="/?erklaerung=ohne#faenge">Fänge ohne Erklärung anzeigen</a></span>
|
||||
</div>
|
||||
@if (_rules.Count == 0)
|
||||
{
|
||||
<p class="empty">Noch keine Regeln.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="scroll">
|
||||
<table class="s-table rule-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Art</th>
|
||||
<th>Muster</th>
|
||||
<th>Text</th>
|
||||
<th class="num">Priorität</th>
|
||||
<th class="num">Treffer</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var rule in _rules)
|
||||
{
|
||||
<tr class="@(rule.Enabled ? null : "off")">
|
||||
<td class="nowrap">@KindLabel(rule.Kind)</td>
|
||||
<td class="mono">@rule.Pattern</td>
|
||||
<td>
|
||||
@rule.Text
|
||||
<div class="muted rule-meta">
|
||||
@(rule.Note is { } note ? note + " · " : "")von @rule.CreatedBy, @rule.UpdatedAt.ToLocalTime().ToString("dd.MM.yyyy")
|
||||
</div>
|
||||
</td>
|
||||
<td class="num">@rule.Priority</td>
|
||||
<td class="num">@Formatting.Number(_hits.GetValueOrDefault(rule.Id))</td>
|
||||
<td class="nowrap">
|
||||
<form method="post" action="/explanations/@rule.Id/enabled" class="inline-form">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="enabled" value="@(rule.Enabled ? "false" : "true")" />
|
||||
<button type="submit" class="ghost">@(rule.Enabled ? "Ausschalten" : "Einschalten")</button>
|
||||
</form>
|
||||
</td>
|
||||
<td class="nowrap">
|
||||
<form method="post" action="/explanations/@rule.Id/delete" class="inline-form" onsubmit="return confirm('Regel wirklich löschen?')">
|
||||
<AntiforgeryToken />
|
||||
<button type="submit" class="ghost danger-text">Löschen</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private IReadOnlyList<ExplanationRuleEntity> _rules = [];
|
||||
private IReadOnlyDictionary<int, int> _hits = new Dictionary<int, int>();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_rules = await Store.ListAsync();
|
||||
_hits = await Queries.CountHitsAsync();
|
||||
}
|
||||
|
||||
private static string KindLabel(ExplanationKind kind) => kind switch
|
||||
{
|
||||
ExplanationKind.Target => "Ziel",
|
||||
ExplanationKind.ClientInfo => "User-Agent",
|
||||
_ => "Ausgang"
|
||||
};
|
||||
}
|
||||
@@ -5,11 +5,19 @@
|
||||
@inject McpTokenStore Store
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<SettingsSection Id="mcp" Title="MCP-Zugriff" Description="KI-Assistenten wie Claude lesen die Fänge über das Model Context Protocol Nur im LAN.">
|
||||
<SettingsSection Id="mcp" Title="MCP-Zugriff" Description="KI-Assistenten wie Claude lesen die Fänge über das Model Context Protocol und pflegen die Erklärungsregeln. Regeln ändern dürfen nur Tokens mit Schreibrecht. Nur im LAN.">
|
||||
@if (Revoked == "revoked")
|
||||
{
|
||||
<Notice>Token widerrufen.</Notice>
|
||||
}
|
||||
else if (Revoked == "write-on")
|
||||
{
|
||||
<Notice>Schreibrecht erteilt.</Notice>
|
||||
}
|
||||
else if (Revoked == "write-off")
|
||||
{
|
||||
<Notice>Schreibrecht entzogen.</Notice>
|
||||
}
|
||||
|
||||
@if (_newToken is not null)
|
||||
{
|
||||
@@ -37,6 +45,7 @@
|
||||
<th>Name</th>
|
||||
<th>Erstellt</th>
|
||||
<th>Zuletzt genutzt</th>
|
||||
<th>Zugriff</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -47,6 +56,14 @@
|
||||
<td>@token.Name</td>
|
||||
<td class="nowrap">@token.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</td>
|
||||
<td class="nowrap">@(token.LastUsedAt?.ToLocalTime().ToString("dd.MM.yyyy HH:mm") ?? "nie")</td>
|
||||
<td class="nowrap">
|
||||
<form method="post" action="/mcp-tokens/@token.Id/write" class="inline-form">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="enabled" value="@(token.CanWrite ? "false" : "true")" />
|
||||
<span>@(token.CanWrite ? "Lesen und schreiben" : "Nur lesen")</span>
|
||||
<button type="submit" class="ghost">@(token.CanWrite ? "Schreibrecht entziehen" : "Schreibrecht erteilen")</button>
|
||||
</form>
|
||||
</td>
|
||||
<td class="num">
|
||||
<form method="post" action="/mcp-tokens/@token.Id/revoke" onsubmit="return confirm('Token „@token.Name“ widerrufen?')">
|
||||
<AntiforgeryToken />
|
||||
@@ -72,6 +89,10 @@
|
||||
<span class="field-error">@nameError</span>
|
||||
}
|
||||
</div>
|
||||
<label class="inline-check">
|
||||
<InputCheckbox @bind-Value="Model!.CanWrite" />
|
||||
<span>Mit Schreibrecht</span>
|
||||
</label>
|
||||
<button type="submit">Token erzeugen</button>
|
||||
</EditForm>
|
||||
</SettingsSection>
|
||||
@@ -103,9 +124,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
_newToken = await Tokens.CreateAsync(name);
|
||||
_newToken = await Tokens.CreateAsync(name, Model.CanWrite);
|
||||
_newTokenName = name;
|
||||
Model.Name = null;
|
||||
Model.CanWrite = false;
|
||||
_tokens = await Store.ListAsync();
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,6 @@ namespace Flypaper.Web.Components.Pages.Settings;
|
||||
public sealed class McpTokenModel
|
||||
{
|
||||
public string? Name { get; set; }
|
||||
|
||||
public bool CanWrite { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user