Add IP origin enrichment with DB-IP and world map
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
536aee1f31
commit
3671019e60
47 files changed
+1389
-12
No files matched your search
@@ -10,4 +10,7 @@
|
||||
</form>
|
||||
</nav>
|
||||
@Body
|
||||
<footer class="footer">
|
||||
<a href="https://db-ip.com">IP Geolocation by DB-IP</a> (CC BY 4.0) · Kartendaten: Natural Earth
|
||||
</footer>
|
||||
</main>
|
||||
@@ -1,6 +1,7 @@
|
||||
@page "/"
|
||||
@using Flypaper.Core.Abstractions
|
||||
@using Flypaper.Storage.Dashboard
|
||||
@using Flypaper.Storage.Entities
|
||||
@inject DashboardQueries Queries
|
||||
@inject IConnectionGovernor Governor
|
||||
|
||||
@@ -25,7 +26,11 @@
|
||||
<div class="metric"><span class="label">Abgelehnt</span><span class="value">@data.Rejected.ToString("N0")</span></div>
|
||||
</section>
|
||||
|
||||
<WorldMap CatchesByCountry="data.CatchesByCountry" />
|
||||
|
||||
<section class="tops">
|
||||
<TopTable Title="Top 10 Länder" KeyLabel="Land" Entries="data.TopCountries" ShowFlags="true" />
|
||||
<TopTable Title="Top 10 Provider (ASN)" KeyLabel="Provider" Entries="data.TopProviders" />
|
||||
<TopTable Title="Top 10 IPs" KeyLabel="IP" Entries="data.TopIps" />
|
||||
<TopTable Title="Top 10 Ziele" KeyLabel="Ziel" Entries="data.TopTargets" />
|
||||
</section>
|
||||
@@ -44,6 +49,8 @@
|
||||
<tr>
|
||||
<th>Zeit</th>
|
||||
<th>IP</th>
|
||||
<th>Herkunft</th>
|
||||
<th>Provider</th>
|
||||
<th>Ziel</th>
|
||||
<th>User-Agent</th>
|
||||
<th class="num">Dauer</th>
|
||||
@@ -57,6 +64,18 @@
|
||||
<tr data-expand="event:@trapEvent.Id" tabindex="0" aria-expanded="false">
|
||||
<td class="nowrap">@trapEvent.StartedAt.ToLocalTime().ToString("dd.MM. HH:mm:ss")</td>
|
||||
<td class="mono">@trapEvent.RemoteIp</td>
|
||||
<td class="nowrap" title="@Origin(trapEvent)">
|
||||
@if (trapEvent.CountryCode is { } countryCode)
|
||||
{
|
||||
@($"{Formatting.Flag(countryCode)} {countryCode}")
|
||||
<span class="detail">@Origin(trapEvent)</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="muted">–</span>
|
||||
}
|
||||
</td>
|
||||
<td class="clip" title="@Formatting.Provider(trapEvent.Asn, trapEvent.Provider)">@Formatting.Provider(trapEvent.Asn, trapEvent.Provider)</td>
|
||||
<td class="mono clip" title="@trapEvent.Target">@trapEvent.Target</td>
|
||||
<td class="clip" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
||||
<td class="num">@Formatting.Duration(TimeSpan.FromMilliseconds(trapEvent.DurationMs))</td>
|
||||
@@ -82,4 +101,7 @@
|
||||
_data = await Queries.GetAsync();
|
||||
_loadedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
private static string Origin(TrapEventEntity trapEvent) =>
|
||||
string.Join(", ", new[] { trapEvent.City, trapEvent.Country }.Where(part => !string.IsNullOrEmpty(part)));
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
@foreach (var entry in Entries)
|
||||
{
|
||||
<tr data-expand="@($"{KeyLabel}:{entry.Key}")" tabindex="0" aria-expanded="false">
|
||||
<td class="mono clip" title="@entry.Key">@entry.Key</td>
|
||||
<td class="mono clip" title="@Display(entry)">@(ShowFlags ? $"{Formatting.Flag(entry.Key)} " : "")@Display(entry)</td>
|
||||
<td class="num">@entry.Count.ToString("N0")</td>
|
||||
<td class="num">@Formatting.Duration(entry.HoldTime)</td>
|
||||
</tr>
|
||||
@@ -35,4 +35,8 @@
|
||||
[Parameter, EditorRequired] public required string KeyLabel { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required IReadOnlyList<TopEntry> Entries { get; set; }
|
||||
|
||||
[Parameter] public bool ShowFlags { get; set; }
|
||||
|
||||
private static string Display(TopEntry entry) => entry.Label is null ? entry.Key : $"{entry.Key} · {entry.Label}";
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
@using System.Globalization
|
||||
|
||||
<section class="card">
|
||||
<h2>Herkunft</h2>
|
||||
<svg class="world-map" viewBox="0 0 @Map.Width.ToString(CultureInfo.InvariantCulture) @Map.Height.ToString(CultureInfo.InvariantCulture)" role="img" aria-label="Weltkarte der Fänge nach Land">
|
||||
@foreach (var country in Map.Countries)
|
||||
{
|
||||
var count = Count(country.Code);
|
||||
<path d="@country.Path" class="@($"level-{Level(count)}")"><title>@country.Name: @count.ToString("N0") @(count == 1 ? "Fang" : "Fänge")</title></path>
|
||||
}
|
||||
</svg>
|
||||
<div class="map-legend">
|
||||
<span>0</span>
|
||||
@for (var level = 0; level <= Levels; level++)
|
||||
{
|
||||
<span class="swatch @($"level-{level}")"></span>
|
||||
}
|
||||
<span>@_max.ToString("N0")</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private const int Levels = 5;
|
||||
private int _max;
|
||||
|
||||
[Parameter, EditorRequired] public required IReadOnlyDictionary<string, int> CatchesByCountry { get; set; }
|
||||
|
||||
private static WorldMapData Map => WorldMapData.Instance;
|
||||
|
||||
protected override void OnParametersSet() => _max = CatchesByCountry.Count == 0 ? 0 : CatchesByCountry.Values.Max();
|
||||
|
||||
private int Count(string? code) => code is not null && CatchesByCountry.TryGetValue(code, out var count) ? count : 0;
|
||||
|
||||
private int Level(int count) =>
|
||||
count == 0 || _max == 0 ? 0 : Math.Max(1, (int)Math.Ceiling(Math.Log(count + 1) / Math.Log(_max + 1) * Levels));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Flypaper.Web.Components.Pages.Dashboard;
|
||||
|
||||
internal sealed record WorldMapData(double Width, double Height, IReadOnlyList<WorldMapCountry> Countries)
|
||||
{
|
||||
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
public static WorldMapData Instance { get; } = Load();
|
||||
|
||||
private static WorldMapData Load()
|
||||
{
|
||||
using var stream = typeof(WorldMapData).Assembly.GetManifestResourceStream("Flypaper.Web.world-map.json")
|
||||
?? throw new InvalidOperationException("Embedded world map is missing.");
|
||||
return JsonSerializer.Deserialize<WorldMapData>(stream, JsonOptions)
|
||||
?? throw new InvalidOperationException("Embedded world map is empty.");
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed record WorldMapCountry(string? Code, string Name, string Path);
|
||||
@@ -0,0 +1 @@
|
||||
{"width":1000.0,"height":439.1,"countries":[{"code":"AF","name":"Afghanistan","path":"M669.6,108.7L671,108.7L673.1,109.4L674,109.9L675.5,108.8L676.6,109.4L677,107.9L678.5,108L678.7,107.5L678.6,106.1L679.3,104.9L680.9,105.7L681,106.7L681.8,106.9L682.4,109.7L683.8,110.8L684.5,110.1L685.5,109.8L686.6,108.3L688.4,108.5L691.1,108.5L691.8,109.5L690.5,109.9L689.4,110.5L686.6,110.9L684,111.6L683,113.1L684,114.5L684.8,116.2L683.9,117.6L684.4,119L684.1,120.2L681.6,120.1L683.2,122.4L681.8,123.3L681.2,125.4L681.9,127.5L681.1,128.4L680.1,128.1L678.2,128.6L678.1,129.5L676.2,129.5L675.2,131.5L675.8,134.5L672.6,136L670.7,135.7L670.4,136.5L668.7,136L666.1,136.5L661.3,134.7L663,131.5L662.3,129.3L660.2,128.7L659.5,126.5L658,123.7L658.7,121.8L657.4,121.3L657.6,118.8L657.5,114.5L660.5,115.8L662.3,115.4L662.5,113.8L664.4,113.3L665.5,112.3L665.3,109.6L667.2,108.9L667.3,107.7L668.8,108.6L669.6,108.7Z"},{"code":"AL","name":"Albanien","path":"M552.5,97.2L552.5,98L551.7,98.5L551.7,99.6L550.7,101.2L550.2,100.9L550.1,100.2L548.6,99.1L548.2,97.5L548.2,95.3L548.5,94.3L548,93.8L547.8,92.8L548.7,91.2L548.9,91.8L549.5,91.5L550.1,92.4L550.8,92.7L551,93.9L550.8,95L551.3,96.4L552.5,97.2Z"},{"code":"DZ","name":"Algerien","path":"M476.7,143.4L476.8,142.7L476.8,142.5L476.9,138.2L481.3,135.6L483.9,135.1L486.1,134.1L487.2,132.4L490.3,131L490.4,128.4L491.9,128.1L493.1,126.8L496.6,126.2L497.1,124.8L496.4,124.1L495.5,120.4L495.4,118.4L494.4,116.2L496.9,114.3L499.7,113.7L501.3,112.3L503.8,111.3L508.1,110.7L512.3,110.4L513.6,110.9L516,109.6L518.7,109.5L519.8,110.3L521.5,110.1L521.1,111.9L521.6,115.1L521.1,117.9L519.5,119.8L519.8,122.4L522,124.5L522.1,125.3L523.7,126.7L525.1,133L526,136.2L526.2,137.8L525.9,140.7L526.1,142.3L525.8,144.3L526.1,146.6L525.1,148.1L526.8,150.7L526.9,152.2L527.9,154.3L529.2,153.6L531.4,155.3L532.6,157.6L523.5,164.5L515.6,171.8L511.8,173.4L508.7,173.8L508.7,171.4L507.4,170.8L505.7,169.8L505,168L495.8,160L486.7,152.1L476.7,143.4Z"},{"code":"AO","name":"Angola","path":"M536.7,264L535.7,264.8L535.2,265.8L535.1,267.4L534.4,267.8L533.7,265L534.8,263.3L535.7,262.7L536.7,264ZM534.8,269L536,268.5L536.8,268.6L537.8,268.1L546.1,268.1L546.8,271L547.5,273.3L548.2,274.5L549.2,276.5L551.1,276.2L552,275.6L553.6,276.2L554,275.2L554.8,273L556.5,272.9L556.7,272.2L558.1,272.2L557.8,273.6L561.3,273.5L561.3,275.9L561.8,277.4L561.4,279.7L561.5,282L562.4,283.4L562.2,287.9L562.9,287.5L564.1,287.6L565.8,287.1L567.1,287.3L567.4,288.5L567,290.3L567.4,292.1L567,293.5L567.2,294.8L561.3,294.7L560.8,306.7L562.5,309.7L564.3,312L559.1,313.5L552.4,313L550.6,311.2L539.3,311.4L538.9,311.7L537.3,310L535.5,309.9L533.8,310.5L532.5,311.2L532.3,308.9L532.7,305.6L533.8,302.2L533.9,300.6L534.9,297.2L535.6,295.6L537.3,293.2L538.2,291.5L538.5,288.7L538.4,286.6L537.6,285.2L536.9,282.9L536.2,280.6L536.4,279.8L537.3,278.3L536.5,274.7L535.9,272.1L534.5,269.7L534.8,269Z"},{"code":"AR","name":"Argentinien","path":"M343.2,430.7L344.7,432L346.9,434.2L350.6,435.8L354.1,436.5L353.8,437.9L351.7,438.1L350.1,437.1L348.7,437L346.3,437L343.2,430.7ZM347.6,358.1L347.5,361L347.5,364.6L348.3,368L347.9,368.8L348.2,371L348.5,372.8L352.4,375.8L352.6,378.1L354.6,379.6L354.9,381.2L353.5,385.5L350.2,387.3L345.3,388L342.5,387.7L343.6,389.7L343.8,392.1L344.7,393.8L343.6,395L341.2,395.4L338.4,394.2L337.7,395.1L339.1,398.3L341.1,399.3L342.1,398.3L343.4,399.9L341.5,400.9L340.2,402.9L340.9,406.1L341,407.8L338.7,407.8L337.4,409.4L337.6,411.8L340.8,414L343.4,414.6L343.6,417.4L341.5,419.1L341.5,422.6L339.9,423.8L339.5,425.2L341.7,428.2L344,429.9L342.9,429.7L340.6,429.3L334.9,428.9L333.1,427.2L332.1,425L330.6,425.2L329.3,424.1L327.6,421L328.8,419.6L328.7,417.7L327.8,416.2L327.9,413.6L327.1,409.5L326.1,407.6L326.9,407L326.2,405.8L324.8,405.2L325.1,403.9L323.6,402.6L321.6,398.9L322.4,398.3L320.5,394.3L319.9,390.9L319.6,388L320.7,386.8L318.9,383.5L318,380.4L319.2,378.2L318.4,375.4L318.9,372L318,368.8L317.2,368.2L314.4,362.2L315.2,358.6L314.1,355.1L314.3,351.9L315.3,348.6L316.7,346.3L315.7,344.9L316,343.8L314.7,337.7L317.3,336L317.6,332.2L317.1,331.3L318.9,328L322.6,328.8L324.6,331.5L325.2,328.5L328.3,328.7L328.9,329.5L334.8,335.4L337.2,336L340.9,338.7L343.9,340.1L344.6,341.7L342.9,347.1L345.7,348.1L348.8,348.7L350.9,348.1L352.8,345.3L352.8,342.2L354,341.5L355.7,343.6L356.1,346.4L354.1,348.4L352.6,349.9L350.2,353.3L347.6,358.1Z"},{"code":"AM","name":"Armenien","path":"M617.6,104L616.7,104.1L615.2,102.2L615.1,101.7L614,101.7L613.1,100.8L612.6,100.9L611.4,99.9L609.4,99.1L609.3,97.5L608.6,96.3L611.9,95.8L612.6,96.7L613.7,97.3L613.4,98.1L615,99.2L614.5,100.3L615.8,101.2L617,101.7L617.6,104Z"},{"code":"AZ","name":"Aserbaidschan","path":"M615,93.8L615.8,94L617.9,95.9L619.1,96.2L619.3,95.3L620.5,94L622.2,95.7L624,98L625.2,98.2L626.2,99.1L624.2,99.3L624.4,101.9L624.2,103.1L623.5,103.9L623.9,105.5L623.3,105.7L621.4,103.9L621.9,102.3L620.9,101.3L620,101.6L617.6,104L617,101.7L615.8,101.2L614.5,100.3L615,99.2L613.4,98.1L613.7,97.3L612.6,96.7L611.9,95.8L612.4,95.3L614.5,96.2L615.9,96.4L616.1,96.1L614.5,94.3L615,93.8ZM616.7Line truncated
|
||||
@@ -9,4 +9,11 @@ public static class Formatting
|
||||
{ TotalMinutes: >= 1 } => $"{duration.Minutes} min {duration.Seconds} s",
|
||||
_ => $"{duration.TotalSeconds:0.0} s"
|
||||
};
|
||||
|
||||
public static string Flag(string? countryCode) =>
|
||||
countryCode is { Length: 2 } && char.IsAsciiLetter(countryCode[0]) && char.IsAsciiLetter(countryCode[1])
|
||||
? string.Concat(countryCode.ToUpperInvariant().Select(c => char.ConvertFromUtf32(0x1F1E6 + c - 'A')))
|
||||
: "";
|
||||
|
||||
public static string? Provider(long? asn, string? provider) => asn is null ? provider : $"AS{asn} {provider}".TrimEnd();
|
||||
}
|
||||
@@ -5,6 +5,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="Components\Pages\Dashboard\world-map.json" />
|
||||
<EmbeddedResource Include="Components\Pages\Dashboard\world-map.json" LogicalName="Flypaper.Web.world-map.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Flypaper.GeoIp\Flypaper.GeoIp.csproj" />
|
||||
<ProjectReference Include="..\Flypaper.Http\Flypaper.Http.csproj" />
|
||||
<ProjectReference Include="..\Flypaper.Storage\Flypaper.Storage.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Flypaper.Core;
|
||||
using Flypaper.GeoIp;
|
||||
using Flypaper.Http;
|
||||
using Flypaper.Storage;
|
||||
using Flypaper.Web.Auth;
|
||||
@@ -16,6 +17,7 @@ builder.AddFlypaperStorage();
|
||||
builder.Services.AddRazorComponents();
|
||||
builder.Services.AddFlypaperCore(builder.Configuration);
|
||||
builder.Services.AddFlypaperHttp(builder.Configuration);
|
||||
builder.Services.AddFlypaperGeoIp(builder.Configuration);
|
||||
|
||||
var dataProtection = builder.Services.AddDataProtection().SetApplicationName("Flypaper");
|
||||
if (builder.Configuration["Flypaper:DataProtection:KeysPath"] is { Length: > 0 } keysPath)
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore": "Warning"
|
||||
"Microsoft.EntityFrameworkCore": "Warning",
|
||||
"System.Net.Http.HttpClient": "Warning"
|
||||
},
|
||||
"Console": {
|
||||
"FormatterName": "simple",
|
||||
|
||||
@@ -369,3 +369,85 @@ tbody th {
|
||||
.top h1 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.world-map {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.world-map path {
|
||||
stroke: var(--surface);
|
||||
stroke-width: 0.5;
|
||||
}
|
||||
|
||||
.world-map path:hover {
|
||||
stroke: var(--text);
|
||||
stroke-width: 1;
|
||||
}
|
||||
|
||||
.level-0 {
|
||||
fill: color-mix(in srgb, var(--text) 10%, var(--surface));
|
||||
background: color-mix(in srgb, var(--text) 10%, var(--surface));
|
||||
}
|
||||
|
||||
.level-1 {
|
||||
fill: color-mix(in srgb, var(--accent) 25%, var(--surface));
|
||||
background: color-mix(in srgb, var(--accent) 25%, var(--surface));
|
||||
}
|
||||
|
||||
.level-2 {
|
||||
fill: color-mix(in srgb, var(--accent) 42%, var(--surface));
|
||||
background: color-mix(in srgb, var(--accent) 42%, var(--surface));
|
||||
}
|
||||
|
||||
.level-3 {
|
||||
fill: color-mix(in srgb, var(--accent) 60%, var(--surface));
|
||||
background: color-mix(in srgb, var(--accent) 60%, var(--surface));
|
||||
}
|
||||
|
||||
.level-4 {
|
||||
fill: color-mix(in srgb, var(--accent) 80%, var(--surface));
|
||||
background: color-mix(in srgb, var(--accent) 80%, var(--surface));
|
||||
}
|
||||
|
||||
.level-5 {
|
||||
fill: var(--accent);
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.map-legend {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.map-legend .swatch {
|
||||
width: 18px;
|
||||
height: 10px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.detail {
|
||||
display: none;
|
||||
}
|
||||
|
||||
tr.open .detail {
|
||||
display: block;
|
||||
color: var(--muted);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 24px;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: inherit;
|
||||
}
|
||||
Reference in new issue
Block a user