@gruu6y/page-clean-login 0.2.2 → 0.2.4
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.en.md +2 -0
- package/README.md +2 -0
- package/lib/agent-cli.mjs +31 -1
- package/lib/browser-environment.mjs +23 -0
- package/lib/browser-launcher.mjs +84 -8
- package/lib/camoufox-loader.mjs +13 -2
- package/lib/magpie-plugins.mjs +64 -4
- package/lib/native-signin.mjs +14 -3
- package/lib/provider-sources.mjs +27 -10
- package/lib/proxy-score.mjs +3 -1
- package/lib/server.mjs +21 -9
- package/lib/signin-flow.mjs +32 -4
- package/package.json +1 -1
- package/ui/app.js +17 -6
package/README.en.md
CHANGED
|
@@ -232,6 +232,7 @@ Accounts and exits are fully drivable from the command line, with no page open:
|
|
|
232
232
|
|
|
233
233
|
```sh
|
|
234
234
|
bun bin/clean-login.mjs proxies add home-01 http 127.0.0.1 7102 # store an exit
|
|
235
|
+
bun bin/clean-login.mjs proxies update <proxyId> --host 10.0.0.2 --exit-port 1080 # change an exit (a connection change clears probe results)
|
|
235
236
|
bun bin/clean-login.mjs accounts import plan # preview magpie's accounts
|
|
236
237
|
bun bin/clean-login.mjs accounts import run --only <provider>#<recordId>
|
|
237
238
|
bun bin/clean-login.mjs accounts exit <provider> <key> --mode custom --proxy <proxyId>
|
|
@@ -283,6 +284,7 @@ Run `bun bin/clean-login.mjs help` for the full command list. A remote service (
|
|
|
283
284
|
- No telemetry and no account. The only network calls are the ones you start: proxy tests, the trust-score page, the identity-check page, the runtime download, and the provider's own sign-in.
|
|
284
285
|
- Proxies, accounts, fingerprints and browser profiles live in `~/.config/magpie/magpie-clean-login/` (override with `MAGPIE_CLEAN_LOGIN_DATA`; the config root itself with `MAGPIE_CONFIG_DIR`). The market catalog is read from `~/.cache/magpie/` (`MAGPIE_CACHE_DIR`). Hosted-renewal switches and recent records live in `renew-hosting.json` in that same directory; it holds switches, times and outcomes, never a credential.
|
|
285
286
|
- The login browser unpacks to `%LOCALAPPDATA%/magpie-clean-login/camoufox` on Windows, `~/Library/Caches/magpie-clean-login/camoufox` on macOS, and `$XDG_CACHE_HOME/magpie-clean-login/camoufox` on Linux (all overridable with `MAGPIE_CLEAN_LOGIN_BROWSER_DIR`).
|
|
287
|
+
- On Linux without `DISPLAY` or `WAYLAND_DISPLAY`, opt into an X11 display (such as `:99`) with `MAGPIE_CLEAN_LOGIN_DISPLAY`; to opt into the system fontconfig instead of Camoufox's stock anti-fingerprinting config, set `MAGPIE_CLEAN_LOGIN_FONTCONFIG=system` (`/etc/fonts/fonts.conf`) or a custom `fonts.conf` path (an existing `FONTCONFIG_FILE` is never overridden).
|
|
286
288
|
- Stored proxy passwords never reach the page and are never logged. The page token is per-process and exists only in the page the service serves.
|
|
287
289
|
|
|
288
290
|
<a id="contributing"></a>
|
package/README.md
CHANGED
|
@@ -233,6 +233,7 @@ bun bin/clean-login.mjs assets # 只看已登记的资产(邮箱、手机
|
|
|
233
233
|
|
|
234
234
|
```sh
|
|
235
235
|
bun bin/clean-login.mjs proxies add 家宽01 http 127.0.0.1 7102 # 存一条出口
|
|
236
|
+
bun bin/clean-login.mjs proxies update <proxyId> --host 10.0.0.2 --exit-port 1080 # 改一条出口(改连接会清空探测结果)
|
|
236
237
|
bun bin/clean-login.mjs accounts import plan # 预览 magpie 已有的账号
|
|
237
238
|
bun bin/clean-login.mjs accounts import run --only <provider>#<recordId>
|
|
238
239
|
bun bin/clean-login.mjs accounts exit <provider> <key> --mode custom --proxy <proxyId>
|
|
@@ -288,6 +289,7 @@ bun bin/clean-login.mjs score cancel # 停掉信任度评分
|
|
|
288
289
|
- 没有遥测,也没有账号。唯一的网络调用就是你自己发起的那些:代理测试、信任分页面、身份检测页面、运行时下载,以及供应商自己的登录。
|
|
289
290
|
- 代理、账号、指纹和浏览器配置都在 `~/.config/magpie/magpie-clean-login/`(用 `MAGPIE_CLEAN_LOGIN_DATA` 覆盖;配置根本身用 `MAGPIE_CONFIG_DIR`)。市场目录从 `~/.cache/magpie/` 读取(`MAGPIE_CACHE_DIR`)。续期托管的开通状态与最近记录在同一个目录下的 `renew-hosting.json`,里面只有开关、时间和结果,没有任何凭据。
|
|
290
291
|
- 登录浏览器在 Windows 上解包到 `%LOCALAPPDATA%/magpie-clean-login/camoufox`,在 macOS 上解包到 `~/Library/Caches/magpie-clean-login/camoufox`,在 Linux 上解包到 `$XDG_CACHE_HOME/magpie-clean-login/camoufox`(均可用 `MAGPIE_CLEAN_LOGIN_BROWSER_DIR` 覆盖)。
|
|
292
|
+
- 在无界面的 Linux 上,若未设置 `DISPLAY` 和 `WAYLAND_DISPLAY` 且需要把登录浏览器指向指定 X11 显示(如 `:99`),可用 `MAGPIE_CLEAN_LOGIN_DISPLAY` 显式开启;若需改用系统字体配置而非 Camoufox 默认的防指纹字体配置,可设置 `MAGPIE_CLEAN_LOGIN_FONTCONFIG=system`(`/etc/fonts/fonts.conf`)或自定义的 `fonts.conf` 路径(不会覆盖已有的 `FONTCONFIG_FILE`)。
|
|
291
293
|
- 存下来的代理密码不会到达页面,也不会写进日志。页面 token 每进程一份,只存在于服务送出的页面里。
|
|
292
294
|
|
|
293
295
|
<a id="contributing"></a>
|
package/lib/agent-cli.mjs
CHANGED
|
@@ -98,6 +98,9 @@ const VALUE_FLAGS = new Set([
|
|
|
98
98
|
"text",
|
|
99
99
|
"input",
|
|
100
100
|
"only",
|
|
101
|
+
"name",
|
|
102
|
+
"host",
|
|
103
|
+
"exit-port",
|
|
101
104
|
]);
|
|
102
105
|
|
|
103
106
|
export function parseArgs(argv) {
|
|
@@ -281,6 +284,8 @@ export function usage() {
|
|
|
281
284
|
" providers Merged provider cards, compact.",
|
|
282
285
|
" proxies Stored proxies, compact (no credentials).",
|
|
283
286
|
" proxies add <name> <type> <host> <port> Store an exit (type http|https|socks5).",
|
|
287
|
+
" proxies update <id> [--name N] [--type T] [--host H] [--exit-port P] [--user U] [--pass P]",
|
|
288
|
+
" Change an exit; a connection change clears its per-provider latency and score.",
|
|
284
289
|
" proxies delete <proxyId> Remove a stored exit.",
|
|
285
290
|
" proxies targets The endpoints a proxy probe can be aimed at.",
|
|
286
291
|
" accounts Known accounts and their signed-in state.",
|
|
@@ -329,7 +334,8 @@ export function usage() {
|
|
|
329
334
|
" --only KEY Pick one account out of an import plan (repeatable).",
|
|
330
335
|
" --mode M Exit mode for accounts exit: inherit, direct or custom.",
|
|
331
336
|
" --note TEXT Note for assets add/update, or the report note.",
|
|
332
|
-
" --user / --pass Optional credentials for proxies add.",
|
|
337
|
+
" --user / --pass Optional credentials for proxies add and update.",
|
|
338
|
+
" --exit-port N Exit port for proxies update (--port is the service port).",
|
|
333
339
|
" --single Replace the single stored account for this provider.",
|
|
334
340
|
"",
|
|
335
341
|
].join("\n");
|
|
@@ -403,6 +409,30 @@ export async function runCli(argv, {
|
|
|
403
409
|
noSurplus(positional, 3);
|
|
404
410
|
return emit(await del(`/api/proxies/${encodeURIComponent(required(positional[2] ?? options.id, "<proxyId>"))}`), options, write);
|
|
405
411
|
}
|
|
412
|
+
if (action === "update") {
|
|
413
|
+
// Only fields the caller spelled out are sent, so a later read cannot
|
|
414
|
+
// mistake an omitted flag for a request to clear it. The exit's port
|
|
415
|
+
// goes through --exit-port because --port already means the service
|
|
416
|
+
// port (the same ambiguity the positional port on `proxies add`
|
|
417
|
+
// avoids). The id is required first so a bare `proxies update` reports
|
|
418
|
+
// the missing argument, not "nothing to update".
|
|
419
|
+
const id = required(positional[2] ?? options.id, "<proxyId>");
|
|
420
|
+
const body = {};
|
|
421
|
+
if (Object.prototype.hasOwnProperty.call(options, "name")) body.name = String(options.name);
|
|
422
|
+
if (Object.prototype.hasOwnProperty.call(options, "type")) body.type = String(options.type);
|
|
423
|
+
if (Object.prototype.hasOwnProperty.call(options, "host")) body.host = String(options.host);
|
|
424
|
+
if (Object.prototype.hasOwnProperty.call(options, "exit-port")) body.port = String(options["exit-port"]);
|
|
425
|
+
if (Object.prototype.hasOwnProperty.call(options, "user")) body.username = String(options.user);
|
|
426
|
+
if (Object.prototype.hasOwnProperty.call(options, "pass")) body.password = String(options.pass);
|
|
427
|
+
if (!Object.keys(body).length) {
|
|
428
|
+
throw new CliError(
|
|
429
|
+
"Nothing to update; pass --name, --type, --host, --exit-port, --user or --pass.",
|
|
430
|
+
{ code: "bad_command" },
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
noSurplus(positional, 3);
|
|
434
|
+
return emit(await patch(`/api/proxies/${encodeURIComponent(id)}`, body), options, write);
|
|
435
|
+
}
|
|
406
436
|
if (action === "targets") {
|
|
407
437
|
noSurplus(positional, 2);
|
|
408
438
|
return emit(await get("/api/proxy-targets"), options, write);
|
|
@@ -811,6 +811,29 @@ export function createEnvironmentManager({
|
|
|
811
811
|
: null,
|
|
812
812
|
modelVerified: result?.modelVerified === true,
|
|
813
813
|
};
|
|
814
|
+
// The installer's byte total was measured before this record existed, so
|
|
815
|
+
// the stored count must add the record's own size — otherwise the
|
|
816
|
+
// reported installedBytes sits ~350 B short of what is actually on disk.
|
|
817
|
+
// An older record being replaced was part of that measurement and has to
|
|
818
|
+
// come back out. The file grows with the digit count of `bytes`, so the
|
|
819
|
+
// corrected value is solved to a fixed point in a couple of render rounds.
|
|
820
|
+
if (payload.bytes !== null) {
|
|
821
|
+
let previousSize = 0;
|
|
822
|
+
try {
|
|
823
|
+
previousSize = (await stat(recordFile)).size;
|
|
824
|
+
} catch {
|
|
825
|
+
// No record on disk yet: nothing was counted twice.
|
|
826
|
+
}
|
|
827
|
+
const base = payload.bytes - previousSize;
|
|
828
|
+
let bytes = base;
|
|
829
|
+
for (let round = 0; round < 3; round += 1) {
|
|
830
|
+
payload.bytes = bytes;
|
|
831
|
+
const size = Buffer.byteLength(`${JSON.stringify(payload, null, 2)}\n`);
|
|
832
|
+
if (base + size === bytes) break;
|
|
833
|
+
bytes = base + size;
|
|
834
|
+
}
|
|
835
|
+
payload.bytes = bytes;
|
|
836
|
+
}
|
|
814
837
|
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
815
838
|
const temp = join(dir, `.${INSTALL_RECORD_NAME}.${process.pid}.${randomUUID()}.tmp`);
|
|
816
839
|
await writeFile(temp, `${JSON.stringify(payload, null, 2)}\n`, { mode: 0o600 });
|
package/lib/browser-launcher.mjs
CHANGED
|
@@ -20,10 +20,11 @@
|
|
|
20
20
|
// browser does not add per-launch canvas noise on top of the pinned identity.
|
|
21
21
|
|
|
22
22
|
import { fork } from "node:child_process";
|
|
23
|
+
import { existsSync } from "node:fs";
|
|
23
24
|
import { mkdir, stat } from "node:fs/promises";
|
|
24
25
|
import { fileURLToPath } from "node:url";
|
|
25
|
-
import { browserEnvironmentRoot, fingerprintModelDir } from "./browser-environment.mjs";
|
|
26
|
-
import { loadCamoufoxSandboxed } from "./camoufox-loader.mjs";
|
|
26
|
+
import { BROWSER_DIR_ENV, browserEnvironmentRoot, fingerprintModelDir } from "./browser-environment.mjs";
|
|
27
|
+
import { camoufoxCacheEnv, loadCamoufoxSandboxed } from "./camoufox-loader.mjs";
|
|
27
28
|
|
|
28
29
|
const HOST_PATH = fileURLToPath(new URL("./signin-browser-host.mjs", import.meta.url));
|
|
29
30
|
const SCORE_HOST_PATH = fileURLToPath(new URL("./score-browser-host.mjs", import.meta.url));
|
|
@@ -55,6 +56,58 @@ export function navigationWarning(error) {
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
export const DISPLAY_ENV = "MAGPIE_CLEAN_LOGIN_DISPLAY";
|
|
60
|
+
export const FONTCONFIG_ENV = "MAGPIE_CLEAN_LOGIN_FONTCONFIG";
|
|
61
|
+
export const SYSTEM_FONTCONFIG_PATH = "/etc/fonts/fonts.conf";
|
|
62
|
+
|
|
63
|
+
// The env the forked browser hosts run under. FPGEN_DATA_DIR is the name
|
|
64
|
+
// fpgen-js actually reads (only a fallback — the host also calls setModelDir
|
|
65
|
+
// from its launch input). camoufoxCacheEnv repeats the import-time cache
|
|
66
|
+
// redirect inside the child: without it the spawned process resolves the real
|
|
67
|
+
// user cache (LOCALAPPDATA / XDG_CACHE_HOME) and runtime writes like
|
|
68
|
+
// fontconfig's escape the sandbox. Because those overrides would also move
|
|
69
|
+
// browserEnvironmentRoot() inside the host, BROWSER_DIR_ENV is pinned so the
|
|
70
|
+
// host still finds the same sandbox root the parent computed.
|
|
71
|
+
//
|
|
72
|
+
// On Linux, DISPLAY and FONTCONFIG_FILE are explicit opt-ins via DISPLAY_ENV
|
|
73
|
+
// and FONTCONFIG_ENV: we never silently probe /tmp/.X11-unix/X99 or replace
|
|
74
|
+
// Camoufox's stock anti-fingerprinting fontconfig by default, and we never
|
|
75
|
+
// override an existing DISPLAY, WAYLAND_DISPLAY, or FONTCONFIG_FILE.
|
|
76
|
+
export function hostEnv(
|
|
77
|
+
env,
|
|
78
|
+
sandboxRoot,
|
|
79
|
+
modelDir,
|
|
80
|
+
platform = process.platform,
|
|
81
|
+
{ existsSync: exists = existsSync } = {},
|
|
82
|
+
) {
|
|
83
|
+
const baseEnv = env ?? {};
|
|
84
|
+
let display = {};
|
|
85
|
+
let fontEnv = {};
|
|
86
|
+
if (platform === "linux") {
|
|
87
|
+
if (!baseEnv.DISPLAY && !baseEnv.WAYLAND_DISPLAY) {
|
|
88
|
+
const requestedDisplay =
|
|
89
|
+
typeof baseEnv[DISPLAY_ENV] === "string" ? baseEnv[DISPLAY_ENV].trim() : "";
|
|
90
|
+
if (requestedDisplay) display = { DISPLAY: requestedDisplay };
|
|
91
|
+
}
|
|
92
|
+
if (!baseEnv.FONTCONFIG_FILE) {
|
|
93
|
+
const fc =
|
|
94
|
+
typeof baseEnv[FONTCONFIG_ENV] === "string" ? baseEnv[FONTCONFIG_ENV].trim() : "";
|
|
95
|
+
if (fc && fc.toLowerCase() !== "off") {
|
|
96
|
+
const candidate = fc.toLowerCase() === "system" ? SYSTEM_FONTCONFIG_PATH : fc;
|
|
97
|
+
if (exists(candidate)) fontEnv = { FONTCONFIG_FILE: candidate };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...baseEnv,
|
|
103
|
+
...display,
|
|
104
|
+
...fontEnv,
|
|
105
|
+
...camoufoxCacheEnv(sandboxRoot, platform),
|
|
106
|
+
[BROWSER_DIR_ENV]: sandboxRoot,
|
|
107
|
+
FPGEN_DATA_DIR: modelDir,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
58
111
|
export class SignInBrowserError extends Error {
|
|
59
112
|
constructor(code, message, status = 500) {
|
|
60
113
|
super(message);
|
|
@@ -314,6 +367,7 @@ export async function launchSignInBrowser({
|
|
|
314
367
|
// pinned fingerprint and the same exit, but no window on the desktop.
|
|
315
368
|
headless = false,
|
|
316
369
|
env = process.env,
|
|
370
|
+
platform = process.platform,
|
|
317
371
|
deps = {},
|
|
318
372
|
} = {}) {
|
|
319
373
|
if (typeof url !== "string" || !url) {
|
|
@@ -347,10 +401,13 @@ export async function launchSignInBrowser({
|
|
|
347
401
|
child = spawnHost(deps.hostPath ?? HOST_PATH, [], {
|
|
348
402
|
stdio: ["pipe", "ignore", "pipe", "ipc"],
|
|
349
403
|
windowsHide: false,
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
404
|
+
env: hostEnv(
|
|
405
|
+
env,
|
|
406
|
+
browserEnvironmentRoot(env),
|
|
407
|
+
resolvedModelDir,
|
|
408
|
+
platform,
|
|
409
|
+
deps.existsSync ? { existsSync: deps.existsSync } : undefined,
|
|
410
|
+
),
|
|
354
411
|
});
|
|
355
412
|
} catch (error) {
|
|
356
413
|
throw new SignInBrowserError(
|
|
@@ -503,6 +560,11 @@ export async function launchScoreBrowser({
|
|
|
503
560
|
// start must not eat the page's own deadline.
|
|
504
561
|
launchTimeoutMs = 60_000,
|
|
505
562
|
env = process.env,
|
|
563
|
+
platform = process.platform,
|
|
564
|
+
// A display-less Linux box cannot show a window; the headed launch fails
|
|
565
|
+
// there outright. Headless is the default in that case only — wherever a
|
|
566
|
+
// display exists (and on win32/darwin always) the window still opens.
|
|
567
|
+
headless = platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY,
|
|
506
568
|
deps = {},
|
|
507
569
|
} = {}) {
|
|
508
570
|
if (typeof url !== "string" || !url) {
|
|
@@ -527,6 +589,7 @@ export async function launchScoreBrowser({
|
|
|
527
589
|
timeoutMs,
|
|
528
590
|
// Never reuse timeoutMs: this is the first-navigation deadline.
|
|
529
591
|
navTimeoutMs: navigationTimeoutMs,
|
|
592
|
+
headless: Boolean(headless),
|
|
530
593
|
});
|
|
531
594
|
|
|
532
595
|
const spawnHost = deps.fork ?? fork;
|
|
@@ -535,7 +598,13 @@ export async function launchScoreBrowser({
|
|
|
535
598
|
child = spawnHost(deps.hostPath ?? SCORE_HOST_PATH, [], {
|
|
536
599
|
stdio: ["pipe", "ignore", "pipe", "ipc"],
|
|
537
600
|
windowsHide: false,
|
|
538
|
-
env:
|
|
601
|
+
env: hostEnv(
|
|
602
|
+
env,
|
|
603
|
+
browserEnvironmentRoot(env),
|
|
604
|
+
resolvedModelDir,
|
|
605
|
+
platform,
|
|
606
|
+
deps.existsSync ? { existsSync: deps.existsSync } : undefined,
|
|
607
|
+
),
|
|
539
608
|
});
|
|
540
609
|
} catch (error) {
|
|
541
610
|
throw new ScoreBrowserError(
|
|
@@ -699,6 +768,7 @@ export async function launchIdentityCheckBrowser({
|
|
|
699
768
|
timeoutMs,
|
|
700
769
|
launchTimeoutMs = 60_000,
|
|
701
770
|
env = process.env,
|
|
771
|
+
platform = process.platform,
|
|
702
772
|
deps = {},
|
|
703
773
|
} = {}) {
|
|
704
774
|
if (typeof url !== "string" || !url) {
|
|
@@ -732,7 +802,13 @@ export async function launchIdentityCheckBrowser({
|
|
|
732
802
|
child = spawnHost(deps.hostPath ?? IDENTITY_HOST_PATH, [], {
|
|
733
803
|
stdio: ["pipe", "ignore", "pipe", "ipc"],
|
|
734
804
|
windowsHide: false,
|
|
735
|
-
env:
|
|
805
|
+
env: hostEnv(
|
|
806
|
+
env,
|
|
807
|
+
browserEnvironmentRoot(env),
|
|
808
|
+
resolvedModelDir,
|
|
809
|
+
platform,
|
|
810
|
+
deps.existsSync ? { existsSync: deps.existsSync } : undefined,
|
|
811
|
+
),
|
|
736
812
|
});
|
|
737
813
|
} catch (error) {
|
|
738
814
|
throw new SignInBrowserError(
|
package/lib/camoufox-loader.mjs
CHANGED
|
@@ -30,13 +30,24 @@ import { basename, dirname, join, resolve, sep } from "node:path";
|
|
|
30
30
|
// (~/Library/Caches/camoufox) is made a symlink to <sandbox>/camoufox;
|
|
31
31
|
// a pre-existing real directory is migrated into the sandbox first so its
|
|
32
32
|
// bytes stay reachable through the link.
|
|
33
|
+
// The env-var half of the redirect, with no side effects. Forked browser
|
|
34
|
+
// hosts need exactly these overrides in their process env so a runtime write
|
|
35
|
+
// (fontconfig, camoufox's own cache) lands under the same sandbox root the
|
|
36
|
+
// import-time redirect uses. darwin returns {} because homedir is
|
|
37
|
+
// unredirectable — the install symlink does the work there.
|
|
38
|
+
export function camoufoxCacheEnv(dir, platform = process.platform) {
|
|
39
|
+
if (platform === "darwin") return {};
|
|
40
|
+
if (platform === "win32") return { LOCALAPPDATA: dir };
|
|
41
|
+
return { XDG_CACHE_HOME: dir };
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
function cacheRedirect(dir, env, platform) {
|
|
34
45
|
if (platform === "darwin") {
|
|
35
46
|
ensureDarwinInstallSymlink(dir);
|
|
36
47
|
return null; // homedir is unredirectable; the symlink does the work
|
|
37
48
|
}
|
|
38
|
-
|
|
39
|
-
return { key
|
|
49
|
+
const [key, value] = Object.entries(camoufoxCacheEnv(dir, platform))[0];
|
|
50
|
+
return { key, value };
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
export class CamoufoxSandboxError extends Error {
|
package/lib/magpie-plugins.mjs
CHANGED
|
@@ -210,6 +210,31 @@ function normalizeMethod(method) {
|
|
|
210
210
|
return classifyMethod(method);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
const PLUGIN_DIR_FORBIDDEN = /[\u0000-\u001f\u007f:]/;
|
|
214
|
+
|
|
215
|
+
// Validates and normalizes a scanned plugin's relative directory under
|
|
216
|
+
// `node_modules` into a bounded POSIX path, rejecting traversals, absolute
|
|
217
|
+
// paths, drive prefixes, control chars, and nested dependency subpaths.
|
|
218
|
+
export function normalizePluginDir(value) {
|
|
219
|
+
if (typeof value !== "string" || !value || value.length > 256) return null;
|
|
220
|
+
if (PLUGIN_DIR_FORBIDDEN.test(value)) return null;
|
|
221
|
+
const posix = value.replaceAll("\\", "/");
|
|
222
|
+
if (posix.startsWith("/") || posix.endsWith("/")) return null;
|
|
223
|
+
const segments = posix.split("/");
|
|
224
|
+
if (segments.some((segment) => !segment || segment === "." || segment === "..")) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
if (segments.length === 1) {
|
|
228
|
+
return segments[0].startsWith("@") || segments[0].startsWith(".") ? null : posix;
|
|
229
|
+
}
|
|
230
|
+
if (segments.length === 2) {
|
|
231
|
+
return segments[0].startsWith("@") && segments[0].length > 1 && !segments[1].startsWith(".")
|
|
232
|
+
? posix
|
|
233
|
+
: null;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
213
238
|
// Accepts anything and returns the public-safe scan shape. Never throws and
|
|
214
239
|
// never carries a function or an unbounded field into the API response.
|
|
215
240
|
export function normalizeScan(raw) {
|
|
@@ -236,6 +261,7 @@ export function normalizeScan(raw) {
|
|
|
236
261
|
// the same registry file also holds.
|
|
237
262
|
api: typeof entry.api === "string" && entry.api.trim() ? entry.api.trim().slice(0, 512) : "",
|
|
238
263
|
package: typeof entry.package === "string" && entry.package ? entry.package : null,
|
|
264
|
+
dir: normalizePluginDir(entry.dir),
|
|
239
265
|
methods,
|
|
240
266
|
});
|
|
241
267
|
}
|
|
@@ -257,7 +283,7 @@ export function pluginRootDir(env = process.env) {
|
|
|
257
283
|
// line is parsed back.
|
|
258
284
|
const CHILD_SOURCE = String.raw`
|
|
259
285
|
import { readdirSync, readFileSync, existsSync } from "node:fs";
|
|
260
|
-
import { basename, join } from "node:path";
|
|
286
|
+
import { basename, join, relative, sep } from "node:path";
|
|
261
287
|
import { pathToFileURL } from "node:url";
|
|
262
288
|
|
|
263
289
|
const root = process.env.CLEAN_LOGIN_PLUGIN_ROOT || "";
|
|
@@ -269,6 +295,20 @@ const client = {
|
|
|
269
295
|
};
|
|
270
296
|
const providers = [];
|
|
271
297
|
|
|
298
|
+
// Direct dependencies declared in plugins/package.json help identify custom-named
|
|
299
|
+
// unscoped provider plugins without importing every transitive dependency.
|
|
300
|
+
const directDeps = new Set();
|
|
301
|
+
try {
|
|
302
|
+
const pluginPkgFile = join(root, "..", "package.json");
|
|
303
|
+
if (existsSync(pluginPkgFile)) {
|
|
304
|
+
const pluginPkg = JSON.parse(readFileSync(pluginPkgFile, "utf8"));
|
|
305
|
+
for (const section of [pluginPkg?.dependencies, pluginPkg?.optionalDependencies]) {
|
|
306
|
+
if (!section || typeof section !== "object" || Array.isArray(section)) continue;
|
|
307
|
+
for (const depName of Object.keys(section)) directDeps.add(depName);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
} catch {}
|
|
311
|
+
|
|
272
312
|
// Display names live in magpie's own plugin registry, one level above the
|
|
273
313
|
// packages: plugins/node_modules -> magpie/plugin-providers.json. Only id,
|
|
274
314
|
// name and the declared API base are read: that file also carries accounts and
|
|
@@ -299,15 +339,22 @@ function emit(payload) {
|
|
|
299
339
|
return new Promise((resolve) => process.stdout.write(text, () => resolve()));
|
|
300
340
|
}
|
|
301
341
|
|
|
342
|
+
const isDirLike = (entry) => entry.isDirectory() || entry.isSymbolicLink();
|
|
343
|
+
|
|
302
344
|
try {
|
|
303
345
|
const scopes = existsSync(root) ? readdirSync(root, { withFileTypes: true }) : [];
|
|
304
346
|
const dirs = [];
|
|
305
347
|
for (const scope of scopes) {
|
|
306
|
-
if (!scope.
|
|
348
|
+
if (!isDirLike(scope) || scope.name.startsWith(".")) continue;
|
|
349
|
+
if (!scope.name.startsWith("@")) {
|
|
350
|
+
const pkgDir = join(root, scope.name);
|
|
351
|
+
if (existsSync(join(pkgDir, "package.json"))) dirs.push(pkgDir);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
307
354
|
const scopeDir = join(root, scope.name);
|
|
308
355
|
const entries = existsSync(scopeDir) ? readdirSync(scopeDir, { withFileTypes: true }) : [];
|
|
309
356
|
for (const dirent of entries) {
|
|
310
|
-
if (dirent.
|
|
357
|
+
if (isDirLike(dirent) && !dirent.name.startsWith(".")) dirs.push(join(scopeDir, dirent.name));
|
|
311
358
|
}
|
|
312
359
|
}
|
|
313
360
|
for (const dir of dirs) {
|
|
@@ -321,12 +368,24 @@ try {
|
|
|
321
368
|
if (!existsSync(pkgFile)) continue;
|
|
322
369
|
let pkg = null;
|
|
323
370
|
try { pkg = JSON.parse(readFileSync(pkgFile, "utf8")); } catch { continue; }
|
|
371
|
+
if (pkg?.magpie?.page) continue;
|
|
324
372
|
// A manifest without a name is legal (a bundled browser build ships one),
|
|
325
373
|
// so fall back to the directory name. Do NOT reach for dirent here: it
|
|
326
374
|
// only exists inside the scope loop above, and reading it threw a
|
|
327
375
|
// ReferenceError that took the whole scan down.
|
|
328
376
|
const packageName =
|
|
329
377
|
typeof pkg?.name === "string" && pkg.name ? pkg.name : basename(dir);
|
|
378
|
+
const relDir = relative(root, dir).split(sep).join("/");
|
|
379
|
+
if (
|
|
380
|
+
!relDir.startsWith("@") &&
|
|
381
|
+
!packageName.startsWith("@") &&
|
|
382
|
+
!directDeps.has(relDir) &&
|
|
383
|
+
!Boolean(pkg?.magpie) &&
|
|
384
|
+
!/^(?:opencode|magpie)-/.test(packageName) &&
|
|
385
|
+
!/^(?:opencode|magpie)-/.test(relDir)
|
|
386
|
+
) {
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
330
389
|
const entry = typeof pkg?.main === "string" && pkg.main ? pkg.main : "index.mjs";
|
|
331
390
|
const mainFile = join(dir, entry);
|
|
332
391
|
if (!existsSync(mainFile)) continue;
|
|
@@ -366,6 +425,7 @@ try {
|
|
|
366
425
|
// means this provider cannot be a probe target.
|
|
367
426
|
api: apis.get(auth.provider) || "",
|
|
368
427
|
package: packageName,
|
|
428
|
+
dir: relDir,
|
|
369
429
|
methods: list.map((method) => ({
|
|
370
430
|
type: typeof method?.type === "string" ? method.type : "",
|
|
371
431
|
label: typeof method?.label === "string" ? method.label : "",
|
|
@@ -419,7 +479,7 @@ export async function scanMagpiePlugins({
|
|
|
419
479
|
env = process.env,
|
|
420
480
|
execFile: execFileImpl = execFile,
|
|
421
481
|
execPath = process.execPath,
|
|
422
|
-
timeoutMs =
|
|
482
|
+
timeoutMs = 30_000,
|
|
423
483
|
} = {}) {
|
|
424
484
|
const root = pluginRootDir(env);
|
|
425
485
|
try {
|
package/lib/native-signin.mjs
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
// user pastes when the callback cannot reach this machine.
|
|
19
19
|
|
|
20
20
|
import { spawn as spawnChild } from "node:child_process";
|
|
21
|
+
import { isAllowedSignInUrl } from "./open-external.mjs";
|
|
22
|
+
|
|
23
|
+
export { isAllowedSignInUrl as isSignInUrl };
|
|
21
24
|
|
|
22
25
|
export const NATIVE_SIGNIN_STATES = Object.freeze([
|
|
23
26
|
"starting",
|
|
@@ -35,13 +38,15 @@ const TERMINAL = new Set(["done", "error", "cancelled"]);
|
|
|
35
38
|
// parsers below never depend on that.
|
|
36
39
|
const ANSI = /\u001b\[[0-9;]*[A-Za-z]/g;
|
|
37
40
|
|
|
38
|
-
const URL_LINE = /https?:\/\/[^\s"'<>]
|
|
41
|
+
const URL_LINE = /https?:\/\/[^\s"'<>]+/g;
|
|
39
42
|
const CODE_LINE = /\bconfirm the code\s+([A-Z0-9][A-Z0-9-]{2,})\b/i;
|
|
40
43
|
const RISK_PROMPT = /sign in anyway\?\s*\[y\/N\]/i;
|
|
41
44
|
const PASTE_CODE = /paste the code the page shows here/i;
|
|
42
45
|
const PASTE_CALLBACK = /paste its whole address here/i;
|
|
43
46
|
const PASTE_ANY = /paste (?:its whole address|the code)/i;
|
|
44
47
|
const INSTALLING = /^installing /i;
|
|
48
|
+
const UNSUPPORTED_ACCOUNT = /only .* can be added and switched/i;
|
|
49
|
+
const PROXY_ENV_LINE = /^\s*(?:https?|all)_proxy\s*=/i;
|
|
45
50
|
const TIMED_OUT = /timed out|didn't finish/i;
|
|
46
51
|
|
|
47
52
|
export class NativeSignInError extends Error {
|
|
@@ -81,9 +86,15 @@ export function readNativeLine(raw) {
|
|
|
81
86
|
if (PASTE_CALLBACK.test(line)) return { kind: "paste", what: "callback" };
|
|
82
87
|
if (PASTE_ANY.test(line)) return { kind: "paste", what: "callback" };
|
|
83
88
|
if (INSTALLING.test(line.trim())) return { kind: "installing", text: line.trim() };
|
|
89
|
+
if (UNSUPPORTED_ACCOUNT.test(line)) return { kind: "failed", text: line.trim() };
|
|
84
90
|
const code = line.match(CODE_LINE);
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
if (!PROXY_ENV_LINE.test(line)) {
|
|
92
|
+
for (const m of line.matchAll(URL_LINE)) {
|
|
93
|
+
if (isAllowedSignInUrl(m[0])) {
|
|
94
|
+
return { kind: "url", url: m[0], code: code ? code[1] : "" };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
87
98
|
if (code) return { kind: "code", code: code[1] };
|
|
88
99
|
if (TIMED_OUT.test(line)) return { kind: "failed", text: line.trim() };
|
|
89
100
|
return null;
|
package/lib/provider-sources.mjs
CHANGED
|
@@ -260,6 +260,19 @@ function slug(value) {
|
|
|
260
260
|
.replace(/^-+|-+$/g, "");
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
// Built-in agents supported by `magpie accounts add <agent>`. Any other id is
|
|
264
|
+
// rejected by magpie's CLI ("only ... can be added and switched"), so custom
|
|
265
|
+
// providers without a plugin must not be given a dead native door.
|
|
266
|
+
export const NATIVE_ACCOUNT_AGENTS = Object.freeze(
|
|
267
|
+
new Set(["claude", "codex", "copilot", "gemini", "antigravity", "zed", "factory", "mimo"]),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
/** Return the canonical built-in native account agent id, or null if unsupported. */
|
|
271
|
+
export function nativeAgentId(value) {
|
|
272
|
+
const id = slug(value);
|
|
273
|
+
return NATIVE_ACCOUNT_AGENTS.has(id) ? id : null;
|
|
274
|
+
}
|
|
275
|
+
|
|
263
276
|
function itemFromEntry(entry) {
|
|
264
277
|
if (typeof entry === "string") {
|
|
265
278
|
const id = slug(entry);
|
|
@@ -383,13 +396,13 @@ function magpieOnlyProvider(item, pluginItem, scanFailure) {
|
|
|
383
396
|
...flags,
|
|
384
397
|
signInProvider: pluginItem ? pluginItem.id : null,
|
|
385
398
|
pluginPackage: pluginItem ? pluginItem.package : null,
|
|
386
|
-
// magpie signs
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
//
|
|
391
|
-
// sign-in.
|
|
392
|
-
nativeSignIn: !pluginItem,
|
|
399
|
+
// magpie signs only its built-in account agents in itself (`magpie accounts
|
|
400
|
+
// add <agent>`). Custom/non-built-in magpie providers without an installed
|
|
401
|
+
// plugin cannot be added that way and must not get a dead native door.
|
|
402
|
+
// Built-ins still defer to an installed plugin when one exists, so a plugin
|
|
403
|
+
// that offers only a key or a local session is not quietly turned into a
|
|
404
|
+
// browser sign-in.
|
|
405
|
+
nativeSignIn: !pluginItem && Boolean(nativeAgentId(item.id)),
|
|
393
406
|
};
|
|
394
407
|
}
|
|
395
408
|
|
|
@@ -649,9 +662,13 @@ export function mergeProviderSources({ local = [], magpie, plugins, catalog } =
|
|
|
649
662
|
// the registry's own `browser-oauth` entries keep their entry instead of
|
|
650
663
|
// losing the only door they have (the plugin layer below is not gated on
|
|
651
664
|
// that read either, for the same reason). A list that WAS read keeps the
|
|
652
|
-
// final say: not in it means no native door. A token-import provider
|
|
653
|
-
// not a browser door,
|
|
654
|
-
nativeSignIn:
|
|
665
|
+
// final say: not in it means no native door. A token-import provider or
|
|
666
|
+
// non-built-in agent is not a native browser door, even when magpie lists it.
|
|
667
|
+
nativeSignIn:
|
|
668
|
+
!pluginItem &&
|
|
669
|
+
provider.signInMode === "browser-oauth" &&
|
|
670
|
+
Boolean(nativeAgentId(provider.agentId || provider.id)) &&
|
|
671
|
+
(inMagpie || !available),
|
|
655
672
|
});
|
|
656
673
|
}
|
|
657
674
|
|
package/lib/proxy-score.mjs
CHANGED
|
@@ -31,7 +31,9 @@ export const SCORE_TIMEOUT_ENV = "MAGPIE_CLEAN_LOGIN_SCORE_TIMEOUT_MS";
|
|
|
31
31
|
export const DEFAULT_SCORE_TIMEOUT_MS = 90_000;
|
|
32
32
|
export const SCORE_LABEL_MAX = 40;
|
|
33
33
|
export const SCORE_IP_MAX = 80;
|
|
34
|
-
|
|
34
|
+
// Long enough to keep a full browser-launch failure, including playwright's
|
|
35
|
+
// own "missing display / xvfb" hints which run well past a UI-sized cap.
|
|
36
|
+
export const SCORE_ERROR_MAX = 2000;
|
|
35
37
|
export const SCORE_ERROR_CODE_MAX = 48;
|
|
36
38
|
|
|
37
39
|
// The page's own element ids.
|
package/lib/server.mjs
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
userIcon,
|
|
34
34
|
userIconType,
|
|
35
35
|
} from "./provider-icons.mjs";
|
|
36
|
-
import { createPluginScanner } from "./magpie-plugins.mjs";
|
|
36
|
+
import { createPluginScanner, scanMagpiePlugins } from "./magpie-plugins.mjs";
|
|
37
37
|
import { MarketInstallError, createMarketInstaller } from "./market-install.mjs";
|
|
38
38
|
import { RenewHostingError, createRenewHosting, offView } from "./renew-hosting.mjs";
|
|
39
39
|
import { buildIssueRequest, isAllowedIssueUrl } from "./issue-report.mjs";
|
|
@@ -530,7 +530,10 @@ export async function startServer({
|
|
|
530
530
|
// The asset registry shares the plugin's private data directory but keeps
|
|
531
531
|
// its own file, so it never has to migrate the proxy store's shape.
|
|
532
532
|
const assetStore = createAssetStore({ dataDir });
|
|
533
|
-
|
|
533
|
+
// `env` is the caller's contract: no factory below may fall back to
|
|
534
|
+
// process.env when an env was handed in (the environment root and the
|
|
535
|
+
// plugin scan root both derive from it).
|
|
536
|
+
const environment = environmentManager || createEnvironmentManager({ env });
|
|
534
537
|
// Keeps magpie's providers.json in step with the exits accounts signed in
|
|
535
538
|
// through, so each account really runs through the exit the user picked.
|
|
536
539
|
const accountProxySync =
|
|
@@ -544,7 +547,11 @@ export async function startServer({
|
|
|
544
547
|
// cached with a TTL and warmed in the background only after the service is
|
|
545
548
|
// listening, so it can never delay startup. `createPluginScanner` disables
|
|
546
549
|
// itself under NODE_ENV=test unless a scanner is injected.
|
|
547
|
-
const
|
|
550
|
+
const scannerEnv = env ?? process.env;
|
|
551
|
+
const pluginScanner = pluginScannerOption || createPluginScanner({
|
|
552
|
+
scan: () => scanMagpiePlugins({ env: scannerEnv }),
|
|
553
|
+
enabled: scannerEnv.NODE_ENV !== "test",
|
|
554
|
+
});
|
|
548
555
|
const providerRegistration =
|
|
549
556
|
providerRegistrationOption ||
|
|
550
557
|
createProviderRegistration({ env: env ?? process.env, pluginScanner });
|
|
@@ -934,13 +941,14 @@ export async function startServer({
|
|
|
934
941
|
// request blocks until the download job settles, so a caller that just
|
|
935
942
|
// started a prepare makes one request instead of one per poll. A request
|
|
936
943
|
// with no wait reads once and returns immediately.
|
|
937
|
-
// The environment routes answer {environment, job},
|
|
938
|
-
// status carries absolute paths (executablePath, installDir, modelDir)
|
|
939
|
-
//
|
|
940
|
-
//
|
|
944
|
+
// The environment routes answer {environment, job}, and the manager's
|
|
945
|
+
// status carries absolute paths (executablePath, installDir, modelDir).
|
|
946
|
+
// `installDir` stays so the UI can show where the sandboxed browser lives
|
|
947
|
+
// instead of falling back to "Unknown"; `executablePath` and `modelDir` stay
|
|
948
|
+
// stripped so internal launch details are never published.
|
|
941
949
|
function publicEnvironmentStatus(status) {
|
|
942
950
|
if (!status || typeof status !== "object") return status;
|
|
943
|
-
const { executablePath,
|
|
951
|
+
const { executablePath, modelDir, ...rest } = status;
|
|
944
952
|
return rest;
|
|
945
953
|
}
|
|
946
954
|
|
|
@@ -1392,8 +1400,12 @@ export async function startServer({
|
|
|
1392
1400
|
|
|
1393
1401
|
if (url.pathname === "/api/proxies") {
|
|
1394
1402
|
if (req.method === "GET") {
|
|
1403
|
+
// The recovery flag is only set while the store loads, so read it
|
|
1404
|
+
// after list() has resolved — before the fix the first request
|
|
1405
|
+
// against a corrupt proxies.json missed it.
|
|
1406
|
+
const proxies = await store.list();
|
|
1395
1407
|
const recovered = typeof store.recovered === "function" ? store.recovered() : null;
|
|
1396
|
-
json(res, 200, { proxies
|
|
1408
|
+
json(res, 200, { proxies, ...(recovered ? { recovered } : {}) });
|
|
1397
1409
|
return;
|
|
1398
1410
|
}
|
|
1399
1411
|
if (req.method === "POST") {
|
package/lib/signin-flow.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { randomUUID } from "node:crypto";
|
|
19
19
|
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
20
|
-
import { join } from "node:path";
|
|
20
|
+
import { isAbsolute, join, relative } from "node:path";
|
|
21
21
|
import { pathToFileURL } from "node:url";
|
|
22
22
|
import { readAuthKeys } from "./account-keys.mjs";
|
|
23
23
|
import { readAuthEntries, signInKey, writeBack } from "./signin-writeback.mjs";
|
|
@@ -248,15 +248,43 @@ export async function defaultLoadProvider({ provider, env = process.env, client,
|
|
|
248
248
|
let scan = pluginScanner?.get ? pluginScanner.get() : null;
|
|
249
249
|
if (!scan?.available && pluginScanner?.refresh) scan = await pluginScanner.refresh();
|
|
250
250
|
const entry = scan?.providers?.find?.((item) => item?.id === provider);
|
|
251
|
-
|
|
251
|
+
const rawPath = typeof entry?.dir === "string" && entry.dir ? entry.dir : entry?.package;
|
|
252
|
+
if (!entry || typeof rawPath !== "string" || !rawPath) {
|
|
252
253
|
throw new SignInFlowError(
|
|
253
254
|
"plugin_missing",
|
|
254
255
|
`No installed provider plugin provides "${provider}".`,
|
|
255
256
|
404,
|
|
256
257
|
);
|
|
257
258
|
}
|
|
259
|
+
if (
|
|
260
|
+
rawPath.startsWith("/") ||
|
|
261
|
+
rawPath.startsWith("\\") ||
|
|
262
|
+
/[\u0000-\u001f\u007f:]/.test(rawPath)
|
|
263
|
+
) {
|
|
264
|
+
throw new SignInFlowError(
|
|
265
|
+
"plugin_load_failed",
|
|
266
|
+
`Invalid plugin directory for "${provider}".`,
|
|
267
|
+
502,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
const segments = rawPath.split(/[/\\]+/).filter(Boolean);
|
|
271
|
+
if (!segments.length || segments.some((segment) => segment === "." || segment === "..")) {
|
|
272
|
+
throw new SignInFlowError(
|
|
273
|
+
"plugin_load_failed",
|
|
274
|
+
`Invalid plugin directory for "${provider}".`,
|
|
275
|
+
502,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
258
278
|
const root = pluginRootDir(env);
|
|
259
|
-
const dir = join(root, ...
|
|
279
|
+
const dir = join(root, ...segments);
|
|
280
|
+
const rel = relative(root, dir);
|
|
281
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) {
|
|
282
|
+
throw new SignInFlowError(
|
|
283
|
+
"plugin_load_failed",
|
|
284
|
+
`Invalid plugin directory for "${provider}".`,
|
|
285
|
+
502,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
260
288
|
let mod;
|
|
261
289
|
try {
|
|
262
290
|
mod = await import(pathToFileURL(await readPluginEntry(dir)).href);
|
|
@@ -302,7 +330,7 @@ export async function defaultLoadProvider({ provider, env = process.env, client,
|
|
|
302
330
|
}
|
|
303
331
|
const auth = hooks?.auth;
|
|
304
332
|
if (auth && auth.provider === provider && Array.isArray(auth.methods)) {
|
|
305
|
-
return { methods: auth.methods, package: entry.package };
|
|
333
|
+
return { methods: auth.methods, package: entry.package || entry.dir };
|
|
306
334
|
}
|
|
307
335
|
}
|
|
308
336
|
throw new SignInFlowError(
|
package/package.json
CHANGED
package/ui/app.js
CHANGED
|
@@ -326,6 +326,7 @@ const messages = {
|
|
|
326
326
|
errorInvalidPort: "The port must be between 1 and 65535.",
|
|
327
327
|
errorInvalidUsername: "The username is not valid.",
|
|
328
328
|
errorInvalidPassword: "The password is not valid.",
|
|
329
|
+
errorNameTaken: "A proxy with that name already exists.",
|
|
329
330
|
errorNotFound: "This proxy no longer exists.",
|
|
330
331
|
errorInvalidJson: "The request was not valid JSON.",
|
|
331
332
|
errorTooLarge: "The request was too large.",
|
|
@@ -853,6 +854,7 @@ const messages = {
|
|
|
853
854
|
errorInvalidPort: "端口应在 1 到 65535 之间。",
|
|
854
855
|
errorInvalidUsername: "用户名无效。",
|
|
855
856
|
errorInvalidPassword: "密码无效。",
|
|
857
|
+
errorNameTaken: "已存在同名的代理。",
|
|
856
858
|
errorNotFound: "这个代理已不存在。",
|
|
857
859
|
errorInvalidJson: "请求不是有效的 JSON。",
|
|
858
860
|
errorTooLarge: "请求内容过大。",
|
|
@@ -1380,6 +1382,7 @@ const messages = {
|
|
|
1380
1382
|
errorInvalidPort: "連接埠應在 1 到 65535 之間。",
|
|
1381
1383
|
errorInvalidUsername: "使用者名稱無效。",
|
|
1382
1384
|
errorInvalidPassword: "密碼無效。",
|
|
1385
|
+
errorNameTaken: "已存在同名的代理。",
|
|
1383
1386
|
errorNotFound: "這個代理已不存在。",
|
|
1384
1387
|
errorInvalidJson: "請求不是有效的 JSON。",
|
|
1385
1388
|
errorTooLarge: "請求內容過大。",
|
|
@@ -1907,6 +1910,7 @@ const messages = {
|
|
|
1907
1910
|
errorInvalidPort: "ポートは 1 から 65535 の範囲で入力してください。",
|
|
1908
1911
|
errorInvalidUsername: "ユーザー名が無効です。",
|
|
1909
1912
|
errorInvalidPassword: "パスワードが無効です。",
|
|
1913
|
+
errorNameTaken: "同名のプロキシがすでに存在します。",
|
|
1910
1914
|
errorNotFound: "このプロキシは存在しません。",
|
|
1911
1915
|
errorInvalidJson: "リクエストが有効な JSON ではありません。",
|
|
1912
1916
|
errorTooLarge: "リクエストが大きすぎます。",
|
|
@@ -2385,6 +2389,7 @@ const errorKeys = {
|
|
|
2385
2389
|
identity_mismatch: "errorAccountMismatch",
|
|
2386
2390
|
invalid_account: "errorAccountInvalid",
|
|
2387
2391
|
invalid_name: "errorInvalidName",
|
|
2392
|
+
name_taken: "errorNameTaken",
|
|
2388
2393
|
invalid_type: "errorInvalidType",
|
|
2389
2394
|
invalid_host: "errorInvalidHost",
|
|
2390
2395
|
invalid_port: "errorInvalidPort",
|
|
@@ -2417,7 +2422,13 @@ const testErrorKeys = {
|
|
|
2417
2422
|
unknown: "testUnknown",
|
|
2418
2423
|
};
|
|
2419
2424
|
|
|
2420
|
-
function apiErrorText(
|
|
2425
|
+
function apiErrorText(error) {
|
|
2426
|
+
const code = error?.code;
|
|
2427
|
+
// The proxy store returns one code for every name failure ("Name is
|
|
2428
|
+
// required.", "...too long.", "Name must not contain < or >."). A single
|
|
2429
|
+
// localized string cannot say which one happened, so the server's own
|
|
2430
|
+
// message is the honest answer whenever it exists.
|
|
2431
|
+
if (code === "invalid_name" && error?.serverMessage) return String(error.serverMessage);
|
|
2421
2432
|
return text[errorKeys[code]] || text.errorGeneric;
|
|
2422
2433
|
}
|
|
2423
2434
|
|
|
@@ -4343,7 +4354,7 @@ function serverErrorText(error) {
|
|
|
4343
4354
|
if (code === "network") return text.errorNetwork;
|
|
4344
4355
|
const key = (code !== "not_found" ? errorKeys[code] : undefined) || checkErrorKeys[code];
|
|
4345
4356
|
if (key && text[key]) return text[key];
|
|
4346
|
-
return [code, message].filter(Boolean).join(" · ") || apiErrorText(error
|
|
4357
|
+
return [code, message].filter(Boolean).join(" · ") || apiErrorText(error);
|
|
4347
4358
|
}
|
|
4348
4359
|
|
|
4349
4360
|
function signInStateLabel(state) {
|
|
@@ -5307,7 +5318,7 @@ function environmentChecksumVerified(env) {
|
|
|
5307
5318
|
function environmentRequestErrorText(error) {
|
|
5308
5319
|
const code = error?.code;
|
|
5309
5320
|
if (code && environmentErrorKeys[code]) return text[environmentErrorKeys[code]];
|
|
5310
|
-
return apiErrorText(
|
|
5321
|
+
return apiErrorText(error);
|
|
5311
5322
|
}
|
|
5312
5323
|
|
|
5313
5324
|
function stopEnvironmentPolling() {
|
|
@@ -5772,7 +5783,7 @@ async function testDialogProxy() {
|
|
|
5772
5783
|
return;
|
|
5773
5784
|
}
|
|
5774
5785
|
context.lastTest = null;
|
|
5775
|
-
setTestResult("error", text.testFailure.replace("{error}", apiErrorText(error
|
|
5786
|
+
setTestResult("error", text.testFailure.replace("{error}", apiErrorText(error)));
|
|
5776
5787
|
} finally {
|
|
5777
5788
|
if (dialogContext === context) {
|
|
5778
5789
|
context.testing = false;
|
|
@@ -5812,7 +5823,7 @@ async function saveProxy() {
|
|
|
5812
5823
|
if (testedValues && saved.status !== "ok") testRowProxy(saved.id);
|
|
5813
5824
|
} catch (error) {
|
|
5814
5825
|
if (dialogContext === context && byId("proxy-dialog").open) {
|
|
5815
|
-
setFormError(apiErrorText(error
|
|
5826
|
+
setFormError(apiErrorText(error));
|
|
5816
5827
|
context.saving = false;
|
|
5817
5828
|
setDialogBusy(false);
|
|
5818
5829
|
}
|
|
@@ -5881,7 +5892,7 @@ async function confirmDelete() {
|
|
|
5881
5892
|
} catch (error) {
|
|
5882
5893
|
deleting = false;
|
|
5883
5894
|
if (byId("confirm-dialog").open) {
|
|
5884
|
-
setConfirmError(apiErrorText(error
|
|
5895
|
+
setConfirmError(apiErrorText(error));
|
|
5885
5896
|
setConfirmBusy(false);
|
|
5886
5897
|
} else {
|
|
5887
5898
|
confirmController.cancel();
|