@bom0792/herdgate 0.9.21 → 0.9.26
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 +67 -3
- package/bin/herdgate.mjs +11 -3
- package/bin/home-tui.mjs +121 -0
- package/package.json +3 -1
- package/plugin/server/index.mjs +7 -0
- package/plugin/server/mobile-tui-core.mjs +321 -0
- package/plugin/server/mobile-tui-stream.mjs +61 -0
- package/plugin/server/publish-tui.mjs +29 -5
- package/plugin/server/ssh.d.mts +3 -0
- package/plugin/server/ssh.mjs +50 -7
- package/src/cloud/gateway.ts +35 -45
- package/src/cloud/ssh-tcp-edge.ts +119 -0
- package/src/cloud/sshd.ts +9 -5
- package/src/host/mobile-tui-core.mjs +3 -0
- package/src/host/mobile-tui.ts +72 -0
- package/src/web/app.css +2 -0
- package/src/web/app.js +365 -183
- package/src/web/index.html +1 -0
- package/src/web/sw.js +1 -1
- package/templates/herdgate-tcp-edge.service +20 -0
- package/windows/cli.mjs +6 -4
- package/windows/install-cli.mjs +12 -4
- package/windows/setup-tui.mjs +110 -0
package/src/web/index.html
CHANGED
package/src/web/sw.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Bump VERSION when a shell file changes; old caches are dropped on activate.
|
|
5
5
|
|
|
6
|
-
const VERSION = "herdgate-
|
|
6
|
+
const VERSION = "herdgate-v16";
|
|
7
7
|
const SHELL = ["/", "/app.css", "/e2e.js", "/app.js", "/app.webmanifest", "/icons/icon.svg"];
|
|
8
8
|
|
|
9
9
|
self.addEventListener("install", (event) => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Herdgate public SSH TCP edge
|
|
3
|
+
After=network.target
|
|
4
|
+
|
|
5
|
+
[Service]
|
|
6
|
+
Type=simple
|
|
7
|
+
DynamicUser=yes
|
|
8
|
+
WorkingDirectory=/opt/herdgate-tcp-edge
|
|
9
|
+
EnvironmentFile=/etc/herdgate-tcp-edge.env
|
|
10
|
+
ExecStart=/usr/bin/node /opt/herdgate-tcp-edge/ssh-tcp-edge.mjs
|
|
11
|
+
Restart=on-failure
|
|
12
|
+
RestartSec=2s
|
|
13
|
+
NoNewPrivileges=yes
|
|
14
|
+
PrivateTmp=yes
|
|
15
|
+
ProtectHome=yes
|
|
16
|
+
ProtectSystem=strict
|
|
17
|
+
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
|
|
18
|
+
|
|
19
|
+
[Install]
|
|
20
|
+
WantedBy=multi-user.target
|
package/windows/cli.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
const release = realpathSync(fileURLToPath(new URL("../", import.meta.url)));
|
|
7
7
|
const releases = dirname(release);
|
|
8
8
|
const root = dirname(releases);
|
|
9
|
-
const usage = `herdgate-tui start [path-to-herdr.exe]
|
|
9
|
+
const usage = `herdgate-tui start [path-to-herdr.exe] [--hc path-to-herdr-core.exe | --mobile-tui d_read | --mobile-tui-act d_act]
|
|
10
10
|
herdgate-tui status | stop | version | versions
|
|
11
11
|
herdgate-tui use <release-id>`;
|
|
12
12
|
|
|
@@ -32,11 +32,13 @@ try {
|
|
|
32
32
|
run("windows/install-cli.mjs", ["--root", root, "--use", args[0]]);
|
|
33
33
|
} else if ((cmd === "status" || cmd === "stop") && !args.length) {
|
|
34
34
|
run("plugin/server/publish-tui.mjs", [cmd]);
|
|
35
|
-
} else if (cmd === "start"
|
|
35
|
+
} else if (cmd === "start" || cmd === "check") {
|
|
36
|
+
const requested = args[0] && !args[0].startsWith("--") ? args.shift() : null;
|
|
37
|
+
if (args.length && (args.length !== 2 || !["--hc", "--mobile-tui", "--mobile-tui-act"].includes(args[0]) || !args[1])) throw new Error(usage);
|
|
36
38
|
const pilot = process.env.LOCALAPPDATA && join(process.env.LOCALAPPDATA, "HerdrPilot", "v0.9.5", "herdr.exe");
|
|
37
|
-
const bin =
|
|
39
|
+
const bin = requested || process.env.HERDGATE_HERDR_BIN || (pilot && existsSync(pilot) ? pilot : null);
|
|
38
40
|
if (!bin) throw new Error("give the full path to Herdr 0.9.5: herdgate-tui start <path-to-herdr.exe>");
|
|
39
|
-
run("plugin/server/publish-tui.mjs", [cmd, bin]);
|
|
41
|
+
run("plugin/server/publish-tui.mjs", [cmd, bin, ...args]);
|
|
40
42
|
} else {
|
|
41
43
|
throw new Error(usage);
|
|
42
44
|
}
|
package/windows/install-cli.mjs
CHANGED
|
@@ -99,17 +99,21 @@ function installShim(root) {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
try {
|
|
102
|
+
if (process.platform === "win32" && typeof globalThis.WebSocket !== "function") throw new Error("run this installer with Node 22+ with WebSocket enabled");
|
|
102
103
|
const args = process.argv.slice(2);
|
|
103
104
|
let root = process.platform === "win32" && process.env.LOCALAPPDATA ? join(process.env.LOCALAPPDATA, "Herdgate", "cli") : null;
|
|
104
105
|
let use = null;
|
|
106
|
+
let stage = false;
|
|
105
107
|
while (args.length) {
|
|
106
108
|
const flag = args.shift();
|
|
109
|
+
if (flag === "--stage") { stage = true; continue; }
|
|
107
110
|
const value = args.shift();
|
|
108
111
|
if (flag === "--root" && value) root = resolve(value);
|
|
109
112
|
else if (flag === "--use" && value) use = value;
|
|
110
|
-
else throw new Error("usage: node windows/install-cli.mjs [--root <dir>] [--use <release-id>]");
|
|
113
|
+
else throw new Error("usage: node windows/install-cli.mjs [--root <dir>] [--stage | --use <release-id>]");
|
|
111
114
|
}
|
|
112
115
|
if (!root) throw new Error("this installer defaults to %LOCALAPPDATA% on Windows");
|
|
116
|
+
if (stage && use) throw new Error("--stage and --use cannot be combined");
|
|
113
117
|
directory(root);
|
|
114
118
|
const releases = join(root, "releases");
|
|
115
119
|
directory(releases);
|
|
@@ -117,9 +121,13 @@ try {
|
|
|
117
121
|
mkdirSync(lock);
|
|
118
122
|
try {
|
|
119
123
|
const id = use ?? installRelease(releases);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
if (stage) {
|
|
125
|
+
console.log(id);
|
|
126
|
+
} else {
|
|
127
|
+
selectRelease(root, releases, id);
|
|
128
|
+
installShim(root);
|
|
129
|
+
console.log(`Herdgate TUI CLI: ${id}\nShim: ${join(root, "bin", "herdgate-tui.cmd")}`);
|
|
130
|
+
}
|
|
123
131
|
} finally {
|
|
124
132
|
rmSync(lock, { force: true, recursive: true });
|
|
125
133
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// npm entry point: stage a release before stopping the existing publisher.
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
|
|
9
|
+
const installer = fileURLToPath(new URL("./install-cli.mjs", import.meta.url));
|
|
10
|
+
const releaseId = /^tui-[a-f0-9]{16}$/;
|
|
11
|
+
const normalize = (path) => process.platform === "win32" ? path.toLowerCase() : path;
|
|
12
|
+
const errorText = (e) => e instanceof Error ? e.message : String(e);
|
|
13
|
+
function invoke(file, args) {
|
|
14
|
+
const child = spawnSync(process.execPath, [file, ...args], { encoding: "utf8", shell: false, windowsHide: true, timeout: 30_000 });
|
|
15
|
+
if (child.error) throw child.error;
|
|
16
|
+
if (child.status !== 0) throw new Error(child.stderr.trim() || `${args[0]} failed (${child.status})`);
|
|
17
|
+
return child.stdout.trim();
|
|
18
|
+
}
|
|
19
|
+
function storedProfile(path) {
|
|
20
|
+
if (!existsSync(path)) return null;
|
|
21
|
+
const { args } = JSON.parse(readFileSync(path, "utf8"));
|
|
22
|
+
if (!Array.isArray(args) || args.length > 3 || args.some((v) => typeof v !== "string")) throw new Error("invalid TUI profile; inspect the saved profile before updating");
|
|
23
|
+
return args;
|
|
24
|
+
}
|
|
25
|
+
function writeProfile(path, args) {
|
|
26
|
+
const tmp = `${path}.${randomUUID()}`;
|
|
27
|
+
try {
|
|
28
|
+
writeFileSync(tmp, JSON.stringify({ args }) + "\n", { flag: "wx", mode: 0o600 });
|
|
29
|
+
renameSync(tmp, path);
|
|
30
|
+
} finally { rmSync(tmp, { force: true }); }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function setup() {
|
|
34
|
+
const [cmd, ...requested] = process.argv.slice(2);
|
|
35
|
+
if (cmd === "update" && requested.length) throw new Error("use tui setup to change publisher options");
|
|
36
|
+
if (!["setup", "update"].includes(cmd)) throw new Error("expected tui setup or tui update");
|
|
37
|
+
if (!process.env.LOCALAPPDATA) throw new Error("%LOCALAPPDATA% is required for this installer");
|
|
38
|
+
const root = join(process.env.LOCALAPPDATA, "Herdgate", "cli");
|
|
39
|
+
mkdirSync(root, { recursive: true });
|
|
40
|
+
const lock = join(root, ".setup");
|
|
41
|
+
mkdirSync(lock);
|
|
42
|
+
try {
|
|
43
|
+
const link = join(root, "current");
|
|
44
|
+
const releases = join(root, "releases");
|
|
45
|
+
const profilePath = join(root, "publisher-profile.json");
|
|
46
|
+
const profile = storedProfile(profilePath);
|
|
47
|
+
if (cmd === "update" && !profile) throw new Error("no saved publisher mode; run tui setup with your current options once");
|
|
48
|
+
// 'setup' without arguments on an already configured machine keeps its mode.
|
|
49
|
+
const args = requested.length ? requested : profile ?? [];
|
|
50
|
+
let prior;
|
|
51
|
+
if (existsSync(link)) {
|
|
52
|
+
const target = realpathSync(link);
|
|
53
|
+
prior = basename(target);
|
|
54
|
+
if (!releaseId.test(prior) || normalize(dirname(target)) !== normalize(realpathSync(releases))) {
|
|
55
|
+
throw new Error("current does not point to an installed release");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const install = (...options) => invoke(installer, ["--root", root, ...options]);
|
|
59
|
+
const cli = (id, ...options) => invoke(join(releases, id, "windows", "cli.mjs"), options);
|
|
60
|
+
const status = (id) => JSON.parse(cli(id, "status"));
|
|
61
|
+
const stop = (id) => {
|
|
62
|
+
if (JSON.parse(cli(id, "stop")).state !== "stopped") throw new Error("publisher did not stop; no Herdr processes were signalled");
|
|
63
|
+
};
|
|
64
|
+
const start = async (id, options) => {
|
|
65
|
+
cli(id, "start", ...options);
|
|
66
|
+
const deadline = Date.now() + 10_000;
|
|
67
|
+
let result;
|
|
68
|
+
do {
|
|
69
|
+
result = status(id);
|
|
70
|
+
if (result.state === "connected") return result;
|
|
71
|
+
if (result.state === "stopped" || result.state === "stale") break;
|
|
72
|
+
await delay(300);
|
|
73
|
+
} while (Date.now() < deadline);
|
|
74
|
+
throw new Error(`publisher did not connect (${result.state})${result.log ? `; see ${result.log}` : ""}`);
|
|
75
|
+
};
|
|
76
|
+
const next = install("--stage");
|
|
77
|
+
if (!releaseId.test(next)) throw new Error("installer did not return a release ID");
|
|
78
|
+
cli(next, "check", ...args); // validate executable, pairing and Herdr before disrupting the old worker
|
|
79
|
+
const oldStatus = status(prior ?? next);
|
|
80
|
+
const running = !["stopped", "stale"].includes(oldStatus.state);
|
|
81
|
+
if (prior === next && profile && JSON.stringify(args) === JSON.stringify(profile) && oldStatus.state === "connected") {
|
|
82
|
+
install("--use", next); // refresh pinned Node shim, no worker restart
|
|
83
|
+
console.log(JSON.stringify({ release: next, ...oldStatus }));
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (oldStatus.state !== "stopped") stop(prior ?? next);
|
|
87
|
+
let triedStart = false;
|
|
88
|
+
try {
|
|
89
|
+
install("--use", next);
|
|
90
|
+
triedStart = true;
|
|
91
|
+
const result = await start(next, args);
|
|
92
|
+
writeProfile(profilePath, args);
|
|
93
|
+
console.log(JSON.stringify({ release: next, ...result }));
|
|
94
|
+
} catch (cause) {
|
|
95
|
+
try {
|
|
96
|
+
if (triedStart && status(next).state !== "stopped") stop(next);
|
|
97
|
+
if (prior) {
|
|
98
|
+
install("--use", prior);
|
|
99
|
+
if (running) await start(prior, profile ?? args);
|
|
100
|
+
}
|
|
101
|
+
} catch (recovery) {
|
|
102
|
+
throw new Error(`${errorText(cause)}; could not restore the old publisher: ${errorText(recovery)}`);
|
|
103
|
+
}
|
|
104
|
+
throw new Error(`${errorText(cause)}${prior ? "; previous release restored" : ""}`);
|
|
105
|
+
}
|
|
106
|
+
} finally { rmSync(lock, { force: true, recursive: true }); }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try { await setup(); }
|
|
110
|
+
catch (e) { console.error(`herdgate tui: ${errorText(e)}`); process.exitCode = 1; }
|