Compare commits
2 Commits
feat/repor
...
afb8bfe10e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afb8bfe10e | ||
| add5f1f4f3 |
61
src/main.js
61
src/main.js
@@ -140,50 +140,6 @@ const GATEWAY_CANDIDATES = [
|
|||||||
"http://10.0.0.1",
|
"http://10.0.0.1",
|
||||||
];
|
];
|
||||||
|
|
||||||
// --- Geolocation via API -----------------------------------------------------
|
|
||||||
|
|
||||||
async function fetchGeoInfo() {
|
|
||||||
try {
|
|
||||||
const res = await fetch("https://freeipapi.com/api/json/");
|
|
||||||
if (!res.ok) return null;
|
|
||||||
return await res.json();
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Telemetry Report --------------------------------------------------------
|
|
||||||
|
|
||||||
function getClientId() {
|
|
||||||
const key = "netwatch_client_id";
|
|
||||||
let id = localStorage.getItem(key);
|
|
||||||
if (!id) {
|
|
||||||
id = crypto.randomUUID();
|
|
||||||
localStorage.setItem(key, id);
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const clientId = getClientId();
|
|
||||||
|
|
||||||
function buildReport(state) {
|
|
||||||
return {
|
|
||||||
clientId,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
geo: state.geoInfo,
|
|
||||||
hosts: state.wan.map((h) => ({
|
|
||||||
name: h.name,
|
|
||||||
url: h.url,
|
|
||||||
status: h.status,
|
|
||||||
history: h.history.map((s) => ({
|
|
||||||
t: s.timestamp,
|
|
||||||
latency: s.latency,
|
|
||||||
error: s.error || null,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Formatting Helpers ------------------------------------------------------
|
// --- Formatting Helpers ------------------------------------------------------
|
||||||
|
|
||||||
function formatUTCTimestamp(date) {
|
function formatUTCTimestamp(date) {
|
||||||
@@ -313,7 +269,6 @@ class AppState {
|
|||||||
this.local = localHosts.map((h) => new HostState(h));
|
this.local = localHosts.map((h) => new HostState(h));
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
this.tickCount = 0;
|
this.tickCount = 0;
|
||||||
this.geoInfo = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get allHosts() {
|
get allHosts() {
|
||||||
@@ -596,9 +551,9 @@ function hostRowHTML(host, index, showPin = true) {
|
|||||||
: `<div class="flex-shrink-0 w-4 h-4"></div>`;
|
: `<div class="flex-shrink-0 w-4 h-4"></div>`;
|
||||||
return `
|
return `
|
||||||
<div class="host-row bg-gray-800/50 rounded-lg p-2 border border-gray-700/50" data-index="${index}">
|
<div class="host-row bg-gray-800/50 rounded-lg p-2 border border-gray-700/50" data-index="${index}">
|
||||||
<div class="flex items-center gap-4 min-w-0">
|
<div class="host-row-inner flex items-center gap-4 min-w-0">
|
||||||
${pinBtn}
|
${pinBtn}
|
||||||
<div class="w-[420px] flex-shrink-0 grid grid-cols-[minmax(0,1fr)_auto] items-center">
|
<div class="host-info-panel w-[420px] flex-shrink-0 grid grid-cols-[minmax(0,1fr)_auto] items-center">
|
||||||
<div class="flex items-center gap-2 min-w-[200px]">
|
<div class="flex items-center gap-2 min-w-[200px]">
|
||||||
<div class="w-3 h-3 rounded-full flex-shrink-0" style="background-color: ${latencyHex(null)}"></div>
|
<div class="w-3 h-3 rounded-full flex-shrink-0" style="background-color: ${latencyHex(null)}"></div>
|
||||||
<span class="font-medium text-white truncate">${host.name}</span>
|
<span class="font-medium text-white truncate">${host.name}</span>
|
||||||
@@ -634,9 +589,9 @@ function buildUI(state) {
|
|||||||
app.innerHTML = `
|
app.innerHTML = `
|
||||||
<div class="mx-auto px-[5%] py-8">
|
<div class="mx-auto px-[5%] py-8">
|
||||||
<header class="mb-8">
|
<header class="mb-8">
|
||||||
<div class="flex items-center justify-between mb-4">
|
<div class="header-top flex items-center justify-between mb-4">
|
||||||
<h1 class="text-3xl font-bold text-white"><a href="https://git.eeqj.de/sneak/netwatch" target="_blank" rel="noopener" class="underline decoration-dashed decoration-gray-500 underline-offset-4">NetWatch</a> by <a href="https://sneak.berlin" target="_blank" rel="noopener" class="text-blue-400 underline hover:text-blue-300">@sneak</a></h1>
|
<h1 class="text-3xl font-bold text-white"><a href="https://git.eeqj.de/sneak/netwatch" target="_blank" rel="noopener" class="underline decoration-dashed decoration-gray-500 underline-offset-4">NetWatch</a> by <a href="https://sneak.berlin" target="_blank" rel="noopener" class="text-blue-400 underline hover:text-blue-300">@sneak</a></h1>
|
||||||
<div class="flex flex-col items-end gap-2">
|
<div class="header-controls flex flex-col items-end gap-2">
|
||||||
<button id="pause-btn"
|
<button id="pause-btn"
|
||||||
class="flex items-center gap-3 px-6 py-3 bg-gray-800 hover:bg-gray-700 border border-gray-600 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500">
|
class="flex items-center gap-3 px-6 py-3 bg-gray-800 hover:bg-gray-700 border border-gray-600 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500">
|
||||||
<svg id="pause-icon" class="w-8 h-8 text-yellow-400" fill="currentColor" viewBox="0 0 24 24">
|
<svg id="pause-icon" class="w-8 h-8 text-yellow-400" fill="currentColor" viewBox="0 0 24 24">
|
||||||
@@ -1185,9 +1140,6 @@ async function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const state = new AppState(localHosts);
|
const state = new AppState(localHosts);
|
||||||
fetchGeoInfo().then((geo) => {
|
|
||||||
state.geoInfo = geo;
|
|
||||||
});
|
|
||||||
buildUI(state);
|
buildUI(state);
|
||||||
log.info("UI built, starting tick loop");
|
log.info("UI built, starting tick loop");
|
||||||
|
|
||||||
@@ -1242,11 +1194,6 @@ async function init() {
|
|||||||
doTick();
|
doTick();
|
||||||
let tickIntervalId = setInterval(doTick, CONFIG.updateInterval);
|
let tickIntervalId = setInterval(doTick, CONFIG.updateInterval);
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
if (state.tickCount > 1)
|
|
||||||
console.log("NetWatch report:", buildReport(state));
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById("interval-select")
|
.getElementById("interval-select")
|
||||||
.addEventListener("change", (e) => {
|
.addEventListener("change", (e) => {
|
||||||
|
|||||||
@@ -21,3 +21,54 @@ body {
|
|||||||
rgba(255, 255, 255, 0) 100%
|
rgba(255, 255, 255, 0) 100%
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mobile-responsive host rows */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.host-row-inner {
|
||||||
|
flex-direction: column !important;
|
||||||
|
align-items: stretch !important;
|
||||||
|
gap: 0.5rem !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.host-row-inner .pin-btn {
|
||||||
|
align-self: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.host-info-panel {
|
||||||
|
width: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.host-row .sparkline-container {
|
||||||
|
width: 100% !important;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Summary line: allow wrapping */
|
||||||
|
#summary {
|
||||||
|
display: flex !important;
|
||||||
|
flex-wrap: wrap !important;
|
||||||
|
gap: 0.25rem 0.5rem !important;
|
||||||
|
justify-content: center !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#summary .text-gray-600.mx-3 {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Header: stack controls below title */
|
||||||
|
.header-top {
|
||||||
|
flex-direction: column !important;
|
||||||
|
align-items: flex-start !important;
|
||||||
|
gap: 1rem !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-controls {
|
||||||
|
align-items: flex-start !important;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pause-btn {
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user