omo-web 0.1.0 → 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/README.md +3 -1
- package/bin/launcher-settings.js +116 -0
- package/bin/launcher-tls.js +67 -0
- package/bin/listen-address.js +20 -0
- package/bin/omo-web.js +4 -2
- package/bin/tui.js +192 -42
- package/bin/windows-password.js +7 -4
- package/dist/server.js +27 -8
- package/package.json +2 -5
package/README.md
CHANGED
|
@@ -15,7 +15,9 @@ omo-web
|
|
|
15
15
|
|
|
16
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
17
|
|
|
18
|
-
In an interactive terminal, `omo-web` opens a keyboard-driven launcher. Use ↑/↓ and Enter to choose working directories
|
|
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.
|
|
19
21
|
|
|
20
22
|
OmO Web is licensed under MIT. The package includes the original notices for its third-party assets.
|
|
21
23
|
|
|
@@ -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/omo-web.js
CHANGED
|
@@ -24,8 +24,10 @@ if (args.length === 1 && args[0] === "--version") {
|
|
|
24
24
|
|
|
25
25
|
${cliTr("需要 Bun 和 OmO Native (omo)。默认使用当前目录。", "Requires Bun and OmO Native (omo). Defaults to the current directory.")}
|
|
26
26
|
${cliTr("用 OMO_WEB_WORKSPACES 和 OMO_WEB_PORT 设置目录和端口。", "Set directories and port with OMO_WEB_WORKSPACES and OMO_WEB_PORT.")}
|
|
27
|
-
${cliTr("
|
|
28
|
-
"
|
|
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.")}
|
|
29
31
|
${cliTr("仅在受限私网或 VPN 使用无密码模式;脚本需显式设置 OMO_WEB_ALLOW_UNAUTHENTICATED=1。",
|
|
30
32
|
"Use password-free access only on a restricted private network or VPN. Scripts must set OMO_WEB_ALLOW_UNAUTHENTICATED=1.")}
|
|
31
33
|
https://github.com/NekoCCN/OmO-Web/blob/main/docs/usage.md`);
|
package/bin/tui.js
CHANGED
|
@@ -4,6 +4,9 @@ import { statSync } from "node:fs";
|
|
|
4
4
|
import { delimiter, join, resolve } from "node:path";
|
|
5
5
|
import { emitKeypressEvents } from "node:readline";
|
|
6
6
|
import { stripVTControlCharacters } from "node:util";
|
|
7
|
+
import { loadLauncherSettings } from "./launcher-settings.js";
|
|
8
|
+
import { generateCertificate } from "./launcher-tls.js";
|
|
9
|
+
import { interfaceAddresses, isRemoteAddress, loopbackAddress, wildcardAddress } from "./listen-address.js";
|
|
7
10
|
import { cliTr } from "./locale.js";
|
|
8
11
|
|
|
9
12
|
const CSI = "\x1b[";
|
|
@@ -15,10 +18,8 @@ const CONFIG_PREFIX = "OmO Web config: ";
|
|
|
15
18
|
const START_MS = 30_000;
|
|
16
19
|
const STOP_MS = 4_000;
|
|
17
20
|
const REMOTE_WARNING = cliTr("警告:无密码保护", "Warning: No password protection");
|
|
18
|
-
const REMOTE_RISK =
|
|
19
|
-
|
|
20
|
-
cliTr("能连上的人可访问 OmO 和工作目录。", "Anyone who connects can access OmO and your working directories."),
|
|
21
|
-
];
|
|
21
|
+
const REMOTE_RISK = cliTr("能连上的人可访问 OmO 和工作目录。",
|
|
22
|
+
"Anyone who connects can access OmO and your working directories.");
|
|
22
23
|
const windows = process.platform === "win32";
|
|
23
24
|
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
24
25
|
const controls = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/gu;
|
|
@@ -139,17 +140,25 @@ export async function startTui({ entry, version }) {
|
|
|
139
140
|
const color = process.env.NO_COLOR === undefined;
|
|
140
141
|
const ink = (sgr, text) => color ? `${CSI}${sgr}m${text}${CSI}0m` : text;
|
|
141
142
|
const cwd = process.cwd();
|
|
142
|
-
const
|
|
143
|
-
|
|
143
|
+
const settings = await loadLauncherSettings(process.env);
|
|
144
|
+
let env = settings.effectiveEnv();
|
|
145
|
+
const address = () => env.OMO_WEB_HOST ?? loopbackAddress;
|
|
146
|
+
const unprotected = () => isRemoteAddress(address()) && !env.OMO_WEB_PASSWORD_FILE;
|
|
147
|
+
const optedIn = () => env.OMO_WEB_ALLOW_UNAUTHENTICATED === "1";
|
|
148
|
+
const hasPassword = () => Boolean(env.OMO_WEB_PASSWORD_FILE);
|
|
149
|
+
const hasHttps = () => Boolean(env.OMO_WEB_TLS_CERT && env.OMO_WEB_TLS_KEY && env.OMO_WEB_ORIGIN);
|
|
150
|
+
const switchLabel = on => on ? cliTr("开", "On") : cliTr("关", "Off");
|
|
144
151
|
let workspaces;
|
|
145
152
|
let draft;
|
|
153
|
+
let saving;
|
|
154
|
+
let networks = [];
|
|
146
155
|
let pasting = false;
|
|
147
156
|
let selected = 0;
|
|
148
157
|
let server;
|
|
149
158
|
let url;
|
|
150
159
|
let phase = "idle";
|
|
151
160
|
let stopped = false;
|
|
152
|
-
let notice =
|
|
161
|
+
let notice = settings.warning;
|
|
153
162
|
let exitCode;
|
|
154
163
|
let settle;
|
|
155
164
|
let paint;
|
|
@@ -158,8 +167,10 @@ export async function startTui({ entry, version }) {
|
|
|
158
167
|
const directoriesLabel = cliTr("工作目录", "Working directories");
|
|
159
168
|
const quitAction = [cliTr("退出", "Quit"), () => quit(0)];
|
|
160
169
|
const stopAction = [cliTr("停止服务", "Stop web"), stopWeb];
|
|
170
|
+
const backAction = [cliTr("返回", "Back"), () => go("idle")];
|
|
161
171
|
const menus = {
|
|
162
|
-
idle: [[cliTr("启动服务", "Start web"), requestStart], [directoriesLabel, editWorkspaces],
|
|
172
|
+
idle: [[cliTr("启动服务", "Start web"), requestStart], [directoriesLabel, editWorkspaces],
|
|
173
|
+
[cliTr("访问设置", "Access settings"), () => go("settings")], quitAction],
|
|
163
174
|
confirming: [
|
|
164
175
|
[cliTr("返回", "Back"), backFromConfirmation],
|
|
165
176
|
[cliTr("仅本次无密码启动", "Start once without a password"), () => startWeb(true)],
|
|
@@ -171,6 +182,8 @@ export async function startTui({ entry, version }) {
|
|
|
171
182
|
const status = {
|
|
172
183
|
idle: [() => notice ? cliTr("待机 / 见提示", "Idle / see notice")
|
|
173
184
|
: stopped ? cliTr("已停止", "Stopped") : cliTr("待机", "Idle"), "36"],
|
|
185
|
+
settings: [() => cliTr("访问设置", "Access settings"), "36;1"],
|
|
186
|
+
networks: [() => cliTr("监听地址", "Listen address"), "36;1"],
|
|
174
187
|
confirming: [() => cliTr("确认远程访问", "Confirm remote access"), "33;1"],
|
|
175
188
|
starting: [() => cliTr("启动中", "Starting"), "33;1"],
|
|
176
189
|
ready: [() => cliTr("监听中", "Listening"), "32;1"],
|
|
@@ -184,10 +197,30 @@ export async function startTui({ entry, version }) {
|
|
|
184
197
|
width: Math.min(72, (output.columns || 80) - 4),
|
|
185
198
|
height: Math.max(1, (output.rows || 24) - 1),
|
|
186
199
|
});
|
|
187
|
-
const riskLines = width =>
|
|
200
|
+
const riskLines = width => [cliTr(`${address()} 无密码访问`, `${address()} without a password`), REMOTE_RISK]
|
|
201
|
+
.flatMap(line => fold(line, width));
|
|
188
202
|
const confirmationFits = ({ width, height }) => width >= 32 && riskLines(width).length + 2 <= height;
|
|
189
|
-
|
|
190
|
-
|
|
203
|
+
function activeMenu(dimensions) {
|
|
204
|
+
if (phase === "settings") return [
|
|
205
|
+
[cliTr(`监听地址:${address()}`, `Listen address: ${address()}`), () => {
|
|
206
|
+
networks = interfaceAddresses();
|
|
207
|
+
go("networks");
|
|
208
|
+
}],
|
|
209
|
+
[cliTr(`密码:${switchLabel(hasPassword())}`, `Password: ${switchLabel(hasPassword())}`), togglePassword],
|
|
210
|
+
[cliTr("设置 / 修改密码", "Set / change password"), editPassword],
|
|
211
|
+
[cliTr(`HTTPS:${switchLabel(hasHttps())}`, `HTTPS: ${switchLabel(hasHttps())}`), toggleHttps],
|
|
212
|
+
[cliTr("生成 SSL 自签证书", "Generate self-signed SSL certificate"), editCertificate],
|
|
213
|
+
backAction,
|
|
214
|
+
];
|
|
215
|
+
if (phase === "networks") return [
|
|
216
|
+
[cliTr(`仅本机 (${loopbackAddress})`, `Loopback only (${loopbackAddress})`), () => chooseAddress(loopbackAddress)],
|
|
217
|
+
[cliTr(`全部 IPv4 网卡 (${wildcardAddress})`, `All IPv4 interfaces (${wildcardAddress})`), () => chooseAddress(wildcardAddress)],
|
|
218
|
+
...networks.map(({ name, address: ip, cidr }) =>
|
|
219
|
+
[`${cidr ?? ip} — ${name}`, () => chooseAddress(ip)]),
|
|
220
|
+
[cliTr("返回", "Back"), () => go("settings")],
|
|
221
|
+
];
|
|
222
|
+
return phase === "confirming" && !confirmationFits(dimensions) ? menus.confirming.slice(0, 1) : menus[phase];
|
|
223
|
+
}
|
|
191
224
|
|
|
192
225
|
function render() {
|
|
193
226
|
paint = undefined;
|
|
@@ -210,29 +243,34 @@ export async function startTui({ entry, version }) {
|
|
|
210
243
|
ink("36", `+${"-".repeat(width)}+`),
|
|
211
244
|
] : fold(`OmO Web / ${label}`, width).map(line => ink(tone, line));
|
|
212
245
|
const short = text => fold(text, width)[0];
|
|
213
|
-
const editorTitle = ink("1", short(
|
|
246
|
+
const editorTitle = draft && ink("1", short(draft.title));
|
|
214
247
|
const menu = activeMenu(dimensions);
|
|
215
248
|
const focus = Math.min(selected, menu.length - 1);
|
|
216
249
|
const actions = menu.map(([action], index) => index === focus
|
|
217
250
|
? ink("7;1", short(`> ${action} `)) : short(` ${action}`));
|
|
218
251
|
const message = notice ? fold(notice, width).slice(0, 2).map(line => ink("33;1", line)) : [];
|
|
219
|
-
const warning = unprotected && (optedIn || server) && phase !== "confirming"
|
|
252
|
+
const warning = unprotected() && (optedIn() || server) && phase !== "confirming"
|
|
220
253
|
? fold(REMOTE_WARNING, width).map(line => ink("33;1", line)) : [];
|
|
221
254
|
const risk = phase === "confirming" && menu.length > 1
|
|
222
255
|
? riskLines(width).map(line => ink("33;1", line)) : [];
|
|
223
256
|
let editor;
|
|
224
257
|
let lines;
|
|
225
258
|
if (draft) {
|
|
226
|
-
editor = editorLine(draft, Math.max(2, width - 2));
|
|
259
|
+
editor = editorLine(draft.masked ? { ...draft, text: "*".repeat(draft.text.length) } : draft, Math.max(2, width - 2));
|
|
227
260
|
lines = [...header, "", editorTitle, `> ${editor}`, "",
|
|
228
|
-
...fold(
|
|
229
|
-
`Separate paths with "${delimiter}". Empty uses the launch directory.`), width),
|
|
261
|
+
...fold(draft.hint, width),
|
|
230
262
|
...message, "", ...fold(cliTr("Enter 确认 / Esc 取消 / Ctrl+U 清空", "Enter confirm / Esc cancel / Ctrl+U clear"), width)];
|
|
231
263
|
} else if (phase === "confirming") {
|
|
232
264
|
lines = [...header, "", ...risk, "", ...actions, "",
|
|
233
265
|
...fold(menu.length > 1
|
|
234
266
|
? cliTr("↑/↓ 移动 / Enter 选择 / Esc 返回", "Up/Down move / Enter select / Esc back")
|
|
235
267
|
: cliTr("请放大终端以查看风险提示。", "Enlarge the terminal to review the risk."), width)];
|
|
268
|
+
} else if (phase === "settings" || phase === "networks") {
|
|
269
|
+
const hint = phase === "networks" ? cliTr("选择监听网卡,不会修改防火墙规则。", "Select a listen interface; firewall rules are unchanged.")
|
|
270
|
+
: cliTr("Enter 修改 · 保存后下次启动生效 · Esc 返回", "Enter to edit · Applies on the next start · Esc back");
|
|
271
|
+
const origin = phase === "settings" && hasHttps() ? fold(cliTr(`HTTPS 地址:${env.OMO_WEB_ORIGIN}`,
|
|
272
|
+
`HTTPS URL: ${env.OMO_WEB_ORIGIN}`), width) : [];
|
|
273
|
+
lines = [...header, "", ...actions, "", ...message, ...origin, ...fold(hint, width)];
|
|
236
274
|
} else {
|
|
237
275
|
const paths = activePaths();
|
|
238
276
|
const urlRows = url ? fold(url, Math.max(2, width - 2)) : [];
|
|
@@ -242,7 +280,11 @@ export async function startTui({ entry, version }) {
|
|
|
242
280
|
const directories = paths.length ? paths.slice(0, pathCount).map(path => ` ${pathLabel(path, width - 2)}`)
|
|
243
281
|
: [short(cliTr(" (未配置)", " (none configured)"))];
|
|
244
282
|
if (paths.length > pathCount) directories.push(short(cliTr(` 另有 ${paths.length - pathCount} 个`, ` +${paths.length - pathCount} more`)));
|
|
245
|
-
|
|
283
|
+
const connection = phase === "idle" ? [
|
|
284
|
+
short(cliTr(` ${address()} · ${hasHttps() ? "HTTPS" : "HTTP"} · 密码${switchLabel(hasPassword())}`,
|
|
285
|
+
` ${address()} · ${hasHttps() ? "HTTPS" : "HTTP"} · Password ${switchLabel(hasPassword())}`)),
|
|
286
|
+
] : [];
|
|
287
|
+
lines = [...header, ...warning, "", ...details, ...connection, ink("1", short(directoriesLabel)), ...directories,
|
|
246
288
|
"", ...actions, ...message, "", ...fold(cliTr("↑/↓ 移动 / Enter 选择 / Q 退出", "Up/Down move / Enter select / Q quit"), width)];
|
|
247
289
|
}
|
|
248
290
|
for (let blank = lines.lastIndexOf(""); lines.length > height && blank >= 0; blank = lines.lastIndexOf("")) {
|
|
@@ -257,7 +299,11 @@ export async function startTui({ entry, version }) {
|
|
|
257
299
|
lines = [...risk, ...actions];
|
|
258
300
|
} else {
|
|
259
301
|
const compactStatus = ink(tone, short(`OmO Web / ${label}`));
|
|
260
|
-
|
|
302
|
+
if (phase === "settings" || phase === "networks") {
|
|
303
|
+
const slots = Math.max(1, height - 1 - message.length);
|
|
304
|
+
const first = Math.max(0, Math.min(focus - Math.floor(slots / 2), actions.length - slots));
|
|
305
|
+
lines = height > 1 ? [compactStatus, ...actions.slice(first, first + slots), ...message] : [actions[focus]];
|
|
306
|
+
} else lines = actions.length > height ? [actions[focus]] : warning.length && height > 1
|
|
261
307
|
? [compactStatus, ...warning.slice(0, Math.max(1, height - 2)), actions[focus]]
|
|
262
308
|
: [...actions, ...message, compactStatus];
|
|
263
309
|
}
|
|
@@ -270,9 +316,120 @@ export async function startTui({ entry, version }) {
|
|
|
270
316
|
paint ??= setImmediate(render);
|
|
271
317
|
}
|
|
272
318
|
|
|
319
|
+
function go(next) {
|
|
320
|
+
phase = next;
|
|
321
|
+
selected = 0;
|
|
322
|
+
notice = "";
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function runSetting(action) {
|
|
326
|
+
notice = cliTr("正在保存…", "Saving…");
|
|
327
|
+
saving = Promise.resolve().then(action).then(message => {
|
|
328
|
+
env = settings.effectiveEnv();
|
|
329
|
+
notice = message ?? cliTr("已保存,下次启动生效。", "Saved. Applies on the next start.");
|
|
330
|
+
}).catch(error => {
|
|
331
|
+
if (!(error instanceof Error)) throw error;
|
|
332
|
+
notice = error.message;
|
|
333
|
+
}).finally(() => {
|
|
334
|
+
saving = undefined;
|
|
335
|
+
if (exitCode !== undefined) settle(exitCode);
|
|
336
|
+
else redraw();
|
|
337
|
+
});
|
|
338
|
+
redraw();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function chooseAddress(host) {
|
|
342
|
+
runSetting(async () => {
|
|
343
|
+
await settings.save({ OMO_WEB_HOST: host, OMO_WEB_ALLOW_UNAUTHENTICATED: null });
|
|
344
|
+
go("settings");
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function togglePassword() {
|
|
349
|
+
runSetting(async () => {
|
|
350
|
+
if (!await settings.setPasswordEnabled(!hasPassword())) {
|
|
351
|
+
editPassword();
|
|
352
|
+
return "";
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function editPassword() {
|
|
358
|
+
draft = {
|
|
359
|
+
masked: true, text: "", cursor: 0, title: cliTr("新密码", "New password"),
|
|
360
|
+
hint: cliTr("20–128 个可打印 ASCII 字符,输入仅显示星号。", "20–128 printable ASCII characters. Input is masked."),
|
|
361
|
+
submit(password) {
|
|
362
|
+
if (!/^[\x20-\x7e]{20,128}$/u.test(password)) {
|
|
363
|
+
notice = cliTr("请使用 20–128 个可打印 ASCII 字符。", "Use 20–128 printable ASCII characters.");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
runSetting(async () => {
|
|
367
|
+
await settings.changePassword(password);
|
|
368
|
+
draft = undefined;
|
|
369
|
+
});
|
|
370
|
+
},
|
|
371
|
+
};
|
|
372
|
+
notice = "";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function toggleHttps() {
|
|
376
|
+
runSetting(async () => {
|
|
377
|
+
if (!await settings.setHttpsEnabled(!hasHttps())) {
|
|
378
|
+
editCertificate();
|
|
379
|
+
return "";
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function editCertificate() {
|
|
385
|
+
let current;
|
|
386
|
+
try {
|
|
387
|
+
if (env.OMO_WEB_ORIGIN) current = new URL(env.OMO_WEB_ORIGIN).hostname;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
if (!(error instanceof TypeError)) throw error;
|
|
390
|
+
}
|
|
391
|
+
const text = current ?? (address() === wildcardAddress ? interfaceAddresses()[0]?.address ?? loopbackAddress : address());
|
|
392
|
+
draft = {
|
|
393
|
+
text, cursor: text.length, title: cliTr("证书主机名", "Certificate host"),
|
|
394
|
+
hint: cliTr("浏览器使用的 IP 或 DNS 名。需 OpenSSL;请核验证书。",
|
|
395
|
+
"Browser IP or DNS name. Requires OpenSSL. Verify the certificate."),
|
|
396
|
+
submit(host) {
|
|
397
|
+
runSetting(async () => {
|
|
398
|
+
const path = await generateCertificate(settings, host, Number(env.OMO_WEB_PORT ?? "4317"));
|
|
399
|
+
draft = undefined;
|
|
400
|
+
return cliTr(`证书已生成:${path}`, `Certificate generated: ${path}`);
|
|
401
|
+
});
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
notice = "";
|
|
405
|
+
}
|
|
406
|
+
|
|
273
407
|
function editWorkspaces() {
|
|
274
408
|
const text = configured() || cwd;
|
|
275
|
-
draft = {
|
|
409
|
+
draft = {
|
|
410
|
+
text, cursor: text.length, title: cliTr("编辑目录", "Edit directories"),
|
|
411
|
+
hint: cliTr(`用 "${delimiter}" 分隔路径,留空使用启动目录。`,
|
|
412
|
+
`Separate paths with "${delimiter}". Empty uses the launch directory.`),
|
|
413
|
+
submit: applyWorkspaces,
|
|
414
|
+
};
|
|
415
|
+
notice = "";
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function applyWorkspaces(text) {
|
|
419
|
+
const paths = text.split(delimiter).filter(Boolean).map(path => resolve(cwd, path));
|
|
420
|
+
for (const path of paths) {
|
|
421
|
+
try {
|
|
422
|
+
if (statSync(path, { throwIfNoEntry: false })?.isDirectory()) continue;
|
|
423
|
+
notice = cliTr(`不是目录:${path}`, `Not a directory: ${path}`);
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (!(error instanceof Error)) throw error;
|
|
426
|
+
notice = cliTr(`无法使用目录 (${error.code ?? "?"}):${path}`,
|
|
427
|
+
`Cannot use directory (${error.code ?? "?"}): ${path}`);
|
|
428
|
+
}
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
workspaces = paths.join(delimiter);
|
|
432
|
+
draft = undefined;
|
|
276
433
|
notice = "";
|
|
277
434
|
}
|
|
278
435
|
|
|
@@ -281,43 +438,34 @@ export async function startTui({ entry, version }) {
|
|
|
281
438
|
draft = undefined;
|
|
282
439
|
notice = "";
|
|
283
440
|
} else if (!pasting && (key.name === "return" || key.name === "enter")) {
|
|
284
|
-
|
|
285
|
-
for (const path of paths) {
|
|
286
|
-
try {
|
|
287
|
-
if (statSync(path, { throwIfNoEntry: false })?.isDirectory()) continue;
|
|
288
|
-
notice = cliTr(`不是目录:${path}`, `Not a directory: ${path}`);
|
|
289
|
-
} catch (error) {
|
|
290
|
-
if (!(error instanceof Error)) throw error;
|
|
291
|
-
notice = cliTr(`无法使用目录 (${error.code ?? "?"}):${path}`,
|
|
292
|
-
`Cannot use directory (${error.code ?? "?"}): ${path}`);
|
|
293
|
-
}
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
workspaces = paths.join(delimiter);
|
|
297
|
-
draft = undefined;
|
|
298
|
-
notice = "";
|
|
441
|
+
draft.submit(draft.text);
|
|
299
442
|
} else {
|
|
300
443
|
const { text: value, cursor } = draft;
|
|
301
444
|
const left = value.slice(0, cursor), right = value.slice(cursor);
|
|
302
445
|
const previous = () => cursor - (glyphs(left).at(-1)?.length ?? 0);
|
|
303
446
|
const next = () => cursor + (glyphs(right)[0]?.length ?? 0);
|
|
304
|
-
if (!pasting && key.ctrl && key.name === "u") draft
|
|
447
|
+
if (!pasting && key.ctrl && key.name === "u") Object.assign(draft, { text: "", cursor: 0 });
|
|
305
448
|
else if (!pasting && key.name === "left") draft.cursor = previous();
|
|
306
449
|
else if (!pasting && key.name === "right") draft.cursor = next();
|
|
307
450
|
else if (!pasting && key.name === "home") draft.cursor = 0;
|
|
308
451
|
else if (!pasting && key.name === "end") draft.cursor = value.length;
|
|
309
452
|
else if (!pasting && key.name === "backspace") {
|
|
310
|
-
draft
|
|
453
|
+
Object.assign(draft, { text: value.slice(0, previous()) + right, cursor: previous() });
|
|
311
454
|
} else if (!pasting && key.name === "delete") draft.text = left + value.slice(next());
|
|
312
455
|
else if (!key.ctrl && !key.meta && text && text === safeText(text) && value.length + text.length <= 8192) {
|
|
313
|
-
draft
|
|
456
|
+
Object.assign(draft, { text: left + text + right, cursor: cursor + text.length });
|
|
314
457
|
} else return;
|
|
315
458
|
notice = "";
|
|
316
459
|
}
|
|
317
460
|
}
|
|
318
461
|
|
|
319
462
|
function requestStart() {
|
|
320
|
-
if (
|
|
463
|
+
if (settings.warning) {
|
|
464
|
+
notice = settings.warning;
|
|
465
|
+
} else if (settings.hasListenerOverride && isRemoteAddress(address()) && !hasHttps()) {
|
|
466
|
+
notice = cliTr("非本机监听必须启用 HTTPS。请在访问设置中启用或生成证书。",
|
|
467
|
+
"Remote listening requires HTTPS. Enable it or generate a certificate in Access settings.");
|
|
468
|
+
} else if (unprotected() && !optedIn()) {
|
|
321
469
|
phase = "confirming";
|
|
322
470
|
selected = 0;
|
|
323
471
|
} else startWeb();
|
|
@@ -333,13 +481,13 @@ export async function startTui({ entry, version }) {
|
|
|
333
481
|
selected = 0;
|
|
334
482
|
notice = "";
|
|
335
483
|
redraw();
|
|
336
|
-
const
|
|
337
|
-
...
|
|
484
|
+
const serverEnv = {
|
|
485
|
+
...env,
|
|
338
486
|
...(workspaces === undefined ? {} : { OMO_WEB_WORKSPACES: workspaces }),
|
|
339
487
|
...(confirmed ? { OMO_WEB_ALLOW_UNAUTHENTICATED: "1" } : {}),
|
|
340
488
|
};
|
|
341
489
|
const child = spawn("bun", ["--no-env-file", entry], {
|
|
342
|
-
env, stdio: ["ignore", "pipe", "pipe"], detached: !windows, windowsHide: true,
|
|
490
|
+
env: serverEnv, stdio: ["ignore", "pipe", "pipe"], detached: !windows, windowsHide: true,
|
|
343
491
|
});
|
|
344
492
|
let errorMessage;
|
|
345
493
|
let configMessage;
|
|
@@ -434,12 +582,13 @@ export async function startTui({ entry, version }) {
|
|
|
434
582
|
if (exitCode !== undefined) return;
|
|
435
583
|
exitCode = code;
|
|
436
584
|
if (server) stopWeb();
|
|
437
|
-
else settle(code);
|
|
585
|
+
else if (!saving) settle(code);
|
|
438
586
|
}
|
|
439
587
|
|
|
440
588
|
function onKey(text, key) {
|
|
441
589
|
if (exitCode !== undefined || !key) return;
|
|
442
590
|
if (key.ctrl && key.name === "c") return quit(130);
|
|
591
|
+
if (saving) return;
|
|
443
592
|
if (key.name === "paste-start" || key.name === "paste-end") {
|
|
444
593
|
pasting = key.name === "paste-start";
|
|
445
594
|
return;
|
|
@@ -447,6 +596,7 @@ export async function startTui({ entry, version }) {
|
|
|
447
596
|
if (draft) editKey(text, key);
|
|
448
597
|
else if (pasting) return;
|
|
449
598
|
else if (key.name === "escape" && phase === "confirming") backFromConfirmation();
|
|
599
|
+
else if (key.name === "escape" && (phase === "settings" || phase === "networks")) go(phase === "settings" ? "idle" : "settings");
|
|
450
600
|
else if (key.name === "q" || key.name === "escape") return quit(0);
|
|
451
601
|
else {
|
|
452
602
|
const menu = activeMenu(viewport());
|
package/bin/windows-password.js
CHANGED
|
@@ -56,9 +56,13 @@ export function readWindowsPasswordFile(path) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export async function createWindowsPasswordFile(path, password) {
|
|
59
|
+
if (!/^[\x20-\x7e]{20,128}$/.test(password) || /[\r\n]/.test(password)) throw new Error("Invalid password.");
|
|
60
|
+
await createWindowsPrivateFile(path, Buffer.from(`${password}\n`, "ascii"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function createWindowsPrivateFile(path, bytes) {
|
|
59
64
|
await powershell(String.raw`
|
|
60
|
-
$
|
|
61
|
-
if ($password -notmatch '\A[\x20-\x7E]{20,128}\z') { throw 'Invalid password' }
|
|
65
|
+
$bytes = [Convert]::FromBase64String([Console]::In.ReadToEnd())
|
|
62
66
|
$acl = [System.Security.AccessControl.FileSecurity]::new()
|
|
63
67
|
$acl.SetOwner($sid)
|
|
64
68
|
$acl.SetAccessRuleProtection($true, $false)
|
|
@@ -67,10 +71,9 @@ export async function createWindowsPasswordFile(path, password) {
|
|
|
67
71
|
$file = [IO.FileStream]::new($path, [IO.FileMode]::CreateNew,
|
|
68
72
|
[System.Security.AccessControl.FileSystemRights]::Write, [IO.FileShare]::None, 4096, [IO.FileOptions]::None, $acl)
|
|
69
73
|
try {
|
|
70
|
-
$bytes = [Text.Encoding]::ASCII.GetBytes($password + [char]10)
|
|
71
74
|
$file.Write($bytes, 0, $bytes.Length)
|
|
72
75
|
} finally {
|
|
73
76
|
$file.Dispose()
|
|
74
77
|
}
|
|
75
|
-
`, path,
|
|
78
|
+
`, path, bytes.toString("base64"));
|
|
76
79
|
}
|
package/dist/server.js
CHANGED
|
@@ -11813,6 +11813,25 @@ import { open as open8 } from "fs/promises";
|
|
|
11813
11813
|
import { isIP } from "net";
|
|
11814
11814
|
import { createSecureContext } from "tls";
|
|
11815
11815
|
|
|
11816
|
+
// packaging/npm/listen-address.js
|
|
11817
|
+
import { networkInterfaces } from "os";
|
|
11818
|
+
var loopbackAddress = "127.0.0.1";
|
|
11819
|
+
var wildcardAddress = "0.0.0.0";
|
|
11820
|
+
function interfaceAddresses() {
|
|
11821
|
+
const entries = new Map;
|
|
11822
|
+
for (const [name, addresses] of Object.entries(networkInterfaces())) {
|
|
11823
|
+
for (const item of addresses ?? []) {
|
|
11824
|
+
if (item.family === "IPv4" && !item.internal && !entries.has(item.address)) {
|
|
11825
|
+
entries.set(item.address, { name, address: item.address, cidr: item.cidr });
|
|
11826
|
+
}
|
|
11827
|
+
}
|
|
11828
|
+
}
|
|
11829
|
+
return [...entries.values()];
|
|
11830
|
+
}
|
|
11831
|
+
function isRemoteAddress(host) {
|
|
11832
|
+
return host !== undefined && host !== loopbackAddress;
|
|
11833
|
+
}
|
|
11834
|
+
|
|
11816
11835
|
// packaging/npm/windows-password.js
|
|
11817
11836
|
import { execFile } from "child_process";
|
|
11818
11837
|
import { join as join8, resolve as resolve7 } from "path";
|
|
@@ -11893,7 +11912,6 @@ class WebAccessConfigError extends Error {
|
|
|
11893
11912
|
this.setting = setting;
|
|
11894
11913
|
}
|
|
11895
11914
|
}
|
|
11896
|
-
var hostSchema = _enum(["127.0.0.1", "0.0.0.0"]);
|
|
11897
11915
|
var passwordSchema = string2().regex(/^[\x20-\x7e]{20,128}$/);
|
|
11898
11916
|
var MAX_AUTH_FAILURES = 5;
|
|
11899
11917
|
var MAX_TRACKED_ADDRESSES = 1024;
|
|
@@ -11981,19 +11999,20 @@ function validateCertificate(cert, key, origin) {
|
|
|
11981
11999
|
}
|
|
11982
12000
|
}
|
|
11983
12001
|
async function loadWebAccess(env, port) {
|
|
11984
|
-
const host =
|
|
11985
|
-
if (!
|
|
11986
|
-
throw new WebAccessConfigError("OMO_WEB_HOST", cliTr("\
|
|
12002
|
+
const host = env.OMO_WEB_HOST ?? loopbackAddress;
|
|
12003
|
+
if (host !== loopbackAddress && host !== wildcardAddress && !interfaceAddresses().some((entry) => entry.address === host)) {
|
|
12004
|
+
throw new WebAccessConfigError("OMO_WEB_HOST", cliTr("\u8BF7\u9009\u62E9 127.0.0.1\u30010.0.0.0 \u6216\u672C\u673A\u7F51\u5361\u5DF2\u5206\u914D\u7684 IPv4 \u5730\u5740\u3002", "Use 127.0.0.1, 0.0.0.0, or an IPv4 address assigned to a local interface."));
|
|
12005
|
+
}
|
|
11987
12006
|
const {
|
|
11988
12007
|
OMO_WEB_PASSWORD_FILE: passwordFile,
|
|
11989
12008
|
OMO_WEB_ORIGIN: originSetting,
|
|
11990
12009
|
OMO_WEB_TLS_CERT: certFile,
|
|
11991
12010
|
OMO_WEB_TLS_KEY: keyFile
|
|
11992
12011
|
} = env;
|
|
11993
|
-
const publicBinding = host
|
|
12012
|
+
const publicBinding = isRemoteAddress(host);
|
|
11994
12013
|
const unprotected = publicBinding && passwordFile === undefined;
|
|
11995
12014
|
if (unprotected && env.OMO_WEB_ALLOW_UNAUTHENTICATED !== "1") {
|
|
11996
|
-
throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\
|
|
12015
|
+
throw new WebAccessConfigError("OMO_WEB_PASSWORD_FILE", cliTr("\u975E\u672C\u673A\u76D1\u542C\u5FC5\u987B\u914D\u7F6E\u5BC6\u7801\u6587\u4EF6\uFF0C\u6216\u663E\u5F0F\u8BBE\u7F6E OMO_WEB_ALLOW_UNAUTHENTICATED=1\u3002", "Non-loopback listening requires a password file or explicit OMO_WEB_ALLOW_UNAUTHENTICATED=1."));
|
|
11997
12016
|
}
|
|
11998
12017
|
let origin;
|
|
11999
12018
|
let tls;
|
|
@@ -12025,7 +12044,7 @@ async function loadWebAccess(env, port) {
|
|
|
12025
12044
|
}
|
|
12026
12045
|
const limiter = publicBinding && digest ? authFailureLimiter() : undefined;
|
|
12027
12046
|
return {
|
|
12028
|
-
hostname: host
|
|
12047
|
+
hostname: host,
|
|
12029
12048
|
origin,
|
|
12030
12049
|
tls,
|
|
12031
12050
|
unprotected,
|
|
@@ -12492,7 +12511,7 @@ var app = await startApp({
|
|
|
12492
12511
|
process.exit(1);
|
|
12493
12512
|
});
|
|
12494
12513
|
if (app.unprotected)
|
|
12495
|
-
console.warn(cliTr("\u8B66\u544A\uFF1A\
|
|
12514
|
+
console.warn(cliTr("\u8B66\u544A\uFF1A\u975E\u672C\u673A\u76D1\u542C\u672A\u8BBE\u5BC6\u7801\u3002\u80FD\u8BBF\u95EE\u6B64\u5730\u5740\u7684\u4EBA\u90FD\u80FD\u8BFB\u53D6\u4F1A\u8BDD\u5E76\u901A\u8FC7 OmO \u64CD\u4F5C\u672C\u673A\u3002\u4EC5\u5728\u53D7\u9650\u79C1\u7F51\u6216 VPN \u5185\u4F7F\u7528\u3002", "Warning: non-loopback listening without a password. Anyone who can reach this address can read sessions and run tools through OmO. Use only on a restricted private network or VPN."));
|
|
12496
12515
|
console.log(`OmO Web: ${app.url.href}`);
|
|
12497
12516
|
console.log(`${cliTr("\u5DE5\u4F5C\u76EE\u5F55", "Working directories")}: ${workspaces.join(", ")}`);
|
|
12498
12517
|
var halt = () => {
|
package/package.json
CHANGED
|
@@ -24,13 +24,10 @@
|
|
|
24
24
|
"workbench"
|
|
25
25
|
],
|
|
26
26
|
"files": [
|
|
27
|
-
"bin
|
|
28
|
-
"bin/tui.js",
|
|
29
|
-
"bin/locale.js",
|
|
30
|
-
"bin/windows-password.js",
|
|
27
|
+
"bin/*.js",
|
|
31
28
|
"dist/app.js",
|
|
32
29
|
"dist/server.js",
|
|
33
30
|
"public"
|
|
34
31
|
],
|
|
35
|
-
"version": "0.1.
|
|
32
|
+
"version": "0.1.1"
|
|
36
33
|
}
|