Etap 3: broker EMQX z TLS i ACL, symulator czujnika ciśnienia, instrukcja
- docker-compose: EMQX 5.8.6 (1883/8883/18083), symulator (FastAPI, MQTT 5), sniffer tcpdump - emqx.conf, acl.conf: uwierzytelnianie, autoryzacja (default deny), TLS - hasła wyłącznie w pliku .env (poza repozytorium), konta tworzone przy starcie brokera - skrypty: generowanie certyfikatów, podgląd w Wiresharku, klient SCADA - INSTRUKCJA.md: wykonanie zadań i zbieranie dowodów do sprawozdania - screeny/: zrzuty ekranu do sprawozdania Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
76c79e18e8
commit
9bcca5d9e3
35 files changed
+2162
No files matched your search
@@ -0,0 +1,304 @@
|
||||
"use strict";
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
let D = {}; // wartości domyślne z serwera
|
||||
let mode = "plain"; // plain | tls
|
||||
let lastEventId = 0;
|
||||
let lastState = null;
|
||||
let formDirty = false; // nie nadpisuj pól czujnika, gdy użytkownik je edytuje
|
||||
|
||||
// ------------------------------------------------------------------ helpers
|
||||
async function api(path, body) {
|
||||
const opts = body === undefined ? { method: "POST" } :
|
||||
{ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) };
|
||||
const res = await fetch(path, opts);
|
||||
let data = {};
|
||||
try { data = await res.json(); } catch (_) { /* brak treści */ }
|
||||
if (!res.ok) {
|
||||
const msg = data.error || (data.detail && JSON.stringify(data.detail)) || res.statusText;
|
||||
toast(msg, true);
|
||||
throw new Error(msg);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
let toastTimer;
|
||||
function toast(msg, isErr = false) {
|
||||
const t = $("toast");
|
||||
t.textContent = msg;
|
||||
t.className = "toast" + (isErr ? " err" : "");
|
||||
t.hidden = false;
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => { t.hidden = true; }, 4500);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ połączenie
|
||||
function setMode(m, setPort = true) {
|
||||
mode = m;
|
||||
document.querySelectorAll(".seg").forEach((b) =>
|
||||
b.setAttribute("aria-checked", String(b.dataset.mode === m)));
|
||||
$("tlsBox").hidden = m !== "tls";
|
||||
if (setPort) $("port").value = m === "tls" ? D.tls_port : D.plain_port;
|
||||
$("modeHint").textContent = m === "tls"
|
||||
? "Ruch szyfrowany: w Wiresharku zobaczysz handshake TLS i „Application Data” zamiast treści."
|
||||
: "Ruch jawny: temat, treść oraz login i hasło widać w Wiresharku jako zwykły tekst.";
|
||||
}
|
||||
|
||||
const ACCOUNTS = () => ({
|
||||
czujnik: ["czujnik_cisnienia", D.password],
|
||||
scada: ["scada_panel", D.scada_password],
|
||||
bad: ["czujnik_cisnienia", "zle-haslo"],
|
||||
anon: ["", ""],
|
||||
});
|
||||
|
||||
function applyAccount() {
|
||||
const acc = ACCOUNTS()[$("account").value];
|
||||
if (!acc) return;
|
||||
[$("username").value, $("password").value] = acc;
|
||||
}
|
||||
|
||||
async function connect() {
|
||||
const btn = $("btnConnect");
|
||||
btn.disabled = true;
|
||||
btn.textContent = "Łączenie…";
|
||||
try {
|
||||
await api("/api/connect", {
|
||||
host: $("host").value.trim(),
|
||||
port: Number($("port").value),
|
||||
tls: mode === "tls",
|
||||
tls_version: $("tlsVersion").value,
|
||||
verify: $("verify").checked,
|
||||
ca_file: $("caFile").value.trim(),
|
||||
client_id: $("clientId").value.trim(),
|
||||
username: $("username").value.trim(),
|
||||
password: $("password").value,
|
||||
sensor_id: D.sensor_id,
|
||||
// status/komendy tylko dla konta czujnika (inne konta nie mają do nich praw)
|
||||
status_topic: $("username").value.trim() === "czujnik_cisnienia" ? D.status_topic : "",
|
||||
command_topic: $("username").value.trim() === "czujnik_cisnienia" ? D.command_topic : "",
|
||||
});
|
||||
toast(mode === "tls" ? "Połączono przez TLS" : "Połączono (bez szyfrowania)");
|
||||
} catch (_) { /* toast już pokazany */ }
|
||||
finally {
|
||||
btn.disabled = false;
|
||||
btn.textContent = "Połącz";
|
||||
poll();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ czujnik
|
||||
async function pushSensorConfig() {
|
||||
await api("/api/sensor/config", {
|
||||
topic: $("topic").value.trim(),
|
||||
interval: Number($("interval").value),
|
||||
qos: Number($("qos").value),
|
||||
setpoint: Number($("setpoint").value),
|
||||
});
|
||||
formDirty = false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ render
|
||||
function renderConn(m) {
|
||||
const pill = $("connPill");
|
||||
let cls = "pill-off", txt = "Rozłączono";
|
||||
if (m.state === "connecting") { cls = "pill-wait"; txt = "Łączenie…"; }
|
||||
if (m.state === "connected") {
|
||||
cls = m.tls ? "pill-tls" : "pill-plain";
|
||||
txt = `${m.tls ? "TLS" : "Bez szyfrowania"} · ${m.host}:${m.port} · ${m.username || "anonim"}`;
|
||||
}
|
||||
pill.className = "pill " + cls;
|
||||
$("connText").textContent = txt;
|
||||
$("btnDisconnect").disabled = m.state === "disconnected";
|
||||
|
||||
const info = $("tlsInfo");
|
||||
if (m.state === "connected" && m.tls_info) {
|
||||
const t = m.tls_info;
|
||||
info.innerHTML = "";
|
||||
for (const [k, v] of [["Protokół", t.version], ["Szyfr", t.cipher], ["Certyfikat", t.subject],
|
||||
["Wystawca", t.issuer], ["Ważny do", t.not_after || "—"]]) {
|
||||
const dt = document.createElement("dt"); dt.textContent = k;
|
||||
const dd = document.createElement("dd"); dd.textContent = v;
|
||||
info.append(dt, dd);
|
||||
}
|
||||
info.hidden = false;
|
||||
} else {
|
||||
info.hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
function renderSensor(s, m) {
|
||||
$("sensorIdLabel").textContent = s.sensor_id;
|
||||
$("spLabel").textContent = s.setpoint.toFixed(1);
|
||||
$("loLabel").textContent = s.alarm_low;
|
||||
$("hiLabel").textContent = s.alarm_high;
|
||||
if (s.last) {
|
||||
$("pValue").textContent = s.last.p.toFixed(3);
|
||||
const b = $("pStatus");
|
||||
b.textContent = s.last.s;
|
||||
b.className = "badge " + (s.last.s === "OK" ? "ok" : "alarm");
|
||||
}
|
||||
if (!formDirty && document.activeElement?.closest("#sensorCard") == null) {
|
||||
$("topic").value = s.topic;
|
||||
$("interval").value = s.interval;
|
||||
$("qos").value = String(s.qos);
|
||||
$("setpoint").value = s.setpoint;
|
||||
}
|
||||
$("btnStart").disabled = s.running || m.state !== "connected";
|
||||
$("btnStop").disabled = !s.running;
|
||||
$("btnStart").textContent = s.running ? "Wysyłanie…" : "Start";
|
||||
const st = m.stats;
|
||||
$("stats").textContent =
|
||||
`Wysłane: ${st.sent} · potwierdzone (PUBACK): ${st.acked} · odrzucone: ${st.denied} · odebrane: ${st.received}` +
|
||||
(m.subscriptions.length ? ` · subskrypcje: ${m.subscriptions.join(", ")}` : "");
|
||||
}
|
||||
|
||||
const LV = { ok: "OK", info: "info", warn: "uwaga", error: "błąd", tx: "TX", rx: "RX" };
|
||||
|
||||
function renderEvents(events) {
|
||||
const ol = $("log");
|
||||
if (events.length === 0 && ol.children.length === 0) {
|
||||
ol.innerHTML = '<li class="empty">Brak zdarzeń — połącz się z brokerem.</li>';
|
||||
return;
|
||||
}
|
||||
const empty = ol.querySelector(".empty");
|
||||
if (events.length && empty) empty.remove();
|
||||
const atTop = ol.scrollTop < 10;
|
||||
for (const e of events) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "e-" + e.level;
|
||||
if (e.level === "tx" && e.message.includes("PUBLISH") && e.detail?.includes('"seq"')) li.dataset.telemetry = "1";
|
||||
const t = document.createElement("span"); t.className = "t"; t.textContent = e.time;
|
||||
const lv = document.createElement("span"); lv.className = "lv lv-" + e.level; lv.textContent = LV[e.level] || e.level;
|
||||
const msg = document.createElement("span"); msg.className = "msg"; msg.textContent = e.message;
|
||||
if (e.detail) {
|
||||
const d = document.createElement("span"); d.className = "det"; d.textContent = e.detail;
|
||||
msg.append(d);
|
||||
}
|
||||
li.append(t, lv, msg);
|
||||
li.hidden = $("hideTelemetry").checked && li.dataset.telemetry === "1";
|
||||
ol.prepend(li);
|
||||
lastEventId = Math.max(lastEventId, e.id);
|
||||
}
|
||||
while (ol.children.length > 400) ol.lastElementChild.remove();
|
||||
if (atTop) ol.scrollTop = 0;
|
||||
}
|
||||
|
||||
function drawChart(hist, s) {
|
||||
const c = $("chart");
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
const w = c.clientWidth, h = c.clientHeight;
|
||||
if (c.width !== w * dpr) { c.width = w * dpr; c.height = h * dpr; }
|
||||
const g = c.getContext("2d");
|
||||
g.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
g.clearRect(0, 0, w, h);
|
||||
const css = getComputedStyle(document.documentElement);
|
||||
const col = (n) => css.getPropertyValue(n).trim();
|
||||
const vals = hist.map((x) => x.p);
|
||||
const lo = Math.min(s.alarm_low - 0.5, ...vals), hi = Math.max(s.alarm_high + 0.5, ...vals);
|
||||
const y = (v) => h - 18 - ((v - lo) / (hi - lo)) * (h - 28);
|
||||
const padL = 34;
|
||||
|
||||
g.font = "11px system-ui"; g.fillStyle = col("--muted"); g.textBaseline = "middle";
|
||||
for (const [v, c2] of [[s.alarm_high, "--err"], [s.setpoint, "--muted"], [s.alarm_low, "--err"]]) {
|
||||
g.strokeStyle = col(c2); g.globalAlpha = 0.5; g.setLineDash([4, 4]);
|
||||
g.beginPath(); g.moveTo(padL, y(v)); g.lineTo(w, y(v)); g.stroke();
|
||||
g.globalAlpha = 1; g.setLineDash([]);
|
||||
g.fillText(v.toFixed(1), 2, y(v));
|
||||
}
|
||||
if (vals.length < 2) {
|
||||
g.fillText("Brak pomiarów", padL + 8, h / 2);
|
||||
return;
|
||||
}
|
||||
const n = 60, pts = vals.slice(-n);
|
||||
const x = (i) => padL + (i / (n - 1)) * (w - padL - 4);
|
||||
g.strokeStyle = col("--accent"); g.lineWidth = 2; g.lineJoin = "round";
|
||||
g.beginPath();
|
||||
pts.forEach((v, i) => (i ? g.lineTo(x(i), y(v)) : g.moveTo(x(i), y(v))));
|
||||
g.stroke();
|
||||
const last = pts[pts.length - 1];
|
||||
g.fillStyle = col("--accent");
|
||||
g.beginPath(); g.arc(x(pts.length - 1), y(last), 3.5, 0, Math.PI * 2); g.fill();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ polling
|
||||
async function poll() {
|
||||
try {
|
||||
const res = await fetch(`/api/state?after=${lastEventId}`);
|
||||
const st = await res.json();
|
||||
lastState = st;
|
||||
renderConn(st.mqtt);
|
||||
renderSensor(st.sensor, st.mqtt);
|
||||
renderEvents(st.events);
|
||||
drawChart(st.history, st.sensor);
|
||||
} catch (_) {
|
||||
$("connText").textContent = "Brak kontaktu z symulatorem";
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ init
|
||||
async function init() {
|
||||
D = await (await fetch("/api/defaults")).json();
|
||||
$("host").value = D.host;
|
||||
$("tlsVersion").value = D.tls_version;
|
||||
$("verify").checked = D.verify;
|
||||
$("caFile").value = D.ca_file;
|
||||
$("clientId").value = D.client_id;
|
||||
applyAccount();
|
||||
setMode(D.tls ? "tls" : "plain");
|
||||
$("pubTopic").value = D.command_topic;
|
||||
$("pubPayload").value = '{"cmd":"otworz_zawor","value":100}';
|
||||
|
||||
document.querySelectorAll(".seg").forEach((b) => b.addEventListener("click", () => setMode(b.dataset.mode)));
|
||||
$("account").addEventListener("change", applyAccount);
|
||||
["username", "password"].forEach((id) => $(id).addEventListener("input", () => { $("account").value = "custom"; }));
|
||||
$("btnConnect").addEventListener("click", connect);
|
||||
$("btnDisconnect").addEventListener("click", () => api("/api/disconnect").then(poll));
|
||||
|
||||
["topic", "interval", "qos", "setpoint"].forEach((id) => {
|
||||
$(id).addEventListener("input", () => { formDirty = true; });
|
||||
$(id).addEventListener("change", () => pushSensorConfig().catch(() => {}));
|
||||
});
|
||||
$("btnStart").addEventListener("click", async () => {
|
||||
if (formDirty) await pushSensorConfig();
|
||||
await api("/api/sensor/start").catch(() => {});
|
||||
poll();
|
||||
});
|
||||
$("btnStop").addEventListener("click", () => api("/api/sensor/stop").then(poll));
|
||||
$("btnOnce").addEventListener("click", async () => {
|
||||
if (formDirty) await pushSensorConfig();
|
||||
await api("/api/sensor/once").catch(() => {});
|
||||
poll();
|
||||
});
|
||||
$("btnSpike").addEventListener("click", () => api("/api/sensor/spike").then(poll));
|
||||
|
||||
document.querySelectorAll("#pubPresets .chip").forEach((c) => c.addEventListener("click", () => {
|
||||
$("pubTopic").value = c.dataset.topic;
|
||||
$("pubPayload").value = c.dataset.payload;
|
||||
}));
|
||||
$("btnPublish").addEventListener("click", () => api("/api/publish", {
|
||||
topic: $("pubTopic").value, payload: $("pubPayload").value,
|
||||
qos: Number($("pubQos").value), retain: $("pubRetain").checked,
|
||||
}).then(poll).catch(() => {}));
|
||||
$("btnSubscribe").addEventListener("click", () =>
|
||||
api("/api/subscribe", { topic: $("subTopic").value, qos: 1 }).then(poll).catch(() => {}));
|
||||
|
||||
$("hideTelemetry").addEventListener("change", () => {
|
||||
document.querySelectorAll("#log li[data-telemetry]").forEach((li) => { li.hidden = $("hideTelemetry").checked; });
|
||||
});
|
||||
$("btnClear").addEventListener("click", () => api("/api/log/clear").then(() => { $("log").innerHTML = ""; }));
|
||||
window.addEventListener("resize", () => lastState && drawChart(lastState.history, lastState.sensor));
|
||||
|
||||
await poll();
|
||||
// po odświeżeniu strony pokaż ustawienia aktywnego połączenia
|
||||
const m = lastState?.mqtt;
|
||||
if (m && m.state !== "disconnected") {
|
||||
setMode(m.tls ? "tls" : "plain", false);
|
||||
$("host").value = m.host;
|
||||
$("port").value = m.port;
|
||||
$("clientId").value = m.client_id;
|
||||
if (m.username) $("username").value = m.username;
|
||||
}
|
||||
setInterval(poll, 1000);
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,158 @@
|
||||
<!doctype html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Symulator PT-101 · MQTT</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<div class="brand">
|
||||
<svg viewBox="0 0 24 24" class="gauge" aria-hidden="true"><path d="M12 4a9 9 0 0 0-9 9 9 9 0 0 0 2 5.6h14A9 9 0 0 0 21 13a9 9 0 0 0-9-9Z" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="m12 13 4-4" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="12" cy="13" r="1.6" fill="currentColor"/></svg>
|
||||
<div>
|
||||
<h1>Symulator czujnika ciśnienia</h1>
|
||||
<p class="sub">MQTT 5 · broker EMQX · <span id="sensorIdLabel">PT-101</span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="connPill" class="pill pill-off"><span class="dot"></span><span id="connText">Rozłączono</span></div>
|
||||
</header>
|
||||
|
||||
<main class="grid">
|
||||
<!-- ======================= POŁĄCZENIE ======================= -->
|
||||
<section class="card" id="connCard">
|
||||
<h2>1. Połączenie z brokerem</h2>
|
||||
|
||||
<div class="segmented" role="radiogroup" aria-label="Tryb transmisji">
|
||||
<button type="button" class="seg" data-mode="plain" role="radio">
|
||||
<svg viewBox="0 0 24 24"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 7.5-2"/></svg>
|
||||
<span><b>Bez szyfrowania</b><small>MQTT · port 1883</small></span>
|
||||
</button>
|
||||
<button type="button" class="seg" data-mode="tls" role="radio">
|
||||
<svg viewBox="0 0 24 24"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v4"/></svg>
|
||||
<span><b>Szyfrowane TLS</b><small>MQTTS · port 8883</small></span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="hint" id="modeHint"></p>
|
||||
|
||||
<div class="row">
|
||||
<label class="grow">Host brokera<input id="host" autocomplete="off"></label>
|
||||
<label class="w-port">Port<input id="port" type="number" min="1" max="65535"></label>
|
||||
</div>
|
||||
|
||||
<div id="tlsBox" class="subbox">
|
||||
<div class="row">
|
||||
<label class="grow">Wersja TLS
|
||||
<select id="tlsVersion">
|
||||
<option value="1.2">TLS 1.2 (pełny handshake widoczny w Wiresharku)</option>
|
||||
<option value="1.3">TLS 1.3</option>
|
||||
<option value="auto">Automatycznie (najwyższa)</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<label class="check"><input type="checkbox" id="verify"> Weryfikuj certyfikat brokera (zaufane CA + nazwa hosta)</label>
|
||||
<label>Plik certyfikatu CA (w kontenerze)<input id="caFile" autocomplete="off"></label>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="grow">Konto
|
||||
<select id="account">
|
||||
<option value="czujnik">czujnik_cisnienia (urządzenie)</option>
|
||||
<option value="scada">scada_panel (SCADA)</option>
|
||||
<option value="bad">czujnik_cisnienia + błędne hasło</option>
|
||||
<option value="anon">anonimowo (bez loginu)</option>
|
||||
<option value="custom">własne…</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="grow">Użytkownik<input id="username" autocomplete="off"></label>
|
||||
<label class="grow">Hasło<input id="password" type="password" autocomplete="off"></label>
|
||||
</div>
|
||||
<label>Client ID<input id="clientId" autocomplete="off"></label>
|
||||
|
||||
<div class="actions">
|
||||
<button id="btnConnect" class="btn primary">Połącz</button>
|
||||
<button id="btnDisconnect" class="btn">Rozłącz</button>
|
||||
</div>
|
||||
|
||||
<dl id="tlsInfo" class="kv" hidden></dl>
|
||||
</section>
|
||||
|
||||
<!-- ======================= POMIAR ======================= -->
|
||||
<section class="card" id="sensorCard">
|
||||
<h2>2. Czujnik — pomiary</h2>
|
||||
<div class="readout">
|
||||
<div>
|
||||
<div class="value"><span id="pValue">—</span><span class="unit">bar</span></div>
|
||||
<div class="meta">wartość zadana <b id="spLabel">6.0</b> bar · alarm < <span id="loLabel">4.5</span> / > <span id="hiLabel">7.5</span></div>
|
||||
</div>
|
||||
<span id="pStatus" class="badge">—</span>
|
||||
</div>
|
||||
<canvas id="chart" height="150" aria-label="Wykres ciśnienia"></canvas>
|
||||
|
||||
<div class="row">
|
||||
<label class="grow">Temat telemetrii<input id="topic" autocomplete="off"></label>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Interwał [s]<input id="interval" type="number" step="0.5" min="0.2"></label>
|
||||
<label>QoS
|
||||
<select id="qos"><option>0</option><option>1</option><option>2</option></select>
|
||||
</label>
|
||||
<label>Wartość zadana [bar]<input id="setpoint" type="number" step="0.1" min="0"></label>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button id="btnStart" class="btn primary">Start</button>
|
||||
<button id="btnStop" class="btn">Stop</button>
|
||||
<button id="btnOnce" class="btn">Wyślij 1 pomiar</button>
|
||||
<button id="btnSpike" class="btn ghost">Skok ciśnienia</button>
|
||||
</div>
|
||||
<p class="stats" id="stats"></p>
|
||||
</section>
|
||||
|
||||
<!-- ======================= TEST ACL ======================= -->
|
||||
<section class="card" id="aclCard">
|
||||
<h2>3. Test uprawnień (ACL)</h2>
|
||||
<p class="hint">Wyślij wiadomość na temat, do którego zalogowane konto nie ma prawa. Przy QoS 1 broker odpowie
|
||||
<code>PUBACK 0x87 Not authorized</code>, a w logach EMQX pojawi się wpis o odmowie.</p>
|
||||
<div class="chips" id="pubPresets">
|
||||
<button type="button" class="chip deny" data-topic="zaklad/hala1/cisnienie/komendy" data-payload='{"cmd":"otworz_zawor","value":100}'>czujnik → komendy ✕</button>
|
||||
<button type="button" class="chip deny" data-topic="zaklad/hala2/cisnienie/telemetria" data-payload='{"pressure":99.9}'>inna hala ✕</button>
|
||||
<button type="button" class="chip ok" data-topic="zaklad/hala1/cisnienie/telemetria" data-payload='{"sensor_id":"PT-101","pressure":6.0,"unit":"bar"}'>telemetria ✓</button>
|
||||
<button type="button" class="chip" data-topic="zaklad/hala1/cisnienie/komendy" data-payload='{"cmd":"set_interval","value":1}'>komenda SCADA</button>
|
||||
</div>
|
||||
<label>Temat<input id="pubTopic" autocomplete="off"></label>
|
||||
<label>Treść (payload)<textarea id="pubPayload" rows="2" spellcheck="false"></textarea></label>
|
||||
<div class="row end">
|
||||
<label>QoS
|
||||
<select id="pubQos"><option>0</option><option selected>1</option><option>2</option></select>
|
||||
</label>
|
||||
<label class="check inline"><input type="checkbox" id="pubRetain"> retain</label>
|
||||
<button id="btnPublish" class="btn primary">Publikuj</button>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
<div class="row end">
|
||||
<label class="grow">Subskrybuj temat<input id="subTopic" value="#" autocomplete="off"></label>
|
||||
<button id="btnSubscribe" class="btn">Subskrybuj</button>
|
||||
</div>
|
||||
<p class="hint">Np. <code>#</code> lub <code>$SYS/#</code> — oba zabronione dla każdego konta.</p>
|
||||
</section>
|
||||
|
||||
<!-- ======================= DZIENNIK ======================= -->
|
||||
<section class="card" id="logCard">
|
||||
<div class="card-head">
|
||||
<h2>4. Dziennik zdarzeń</h2>
|
||||
<div class="log-tools">
|
||||
<label class="check inline"><input type="checkbox" id="hideTelemetry"> ukryj pomiary</label>
|
||||
<button id="btnClear" class="btn small ghost">Wyczyść</button>
|
||||
</div>
|
||||
</div>
|
||||
<ol id="log" class="log" aria-live="polite"></ol>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<div id="toast" class="toast" hidden></div>
|
||||
<script src="/static/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,181 @@
|
||||
:root {
|
||||
--bg: #f4f5f7;
|
||||
--card: #ffffff;
|
||||
--ink: #1b1f24;
|
||||
--muted: #646d78;
|
||||
--line: #e1e4e8;
|
||||
--field: #fbfbfc;
|
||||
--accent: #0f6e8c;
|
||||
--accent-ink: #ffffff;
|
||||
--ok: #1d7a46;
|
||||
--ok-bg: #e5f4eb;
|
||||
--warn: #9a6400;
|
||||
--warn-bg: #fdf3dc;
|
||||
--err: #b42318;
|
||||
--err-bg: #fde8e6;
|
||||
--tx: #3d5a9e;
|
||||
--rx: #6b3fa0;
|
||||
--plain: #b45309;
|
||||
--tls: #1d7a46;
|
||||
--radius: 10px;
|
||||
color-scheme: light;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #111418;
|
||||
--card: #1a1e24;
|
||||
--ink: #e6e8eb;
|
||||
--muted: #98a1ab;
|
||||
--line: #2c323a;
|
||||
--field: #14181d;
|
||||
--accent: #3aa6c6;
|
||||
--accent-ink: #06161c;
|
||||
--ok: #4fc483;
|
||||
--ok-bg: #143322;
|
||||
--warn: #e6b450;
|
||||
--warn-bg: #33290f;
|
||||
--err: #f2786d;
|
||||
--err-bg: #3a1a17;
|
||||
--tx: #8aa6ea;
|
||||
--rx: #c19ae9;
|
||||
--plain: #f0a04b;
|
||||
--tls: #4fc483;
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
[hidden] { display: none !important; }
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
}
|
||||
code, .mono { font-family: ui-monospace, "JetBrains Mono", "Fira Code", Consolas, monospace; font-size: 12.5px; }
|
||||
|
||||
.topbar {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
|
||||
padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line);
|
||||
position: sticky; top: 0; z-index: 5;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 12px; }
|
||||
.gauge { width: 34px; height: 34px; color: var(--accent); }
|
||||
h1 { font-size: 17px; margin: 0; }
|
||||
.sub { margin: 0; color: var(--muted); font-size: 12.5px; }
|
||||
|
||||
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
|
||||
font-weight: 600; font-size: 13px; border: 1px solid var(--line); }
|
||||
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
|
||||
.pill-off { color: var(--muted); }
|
||||
.pill-wait { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
|
||||
.pill-plain { color: var(--plain); background: var(--warn-bg); border-color: transparent; }
|
||||
.pill-tls { color: var(--tls); background: var(--ok-bg); border-color: transparent; }
|
||||
|
||||
.grid {
|
||||
display: grid; gap: 18px; padding: 20px 24px 40px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
max-width: 1400px; margin: 0 auto;
|
||||
}
|
||||
@media (max-width: 960px) { .grid { grid-template-columns: 1fr; padding: 16px; } }
|
||||
|
||||
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
|
||||
padding: 18px 20px; min-width: 0; }
|
||||
.card h2 { font-size: 15px; margin: 0 0 14px; }
|
||||
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
|
||||
.card-head h2 { margin: 0; }
|
||||
|
||||
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
|
||||
input, select, textarea {
|
||||
font: inherit; color: var(--ink); background: var(--field);
|
||||
border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; width: 100%;
|
||||
}
|
||||
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; resize: vertical; }
|
||||
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
|
||||
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
|
||||
.check input { width: auto; }
|
||||
.check.inline { margin: 0 0 10px; }
|
||||
|
||||
.row { display: flex; gap: 12px; flex-wrap: wrap; }
|
||||
.row > label { flex: 1 1 120px; }
|
||||
.row .grow { flex: 3 1 200px; }
|
||||
.row .w-port { flex: 0 1 110px; }
|
||||
.row.end { align-items: flex-end; }
|
||||
.row.end .btn { margin-bottom: 10px; }
|
||||
|
||||
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
|
||||
.seg {
|
||||
display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
|
||||
padding: 10px 12px; border-radius: 9px; border: 1.5px solid var(--line);
|
||||
background: var(--field); color: var(--ink); font: inherit;
|
||||
}
|
||||
.seg svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; }
|
||||
.seg span { display: flex; flex-direction: column; }
|
||||
.seg small { color: var(--muted); }
|
||||
.seg[data-mode="plain"][aria-checked="true"] { border-color: var(--plain); color: var(--plain); background: var(--warn-bg); }
|
||||
.seg[data-mode="tls"][aria-checked="true"] { border-color: var(--tls); color: var(--tls); background: var(--ok-bg); }
|
||||
.seg[aria-checked="true"] small { color: inherit; opacity: .85; }
|
||||
|
||||
.subbox { border-left: 3px solid var(--tls); padding: 8px 0 2px 12px; margin: 4px 0 12px; }
|
||||
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }
|
||||
|
||||
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
|
||||
.btn {
|
||||
font: inherit; font-weight: 600; cursor: pointer; padding: 8px 14px; border-radius: 7px;
|
||||
border: 1px solid var(--line); background: var(--field); color: var(--ink);
|
||||
}
|
||||
.btn:hover { border-color: var(--accent); }
|
||||
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
|
||||
.btn.ghost { background: transparent; }
|
||||
.btn.small { padding: 4px 10px; font-size: 12.5px; }
|
||||
.btn:disabled { opacity: .45; cursor: not-allowed; }
|
||||
|
||||
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 14px 0 0;
|
||||
padding: 10px 12px; border-radius: 8px; background: var(--ok-bg); font-size: 12.5px; }
|
||||
.kv dt { color: var(--muted); }
|
||||
.kv dd { margin: 0; word-break: break-word; }
|
||||
|
||||
.readout { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
|
||||
.value { font-size: 44px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.05; }
|
||||
.value .unit { font-size: 18px; font-weight: 600; color: var(--muted); margin-left: 6px; }
|
||||
.meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
|
||||
.badge { padding: 4px 10px; border-radius: 6px; font-weight: 700; font-size: 12px; background: var(--line); color: var(--muted); }
|
||||
.badge.ok { background: var(--ok-bg); color: var(--ok); }
|
||||
.badge.alarm { background: var(--err-bg); color: var(--err); }
|
||||
#chart { width: 100%; height: 150px; display: block; margin: 12px 0 14px; }
|
||||
.stats { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
|
||||
|
||||
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
|
||||
.chip { font: inherit; font-size: 12.5px; cursor: pointer; padding: 4px 10px; border-radius: 999px;
|
||||
border: 1px solid var(--line); background: var(--field); color: var(--ink); }
|
||||
.chip.deny { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
|
||||
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
|
||||
.divider { border-top: 1px solid var(--line); margin: 6px 0 14px; }
|
||||
|
||||
.log-tools { display: flex; align-items: center; gap: 12px; }
|
||||
.log-tools .check.inline { margin: 0; }
|
||||
.log { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto;
|
||||
border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
|
||||
.log li { display: grid; grid-template-columns: 86px 44px 1fr; gap: 8px; padding: 6px 10px;
|
||||
border-bottom: 1px solid var(--line); font-size: 12.5px; }
|
||||
.log li:last-child { border-bottom: 0; }
|
||||
.log .t { color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
|
||||
.log .lv { font-weight: 700; font-size: 11px; text-transform: uppercase; padding-top: 1px; }
|
||||
.log .msg { min-width: 0; }
|
||||
.log .det { display: block; color: var(--muted); font-family: ui-monospace, Consolas, monospace;
|
||||
word-break: break-all; margin-top: 2px; }
|
||||
.lv-ok { color: var(--ok); } .lv-info { color: var(--muted); } .lv-warn { color: var(--warn); }
|
||||
.lv-error { color: var(--err); } .lv-tx { color: var(--tx); } .lv-rx { color: var(--rx); }
|
||||
.log li.e-error { background: var(--err-bg); }
|
||||
.log .empty { display: block; color: var(--muted); padding: 14px; }
|
||||
|
||||
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; border-radius: 9px;
|
||||
background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: 0 8px 24px rgb(0 0 0 / .2); z-index: 10; }
|
||||
.toast.err { background: var(--err); color: #fff; }
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.topbar { padding: 12px 16px; }
|
||||
.segmented { grid-template-columns: 1fr; }
|
||||
.log li { grid-template-columns: 70px 1fr; }
|
||||
.log .lv { display: none; }
|
||||
}
|
||||
Reference in new issue
Block a user