@usex/mikrotik-mcp 6.3.0 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,7 +48,7 @@ Then just ask:
48
48
 
49
49
  - **IP Intelligence:** `lookup_ip_intelligence` and Diagnostics → IP Intelligence compare full ipquery/ipkit responses: ASN/organization, location, risk and every additional field, with searchable details and JSON export. Public IPs are sent only on submission; private IPs stay local. [Guide](docs/ip-intelligence.md).
50
50
  - **Service probes:** add, edit, search and remove approved HTTPS/TLS/TCP/DNS targets directly in Config or Service Routing, with explicit IP/CIDR boundaries and safe-apply confirmation. [Setup guide](docs/service-contracts.md#dashboard-setup-no-json-required).
51
- - **OpenVPN connections:** active users, source/tunnel IPs, cached country flags and ASN organizations, searchable source networks and live connection time, with confirmed single-session disconnect and read-only access controls. [Guide](docs/openvpn-connections.md).
51
+ - **OpenVPN connections:** live sessions and persistent observed history, per-user/date connection counts, IP/ASN/country breakdowns and daily charts. Local cached reports avoid router reads; collection gaps remain visible. Includes confirmed single-session disconnect. [Guide](docs/openvpn-connections.md).
52
52
  - **Service Routing:** live IPv4/IPv6 routes, fuzzy address-list search, exact/wildcard domain-to-exit policies with optional health probes, per-policy live matched-traffic counters and charts, VRF HTTPS exit checks and
53
53
  explicitly authorized failover, with preview, backup and Safe Mode. [Guide](docs/service-routing.md)
54
54
  - **Flight Recorder:** opt-in, durable pre/post-incident telemetry and log metadata,
@@ -236,9 +236,9 @@ mikrotik-mcp devices # site-a (default) · site-b
236
236
  #### Docker: one writable `devices.json` for all MCP settings
237
237
 
238
238
  Use the published **[alimaster/mikrotik-mcp](https://hub.docker.com/r/alimaster/mikrotik-mcp)**
239
- image (`6.2.0`, or the moving `latest` tag). Docker selects `linux/amd64` or
239
+ image (`6.3.0`, or the moving `latest` tag). Docker selects `linux/amd64` or
240
240
  `linux/arm64` automatically; no local build is needed. Compose defaults to
241
- `6.2.0`; set `MIKROTIK_IMAGE_TAG` explicitly to select a different release.
241
+ `6.3.0`; set `MIKROTIK_IMAGE_TAG` explicitly to select a different release.
242
242
 
243
243
  **Not ARM-only:** the same image runs on x86-64 and ARM64 Linux hosts (including
244
244
  Ubuntu), and on Windows/macOS through Docker Desktop's **Linux containers**.
@@ -275,13 +275,13 @@ Create a real JSON file on the host (no comments or trailing commas). For exampl
275
275
  ```
276
276
 
277
277
  ```bash
278
- docker pull alimaster/mikrotik-mcp:6.2.0
278
+ docker pull alimaster/mikrotik-mcp:6.3.0
279
279
  docker run -d --name mikrotik-mcp --restart unless-stopped \
280
280
  -p 127.0.0.1:8000:8000 -p 127.0.0.1:9090:9090 \
281
281
  --mount type=volume,src=mikrotik-state,dst=/home/bun/.mikrotik-mcp \
282
282
  --mount type=bind,src=/absolute/path/devices.json,dst=/home/bun/.mikrotik-mcp/devices.json \
283
283
  --mount type=bind,src=/absolute/path/mikrotik_ed25519,dst=/run/secrets/mikrotik_key,readonly \
284
- alimaster/mikrotik-mcp:6.2.0
284
+ alimaster/mikrotik-mcp:6.3.0
285
285
  ```
286
286
 
287
287
  Dashboard: **http://localhost:9090** · MCP: **http://localhost:8000/mcp**.
package/dist/cli.js CHANGED
@@ -21913,13 +21913,13 @@ async function undoMigration(id, confirm, selected) {
21913
21913
  throw new Error("Undo lost Safe Mode or exceeded its time budget.");
21914
21914
  await checkedRead(item.undo, createContext(undefined, device));
21915
21915
  }
21916
- const beforeTarget = (await import("./shared/cli-3kxktenb.js")).openSnapshotStore;
21917
- const db = await beforeTarget((await import("./shared/cli-b7dr5556.js")).DEFAULT_SNAPSHOT_DB);
21916
+ const beforeTarget = (await import("./shared/cli-j9nrx9mk.js")).openSnapshotStore;
21917
+ const db = await beforeTarget((await import("./shared/cli-pmy050a0.js")).DEFAULT_SNAPSHOT_DB);
21918
21918
  try {
21919
21919
  const original = db.get(p.snapshots.target);
21920
21920
  if (!original)
21921
21921
  throw new Error("Original target snapshot unavailable.");
21922
- const { normalizeExport } = await import("./shared/cli-rcgz8540.js");
21922
+ const { normalizeExport } = await import("./shared/cli-qc7ckbhk.js");
21923
21923
  if (normalizeExport((await migrationInventory(device)).export) !== normalizeExport(original.body))
21924
21924
  throw new Error("Target differs from its backup. Undo verification failed.");
21925
21925
  } finally {
@@ -34669,7 +34669,7 @@ var cache3 = null;
34669
34669
  async function gateway() {
34670
34670
  if (cache3)
34671
34671
  return cache3;
34672
- const { moduleCatalog } = await import("./shared/cli-dytg82ck.js");
34672
+ const { moduleCatalog } = await import("./shared/cli-wpshhzhr.js");
34673
34673
  const forIndex = [];
34674
34674
  const byName = new Map;
34675
34675
  for (const mod of moduleCatalog) {
@@ -59962,7 +59962,7 @@ var riskByTool = null;
59962
59962
  async function riskIndex() {
59963
59963
  if (riskByTool)
59964
59964
  return riskByTool;
59965
- const { moduleCatalog } = await import("./shared/cli-dytg82ck.js");
59965
+ const { moduleCatalog } = await import("./shared/cli-wpshhzhr.js");
59966
59966
  const index = new Map;
59967
59967
  for (const mod of moduleCatalog) {
59968
59968
  for (const tool of mod.tools)
@@ -71068,7 +71068,7 @@ import { existsSync as existsSync6 } from "fs";
71068
71068
  import { spawn } from "child_process";
71069
71069
  import { readFileSync as readFileSync14 } from "fs";
71070
71070
  import { homedir as homedir6, networkInterfaces as networkInterfaces2 } from "os";
71071
- import { dirname as dirname23, join as join16 } from "path";
71071
+ import { dirname as dirname24, join as join16 } from "path";
71072
71072
  var {serve } = globalThis.Bun;
71073
71073
 
71074
71074
  // src/observability/modules.ts
@@ -71632,8 +71632,8 @@ function logError(e) {
71632
71632
  }
71633
71633
 
71634
71634
  // src/observability/openvpn-routes.ts
71635
- async function openVpnRoutes(req, url) {
71636
- if (url.pathname !== "/api/openvpn/sessions" && url.pathname !== "/api/openvpn/disconnect")
71635
+ async function openVpnRoutes(req, url, history) {
71636
+ if (!["/api/openvpn/sessions", "/api/openvpn/disconnect", "/api/openvpn/history"].includes(url.pathname))
71637
71637
  return null;
71638
71638
  try {
71639
71639
  const device = url.searchParams.get("device");
@@ -71641,7 +71641,28 @@ async function openVpnRoutes(req, url) {
71641
71641
  throw new DashboardInputError(400, "Select an explicit router first.");
71642
71642
  const ctx = createContext(undefined, device);
71643
71643
  let result;
71644
- if (req.method === "GET" && url.pathname === "/api/openvpn/sessions") {
71644
+ if (req.method === "GET" && url.pathname === "/api/openvpn/history") {
71645
+ let resolved;
71646
+ try {
71647
+ resolved = resolveDeviceName(device);
71648
+ } catch {
71649
+ throw new DashboardInputError(400, "Unknown router.");
71650
+ }
71651
+ try {
71652
+ assertDeviceAccess([resolved], "list_ovpn_sessions", "READ");
71653
+ } catch {
71654
+ throw new DashboardInputError(403, "Device access denied.");
71655
+ }
71656
+ if (!history)
71657
+ return Response.json({ error: "OpenVPN history storage is unavailable." }, { status: 503 });
71658
+ const user = url.searchParams.get("user") ?? "";
71659
+ const from = Number(url.searchParams.get("from") ?? 0);
71660
+ const to = Number(url.searchParams.get("to") ?? 8640000000000000);
71661
+ const offset = Number(url.searchParams.get("offset") ?? 0);
71662
+ if (user.length > 256 || ![from, to, offset].every(Number.isSafeInteger) || from < 0 || to < from || to > 8640000000000000 || offset < 0 || offset > 1e6)
71663
+ throw new DashboardInputError(400, "Provide a valid user, date range and page.");
71664
+ result = history.report({ device: resolved, user, from, to, offset });
71665
+ } else if (req.method === "GET" && url.pathname === "/api/openvpn/sessions") {
71645
71666
  const snapshot = await listOpenVpnSessions(ctx);
71646
71667
  result = {
71647
71668
  ...snapshot,
@@ -71674,6 +71695,203 @@ async function openVpnRoutes(req, url) {
71674
71695
  }
71675
71696
  }
71676
71697
 
71698
+ // src/observability/openvpn-history.ts
71699
+ import { randomUUID as randomUUID12 } from "crypto";
71700
+ import { chmodSync as chmodSync2, mkdirSync as mkdirSync17 } from "fs";
71701
+ import { dirname as dirname18 } from "path";
71702
+ var OPENVPN_HISTORY_INTERVAL = 15000;
71703
+ function sameObservedSession(previous, session, at) {
71704
+ if (previous.ended !== null)
71705
+ return false;
71706
+ if (session.uptimeSeconds === null || previous.uptime === null)
71707
+ return at - previous.lastSeen <= OPENVPN_HISTORY_INTERVAL * 3;
71708
+ return session.uptimeSeconds >= previous.uptime && Math.abs(at - session.uptimeSeconds * 1000 - previous.started) <= 20000;
71709
+ }
71710
+
71711
+ class OpenVpnHistoryStore {
71712
+ db;
71713
+ cache = new Map;
71714
+ constructor(db) {
71715
+ this.db = db;
71716
+ db.run("PRAGMA journal_mode=WAL");
71717
+ db.run("PRAGMA busy_timeout=5000");
71718
+ db.run(`CREATE TABLE IF NOT EXISTS ovpn_history (
71719
+ id TEXT PRIMARY KEY, device TEXT NOT NULL, user TEXT NOT NULL, identity TEXT NOT NULL,
71720
+ ip TEXT NOT NULL, tunnel TEXT NOT NULL, started INTEGER NOT NULL, firstSeen INTEGER NOT NULL,
71721
+ lastSeen INTEGER NOT NULL, ended INTEGER, uptime INTEGER, uncertain INTEGER NOT NULL,
71722
+ country TEXT NOT NULL, countryCode TEXT NOT NULL, asn TEXT NOT NULL, organization TEXT NOT NULL,
71723
+ geoStatus TEXT NOT NULL)`);
71724
+ db.run("CREATE INDEX IF NOT EXISTS ovpn_history_geo ON ovpn_history(ip,lastSeen) WHERE geoStatus='pending'");
71725
+ db.run("CREATE INDEX IF NOT EXISTS ovpn_history_user ON ovpn_history(device,user,started)");
71726
+ db.run("CREATE INDEX IF NOT EXISTS ovpn_history_time ON ovpn_history(device,started)");
71727
+ db.run("CREATE INDEX IF NOT EXISTS ovpn_history_ip ON ovpn_history(ip)");
71728
+ db.run("CREATE INDEX IF NOT EXISTS ovpn_history_active ON ovpn_history(device) WHERE ended IS NULL");
71729
+ db.run(`CREATE TABLE IF NOT EXISTS ovpn_coverage (
71730
+ device TEXT PRIMARY KEY, first INTEGER NOT NULL, last INTEGER NOT NULL,
71731
+ gaps INTEGER NOT NULL DEFAULT 0, failures INTEGER NOT NULL DEFAULT 0)`);
71732
+ }
71733
+ ingest(snapshot) {
71734
+ const { device, observedAt: at, sessions } = snapshot;
71735
+ this.db.transaction(() => {
71736
+ const coverage = this.db.query("SELECT last FROM ovpn_coverage WHERE device=?").get(device);
71737
+ if (coverage && at <= coverage.last)
71738
+ return;
71739
+ const gap = !!coverage && at - coverage.last > OPENVPN_HISTORY_INTERVAL * 3;
71740
+ const previous = this.db.query("SELECT * FROM ovpn_history WHERE device=? AND ended IS NULL").all(device);
71741
+ const active = new Map(previous.map((row) => [row.identity, row]));
71742
+ for (const session of sessions) {
71743
+ const identity = JSON.stringify([
71744
+ session.id,
71745
+ session.sessionId,
71746
+ session.name,
71747
+ session.callerId,
71748
+ session.address
71749
+ ]);
71750
+ const old = active.get(identity);
71751
+ const geo = session.sourceGeo;
71752
+ if (old && sameObservedSession(old, session, at)) {
71753
+ this.db.query(`UPDATE ovpn_history SET lastSeen=?,
71754
+ started=CASE WHEN uptime IS NULL AND ? IS NOT NULL THEN ? ELSE started END,
71755
+ uptime=COALESCE(?,uptime),uncertain=MAX(uncertain,?),
71756
+ country=CASE WHEN ?='' THEN country ELSE ? END,
71757
+ countryCode=CASE WHEN ?='' THEN countryCode ELSE ? END,
71758
+ asn=CASE WHEN ?='' THEN asn ELSE ? END,
71759
+ organization=CASE WHEN ?='' THEN organization ELSE ? END,
71760
+ geoStatus=CASE WHEN countryCode='' THEN ? ELSE geoStatus END WHERE id=?`).run(at, session.uptimeSeconds, at - (session.uptimeSeconds ?? 0) * 1000, session.uptimeSeconds, Number(gap || session.uptimeSeconds === null), geo?.country ?? "", geo?.country ?? "", geo?.countryCode ?? "", geo?.countryCode ?? "", geo?.asn ?? "", geo?.asn ?? "", geo?.asnOrganization ?? "", geo?.asnOrganization ?? "", geo?.status ?? "pending", old.id);
71761
+ active.delete(identity);
71762
+ } else {
71763
+ this.db.query("INSERT INTO ovpn_history VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)").run(randomUUID12(), device, session.name, identity, session.callerId, session.address, at - (session.uptimeSeconds ?? 0) * 1000, at, at, null, session.uptimeSeconds, Number(gap || session.uptimeSeconds === null), geo?.country ?? "", geo?.countryCode ?? "", geo?.asn ?? "", geo?.asnOrganization ?? "", geo?.status ?? "pending");
71764
+ }
71765
+ }
71766
+ for (const row of active.values())
71767
+ this.db.query("UPDATE ovpn_history SET ended=?,uncertain=MAX(uncertain,?) WHERE id=?").run(at, Number(gap), row.id);
71768
+ this.db.query(`INSERT INTO ovpn_coverage(device,first,last) VALUES (?,?,?)
71769
+ ON CONFLICT(device) DO UPDATE SET last=excluded.last,gaps=gaps+?`).run(device, at, at, Number(gap));
71770
+ })();
71771
+ }
71772
+ failure(device) {
71773
+ this.db.query("UPDATE ovpn_coverage SET failures=failures+1 WHERE device=?").run(device);
71774
+ }
71775
+ enrich(lookup) {
71776
+ const pending = this.db.query("SELECT ip FROM ovpn_history WHERE geoStatus='pending' GROUP BY ip ORDER BY MAX(lastSeen) DESC LIMIT 100").all();
71777
+ for (const { ip } of pending) {
71778
+ const geo = lookup(ip);
71779
+ if (!geo || geo.status === "pending")
71780
+ continue;
71781
+ this.db.query("UPDATE ovpn_history SET country=?,countryCode=?,asn=?,organization=?,geoStatus=? WHERE ip=? AND geoStatus='pending'").run(geo.country ?? "", geo.countryCode ?? "", geo.asn ?? "", geo.asnOrganization ?? "", geo.status, ip);
71782
+ }
71783
+ }
71784
+ report(filter, now = Date.now()) {
71785
+ const key = JSON.stringify(filter);
71786
+ const cached = this.cache.get(key);
71787
+ if (cached && cached.expires > now)
71788
+ return cached.report;
71789
+ const { device, user, from, to, offset } = filter;
71790
+ const where = "device=? AND (?='' OR user=?) AND started>=? AND started<=?";
71791
+ const args = [device, user, user, from, to];
71792
+ const totals = this.db.query(`SELECT
71793
+ COUNT(*) connections,COUNT(DISTINCT user) users,COUNT(DISTINCT NULLIF(ip,'')) ips,
71794
+ COUNT(DISTINCT NULLIF(countryCode,'')) countries,COUNT(DISTINCT NULLIF(asn,'')) networks,
71795
+ COALESCE(SUM(uptime),0) seconds FROM ovpn_history WHERE ${where}`).get(...args);
71796
+ const groups = (label, detail) => this.db.query(`SELECT ${label} label,${detail} detail,COUNT(*) count FROM ovpn_history WHERE ${where}
71797
+ GROUP BY label ORDER BY count DESC,label LIMIT 20`).all(...args);
71798
+ const dayMs = 86400000;
71799
+ const lastDay = Math.floor(Math.min(to, now) / dayMs) * dayMs;
71800
+ const firstDay = Math.max(Math.floor(from / dayMs) * dayMs, lastDay - 89 * dayMs);
71801
+ const daily = new Map(this.db.query(`SELECT strftime('%Y-%m-%d',started/1000,'unixepoch') day,COUNT(*) count FROM ovpn_history WHERE ${where} AND started>=? GROUP BY day`).all(...args, firstDay).map((row) => [row.day, row.count]));
71802
+ const timeline = [];
71803
+ for (let at = firstDay;at <= lastDay; at += dayMs) {
71804
+ const day = new Date(at).toISOString().slice(0, 10);
71805
+ timeline.push({ day, count: daily.get(day) ?? 0 });
71806
+ }
71807
+ const report = {
71808
+ generatedAt: now,
71809
+ coverage: this.db.query("SELECT first,last,gaps,failures FROM ovpn_coverage WHERE device=?").get(device),
71810
+ users: this.db.query("SELECT DISTINCT user FROM ovpn_history WHERE device=? ORDER BY user LIMIT 10000").all(device).map((r) => r.user),
71811
+ allTime: this.db.query("SELECT COUNT(*) n FROM ovpn_history WHERE device=? AND (?='' OR user=?)").get(device, user, user).n,
71812
+ totals,
71813
+ timeline,
71814
+ ips: groups("COALESCE(NULLIF(ip,''),'Unknown IP')", "MAX(organization)"),
71815
+ networks: groups("COALESCE(NULLIF(asn,''),'Unknown ASN')", "MAX(organization)"),
71816
+ countries: groups("COALESCE(NULLIF(country,''),'Unknown country')", "MAX(countryCode)"),
71817
+ sessions: this.db.query(`SELECT * FROM ovpn_history WHERE ${where} ORDER BY started DESC,id LIMIT 50 OFFSET ?`).all(...args, offset),
71818
+ offset,
71819
+ limit: 50
71820
+ };
71821
+ if (this.cache.size >= 128)
71822
+ this.cache.delete(this.cache.keys().next().value);
71823
+ this.cache.set(key, { expires: now + 30000, report });
71824
+ return report;
71825
+ }
71826
+ close() {
71827
+ this.cache.clear();
71828
+ this.db.close();
71829
+ }
71830
+ }
71831
+ async function openOpenVpnHistory(path) {
71832
+ mkdirSync17(dirname18(path), { recursive: true, mode: 448 });
71833
+ const { Database } = await import("bun:sqlite");
71834
+ const db = new Database(path, { create: true });
71835
+ chmodSync2(path, 384);
71836
+ try {
71837
+ return new OpenVpnHistoryStore(db);
71838
+ } catch (error) {
71839
+ db.close();
71840
+ throw error;
71841
+ }
71842
+ }
71843
+
71844
+ // src/observability/openvpn-history-sampler.ts
71845
+ function startOpenVpnHistorySampler(store) {
71846
+ let stopped = false;
71847
+ let timer;
71848
+ const retries = new Map;
71849
+ async function sample() {
71850
+ for (const [device, config] of Object.entries(getConfig().devices)) {
71851
+ if (stopped)
71852
+ return;
71853
+ if (config.disabled || config.mac || getSafeModeManager(device).isActive)
71854
+ continue;
71855
+ if ((retries.get(device)?.at ?? 0) > Date.now())
71856
+ continue;
71857
+ try {
71858
+ const snapshot = await listOpenVpnSessions(createContext(undefined, device));
71859
+ if (stopped)
71860
+ return;
71861
+ store.ingest({
71862
+ ...snapshot,
71863
+ sessions: snapshot.sessions.map((s) => ({
71864
+ ...s,
71865
+ callerId: sourceIpLiteral(s.callerId) ?? s.callerId,
71866
+ sourceGeo: getIpGeo(s.callerId)
71867
+ }))
71868
+ });
71869
+ retries.delete(device);
71870
+ } catch {
71871
+ const delay = Math.min(300000, (retries.get(device)?.delay ?? 15000) * 2);
71872
+ retries.set(device, { at: Date.now() + delay, delay });
71873
+ if (!stopped) {
71874
+ try {
71875
+ store.failure(device);
71876
+ } catch {}
71877
+ }
71878
+ }
71879
+ }
71880
+ if (!stopped) {
71881
+ try {
71882
+ store.enrich(getIpGeo);
71883
+ } catch {}
71884
+ }
71885
+ if (!stopped)
71886
+ timer = setTimeout(() => void sample(), OPENVPN_HISTORY_INTERVAL);
71887
+ }
71888
+ sample();
71889
+ return () => {
71890
+ stopped = true;
71891
+ clearTimeout(timer);
71892
+ };
71893
+ }
71894
+
71677
71895
  // src/observability/ip-intelligence-routes.ts
71678
71896
  async function ipIntelligenceRoutes(req, url) {
71679
71897
  if (url.pathname !== "/api/ip-intelligence")
@@ -71766,9 +71984,9 @@ async function roundTripRoutes(req, url) {
71766
71984
  }
71767
71985
 
71768
71986
  // src/observability/um-report-cache.ts
71769
- import { createHash as createHash12, randomUUID as randomUUID12 } from "crypto";
71987
+ import { createHash as createHash12, randomUUID as randomUUID13 } from "crypto";
71770
71988
  import { mkdir, readFile, rename, stat, unlink, writeFile } from "fs/promises";
71771
- import { dirname as dirname18, join as join12 } from "path";
71989
+ import { dirname as dirname19, join as join12 } from "path";
71772
71990
  var MAX_BYTES = 32 * 1024 * 1024;
71773
71991
  var MAX_AGE = 24 * 60 * 60000;
71774
71992
  var sourceSchema = object({
@@ -71828,12 +72046,12 @@ async function loadUmReportCache(path, device, fields) {
71828
72046
  async function saveUmReportCache(path, snapshot) {
71829
72047
  if (!path || Object.values(snapshot.sources).some((source) => source.error))
71830
72048
  return false;
71831
- const temp = `${path}.${randomUUID12()}.tmp`;
72049
+ const temp = `${path}.${randomUUID13()}.tmp`;
71832
72050
  try {
71833
72051
  const text = JSON.stringify({ version: 1, snapshot });
71834
72052
  if (Buffer.byteLength(text) > MAX_BYTES)
71835
72053
  return false;
71836
- await mkdir(dirname18(path), { recursive: true, mode: 448 });
72054
+ await mkdir(dirname19(path), { recursive: true, mode: 448 });
71837
72055
  await writeFile(temp, text, { encoding: "utf8", mode: 384, flag: "wx" });
71838
72056
  await rename(temp, path);
71839
72057
  return true;
@@ -72556,7 +72774,7 @@ function buildUmReport(snapshot, query) {
72556
72774
  // src/observability/config-history.ts
72557
72775
  import {
72558
72776
  existsSync as existsSync5,
72559
- mkdirSync as mkdirSync17,
72777
+ mkdirSync as mkdirSync18,
72560
72778
  readFileSync as readFileSync12,
72561
72779
  readdirSync as readdirSync3,
72562
72780
  rmSync as rmSync3,
@@ -72608,7 +72826,7 @@ function deleteVersion(id) {
72608
72826
  }
72609
72827
  function recordVersion(config, kind, now, label) {
72610
72828
  const dir = historyDir();
72611
- mkdirSync17(dir, { recursive: true });
72829
+ mkdirSync18(dir, { recursive: true });
72612
72830
  let ts = now;
72613
72831
  while (existsSync5(join13(dir, `v${ts}.json`)))
72614
72832
  ts++;
@@ -73195,8 +73413,8 @@ data: ${JSON.stringify(sample)}
73195
73413
  }
73196
73414
 
73197
73415
  // src/observability/store.ts
73198
- import { mkdirSync as mkdirSync18 } from "fs";
73199
- import { dirname as dirname19 } from "path";
73416
+ import { mkdirSync as mkdirSync19 } from "fs";
73417
+ import { dirname as dirname20 } from "path";
73200
73418
  function rowToEvent2(r) {
73201
73419
  return {
73202
73420
  id: r.id,
@@ -73374,7 +73592,7 @@ class SqliteEventStore {
73374
73592
  async function openSqliteStore(path) {
73375
73593
  if (path !== ":memory:") {
73376
73594
  try {
73377
- mkdirSync18(dirname19(path), { recursive: true });
73595
+ mkdirSync19(dirname20(path), { recursive: true });
73378
73596
  } catch {}
73379
73597
  }
73380
73598
  const { Database } = await import("bun:sqlite");
@@ -73383,8 +73601,8 @@ async function openSqliteStore(path) {
73383
73601
  }
73384
73602
 
73385
73603
  // src/observability/capsman-store.ts
73386
- import { mkdirSync as mkdirSync19 } from "fs";
73387
- import { dirname as dirname20 } from "path";
73604
+ import { mkdirSync as mkdirSync20 } from "fs";
73605
+ import { dirname as dirname21 } from "path";
73388
73606
  function summariseRadioSamples(rows) {
73389
73607
  const byRadio = new Map;
73390
73608
  for (const r of rows) {
@@ -73474,7 +73692,7 @@ class SqliteCapsmanStore {
73474
73692
  async function openCapsmanStore(path) {
73475
73693
  if (path !== ":memory:") {
73476
73694
  try {
73477
- mkdirSync19(dirname20(path), { recursive: true });
73695
+ mkdirSync20(dirname21(path), { recursive: true });
73478
73696
  } catch {}
73479
73697
  }
73480
73698
  const { Database } = await import("bun:sqlite");
@@ -73553,8 +73771,8 @@ function stopCapsmanSampler() {
73553
73771
  }
73554
73772
 
73555
73773
  // src/observability/usage-store.ts
73556
- import { mkdirSync as mkdirSync20 } from "fs";
73557
- import { dirname as dirname21 } from "path";
73774
+ import { mkdirSync as mkdirSync21 } from "fs";
73775
+ import { dirname as dirname22 } from "path";
73558
73776
  function dayOf(ts) {
73559
73777
  return new Date(ts).toISOString().slice(0, 10);
73560
73778
  }
@@ -73691,7 +73909,7 @@ class SqliteUsageStore {
73691
73909
  async function openUsageStore(path) {
73692
73910
  if (path !== ":memory:") {
73693
73911
  try {
73694
- mkdirSync20(dirname21(path), { recursive: true });
73912
+ mkdirSync21(dirname22(path), { recursive: true });
73695
73913
  } catch {}
73696
73914
  }
73697
73915
  const { Database } = await import("bun:sqlite");
@@ -74538,8 +74756,8 @@ async function rolloutRoutes(req, url) {
74538
74756
  }
74539
74757
 
74540
74758
  // src/policy/results.ts
74541
- import { mkdirSync as mkdirSync21 } from "fs";
74542
- import { dirname as dirname22 } from "path";
74759
+ import { mkdirSync as mkdirSync22 } from "fs";
74760
+ import { dirname as dirname23 } from "path";
74543
74761
  var SCHEMA_STATEMENTS9 = [
74544
74762
  `CREATE TABLE IF NOT EXISTS policy_results (
74545
74763
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -74599,7 +74817,7 @@ class SqlitePolicyResultStore {
74599
74817
  async function openPolicyResultStore(path) {
74600
74818
  if (path !== ":memory:") {
74601
74819
  try {
74602
- mkdirSync21(dirname22(path), { recursive: true });
74820
+ mkdirSync22(dirname23(path), { recursive: true });
74603
74821
  } catch {}
74604
74822
  }
74605
74823
  const { Database } = await import("bun:sqlite");
@@ -76712,14 +76930,22 @@ async function runDashboard(cfg, transportLabel) {
76712
76930
  });
76713
76931
  startHealthChecks(30000);
76714
76932
  startGeoLookups();
76933
+ let openVpnHistory;
76934
+ let stopOpenVpnHistory;
76935
+ try {
76936
+ openVpnHistory = await openOpenVpnHistory(join16(dirname24(cfg.dbPath), "openvpn-history.db"));
76937
+ stopOpenVpnHistory = startOpenVpnHistorySampler(openVpnHistory);
76938
+ } catch (e) {
76939
+ logger.warn(`[${SERVER_TAG3}] OpenVPN history disabled: ${String(e)}`);
76940
+ }
76715
76941
  try {
76716
- usageStore = await openUsageStore(join16(dirname23(cfg.dbPath), "usage.db"));
76942
+ usageStore = await openUsageStore(join16(dirname24(cfg.dbPath), "usage.db"));
76717
76943
  startUsageSampler(usageStore);
76718
76944
  } catch (e) {
76719
76945
  logger.warn(`[${SERVER_TAG3}] usage history disabled: ${String(e)}`);
76720
76946
  }
76721
76947
  try {
76722
- capsmanStore = await openCapsmanStore(join16(dirname23(cfg.dbPath), "capsman.db"));
76948
+ capsmanStore = await openCapsmanStore(join16(dirname24(cfg.dbPath), "capsman.db"));
76723
76949
  startCapsmanSampler(capsmanStore);
76724
76950
  } catch (e) {
76725
76951
  logger.warn(`[${SERVER_TAG3}] capsman trends disabled: ${String(e)}`);
@@ -76790,7 +77016,7 @@ async function runDashboard(cfg, transportLabel) {
76790
77016
  const operationsResp = await operationsRoutes(req, url);
76791
77017
  if (operationsResp)
76792
77018
  return operationsResp;
76793
- const openVpnResp = await openVpnRoutes(req, url);
77019
+ const openVpnResp = await openVpnRoutes(req, url, openVpnHistory);
76794
77020
  if (openVpnResp)
76795
77021
  return openVpnResp;
76796
77022
  const ipNetworkResp = ipGeoRoute(req, url);
@@ -77138,6 +77364,8 @@ async function runDashboard(cfg, transportLabel) {
77138
77364
  server,
77139
77365
  store,
77140
77366
  stop() {
77367
+ stopOpenVpnHistory?.();
77368
+ openVpnHistory?.close();
77141
77369
  stopHealthChecks();
77142
77370
  stopGeoLookups();
77143
77371
  stopUsageSampler();
@@ -77154,7 +77382,7 @@ async function runDashboard(cfg, transportLabel) {
77154
77382
  }
77155
77383
 
77156
77384
  // src/transport/http.ts
77157
- import { randomUUID as randomUUID13 } from "crypto";
77385
+ import { randomUUID as randomUUID14 } from "crypto";
77158
77386
  var {serve: serve2 } = globalThis.Bun;
77159
77387
 
77160
77388
  // node_modules/content-type/index.js
@@ -86679,7 +86907,7 @@ async function runHttp(mcp) {
86679
86907
  if (existing)
86680
86908
  return existing;
86681
86909
  const transport = new WebStandardStreamableHTTPServerTransport({
86682
- sessionIdGenerator: () => randomUUID13(),
86910
+ sessionIdGenerator: () => randomUUID14(),
86683
86911
  enableJsonResponse: true,
86684
86912
  ...security,
86685
86913
  onsessioninitialized: (id) => {