omo-web 0.1.1 → 0.1.3

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 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 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`.
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`), bind to an IPv4 interface, or set the HTTPS origin of a reverse proxy. Changes apply on the next start. Non-loopback listeners require HTTPS; passwordless remote access needs confirmation. The browser username is `omo`. Use at least 20 characters for remote access; shorter passwords are accepted with a warning.
19
+
20
+ For a local proxy or tunnel that handles HTTPS, keep the default upstream `http://127.0.0.1:4317`, preserve the original `Host`, and set the exact public origin (for example `https://web.example.com`) in **Proxy origin** or `OMO_WEB_PROXY_ORIGIN`.
19
21
 
20
22
  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
23
 
@@ -0,0 +1,12 @@
1
+ export const passwordPattern = /^[\x20-\x7e]{1,128}$/;
2
+ export const recommendedPasswordLength = 20;
3
+
4
+ export function parseProxyOrigin(value) {
5
+ try {
6
+ const url = new URL(value);
7
+ return url.protocol === "https:" && url.origin === value ? url : undefined;
8
+ } catch (error) {
9
+ if (!(error instanceof TypeError)) throw error;
10
+ return undefined;
11
+ }
12
+ }
@@ -7,7 +7,7 @@ import { createWindowsPasswordFile } from "./windows-password.js";
7
7
 
8
8
  const envKeys = [
9
9
  "OMO_WEB_HOST", "OMO_WEB_PASSWORD_FILE", "OMO_WEB_ALLOW_UNAUTHENTICATED",
10
- "OMO_WEB_ORIGIN", "OMO_WEB_TLS_CERT", "OMO_WEB_TLS_KEY",
10
+ "OMO_WEB_ORIGIN", "OMO_WEB_TLS_CERT", "OMO_WEB_TLS_KEY", "OMO_WEB_PROXY_ORIGIN",
11
11
  ];
12
12
  const keys = new Set([...envKeys, "savedPassword", "httpsEnabled"]);
13
13
 
package/bin/omo-web.js CHANGED
@@ -26,6 +26,8 @@ ${cliTr("需要 Bun 和 OmO Native (omo)。默认使用当前目录。", "Requir
26
26
  ${cliTr("用 OMO_WEB_WORKSPACES 和 OMO_WEB_PORT 设置目录和端口。", "Set directories and port with OMO_WEB_WORKSPACES and OMO_WEB_PORT.")}
27
27
  ${cliTr("在「访问设置」中选择网卡、设置密码和生成 SSL 自签证书。",
28
28
  "Use Access settings in the launcher to choose an interface, set a password, or generate an SSL certificate.")}
29
+ ${cliTr("内网穿透或反代可设置 OMO_WEB_PROXY_ORIGIN;代理需保留浏览器的 Host。",
30
+ "Set OMO_WEB_PROXY_ORIGIN for a tunnel or reverse proxy. Preserve the browser's Host.")}
29
31
  ${cliTr("非本机监听必须使用 HTTPS。建议设置访问密码。",
30
32
  "Non-loopback listening requires HTTPS. Set an access password for protection.")}
31
33
  ${cliTr("仅在受限私网或 VPN 使用无密码模式;脚本需显式设置 OMO_WEB_ALLOW_UNAUTHENTICATED=1。",
package/bin/tui.js CHANGED
@@ -4,6 +4,7 @@ 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 { parseProxyOrigin, passwordPattern, recommendedPasswordLength } from "./access-policy.js";
7
8
  import { loadLauncherSettings } from "./launcher-settings.js";
8
9
  import { generateCertificate } from "./launcher-tls.js";
9
10
  import { interfaceAddresses, isRemoteAddress, loopbackAddress, wildcardAddress } from "./listen-address.js";
@@ -15,6 +16,7 @@ const SHOW_CURSOR = `${CSI}?25h`;
15
16
  const HIDE_CURSOR = `${CSI}?25l`;
16
17
  const MAX_RECEIPT = 4096;
17
18
  const CONFIG_PREFIX = "OmO Web config: ";
19
+ const WARNING_PREFIX = "OmO Web warning: ";
18
20
  const START_MS = 30_000;
19
21
  const STOP_MS = 4_000;
20
22
  const REMOTE_WARNING = cliTr("警告:无密码保护", "Warning: No password protection");
@@ -143,7 +145,8 @@ export async function startTui({ entry, version }) {
143
145
  const settings = await loadLauncherSettings(process.env);
144
146
  let env = settings.effectiveEnv();
145
147
  const address = () => env.OMO_WEB_HOST ?? loopbackAddress;
146
- const unprotected = () => isRemoteAddress(address()) && !env.OMO_WEB_PASSWORD_FILE;
148
+ const proxyOrigin = () => env.OMO_WEB_PROXY_ORIGIN;
149
+ const unprotected = () => (isRemoteAddress(address()) || Boolean(proxyOrigin())) && !env.OMO_WEB_PASSWORD_FILE;
147
150
  const optedIn = () => env.OMO_WEB_ALLOW_UNAUTHENTICATED === "1";
148
151
  const hasPassword = () => Boolean(env.OMO_WEB_PASSWORD_FILE);
149
152
  const hasHttps = () => Boolean(env.OMO_WEB_TLS_CERT && env.OMO_WEB_TLS_KEY && env.OMO_WEB_ORIGIN);
@@ -156,6 +159,7 @@ export async function startTui({ entry, version }) {
156
159
  let selected = 0;
157
160
  let server;
158
161
  let url;
162
+ let startupWarning = "";
159
163
  let phase = "idle";
160
164
  let stopped = false;
161
165
  let notice = settings.warning;
@@ -197,7 +201,7 @@ export async function startTui({ entry, version }) {
197
201
  width: Math.min(72, (output.columns || 80) - 4),
198
202
  height: Math.max(1, (output.rows || 24) - 1),
199
203
  });
200
- const riskLines = width => [cliTr(`${address()} 无密码访问`, `${address()} without a password`), REMOTE_RISK]
204
+ const riskLines = width => [cliTr(`${proxyOrigin() || address()} 无密码访问`, `${proxyOrigin() || address()} without a password`), REMOTE_RISK]
201
205
  .flatMap(line => fold(line, width));
202
206
  const confirmationFits = ({ width, height }) => width >= 32 && riskLines(width).length + 2 <= height;
203
207
  function activeMenu(dimensions) {
@@ -210,6 +214,7 @@ export async function startTui({ entry, version }) {
210
214
  [cliTr("设置 / 修改密码", "Set / change password"), editPassword],
211
215
  [cliTr(`HTTPS:${switchLabel(hasHttps())}`, `HTTPS: ${switchLabel(hasHttps())}`), toggleHttps],
212
216
  [cliTr("生成 SSL 自签证书", "Generate self-signed SSL certificate"), editCertificate],
217
+ [cliTr(`代理入口:${proxyOrigin() || "关"}`, `Proxy origin: ${proxyOrigin() || "Off"}`), editProxyOrigin],
213
218
  backAction,
214
219
  ];
215
220
  if (phase === "networks") return [
@@ -251,6 +256,7 @@ export async function startTui({ entry, version }) {
251
256
  const message = notice ? fold(notice, width).slice(0, 2).map(line => ink("33;1", line)) : [];
252
257
  const warning = unprotected() && (optedIn() || server) && phase !== "confirming"
253
258
  ? fold(REMOTE_WARNING, width).map(line => ink("33;1", line)) : [];
259
+ if (phase === "ready" && startupWarning) warning.push(...fold(startupWarning, width).map(line => ink("33;1", line)));
254
260
  const risk = phase === "confirming" && menu.length > 1
255
261
  ? riskLines(width).map(line => ink("33;1", line)) : [];
256
262
  let editor;
@@ -357,15 +363,41 @@ export async function startTui({ entry, version }) {
357
363
  function editPassword() {
358
364
  draft = {
359
365
  masked: true, text: "", cursor: 0, title: cliTr("新密码", "New password"),
360
- hint: cliTr("20–128 个可打印 ASCII 字符,输入仅显示星号。", "20–128 printable ASCII characters. Input is masked."),
366
+ hint: cliTr("1–128 个可打印 ASCII 字符,建议至少 20 个。输入仅显示星号。",
367
+ "1–128 printable ASCII characters. Aim for at least 20; input is masked."),
361
368
  submit(password) {
362
- if (!/^[\x20-\x7e]{20,128}$/u.test(password)) {
363
- notice = cliTr("请使用 20–128 个可打印 ASCII 字符。", "Use 20–128 printable ASCII characters.");
369
+ if (!passwordPattern.test(password)) {
370
+ notice = cliTr("请使用 1–128 个可打印 ASCII 字符。", "Use 1–128 printable ASCII characters.");
364
371
  return;
365
372
  }
366
373
  runSetting(async () => {
367
374
  await settings.changePassword(password);
368
375
  draft = undefined;
376
+ if (password.length < recommendedPasswordLength) return cliTr(
377
+ "已保存。密码较短,建议使用至少 20 个字符。",
378
+ "Saved. Short password; use at least 20 characters for better protection.");
379
+ });
380
+ },
381
+ };
382
+ notice = "";
383
+ }
384
+
385
+ function editProxyOrigin() {
386
+ const text = proxyOrigin() ?? "";
387
+ draft = {
388
+ text, cursor: text.length, title: cliTr("外部 HTTPS 入口", "External HTTPS origin"),
389
+ hint: cliTr("例如 https://web.example.com;代理保留 Host。清空可关闭。",
390
+ "E.g. https://web.example.com. Preserve Host. Empty disables."),
391
+ submit(value) {
392
+ const origin = value === "" ? null : parseProxyOrigin(value);
393
+ if (origin === undefined) {
394
+ notice = cliTr("请输入不含路径或尾部斜杠的 HTTPS origin。",
395
+ "Enter an HTTPS origin without a path or trailing slash.");
396
+ return;
397
+ }
398
+ runSetting(async () => {
399
+ await settings.save({ OMO_WEB_PROXY_ORIGIN: origin?.origin ?? null, OMO_WEB_ALLOW_UNAUTHENTICATED: null });
400
+ draft = undefined;
369
401
  });
370
402
  },
371
403
  };
@@ -480,6 +512,7 @@ export async function startTui({ entry, version }) {
480
512
  phase = "starting";
481
513
  selected = 0;
482
514
  notice = "";
515
+ startupWarning = "";
483
516
  redraw();
484
517
  const serverEnv = {
485
518
  ...env,
@@ -506,6 +539,10 @@ export async function startTui({ entry, version }) {
506
539
  redraw();
507
540
  });
508
541
  receiveLines(child.stderr, line => {
542
+ if ((phase === "starting" || phase === "ready") && line.startsWith(WARNING_PREFIX)) {
543
+ startupWarning = safeText(stripVTControlCharacters(line.slice(WARNING_PREFIX.length))).trim();
544
+ redraw();
545
+ }
509
546
  if (phase !== "starting" || configMessage || !line.startsWith(CONFIG_PREFIX)) return;
510
547
  configMessage = safeText(stripVTControlCharacters(line.slice(CONFIG_PREFIX.length))).trim();
511
548
  });
@@ -1,5 +1,6 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { join, resolve } from "node:path";
3
+ import { passwordPattern } from "./access-policy.js";
3
4
 
4
5
  const identity = String.raw`
5
6
  $ErrorActionPreference = 'Stop'
@@ -56,7 +57,7 @@ export function readWindowsPasswordFile(path) {
56
57
  }
57
58
 
58
59
  export async function createWindowsPasswordFile(path, password) {
59
- if (!/^[\x20-\x7e]{20,128}$/.test(password) || /[\r\n]/.test(password)) throw new Error("Invalid password.");
60
+ if (!passwordPattern.test(password)) throw new Error("Invalid password.");
60
61
  await createWindowsPrivateFile(path, Buffer.from(`${password}\n`, "ascii"));
61
62
  }
62
63