omo-web 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +23 -2
- package/bin/launcher-settings.js +116 -0
- package/bin/launcher-tls.js +67 -0
- package/bin/listen-address.js +20 -0
- package/bin/locale.js +6 -0
- package/bin/omo-web.js +98 -0
- package/bin/tui.js +645 -0
- package/bin/windows-password.js +79 -0
- package/dist/app.js +7 -0
- package/dist/server.js +12524 -0
- package/package.json +31 -4
- package/public/dag-graph.css +80 -0
- package/public/favicon.svg +13 -0
- package/public/icons.svg +89 -0
- package/public/index.html +486 -0
- package/public/licenses/teenyicons.txt +25 -0
- package/public/licenses/zod.txt +21 -0
- package/public/styles.css +422 -0
- package/public/tool-ledger.css +354 -0
- package/public/workbench.css +782 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OmO Web contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OmO Web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A local browser workbench for OmO Native. Open sessions from different project folders, handle approvals, and inspect tool output or DAGs from the browser. OmO Native keeps your model settings and credentials.
|
|
4
|
+
|
|
5
|
+
## Get started
|
|
6
|
+
|
|
7
|
+
Install Node.js 18+, [Bun](https://bun.sh/docs/installation), and [OmO Native](https://github.com/code-yeongyu/oh-my-openagent). Configure your model in `omo` first.
|
|
8
|
+
|
|
9
|
+
If the CLI is already installed, run it from a project directory:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
cd /path/to/your/project
|
|
13
|
+
omo-web
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Open the printed URL (normally `http://127.0.0.1:4317`). The local browser connects to OmO on the host. `omo-web --help` lists startup commands.
|
|
17
|
+
|
|
18
|
+
In an interactive terminal, `omo-web` opens a keyboard-driven launcher. Use ↑/↓ and Enter to choose working directories or open **Access settings**. There you can change or disable the password, toggle HTTPS, generate a self-signed certificate (requires OpenSSL 1.1.1+ on `PATH`), and bind to loopback, a specific IPv4 interface, or all IPv4 interfaces (`0.0.0.0`). Access settings are saved and apply on the next start. Non-loopback listeners require HTTPS; passwordless startup needs confirmation. The browser username is `omo`.
|
|
19
|
+
|
|
20
|
+
Once running, open the browser or stop the service from the same screen. For scripts or logging, `omo-web serve` uses environment variables only.
|
|
21
|
+
|
|
22
|
+
OmO Web is licensed under MIT. The package includes the original notices for its third-party assets.
|
|
23
|
+
|
|
24
|
+
[Installation](https://github.com/NekoCCN/OmO-Web#install) · [简体中文](https://github.com/NekoCCN/OmO-Web/blob/main/README.zh-CN.md) · [GitHub Releases](https://github.com/NekoCCN/OmO-Web/releases) · [Remote access](https://github.com/NekoCCN/OmO-Web/blob/main/docs/usage.md#密码与远程访问)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { cliTr } from "./locale.js";
|
|
6
|
+
import { createWindowsPasswordFile } from "./windows-password.js";
|
|
7
|
+
|
|
8
|
+
const envKeys = [
|
|
9
|
+
"OMO_WEB_HOST", "OMO_WEB_PASSWORD_FILE", "OMO_WEB_ALLOW_UNAUTHENTICATED",
|
|
10
|
+
"OMO_WEB_ORIGIN", "OMO_WEB_TLS_CERT", "OMO_WEB_TLS_KEY",
|
|
11
|
+
];
|
|
12
|
+
const keys = new Set([...envKeys, "savedPassword", "httpsEnabled"]);
|
|
13
|
+
|
|
14
|
+
async function atomicFile(path, create) {
|
|
15
|
+
const staged = `${path}.${randomUUID()}.tmp`;
|
|
16
|
+
try {
|
|
17
|
+
await create(staged);
|
|
18
|
+
await rename(staged, path);
|
|
19
|
+
} finally {
|
|
20
|
+
await rm(staged, { force: true });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function loadLauncherSettings(base) {
|
|
25
|
+
const dataDir = resolve(base.OMO_WEB_DATA ?? join(homedir(), ".omo-web"));
|
|
26
|
+
const directory = join(dataDir, "launcher");
|
|
27
|
+
const config = join(directory, "settings.json");
|
|
28
|
+
let overrides = {};
|
|
29
|
+
let warning = "";
|
|
30
|
+
let readable = true;
|
|
31
|
+
try {
|
|
32
|
+
const info = await lstat(directory);
|
|
33
|
+
if (!info.isDirectory() || (process.platform !== "win32" &&
|
|
34
|
+
(info.uid !== process.getuid() || (info.mode & 0o077) !== 0))) {
|
|
35
|
+
throw new Error("Expected a private launcher directory.");
|
|
36
|
+
}
|
|
37
|
+
const object = JSON.parse(await readFile(config, "utf8"));
|
|
38
|
+
if (object === null || typeof object !== "object" || Array.isArray(object) ||
|
|
39
|
+
Object.entries(object).some(([key, value]) => !keys.has(key) ||
|
|
40
|
+
(key === "httpsEnabled" ? value !== "0" && value !== "1" : value !== null && typeof value !== "string"))) {
|
|
41
|
+
throw new Error("Invalid launcher settings.");
|
|
42
|
+
}
|
|
43
|
+
overrides = object;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (error?.code !== "ENOENT") {
|
|
46
|
+
readable = false;
|
|
47
|
+
warning = cliTr("无法读取私密启动器设置。请检查设置目录后重试。",
|
|
48
|
+
"Could not load private launcher settings. Check the settings directory and retry.");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function prepare() {
|
|
53
|
+
if (!readable) throw new Error(warning);
|
|
54
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
55
|
+
const info = await lstat(directory);
|
|
56
|
+
if (!info.isDirectory() || (process.platform !== "win32" &&
|
|
57
|
+
(info.uid !== process.getuid() || (info.mode & 0o077) !== 0))) {
|
|
58
|
+
throw new Error("Expected a private launcher directory.");
|
|
59
|
+
}
|
|
60
|
+
return directory;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function save(patch) {
|
|
64
|
+
await prepare();
|
|
65
|
+
const next = { ...overrides, ...patch };
|
|
66
|
+
await atomicFile(config, path => writeFile(path, `${JSON.stringify(next, null, 2)}\n`, { flag: "wx", mode: 0o600 }));
|
|
67
|
+
overrides = next;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function effectiveEnv() {
|
|
71
|
+
const env = { ...base };
|
|
72
|
+
for (const key of envKeys) {
|
|
73
|
+
const value = overrides[key];
|
|
74
|
+
if (value === null) delete env[key];
|
|
75
|
+
else if (value !== undefined) env[key] = value;
|
|
76
|
+
}
|
|
77
|
+
if (overrides.httpsEnabled === "0") {
|
|
78
|
+
delete env.OMO_WEB_ORIGIN;
|
|
79
|
+
delete env.OMO_WEB_TLS_CERT;
|
|
80
|
+
delete env.OMO_WEB_TLS_KEY;
|
|
81
|
+
}
|
|
82
|
+
return env;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
directory, warning, prepare, save, effectiveEnv,
|
|
87
|
+
get hasListenerOverride() { return overrides.OMO_WEB_HOST !== undefined || overrides.httpsEnabled !== undefined; },
|
|
88
|
+
async changePassword(password) {
|
|
89
|
+
await prepare();
|
|
90
|
+
const path = join(directory, "password.txt");
|
|
91
|
+
await atomicFile(path, staged => process.platform === "win32" ? createWindowsPasswordFile(staged, password)
|
|
92
|
+
: writeFile(staged, `${password}\n`, { flag: "wx", mode: 0o600 }));
|
|
93
|
+
await save({ OMO_WEB_PASSWORD_FILE: path, savedPassword: path, OMO_WEB_ALLOW_UNAUTHENTICATED: null });
|
|
94
|
+
},
|
|
95
|
+
async setPasswordEnabled(enabled) {
|
|
96
|
+
const current = effectiveEnv().OMO_WEB_PASSWORD_FILE;
|
|
97
|
+
const path = current ? resolve(current) : overrides.savedPassword ?? base.OMO_WEB_PASSWORD_FILE;
|
|
98
|
+
if (enabled && !path) return false;
|
|
99
|
+
await save({
|
|
100
|
+
OMO_WEB_PASSWORD_FILE: enabled ? resolve(path) : null,
|
|
101
|
+
savedPassword: path === undefined ? null : resolve(path),
|
|
102
|
+
OMO_WEB_ALLOW_UNAUTHENTICATED: null,
|
|
103
|
+
});
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
async setHttpsEnabled(enabled) {
|
|
107
|
+
if (enabled && !["OMO_WEB_ORIGIN", "OMO_WEB_TLS_CERT", "OMO_WEB_TLS_KEY"].every(key =>
|
|
108
|
+
overrides[key] === undefined ? base[key] : overrides[key])) return false;
|
|
109
|
+
await save({ httpsEnabled: enabled ? "1" : "0" });
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
async enableGeneratedTls({ origin, certFile, keyFile }) {
|
|
113
|
+
await save({ httpsEnabled: "1", OMO_WEB_ORIGIN: origin, OMO_WEB_TLS_CERT: certFile, OMO_WEB_TLS_KEY: keyFile });
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { isIP } from "node:net";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { cliTr } from "./locale.js";
|
|
7
|
+
import { createWindowsPrivateFile } from "./windows-password.js";
|
|
8
|
+
|
|
9
|
+
const run = promisify(execFile);
|
|
10
|
+
|
|
11
|
+
export function certificateOrigin(input, port) {
|
|
12
|
+
const host = input.trim().toLowerCase();
|
|
13
|
+
const family = isIP(host);
|
|
14
|
+
if (host === "0.0.0.0" || (family !== 4 &&
|
|
15
|
+
(family !== 0 || host.length > 253 || /^[\d.]+$/.test(host) || host.split(".")
|
|
16
|
+
.some(label => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label))))) {
|
|
17
|
+
throw new Error(cliTr("请输入浏览器使用的 IPv4 地址或 DNS 名(不含端口)。",
|
|
18
|
+
"Enter the browser's IPv4 address or DNS name, without a port."));
|
|
19
|
+
}
|
|
20
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
21
|
+
throw new Error(cliTr("生成 HTTPS 证书需要固定端口(OMO_WEB_PORT)。",
|
|
22
|
+
"HTTPS generation requires a fixed port (OMO_WEB_PORT)."));
|
|
23
|
+
}
|
|
24
|
+
const url = new URL(`https://${host}:${port}`);
|
|
25
|
+
if (url.hostname !== host) throw new Error(cliTr("请输入规范的 IPv4 地址或 DNS 名。",
|
|
26
|
+
"Enter a canonical IPv4 address or DNS name."));
|
|
27
|
+
return { url, san: `${family === 4 ? "IP" : "DNS"}:${host}` };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function generateCertificate(settings, input, port) {
|
|
31
|
+
const { url, san } = certificateOrigin(input, port);
|
|
32
|
+
const folder = await mkdtemp(join(await settings.prepare(), "tls-"));
|
|
33
|
+
const certFile = join(folder, "cert.pem");
|
|
34
|
+
const keyFile = join(folder, "key.pem");
|
|
35
|
+
const configuration = join(folder, "openssl.cnf");
|
|
36
|
+
let saved = false;
|
|
37
|
+
try {
|
|
38
|
+
// A fixed request config avoids inheriting a machine's CA extensions.
|
|
39
|
+
await writeFile(configuration, "[req]\ndistinguished_name = dn\n[dn]\n", { flag: "wx", mode: 0o600 });
|
|
40
|
+
let output;
|
|
41
|
+
try {
|
|
42
|
+
({ stdout: output } = await run("openssl", [
|
|
43
|
+
"req", "-config", configuration, "-x509", "-newkey", "ec", "-pkeyopt", "ec_paramgen_curve:prime256v1",
|
|
44
|
+
"-nodes", "-days", "90", "-subj", "/CN=OmO Web", "-addext", `subjectAltName=${san}`,
|
|
45
|
+
"-addext", "basicConstraints=critical,CA:FALSE", "-addext", "extendedKeyUsage=serverAuth",
|
|
46
|
+
"-out", "-", "-keyout", "-",
|
|
47
|
+
], { env: { ...process.env, MSYS2_ARG_CONV_EXCL: "*" }, timeout: 8000, maxBuffer: 16384, windowsHide: true }));
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (!(error instanceof Error)) throw error;
|
|
50
|
+
throw new Error(error.code === "ENOENT"
|
|
51
|
+
? cliTr("找不到 OpenSSL。请安装 OpenSSL 1.1.1+ 并加入 PATH。", "Install OpenSSL 1.1.1+ and add it to PATH.")
|
|
52
|
+
: cliTr("OpenSSL 生成证书失败。请检查 OpenSSL 安装和版本。", "OpenSSL could not generate the certificate. Check its installation and version."));
|
|
53
|
+
}
|
|
54
|
+
const cert = output.match(/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/u)?.[0];
|
|
55
|
+
const key = output.match(/-----BEGIN PRIVATE KEY-----[\s\S]+?-----END PRIVATE KEY-----/u)?.[0];
|
|
56
|
+
if (!cert || !key) throw new Error(cliTr("OpenSSL 未返回完整的证书和私钥。", "OpenSSL did not return a certificate and private key."));
|
|
57
|
+
await writeFile(certFile, `${cert}\n`, { flag: "wx", mode: 0o644 });
|
|
58
|
+
if (process.platform === "win32") await createWindowsPrivateFile(keyFile, Buffer.from(`${key}\n`));
|
|
59
|
+
else await writeFile(keyFile, `${key}\n`, { flag: "wx", mode: 0o600 });
|
|
60
|
+
await rm(configuration);
|
|
61
|
+
await settings.enableGeneratedTls({ origin: url.origin, certFile, keyFile });
|
|
62
|
+
saved = true;
|
|
63
|
+
return certFile;
|
|
64
|
+
} finally {
|
|
65
|
+
if (!saved) await rm(folder, { force: true, recursive: true });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { networkInterfaces } from "node:os";
|
|
2
|
+
|
|
3
|
+
export const loopbackAddress = "127.0.0.1";
|
|
4
|
+
export const wildcardAddress = "0.0.0.0";
|
|
5
|
+
|
|
6
|
+
export function interfaceAddresses() {
|
|
7
|
+
const entries = new Map();
|
|
8
|
+
for (const [name, addresses] of Object.entries(networkInterfaces())) {
|
|
9
|
+
for (const item of addresses ?? []) {
|
|
10
|
+
if (item.family === "IPv4" && !item.internal && !entries.has(item.address)) {
|
|
11
|
+
entries.set(item.address, { name, address: item.address, cidr: item.cidr });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return [...entries.values()];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isRemoteAddress(host) {
|
|
19
|
+
return host !== undefined && host !== loopbackAddress;
|
|
20
|
+
}
|
package/bin/locale.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const system = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG
|
|
2
|
+
|| Intl.DateTimeFormat().resolvedOptions().locale;
|
|
3
|
+
export const cliLocale = /^zh(?:[-_.@]|$)/iu.test(system) ? "zh-CN" : "en";
|
|
4
|
+
|
|
5
|
+
/** @param {string} zh @param {string} en */
|
|
6
|
+
export const cliTr = (zh, en) => cliLocale === "zh-CN" ? zh : en;
|
package/bin/omo-web.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { randomBytes } from "node:crypto";
|
|
4
|
+
import { closeSync, fchmodSync, openSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { cliTr } from "./locale.js";
|
|
7
|
+
import { startTui, stopWindowsServer } from "./tui.js";
|
|
8
|
+
import { createWindowsPasswordFile } from "./windows-password.js";
|
|
9
|
+
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const version = () => JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
12
|
+
const entry = fileURLToPath(new URL("../dist/server.js", import.meta.url));
|
|
13
|
+
const terminal = process.stdin.isTTY && process.stdout.isTTY && process.env.TERM !== "dumb";
|
|
14
|
+
|
|
15
|
+
if (args.length === 1 && args[0] === "--version") {
|
|
16
|
+
console.log(version());
|
|
17
|
+
} else if (args.length === 1 && ["--help", "-h"].includes(args[0])) {
|
|
18
|
+
console.log(`${cliTr("用法:", "Usage:")} omo-web [tui | serve | password-file <path>]
|
|
19
|
+
|
|
20
|
+
omo-web ${cliTr("在交互终端打开启动器,否则直接启动服务。", "Open the launcher in a terminal; start directly otherwise.")}
|
|
21
|
+
omo-web tui ${cliTr("打开交互式启动器。", "Open the interactive launcher.")}
|
|
22
|
+
omo-web serve ${cliTr("直接启动 Web 服务。", "Start the Web service directly.")}
|
|
23
|
+
omo-web password-file <path> ${cliTr("创建私密随机密码文件,不覆盖。", "Create a private random password file without overwriting.")}
|
|
24
|
+
|
|
25
|
+
${cliTr("需要 Bun 和 OmO Native (omo)。默认使用当前目录。", "Requires Bun and OmO Native (omo). Defaults to the current directory.")}
|
|
26
|
+
${cliTr("用 OMO_WEB_WORKSPACES 和 OMO_WEB_PORT 设置目录和端口。", "Set directories and port with OMO_WEB_WORKSPACES and OMO_WEB_PORT.")}
|
|
27
|
+
${cliTr("在「访问设置」中选择网卡、设置密码和生成 SSL 自签证书。",
|
|
28
|
+
"Use Access settings in the launcher to choose an interface, set a password, or generate an SSL certificate.")}
|
|
29
|
+
${cliTr("非本机监听必须使用 HTTPS。建议设置访问密码。",
|
|
30
|
+
"Non-loopback listening requires HTTPS. Set an access password for protection.")}
|
|
31
|
+
${cliTr("仅在受限私网或 VPN 使用无密码模式;脚本需显式设置 OMO_WEB_ALLOW_UNAUTHENTICATED=1。",
|
|
32
|
+
"Use password-free access only on a restricted private network or VPN. Scripts must set OMO_WEB_ALLOW_UNAUTHENTICATED=1.")}
|
|
33
|
+
https://github.com/NekoCCN/OmO-Web/blob/main/docs/usage.md`);
|
|
34
|
+
} else if (args.length === 2 && args[0] === "password-file" && args[1]) {
|
|
35
|
+
process.exitCode = await createPasswordFile(args[1]);
|
|
36
|
+
} else if (args.length > 1 || (args.length === 1 && args[0] !== "tui" && args[0] !== "serve")) {
|
|
37
|
+
console.error(cliTr("omo-web: 参数不受支持。请查看 omo-web --help。",
|
|
38
|
+
"omo-web: unsupported arguments. See omo-web --help."));
|
|
39
|
+
process.exitCode = 2;
|
|
40
|
+
} else if (args[0] === "tui" && !terminal) {
|
|
41
|
+
console.error(cliTr("omo-web: 启动器需要交互终端。请改用 omo-web serve。",
|
|
42
|
+
"omo-web: the launcher needs an interactive terminal. Use omo-web serve instead."));
|
|
43
|
+
process.exitCode = 2;
|
|
44
|
+
} else if (args[0] !== "serve" && terminal) {
|
|
45
|
+
process.exitCode = await startTui({ entry, version: version() });
|
|
46
|
+
} else {
|
|
47
|
+
const child = spawn("bun", ["--no-env-file", entry], { stdio: "inherit" });
|
|
48
|
+
let stopping = false;
|
|
49
|
+
const stop = signal => {
|
|
50
|
+
if (stopping) return;
|
|
51
|
+
stopping = true;
|
|
52
|
+
if (process.platform === "win32") stopWindowsServer(child);
|
|
53
|
+
else child.kill(signal);
|
|
54
|
+
};
|
|
55
|
+
const onInterrupt = () => stop("SIGINT");
|
|
56
|
+
const onTerminate = () => stop("SIGTERM");
|
|
57
|
+
process.once("SIGINT", onInterrupt);
|
|
58
|
+
process.once("SIGTERM", onTerminate);
|
|
59
|
+
child.once("error", error => {
|
|
60
|
+
console.error(error.code === "ENOENT"
|
|
61
|
+
? cliTr("omo-web: PATH 中找不到 Bun。请从 https://bun.sh 安装。",
|
|
62
|
+
"omo-web: Bun was not found on PATH. Install Bun from https://bun.sh.")
|
|
63
|
+
: cliTr(`omo-web: 无法运行 Bun (${error.code ?? "?"})。`, `omo-web: Could not run Bun (${error.code ?? "?"}).`));
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
});
|
|
66
|
+
child.once("close", (code, signal) => {
|
|
67
|
+
process.removeListener("SIGINT", onInterrupt);
|
|
68
|
+
process.removeListener("SIGTERM", onTerminate);
|
|
69
|
+
process.exitCode ??= code ?? (signal === "SIGINT" ? 130 : signal === "SIGTERM" ? 143 : 1);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function createPasswordFile(path) {
|
|
74
|
+
try {
|
|
75
|
+
const password = randomBytes(32).toString("base64url");
|
|
76
|
+
if (process.platform === "win32") {
|
|
77
|
+
await createWindowsPasswordFile(path, password);
|
|
78
|
+
} else {
|
|
79
|
+
const fd = openSync(path, "wx", 0o600);
|
|
80
|
+
try {
|
|
81
|
+
writeFileSync(fd, `${password}\n`);
|
|
82
|
+
fchmodSync(fd, 0o600);
|
|
83
|
+
} finally {
|
|
84
|
+
closeSync(fd);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (!(error instanceof Error)) throw error;
|
|
89
|
+
console.error(error.code === "EEXIST"
|
|
90
|
+
? cliTr("omo-web: 目标已存在,未覆盖。", "omo-web: destination already exists; not overwritten.")
|
|
91
|
+
: cliTr("omo-web: 无法创建私密密码文件。请检查目标路径和权限。",
|
|
92
|
+
"omo-web: could not create a private password file. Check the destination and permissions."));
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
console.log(cliTr("密码文件已创建。请将 OMO_WEB_PASSWORD_FILE 设为该路径。",
|
|
96
|
+
"Password file created. Set OMO_WEB_PASSWORD_FILE to its path."));
|
|
97
|
+
return 0;
|
|
98
|
+
}
|