feat: build wahrwelt A/D toolkit
This commit is contained in:
1 parent
303438d206
commit
653924d8c6
564 files changed
+36310
-49998
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#30343a" />
|
||||
<link rel="icon" type="image/jpeg" href="/logo.jpg" />
|
||||
<meta name="description" content="wahrwelt: просмотр трафика в Packmate" />
|
||||
<title>wahrwelt / Packmate</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "wahrwelt-packmate-ui",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite --host 127.0.0.1",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"build": "tsc --noEmit && vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": ">=19.3.0",
|
||||
"react-dom": ">=19.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": ">=7.0.1",
|
||||
"@testing-library/react": ">=16.3.3",
|
||||
"@testing-library/user-event": ">=14.6.8",
|
||||
"@types/react": ">=19.3.0",
|
||||
"@types/react-dom": ">=19.3.0",
|
||||
"@vitejs/plugin-react": ">=6.1.2",
|
||||
"happy-dom": ">=21.0.1",
|
||||
"typescript": ">=7.0.2",
|
||||
"vite": ">=8.3.4",
|
||||
"vitest": ">=5.0.4"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -0,0 +1,219 @@
|
||||
import { act, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import App from "./App";
|
||||
import type { Packet, Service, Stream } from "./types";
|
||||
|
||||
const { apiMock } = vi.hoisted(() => ({
|
||||
apiMock: {
|
||||
services: vi.fn(),
|
||||
createService: vi.fn(),
|
||||
updateService: vi.fn(),
|
||||
deleteService: vi.fn(),
|
||||
patterns: vi.fn(),
|
||||
createPattern: vi.fn(),
|
||||
updatePattern: vi.fn(),
|
||||
setPatternEnabled: vi.fn(),
|
||||
deletePattern: vi.fn(),
|
||||
lookBack: vi.fn(),
|
||||
streams: vi.fn(),
|
||||
packets: vi.fn(),
|
||||
setFavorite: vi.fn(),
|
||||
pcapStarted: vi.fn(),
|
||||
startPcap: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("./api", () => ({ api: apiMock }));
|
||||
class MockWebSocket {
|
||||
static instances: MockWebSocket[] = [];
|
||||
onopen: (() => void) | null = null;
|
||||
onmessage: ((event: MessageEvent<string>) => void) | null = null;
|
||||
onerror: (() => void) | null = null;
|
||||
onclose: (() => void) | null = null;
|
||||
close = vi.fn();
|
||||
|
||||
constructor(readonly url: string) {
|
||||
MockWebSocket.instances.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
function deferred<T>() {
|
||||
let resolve!: (value: T) => void;
|
||||
const promise = new Promise<T>((done) => { resolve = done; });
|
||||
return { promise, resolve };
|
||||
}
|
||||
|
||||
function service(port: number, name: string): Service {
|
||||
return {
|
||||
port,
|
||||
name,
|
||||
decryptTls: false,
|
||||
http: false,
|
||||
urldecodeHttpRequests: false,
|
||||
mergeAdjacentPackets: false,
|
||||
parseWebSockets: false,
|
||||
};
|
||||
}
|
||||
|
||||
function stream(id: number, port = 80): Stream {
|
||||
return {
|
||||
id,
|
||||
service: port,
|
||||
protocol: "TCP",
|
||||
startTimestamp: 1_700_000_000_000,
|
||||
endTimestamp: 1_700_000_000_100,
|
||||
foundPatternsIds: [],
|
||||
favorite: false,
|
||||
ttl: 64,
|
||||
userAgentHash: null,
|
||||
sizeBytes: 10,
|
||||
packetsCount: 1,
|
||||
};
|
||||
}
|
||||
|
||||
function packet(id: number, text: string): Packet {
|
||||
return {
|
||||
id,
|
||||
matches: [],
|
||||
timestamp: 1_700_000_000_000 + id,
|
||||
incoming: true,
|
||||
ungzipped: false,
|
||||
webSocketParsed: false,
|
||||
tlsDecrypted: false,
|
||||
hasHttpBody: false,
|
||||
content: btoa(String.fromCharCode(...new TextEncoder().encode(text))),
|
||||
};
|
||||
}
|
||||
|
||||
function pageOfStreams(firstId = 10): Stream[] {
|
||||
return Array.from({ length: 10 }, (_, index) => stream(firstId - index));
|
||||
}
|
||||
|
||||
function pageOfPackets(firstId = 100): Packet[] {
|
||||
return Array.from({ length: 10 }, (_, index) => packet(firstId - index, `пакет-${firstId - index}`));
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
MockWebSocket.instances = [];
|
||||
vi.stubGlobal("WebSocket", MockWebSocket);
|
||||
window.history.replaceState({}, "", "/");
|
||||
localStorage.clear();
|
||||
localStorage.setItem("packmate.pageSize", "10");
|
||||
for (const method of Object.values(apiMock)) {
|
||||
method.mockReset();
|
||||
}
|
||||
apiMock.services.mockResolvedValue([service(80, "HTTP"), service(443, "HTTPS")]);
|
||||
apiMock.patterns.mockResolvedValue([]);
|
||||
apiMock.pcapStarted.mockResolvedValue(false);
|
||||
});
|
||||
|
||||
it("получает события через WebSocket и сохраняет остановку короткого PCAP", async () => {
|
||||
const startRequest = deferred<void>();
|
||||
apiMock.streams.mockResolvedValue([]);
|
||||
apiMock.startPcap.mockReturnValue(startRequest.promise);
|
||||
const view = render(<App />);
|
||||
const startButton = await screen.findByTitle("Начать обработку PCAP-файла");
|
||||
const socket = MockWebSocket.instances.at(-1)!;
|
||||
expect(socket.url).toBe(`ws://${window.location.host}/api/ws`);
|
||||
|
||||
fireEvent.click(startButton);
|
||||
await act(async () => {
|
||||
socket.onmessage?.(new MessageEvent("message", {
|
||||
data: JSON.stringify({ type: "PCAP_STARTED", value: null }),
|
||||
}));
|
||||
socket.onmessage?.(new MessageEvent("message", {
|
||||
data: JSON.stringify({ type: "PCAP_STOPPED", value: null }),
|
||||
}));
|
||||
startRequest.resolve();
|
||||
});
|
||||
|
||||
expect(screen.getByTitle("Начать обработку PCAP-файла")).toBeInTheDocument();
|
||||
view.unmount();
|
||||
expect(socket.close).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
describe("смена выборки во время загрузки", () => {
|
||||
it("не добавляет позднюю страницу потоков к выбранному другому сервису", async () => {
|
||||
const oldPage = deferred<Stream[]>();
|
||||
apiMock.streams.mockImplementation((port: number | undefined, query: { startingFrom: number | null }) => {
|
||||
if (port === 443) {
|
||||
return Promise.resolve([stream(900, 443)]);
|
||||
}
|
||||
return query.startingFrom === null ? Promise.resolve(pageOfStreams()) : oldPage.promise;
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
await screen.findByRole("button", { name: /#10 TCP/ });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Загрузить еще потоки" }));
|
||||
await waitFor(() => expect(apiMock.streams).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
expect.objectContaining({ startingFrom: 1 }),
|
||||
expect.any(AbortSignal),
|
||||
));
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /HTTPS #443/ }));
|
||||
await screen.findByRole("button", { name: /#900 TCP/ });
|
||||
|
||||
await act(async () => oldPage.resolve([stream(99, 80)]));
|
||||
expect(screen.queryByRole("button", { name: /#99 TCP/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /#900 TCP/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("игнорирует поздние пакеты старого потока и не снимает индикатор нового запроса", async () => {
|
||||
const initialPage = deferred<Packet[]>();
|
||||
const currentPage = deferred<Packet[]>();
|
||||
apiMock.streams.mockResolvedValue(pageOfStreams());
|
||||
apiMock.packets.mockImplementation((streamId: number, query: { startingFrom: number | null }) => {
|
||||
if (streamId === 10 && query.startingFrom === null) {
|
||||
return initialPage.promise;
|
||||
}
|
||||
if (streamId === 9 && query.startingFrom === null) {
|
||||
return currentPage.promise;
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
fireEvent.click(await screen.findByRole("button", { name: /#10 TCP/ }));
|
||||
await waitFor(() => expect(apiMock.packets).toHaveBeenCalledWith(10, { startingFrom: null, pageSize: 10 }, expect.any(AbortSignal)));
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /#9 TCP/ }));
|
||||
await waitFor(() => expect(apiMock.packets).toHaveBeenCalledWith(9, { startingFrom: null, pageSize: 10 }, expect.any(AbortSignal)));
|
||||
await act(async () => initialPage.resolve(pageOfPackets(80)));
|
||||
expect(screen.getByText("Загрузка пакетов...")).toBeInTheDocument();
|
||||
|
||||
await act(async () => currentPage.resolve([packet(1, "актуальный пакет")]));
|
||||
expect(await screen.findByText("актуальный пакет")).toBeInTheDocument();
|
||||
expect(screen.queryByText(/пакет-80/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("отменяет позднюю дополнительную страницу пакетов после выбора другого потока", async () => {
|
||||
const oldPage = deferred<Packet[]>();
|
||||
apiMock.streams.mockResolvedValue(pageOfStreams());
|
||||
apiMock.packets.mockImplementation((streamId: number, query: { startingFrom: number | null }) => {
|
||||
if (streamId === 10 && query.startingFrom === null) {
|
||||
return Promise.resolve(pageOfPackets());
|
||||
}
|
||||
if (streamId === 10) {
|
||||
return oldPage.promise;
|
||||
}
|
||||
return Promise.resolve([packet(2, "пакет выбранного потока")]);
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
fireEvent.click(await screen.findByRole("button", { name: /#10 TCP/ }));
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Загрузить еще пакеты" }));
|
||||
await waitFor(() => expect(apiMock.packets).toHaveBeenCalledWith(
|
||||
10,
|
||||
{ startingFrom: 91, pageSize: 10 },
|
||||
expect.any(AbortSignal),
|
||||
));
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: /#9 TCP/ }));
|
||||
expect(await screen.findByText("пакет выбранного потока")).toBeInTheDocument();
|
||||
await act(async () => oldPage.resolve([packet(80, "пакет-старого потока")]));
|
||||
|
||||
expect(screen.queryByText("пакет-старого потока")).not.toBeInTheDocument();
|
||||
expect(screen.getByText("пакет выбранного потока")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,95 @@
|
||||
import type {
|
||||
Packet,
|
||||
Pattern,
|
||||
PatternInput,
|
||||
Service,
|
||||
Stream,
|
||||
} from "./types";
|
||||
|
||||
const apiRoot = "/api";
|
||||
|
||||
export class ApiError extends Error {
|
||||
readonly status: number;
|
||||
|
||||
constructor(status: number, serverMessage?: string) {
|
||||
super(status === 401 ? "Требуется войти в Packmate" : serverMessage ?? `Ошибка сервера: ${status}`);
|
||||
this.name = "ApiError";
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
async function request<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
const headers = new Headers(init.headers);
|
||||
if (init.body !== undefined && !headers.has("Content-Type")) {
|
||||
headers.set("Content-Type", "application/json");
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiRoot}/${path.replace(/^\/+/, "")}`, {
|
||||
...init,
|
||||
headers,
|
||||
credentials: "same-origin",
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let serverMessage: string | undefined;
|
||||
if (response.status >= 400 && response.status < 500
|
||||
&& response.headers.get("Content-Type")?.includes("application/json")) {
|
||||
try {
|
||||
const body: unknown = await response.json();
|
||||
if (typeof body === "object" && body !== null && "message" in body
|
||||
&& typeof body.message === "string") {
|
||||
serverMessage = body.message.slice(0, 240);
|
||||
}
|
||||
} catch {
|
||||
serverMessage = undefined;
|
||||
}
|
||||
}
|
||||
throw new ApiError(response.status, serverMessage);
|
||||
}
|
||||
if (response.status === 204) {
|
||||
return undefined as T;
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
if (text.length === 0) {
|
||||
return undefined as T;
|
||||
}
|
||||
return JSON.parse(text) as T;
|
||||
}
|
||||
|
||||
function post<T>(path: string, body?: unknown, signal?: AbortSignal): Promise<T> {
|
||||
return request(path, {
|
||||
method: "POST",
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
export const api = {
|
||||
services: () => request<Service[]>("service/"),
|
||||
createService: (service: Service) => post<Service>("service/", service),
|
||||
updateService: (port: number, service: Service) => post<Service>(`service/${port}`, service),
|
||||
deleteService: (port: number) => request<void>(`service/${port}`, { method: "DELETE" }),
|
||||
patterns: () => request<Pattern[]>("pattern/"),
|
||||
createPattern: (pattern: PatternInput) => post<Pattern>("pattern/", pattern),
|
||||
updatePattern: (id: number, pattern: Pick<Pattern, "name" | "color">) =>
|
||||
post<Pattern>(`pattern/${id}`, pattern),
|
||||
setPatternEnabled: (id: number, enabled: boolean) =>
|
||||
post<void>(`pattern/${id}/enable?enabled=${String(enabled)}`),
|
||||
deletePattern: (id: number) => request<void>(`pattern/${id}`, { method: "DELETE" }),
|
||||
lookBack: (id: number, minutes: number) => post<void>(`pattern/${id}/lookback`, minutes),
|
||||
streams: (
|
||||
servicePort: number | undefined,
|
||||
payload: { startingFrom: number | null; pageSize: number; pattern: { id: number } | null; favorites: boolean },
|
||||
signal?: AbortSignal,
|
||||
) => post<Stream[]>(`stream/${servicePort ?? "all"}`, payload, signal),
|
||||
packets: (
|
||||
streamId: number,
|
||||
payload: { startingFrom: number | null; pageSize: number },
|
||||
signal?: AbortSignal,
|
||||
) => post<Packet[]>(`packet/${streamId}`, payload, signal),
|
||||
setFavorite: (streamId: number, favorite: boolean) =>
|
||||
post<void>(`stream/${streamId}/${favorite ? "favorite" : "unfavorite"}`),
|
||||
pcapStarted: () => request<boolean>("pcap/started"),
|
||||
startPcap: () => post<void>("pcap/start"),
|
||||
};
|
||||
@@ -0,0 +1,106 @@
|
||||
import { useMemo } from "react";
|
||||
import { decodePacket, hexDump, packetSegments, packetText, pythonBytes, safePatternColor } from "../packet";
|
||||
import type { Packet, Pattern } from "../types";
|
||||
|
||||
interface PacketViewProps {
|
||||
packet: Packet;
|
||||
previous?: Packet;
|
||||
patterns: Pattern[];
|
||||
hexdumpMode: boolean;
|
||||
blockSize: number;
|
||||
lineNumberBase: number;
|
||||
notify: (message: string) => void;
|
||||
}
|
||||
|
||||
function dateText(timestamp: number): string {
|
||||
return new Intl.DateTimeFormat("ru-RU", {
|
||||
dateStyle: "short",
|
||||
timeStyle: "medium",
|
||||
}).format(new Date(timestamp));
|
||||
}
|
||||
|
||||
async function copyText(value: string): Promise<void> {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(value);
|
||||
return;
|
||||
}
|
||||
const field = document.createElement("textarea");
|
||||
field.value = value;
|
||||
field.setAttribute("readonly", "");
|
||||
field.style.position = "fixed";
|
||||
field.style.opacity = "0";
|
||||
document.body.append(field);
|
||||
field.select();
|
||||
const copied = document.execCommand("copy");
|
||||
field.remove();
|
||||
if (!copied) {
|
||||
throw new Error("Буфер обмена недоступен");
|
||||
}
|
||||
}
|
||||
|
||||
export function PacketView({
|
||||
packet,
|
||||
previous,
|
||||
patterns,
|
||||
hexdumpMode,
|
||||
blockSize,
|
||||
lineNumberBase,
|
||||
notify,
|
||||
}: PacketViewProps) {
|
||||
const bytes = useMemo(() => decodePacket(packet.content), [packet.content]);
|
||||
const segments = useMemo(() => packetSegments(packet, patterns), [packet, patterns]);
|
||||
const body = useMemo(
|
||||
() => hexdumpMode ? hexDump(bytes, blockSize, lineNumberBase) : packetText(bytes),
|
||||
[bytes, blockSize, hexdumpMode, lineNumberBase],
|
||||
);
|
||||
const flags = [
|
||||
packet.ungzipped ? "GZIP" : "",
|
||||
packet.webSocketParsed ? "WS" : "",
|
||||
packet.tlsDecrypted ? "TLS" : "",
|
||||
].filter(Boolean);
|
||||
|
||||
const copy = async (value: string, label: string) => {
|
||||
try {
|
||||
await copyText(value);
|
||||
notify(`${label}: скопировано`);
|
||||
} catch {
|
||||
notify("Не удалось скопировать данные");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<article className={`packet ${packet.incoming ? "packet-request" : "packet-response"}`}>
|
||||
<header className="packet-header">
|
||||
<div className="packet-meta">
|
||||
<strong>#{packet.id}</strong>
|
||||
<time dateTime={new Date(packet.timestamp).toISOString()}>{dateText(packet.timestamp)}</time>
|
||||
{previous && <span>+{packet.timestamp - previous.timestamp} мс</span>}
|
||||
<span className="packet-direction">{packet.incoming ? "Запрос" : "Ответ"}</span>
|
||||
{flags.map((flag) => <span className="packet-flag" key={flag}>{flag}</span>)}
|
||||
</div>
|
||||
<div className="packet-actions">
|
||||
<button type="button" className="text-button" onClick={() => void copy(bytesToHex(bytes), "HEX")}>
|
||||
Копировать HEX
|
||||
</button>
|
||||
<button type="button" className="text-button" onClick={() => void copy(packetText(bytes), "Текст")}>
|
||||
Копировать текст
|
||||
</button>
|
||||
<button type="button" className="text-button" onClick={() => void copy(pythonBytes(bytes), "Python bytes")}>
|
||||
Копировать как Python bytes
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<pre className="packet-content">
|
||||
{hexdumpMode
|
||||
? body
|
||||
: segments.map((segment, index) => segment.pattern
|
||||
? <mark key={`${segment.pattern.id}-${index}`} style={{ backgroundColor: safePatternColor(segment.pattern.color) }}>{segment.text}</mark>
|
||||
: <span key={`text-${index}`}>{segment.text}</span>)}
|
||||
</pre>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function bytesToHex(bytes: Uint8Array): string {
|
||||
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { StrictMode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./styles.css";
|
||||
|
||||
const root = document.getElementById("root");
|
||||
if (!root) {
|
||||
throw new Error("Не найден корневой элемент интерфейса Packmate");
|
||||
}
|
||||
|
||||
createRoot(root).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
);
|
||||
@@ -0,0 +1,79 @@
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { PacketView } from "./components/PacketView";
|
||||
import { decodePacket, hexDump, packetSegments } from "./packet";
|
||||
import type { Packet, Pattern } from "./types";
|
||||
|
||||
const pattern: Pattern = {
|
||||
id: 3,
|
||||
enabled: true,
|
||||
deleted: false,
|
||||
name: "Маркер",
|
||||
value: "secret",
|
||||
color: "#ff5959",
|
||||
searchType: "SUBSTRING",
|
||||
directionType: "BOTH",
|
||||
actionType: "FIND",
|
||||
serviceId: null,
|
||||
};
|
||||
|
||||
function packet(text: string): Packet {
|
||||
return {
|
||||
id: 8,
|
||||
matches: [],
|
||||
timestamp: 1_700_000_000_000,
|
||||
incoming: true,
|
||||
ungzipped: false,
|
||||
webSocketParsed: false,
|
||||
tlsDecrypted: false,
|
||||
hasHttpBody: false,
|
||||
content: btoa(String.fromCharCode(...new TextEncoder().encode(text))),
|
||||
};
|
||||
}
|
||||
|
||||
describe("отображение содержимого пакета", () => {
|
||||
it("подсвечивает диапазон совпадения без преобразования байтового содержимого в HTML", () => {
|
||||
const value = packet("до secret после <script>alert(1)</script>");
|
||||
value.matches = [{ patternId: pattern.id, startPosition: 3, endPosition: 8 }];
|
||||
|
||||
const segments = packetSegments(value, [pattern]);
|
||||
expect(segments).toEqual([
|
||||
{ text: "до " },
|
||||
{ text: "secret", pattern },
|
||||
{ text: " после <script>alert(1)</script>" },
|
||||
]);
|
||||
|
||||
const view = render(<PacketView
|
||||
packet={value}
|
||||
patterns={[pattern]}
|
||||
hexdumpMode={false}
|
||||
blockSize={16}
|
||||
lineNumberBase={10}
|
||||
notify={() => undefined}
|
||||
/>);
|
||||
expect(screen.getByText("secret").tagName).toBe("MARK");
|
||||
expect(view.container.querySelector("script")).toBeNull();
|
||||
expect(view.container.textContent).toContain("<script>alert(1)</script>");
|
||||
});
|
||||
|
||||
it("считает диапазон SUBBYTES в байтах, а не UTF-16 позициях", () => {
|
||||
const bytes = new TextEncoder().encode("Жx");
|
||||
const value: Packet = {
|
||||
...packet(""),
|
||||
content: btoa(String.fromCharCode(...bytes)),
|
||||
matches: [{ patternId: 3, startPosition: 2, endPosition: 2 }],
|
||||
};
|
||||
const bytePattern = { ...pattern, searchType: "SUBBYTES" as const, value: "78" };
|
||||
|
||||
expect(packetSegments(value, [bytePattern])).toEqual([
|
||||
{ text: "Ж" },
|
||||
{ text: "x", pattern: bytePattern },
|
||||
]);
|
||||
});
|
||||
|
||||
it("строит читаемые строки HEX-дампа с выбранной шириной", () => {
|
||||
expect(hexDump(decodePacket("AQIDBA=="), 2, 16)).toBe(
|
||||
"0000000000: 01 02 |..|\n0000000002: 03 04 |..|",
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
import type { FoundPattern, Packet, Pattern, PatternSearchType } from "./types";
|
||||
|
||||
export interface TextSegment {
|
||||
text: string;
|
||||
pattern?: Pattern;
|
||||
}
|
||||
|
||||
export function decodePacket(content: string): Uint8Array {
|
||||
const binary = atob(content);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let index = 0; index < binary.length; index += 1) {
|
||||
bytes[index] = binary.charCodeAt(index);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export function packetText(bytes: Uint8Array): string {
|
||||
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
|
||||
}
|
||||
|
||||
function rangeForMatch(
|
||||
bytes: Uint8Array,
|
||||
match: FoundPattern,
|
||||
searchType: PatternSearchType,
|
||||
): [number, number] {
|
||||
if (searchType !== "SUBBYTES") {
|
||||
return [match.startPosition, match.endPosition + 1];
|
||||
}
|
||||
|
||||
const start = Math.max(0, Math.min(bytes.length, match.startPosition));
|
||||
const end = Math.max(start, Math.min(bytes.length, match.endPosition + 1));
|
||||
return [packetText(bytes.subarray(0, start)).length, packetText(bytes.subarray(0, end)).length];
|
||||
}
|
||||
|
||||
export function packetSegments(packet: Packet, patterns: Pattern[]): TextSegment[] {
|
||||
const bytes = decodePacket(packet.content);
|
||||
const text = packetText(bytes);
|
||||
const byId = new Map(patterns.map((pattern) => [pattern.id, pattern]));
|
||||
const ranges = packet.matches
|
||||
.flatMap((match) => {
|
||||
const pattern = byId.get(match.patternId);
|
||||
if (!pattern || pattern.deleted || pattern.actionType !== "FIND") {
|
||||
return [];
|
||||
}
|
||||
const [start, end] = rangeForMatch(bytes, match, pattern.searchType);
|
||||
const safeStart = Math.max(0, Math.min(text.length, start));
|
||||
const safeEnd = Math.max(safeStart, Math.min(text.length, end));
|
||||
return safeEnd > safeStart ? [{ start: safeStart, end: safeEnd, pattern }] : [];
|
||||
})
|
||||
.sort((left, right) => left.start - right.start || left.end - right.end);
|
||||
|
||||
const segments: TextSegment[] = [];
|
||||
let cursor = 0;
|
||||
for (const range of ranges) {
|
||||
if (range.start < cursor) {
|
||||
continue;
|
||||
}
|
||||
if (range.start > cursor) {
|
||||
segments.push({ text: text.slice(cursor, range.start) });
|
||||
}
|
||||
segments.push({ text: text.slice(range.start, range.end), pattern: range.pattern });
|
||||
cursor = range.end;
|
||||
}
|
||||
if (cursor < text.length || segments.length === 0) {
|
||||
segments.push({ text: text.slice(cursor) });
|
||||
}
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function hexDump(bytes: Uint8Array, blockSize: number, lineNumberBase: number): string {
|
||||
const width = Number.isFinite(blockSize) ? Math.max(1, Math.min(128, Math.trunc(blockSize))) : 16;
|
||||
const base = lineNumberBase === 16 ? 16 : 10;
|
||||
const rows: string[] = [];
|
||||
|
||||
for (let offset = 0; offset < bytes.length; offset += width) {
|
||||
const block = bytes.subarray(offset, Math.min(offset + width, bytes.length));
|
||||
const address = offset.toString(base).padStart(10, "0");
|
||||
const hex = Array.from(block, (byte) => byte.toString(16).padStart(2, "0").toUpperCase());
|
||||
const paddedHex = [...hex, ...Array.from({ length: width - block.length }, () => " ")]
|
||||
.join(" ");
|
||||
const chars = Array.from(block, (byte) =>
|
||||
byte >= 0x20 && byte <= 0x7e ? String.fromCharCode(byte) : ".",
|
||||
).join("");
|
||||
rows.push(`${address}: ${paddedHex} |${chars.padEnd(width, " ")}|`);
|
||||
}
|
||||
|
||||
return rows.join("\n");
|
||||
}
|
||||
|
||||
export function pythonBytes(bytes: Uint8Array): string {
|
||||
return `b'${Array.from(bytes, (byte) => `\\x${byte.toString(16).padStart(2, "0")}`).join("")}'`;
|
||||
}
|
||||
|
||||
export function safePatternColor(color: string): string {
|
||||
if (/^#[\da-f]{3}(?:[\da-f]{3}|[\da-f]{5})?$/i.test(color)) {
|
||||
return color;
|
||||
}
|
||||
if (/^(?:red|green|blue|orange|purple|teal|yellow|white|black|gray|grey)$/i.test(color)) {
|
||||
return color;
|
||||
}
|
||||
return "#ff5959";
|
||||
}
|
||||
@@ -0,0 +1,992 @@
|
||||
:root {
|
||||
color-scheme: light;
|
||||
--topbar: #30343a;
|
||||
--topbar-text: #f4f5f6;
|
||||
--panel: #f7f8f9;
|
||||
--panel-border: #d4d8dd;
|
||||
--text: #22262b;
|
||||
--muted: #68717b;
|
||||
--accent: #087cf0;
|
||||
--request: #fff6f4;
|
||||
--response: #f0f9fc;
|
||||
--highlight: #ffe083;
|
||||
--danger: #d94050;
|
||||
--shadow: 0 5px 18px rgb(0 0 0 / 20%);
|
||||
font-family: "Open Sans", "Segoe UI", Arial, sans-serif;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
color-scheme: dark;
|
||||
--topbar: #202328;
|
||||
--topbar-text: #f4f5f6;
|
||||
--panel: #24282d;
|
||||
--panel-border: #444b53;
|
||||
--text: #e4e8ec;
|
||||
--muted: #aeb6bf;
|
||||
--accent: #70b3ff;
|
||||
--request: #34383e;
|
||||
--response: #2b5378;
|
||||
--highlight: #79651c;
|
||||
--danger: #ff737f;
|
||||
--shadow: 0 5px 18px rgb(0 0 0 / 45%);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
min-width: 360px;
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
button,
|
||||
input,
|
||||
select {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
button {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
button:focus-visible,
|
||||
input:focus-visible,
|
||||
select:focus-visible,
|
||||
summary:focus-visible {
|
||||
outline: 3px solid #55a8ff;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.app-shell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
min-height: 420px;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
z-index: 4;
|
||||
display: flex;
|
||||
min-height: 54px;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 0 12px;
|
||||
overflow-x: auto;
|
||||
color: var(--topbar-text);
|
||||
background: var(--topbar);
|
||||
box-shadow: 0 2px 7px rgb(0 0 0 / 22%);
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: none;
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
letter-spacing: 0.01em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.brand img {
|
||||
width: 56px;
|
||||
height: 32px;
|
||||
object-fit: cover;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.brand small {
|
||||
font-size: 12px;
|
||||
color: #c5cbd3;
|
||||
}
|
||||
|
||||
.traffic-stats {
|
||||
display: flex;
|
||||
flex: none;
|
||||
gap: 4px;
|
||||
color: #9eb5c8;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.traffic-stats abbr {
|
||||
text-decoration: underline dotted;
|
||||
text-underline-offset: 3px;
|
||||
}
|
||||
|
||||
.stats-separator {
|
||||
color: #77818b;
|
||||
}
|
||||
|
||||
.service-tabs {
|
||||
display: flex;
|
||||
min-width: max-content;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.service-tabs > button,
|
||||
.service-tab > button {
|
||||
min-height: 34px;
|
||||
padding: 6px 8px;
|
||||
border: 0;
|
||||
border-radius: 3px;
|
||||
color: #dce2e8;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.service-tabs > button:hover,
|
||||
.service-tab > button:hover,
|
||||
.service-tabs > button.active,
|
||||
.service-tab.active > button {
|
||||
color: #fff;
|
||||
background: #41474f;
|
||||
}
|
||||
|
||||
.service-tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.service-tab small {
|
||||
color: #a8b0b8;
|
||||
}
|
||||
|
||||
.service-tab > .service-edit {
|
||||
min-width: 26px;
|
||||
padding: 4px;
|
||||
color: #dce2e8;
|
||||
}
|
||||
|
||||
.service-tabs .add-service {
|
||||
min-width: 32px;
|
||||
color: #c5f1d1;
|
||||
font-size: 21px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.pattern-menu {
|
||||
position: relative;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.pattern-menu summary {
|
||||
padding: 8px 5px;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pattern-menu summary::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.pattern-menu summary::after {
|
||||
margin-left: 6px;
|
||||
content: "▾";
|
||||
}
|
||||
|
||||
.pattern-menu[open] summary,
|
||||
.pattern-menu summary:hover {
|
||||
color: #fff;
|
||||
background: #41474f;
|
||||
}
|
||||
|
||||
.pattern-popover {
|
||||
position: fixed;
|
||||
top: 48px;
|
||||
left: 192px;
|
||||
z-index: 7;
|
||||
width: min(740px, calc(100vw - 24px));
|
||||
max-height: min(70vh, 720px);
|
||||
padding: 8px;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 5px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.pattern-add,
|
||||
.pattern-all {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 9px 12px;
|
||||
border: 0;
|
||||
border-radius: 3px;
|
||||
color: var(--text);
|
||||
text-align: left;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pattern-add {
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.pattern-all {
|
||||
margin: 4px 0;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.pattern-row {
|
||||
display: flex;
|
||||
min-height: 44px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
padding: 6px 5px;
|
||||
border-top: 1px solid var(--panel-border);
|
||||
}
|
||||
|
||||
.pattern-select {
|
||||
flex: 1;
|
||||
min-width: 180px;
|
||||
padding: 5px;
|
||||
border: 0;
|
||||
color: var(--text);
|
||||
text-align: left;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pattern-select:disabled {
|
||||
cursor: default;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.pattern-select span {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.pattern-ignore .pattern-select {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.disabled-pattern {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.pattern-actions {
|
||||
display: flex;
|
||||
flex: none;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.pattern-actions button {
|
||||
padding: 5px 7px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 3px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pattern-actions button:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.selected-pattern {
|
||||
flex: none;
|
||||
max-width: 210px;
|
||||
overflow: hidden;
|
||||
color: #d5eaff;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.settings-button {
|
||||
flex: none;
|
||||
min-width: 34px;
|
||||
margin-left: auto;
|
||||
padding: 5px;
|
||||
border: 0;
|
||||
color: #e3e8ed;
|
||||
font-size: 19px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.workspace {
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
display: flex;
|
||||
width: 25%;
|
||||
min-width: 235px;
|
||||
max-width: 360px;
|
||||
flex: none;
|
||||
flex-direction: column;
|
||||
border-right: 1px solid var(--panel-border);
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.sidebar-toolbar {
|
||||
display: flex;
|
||||
min-height: 48px;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 7px 9px;
|
||||
background: linear-gradient(#fff, #eef0f2);
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] .sidebar-toolbar {
|
||||
background: linear-gradient(#2d3238, #25292e);
|
||||
}
|
||||
|
||||
.tool-button {
|
||||
min-width: 34px;
|
||||
height: 34px;
|
||||
padding: 2px 6px;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 4px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.pause-button {
|
||||
color: #259b4b;
|
||||
}
|
||||
|
||||
.pause-button.selected {
|
||||
color: #fff;
|
||||
background: #d94250;
|
||||
}
|
||||
|
||||
.favorite-button {
|
||||
color: #dc3545;
|
||||
font-size: 21px;
|
||||
}
|
||||
|
||||
.favorite-button.selected {
|
||||
color: #fff;
|
||||
background: #dc3545;
|
||||
}
|
||||
|
||||
.hex-button {
|
||||
color: #087cf0;
|
||||
}
|
||||
|
||||
.hex-button.selected {
|
||||
color: #fff;
|
||||
background: #087cf0;
|
||||
}
|
||||
|
||||
.file-button {
|
||||
color: #d28b00;
|
||||
}
|
||||
|
||||
.to-top-button {
|
||||
min-width: 36px;
|
||||
margin-left: auto;
|
||||
color: #07859a;
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.stream-search {
|
||||
position: relative;
|
||||
display: flex;
|
||||
padding: 4px 9px 7px;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
}
|
||||
|
||||
.stream-search input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
padding: 7px 28px 7px 9px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 4px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.stream-search button {
|
||||
position: absolute;
|
||||
top: 7px;
|
||||
right: 14px;
|
||||
border: 0;
|
||||
color: var(--muted);
|
||||
font-size: 19px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.stream-list {
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.stream-list ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.stream-item {
|
||||
position: relative;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
transition: background-color 120ms ease;
|
||||
}
|
||||
|
||||
.stream-item:hover {
|
||||
background: color-mix(in srgb, var(--accent) 8%, var(--panel));
|
||||
}
|
||||
|
||||
.stream-item.stream-selected {
|
||||
background: color-mix(in srgb, var(--accent) 15%, var(--panel));
|
||||
box-shadow: inset 3px 0 var(--accent);
|
||||
}
|
||||
|
||||
.stream-item.stream-favorite {
|
||||
background-color: color-mix(in srgb, #dc3545 9%, var(--panel));
|
||||
}
|
||||
|
||||
.stream-select {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 2px;
|
||||
padding: 10px 36px 10px 17px;
|
||||
border: 0;
|
||||
color: var(--text);
|
||||
line-height: 1.35;
|
||||
text-align: left;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.stream-select strong {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.stream-select time,
|
||||
.stream-ttl {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.stream-patterns {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.stream-star {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
padding: 0 3px;
|
||||
border: 0;
|
||||
color: #d94050;
|
||||
font-size: 19px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.stream-star.is-favorite {
|
||||
color: #d94050;
|
||||
}
|
||||
|
||||
.list-message {
|
||||
padding: 9px 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
display: block;
|
||||
width: calc(100% - 18px);
|
||||
margin: 9px;
|
||||
padding: 8px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 4px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.load-more:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.packet-pane {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
padding: 14px 22px 24px;
|
||||
overflow: auto;
|
||||
background: var(--panel);
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.packet-legend {
|
||||
position: sticky;
|
||||
top: -14px;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
min-height: 38px;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 0;
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.legend-request {
|
||||
padding: 1px 3px;
|
||||
background: var(--request);
|
||||
box-shadow: 0 0 3px 3px var(--request);
|
||||
}
|
||||
|
||||
.legend-response {
|
||||
padding: 1px 3px;
|
||||
background: var(--response);
|
||||
box-shadow: 0 0 3px 3px var(--response);
|
||||
}
|
||||
|
||||
.socket-state {
|
||||
margin-left: auto;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
margin-left: 10px;
|
||||
padding: 5px 7px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 3px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.stream-heading {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 7px 14px;
|
||||
margin: 1px 0 10px;
|
||||
padding: 8px 10px;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.stream-heading strong {
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.empty-detail {
|
||||
margin: 32px 0;
|
||||
color: var(--muted);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.packet {
|
||||
margin: 0 0 14px;
|
||||
padding: 7px 0 9px;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
box-shadow: 0 5px 8px -9px #4b4e51;
|
||||
}
|
||||
|
||||
.packet-request {
|
||||
background: var(--request);
|
||||
}
|
||||
|
||||
.packet-response {
|
||||
background: var(--response);
|
||||
}
|
||||
|
||||
.packet-header {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px 12px;
|
||||
padding: 2px 6px 7px;
|
||||
border-bottom: 1px solid color-mix(in srgb, var(--panel-border) 75%, transparent);
|
||||
}
|
||||
|
||||
.packet-meta,
|
||||
.packet-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 4px 10px;
|
||||
}
|
||||
|
||||
.packet-meta time,
|
||||
.packet-meta > span {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.packet-direction {
|
||||
color: var(--text) !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.packet-flag {
|
||||
padding: 1px 4px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.text-button {
|
||||
padding: 2px 0;
|
||||
border: 0;
|
||||
color: var(--accent);
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.text-button:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.packet-content {
|
||||
margin: 0;
|
||||
padding: 11px 7px 8px;
|
||||
overflow-x: auto;
|
||||
color: var(--text);
|
||||
font-family: "Ubuntu Mono", "Cascadia Mono", "Liberation Mono", monospace;
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
tab-size: 4;
|
||||
}
|
||||
|
||||
.packet-content mark {
|
||||
padding: 0 1px;
|
||||
color: #151515;
|
||||
box-shadow: 0 0 1px 1px currentColor;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.packet-more,
|
||||
.packet-end {
|
||||
max-width: 420px;
|
||||
margin: 12px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.notice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin: 0 0 8px;
|
||||
padding: 7px 10px;
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--panel-border));
|
||||
border-radius: 4px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
box-shadow: 0 2px 6px rgb(0 0 0 / 10%);
|
||||
}
|
||||
|
||||
.notice button {
|
||||
border: 0;
|
||||
color: var(--muted);
|
||||
font-size: 19px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.statusbar {
|
||||
min-height: 22px;
|
||||
padding: 3px 9px;
|
||||
border-top: 1px solid var(--panel-border);
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.dialog-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 10;
|
||||
display: grid;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
padding: 18px;
|
||||
overflow: auto;
|
||||
background: rgb(0 0 0 / 55%);
|
||||
}
|
||||
|
||||
.dialog {
|
||||
width: min(780px, 100%);
|
||||
max-height: min(92vh, 980px);
|
||||
overflow: auto;
|
||||
border: 1px solid #727982;
|
||||
border-radius: 7px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 13px 20px;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.dialog-header h2 {
|
||||
margin: 0;
|
||||
font-size: clamp(20px, 3vw, 28px);
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.dialog-close {
|
||||
padding: 0 5px;
|
||||
border: 0;
|
||||
color: var(--muted);
|
||||
font-size: 27px;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
padding: 16px 20px 20px;
|
||||
}
|
||||
|
||||
.form-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-field > span {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-field input:not([type="checkbox"]):not([type="color"]),
|
||||
.form-field select {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid #adb5bd;
|
||||
border-radius: 4px;
|
||||
color: var(--text);
|
||||
background: var(--panel);
|
||||
}
|
||||
|
||||
.form-field input[type="color"] {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
padding: 4px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 4px;
|
||||
background: var(--panel);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.form-field small {
|
||||
color: var(--muted);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.service-options {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin: 5px 0 20px;
|
||||
padding: 12px 13px;
|
||||
border: 1px solid var(--panel-border);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.service-options legend {
|
||||
padding: 0 6px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.service-options label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.service-options input {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
.dialog-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-top: 20px;
|
||||
padding-top: 14px;
|
||||
border-top: 1px solid var(--panel-border);
|
||||
}
|
||||
|
||||
.dialog-actions button {
|
||||
min-height: 38px;
|
||||
padding: 8px 14px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button-primary {
|
||||
color: #fff;
|
||||
background: #087cf0;
|
||||
}
|
||||
|
||||
.button-secondary {
|
||||
color: #fff;
|
||||
background: #68717b;
|
||||
}
|
||||
|
||||
.button-danger {
|
||||
color: #fff;
|
||||
background: #d94050;
|
||||
}
|
||||
|
||||
.dialog-delete {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.validation-message {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.topbar {
|
||||
gap: 8px;
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 32%;
|
||||
min-width: 210px;
|
||||
}
|
||||
|
||||
.packet-pane {
|
||||
padding-right: 14px;
|
||||
padding-left: 14px;
|
||||
}
|
||||
|
||||
.selected-pattern {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 650px) {
|
||||
body {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.app-shell {
|
||||
height: auto;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.topbar {
|
||||
flex-wrap: wrap;
|
||||
min-height: 54px;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.service-tabs {
|
||||
order: 5;
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.workspace {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 100%;
|
||||
max-width: none;
|
||||
min-width: 0;
|
||||
max-height: 45vh;
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid var(--panel-border);
|
||||
}
|
||||
|
||||
.stream-list {
|
||||
max-height: calc(45vh - 94px);
|
||||
}
|
||||
|
||||
.packet-pane {
|
||||
min-height: 48vh;
|
||||
padding: 9px 10px 20px;
|
||||
}
|
||||
|
||||
.pattern-popover {
|
||||
top: 48px;
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
.pattern-row {
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pattern-actions {
|
||||
flex-wrap: wrap;
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.statusbar {
|
||||
position: sticky;
|
||||
bottom: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import { afterEach } from "vitest";
|
||||
|
||||
afterEach(cleanup);
|
||||
@@ -0,0 +1,80 @@
|
||||
export type PatternSearchType = "REGEX" | "SUBSTRING" | "SUBBYTES";
|
||||
export type PatternDirectionType = "INPUT" | "OUTPUT" | "BOTH";
|
||||
export type PatternActionType = "FIND" | "IGNORE";
|
||||
|
||||
export interface Service {
|
||||
port: number;
|
||||
name: string;
|
||||
decryptTls: boolean;
|
||||
http: boolean;
|
||||
urldecodeHttpRequests: boolean;
|
||||
mergeAdjacentPackets: boolean;
|
||||
parseWebSockets: boolean;
|
||||
}
|
||||
|
||||
export interface Pattern {
|
||||
id: number;
|
||||
enabled: boolean;
|
||||
deleted: boolean;
|
||||
name: string;
|
||||
value: string;
|
||||
color: string;
|
||||
searchType: PatternSearchType;
|
||||
directionType: PatternDirectionType;
|
||||
actionType: PatternActionType;
|
||||
serviceId: number | null;
|
||||
}
|
||||
|
||||
export interface PatternInput extends Omit<Pattern, "id" | "enabled" | "deleted"> {
|
||||
id?: number;
|
||||
}
|
||||
|
||||
export interface Stream {
|
||||
id: number;
|
||||
service: number;
|
||||
protocol: string;
|
||||
startTimestamp: number;
|
||||
endTimestamp: number;
|
||||
foundPatternsIds: number[];
|
||||
favorite: boolean;
|
||||
ttl: number;
|
||||
userAgentHash: string | null;
|
||||
sizeBytes: number;
|
||||
packetsCount: number;
|
||||
}
|
||||
|
||||
export interface FoundPattern {
|
||||
patternId: number;
|
||||
startPosition: number;
|
||||
endPosition: number;
|
||||
}
|
||||
|
||||
export interface Packet {
|
||||
id: number;
|
||||
matches: FoundPattern[];
|
||||
timestamp: number;
|
||||
incoming: boolean;
|
||||
ungzipped: boolean;
|
||||
webSocketParsed: boolean;
|
||||
tlsDecrypted: boolean;
|
||||
hasHttpBody: boolean;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface RouteState {
|
||||
servicePort?: number;
|
||||
streamId?: number;
|
||||
patternId?: number;
|
||||
}
|
||||
|
||||
export interface CountersUpdate {
|
||||
totalPackets: number;
|
||||
totalStreams: number;
|
||||
servicesPackets: Record<string, number>;
|
||||
servicesStreams: Record<string, number>;
|
||||
}
|
||||
|
||||
export interface SubscriptionMessage {
|
||||
type: string;
|
||||
value: unknown;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noImplicitOverride": true
|
||||
},
|
||||
"include": ["src", "vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
base: "/",
|
||||
server: {
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: process.env.PACKMATE_API_ORIGIN ?? "http://127.0.0.1:65000",
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
test: {
|
||||
environment: "happy-dom",
|
||||
setupFiles: ["./src/test/setup.ts"],
|
||||
restoreMocks: true,
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user