omo-web 0.1.8 → 0.1.10

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,7 @@ 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`), 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.
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 sign-in page asks only for the password. Use at least 20 characters for remote access; shorter passwords are accepted with a warning.
19
19
 
20
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`.
21
21
 
package/bin/tui.js CHANGED
@@ -168,6 +168,11 @@ export async function startTui({ entry, version }) {
168
168
  let paint;
169
169
  const finished = new Promise(resolve => { settle = resolve; });
170
170
 
171
+ const browserUrl = () => {
172
+ if (!url) return;
173
+ return parseProxyOrigin(proxyOrigin())?.origin ??
174
+ (env.OMO_WEB_ORIGIN === new URL(url).origin ? env.OMO_WEB_ORIGIN : url);
175
+ };
171
176
  const directoriesLabel = cliTr("工作目录", "Working directories");
172
177
  const quitAction = [cliTr("退出", "Quit"), () => quit(0)];
173
178
  const stopAction = [cliTr("停止服务", "Stop web"), stopWeb];
@@ -238,21 +243,23 @@ export async function startTui({ entry, version }) {
238
243
  const [state, tone] = status[phase];
239
244
  const label = state();
240
245
  const build = fold(`v${version}`, 20)[0];
241
- const title = cliTr(" Web 监听 ", " WEB LISTENER ");
242
- const brand = "-- OmO Web ";
243
- const gap = width - textWidth(title) - textWidth(label) - textWidth(build) - 1;
244
- const boxed = width >= 44 && gap >= 2;
245
- const header = boxed ? [
246
- ink("36;1", `+${brand}${"-".repeat(width - brand.length)}+`),
247
- `|${title}${ink(tone, label)}${" ".repeat(gap)}${build} |`,
248
- ink("36", `+${"-".repeat(width)}+`),
249
- ] : fold(`OmO Web / ${label}`, width).map(line => ink(tone, line));
246
+ const brand = "OmO Web";
247
+ const gap = width - textWidth(`${brand} ${label}${build}`);
248
+ const header = gap >= 3 ? [
249
+ `${ink("36;1", brand)} ${ink(tone, label)}${" ".repeat(gap)}${ink("2", build)}`,
250
+ ink("2", "─".repeat(Math.floor(width / cells("─")))),
251
+ ] : fold(`${brand} / ${label}`, width).map(line => ink(tone, line));
250
252
  const short = text => fold(text, width)[0];
253
+ const addressRows = (title, href) => [ink("1", short(title)), ...fold(href, Math.max(2, width - 2)).map(row => ` ${row}`)];
251
254
  const editorTitle = draft && ink("1", short(draft.title));
252
255
  const menu = activeMenu(dimensions);
253
256
  const focus = Math.min(selected, menu.length - 1);
254
- const actions = menu.map(([action], index) => index === focus
255
- ? ink("7;1", short(`> ${action} `)) : short(` ${action}`));
257
+ const proxyAction = phase === "settings" && proxyOrigin();
258
+ const proxyOverflows = proxyAction && textWidth(` ${menu[5][0]}`) > width;
259
+ const actions = menu.map(([action], index) => {
260
+ const title = proxyOverflows && index === 5 ? cliTr("代理入口:开", "Proxy origin: On") : action;
261
+ return index === focus ? ink("36;1", short(`> ${title}`)) : short(` ${title}`);
262
+ });
256
263
  const message = notice ? fold(notice, width).slice(0, 2).map(line => ink("33;1", line)) : [];
257
264
  const warning = unprotected() && (optedIn() || server) && phase !== "confirming"
258
265
  ? fold(REMOTE_WARNING, width).map(line => ink("33;1", line)) : [];
@@ -261,6 +268,7 @@ export async function startTui({ entry, version }) {
261
268
  ? riskLines(width).map(line => ink("33;1", line)) : [];
262
269
  let editor;
263
270
  let lines;
271
+ let readyAddresses = [];
264
272
  if (draft) {
265
273
  editor = editorLine(draft.masked ? { ...draft, text: "*".repeat(draft.text.length) } : draft, Math.max(2, width - 2));
266
274
  lines = [...header, "", editorTitle, `> ${editor}`, "",
@@ -274,15 +282,18 @@ export async function startTui({ entry, version }) {
274
282
  } else if (phase === "settings" || phase === "networks") {
275
283
  const hint = phase === "networks" ? cliTr("选择监听网卡,不会修改防火墙规则。", "Select a listen interface; firewall rules are unchanged.")
276
284
  : cliTr("Enter 修改 · 保存后下次启动生效 · Esc 返回", "Enter to edit · Applies on the next start · Esc back");
277
- const origin = phase === "settings" && hasHttps() ? fold(cliTr(`HTTPS 地址:${env.OMO_WEB_ORIGIN}`,
278
- `HTTPS URL: ${env.OMO_WEB_ORIGIN}`), width) : [];
279
- lines = [...header, "", ...actions, "", ...message, ...origin, ...fold(hint, width)];
285
+ const origin = phase === "settings" && hasHttps() ? addressRows(cliTr("HTTPS 地址", "HTTPS URL"), env.OMO_WEB_ORIGIN) : [];
286
+ const proxy = proxyOverflows ? addressRows(cliTr("代理入口地址", "Proxy URL"), proxyAction) : [];
287
+ lines = [...header, "", ...actions, "", ...message, ...proxy, ...origin, ...fold(hint, width)];
280
288
  } else {
281
289
  const paths = activePaths();
282
- const urlRows = url ? fold(url, Math.max(2, width - 2)) : [];
283
290
  const pathCount = height >= 23 ? 4 : 2;
284
- const details = url ? [ink("1", short(cliTr("浏览器地址", "Browser URL"))), ...urlRows.slice(0, 2).map(line => ` ${line}`),
285
- ...(urlRows.length > 2 ? [" ..."] : []), ""] : [];
291
+ const browser = browserUrl();
292
+ const browserRows = browser ? addressRows(cliTr("浏览器地址", "Browser URL"), browser) : [];
293
+ const upstreamRows = browser && new URL(browser).href !== url
294
+ ? addressRows(cliTr("本地上游", "Local upstream"), url) : [];
295
+ readyAddresses = [browserRows, upstreamRows];
296
+ const details = browser ? [...browserRows, ...upstreamRows, ""] : [];
286
297
  const directories = paths.length ? paths.slice(0, pathCount).map(path => ` ${pathLabel(path, width - 2)}`)
287
298
  : [short(cliTr(" (未配置)", " (none configured)"))];
288
299
  if (paths.length > pathCount) directories.push(short(cliTr(` 另有 ${paths.length - pathCount} 个`, ` +${paths.length - pathCount} more`)));
@@ -305,7 +316,16 @@ export async function startTui({ entry, version }) {
305
316
  lines = [...risk, ...actions];
306
317
  } else {
307
318
  const compactStatus = ink(tone, short(`OmO Web / ${label}`));
308
- if (phase === "settings" || phase === "networks") {
319
+ const addressSpace = height - warning.length - 2;
320
+ if (phase === "ready" && readyAddresses[0].length - 1 <= addressSpace) {
321
+ const [browserRows, upstreamRows] = readyAddresses;
322
+ const addresses = browserRows.length + upstreamRows.length <= addressSpace ? readyAddresses.flat()
323
+ : browserRows.length <= addressSpace ? browserRows : browserRows.slice(1);
324
+ const controls = [compactStatus, ...warning, ...addresses];
325
+ const available = height - controls.length;
326
+ controls.push(...(available >= actions.length ? actions : [actions[focus]]));
327
+ lines = controls;
328
+ } else if (phase === "settings" || phase === "networks") {
309
329
  const slots = Math.max(1, height - 1 - message.length);
310
330
  const first = Math.max(0, Math.min(focus - Math.floor(slots / 2), actions.length - slots));
311
331
  lines = height > 1 ? [compactStatus, ...actions.slice(first, first + slots), ...message] : [actions[focus]];
@@ -597,11 +617,13 @@ export async function startTui({ entry, version }) {
597
617
 
598
618
  function openBrowser() {
599
619
  const current = server;
620
+ const href = browserUrl();
621
+ if (!href) return;
600
622
  const commands = {
601
- darwin: ["open", url],
602
- win32: ["rundll32.exe", "url.dll,FileProtocolHandler", url],
623
+ darwin: ["open", href],
624
+ win32: ["rundll32.exe", "url.dll,FileProtocolHandler", href],
603
625
  };
604
- const [command, ...args] = commands[process.platform] ?? ["xdg-open", url];
626
+ const [command, ...args] = commands[process.platform] ?? ["xdg-open", href];
605
627
  const browser = spawn(command, args, { stdio: "ignore", windowsHide: true, detached: !windows });
606
628
  const failed = () => {
607
629
  if (server !== current || phase !== "ready" || exitCode !== undefined) return;