fix(dashboard): show enriched network details
CI / validate (push) Successful in 5m39s
Release / release (push) Successful in 7m15s

This commit is contained in:
dmg
2026-08-02 08:05:57 -04:00
parent aa0b757814
commit 24808b0f8c
12 changed files with 106 additions and 14 deletions
+7 -2
View File
@@ -5,7 +5,7 @@ import Link from "next/link";
import { UserWorldMap, type UserMapLocation } from "@/components/user-world-map";
import { db } from "@/lib/database";
import { fillDailySeries, mergeRiskActivity, type DailyCount } from "@/lib/admin-metrics";
import { parseUserLocation } from "@/lib/user-location-map";
import { parseUserLocation, parseUserNetwork } from "@/lib/user-location-map";
export const dynamic = "force-dynamic";
@@ -43,7 +43,7 @@ export default async function AdminDashboardPage() {
name: users.firstName,
discordUsername: users.discordUsername,
primaryUsername: minecraftAccounts.username,
classification: ipObservations.classification,
classification: ipIntelligence.classification,
source: ipObservations.source,
observedAt: ipObservations.observedAt,
intelligence: ipIntelligence.rawResponse,
@@ -108,6 +108,7 @@ export default async function AdminDashboardPage() {
const locations = locationRows.flatMap((row): UserMapLocation[] => {
const parsed = parseUserLocation(row.intelligence);
if (!parsed || !row.userId) return [];
const network = parseUserNetwork(row.intelligence);
return [{
userId: row.userId,
name: row.name ?? row.discordUsername,
@@ -117,6 +118,10 @@ export default async function AdminDashboardPage() {
longitude: parsed.longitude,
location: parsed.label,
classification: row.classification,
networkProvider: network.provider,
networkAsn: network.asn,
connectionType: network.connectionType,
proxy: network.proxy,
source: row.source,
observedAt: row.observedAt,
}];
@@ -13,6 +13,10 @@ describe("UserWorldMap", () => {
longitude: -122.0775,
location: "Mountain View, California, US",
classification: "clear",
networkProvider: "Comcast Cable Communications, LLC",
networkAsn: "AS7922",
connectionType: "Residential",
proxy: false,
source: "game",
observedAt: new Date("2026-08-01T12:00:00Z"),
}, {
@@ -23,7 +27,11 @@ describe("UserWorldMap", () => {
latitude: 37.4057,
longitude: -122.0774,
location: "Mountain View, California, US",
classification: "clear",
classification: "vpn",
networkProvider: "Proton AG",
networkAsn: "AS62371",
connectionType: "VPN",
proxy: true,
source: "web",
observedAt: new Date("2026-08-01T13:00:00Z"),
}]} unavailableCount={2} />);
@@ -38,6 +46,13 @@ describe("UserWorldMap", () => {
expect(markup).toMatch(/<text[^>]*>2<\/text>/);
expect(markup).toContain('<details class="mt-5 border-t border-line pt-4" id="map-location-list" open="">');
expect(markup).toContain("Mountain View, California, US");
expect(markup).toContain("Comcast Cable Communications, LLC");
expect(markup).toContain("AS7922");
expect(markup).toContain("Residential");
expect(markup).toContain("Proton AG");
expect(markup).toContain(">Proxy/VPN<");
expect(markup).toContain(">Yes<");
expect(markup).toContain(">No<");
expect(markup).toContain("World overview");
expect(markup).toContain("Interactive OpenStreetMap");
expect(markup).toContain("OpenStreetMap, which receives your IP address");
+9 -5
View File
@@ -23,6 +23,10 @@ export interface UserMapLocation {
longitude: number;
location: string;
classification: string;
networkProvider: string | null;
networkAsn: string | null;
connectionType: string | null;
proxy: boolean | null;
source: string;
observedAt: Date;
}
@@ -98,12 +102,12 @@ export function UserWorldMap({ locations, unavailableCount }: { locations: UserM
<details className="mt-5 border-t border-line pt-4" id="map-location-list" open={locationGroups.some((group) => group.count > 1)}>
<summary className="w-fit cursor-pointer font-mono text-[10px] font-bold uppercase underline underline-offset-4">View accessible location list</summary>
<div className="mt-4 overflow-x-auto">
<table className="w-full min-w-[680px] border-collapse text-left text-xs">
<caption className="sr-only">Latest approximate registered-user locations</caption>
<thead className="border-b border-line font-mono text-[9px] uppercase tracking-wider text-muted"><tr><th className="py-3 pr-4" scope="col">User</th><th className="p-3" scope="col">Location</th><th className="p-3" scope="col">Network</th><th className="p-3" scope="col">Source</th><th className="py-3 pl-4" scope="col">Last observed</th></tr></thead>
<table className="w-full min-w-[980px] border-collapse text-left text-xs">
<caption className="sr-only">Latest approximate registered-user locations and enriched network details</caption>
<thead className="border-b border-line font-mono text-[9px] uppercase tracking-wider text-muted"><tr><th className="py-3 pr-4" scope="col">User</th><th className="p-3" scope="col">Location</th><th className="p-3" scope="col">Network</th><th className="p-3" scope="col">Connection</th><th className="p-3" scope="col">Proxy/VPN</th><th className="p-3" scope="col">Risk</th><th className="p-3" scope="col">Source</th><th className="py-3 pl-4" scope="col">Last observed</th></tr></thead>
<tbody className="divide-y divide-line">
{locations.map((user) => <tr key={user.userId}><th className="py-3 pr-4 text-left" scope="row"><Link className="font-mono font-bold underline underline-offset-4" href={`/admin/users/${user.userId}`}>{user.nickname}</Link><span className="mt-1 block font-mono text-[9px] font-normal text-muted">@{user.discordUsername}</span></th><td className="p-3">{user.location}</td><td className="p-3 font-mono uppercase">{user.classification}</td><td className="p-3">{user.source}</td><td className="py-3 pl-4 font-mono text-[9px]"><time dateTime={user.observedAt.toISOString()}>{user.observedAt.toISOString()}</time></td></tr>)}
{!locations.length && <tr><td className="py-6 text-muted" colSpan={5}>No user observations currently include valid coordinates.</td></tr>}
{locations.map((user) => <tr key={user.userId}><th className="py-3 pr-4 text-left" scope="row"><Link className="font-mono font-bold underline underline-offset-4" href={`/admin/users/${user.userId}`}>{user.nickname}</Link><span className="mt-1 block font-mono text-[9px] font-normal text-muted">@{user.discordUsername}</span></th><td className="p-3">{user.location}</td><td className="p-3"><span className="block">{user.networkProvider ?? "Unknown"}</span>{user.networkAsn && <span className="mt-1 block font-mono text-[9px] text-muted">{user.networkAsn}</span>}</td><td className="p-3">{user.connectionType ?? "Unknown"}</td><td className="p-3 font-mono font-bold uppercase">{user.proxy === null ? "Unknown" : user.proxy ? "Yes" : "No"}</td><td className="p-3 font-mono uppercase">{user.classification}</td><td className="p-3">{user.source}</td><td className="py-3 pl-4 font-mono text-[9px]"><time dateTime={user.observedAt.toISOString()}>{user.observedAt.toISOString()}</time></td></tr>)}
{!locations.length && <tr><td className="py-6 text-muted" colSpan={8}>No user observations currently include valid coordinates.</td></tr>}
</tbody>
</table>
</div>
+24 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { groupMapLocations, parseUserLocation, projectWorldPoint } from "./user-location-map";
import { groupMapLocations, parseUserLocation, parseUserNetwork, projectWorldPoint } from "./user-location-map";
describe("user location map", () => {
it("extracts a valid approximate location from cached IP intelligence", () => {
@@ -19,6 +19,29 @@ describe("user location map", () => {
});
});
it("extracts enriched network fields from existing ProxyCheck cache entries", () => {
expect(parseUserNetwork({
network: { asn: "AS7922", provider: "Comcast Cable Communications, LLC" },
rawResponse: {
status: "ok",
"203.0.113.10": { type: "Residential", proxy: "no" },
},
})).toEqual({
asn: "AS7922",
provider: "Comcast Cable Communications, LLC",
connectionType: "Residential",
proxy: false,
});
});
it("prefers normalized network fields and preserves unavailable values", () => {
expect(parseUserNetwork({
network: { asn: "AS62371", provider: "Proton AG", connectionType: "VPN", proxy: true },
rawResponse: { "198.51.100.5": { type: "Residential", proxy: "no" } },
})).toEqual({ asn: "AS62371", provider: "Proton AG", connectionType: "VPN", proxy: true });
expect(parseUserNetwork({ network: {} })).toEqual({ asn: null, provider: null, connectionType: null, proxy: null });
});
it("rejects missing and out-of-range coordinates", () => {
expect(parseUserLocation({ location: { latitude: 91, longitude: 0 } })).toBeNull();
expect(parseUserLocation({ location: { city: "Unknown" } })).toBeNull();
+33
View File
@@ -6,6 +6,17 @@ function objectValue(value: unknown): UnknownMap | null {
: null;
}
function stringValue(value: unknown) {
return typeof value === "string" && value.trim() ? value.trim() : null;
}
function proxyValue(value: unknown) {
if (typeof value === "boolean") return value;
if (typeof value === "string" && value.toLowerCase() === "yes") return true;
if (typeof value === "string" && value.toLowerCase() === "no") return false;
return null;
}
function coordinate(value: unknown) {
if (typeof value === "number" && Number.isFinite(value)) return value;
if (typeof value === "string" && value.trim() && Number.isFinite(Number(value))) return Number(value);
@@ -18,6 +29,28 @@ export interface ParsedUserLocation {
label: string;
}
export interface ParsedUserNetwork {
asn: string | null;
provider: string | null;
connectionType: string | null;
proxy: boolean | null;
}
export function parseUserNetwork(value: unknown): ParsedUserNetwork {
const intelligence = objectValue(value);
const network = objectValue(intelligence?.network);
const providerResponse = objectValue(intelligence?.rawResponse);
const legacyDetails = Object.values(providerResponse ?? {})
.map(objectValue)
.find((details) => details && ("type" in details || "proxy" in details));
return {
asn: stringValue(network?.asn),
provider: stringValue(network?.provider),
connectionType: stringValue(network?.connectionType) ?? stringValue(legacyDetails?.type),
proxy: proxyValue(network?.proxy) ?? proxyValue(legacyDetails?.proxy),
};
}
export function parseUserLocation(value: unknown): ParsedUserLocation | null {
const intelligence = objectValue(value);
const location = objectValue(intelligence?.location);