@usex/mikrotik-mcp 6.2.0 → 6.3.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 +4 -4
- package/dist/cli.js +153 -57
- package/dist/index.d.ts +8 -3
- package/dist/index.js +1 -1
- package/dist/shared/{library-2a48dhze.js → library-2m4as43g.js} +1 -1
- package/dist/shared/{library-dh2r9fza.js → library-akf94mf2.js} +1 -1
- package/dist/shared/{library-vj9yv0px.js → library-g661a57q.js} +1 -1
- package/dist/shared/{library-ts0epdh7.js → library-hykdpvnj.js} +1 -1
- package/dist/shared/{library-645wm62v.js → library-ttgvk8a6.js} +61 -37
- package/dist/ui/observability.html +73 -73
- package/package.json +12 -12
- package/schemas/README.md +1 -1
- package/schemas/devtools-manifest.json +16 -2
- package/schemas/tool-catalog.json +34 -4
- package/schemas/tools/set_safe_mode_timeout.json +21 -0
- /package/dist/shared/{cli-5qqtzj1z.js → cli-3kxktenb.js} +0 -0
- /package/dist/shared/{cli-fjzymtm7.js → cli-b7dr5556.js} +0 -0
- /package/dist/shared/{cli-j0jhy663.js → cli-dytg82ck.js} +0 -0
- /package/dist/shared/{cli-76mdhx9m.js → cli-rcgz8540.js} +0 -0
package/README.md
CHANGED
|
@@ -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.
|
|
239
|
+
image (`6.2.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.
|
|
241
|
+
`6.2.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.
|
|
278
|
+
docker pull alimaster/mikrotik-mcp:6.2.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.
|
|
284
|
+
alimaster/mikrotik-mcp:6.2.0
|
|
285
285
|
```
|
|
286
286
|
|
|
287
287
|
Dashboard: **http://localhost:9090** · MCP: **http://localhost:8000/mcp**.
|
package/dist/cli.js
CHANGED
|
@@ -18413,12 +18413,25 @@ class SafeModeManager {
|
|
|
18413
18413
|
uncertain = false;
|
|
18414
18414
|
probeSequence = 0;
|
|
18415
18415
|
queue = Promise.resolve();
|
|
18416
|
+
commandTimeoutMs = HARD_CAP_MS;
|
|
18417
|
+
idleTimeoutMs = IDLE_TIMEOUT_MS;
|
|
18418
|
+
setTimeouts(commandTimeoutMs, idleTimeoutMs) {
|
|
18419
|
+
if (!Number.isInteger(commandTimeoutMs) || commandTimeoutMs < 1000 || commandTimeoutMs > 600000 || !Number.isInteger(idleTimeoutMs) || idleTimeoutMs < 1000 || idleTimeoutMs > commandTimeoutMs) {
|
|
18420
|
+
throw new Error("Timeouts must be integer milliseconds: 1000 <= idleTimeoutMs <= commandTimeoutMs <= 600000.");
|
|
18421
|
+
}
|
|
18422
|
+
this.commandTimeoutMs = commandTimeoutMs;
|
|
18423
|
+
this.idleTimeoutMs = idleTimeoutMs;
|
|
18424
|
+
return `Safe Mode command timeout: ${commandTimeoutMs}ms; idle timeout: ${idleTimeoutMs}ms. Applies to subsequent commands only; does not change RouterOS rollback timing or clear an uncertain session.`;
|
|
18425
|
+
}
|
|
18416
18426
|
constructor(deviceName) {
|
|
18417
18427
|
this.deviceName = deviceName;
|
|
18418
18428
|
}
|
|
18419
18429
|
get isActive() {
|
|
18420
18430
|
return this.active;
|
|
18421
18431
|
}
|
|
18432
|
+
get requiresRecovery() {
|
|
18433
|
+
return this.droppedUnexpectedly || this.uncertain;
|
|
18434
|
+
}
|
|
18422
18435
|
lock(fn) {
|
|
18423
18436
|
const run = this.queue.then(fn, fn);
|
|
18424
18437
|
this.queue = run.then(() => {
|
|
@@ -18459,20 +18472,20 @@ class SafeModeManager {
|
|
|
18459
18472
|
return `Error: Safe mode did not activate. Response: ${JSON.stringify(response.slice(0, 300))}`;
|
|
18460
18473
|
}
|
|
18461
18474
|
this.active = true;
|
|
18462
|
-
return "Safe mode ENABLED.
|
|
18475
|
+
return "Safe mode ENABLED. RouterOS tracks reversible changes while protection remains active. " + "Keep a backup; disconnect requests rollback but does not prove restoration. " + "Call commit_safe_mode after verification.";
|
|
18463
18476
|
});
|
|
18464
18477
|
}
|
|
18465
18478
|
execute(command) {
|
|
18466
18479
|
return this.lock(async () => {
|
|
18467
18480
|
if (this.droppedUnexpectedly) {
|
|
18468
|
-
throw new Error("Safe Mode session dropped
|
|
18481
|
+
throw new Error("Safe Mode session dropped. Rollback is unverified; inspect device state against the backup before retrying writes.");
|
|
18469
18482
|
}
|
|
18470
18483
|
if (!this.active || !this.channel) {
|
|
18471
18484
|
throw new Error("Safe mode session is not active.");
|
|
18472
18485
|
}
|
|
18473
18486
|
if (this.uncertain)
|
|
18474
18487
|
throw new Error(UNCERTAIN_SESSION);
|
|
18475
|
-
const response = this.readUntilPrompt(
|
|
18488
|
+
const response = this.readUntilPrompt(this.idleTimeoutMs, undefined, this.commandTimeoutMs, true);
|
|
18476
18489
|
this.channel.write(`${command}
|
|
18477
18490
|
`);
|
|
18478
18491
|
const { text, timedOut } = await response;
|
|
@@ -18480,16 +18493,19 @@ class SafeModeManager {
|
|
|
18480
18493
|
this.uncertain = true;
|
|
18481
18494
|
throw new Error(`Safe Mode command did not return a recognized prompt before the timeout (command: ${command}). ` + `Execution may have occurred; do not retry the write blindly. ${UNCERTAIN_SESSION}`);
|
|
18482
18495
|
}
|
|
18496
|
+
if (classifyPrompt(text) !== "safe") {
|
|
18497
|
+
this.uncertain = true;
|
|
18498
|
+
throw new Error(`Safe Mode protection was lost or could not be confirmed. Changes may already be permanent. ${UNCERTAIN_SESSION}`);
|
|
18499
|
+
}
|
|
18483
18500
|
return this.extractOutput(text, command);
|
|
18484
18501
|
});
|
|
18485
18502
|
}
|
|
18486
18503
|
commit() {
|
|
18487
18504
|
return this.lock(async () => {
|
|
18488
18505
|
if (this.droppedUnexpectedly) {
|
|
18489
|
-
this.droppedUnexpectedly = false;
|
|
18490
18506
|
return {
|
|
18491
18507
|
ok: false,
|
|
18492
|
-
message: "Commit FAILED \u2014 the Safe Mode session dropped
|
|
18508
|
+
message: "Commit FAILED \u2014 the Safe Mode session dropped. Rollback is unverified; compare device state with the backup before retrying."
|
|
18493
18509
|
};
|
|
18494
18510
|
}
|
|
18495
18511
|
if (!this.active || !this.channel) {
|
|
@@ -18499,16 +18515,16 @@ class SafeModeManager {
|
|
|
18499
18515
|
return { ok: false, message: UNCERTAIN_SESSION };
|
|
18500
18516
|
const before = await this.probeMode();
|
|
18501
18517
|
if (before === "released") {
|
|
18502
|
-
this.
|
|
18518
|
+
this.uncertain = true;
|
|
18503
18519
|
return {
|
|
18504
|
-
ok:
|
|
18505
|
-
message: "Safe
|
|
18520
|
+
ok: false,
|
|
18521
|
+
message: "Safe Mode exited before commit was requested. Changes may be permanent; verify device state against the backup."
|
|
18506
18522
|
};
|
|
18507
18523
|
}
|
|
18508
18524
|
if (before === "unknown") {
|
|
18509
18525
|
return {
|
|
18510
18526
|
ok: false,
|
|
18511
|
-
message: "Could not
|
|
18527
|
+
message: "Could not determine Safe Mode state. Session left open; outcome unverified. " + "Call safe_mode_status or rollback_safe_mode and inspect device state."
|
|
18512
18528
|
};
|
|
18513
18529
|
}
|
|
18514
18530
|
this.channel.write(CTRL_X);
|
|
@@ -18525,7 +18541,7 @@ class SafeModeManager {
|
|
|
18525
18541
|
default:
|
|
18526
18542
|
return {
|
|
18527
18543
|
ok: false,
|
|
18528
|
-
message: "Commit status unclear \u2014 no prompt seen after
|
|
18544
|
+
message: "Commit status unclear \u2014 no prompt seen after commit. Session left open; outcome unverified. " + "Inspect device state before retrying."
|
|
18529
18545
|
};
|
|
18530
18546
|
}
|
|
18531
18547
|
});
|
|
@@ -18534,21 +18550,21 @@ class SafeModeManager {
|
|
|
18534
18550
|
return this.lock(async () => {
|
|
18535
18551
|
if (this.droppedUnexpectedly) {
|
|
18536
18552
|
this.droppedUnexpectedly = false;
|
|
18537
|
-
return "Safe Mode session had already dropped
|
|
18553
|
+
return "Safe Mode session had already dropped. Rollback is unverified; compare device state with the backup. Do not blindly reapply writes.";
|
|
18538
18554
|
}
|
|
18539
18555
|
if (!this.active)
|
|
18540
18556
|
return "Safe mode is not active. Nothing to roll back.";
|
|
18541
18557
|
this.cleanup();
|
|
18542
|
-
return "Safe mode session closed.
|
|
18558
|
+
return "Safe mode session closed to request automatic rollback. Rollback is unverified and may be delayed; compare device state with the backup before retrying writes.";
|
|
18543
18559
|
});
|
|
18544
18560
|
}
|
|
18545
18561
|
status() {
|
|
18546
18562
|
if (this.droppedUnexpectedly) {
|
|
18547
|
-
return "Safe mode session DROPPED unexpectedly
|
|
18563
|
+
return "Safe mode session DROPPED unexpectedly. Rollback is unverified; inspect device state against the backup before retrying writes.";
|
|
18548
18564
|
}
|
|
18549
18565
|
if (this.uncertain && this.active)
|
|
18550
18566
|
return UNCERTAIN_SESSION;
|
|
18551
|
-
return this.active ?
|
|
18567
|
+
return this.active ? `Safe mode is ACTIVE (last observed). Command timeout: ${this.commandTimeoutMs}ms; idle timeout: ${this.idleTimeoutMs}ms. ` + "Call commit_safe_mode to persist or rollback_safe_mode to revert." : "Safe mode is NOT active. Changes take effect and persist immediately.";
|
|
18552
18568
|
}
|
|
18553
18569
|
handleUnexpectedDrop = () => {
|
|
18554
18570
|
if (!this.active)
|
|
@@ -18564,6 +18580,7 @@ class SafeModeManager {
|
|
|
18564
18580
|
let buf = "";
|
|
18565
18581
|
let idleTimer;
|
|
18566
18582
|
const hardTimer = setTimeout(() => finish(stripAnsi(buf), true), hardCapMs);
|
|
18583
|
+
const onClose = () => finish(stripAnsi(buf), true);
|
|
18567
18584
|
function armIdle() {
|
|
18568
18585
|
clearTimeout(idleTimer);
|
|
18569
18586
|
idleTimer = setTimeout(() => finish(stripAnsi(buf), true), idleMs);
|
|
@@ -18586,10 +18603,14 @@ class SafeModeManager {
|
|
|
18586
18603
|
clearTimeout(idleTimer);
|
|
18587
18604
|
clearTimeout(hardTimer);
|
|
18588
18605
|
channel.removeListener("data", onData);
|
|
18606
|
+
channel.removeListener("close", onClose);
|
|
18607
|
+
channel.removeListener("error", onClose);
|
|
18589
18608
|
resolve({ text: result, timedOut });
|
|
18590
18609
|
}
|
|
18591
18610
|
armIdle();
|
|
18592
18611
|
channel.on("data", onData);
|
|
18612
|
+
channel.once("close", onClose);
|
|
18613
|
+
channel.once("error", onClose);
|
|
18593
18614
|
});
|
|
18594
18615
|
}
|
|
18595
18616
|
async probeMode() {
|
|
@@ -18724,7 +18745,7 @@ async function runOnce(command, deviceName, opts, ctx) {
|
|
|
18724
18745
|
async function executeMikrotikCommand(command, ctx, opts) {
|
|
18725
18746
|
const deviceName = resolveDeviceName(ctx.device);
|
|
18726
18747
|
const safe = getSafeModeManager(deviceName);
|
|
18727
|
-
if (safe.isActive) {
|
|
18748
|
+
if (safe.isActive || safe.requiresRecovery) {
|
|
18728
18749
|
ctx.info(`[${deviceName}] Executing (safe mode): ${containerCommandForLog(command)}`);
|
|
18729
18750
|
ctx.transport = "ssh";
|
|
18730
18751
|
return safe.execute(command);
|
|
@@ -21892,13 +21913,13 @@ async function undoMigration(id, confirm, selected) {
|
|
|
21892
21913
|
throw new Error("Undo lost Safe Mode or exceeded its time budget.");
|
|
21893
21914
|
await checkedRead(item.undo, createContext(undefined, device));
|
|
21894
21915
|
}
|
|
21895
|
-
const beforeTarget = (await import("./shared/cli-
|
|
21896
|
-
const db = await beforeTarget((await import("./shared/cli-
|
|
21916
|
+
const beforeTarget = (await import("./shared/cli-3kxktenb.js")).openSnapshotStore;
|
|
21917
|
+
const db = await beforeTarget((await import("./shared/cli-b7dr5556.js")).DEFAULT_SNAPSHOT_DB);
|
|
21897
21918
|
try {
|
|
21898
21919
|
const original = db.get(p.snapshots.target);
|
|
21899
21920
|
if (!original)
|
|
21900
21921
|
throw new Error("Original target snapshot unavailable.");
|
|
21901
|
-
const { normalizeExport } = await import("./shared/cli-
|
|
21922
|
+
const { normalizeExport } = await import("./shared/cli-rcgz8540.js");
|
|
21902
21923
|
if (normalizeExport((await migrationInventory(device)).export) !== normalizeExport(original.body))
|
|
21903
21924
|
throw new Error("Target differs from its backup. Undo verification failed.");
|
|
21904
21925
|
} finally {
|
|
@@ -34263,23 +34284,13 @@ async function applyWritesSafely(ctx, deviceName, commands, opts = {}) {
|
|
|
34263
34284
|
await mgr.rollback().catch(() => {
|
|
34264
34285
|
return;
|
|
34265
34286
|
});
|
|
34266
|
-
if (!fallback)
|
|
34267
|
-
return {
|
|
34268
|
-
applied,
|
|
34269
|
-
total,
|
|
34270
|
-
safeMode: `rolled back (a write failed: ${wedged})`,
|
|
34271
|
-
committed: false,
|
|
34272
|
-
error: wedged,
|
|
34273
|
-
fellBack: false
|
|
34274
|
-
};
|
|
34275
|
-
const r = await applyCommandsDirect(ctx, commands);
|
|
34276
34287
|
return {
|
|
34277
|
-
applied
|
|
34288
|
+
applied,
|
|
34278
34289
|
total,
|
|
34279
|
-
safeMode: `
|
|
34280
|
-
committed:
|
|
34281
|
-
error:
|
|
34282
|
-
fellBack:
|
|
34290
|
+
safeMode: `rollback requested, unverified (a write failed: ${wedged}); inspect the snapshot before retrying`,
|
|
34291
|
+
committed: false,
|
|
34292
|
+
error: wedged,
|
|
34293
|
+
fellBack: false
|
|
34283
34294
|
};
|
|
34284
34295
|
}
|
|
34285
34296
|
const c = await mgr.commit();
|
|
@@ -34658,7 +34669,7 @@ var cache3 = null;
|
|
|
34658
34669
|
async function gateway() {
|
|
34659
34670
|
if (cache3)
|
|
34660
34671
|
return cache3;
|
|
34661
|
-
const { moduleCatalog } = await import("./shared/cli-
|
|
34672
|
+
const { moduleCatalog } = await import("./shared/cli-dytg82ck.js");
|
|
34662
34673
|
const forIndex = [];
|
|
34663
34674
|
const byName = new Map;
|
|
34664
34675
|
for (const mod of moduleCatalog) {
|
|
@@ -57101,6 +57112,19 @@ ${details}`;
|
|
|
57101
57112
|
|
|
57102
57113
|
// src/tools/safe-mode.ts
|
|
57103
57114
|
var safeModeTools = [
|
|
57115
|
+
defineTool({
|
|
57116
|
+
name: "set_safe_mode_timeout",
|
|
57117
|
+
title: "Set Safe Mode Command Timeouts",
|
|
57118
|
+
annotations: WRITE,
|
|
57119
|
+
description: "Set per-device MCP Safe Mode command deadlines before or during a session. Applies only to subsequent commands. Increase for slow exports, decrease for faster failure detection. Does not change RouterOS rollback timing, MCP client deadlines, or unblock an uncertain session. Settings are in-memory and reset on MCP restart. Defaults: command 120000ms, idle 15000ms.",
|
|
57120
|
+
inputSchema: {
|
|
57121
|
+
commandTimeoutMs: number2().int().min(1000).max(600000).describe("Absolute command deadline in milliseconds."),
|
|
57122
|
+
idleTimeoutMs: number2().int().min(1000).max(600000).describe("Maximum silence in milliseconds; must not exceed commandTimeoutMs.")
|
|
57123
|
+
},
|
|
57124
|
+
handler(a, ctx) {
|
|
57125
|
+
return getSafeModeManager(resolveDeviceName(ctx.device)).setTimeouts(a.commandTimeoutMs, a.idleTimeoutMs);
|
|
57126
|
+
}
|
|
57127
|
+
}),
|
|
57104
57128
|
defineTool({
|
|
57105
57129
|
name: "safe_mode_status",
|
|
57106
57130
|
title: "Get Safe Mode Session Status",
|
|
@@ -57116,7 +57140,7 @@ var safeModeTools = [
|
|
|
57116
57140
|
name: "enable_safe_mode",
|
|
57117
57141
|
title: "Enable Safe Mode Session",
|
|
57118
57142
|
annotations: WRITE,
|
|
57119
|
-
description: "Opens a Safe Mode SSH session on the targeted device (RouterOS Ctrl+X equivalent) \u2014 all subsequent configuration changes are staged in memory and auto-reverted if the SSH connection drops before an explicit commit." + "
|
|
57143
|
+
description: "Opens a Safe Mode SSH session on the targeted device (RouterOS Ctrl+X equivalent) \u2014 all subsequent configuration changes are staged in memory and auto-reverted if the SSH connection drops before an explicit commit." + " Take a backup first: protection may be lost and disconnect is not proof of rollback. Use set_safe_mode_timeout to tune subsequent command deadlines." + " Safe Mode is SSH-only and is not supported over MAC-Telnet connections." + " Check current state first with safe_mode_status; persist staged changes with commit_safe_mode; discard staged changes without saving with rollback_safe_mode.",
|
|
57120
57144
|
async handler(_a, ctx) {
|
|
57121
57145
|
const device = resolveDeviceName(ctx.device);
|
|
57122
57146
|
ctx.info(`[${device}] Enabling MikroTik safe mode`);
|
|
@@ -57138,7 +57162,7 @@ var safeModeTools = [
|
|
|
57138
57162
|
name: "rollback_safe_mode",
|
|
57139
57163
|
title: "Roll Back Safe Mode Changes",
|
|
57140
57164
|
annotations: WRITE,
|
|
57141
|
-
description: "
|
|
57165
|
+
description: "Closes the targeted Safe Mode SSH session to request RouterOS automatic rollback. Completion is unverified and may be delayed; compare live configuration against a backup before retrying writes." + " Use this when staged changes are incorrect or need to be abandoned without saving." + " To persist staged changes instead, use commit_safe_mode." + " Check current Safe Mode state with safe_mode_status.",
|
|
57142
57166
|
async handler(_a, ctx) {
|
|
57143
57167
|
const device = resolveDeviceName(ctx.device);
|
|
57144
57168
|
ctx.info(`[${device}] Rolling back safe mode changes`);
|
|
@@ -59938,7 +59962,7 @@ var riskByTool = null;
|
|
|
59938
59962
|
async function riskIndex() {
|
|
59939
59963
|
if (riskByTool)
|
|
59940
59964
|
return riskByTool;
|
|
59941
|
-
const { moduleCatalog } = await import("./shared/cli-
|
|
59965
|
+
const { moduleCatalog } = await import("./shared/cli-dytg82ck.js");
|
|
59942
59966
|
const index = new Map;
|
|
59943
59967
|
for (const mod of moduleCatalog) {
|
|
59944
59968
|
for (const tool of mod.tools)
|
|
@@ -71822,8 +71846,32 @@ async function saveUmReportCache(path, snapshot) {
|
|
|
71822
71846
|
|
|
71823
71847
|
// src/observability/um-last-connections.ts
|
|
71824
71848
|
var CACHE_MS = 30000;
|
|
71825
|
-
var
|
|
71826
|
-
var
|
|
71849
|
+
var RESCAN_MS = 15 * 60000;
|
|
71850
|
+
var COLLECTION_MS = 180000;
|
|
71851
|
+
var FIELDS3 = { sessions: [".id", "user", "started"] };
|
|
71852
|
+
var SESSION_IDS = ":put [:serialize to=json value=[/user-manager session find] options=json.no-string-conversion]";
|
|
71853
|
+
function sessionRows(rows) {
|
|
71854
|
+
if (!Array.isArray(rows))
|
|
71855
|
+
throw new Error("Invalid session page");
|
|
71856
|
+
const result = new Map;
|
|
71857
|
+
for (const row of rows) {
|
|
71858
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
71859
|
+
throw new Error("Invalid session row");
|
|
71860
|
+
const { ".id": id, user, started } = row;
|
|
71861
|
+
if (typeof id !== "string" || !/^\*[0-9a-f]+$/i.test(id) || typeof user !== "string" || result.has(id))
|
|
71862
|
+
throw new Error("Invalid session identity");
|
|
71863
|
+
result.set(id, { user, started: umConnectionDate(started) });
|
|
71864
|
+
}
|
|
71865
|
+
return result;
|
|
71866
|
+
}
|
|
71867
|
+
function latestDates(sessions) {
|
|
71868
|
+
const values = new Map;
|
|
71869
|
+
for (const { user, started } of sessions.values()) {
|
|
71870
|
+
if (user && started && started > (values.get(user) ?? ""))
|
|
71871
|
+
values.set(user, started);
|
|
71872
|
+
}
|
|
71873
|
+
return values;
|
|
71874
|
+
}
|
|
71827
71875
|
function umConnectionDate(value) {
|
|
71828
71876
|
if (typeof value !== "string")
|
|
71829
71877
|
return null;
|
|
@@ -71855,30 +71903,78 @@ function getUmLastConnections(device) {
|
|
|
71855
71903
|
const config = getConfig();
|
|
71856
71904
|
let entry = cache7.get(device);
|
|
71857
71905
|
if (!entry || entry.config !== config) {
|
|
71858
|
-
entry = {
|
|
71906
|
+
entry = {
|
|
71907
|
+
config,
|
|
71908
|
+
values: new Map,
|
|
71909
|
+
sessions: new Map,
|
|
71910
|
+
scannedAt: 0,
|
|
71911
|
+
restored: false,
|
|
71912
|
+
retryAt: 0,
|
|
71913
|
+
failed: false
|
|
71914
|
+
};
|
|
71859
71915
|
cache7.set(device, entry);
|
|
71860
71916
|
}
|
|
71861
71917
|
const target = entry;
|
|
71862
71918
|
if (!target.pending && Date.now() >= target.retryAt) {
|
|
71863
71919
|
target.pending = (async () => {
|
|
71864
|
-
|
|
71865
|
-
|
|
71866
|
-
|
|
71867
|
-
|
|
71868
|
-
|
|
71869
|
-
|
|
71870
|
-
|
|
71871
|
-
|
|
71872
|
-
|
|
71873
|
-
|
|
71874
|
-
|
|
71875
|
-
|
|
71876
|
-
|
|
71920
|
+
if (!target.restored) {
|
|
71921
|
+
target.restored = true;
|
|
71922
|
+
const snapshot = await loadUmReportCache(umReportCachePath(device), device, FIELDS3);
|
|
71923
|
+
if (getConfig() !== config)
|
|
71924
|
+
return;
|
|
71925
|
+
if (snapshot?.sources.sessions.available) {
|
|
71926
|
+
try {
|
|
71927
|
+
target.sessions = sessionRows(snapshot.sources.sessions.rows);
|
|
71928
|
+
target.values = latestDates(target.sessions);
|
|
71929
|
+
target.collectedAt = snapshot.collectedAt;
|
|
71930
|
+
target.scannedAt = snapshot.collectedAt;
|
|
71931
|
+
} catch {}
|
|
71932
|
+
}
|
|
71933
|
+
}
|
|
71934
|
+
const deadline = Date.now() + COLLECTION_MS;
|
|
71935
|
+
const ctx = createContext(undefined, device);
|
|
71936
|
+
const run = async (command) => {
|
|
71937
|
+
if (getConfig() !== config)
|
|
71938
|
+
throw new Error("Configuration changed");
|
|
71939
|
+
const remaining = deadline - Date.now();
|
|
71940
|
+
if (remaining <= 0)
|
|
71941
|
+
throw new Error("Last connection read deadline exceeded");
|
|
71942
|
+
const raw = await executeMikrotikCommand(command, ctx, {
|
|
71943
|
+
maxMs: Math.min(60000, remaining)
|
|
71944
|
+
});
|
|
71945
|
+
if (looksLikeError(raw) || raw.length > 2 * 1024 * 1024)
|
|
71946
|
+
throw new Error("Invalid last connection response");
|
|
71947
|
+
return raw;
|
|
71948
|
+
};
|
|
71949
|
+
const ids = JSON.parse(await run(SESSION_IDS));
|
|
71950
|
+
if (!Array.isArray(ids) || ids.length > 1e5 || !ids.every((id) => typeof id === "string" && /^\*[0-9a-f]+$/i.test(id)) || new Set(ids).size !== ids.length)
|
|
71951
|
+
throw new Error("Invalid session identities");
|
|
71952
|
+
const full = !target.scannedAt || Date.now() - target.scannedAt >= RESCAN_MS;
|
|
71953
|
+
const sessions = new Map;
|
|
71954
|
+
const missing = [];
|
|
71955
|
+
for (const id of ids) {
|
|
71956
|
+
const known = full ? undefined : target.sessions.get(id);
|
|
71957
|
+
if (known?.started)
|
|
71958
|
+
sessions.set(id, known);
|
|
71959
|
+
else
|
|
71960
|
+
missing.push(id);
|
|
71961
|
+
}
|
|
71962
|
+
for (let offset = 0;offset < missing.length; offset += 2000) {
|
|
71963
|
+
const batch = missing.slice(offset, offset + 2000);
|
|
71964
|
+
const query = new Cmd("/user-manager session print").raw("as-value").set("from", batch.join(",")).build();
|
|
71965
|
+
const page = sessionRows(JSON.parse(await run(`:put [:serialize to=json value=[${query}] options=json.no-string-conversion]`)));
|
|
71966
|
+
if (page.size !== batch.length || !batch.every((id) => page.has(id)))
|
|
71967
|
+
throw new Error("Incomplete session page");
|
|
71968
|
+
for (const [id, session] of page)
|
|
71969
|
+
sessions.set(id, session);
|
|
71877
71970
|
}
|
|
71878
71971
|
if (getConfig() !== config)
|
|
71879
71972
|
return;
|
|
71880
|
-
target.
|
|
71973
|
+
target.sessions = sessions;
|
|
71974
|
+
target.values = latestDates(sessions);
|
|
71881
71975
|
target.collectedAt = Date.now();
|
|
71976
|
+
if (full)
|
|
71977
|
+
target.scannedAt = target.collectedAt;
|
|
71882
71978
|
target.failed = false;
|
|
71883
71979
|
})().catch(() => {
|
|
71884
71980
|
target.failed = true;
|
|
@@ -71898,7 +71994,7 @@ function getUmLastConnections(device) {
|
|
|
71898
71994
|
var DAY = 86400000;
|
|
71899
71995
|
var CACHE_MS2 = 60000;
|
|
71900
71996
|
var RETRY_MS = 30000;
|
|
71901
|
-
var
|
|
71997
|
+
var COLLECTION_MS2 = 180000;
|
|
71902
71998
|
var count = (v) => Math.max(0, Number(v) || 0);
|
|
71903
71999
|
var size = (v) => Math.max(0, parseSize(v) ?? 0);
|
|
71904
72000
|
var UM_REPORT_FIELDS = {
|
|
@@ -72004,7 +72100,7 @@ var menus = {
|
|
|
72004
72100
|
routers: "router",
|
|
72005
72101
|
groups: "user group"
|
|
72006
72102
|
};
|
|
72007
|
-
async function readSource(ctx, source, deadline = Date.now() +
|
|
72103
|
+
async function readSource(ctx, source, deadline = Date.now() + COLLECTION_MS2, progress) {
|
|
72008
72104
|
let receivedBytes = 0;
|
|
72009
72105
|
const run = (command) => {
|
|
72010
72106
|
const remaining = deadline - Date.now();
|
|
@@ -72062,7 +72158,7 @@ async function readSource(ctx, source, deadline = Date.now() + COLLECTION_MS, pr
|
|
|
72062
72158
|
}
|
|
72063
72159
|
async function collect(device, progress) {
|
|
72064
72160
|
const start = Date.now();
|
|
72065
|
-
const deadline = start +
|
|
72161
|
+
const deadline = start + COLLECTION_MS2;
|
|
72066
72162
|
const config = getConfig();
|
|
72067
72163
|
const ctx = createContext(undefined, device);
|
|
72068
72164
|
const sources = Object.fromEntries(Object.keys(UM_REPORT_FIELDS).map((key) => [key, { available: false, rows: [] }]));
|
package/dist/index.d.ts
CHANGED
|
@@ -359,8 +359,8 @@ declare class SafeModeManager {
|
|
|
359
359
|
private active;
|
|
360
360
|
/**
|
|
361
361
|
* Set when the persistent shell drops WHILE Safe Mode was active — i.e. the
|
|
362
|
-
* session died before an explicit commit,
|
|
363
|
-
*
|
|
362
|
+
* session died before an explicit commit, with an unverified outcome.
|
|
363
|
+
* Distinguishes "never enabled / cleanly closed" from
|
|
364
364
|
* "died with your changes still pending" so commit/status can report the revert
|
|
365
365
|
* instead of a reassuring false success. Cleared on the next enable().
|
|
366
366
|
*/
|
|
@@ -371,9 +371,14 @@ declare class SafeModeManager {
|
|
|
371
371
|
private probeSequence;
|
|
372
372
|
/** Serializes channel access so concurrent tool calls don't interleave I/O. */
|
|
373
373
|
private queue;
|
|
374
|
+
private commandTimeoutMs;
|
|
375
|
+
private idleTimeoutMs;
|
|
376
|
+
/** Applies to subsequent commands, never extends an already-running command. */
|
|
377
|
+
setTimeouts(commandTimeoutMs: number, idleTimeoutMs: number): string;
|
|
374
378
|
/** The device this Safe Mode session belongs to (a configured device name). */
|
|
375
379
|
constructor(deviceName: string);
|
|
376
380
|
get isActive(): boolean;
|
|
381
|
+
get requiresRecovery(): boolean;
|
|
377
382
|
/** Run `fn` exclusively — the persistent channel must not be shared mid-command. */
|
|
378
383
|
private lock;
|
|
379
384
|
/** Open a persistent SSH shell and activate MikroTik Safe Mode. */
|
|
@@ -400,7 +405,7 @@ declare class SafeModeManager {
|
|
|
400
405
|
* Fired by the persistent shell's `close`/`error` events. Arrow-bound so the
|
|
401
406
|
* same reference is used for add/removeListener. Acts ONLY when we still think
|
|
402
407
|
* Safe Mode is active — a drop then means the session died with staged changes
|
|
403
|
-
* pending
|
|
408
|
+
* pending and an unverified rollback, so we flag it and tear the zombie
|
|
404
409
|
* handles down. A close during our own cleanup() (which clears `active` first)
|
|
405
410
|
* is a no-op: it is an intentional teardown, not a lost session.
|
|
406
411
|
*/
|
package/dist/index.js
CHANGED
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
updateSummaryLine,
|
|
71
71
|
allToolModules2,
|
|
72
72
|
selectToolModules2
|
|
73
|
-
} from "./shared/library-
|
|
73
|
+
} from "./shared/library-ttgvk8a6.js";
|
|
74
74
|
|
|
75
75
|
// node_modules/ajv/dist/compile/codegen/code.js
|
|
76
76
|
var require_code = __commonJS(function(exports) {
|