pi-web-ui 0.114.0 → 0.114.1
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/CHANGELOG.md +28 -0
- package/README.md +187 -187
- package/README.zh-CN.md +227 -227
- package/README.zh-TW.md +227 -227
- package/bin/device-hub-cli.mjs +577 -577
- package/bin/frp-manager.mjs +1573 -1573
- package/bin/pi-device-hub.mjs +9 -9
- package/bin/pi-web-ui.mjs +4081 -4073
- package/deploy/nginx-subpath.conf +100 -100
- package/deploy/pi-web-ui.service +36 -36
- package/dist/server/agent-service.js +131 -55
- package/dist/server/attachments.js +51 -5
- package/dist/server/canvas/canvas-agent-tool.js +3 -3
- package/dist/server/canvas/canvas-cards.js +1 -1
- package/dist/server/canvas/canvas-orchestrator.js +3 -3
- package/dist/server/canvas/canvas-scheduled-task.js +45 -0
- package/dist/server/canvas/canvas-validation.js +1 -1
- package/dist/server/client-state.js +6 -2
- package/dist/server/compaction-instructions.js +8 -8
- package/dist/server/device-center/connector.js +33 -14
- package/dist/server/device-center/desktop-page.js +228 -228
- package/dist/server/device-center/hub-page.js +64 -64
- package/dist/server/device-center/hub.js +2 -1
- package/dist/server/device-center/local-hub.js +92 -0
- package/dist/server/device-center/local.js +60 -7
- package/dist/server/device-center/native-desktop/macos.js +190 -190
- package/dist/server/device-center/native-desktop/windows.js +116 -116
- package/dist/server/device-center/path-portal.js +1 -1
- package/dist/server/device-center/relay.js +45 -8
- package/dist/server/dispatch-domain-handlers.js +1 -0
- package/dist/server/dsh/dsh-agent-service.js +5 -1
- package/dist/server/dsh/runtime/cordis.yml +1 -1
- package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
- package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
- package/dist/server/dsh/runtime/launcher.mjs +235 -235
- package/dist/server/dsh/runtime/override.patch.yml +89 -89
- package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
- package/dist/server/engine-probe.js +36 -6
- package/dist/server/eval-tool.js +135 -135
- package/dist/server/global-loader.js +40 -2
- package/dist/server/index.js +56 -32
- package/dist/server/patch-bash-process.js +125 -0
- package/dist/server/patch-tool.js +9 -9
- package/dist/server/patch-turn-end-boundary.js +3 -3
- package/dist/server/persona-chain.js +8 -8
- package/dist/server/plugins.js +26 -2
- package/dist/server/preset-fields.js +7 -0
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-templates.js +106 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/remote-ssh-service.js +39 -39
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/schedule-agent-tool.js +39 -21
- package/dist/server/scheduler-tasks.js +45 -9
- package/dist/server/scm-commitmsg.js +10 -10
- package/dist/server/settings-service.js +6 -0
- package/dist/server/setup-page.js +620 -620
- package/dist/server/text-quote.js +9 -0
- package/dist/server/tool-manager.js +2 -1
- package/dist/server/universal/drivers/claude-code.js +5 -0
- package/dist/server/universal/drivers/codex.js +336 -0
- package/dist/server/universal/index.js +1 -0
- package/dist/server/universal/universal-attachments.js +24 -1
- package/dist/server/universal/universal-session.js +23 -0
- package/dist/server/vision-bridge.js +18 -18
- package/docs/device-center.md +148 -142
- package/docs/device-desktop.md +48 -48
- package/docs/dsh-engine.md +493 -493
- package/extensions/webui.ts +335 -335
- package/package.json +2 -2
- package/plugin-sdk/README.md +174 -174
- package/plugin-sdk/client-utils.mjs +279 -279
- package/plugin-sdk/import-check.mjs +210 -210
- package/plugin-sdk/index.d.ts +698 -698
- package/plugin-sdk/index.mjs +696 -696
- package/plugin-sdk/package.json +13 -13
- package/plugin-sdk/ssh-host-trust.mjs +225 -225
- package/plugins/catalog.json +10 -0
- package/themes/aetheris.css +501 -501
- package/themes/ayu-light.css +116 -116
- package/themes/bases/flow-base.css +1357 -1357
- package/themes/bases/obsidian-base.css +895 -895
- package/themes/bases/statusbar-flat-base.css +112 -112
- package/themes/bases/zhujian-base.css +688 -688
- package/themes/bases/zhupi-base.css +660 -660
- package/themes/catppuccin-latte.css +119 -119
- package/themes/catppuccin.css +116 -116
- package/themes/claude-code-dark.css +147 -147
- package/themes/codex.css +114 -114
- package/themes/cyberpunk.css +50 -50
- package/themes/dark-teal.css +264 -264
- package/themes/dazzle.css +38 -38
- package/themes/everforest-light.css +115 -115
- package/themes/flow-light.css +164 -164
- package/themes/flow.css +161 -161
- package/themes/geist.css +114 -114
- package/themes/gruvbox-light.css +115 -115
- package/themes/kanagawa-lotus.css +115 -115
- package/themes/md-preview.css +24 -24
- package/themes/mist.css +166 -166
- package/themes/nord.css +107 -107
- package/themes/one-dark.css +106 -106
- package/themes/paper.css +174 -174
- package/themes/rose-pine-dawn.css +114 -114
- package/themes/sakura.css +166 -166
- package/themes/solarized-light.css +114 -114
- package/themes/tokyo-night.css +115 -115
- package/themes/translucent.css +85 -85
- package/themes/transparent.css +116 -116
- package/themes/vs-code-dark.css +147 -147
- package/themes/wallpaper-flow.css +382 -382
- package/themes/wallpaper-obsidian.css +74 -74
- package/themes/white.css +164 -164
- package/themes/zhujian-dark.css +115 -115
- package/themes/zhujian.css +114 -114
- package/themes/zhupi-dark.css +115 -115
- package/themes/zhupi.css +114 -114
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BcXJ20RO.js +1 -0
- package/web/dist/assets/BgTasksModal-DjQmiKnE.js +1 -0
- package/web/dist/assets/{CanvasStudio-BEJZE5BI.js → CanvasStudio-PI9pid0Y.js} +3 -3
- package/web/dist/assets/{CanvasStudio-CgUNHqos.js → CanvasStudio-nf5-HxLM.js} +3 -3
- package/web/dist/assets/DeviceCenter-CYttJw2a.js +3 -0
- package/web/dist/assets/DeviceCenter-DPe4sz74.js +3 -0
- package/web/dist/assets/DeviceGroups-D2rogxEN.js +1 -0
- package/web/dist/assets/Dropdown-ZLS04O8p.js +1 -0
- package/web/dist/assets/FilePreview-C9Ut4Lq6.js +2 -0
- package/web/dist/assets/FilePreview-CvK3ZzX5.js +2 -0
- package/web/dist/assets/GlobalSearchModal-C5e-OCw2.js +1 -0
- package/web/dist/assets/GlobalSearchModal-H7pFK2UC.js +1 -0
- package/web/dist/assets/GroupConversation-C2wNM0dQ.js +1 -0
- package/web/dist/assets/GroupConversation-ChN3TWQK.js +1 -0
- package/web/dist/assets/ModelConfigModal-DDZccDYt.js +2 -0
- package/web/dist/assets/PiSetupModal-DHbqfx8T.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +1 -0
- package/web/dist/assets/SCMPanel-buTGziDB.js +2 -0
- package/web/dist/assets/SCMPanel-kx-SCL2s.js +2 -0
- package/web/dist/assets/SettingsModal-BsUF8jqr.js +20 -0
- package/web/dist/assets/SettingsModal-D357Ky7P.js +20 -0
- package/web/dist/assets/{TerminalPanel-DL20uKgU.js → TerminalPanel-BBuM_Sez.js} +2 -2
- package/web/dist/assets/{TerminalPanel-D6cPRFei.js → TerminalPanel-D6x6xz8Q.js} +2 -2
- package/web/dist/assets/TuiOverlayModal-CdbGV3Za.js +1 -0
- package/web/dist/assets/TuiOverlayModal-d6x9u25n.js +1 -0
- package/web/dist/assets/app-globals-DcyO0UPi.js +1 -0
- package/web/dist/assets/{desktop-DPyTy4M3.js → desktop-YguLbrX1.js} +1 -1
- package/web/dist/assets/fi-DaSO0Q-m.js +325 -0
- package/web/dist/assets/index-BPvpea8t.js +85 -0
- package/web/dist/assets/index-D6u8xH0o.js +85 -0
- package/web/dist/assets/index-DDZMv6LO.css +1 -0
- package/web/dist/assets/{plugin-host-CqA4yW6w.js → plugin-host-BRBg6zmQ.js} +1 -1
- package/web/dist/assets/theme-DDl-Oy1b.js +1 -0
- package/web/dist/index.html +37 -36
- package/web/dist/sw.js +179 -179
- package/web/public/sw.js +179 -179
- package/dist/gh-comment-781.md +0 -5
- package/dist/server/device-center/local-page.js +0 -17
- package/dist/server/device-center/smoke-preview.js +0 -3
- package/dist/server/durable/durable-capabilities.js +0 -11
- package/dist/server/markers/builtins/services.js +0 -123
- package/dist/server/markers/builtins/todo.js +0 -189
- package/dist/server/markers-list-tool.js +0 -34
- package/dist/server/orchestrator.js +0 -109
- package/dist/server/system-prompt-soul.js +0 -41
- package/dist/server/univer-service.js +0 -448
- package/dist/server/universal/drivers/dsh-driver.js +0 -379
- package/dist/test-artifact.md +0 -9
- package/dist/test-preview-modal.md +0 -11
- package/dist/test-report.html +0 -20
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +0 -1
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +0 -1
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +0 -3
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +0 -3
- package/web/dist/assets/Dropdown-Oug0DDte.js +0 -1
- package/web/dist/assets/FilePreview-CvdX6nr6.js +0 -2
- package/web/dist/assets/FilePreview-kCZhfBAF.js +0 -2
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +0 -1
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +0 -1
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +0 -1
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +0 -1
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +0 -2
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +0 -1
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +0 -2
- package/web/dist/assets/SCMPanel-BscPm9kf.js +0 -2
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +0 -20
- package/web/dist/assets/SettingsModal-VynB7jNb.js +0 -20
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +0 -1
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +0 -1
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +0 -1
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +0 -1
- package/web/dist/assets/app-globals-CnO6KlEM.js +0 -325
- package/web/dist/assets/index-CPgAH5q7.js +0 -83
- package/web/dist/assets/index-Cje8iugL.js +0 -83
- package/web/dist/assets/index-DnKeiDbj.css +0 -1
- package/web/dist/assets/theme-BqdAjEjF.js +0 -1
package/plugin-sdk/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-web-ui/plugin-sdk",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"private": true,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"description": "Starter helpers + types for pi-web-ui plugins (copy this dir into your plugin, or vendor index.mjs/index.d.ts).",
|
|
7
|
-
"main": "index.mjs",
|
|
8
|
-
"types": "index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": "./index.mjs",
|
|
11
|
-
"./client": "./client-utils.mjs"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-web-ui/plugin-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Starter helpers + types for pi-web-ui plugins (copy this dir into your plugin, or vendor index.mjs/index.d.ts).",
|
|
7
|
+
"main": "index.mjs",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.mjs",
|
|
11
|
+
"./client": "./client-utils.mjs"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
/** Shared, fail-closed OpenSSH verification and explicit, fingerprint-confirmed trust persistence. */
|
|
2
|
-
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
3
|
-
import { chmod, lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
|
|
7
|
-
function equal(a, b) {
|
|
8
|
-
return a.length === b.length && timingSafeEqual(a, b);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function matches(pattern, hostname) {
|
|
12
|
-
if (pattern.startsWith("|")) {
|
|
13
|
-
const parts = pattern.split("|");
|
|
14
|
-
if (parts.length !== 4 || parts[1] !== "1") return false;
|
|
15
|
-
const salt = Buffer.from(parts[2], "base64");
|
|
16
|
-
const digest = Buffer.from(parts[3], "base64");
|
|
17
|
-
return salt.length === 20 && equal(createHmac("sha1", salt).update(hostname).digest(), digest);
|
|
18
|
-
}
|
|
19
|
-
const regex = pattern
|
|
20
|
-
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
21
|
-
.replace(/\*/g, ".*")
|
|
22
|
-
.replace(/\?/g, ".");
|
|
23
|
-
return new RegExp(`^${regex}$`, "i").test(hostname);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function hostMatches(patterns, hostname) {
|
|
27
|
-
let matched = false;
|
|
28
|
-
for (const pattern of patterns.split(",")) {
|
|
29
|
-
if (pattern.startsWith("!")) {
|
|
30
|
-
if (matches(pattern.slice(1), hostname)) return false;
|
|
31
|
-
} else if (matches(pattern, hostname)) matched = true;
|
|
32
|
-
}
|
|
33
|
-
return matched;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Exact host/port binding; hashed hosts, wildcards, negation and @revoked are supported.
|
|
37
|
-
* @cert-authority is intentionally not accepted: certificate verification is not implemented.
|
|
38
|
-
*/
|
|
39
|
-
export function verifyKnownHosts(contents, host, port, key) {
|
|
40
|
-
const hostname = port === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`;
|
|
41
|
-
let trusted = false;
|
|
42
|
-
for (const line of contents.split(/\r?\n/)) {
|
|
43
|
-
const fields = line.trim().split(/\s+/);
|
|
44
|
-
if (!fields[0] || fields[0].startsWith("#")) continue;
|
|
45
|
-
const marker = fields[0].startsWith("@") ? fields.shift() : "";
|
|
46
|
-
const [hosts, algorithm, encoded] = fields;
|
|
47
|
-
if (!hosts || !algorithm || !encoded || !hostMatches(hosts, hostname)) continue;
|
|
48
|
-
const stored = Buffer.from(encoded, "base64");
|
|
49
|
-
if (stored.length < 4) continue;
|
|
50
|
-
const length = stored.readUInt32BE(0);
|
|
51
|
-
if (length > stored.length - 4 || stored.subarray(4, 4 + length).toString("ascii") !== algorithm) continue;
|
|
52
|
-
if (!equal(stored, key)) continue;
|
|
53
|
-
if (marker === "@revoked") return false;
|
|
54
|
-
if (!marker) trusted = true;
|
|
55
|
-
}
|
|
56
|
-
return trusted;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function knownHostsFile() {
|
|
60
|
-
const configured = process.env.PI_WEB_SSH_KNOWN_HOSTS?.trim();
|
|
61
|
-
return path.resolve(
|
|
62
|
-
configured ? configured.replace(/^~(?=[/\\])/, os.homedir()) : path.join(os.homedir(), ".ssh", "known_hosts"),
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function readKnownHosts(file) {
|
|
67
|
-
try {
|
|
68
|
-
return await readFile(file, "utf8");
|
|
69
|
-
} catch (error) {
|
|
70
|
-
if (error.code === "ENOENT") return "";
|
|
71
|
-
throw new Error(`Cannot read SSH known_hosts ${file}: ${error.message}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function fingerprintOf(key) {
|
|
76
|
-
return `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function algorithmOf(key) {
|
|
80
|
-
if (!Buffer.isBuffer(key) || key.length < 5) throw new Error("Invalid SSH host key");
|
|
81
|
-
const length = key.readUInt32BE(0);
|
|
82
|
-
if (!length || length > key.length - 4) throw new Error("Invalid SSH host key");
|
|
83
|
-
const algorithm = key.subarray(4, 4 + length).toString("ascii");
|
|
84
|
-
if (!/^[a-zA-Z0-9@._+-]+$/.test(algorithm)) throw new Error("Invalid SSH host key algorithm");
|
|
85
|
-
return algorithm;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function hostBinding(host, port) {
|
|
89
|
-
if (typeof host !== "string" || !host || /[\s,*?!|#[\]\\/\x00-\x1f\x7f]/.test(host)) {
|
|
90
|
-
throw new Error("Invalid SSH host");
|
|
91
|
-
}
|
|
92
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Invalid SSH port");
|
|
93
|
-
return port === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function matchingRows(contents, hostname) {
|
|
97
|
-
const rows = [];
|
|
98
|
-
for (const line of contents.split(/(?<=\n)/)) {
|
|
99
|
-
const fields = /^(\s*)(?:(@\S+)\s+)?([^\s#]+)(\s+)(\S+)\s+(\S+)/.exec(line);
|
|
100
|
-
if (!fields || !hostMatches(fields[3], hostname)) continue;
|
|
101
|
-
const stored = Buffer.from(fields[6], "base64");
|
|
102
|
-
try {
|
|
103
|
-
if (algorithmOf(stored) !== fields[5]) continue;
|
|
104
|
-
} catch {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
rows.push({ line, fields, stored, marker: fields[2] || "", hosts: fields[3] });
|
|
108
|
-
}
|
|
109
|
-
return rows;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function trustStatus(contents, hostname, key) {
|
|
113
|
-
const rows = matchingRows(contents, hostname);
|
|
114
|
-
if (rows.some((row) => row.marker === "@revoked" && equal(row.stored, key))) return "revoked";
|
|
115
|
-
return rows.length ? "changed" : "unknown";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Serialize the read/modify/rename transaction, including saves to the same file from different callers.
|
|
119
|
-
let pendingSave = Promise.resolve();
|
|
120
|
-
|
|
121
|
-
/** Persist only a caller-confirmed key. Returns the public trust description; never returns key bytes.
|
|
122
|
-
* replace is required for changed keys. Wildcard/CA/revoked bindings cannot be rewritten here.
|
|
123
|
-
* Serialization is process-local; one service process must own the configured trust file.
|
|
124
|
-
*/
|
|
125
|
-
export function saveTrustedHostKey({ host, port = 22, key, fingerprint, replace = false }) {
|
|
126
|
-
const file = knownHostsFile();
|
|
127
|
-
// Capture bytes now: callers cannot change the key while waiting for an earlier save.
|
|
128
|
-
const capturedKey = Buffer.isBuffer(key) ? Buffer.from(key) : key;
|
|
129
|
-
const save = pendingSave.then(async () => {
|
|
130
|
-
const hostname = hostBinding(host, port);
|
|
131
|
-
const algorithm = algorithmOf(capturedKey);
|
|
132
|
-
if (fingerprint !== fingerprintOf(capturedKey)) throw new Error("SSH host key fingerprint mismatch");
|
|
133
|
-
const contents = await readKnownHosts(file);
|
|
134
|
-
const rows = matchingRows(contents, hostname);
|
|
135
|
-
if (rows.some((row) => row.marker === "@revoked")) throw new Error("SSH host key is revoked; cannot save trust");
|
|
136
|
-
const result = { host, port, algorithm, fingerprint, knownHostsFile: file };
|
|
137
|
-
if (verifyKnownHosts(contents, host, port, capturedKey)) return result;
|
|
138
|
-
if (rows.length && !replace) throw new Error("SSH host key changed; explicit replace is required");
|
|
139
|
-
const replacements = new Map();
|
|
140
|
-
for (const row of rows) {
|
|
141
|
-
const bindings = row.hosts.split(",");
|
|
142
|
-
if (
|
|
143
|
-
row.marker ||
|
|
144
|
-
bindings.some((binding) => !binding.startsWith("!") && matches(binding, hostname) && /[*?]/.test(binding))
|
|
145
|
-
) {
|
|
146
|
-
throw new Error("Cannot safely replace wildcard or marked SSH known_hosts binding");
|
|
147
|
-
}
|
|
148
|
-
const remaining = bindings.filter((binding) => binding.startsWith("!") || !matches(binding, hostname));
|
|
149
|
-
// A list containing only exclusions no longer binds any host.
|
|
150
|
-
if (!remaining.some((binding) => !binding.startsWith("!"))) replacements.set(row.line, "");
|
|
151
|
-
else {
|
|
152
|
-
const start = row.fields[1].length;
|
|
153
|
-
replacements.set(
|
|
154
|
-
row.line,
|
|
155
|
-
row.line.slice(0, start) + remaining.join(",") + row.line.slice(start + row.hosts.length),
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
let updated = contents
|
|
160
|
-
.split(/(?<=\n)/)
|
|
161
|
-
.map((line) => replacements.get(line) ?? line)
|
|
162
|
-
.join("");
|
|
163
|
-
if (updated && !updated.endsWith("\n")) updated += "\n";
|
|
164
|
-
updated += `${hostname} ${algorithm} ${capturedKey.toString("base64")}\n`;
|
|
165
|
-
let mode = 0o600;
|
|
166
|
-
try {
|
|
167
|
-
const stat = await lstat(file);
|
|
168
|
-
if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("SSH known_hosts must be a regular file");
|
|
169
|
-
mode = stat.mode & 0o777;
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (error.code !== "ENOENT") throw error;
|
|
172
|
-
}
|
|
173
|
-
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
174
|
-
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
175
|
-
try {
|
|
176
|
-
await writeFile(temporary, updated, { flag: "wx", mode });
|
|
177
|
-
await chmod(temporary, mode);
|
|
178
|
-
await rename(temporary, file);
|
|
179
|
-
} finally {
|
|
180
|
-
await unlink(temporary).catch((error) => {
|
|
181
|
-
if (error.code !== "ENOENT") throw error;
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
});
|
|
186
|
-
pendingSave = save.catch(() => {});
|
|
187
|
-
return save;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Read once per handshake, before any authentication. The override names a single local file. */
|
|
191
|
-
export async function createHostVerifier(host, port = 22) {
|
|
192
|
-
const file = knownHostsFile();
|
|
193
|
-
const contents = await readKnownHosts(file);
|
|
194
|
-
let failure;
|
|
195
|
-
return {
|
|
196
|
-
hostVerifier(key) {
|
|
197
|
-
if (verifyKnownHosts(contents, host, port, key)) return true;
|
|
198
|
-
const fingerprint = fingerprintOf(key);
|
|
199
|
-
failure = new Error(
|
|
200
|
-
`SSH 主机密钥未受信任或已变更 / host key untrusted or changed: ${host}:${port}; presented ${fingerprint}. ` +
|
|
201
|
-
`连接已拒绝,未保存密钥 / Connection refused; no key was saved. ` +
|
|
202
|
-
`请通过服务器控制台或管理员独立核对指纹(服务器上可运行 ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub;按实际密钥类型选文件)。` +
|
|
203
|
-
`核对一致后,用本机 OpenSSH ssh 连接同一主机和端口,设置 StrictHostKeyChecking=ask 和 UserKnownHostsFile 为 ${file},确认提示后重试。` +
|
|
204
|
-
`若密钥已变更,须先由管理员确认轮换,再手动更新对应记录;不要盲目删除旧记录或直接信任 ssh-keyscan 输出。` +
|
|
205
|
-
` Independently verify the fingerprint with the server console/admin, then use OpenSSH ssh with StrictHostKeyChecking=ask and UserKnownHostsFile=${file} for the same host/port; accept only the verified key. ` +
|
|
206
|
-
`For rotated keys, confirm rotation before replacing the old entry. Do not trust ssh-keyscan output alone. ` +
|
|
207
|
-
`Preprovision verified OpenSSH entries in this file, or set PI_WEB_SSH_KNOWN_HOSTS to a trusted known_hosts file in the server environment. ` +
|
|
208
|
-
`CA-only (@cert-authority) entries are not supported; provision the verified host public key.`,
|
|
209
|
-
);
|
|
210
|
-
failure.hostTrust = {
|
|
211
|
-
host,
|
|
212
|
-
port,
|
|
213
|
-
algorithm: algorithmOf(key),
|
|
214
|
-
fingerprint,
|
|
215
|
-
knownHostsFile: file,
|
|
216
|
-
status: trustStatus(contents, port === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`, key),
|
|
217
|
-
};
|
|
218
|
-
Object.defineProperty(failure, "hostKey", { value: Buffer.from(key), enumerable: false });
|
|
219
|
-
return false;
|
|
220
|
-
},
|
|
221
|
-
getError() {
|
|
222
|
-
return failure;
|
|
223
|
-
},
|
|
224
|
-
};
|
|
225
|
-
}
|
|
1
|
+
/** Shared, fail-closed OpenSSH verification and explicit, fingerprint-confirmed trust persistence. */
|
|
2
|
+
import { createHash, createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
3
|
+
import { chmod, lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
function equal(a, b) {
|
|
8
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function matches(pattern, hostname) {
|
|
12
|
+
if (pattern.startsWith("|")) {
|
|
13
|
+
const parts = pattern.split("|");
|
|
14
|
+
if (parts.length !== 4 || parts[1] !== "1") return false;
|
|
15
|
+
const salt = Buffer.from(parts[2], "base64");
|
|
16
|
+
const digest = Buffer.from(parts[3], "base64");
|
|
17
|
+
return salt.length === 20 && equal(createHmac("sha1", salt).update(hostname).digest(), digest);
|
|
18
|
+
}
|
|
19
|
+
const regex = pattern
|
|
20
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
21
|
+
.replace(/\*/g, ".*")
|
|
22
|
+
.replace(/\?/g, ".");
|
|
23
|
+
return new RegExp(`^${regex}$`, "i").test(hostname);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function hostMatches(patterns, hostname) {
|
|
27
|
+
let matched = false;
|
|
28
|
+
for (const pattern of patterns.split(",")) {
|
|
29
|
+
if (pattern.startsWith("!")) {
|
|
30
|
+
if (matches(pattern.slice(1), hostname)) return false;
|
|
31
|
+
} else if (matches(pattern, hostname)) matched = true;
|
|
32
|
+
}
|
|
33
|
+
return matched;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Exact host/port binding; hashed hosts, wildcards, negation and @revoked are supported.
|
|
37
|
+
* @cert-authority is intentionally not accepted: certificate verification is not implemented.
|
|
38
|
+
*/
|
|
39
|
+
export function verifyKnownHosts(contents, host, port, key) {
|
|
40
|
+
const hostname = port === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`;
|
|
41
|
+
let trusted = false;
|
|
42
|
+
for (const line of contents.split(/\r?\n/)) {
|
|
43
|
+
const fields = line.trim().split(/\s+/);
|
|
44
|
+
if (!fields[0] || fields[0].startsWith("#")) continue;
|
|
45
|
+
const marker = fields[0].startsWith("@") ? fields.shift() : "";
|
|
46
|
+
const [hosts, algorithm, encoded] = fields;
|
|
47
|
+
if (!hosts || !algorithm || !encoded || !hostMatches(hosts, hostname)) continue;
|
|
48
|
+
const stored = Buffer.from(encoded, "base64");
|
|
49
|
+
if (stored.length < 4) continue;
|
|
50
|
+
const length = stored.readUInt32BE(0);
|
|
51
|
+
if (length > stored.length - 4 || stored.subarray(4, 4 + length).toString("ascii") !== algorithm) continue;
|
|
52
|
+
if (!equal(stored, key)) continue;
|
|
53
|
+
if (marker === "@revoked") return false;
|
|
54
|
+
if (!marker) trusted = true;
|
|
55
|
+
}
|
|
56
|
+
return trusted;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function knownHostsFile() {
|
|
60
|
+
const configured = process.env.PI_WEB_SSH_KNOWN_HOSTS?.trim();
|
|
61
|
+
return path.resolve(
|
|
62
|
+
configured ? configured.replace(/^~(?=[/\\])/, os.homedir()) : path.join(os.homedir(), ".ssh", "known_hosts"),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function readKnownHosts(file) {
|
|
67
|
+
try {
|
|
68
|
+
return await readFile(file, "utf8");
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code === "ENOENT") return "";
|
|
71
|
+
throw new Error(`Cannot read SSH known_hosts ${file}: ${error.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function fingerprintOf(key) {
|
|
76
|
+
return `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function algorithmOf(key) {
|
|
80
|
+
if (!Buffer.isBuffer(key) || key.length < 5) throw new Error("Invalid SSH host key");
|
|
81
|
+
const length = key.readUInt32BE(0);
|
|
82
|
+
if (!length || length > key.length - 4) throw new Error("Invalid SSH host key");
|
|
83
|
+
const algorithm = key.subarray(4, 4 + length).toString("ascii");
|
|
84
|
+
if (!/^[a-zA-Z0-9@._+-]+$/.test(algorithm)) throw new Error("Invalid SSH host key algorithm");
|
|
85
|
+
return algorithm;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function hostBinding(host, port) {
|
|
89
|
+
if (typeof host !== "string" || !host || /[\s,*?!|#[\]\\/\x00-\x1f\x7f]/.test(host)) {
|
|
90
|
+
throw new Error("Invalid SSH host");
|
|
91
|
+
}
|
|
92
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("Invalid SSH port");
|
|
93
|
+
return port === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function matchingRows(contents, hostname) {
|
|
97
|
+
const rows = [];
|
|
98
|
+
for (const line of contents.split(/(?<=\n)/)) {
|
|
99
|
+
const fields = /^(\s*)(?:(@\S+)\s+)?([^\s#]+)(\s+)(\S+)\s+(\S+)/.exec(line);
|
|
100
|
+
if (!fields || !hostMatches(fields[3], hostname)) continue;
|
|
101
|
+
const stored = Buffer.from(fields[6], "base64");
|
|
102
|
+
try {
|
|
103
|
+
if (algorithmOf(stored) !== fields[5]) continue;
|
|
104
|
+
} catch {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
rows.push({ line, fields, stored, marker: fields[2] || "", hosts: fields[3] });
|
|
108
|
+
}
|
|
109
|
+
return rows;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function trustStatus(contents, hostname, key) {
|
|
113
|
+
const rows = matchingRows(contents, hostname);
|
|
114
|
+
if (rows.some((row) => row.marker === "@revoked" && equal(row.stored, key))) return "revoked";
|
|
115
|
+
return rows.length ? "changed" : "unknown";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Serialize the read/modify/rename transaction, including saves to the same file from different callers.
|
|
119
|
+
let pendingSave = Promise.resolve();
|
|
120
|
+
|
|
121
|
+
/** Persist only a caller-confirmed key. Returns the public trust description; never returns key bytes.
|
|
122
|
+
* replace is required for changed keys. Wildcard/CA/revoked bindings cannot be rewritten here.
|
|
123
|
+
* Serialization is process-local; one service process must own the configured trust file.
|
|
124
|
+
*/
|
|
125
|
+
export function saveTrustedHostKey({ host, port = 22, key, fingerprint, replace = false }) {
|
|
126
|
+
const file = knownHostsFile();
|
|
127
|
+
// Capture bytes now: callers cannot change the key while waiting for an earlier save.
|
|
128
|
+
const capturedKey = Buffer.isBuffer(key) ? Buffer.from(key) : key;
|
|
129
|
+
const save = pendingSave.then(async () => {
|
|
130
|
+
const hostname = hostBinding(host, port);
|
|
131
|
+
const algorithm = algorithmOf(capturedKey);
|
|
132
|
+
if (fingerprint !== fingerprintOf(capturedKey)) throw new Error("SSH host key fingerprint mismatch");
|
|
133
|
+
const contents = await readKnownHosts(file);
|
|
134
|
+
const rows = matchingRows(contents, hostname);
|
|
135
|
+
if (rows.some((row) => row.marker === "@revoked")) throw new Error("SSH host key is revoked; cannot save trust");
|
|
136
|
+
const result = { host, port, algorithm, fingerprint, knownHostsFile: file };
|
|
137
|
+
if (verifyKnownHosts(contents, host, port, capturedKey)) return result;
|
|
138
|
+
if (rows.length && !replace) throw new Error("SSH host key changed; explicit replace is required");
|
|
139
|
+
const replacements = new Map();
|
|
140
|
+
for (const row of rows) {
|
|
141
|
+
const bindings = row.hosts.split(",");
|
|
142
|
+
if (
|
|
143
|
+
row.marker ||
|
|
144
|
+
bindings.some((binding) => !binding.startsWith("!") && matches(binding, hostname) && /[*?]/.test(binding))
|
|
145
|
+
) {
|
|
146
|
+
throw new Error("Cannot safely replace wildcard or marked SSH known_hosts binding");
|
|
147
|
+
}
|
|
148
|
+
const remaining = bindings.filter((binding) => binding.startsWith("!") || !matches(binding, hostname));
|
|
149
|
+
// A list containing only exclusions no longer binds any host.
|
|
150
|
+
if (!remaining.some((binding) => !binding.startsWith("!"))) replacements.set(row.line, "");
|
|
151
|
+
else {
|
|
152
|
+
const start = row.fields[1].length;
|
|
153
|
+
replacements.set(
|
|
154
|
+
row.line,
|
|
155
|
+
row.line.slice(0, start) + remaining.join(",") + row.line.slice(start + row.hosts.length),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
let updated = contents
|
|
160
|
+
.split(/(?<=\n)/)
|
|
161
|
+
.map((line) => replacements.get(line) ?? line)
|
|
162
|
+
.join("");
|
|
163
|
+
if (updated && !updated.endsWith("\n")) updated += "\n";
|
|
164
|
+
updated += `${hostname} ${algorithm} ${capturedKey.toString("base64")}\n`;
|
|
165
|
+
let mode = 0o600;
|
|
166
|
+
try {
|
|
167
|
+
const stat = await lstat(file);
|
|
168
|
+
if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("SSH known_hosts must be a regular file");
|
|
169
|
+
mode = stat.mode & 0o777;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error.code !== "ENOENT") throw error;
|
|
172
|
+
}
|
|
173
|
+
await mkdir(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
174
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
175
|
+
try {
|
|
176
|
+
await writeFile(temporary, updated, { flag: "wx", mode });
|
|
177
|
+
await chmod(temporary, mode);
|
|
178
|
+
await rename(temporary, file);
|
|
179
|
+
} finally {
|
|
180
|
+
await unlink(temporary).catch((error) => {
|
|
181
|
+
if (error.code !== "ENOENT") throw error;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
});
|
|
186
|
+
pendingSave = save.catch(() => {});
|
|
187
|
+
return save;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Read once per handshake, before any authentication. The override names a single local file. */
|
|
191
|
+
export async function createHostVerifier(host, port = 22) {
|
|
192
|
+
const file = knownHostsFile();
|
|
193
|
+
const contents = await readKnownHosts(file);
|
|
194
|
+
let failure;
|
|
195
|
+
return {
|
|
196
|
+
hostVerifier(key) {
|
|
197
|
+
if (verifyKnownHosts(contents, host, port, key)) return true;
|
|
198
|
+
const fingerprint = fingerprintOf(key);
|
|
199
|
+
failure = new Error(
|
|
200
|
+
`SSH 主机密钥未受信任或已变更 / host key untrusted or changed: ${host}:${port}; presented ${fingerprint}. ` +
|
|
201
|
+
`连接已拒绝,未保存密钥 / Connection refused; no key was saved. ` +
|
|
202
|
+
`请通过服务器控制台或管理员独立核对指纹(服务器上可运行 ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub;按实际密钥类型选文件)。` +
|
|
203
|
+
`核对一致后,用本机 OpenSSH ssh 连接同一主机和端口,设置 StrictHostKeyChecking=ask 和 UserKnownHostsFile 为 ${file},确认提示后重试。` +
|
|
204
|
+
`若密钥已变更,须先由管理员确认轮换,再手动更新对应记录;不要盲目删除旧记录或直接信任 ssh-keyscan 输出。` +
|
|
205
|
+
` Independently verify the fingerprint with the server console/admin, then use OpenSSH ssh with StrictHostKeyChecking=ask and UserKnownHostsFile=${file} for the same host/port; accept only the verified key. ` +
|
|
206
|
+
`For rotated keys, confirm rotation before replacing the old entry. Do not trust ssh-keyscan output alone. ` +
|
|
207
|
+
`Preprovision verified OpenSSH entries in this file, or set PI_WEB_SSH_KNOWN_HOSTS to a trusted known_hosts file in the server environment. ` +
|
|
208
|
+
`CA-only (@cert-authority) entries are not supported; provision the verified host public key.`,
|
|
209
|
+
);
|
|
210
|
+
failure.hostTrust = {
|
|
211
|
+
host,
|
|
212
|
+
port,
|
|
213
|
+
algorithm: algorithmOf(key),
|
|
214
|
+
fingerprint,
|
|
215
|
+
knownHostsFile: file,
|
|
216
|
+
status: trustStatus(contents, port === 22 ? host.toLowerCase() : `[${host.toLowerCase()}]:${port}`, key),
|
|
217
|
+
};
|
|
218
|
+
Object.defineProperty(failure, "hostKey", { value: Buffer.from(key), enumerable: false });
|
|
219
|
+
return false;
|
|
220
|
+
},
|
|
221
|
+
getError() {
|
|
222
|
+
return failure;
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
package/plugins/catalog.json
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"id": "lx-music",
|
|
4
|
+
"name": "lx-music",
|
|
5
|
+
"icon": "🎵",
|
|
6
|
+
"iconSvg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M9 18V5l12-2v13\"/><circle cx=\"6\" cy=\"18\" r=\"3\"/><circle cx=\"18\" cy=\"16\" r=\"3\"/></svg>",
|
|
7
|
+
"description": "洛雪音乐播放器:多源搜索、流式播放、同步歌词、歌单与自定义音源,支持 AI 点歌。",
|
|
8
|
+
"descriptionEn": "LX Music player with multi-source search, streaming, synchronized lyrics, playlists, custom sources, and AI playback tools.",
|
|
9
|
+
"source": "xing-shuyin/pi-web-ui/plugins/lx-music",
|
|
10
|
+
"homepage": "https://github.com/xing-shuyin/pi-web-ui/tree/main/plugins/lx-music"
|
|
11
|
+
},
|
|
2
12
|
{
|
|
3
13
|
"id": "webmail",
|
|
4
14
|
"name": "webmail",
|