dsh-mobile-plugin 0.5.52 → 0.5.53
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 +10 -0
- package/dsh-mobile-credentials/lib/credentials.js +34 -2
- package/lib/impl.js +5 -0
- package/lib/mobile/directory-listing.js +3 -1
- package/lib/mobile/host-bridge/endpoints.js +2 -1
- package/lib/mobile/permissions.js +1 -3
- package/lib/mobile/workspaces.js +6 -5
- package/lib/panel/index.html +8 -8
- package/lib/relay/lan-proxy.js +15 -8
- package/lib/remote/browser-notice.cjs +118 -0
- package/lib/remote/controller.cjs +212 -0
- package/lib/remote/crypto.cjs +197 -0
- package/lib/remote/host-control.cjs +59 -0
- package/lib/remote/host.cjs +226 -0
- package/lib/remote/local-headers.cjs +102 -0
- package/lib/remote/local-upstream.cjs +144 -0
- package/lib/remote/local.cjs +144 -0
- package/lib/remote/network.cjs +42 -0
- package/lib/remote/router.cjs +194 -0
- package/lib/remote/routes.cjs +73 -0
- package/lib/remote/runtime.cjs +36 -0
- package/lib/remote/store.cjs +60 -0
- package/lib/remote/transport.cjs +184 -0
- package/lib/remote/tunnel-helper.cjs +167 -0
- package/lib/remote/tunnels.cjs +190 -0
- package/lib/routes/mobile-api.js +7 -2
- package/lib/shared/route-order.cjs +202 -0
- package/package.json +7 -6
- package/lib/mobile/perf-trace.js +0 -142
package/README.md
CHANGED
|
@@ -45,6 +45,16 @@
|
|
|
45
45
|
- **模型**:随时换模型,看有哪些渠道和可用模型,本机自建的渠道也能直接在手机上配。
|
|
46
46
|
- **日程与子代理**:定时任务能看、新建、改、暂停恢复、立刻跑一次、删掉;看正在跑的子代理,打断它或者补一句话。
|
|
47
47
|
|
|
48
|
+
### 远程电脑
|
|
49
|
+
|
|
50
|
+
在家里的 A 电脑打开插件控制台的「远程电脑」,生成并复制绑定信息,再到随身的 B 电脑粘贴添加。绑定信息十分钟内有效、只能使用一次;两台电脑都需要安装支持远程电脑的插件。
|
|
51
|
+
|
|
52
|
+
绑定后在 B 点击「浏览器打开」,即可通过本机地址使用 A 的完整 DSH 网页,不需要域名或手机参与。默认自动选择局域网、直连、IPv6、中转或可用隧道;网络变化后重新选路,正常的实时连接不会因细小测速差异被打断。完整网页授权具有远程操作该 DSH 的能力,只向自己信任的电脑发放。
|
|
53
|
+
|
|
54
|
+
每次网页访问允许一小时,临近到期会提示;在 B 的插件控制台主动续期才能继续,到期后须重新打开,绑定关系保留。停止访问、插件退出或 A 撤销授权会断开网页连接,不停止 A 上已经运行的任务。A 可在「可访问本机的电脑」中撤销 B;B 可移除自己保存的绑定。
|
|
55
|
+
|
|
56
|
+
网页字节在两端插件之间加密,线路只转发密文;长期绑定凭据由宿主凭据存储保存,浏览器只持有本次访问的临时会话。默认只监听本机回环,不把浏览器入口开放给局域网。
|
|
57
|
+
|
|
48
58
|
### 连接
|
|
49
59
|
|
|
50
60
|
- 两种连法:经 relay v2 隧道从公网连回来,或者同一个 Wi-Fi 下走局域网直连。
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
// 电脑网页授权独立于手机权限;调整设备权限会同步收回该授权。
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 每设备凭据库:签发、校验、吊销手机端的持久化凭据。
|
|
@@ -211,6 +212,7 @@ function issue(instanceId, device, hostToken, ttlMs = DEFAULT_TTL_MS, extra = {}
|
|
|
211
212
|
// **只在真给了数组时才写这一格**:不写 = 全权,这是老记录与现网设备的兼容命门,
|
|
212
213
|
// 绝不能在这里补一个默认数组把「没设置」变成「设置成某个子集」。
|
|
213
214
|
if (Array.isArray(extra?.permissions)) record.permissions = extra.permissions.slice();
|
|
215
|
+
if (extra?.remoteWeb === true && deviceKey && keyId) { record.remoteWeb = true; record.kind = 'computer'; }
|
|
214
216
|
prune(now);
|
|
215
217
|
records.push(record);
|
|
216
218
|
rebuildIndex();
|
|
@@ -248,6 +250,7 @@ function setDevicePermissions(instanceId, deviceId, permissions) {
|
|
|
248
250
|
for (const record of records) {
|
|
249
251
|
if (record.instanceId !== instanceId || record.deviceId !== deviceId || !isLive(record)) continue;
|
|
250
252
|
record.permissions = wanted.slice();
|
|
253
|
+
if (record.remoteWeb === true) record.remoteWeb = false;
|
|
251
254
|
count += 1;
|
|
252
255
|
}
|
|
253
256
|
if (count) save();
|
|
@@ -305,6 +308,17 @@ function findByKeyId(instanceId, keyId) {
|
|
|
305
308
|
return null;
|
|
306
309
|
}
|
|
307
310
|
|
|
311
|
+
/** 电脑通道只用它签署已吊销/到期的拒绝,不把失效记录恢复为授权。 */
|
|
312
|
+
function lookupRemoteByKeyId(instanceId, keyId) {
|
|
313
|
+
refresh();
|
|
314
|
+
if (typeof keyId !== 'string' || !keyId) return null;
|
|
315
|
+
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
316
|
+
const record = records[i];
|
|
317
|
+
if (record.instanceId === instanceId && record.keyId === keyId && record.deviceKey) return record;
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
|
|
308
322
|
/**
|
|
309
323
|
* 记一次「这台设备刚连上过」。
|
|
310
324
|
*
|
|
@@ -402,6 +416,22 @@ function revokeAllByInstance(instanceId) {
|
|
|
402
416
|
return count;
|
|
403
417
|
}
|
|
404
418
|
|
|
419
|
+
/** 本实例仍有效的电脑网页授权,只返回管理清单需要的公开字段。 */
|
|
420
|
+
function listRemoteComputers(instanceId) {
|
|
421
|
+
refresh();
|
|
422
|
+
const now = Date.now();
|
|
423
|
+
const devices = new Map();
|
|
424
|
+
for (const record of records) {
|
|
425
|
+
if (record.instanceId !== instanceId || record.remoteWeb !== true || !isLive(record, now)) continue;
|
|
426
|
+
const previous = devices.get(record.deviceId);
|
|
427
|
+
if (!previous || record.createdAt > previous.createdAt) devices.set(record.deviceId, {
|
|
428
|
+
deviceId: record.deviceId, name: record.name || '', platform: record.platform || '',
|
|
429
|
+
lastSeenAt: Number(record.lastSeenAt) || 0, createdAt: Number(record.createdAt) || 0,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
return [...devices.values()];
|
|
433
|
+
}
|
|
434
|
+
|
|
405
435
|
function listActive() {
|
|
406
436
|
load();
|
|
407
437
|
const now = Date.now();
|
|
@@ -428,7 +458,7 @@ function scanDevices(instanceId, now = Date.now()) {
|
|
|
428
458
|
/** 名下有过活记录的 deviceId:这种设备在活动清单里已经有一行,历史那半不能再出现它。 */
|
|
429
459
|
const living = new Set();
|
|
430
460
|
for (const record of records) {
|
|
431
|
-
if (record.instanceId !== instanceId) continue;
|
|
461
|
+
if (record.instanceId !== instanceId || record.kind === 'computer') continue;
|
|
432
462
|
const key = String(record.deviceId || '');
|
|
433
463
|
const createdAt = Number(record.createdAt) || 0;
|
|
434
464
|
if (isLive(record, now)) {
|
|
@@ -644,7 +674,7 @@ function activeDigests(instanceId) {
|
|
|
644
674
|
// 记录只在新签发时追加,倒着走就是 createdAt 倒序:超出上限时被截掉的是最老的。
|
|
645
675
|
for (let i = records.length - 1; i >= 0 && live.length < MAX_ACTIVE_DIGESTS; i -= 1) {
|
|
646
676
|
const record = records[i];
|
|
647
|
-
if (record.instanceId !== instanceId || !isLive(record, now)) continue;
|
|
677
|
+
if (record.instanceId !== instanceId || record.kind === 'computer' || !isLive(record, now)) continue;
|
|
648
678
|
live.push({ hash: record.hash, ...(record.expiresAt ? { expiresAt: record.expiresAt } : {}) });
|
|
649
679
|
}
|
|
650
680
|
return live;
|
|
@@ -671,12 +701,14 @@ module.exports = {
|
|
|
671
701
|
lookup,
|
|
672
702
|
isLive,
|
|
673
703
|
findByKeyId,
|
|
704
|
+
lookupRemoteByKeyId,
|
|
674
705
|
touch,
|
|
675
706
|
renew,
|
|
676
707
|
refresh,
|
|
677
708
|
setReadOnly,
|
|
678
709
|
isReadOnly,
|
|
679
710
|
listActive,
|
|
711
|
+
listRemoteComputers,
|
|
680
712
|
listDevices,
|
|
681
713
|
listHistory,
|
|
682
714
|
listDevicesWithHistory,
|
package/lib/impl.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* `lib/sidecar-lifecycle.cjs`、路由表在 `lib/routes/*`,这些实现不许搬回来
|
|
5
5
|
* (`test/assembly-layer.test.cjs` 钉着)。
|
|
6
6
|
*/
|
|
7
|
+
// 远程电脑入口独立装配,手机端路由与权限保持原有边界。
|
|
7
8
|
import { createRequire } from 'node:module'
|
|
8
9
|
import os from 'node:os'
|
|
9
10
|
import path from 'node:path'
|
|
@@ -36,6 +37,7 @@ const { resolvePort } = require('./relay/port-allocator.cjs')
|
|
|
36
37
|
const { mountTailcat } = require('./tailcat/wiring.cjs') // 直连隧道:入口 + 落点代理 + 助手会话 + 启停
|
|
37
38
|
const { mountP2P } = require('./p2p/wiring.cjs') // 点对点隧道:助手会话 + 落点代理(连接从隧道里进来,不必开回环门)
|
|
38
39
|
const { createPreviewService } = require('./relay/preview.js')
|
|
40
|
+
const { mountRemoteComputers } = require('./remote/runtime.cjs')
|
|
39
41
|
// 手机打开「电脑上的网页版」时用的那枚一次性登录令牌(见 mobile/host-web.js)。
|
|
40
42
|
const hostWeb = require('./mobile/host-web.js')
|
|
41
43
|
// 本机设备凭据库:/api/relay/revoke-all 必须同时吊销局域网直连的 dshc_ 凭据,
|
|
@@ -536,10 +538,13 @@ function apply(ctx) {
|
|
|
536
538
|
})
|
|
537
539
|
ctx.effect(() => () => preview.close(), `${name}: preview pipes`)
|
|
538
540
|
|
|
541
|
+
const remoteComputers = mount('远程电脑', () => mountRemoteComputers({ ctx, state, credentials, registerRoute, lanPortInUse: advertisedLanPort, tailcat, p2p, log: warn }))
|
|
542
|
+
|
|
539
543
|
// 移动端路由表在 lib/routes/mobile-api.js:那里是一张可以对着 App 侧 apiPaths.ts
|
|
540
544
|
// 核对的「路径 → handler」表,不用在 1000 行装配代码里翻。
|
|
541
545
|
mount('移动端路由', () => registerMobileRoutes({
|
|
542
546
|
registerRoute,
|
|
547
|
+
remoteComputers,
|
|
543
548
|
// 直连隧道:已配对的手机走这条拿到自己的入口地址,不用重新扫码。
|
|
544
549
|
tailcat,
|
|
545
550
|
// 点对点隧道:会合那一步(手机报上候选、这里把它拉起来并回自己的候选)。
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 文件浏览保留真实目录路径,仅把全空白输入视为缺省目录。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -82,7 +83,8 @@ async function listingRow(directory, name) {
|
|
|
82
83
|
*/
|
|
83
84
|
async function handleDirectoryListing(_ctx, req, res) {
|
|
84
85
|
const url = new URL(req.url, 'http://x');
|
|
85
|
-
const
|
|
86
|
+
const rawPath = url.searchParams.get('path') || '';
|
|
87
|
+
const asked = rawPath.trim() ? rawPath : '';
|
|
86
88
|
if (asked && !fullyQualified(asked)) {
|
|
87
89
|
return fail(res, 'bad-request', `cannot list "${asked}": not a fully qualified path`);
|
|
88
90
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 本地目录浏览与宿主网关一致,保留路径中的首尾空格。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -232,7 +233,7 @@ async function subagentInterrupt(ctx, payload, signal) {
|
|
|
232
233
|
* `formatDirectoryError` 已经按它们写好了文案,两条路对客户端应当不可区分。
|
|
233
234
|
*/
|
|
234
235
|
async function localListDirectory(ctx, payload, signal) {
|
|
235
|
-
const path = payload && typeof payload.path === 'string' && payload.path.trim() ? payload.path
|
|
236
|
+
const path = payload && typeof payload.path === 'string' && payload.path.trim() ? payload.path : undefined;
|
|
236
237
|
try {
|
|
237
238
|
return ok(await listDirectory(path, { signal }));
|
|
238
239
|
} catch (error) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
+
* 操作记录回传接口下线,不再保留对应权限映射。
|
|
4
5
|
* 按设备发放的权限子集:权限位、档位、以及「移动路由 → 所需权限位」的分类表。
|
|
5
6
|
*
|
|
6
7
|
* 这是本次安全边界收紧的**唯一真源**:路由守卫按这里判位,配对档位按这里展开成权限数组,
|
|
@@ -300,9 +301,6 @@ const MAP = Object.freeze({
|
|
|
300
301
|
'/api/mobile/v1/directory/create': V.FILES_WRITE,
|
|
301
302
|
// 把这一轮回答落成文件:带正文写盘,落点与 file/create 同一份允许区,归 files.write。
|
|
302
303
|
'/api/mobile/v1/session/write-body': V.FILES_WRITE,
|
|
303
|
-
// 操作记录回传:本质是往宿主磁盘写文件(`mobile-traces/`),与文件写入同档;以前误挂在
|
|
304
|
-
// BASE 上,等于任何已鉴权设备都能不限量写盘。
|
|
305
|
-
'/api/mobile/v1/perf-trace': V.FILES_WRITE,
|
|
306
304
|
// 项目写入队列的暂停 / 恢复:只切插件自己的队列开关,**一个文件都不写**,所以 POST 也算
|
|
307
305
|
// view(给 files.write 会把只读设备挡在一件它本来就做不了的事之外,没有收益)。
|
|
308
306
|
'/api/mobile/v1/project/writes': { GET: V.VIEW, POST: V.VIEW },
|
package/lib/mobile/workspaces.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// 浏览、创建和工作区登记透传真实路径,保留目录名称末尾的空格。
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -159,7 +160,7 @@ async function handleWorkspaces(ctx, req, res) {
|
|
|
159
160
|
async function handleListDirectory(ctx, req, res) {
|
|
160
161
|
const url = new URL(req.url, 'http://x');
|
|
161
162
|
const path = url.searchParams.get('path');
|
|
162
|
-
const payload = path && path.trim() ? { path
|
|
163
|
+
const payload = path && path.trim() ? { path } : {};
|
|
163
164
|
const { value, error } = unwrap(await callHost(ctx, 'listDirectory', payload));
|
|
164
165
|
if (error) return sendJson(res, 400, { ok: false, error });
|
|
165
166
|
sendJson(res, 200, { ok: true, listing: value });
|
|
@@ -185,9 +186,9 @@ async function handleDirectoryRoots(_ctx, _req, res) {
|
|
|
185
186
|
*/
|
|
186
187
|
async function handleCreateDirectory(ctx, req, res) {
|
|
187
188
|
const body = await readJsonBody(req, 64 * 1024);
|
|
188
|
-
const path = body && typeof body.path === 'string' ? body.path
|
|
189
|
+
const path = body && typeof body.path === 'string' ? body.path : '';
|
|
189
190
|
const name = body && typeof body.name === 'string' ? body.name.trim() : '';
|
|
190
|
-
if (!path || !name) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path 或 name' } });
|
|
191
|
+
if (!path.trim() || !name) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path 或 name' } });
|
|
191
192
|
const { value, error } = unwrap(await callHost(ctx, 'createDirectory', { path, name }));
|
|
192
193
|
if (error) return sendJson(res, 400, { ok: false, error });
|
|
193
194
|
sendJson(res, 200, { ok: true, path: value && value.path });
|
|
@@ -200,8 +201,8 @@ async function handleCreateDirectory(ctx, req, res) {
|
|
|
200
201
|
*/
|
|
201
202
|
async function handleCreateWorkspace(ctx, req, res) {
|
|
202
203
|
const body = await readJsonBody(req, 64 * 1024);
|
|
203
|
-
const path = body && typeof body.path === 'string' ? body.path
|
|
204
|
-
if (!path) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path' } });
|
|
204
|
+
const path = body && typeof body.path === 'string' ? body.path : '';
|
|
205
|
+
if (!path.trim()) return sendJson(res, 400, { ok: false, error: { code: 'bad-request', message: '缺少 path' } });
|
|
205
206
|
const { value, error } = unwrap(await callWorkspace(ctx, 'create', { path }));
|
|
206
207
|
if (error) return sendJson(res, 400, { ok: false, error });
|
|
207
208
|
sendJson(res, 200, { ok: true, workspace: value && value.workspace, created: !!(value && value.created) });
|