dsh-mobile-plugin 0.5.93 → 0.5.95

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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/config/agent-presets/standard/skills/dsh-mobile-kb/SKILL.md +10 -3
  3. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/cloudflare.md +58 -0
  4. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/frp.md +50 -0
  5. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/ipv4.md +2 -2
  6. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/load-error-after-action.md +27 -0
  7. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network-guide.md +55 -0
  8. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/network.md +5 -1
  9. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/plugin-not-loaded.md +22 -0
  10. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay-server.md +48 -0
  11. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/relay.md +9 -0
  12. package/config/agent-presets/standard/skills/dsh-mobile-kb/references/selfhost-common.md +1 -1
  13. package/lib/client.js +53 -162
  14. package/lib/cloudflared/provision.cjs +392 -0
  15. package/lib/cloudflared/runner.cjs +305 -0
  16. package/lib/cloudflared/wiring.cjs +82 -0
  17. package/lib/frpc/runner.cjs +1 -1
  18. package/lib/impl.js +11 -1
  19. package/lib/mobile/history-derive.js +16 -0
  20. package/lib/mobile/pairing.js +4 -0
  21. package/lib/panel/index.html +47 -27
  22. package/lib/relay/config-store.js +9 -0
  23. package/lib/relay/control.js +8 -0
  24. package/lib/relay/core.js +6 -0
  25. package/lib/relay/lan-network.cjs +23 -0
  26. package/lib/relay/pairing-payload.cjs +2 -1
  27. package/lib/remote/routes.cjs +7 -5
  28. package/lib/remote/tunnel-helper.cjs +3 -3
  29. package/lib/routes/control-plane.js +116 -155
  30. package/lib/routes/mobile-api.js +10 -2
  31. package/lib/shared/route-channels.cjs +1 -0
  32. package/lib/shared/route-order.cjs +8 -1
  33. package/lib/tailcat/host-process.cjs +9 -3
  34. package/package.json +14 -13
@@ -1,4 +1,4 @@
1
- // 2026-11-21:控制面去掉跨站与只读来源拦截,按用户要求不再限制部署位置和访问来源。
1
+ // 2026-11-21:控制面去掉来源拦截,按用户要求不再限制部署位置和访问来源。
2
2
  // 配对二维码在隧道窗口就绪后取当前状态,渲染完成前复核票据与身份。
3
3
  // 网络动作区分配置受理与真实连接,主动重连使用独立动作并保留探测总期限。
4
4
  // 注册本机控制面,并在吊销回执完成后关闭本实例在途连接。
@@ -12,7 +12,7 @@
12
12
  * 依赖以取值器 / 函数注入、不捕获对象:闭包里那些 let(sidecar 等)会被整体替换,`getSidecar` 拿到实例就等于拿到旧 facade 快照。
13
13
  * 改中转地址与手机端写同一份配置、走同一条下发路径;「先登记迁移、再重建隧道」在 worker 的 configure 里(见 ../relay/migrate.js),这里只把失败原因如实带回面板。
14
14
  * 设备清单一条路径回两份内容(活着的设备 / 已解绑的历史),按 query 分叉:路径进了白名单与路由清单,为一次多带的内容再开一条要两处跟着动。
15
- * 配对与管理仍只允许本机及标准局域网直连;只读管理面不再限制来源,从哪儿打开都能进。
15
+ * 配对与管理也不按来源限制:任何能打开面板的浏览器都能用,只拒绝经中转 / 局域网代理转发来的请求。
16
16
  * 桌面侧边栏两颗图标的显示开关写进同一份配置,只认布尔值;手机端配置口不收这两格。
17
17
  */
18
18
 
@@ -20,7 +20,7 @@ const fs = require('node:fs');
20
20
  const net = require('node:net');
21
21
  const path = require('node:path');
22
22
  const QRCode = require('qrcode');
23
- const { trustedLocalNetworkUi, isLoopbackAddress, isLocalNetworkAddress } = require('../http/routing.js');
23
+ const { isLoopbackAddress, isLocalNetworkAddress } = require('../http/routing.js');
24
24
  const { pairingText } = require('../relay/pairing-payload.cjs');
25
25
  const { randomBytes } = require('node:crypto');
26
26
 
@@ -35,7 +35,7 @@ const { canListen } = require('../relay/port-allocator.cjs');
35
35
  // ⚠️ 面板里**能被选中的**那份仍然只能是 `lan`(没有私网时才退 `public`)——它与
36
36
  // `advertisedCandidates` 同口径。IPv6 那份只**显示**、不进那个选择:它由手机侧实测择优
37
37
  // (和公网中转比速度),做成可选中等于骗人(同 A3-40 的刻意设计)。
38
- const { lanCandidates, publicCandidates, ipv6Candidates, withManualIpv6Candidate } = require('../relay/lan-network.cjs');
38
+ const { lanCandidates, publicCandidates, ipv6Candidates, withManualIpv4Candidate, withManualIpv6Candidate } = require('../relay/lan-network.cjs');
39
39
  // 「手机连不上时哪一环断了」这份连接自检:本机只读、不改任何东西(口径见
40
40
  // connection-check.js 与 firewall-probe.js 的文件头)。
41
41
  const { createConnectionCheck } = require('../relay/connection-check.js');
@@ -78,51 +78,6 @@ function preferredIsRelayHost(preferred, state) {
78
78
  });
79
79
  }
80
80
 
81
- function createWebAccessWindow({ now = Date.now, monotonicNow = () => performance.now() } = {}) {
82
- let deadline = 0;
83
- let expiresAt = 0;
84
- const status = () => {
85
- const current = monotonicNow();
86
- if (deadline <= current) {
87
- deadline = 0;
88
- expiresAt = 0;
89
- return { enabled: false, expiresAt: 0 };
90
- }
91
- return { enabled: true, expiresAt };
92
- };
93
- return {
94
- status,
95
- isOpen: () => status().enabled,
96
- enable() {
97
- deadline = monotonicNow() + WEB_ACCESS_WINDOW_MS;
98
- expiresAt = now() + WEB_ACCESS_WINDOW_MS;
99
- return status();
100
- },
101
- disable() {
102
- deadline = 0;
103
- expiresAt = 0;
104
- return status();
105
- },
106
- };
107
- }
108
-
109
- function createWebAccessLocalOnly({ localOnly, trustedLocalUi, sendJson }) {
110
- return (method, handler) => localOnly(method, async (req, res) => {
111
- const route = String(req?.url || '').split('?', 1)[0];
112
- // 会改动本机状态 / 吐密钥的动作(配对、改配置、解绑、更新、重载实现等)仍只允许本机或
113
- // 标准局域网直连。只读管理面(状态、地址、设备清单、面板页、faults 等)不再看来源:
114
- // 不管用户从本机、局域网、公网域名还是反代后面打开,都能正常进入。
115
- const trusted = trustedLocalUi(req) || trustedLocalNetworkUi(req);
116
- if (LOCAL_OPERATOR_ROUTES.has(route) && !trusted) {
117
- return sendJson(res, 403, {
118
- ok: false,
119
- error: { code: 'local_operator_only', message: '该操作会改动配对、中转、设备授权或插件更新,只允许从本机或局域网直连 DSH 执行' },
120
- });
121
- }
122
- return handler(req, res);
123
- });
124
- }
125
-
126
81
  /**
127
82
  * 面板页(`React/` 构建成的单文件 HTML)在包里的位置。
128
83
  *
@@ -232,14 +187,14 @@ function panelUrlOf(req) {
232
187
  /**
233
188
  * 面板地址落在哪一类网络上:`loopback` / `private` / `public`(判不出来时算 `public`)。
234
189
  *
235
- * 侧边栏那颗手机图标(现在它是进入网页的唯一入口)据此决定点下去要不要先开两小时窗口:
190
+ * 侧边栏那颗手机图标(现在它是进入网页的唯一入口)据此决定点下去要不要先弹一句公网确认:
236
191
  *
237
192
  * - `loopback`:本机回环界面,直接进入;
238
- * - `private`:标准局域网直连界面,直接进入,不要求开启公网管理窗口;
239
- * - `public`:公网部署,地址谁都能拨,所以先弹一句确认再开。
193
+ * - `private`:标准局域网直连界面,直接进入;
194
+ * - `public`:公网部署,地址谁都能拨,所以先弹一句确认再进。
240
195
  *
241
196
  * **域名一律按 `public` 算**:内网域名、内网穿透域名长得跟公网域名一样,这里分不出来。
242
- * 猜错的代价是「多弹一次确认」,反过来猜错就是「不知不觉把公网管理口开了两小时」。
197
+ * 猜错的代价只是多弹一次确认。
243
198
  */
244
199
  function panelScopeOf(req) {
245
200
  const host = typeof req?.headers?.host === 'string' ? req.headers.host : '';
@@ -254,30 +209,6 @@ function panelScopeOf(req) {
254
209
  return isLocalNetworkAddress(hostname) ? 'private' : 'public';
255
210
  }
256
211
 
257
- /**
258
- * 开 / 关网页管理窗口这条只认「Host 是地址字面量」的来源。
259
- *
260
- * 2026-11-02 把这条放宽到只要求 `localOnly`(同源、无中转凭据),好让公网 / 局域网部署的人
261
- * 在自己的浏览器里点图标也能开窗口;但那把 DNS 重绑定这个口子留了下来:重绑定页面用的
262
- * origin 与 Host 都是攻击者那个域名(浏览器把 Host 填成域名、连接却落到本机),`localOnly`
263
- * 的同源判断认不出,任意网页就能自己把两小时管理窗口打开。
264
- *
265
- * 判据收窄成「Host 必须是 IP 字面量或 localhost」:重绑定页面**必然**带一个域名 Host,直接被
266
- * 挡;正常直连——回环、局域网 IP、公网 IP、localhost——照旧能开。经域名反代访问的机器后端分
267
- * 不出原始客户端(与 `trustedLocalUi` 对代理的取舍一致),这种部署不再支持用它开窗口。
268
- */
269
- function webAccessHostTrusted(req) {
270
- const host = typeof req?.headers?.host === 'string' ? req.headers.host : '';
271
- if (!host) return false;
272
- let hostname = '';
273
- try {
274
- hostname = new URL(`http://${host}`).hostname.toLowerCase().replace(/^\[|\]$/g, '');
275
- } catch {
276
- return false;
277
- }
278
- return hostname === 'localhost' || net.isIP(hostname) !== 0;
279
- }
280
-
281
212
  /**
282
213
  * @param {object} deps 见 `lib/impl.js` 里 registerControlPlaneRoutes({...}) 的调用点
283
214
  */
@@ -285,7 +216,6 @@ function registerControlPlaneRoutes(deps) {
285
216
  const {
286
217
  registerRoute,
287
218
  localOnly: baseLocalOnly,
288
- trustedLocalUi,
289
219
  readJson,
290
220
  sendJson,
291
221
  sendHtml,
@@ -371,7 +301,6 @@ function registerControlPlaneRoutes(deps) {
371
301
  getMirrorPushFailures,
372
302
  getLanProxyStats,
373
303
  });
374
- const webAccessWindow = createWebAccessWindow();
375
304
  /**
376
305
  * 连接自检:面板的引导页与「连接状态」卡读它。
377
306
  *
@@ -380,11 +309,7 @@ function registerControlPlaneRoutes(deps) {
380
309
  * (见 `../relay/firewall-probe.js`)—— 面板打开弹窗与后台那一次巡检共用同一份结果。
381
310
  */
382
311
  const connectionCheck = createConnectionCheck({ status, lanCandidates, mobileActivity });
383
- const localOnly = createWebAccessLocalOnly({
384
- localOnly: baseLocalOnly,
385
- trustedLocalUi: typeof trustedLocalUi === 'function' ? trustedLocalUi : () => false,
386
- sendJson,
387
- });
312
+ const localOnly = baseLocalOnly;
388
313
 
389
314
  registerRoute({ kind: 'exact', path: '/api/relay/feedback', handler: localOnly(['GET', 'POST'], (req, res) =>
390
315
  handleFeedback({ req, res, readJson, sendJson, credentials, instanceId: () => state.instanceId })) });
@@ -477,15 +402,18 @@ function registerControlPlaneRoutes(deps) {
477
402
  const manualIpv6 = typeof state.manualIpv6Url === 'string' ? state.manualIpv6Url : ''
478
403
  // `manualTcp` 是「TCP 直连」目标(`主机:端口`):面板回显与修改它,手机拿它当裸 TCP 目标。
479
404
  const manualTcp = typeof state.manualTcpUrl === 'string' ? state.manualTcpUrl : ''
405
+ // `manualIpv4` 是公网 IPv4(只认 IPv4 字面量):单列一格供面板回显,并缀进公网候选最后。
406
+ const manualIpv4 = typeof state.manualIpv4Url === 'string' ? state.manualIpv4Url : ''
480
407
  sendJson(res, 200, {
481
408
  ok: true,
482
409
  port,
483
410
  preferred: preferredLan,
484
411
  manual,
485
412
  manualIpv6,
413
+ manualIpv4,
486
414
  manualTcp,
487
415
  lan: lanCandidates(port),
488
- public: publicCandidates(port),
416
+ public: withManualIpv4Candidate(publicCandidates(port), manualIpv4),
489
417
  ipv6: withManualIpv6Candidate(ipv6Candidates(port), manualIpv6),
490
418
  })
491
419
  }) })
@@ -519,8 +447,13 @@ function registerControlPlaneRoutes(deps) {
519
447
  const who = await fetch(`${url}/api/mobile/v1/health`, { signal: controller.signal, redirect: 'follow' })
520
448
  .then((r) => (r.ok ? r.json() : null))
521
449
  .catch(() => null)
522
- if (!who || who.service !== 'dsh-mobile-relay') return { url, ms: null }
523
- return { url, ms: Date.now() - started, service: who.service, version: who.version }
450
+ const elapsed = Date.now() - started
451
+ // 中转自己那条地址体检 `/api/mobile/v1/health` 会带回 `service`。
452
+ if (who && who.service === 'dsh-mobile-relay') return { url, ms: elapsed, service: 'dsh-mobile-relay', version: who.version }
453
+ // 直连地址打回的是**宿主自己**:回 `service=dsh-mobile-plugin` + `instanceId`。带上实例号,
454
+ // 面板据此确认「这个地址绕回来就是本机」(回环检测),而不是别的机器或别的服务。
455
+ if (who && who.service === 'dsh-mobile-plugin') return { url, ms: elapsed, service: 'dsh-mobile-plugin', instanceId: who.instanceId || '', apiVersion: who.apiVersion }
456
+ return { url, ms: null }
524
457
  } catch {
525
458
  return { url, ms: null }
526
459
  } finally {
@@ -529,22 +462,38 @@ function registerControlPlaneRoutes(deps) {
529
462
  }))
530
463
  sendJson(res, 200, { ok: true, results })
531
464
  }) })
532
- // 只有可信本机设置入口可以开 / 关窗口;窗口状态仅驻留进程内,DSH 重启后必定关闭。
533
- registerRoute({ kind: 'exact', path: '/api/relay/web-access', handler: localOnly('POST', async (req, res) => {
534
- // 谁来按这个开关:只认「Host 是地址字面量」的本机直连,理由见 `webAccessHostTrusted`。
535
- // 2026-11-02 一度只要求 `localOnly` 那一层,结果任意网页能靠 DNS 重绑定自己把窗口打开;
536
- // 现在把 Host 收窄到 IP 字面量 / localhost —— 回环、局域网、公网 IP 直连照旧能开,重绑定
537
- // 必带的域名 Host 被挡。跨站页面、带中转凭据、经本机代理转发的仍在 localOnly 挡掉。
538
- if (!webAccessHostTrusted(req)) {
539
- return sendJson(res, 403, { ok: false, error: { code: 'local_only', message: '开启网页管理窗口仅允许从本机地址访问' } });
540
- }
541
- const body = await readJson(req);
542
- if (typeof body?.enabled !== 'boolean') {
543
- return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: 'enabled 必须是布尔值' } });
465
+ /**
466
+ * 直连地址的回环体检(`POST /api/relay/probe-direct`,body `{ url }`)。
467
+ *
468
+ * 直连地址打回的就是这台宿主自己,没有中转那套 `/healthz`;这里直接问它的
469
+ * `/api/mobile/v1/health`,把 `service` 与 `instanceId` 带回来,面板据此确认「绕回来
470
+ * 就是本机」。宿主代测是为了绕开浏览器 CORS,只认 http(s)、只发一次 GET。
471
+ */
472
+ registerRoute({ kind: 'exact', path: '/api/relay/probe-direct', handler: localOnly('POST', async (req, res) => {
473
+ const body = await readJson(req)
474
+ const raw = typeof body?.url === 'string' ? body.url.trim().replace(/\/+$/, '') : ''
475
+ if (!/^https?:\/\//i.test(raw)) return sendJson(res, 200, { ok: true, ms: null })
476
+ const controller = new AbortController()
477
+ const timer = setTimeout(() => controller.abort(), RELAY_PROBE_TIMEOUT_MS)
478
+ const started = Date.now()
479
+ try {
480
+ const who = await fetch(`${raw}/api/mobile/v1/health`, { signal: controller.signal, redirect: 'follow' })
481
+ .then((r) => (r.ok ? r.json() : null))
482
+ .catch(() => null)
483
+ if (!who || typeof who !== 'object') return sendJson(res, 200, { ok: true, ms: null })
484
+ sendJson(res, 200, {
485
+ ok: true,
486
+ ms: Date.now() - started,
487
+ service: typeof who.service === 'string' ? who.service : '',
488
+ instanceId: typeof who.instanceId === 'string' ? who.instanceId : '',
489
+ apiVersion: who.apiVersion,
490
+ })
491
+ } catch {
492
+ sendJson(res, 200, { ok: true, ms: null })
493
+ } finally {
494
+ clearTimeout(timer)
544
495
  }
545
- const webAccess = body.enabled ? webAccessWindow.enable() : webAccessWindow.disable();
546
- return sendJson(res, 200, { ok: true, webAccess });
547
- }) });
496
+ }) })
548
497
  /**
549
498
  * 配了几台手机、最近一次连线是什么时候。
550
499
  *
@@ -583,7 +532,7 @@ function registerControlPlaneRoutes(deps) {
583
532
  return false
584
533
  }
585
534
  }
586
- registerRoute({ kind: 'exact', path: '/api/relay/status', handler: localOnly('GET', async (req, res) => sendJson(res, 200, { ...status(), shellChanged: shellChangedNow(), tailcat: deps.tailcat && typeof deps.tailcat.status === 'function' ? deps.tailcat.status() : null, frp: deps.frp && typeof deps.frp.status === 'function' ? deps.frp.status() : null, panelUrl: panelUrlOf(req), panelScope: panelScopeOf(req), webAccess: webAccessWindow.status(), devices: deviceSummary(), ...mobileActivity(), selfCheck: selfCheck.snapshot() })) })
535
+ registerRoute({ kind: 'exact', path: '/api/relay/status', handler: localOnly('GET', async (req, res) => sendJson(res, 200, { ...status(), shellChanged: shellChangedNow(), tailcat: deps.tailcat && typeof deps.tailcat.status === 'function' ? deps.tailcat.status() : null, frp: deps.frp && typeof deps.frp.status === 'function' ? deps.frp.status() : null, cloudflare: deps.cloudflare && typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null, panelUrl: panelUrlOf(req), panelScope: panelScopeOf(req), devices: deviceSummary(), ...mobileActivity(), selfCheck: selfCheck.snapshot() })) })
587
536
 
588
537
  // ── 手机直连隧道(Tailcat):面板查看与管理 ────────────────────────────────
589
538
  //
@@ -615,6 +564,22 @@ function registerControlPlaneRoutes(deps) {
615
564
  // 面板把用户粘贴的 frpc 配置原样送上来,这里交给进程管理器:它会把 `localPort` 对齐到插件
616
565
  // 此刻真实监听的端口,再起 `frpc -c 配置`。这样「TCP 直连地址」后面才真的有个隧道在转发,
617
566
  // 而不是只填了个地址、什么都没跑。运行状态随 `/api/relay/status` 的 `frp` 一起回给面板。
567
+ registerRoute({ kind: 'exact', path: '/api/relay/frp/config', handler: localOnly('GET', async (_req, res) => {
568
+ if (!deps.frp) {
569
+ return sendJson(res, 503, { ok: false, error: { code: 'frp-unavailable', message: '这台宿主没有接入 frpc 运行能力' } })
570
+ }
571
+ let config = ''
572
+ if (typeof deps.frp.readConfig === 'function') {
573
+ config = deps.frp.readConfig() || ''
574
+ } else if (deps.frp._paths) {
575
+ // 运行中的实例可能是旧外壳(进程启动时缓存、换不掉):直接读它暴露的落盘路径,
576
+ // 免得「查看 FRP 配置」要等一次 DSH 重启才可用。
577
+ for (const file of [deps.frp._paths.jsonConfig, deps.frp._paths.config]) {
578
+ try { config = fs.readFileSync(file, 'utf8'); break } catch { /* 换下一个 */ }
579
+ }
580
+ }
581
+ sendJson(res, 200, { ok: true, config })
582
+ }) })
618
583
  registerRoute({ kind: 'exact', path: '/api/relay/frp/import', handler: localOnly('POST', async (req, res) => {
619
584
  const body = await readJson(req)
620
585
  const config = body && typeof body.config === 'string' ? body.config : ''
@@ -646,6 +611,36 @@ function registerControlPlaneRoutes(deps) {
646
611
  await settings.update({ manualTcpUrl: '' })
647
612
  sendJson(res, 200, { ok: true, status: stopped })
648
613
  }) })
614
+
615
+ // ── Cloudflare 兜底隧道:面板开关 → 启停本地 cloudflared 快速隧道 ─────────────
616
+ //
617
+ // 和 FRP 直连同一类「动作」:状态那一格随 `/api/relay/status` 的 `cloudflare` 一起回给
618
+ // 面板,这里只补启停两条。快速隧道进程的装配、地址写回与停用后恢复原地址都在
619
+ // `lib/cloudflared`(wiring / runner),面板不碰它们的细节。
620
+ registerRoute({ kind: 'exact', path: '/api/cloudflare/start', handler: localOnly('POST', async (_req, res) => {
621
+ if (!deps.cloudflare || typeof deps.cloudflare.start !== 'function') {
622
+ return sendJson(res, 503, { ok: false, error: { code: 'cloudflare-unavailable', message: '这台宿主没有接入 Cloudflare 隧道能力' } })
623
+ }
624
+ try {
625
+ await deps.cloudflare.start()
626
+ const current = typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null
627
+ sendJson(res, 200, { ok: true, ...(current || {}) })
628
+ } catch (err) {
629
+ sendJson(res, 500, { ok: false, error: { code: 'cloudflare-start-failed', message: err && err.message ? err.message : String(err) } })
630
+ }
631
+ }) })
632
+ registerRoute({ kind: 'exact', path: '/api/cloudflare/stop', handler: localOnly('POST', async (_req, res) => {
633
+ if (!deps.cloudflare || typeof deps.cloudflare.stop !== 'function') {
634
+ return sendJson(res, 503, { ok: false, error: { code: 'cloudflare-unavailable', message: '这台宿主没有接入 Cloudflare 隧道能力' } })
635
+ }
636
+ try {
637
+ await deps.cloudflare.stop()
638
+ const current = typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null
639
+ sendJson(res, 200, { ok: true, ...(current || {}) })
640
+ } catch (err) {
641
+ sendJson(res, 500, { ok: false, error: { code: 'cloudflare-stop-failed', message: err && err.message ? err.message : String(err) } })
642
+ }
643
+ }) })
649
644
  const tailcatSnapshot = () => {
650
645
  const state = deps.tailcat && typeof deps.tailcat.status === 'function' ? deps.tailcat.status() : null
651
646
  const allowed = deps.tailcat && typeof deps.tailcat.allowedClients === 'function' ? deps.tailcat.allowedClients() : []
@@ -768,8 +763,7 @@ function registerControlPlaneRoutes(deps) {
768
763
  return sendJson(res, 200, { ok: true, installed: true, faults: guard.faults(), stats: guard.stats() })
769
764
  }) })
770
765
  registerRoute({ kind: 'exact', path: '/api/relay/pairing', handler: localOnly('GET', async (req, res) => {
771
- // 二维码包含一次性配对票据,与配置等操作共用外层来源判断:
772
- // 本机和标准局域网直连可读取,公网即使开启两小时窗口也不能取码。
766
+ // 二维码包含一次性配对票据,与配置等操作共用外层判断:只拒绝经中转 / 局域网代理转发来的请求。
773
767
  if (!state.enabled) {
774
768
  sendJson(res, 409, { ok: false, error: '请先启用远程控制并保存配置' })
775
769
  return
@@ -904,15 +898,14 @@ function registerControlPlaneRoutes(deps) {
904
898
  * 只回「面板画一行需要的东西」,**不回 `hash` / `hostToken`** —— 那些是凭据材料,
905
899
  * 面板只是显示谁连着、什么时候来的。
906
900
  *
907
- * 与二维码那条同一条规矩:都在 `WEB_ACCESS_ROUTES` 里,两小时窗口打开时远程能用是它的
908
- * 用途。设备列表里没有密钥材料;二维码那边多一层考虑,见 `/api/relay/pairing` 的注释。
901
+ * 与二维码那条同一条规矩:都在 `WEB_ACCESS_ROUTES` 清单里,不按来源拦。设备列表里没有
902
+ * 密钥材料;二维码那边多一层考虑,见 `/api/relay/pairing` 的注释。
909
903
  *
910
904
  * `serverNow` 是给面板算「几分钟前」用的:手机与宿主的时钟可能差得多,但面板只需要
911
905
  * 一个同一台机器上的基准。
912
906
  *
913
907
  * `?history=1` 走同一个 handler 换一份内容(已解绑的那几台),不另开一条路径:路径进了
914
- * 白名单与路由清单,为一次多带的内容再加一条要让两处跟着动,且 `createWebAccessLocalOnly`
915
- * 本来就按 `split('?')` 取路径对白名单,同一路径带 query 天然还在里面。
908
+ * 白名单与路由清单,为一次多带的内容再加一条要让两处跟着动。
916
909
  *
917
910
  * `revokedCount` 是历史里的行数,只用来决定面板摆不摆那张卡、折叠行说几台;它与
918
911
  * `devices` 来自同一次内存扫描,不额外查一遍也不缓存 —— 缓存会让「刚解绑的那台」迟到一会儿。
@@ -952,8 +945,7 @@ function registerControlPlaneRoutes(deps) {
952
945
 
953
946
  registerRoute({ kind: 'exact', path: '/api/relay/devices/history/clear', handler: localOnly('POST', async (_req, res) => {
954
947
  // 清空「已解绑」历史:凭据库只删已结束的记录,活设备与密钥一律不动。本地运维动作,
955
- // 与 revoke / revoke-all 同一档:进 WEB_ACCESS_ROUTES 保持白名单语义统一,进
956
- // LOCAL_OPERATOR_ROUTES 让公网两小时窗口也放不过来。
948
+ // 与 revoke / revoke-all 同一档,进 WEB_ACCESS_ROUTES 保持白名单语义统一。
957
949
  const cleared = typeof credentials.clearHistory === 'function' ? credentials.clearHistory(state.instanceId) : 0
958
950
  return sendJson(res, 200, { ok: true, cleared })
959
951
  }) })
@@ -1016,6 +1008,9 @@ function registerControlPlaneRoutes(deps) {
1016
1008
  patch.manualLanUrl = body.manualLanUrl.trim().replace(/\/+$/, '')
1017
1009
  }
1018
1010
  // 用户手填的 IPv6 直连地址(`http://[240e::1]:18787`)。空串合法 = 清掉,口径同上一条。
1011
+ if (typeof body?.manualIpv4Url === 'string' && body.manualIpv4Url.length <= 200) {
1012
+ patch.manualIpv4Url = body.manualIpv4Url.trim().replace(/\/+$/, '')
1013
+ }
1019
1014
  if (typeof body?.manualIpv6Url === 'string' && body.manualIpv6Url.length <= 200) {
1020
1015
  patch.manualIpv6Url = body.manualIpv6Url.trim().replace(/\/+$/, '')
1021
1016
  }
@@ -1297,7 +1292,6 @@ function registerControlPlaneRoutes(deps) {
1297
1292
  // 开到网页面板上:面板与 App 读同一份扫描结果,两边不各算一套口径。
1298
1293
  //
1299
1294
  // 走 localOnly:清的是本机上那个固定收件目录,属于本机运维动作,和其余控制面一样。
1300
- // 面板侧也因此在网页管理窗口打不开时仍可由本机操作。
1301
1295
  registerRoute({ kind: 'exact', path: '/api/relay/inbox/status', handler: localOnly('GET', async (_req, res) => {
1302
1296
  sendJson(res, 200, usageView(await scanInbox()))
1303
1297
  }) })
@@ -1326,22 +1320,21 @@ function registerControlPlaneRoutes(deps) {
1326
1320
  }
1327
1321
 
1328
1322
  // 路由字符串清单放在注册区之后,避免被按路由源码切片的契约测试误认为是真正的 handler。
1329
- /** 网页管理的固定开放窗口;按单调时钟计时,系统校时不会把窗口意外延长。 */
1330
- const WEB_ACCESS_WINDOW_MS = 2 * 60 * 60 * 1000;
1331
- // 只读管理面路由清单:来源限制已放开(从哪儿打开都能进),清单保留用于路由盘点与契约测试。
1323
+ // 控制面路由清单:不再参与放行判断,保留用于路由盘点与契约测试。
1332
1324
  const WEB_ACCESS_ROUTES = new Set([
1333
1325
  '/api/relay/addresses',
1334
1326
  '/api/relay/probe-relays',
1327
+ '/api/relay/probe-direct',
1335
1328
  '/api/relay/status',
1336
1329
  '/api/relay/panel',
1337
1330
  '/api/relay/panel/setup',
1338
1331
  '/api/relay/panel/settings',
1339
- // 控制台那一窗:与上面几条同一张管理面,漏了就等于远程浏览器能绕过窗口读它。
1332
+ // 控制台那一窗:与上面几条同一张管理面,盘点漏了它就少一条。
1340
1333
  '/api/relay/panel/console',
1341
- // 远程电脑独立页:同一张管理面,窗口门漏了它等于远程浏览器绕过窗口读这一页。
1334
+ // 远程电脑独立页:同一张管理面,盘点漏了它就少一条。
1342
1335
  '/api/relay/panel/remote',
1343
1336
  '/api/relay/faults',
1344
- // 配对二维码含一次性票据,同时受 LOCAL_OPERATOR_ROUTES 限制;本机及局域网直连可取,公网窗口不放行。
1337
+ // 配对二维码含一次性票据:与其它路由一样不按来源拦,只拒绝经中转 / 局域网代理转发来的请求。
1345
1338
  '/api/relay/pairing',
1346
1339
  '/api/relay/feedback',
1347
1340
  '/api/relay/toggle',
@@ -1354,10 +1347,13 @@ const WEB_ACCESS_ROUTES = new Set([
1354
1347
  '/api/relay/tailcat',
1355
1348
  '/api/relay/tailcat/enabled',
1356
1349
  '/api/relay/tailcat/revoke',
1357
- // FRP 直连的启停:同属管理动作(收在 LOCAL_OPERATOR_ROUTES 里只认本机/局域网),
1358
- // 但仍留在窗口白名单里保持「路由都在白名单」这条语义统一。
1350
+ // FRP 直连的配置读取与启停:与其它管理动作一样不按来源拦,仍留在清单里保持盘点完整。
1351
+ '/api/relay/frp/config',
1359
1352
  '/api/relay/frp/import',
1360
1353
  '/api/relay/frp/stop',
1354
+ // Cloudflare 兜底隧道的启停:与其它管理动作一样不按来源拦,仍留在清单里保持盘点完整。
1355
+ '/api/cloudflare/start',
1356
+ '/api/cloudflare/stop',
1361
1357
  // 点对点隧道的现状与启停(没有白名单:能连上的前提就是密钥对得上)。
1362
1358
  '/api/relay/p2p',
1363
1359
  '/api/relay/p2p/enabled',
@@ -1382,37 +1378,6 @@ const WEB_ACCESS_ROUTES = new Set([
1382
1378
  '/api/relay/inbox/auto',
1383
1379
  ]);
1384
1380
 
1385
- /**
1386
- * 会改动本机状态或泄露密钥的管理操作。它们除了过 localOnly,还要求请求来自本机或
1387
- * 标准局域网直连(socket 与 Host 均在可信网络,无转发头)。公网两小时窗口只放行只读面板,
1388
- * 不放行这些动作。
1389
- *
1390
- * 这里只收「动作」:读类的 status / addresses / devices(清单)/ faults / selfcheck 等仍走窗口,
1391
- * 因为它们不改本机状态、也不吐密钥材料。
1392
- */
1393
- const LOCAL_OPERATOR_ROUTES = new Set([
1394
- '/api/relay/pairing',
1395
- '/api/relay/feedback',
1396
- '/api/relay/toggle',
1397
- '/api/relay/regenerate',
1398
- '/api/relay/config',
1399
- '/api/relay/revoke-all',
1400
- '/api/relay/devices/revoke',
1401
- '/api/relay/devices/history/clear',
1402
- '/api/relay/tailcat/enabled',
1403
- '/api/relay/tailcat/revoke',
1404
- '/api/relay/p2p/enabled',
1405
- // FRP 直连的启停:会拉起/杀掉本机进程,属于只允许本机或局域网直连的动作。
1406
- '/api/relay/frp/import',
1407
- '/api/relay/frp/stop',
1408
- '/api/relay/update/apply',
1409
- '/api/relay/update/auto',
1410
- '/api/relay/update/ota/apply',
1411
- '/api/relay/restart-sidecar',
1412
- '/api/relay/reload-implementation',
1413
- '/api/relay/inbox/clear',
1414
- '/api/relay/inbox/auto',
1415
- ]);
1416
1381
 
1417
1382
  // `panelDiagnosis` 一并导出,只为让 test/panel-artifact.test.cjs 能拿临时目录跑那三条分支:
1418
1383
  // 三种「读不到」的文案分别对应「重启 / 升级 / 构建」,它们混起来就是这个 bug 的原样。
@@ -1422,8 +1387,4 @@ module.exports = {
1422
1387
  panelUrlOf,
1423
1388
  panelScopeOf,
1424
1389
  WEB_ACCESS_ROUTES,
1425
- LOCAL_OPERATOR_ROUTES,
1426
- WEB_ACCESS_WINDOW_MS,
1427
- createWebAccessWindow,
1428
- createWebAccessLocalOnly,
1429
1390
  };
@@ -20,7 +20,7 @@
20
20
  const { sendJson } = require('../http/routing.js');
21
21
  const { readJsonBody } = require('../shared/http-util.js');
22
22
  const { createP2PRendezvousHandler } = require('../p2p/rendezvous.cjs');
23
- const { orderCandidates, withManualCandidate, manualCandidate, withManualIpv6Candidate, tcpDirectTarget } = require('../relay/lan-network.cjs');
23
+ const { orderCandidates, withManualCandidate, manualCandidate, withManualIpv4Candidate, withManualIpv6Candidate, tcpDirectTarget } = require('../relay/lan-network.cjs');
24
24
  // 中转地址两格的收敛(`relayUrls[0] === relayUrl`)。直接 require 而不是走注入:它是纯函数,
25
25
  // 而这两条路由里少一格就是「手机看到两个矛盾的地址」,不该依赖装配层有没有把它递进来。
26
26
  const { relayAddressesOf, publicRelayBlocked } = require('../relay/core.js');
@@ -235,6 +235,11 @@ function registerMobileRoutes(deps) {
235
235
  // 形状与 `/api/relay/status` 的 `p2p` 完全一致(同一个 `getP2P()`),手机按该口的
236
236
  // `available / enabled / ready / started / path` 说话,不自己猜。
237
237
  p2p: p2p && typeof p2p.status === 'function' ? p2p.status() : null,
238
+ // 「Cloudflare 兜底隧道」这一格。形状照上面 p2p 那条先例:直接取 runner 的 `status()`
239
+ // (`{available,running,pid,url,error,startedAt,starting,retrying,waitingForPort,enabled}`),
240
+ // 手机按该口说话、不自己猜。它是独立线路自己的状态,和 p2p / 中转互不覆盖;宿主没接这一
241
+ // 块(老装配 / 运行时没起)时为 null,手机当「没有这条线路」处理。
242
+ cloudflare: deps.cloudflare && typeof deps.cloudflare.status === 'function' ? deps.cloudflare.status() : null,
238
243
  // 公用中转被宿主强制停用了(用户配了公网可达的自建:自建中转 / 直连 / TCP 直连)。
239
244
  // 面板那份 status(control-plane.js)早就带这一格,手机走的这条心跳原先没带 ——
240
245
  // 于是手机永远按「公用中转还开着」画网络页:选择线路里仍摆「只走公用中转」、
@@ -408,7 +413,7 @@ function registerMobileRoutes(deps) {
408
413
  // 手填的直连地址(穿透域名)缀在**最后**当兜底:它绕公网、比内网慢一个数量级,排在前面
409
414
  // 就等于让手机永远选中它、家里那条内网地址一次都不试(见 `withManualCandidate` 的注释)。
410
415
  const candidates = state.lanEnabled && port > 0
411
- ? withManualCandidate(orderCandidates(safeLanCandidates(port), state.preferredLanAddress), state.manualLanUrl)
416
+ ? withManualIpv4Candidate(withManualCandidate(orderCandidates(safeLanCandidates(port), state.preferredLanAddress), state.manualLanUrl), state.manualIpv4Url)
412
417
  : []
413
418
  // IPv6 直连候选:单独一份、**不参与**上面的排序 —— 它和中转谁更快只有手机实测得出,
414
419
  // 宿主无从判断对端走哪条路由。IPv6 监听独立于局域网开关,关闭 IPv4 不隐藏 IPv6。
@@ -436,6 +441,9 @@ function registerMobileRoutes(deps) {
436
441
  lanCandidates: candidates,
437
442
  // 手填的直连地址单独一格(空串 = 没填 / 局域网关掉):手机把它落到「直连」栏。
438
443
  directUrl,
444
+ // 「Cloudflare 兜底隧道」地址:独立字段(不塞进 directUrl / lanUrls)。空串 = 没起 / 没拿到。
445
+ // 与二维码 / pairing 的 `cloudflareUrl` 同一口径,手机据此把它落到自己的 Cloudflare 槽。
446
+ cloudflareUrl: typeof state.cloudflareUrl === 'string' ? state.cloudflareUrl : '',
439
447
  ipv6Candidates: ipv6,
440
448
  // 「TCP 直连」目标:从设置项 `manualTcpUrl` 解出来,只此一条、不掺网卡候选(与二维码同一来源)。
441
449
  // **始终带这一格**(没配时是空串):手机据此分清「老宿主不认识这格」(整格不出现,别动它手上
@@ -12,6 +12,7 @@ function createRouteChannels() {
12
12
  { channel: 'tunnel', backoffThreshold: 1, budget: 'tunnel' },
13
13
  { channel: 'p2p', backoffThreshold: 1, budget: 'tunnel' },
14
14
  { channel: 'tcp', backoffThreshold: 2, budget: 'tunnel' },
15
+ { channel: 'cloudflare', backoffThreshold: 1, budget: 'tunnel' },
15
16
  ];
16
17
 
17
18
  return exports;
@@ -161,7 +161,7 @@ function createRoutePolicy() {
161
161
  const unknown = warm.filter((route) => !isFresh(facts, norm(route.url)));
162
162
  const ordered = [...known, ...unknown, ...cold];
163
163
  const at = ordered.findIndex((route) => norm(route.url) === current);
164
- if (at <= 0 || cool.has(current) || !isFresh(facts, current))
164
+ if (at <= 0 || cool.has(current))
165
165
  return ordered;
166
166
  const currentCost = settledCostOf(facts, current);
167
167
  if (currentCost === undefined)
@@ -174,6 +174,13 @@ function createRoutePolicy() {
174
174
  const noise = noiseCostOf(facts, current) + noiseCostOf(facts, headUrl);
175
175
  const clean = penaltyFor(facts, current) === 1 && penaltyFor(facts, headUrl) === 1;
176
176
  const required = Math.max(noise, currentCost * ROUTE_SWITCH_SHARE, clean ? SWITCH_GAIN_FLOOR_MS : 0);
177
+ if (!isFresh(facts, current)) {
178
+ if (challenger && gain > 0 && gain <= required) {
179
+ const [item] = ordered.splice(at, 1);
180
+ ordered.unshift(item);
181
+ }
182
+ return ordered;
183
+ }
177
184
  const bouncingBack = facts.lastSwitch?.to === current && facts.lastSwitch.from === headUrl;
178
185
  const worthwhile = headCost !== undefined && gain > required;
179
186
  const settled = !bouncingBack || gain > required * 2;
@@ -1,4 +1,4 @@
1
- // 助手重启读取当前已持久身份与白名单,按 peer 保留 IPC 生命周期。
1
+ // 助手重启读取当前已持久身份与白名单,按 peer 保留 IPC 生命周期;平台表含 Windows ARM64。
2
2
  'use strict';
3
3
 
4
4
  /**
@@ -74,7 +74,12 @@ function platformId(platform = process.platform, arch = process.arch) {
74
74
  const os = platform === 'win32' ? 'win32' : platform;
75
75
  const cpu = arch === 'x64' ? 'x64' : arch === 'arm64' ? 'arm64' : arch;
76
76
  const id = `${os}-${cpu}`;
77
- return ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64', 'win32-x64'].includes(id) ? id : undefined;
77
+ return ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64', 'win32-x64', 'win32-arm64'].includes(id) ? id : undefined;
78
+ }
79
+
80
+ /** 平台包里的助手文件名:Windows(x64 与 ARM64)都带 `.exe`。 */
81
+ function binaryName(platform) {
82
+ return String(platform).startsWith('win32-') ? 'dsh-tailcat-host.exe' : 'dsh-tailcat-host';
78
83
  }
79
84
 
80
85
  /**
@@ -84,7 +89,7 @@ function platformId(platform = process.platform, arch = process.arch) {
84
89
  function resolveBinary(options = {}) {
85
90
  const platform = options.platformId || platformId(options.platform, options.arch);
86
91
  if (!platform) return null;
87
- const name = platform === 'win32-x64' ? 'dsh-tailcat-host.exe' : 'dsh-tailcat-host';
92
+ const name = binaryName(platform);
88
93
  const pkg = `dsh-mobile-tailcat-${platform}`;
89
94
 
90
95
  // 1. 平台包(可选依赖装出来的那份)。npm / pnpm 把可选依赖装在「插件自己这份 node_modules」里,
@@ -342,6 +347,7 @@ module.exports = {
342
347
  TUNNEL_PORT,
343
348
  PAIRING_PORT,
344
349
  platformId,
350
+ binaryName,
345
351
  resolveBinary,
346
352
  createTailcatHost,
347
353
  };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "dsh-mobile-plugin",
3
- "version": "0.5.93",
3
+ "version": "0.5.95",
4
4
  "description": "Mobile API (/api/mobile/v1) and relay client for the DSH mobile app — desktop profile build (dsh 0.2.x, peers resolved by the host)",
5
5
  "license": "MIT",
6
6
  "icon": "./icon.png",
7
7
  "engines": {
8
- "dsh": ">=0.2.0"
8
+ "dsh": ">=0.2.0-0"
9
9
  },
10
10
  "type": "module",
11
11
  "main": "lib/index.js",
@@ -83,17 +83,18 @@
83
83
  "dsh-mobile-shell-linux-arm64": "0.1.2",
84
84
  "dsh-mobile-shell-linux-x64": "0.1.2",
85
85
  "dsh-mobile-shell-win32-x64": "0.1.2",
86
- "dsh-mobile-tailcat-darwin-arm64": "1.1.5",
87
- "dsh-mobile-tailcat-darwin-x64": "1.1.5",
88
- "dsh-mobile-tailcat-linux-arm64": "1.1.5",
89
- "dsh-mobile-tailcat-linux-x64": "1.1.5",
90
- "dsh-mobile-tailcat-win32-x64": "1.1.5"
86
+ "dsh-mobile-tailcat-darwin-arm64": "1.1.7",
87
+ "dsh-mobile-tailcat-darwin-x64": "1.1.7",
88
+ "dsh-mobile-tailcat-linux-arm64": "1.1.7",
89
+ "dsh-mobile-tailcat-linux-x64": "1.1.7",
90
+ "dsh-mobile-tailcat-win32-x64": "1.1.7",
91
+ "dsh-mobile-tailcat-win32-arm64": "1.1.7"
91
92
  },
92
93
  "peerDependencies": {
93
94
  "@deepseek-ai/cordis": ">=4.0.1",
94
- "@deepseek-ai/dsh-client-locale": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1",
95
- "@deepseek-ai/dsh-settings": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1",
96
- "@deepseek-ai/dsh-tools": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1",
95
+ "@deepseek-ai/dsh-client-locale": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
96
+ "@deepseek-ai/dsh-settings": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
97
+ "@deepseek-ai/dsh-tools": "^0.1.1-rc.2 || ^0.2.0-rc.1 || ^0.2.1-rc.2 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
97
98
  "@deepseek-ai/schemastery": "^3.18.1"
98
99
  },
99
100
  "dsh": {
@@ -110,9 +111,9 @@
110
111
  }
111
112
  },
112
113
  "devDependencies": {
113
- "@deepseek-ai/dsh-host-directory-picker-browse": "^0.2.1-rc.3 || ^0.2.2-rc.1",
114
- "@deepseek-ai/dsh-tool-ask-user": "^0.2.1-rc.3 || ^0.2.2-rc.1",
115
- "@deepseek-ai/dsh-tool-present": "^0.2.1-rc.3 || ^0.2.2-rc.1",
114
+ "@deepseek-ai/dsh-host-directory-picker-browse": "^0.2.1-rc.3 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
115
+ "@deepseek-ai/dsh-tool-ask-user": "^0.2.1-rc.3 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
116
+ "@deepseek-ai/dsh-tool-present": "^0.2.1-rc.3 || ^0.2.2-rc.1 || ^0.2.3-alpha.1",
116
117
  "yaml": "2.9.1"
117
118
  }
118
119
  }