dsh-plugin-mobile-gateway 0.6.0 → 0.6.1

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
@@ -1,279 +1,163 @@
1
1
  <p align="center">
2
- <img src="docs/assets/whale-girl-ios-app-promo-16x9.png" alt="鲸鱼娘展示 DeepSeek Harness Mobile 与移动网关" width="100%">
2
+ <img src="docs/assets/whale-girl-ios-app-promo-16x9.png" alt="DeepSeek Harness Mobile 与移动网关" width="100%">
3
3
  </p>
4
4
 
5
5
  # dsh-plugin-mobile-gateway
6
6
 
7
- [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 提供经过设备鉴权的持久化 WebSocket 网关,让 iOS 等移动客户端能够查看工作区和历史会话、收发文字与图片、接收 Agent 实时输出、处理 Human-in-the-loop 选择,以及调整会话模型与权限。
7
+ iPhone 通过经过设备鉴权的 WebSocket 连接 DeepSeek Harness。安装后,Harness WebUI 左侧边栏会出现“移动设备”入口,可直接开启网关、生成配对二维码和管理可信设备。
8
8
 
9
- ![DeepSeek Harness 移动设备管理面板](docs/assets/mobile-device-management.png)
9
+ - WebSocket:`/ws/mobile`
10
+ - 局域网:`ws://<局域网 IP>:3081/ws/mobile`
11
+ - 公网:`wss://<公网 IP>/ws/mobile`
12
+ - 协议文档:[PROTOCOL.md](PROTOCOL.md)
10
13
 
11
- - WebSocket 端点:`/ws/mobile`
12
- - 管理入口:Harness WebUI 左侧边栏底部的“移动设备”
13
- - 默认安全策略:网关默认关闭、设备鉴权默认开启、管理接口仅允许本机访问
14
- - 完整通信格式:[`PROTOCOL.md`](PROTOCOL.md)
14
+ ## 配套 iOS 客户端
15
15
 
16
- ## 直接安装(推荐,无需下载源码)
16
+ [DeepSeek Harness Mobile](https://github.com/Clarklevis1995/dsh-mobile) 是本仓库的兄弟项目。它是面向 iOS 17+ 的 SwiftUI 原生客户端,支持工作区与会话、历史和实时对话、图片、Agent 执行轨迹、Human-in-the-loop、模型与权限设置。
17
17
 
18
- 如果使用 nvm 安装 Node.js,并希望不打开 WebUI、直接从服务器终端生成 iOS 配对字符串,请参照[公网 IP 命令行配对指南](docs/public-ip-deployment-guide.md)。
18
+ <table>
19
+ <tr>
20
+ <td width="33.33%" align="center"><img src="https://raw.githubusercontent.com/Clarklevis1995/dsh-mobile/main/Docs/images/screenshots/home.png" alt="iOS 工作区首页" width="100%"></td>
21
+ <td width="33.33%" align="center"><img src="https://raw.githubusercontent.com/Clarklevis1995/dsh-mobile/main/Docs/images/screenshots/conversation-dark.png" alt="iOS 深色对话界面" width="100%"></td>
22
+ <td width="33.33%" align="center"><img src="https://raw.githubusercontent.com/Clarklevis1995/dsh-mobile/main/Docs/images/screenshots/pairing-dark.png" alt="iOS 设备配对界面" width="100%"></td>
23
+ </tr>
24
+ <tr>
25
+ <td align="center"><strong>工作区首页</strong></td>
26
+ <td align="center"><strong>实时对话</strong></td>
27
+ <td align="center"><strong>设备配对</strong></td>
28
+ </tr>
29
+ </table>
19
30
 
20
- ### 1. 安装插件
31
+ ## 安装插件
21
32
 
22
- 确保本机已经安装并能正常运行 DeepSeek Harness,然后执行:
33
+ 前提:已经安装 `dsh` CLI,并能正常启动 `dsh web`。
23
34
 
24
35
  ```bash
25
36
  dsh plugin --profile web add dsh-plugin-mobile-gateway@latest
26
37
  ```
27
38
 
28
- 这条命令会在执行时从 npm 获取 `latest` 标签指向的最新插件、安装依赖,并将插件加入 `web` profile 的 bundle 列表。用户不需要 clone 仓库,也不需要运行 `pnpm install`。已经安装的插件不会后台自动升级;重新安装最新版本后需要重启 WebUI
29
-
30
- 如果希望固定版本,可以在包名后指定版本号:
39
+ 安装后停止并重新启动 WebUI
31
40
 
32
41
  ```bash
33
- dsh plugin --profile web add dsh-plugin-mobile-gateway@0.6.0
42
+ dsh web
34
43
  ```
35
44
 
36
- 也可以不经过 npm,直接安装 GitHub 版本:
37
-
38
- ```bash
39
- dsh plugin --profile web add github:Clarklevis1995/dsh-plugin-mobile-gateway
40
- ```
45
+ 打开 WebUI,确认左侧边栏底部出现“移动设备”。
41
46
 
42
- ### 2. 重启 Harness WebUI
47
+ ## 局域网配对
43
48
 
44
- 插件组合树只在 WebUI 启动时加载。安装完成后,停止当前的 `dsh web` 进程并重新启动它。刷新浏览器本身不足以加载新安装的服务端插件。
49
+ 适用于 DSH 电脑和 iPhone 位于同一个可互访的局域网。
45
50
 
46
- 可以在启动前检查插件是否进入组合配置:
47
-
48
- ```bash
49
- dsh --profile web --dump-config | grep -A3 mobile-gateway
50
- ```
51
+ 1. 打开 WebUI 的“移动设备”。
52
+ 2. 开启“允许移动设备连接”。
53
+ 3. 保持“设备鉴权”开启。
54
+ 4. 确认面板显示 `ws://<电脑局域网 IP>:3081/ws/mobile`。
55
+ 5. 填写设备名称并点击“生成配对二维码”。
56
+ 6. 在 iOS 客户端打开“设备认证”,扫描二维码。
57
+ 7. WebUI 的可信设备显示“在线”后即完成。
51
58
 
52
- 启动 WebUI 后,左侧边栏底部应出现“移动设备”入口。
59
+ 如果系统防火墙拦截连接,只允许私有网络访问 TCP `3081`。不要把 3081 开放到公网。
53
60
 
54
- ### 3. 局域网直接连接(无需域名、证书或反向代理)
61
+ ## 公网 IP 配对
55
62
 
56
- 插件安装并重启 `dsh web` 后,会额外创建一个仅用于移动端的局域网监听:
63
+ 适用于带固定公网 IPv4 Ubuntu/Debian 服务器(其他发行版本可自行尝试)。Node.js 通过 nvm 安装时,也使用下面的命令。
57
64
 
58
- ```text
59
- ws://<运行 DSH 的电脑局域网 IP>:3081/ws/mobile
60
- ```
65
+ ### 1. 配置端口
61
66
 
62
- 打开 WebUI 的“移动设备”面板时,插件会自动检测电脑的私有 IPv4,并优先把可用地址填入“WebSocket 地址”。开启移动网关、生成二维码并用 iOS 客户端扫码即可。电脑和手机需要位于可互访的同一局域网;如果系统防火墙询问是否允许 Node 接收入站连接,请允许私有网络访问 TCP `3081`。
67
+ 从云厂商控制台复制服务器的公网 IPv4,并在安全组中放行入站 TCP `80` `443`。
63
68
 
64
- 该端口只接受来自本机或私有网络地址的 `/ws/mobile` WebSocket Upgrade,不提供 WebUI,也不暴露 `/mgw/*` 管理接口。局域网监听始终要求设备配对鉴权,WebUI 中的 Debug 鉴权开关不会关闭它的鉴权。
69
+ 不要开放 TCP `3080` `3081`!!!
70
+ 不要开放 TCP `3080` 和 `3081`!!!
71
+ 不要开放 TCP `3080` 和 `3081`!!!
65
72
 
66
- ### 4. 一条命令配置公网 IP(推荐,无需域名)
73
+ ### 2. 配置公网入口
67
74
 
68
- 如果 Harness 部署在带固定公网 IPv4 的腾讯云 Ubuntu/Debian 服务器上,先在腾讯云安全组中放行入站 TCP `80` 和 `443`,然后在服务器执行:
75
+ 把示例 IP 替换为云厂商控制台中的实际公网 IPv4
69
76
 
70
77
  ```bash
71
- sudo npx --yes dsh-plugin-mobile-gateway setup
72
- ```
73
-
74
- 安装器会自动从腾讯云实例元数据读取公网 IPv4,并完成:
75
-
76
- - 安装 Nginx 和独立 Python 虚拟环境中的 Certbot
77
- - 为公网 IP 申请受系统信任的短期 TLS 证书
78
- - 只把 `wss://公网IP/ws/mobile` 代理到 `127.0.0.1:3080`
79
- - 对普通 HTTP、WebUI、`/mgw/*` 管理接口和其他路径返回 `404`
80
- - 创建每天两次运行的 systemd 证书续期任务
81
- - 把公网地址写入 `/etc/dsh-mobile-gateway/public-url`,插件启动时自动读取
82
-
83
- 因此 DSH 仍然只需监听 `127.0.0.1:3080`,不需要把 3080 端口暴露到公网,也不需要 Tunnel、域名或手写 Nginx 配置。
84
-
85
- 邮箱是可选项;希望接收 Let's Encrypt 账户通知时可追加 `--email you@example.com`。如果无法从腾讯云元数据识别公网地址,或 DSH 使用了其他本地端口:
86
-
87
- ```bash
88
- sudo npx --yes dsh-plugin-mobile-gateway setup \
78
+ sudo env "PATH=$PATH" npx --yes dsh-plugin-mobile-gateway@latest setup \
89
79
  --ip 203.0.113.10 \
90
- --port 3080 \
91
- --email you@example.com
80
+ --port 3080
92
81
  ```
93
82
 
94
- 执行完成后重启 `dsh web`,打开 WebUI 的“移动设备”面板。公网 WebSocket 地址会自动显示为 `wss://公网IP/ws/mobile`;开启移动网关并生成二维码即可。
95
-
96
- 查看状态或移除安装器生成的公网入口:
83
+ 安装器完成后,重新启动:
97
84
 
98
85
  ```bash
99
- sudo npx --yes dsh-plugin-mobile-gateway status
100
- sudo npx --yes dsh-plugin-mobile-gateway remove
86
+ dsh web
101
87
  ```
102
88
 
103
- `remove` 只删除本插件生成的 Nginx 配置、地址文件和续期任务,不卸载软件,也不删除已有证书。IP 证书有效期约 6 天,必须保持 80 端口可达以便自动续期。相关能力来自 [Let's Encrypt 的短期 IP 地址证书](https://letsencrypt.org/2026/03/11/shorter-certs-certbot/);公网 IP 自动识别使用[腾讯云实例元数据](https://cloud.tencent.com/document/product/213/17940)。
104
-
105
- #### 已有域名或反向代理
89
+ ### 3. 打开远程 WebUI(使用端口转发,VSCode等IDE自带)
106
90
 
107
- 打开“移动设备”面板:
91
+ 如果 WebUI 运行在远程服务器,在自己的电脑执行:
108
92
 
109
- 1. 开启“允许移动设备连接”。
110
- 2. 保持“设备鉴权”开启。
111
- 3. 在“WebSocket 地址”中填写手机可以访问的地址。
112
-
113
- 本机浏览器调试可以使用:
114
-
115
- ```text
116
- ws://127.0.0.1:3080/ws/mobile
93
+ ```bash
94
+ ssh -N -L 3080:127.0.0.1:3080 <服务器用户名>@<服务器公网 IP>
117
95
  ```
118
96
 
119
- 真机不能使用 `127.0.0.1`,因为它在手机上指向手机自身。同一私有局域网可使用插件自动提供的 `ws://局域网IP:3081/ws/mobile`;公网连接则应通过 TLS 反向代理提供:
97
+ 然后在本地浏览器打开:
120
98
 
121
99
  ```text
122
- wss://gateway.example.com/ws/mobile
100
+ http://127.0.0.1:3080
123
101
  ```
124
102
 
125
- 只有 localhost、`.local` 主机名及 RFC 1918/链路本地私有地址允许使用 `ws://`。其他地址会强制要求 `wss://`,以免一次性配对信息和长期连接暴露在公网明文网络中。
126
-
127
- ### 5. 配对 iOS 客户端
128
-
129
- 1. 在 WebUI 中填写设备名称,例如 `iPhone`。
130
- 2. 点击“生成配对二维码”。
131
- 3. 在 iOS 客户端首页点击认证按钮:
132
- - 选择“扫描二维码”,扫码后自动连接;或
133
- - 选择“手动输入配对信息”,粘贴 WebUI 中复制的 Base64URL 配对 Token,再点击连接。
134
- 4. iOS 首次连接成功后会把长期设备凭证保存到 Keychain。配对二维码只能使用一次,并会在 5 分钟后过期。
135
- 5. WebUI 的可信设备列表显示“在线”,iOS 首页连接状态变为绿色,即表示连接完成。
136
-
137
- 后续启动 iOS 客户端时会使用 Keychain 中的长期凭证重新连接,不需要再次扫码。重新配对同一套 iOS 安装也会复用其设备身份,不会重复创建可信设备。
138
-
139
- ## 日常使用
140
-
141
- 连接成功后,移动客户端可以:
103
+ ### 4. 使用 WebUI 配对
142
104
 
143
- - 浏览工作区、未分组会话和服务端目录
144
- - 创建工作区与新会话
145
- - 加载历史消息与轨迹
146
- - 从历史消息安全加载图片,并把 iOS 本地图片发送给 Agent
147
- - 实时接收思考、工具调用和最终回答
148
- - 向远端 Agent 发送任务
149
- - 查询或切换会话模型、推理等级和访问权限
150
- - 查看上下文用量与会话统计
105
+ 1. 打开“移动设备”。
106
+ 2. 开启“允许移动设备连接”。
107
+ 3. 保持“设备鉴权”开启。
108
+ 4. 确认 WebSocket 地址为 `wss://<公网 IP>/ws/mobile`。
109
+ 5. 填写设备名称并点击“生成配对二维码”。
110
+ 6. iPhone 打开“设备认证”,扫描二维码;也可以复制 Base64URL 配对字符串手动连接。
111
+ 7. WebUI 的可信设备显示“在线”后即完成。
151
112
 
152
- 关闭“允许移动设备连接”会立即断开移动端,但不会影响普通 Harness WebUI。网关开启后,如果默认 5 分钟内没有可信设备成功连接,会自动关闭。
113
+ 二维码只能使用一次,并会在 5 分钟后过期;超时后在 WebUI 重新生成即可。
153
114
 
154
- ## 可信设备管理
115
+ ## 公网入口管理
155
116
 
156
- 长期设备凭证只在首次配对成功时返回一次,移动端应保存在 Keychain。服务端仅保存凭证的 SHA-256 摘要:
117
+ 查看状态:
157
118
 
158
- ```text
159
- ~/.dsh/mobile-gateway-devices.json
119
+ ```bash
120
+ sudo env "PATH=$PATH" npx --yes dsh-plugin-mobile-gateway@latest status
160
121
  ```
161
122
 
162
- 在 WebUI 的“可信设备”列表中点击“吊销”会:
163
-
164
- - 从可信设备列表删除该设备
165
- - 立即关闭该设备现有的 WebSocket 连接
166
- - 使该设备保存的长期凭证永久失效
167
-
168
- 被吊销的设备再次连接会收到 `401 Unauthorized`,需要重新配对。
169
-
170
- ## 更新插件(无需源码)
171
-
172
- 插件会被安装到 profile 中,不会自动更新。升级时重新安装最新 npm 版本并重启 WebUI:
123
+ 移除公网入口:
173
124
 
174
125
  ```bash
175
- dsh plugin --profile web remove dsh-plugin-mobile-gateway
176
- dsh plugin --profile web add dsh-plugin-mobile-gateway
126
+ sudo env "PATH=$PATH" npx --yes dsh-plugin-mobile-gateway@latest remove
177
127
  ```
178
128
 
179
- 然后停止并重新启动 `dsh web`。
129
+ ## 更新插件
180
130
 
181
- ## 卸载
131
+ 重新安装 npm 最新版本:
182
132
 
183
133
  ```bash
184
- dsh plugin --profile web remove dsh-plugin-mobile-gateway
134
+ dsh plugin --profile web add dsh-plugin-mobile-gateway@latest
185
135
  ```
186
136
 
187
- 如果旧版 DSH 没有自动清理 bundle,再从 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` 中删除 `dsh-plugin-mobile-gateway`,随后重启 WebUI。
188
-
189
- 卸载插件不会自动删除 `~/.dsh/mobile-gateway-devices.json`。
190
-
191
- ## 手动公网部署
192
-
193
- 不使用一键安装器时,公网入口应由 Nginx、Caddy 或其他反向代理提供 HTTPS/WSS,并且只公开 WebSocket 路由,不要公开 `/mgw` 管理接口或整个未鉴权 WebUI。
194
-
195
- Nginx 核心配置示例:
137
+ 随后停止并重新启动 `dsh web`。
196
138
 
197
- ```nginx
198
- location = /ws/mobile {
199
- proxy_pass http://127.0.0.1:3080;
200
- proxy_http_version 1.1;
201
- proxy_set_header Upgrade $http_upgrade;
202
- proxy_set_header Connection "upgrade";
203
- }
204
- ```
139
+ ## 卸载插件
205
140
 
206
- TLS 证书、域名、防火墙、访问日志保护和代理层速率限制由部署环境负责。
207
-
208
- 如需把公网地址写入 profile,可在 `cordis.patch.yml` 的 `mobile-gateway` 配置段覆盖:
209
-
210
- ```yaml
211
- - id: mobile-gateway
212
- config:
213
- path: /ws/mobile
214
- gatewayEnabled: false
215
- gatewayWaitTimeoutMs: 300000
216
- requireAuth: true
217
- adminLoopbackOnly: true
218
- lanEnabled: true
219
- lanHost: 0.0.0.0
220
- lanPort: 3081
221
- lanAdvertiseHost: ''
222
- publicUrl: wss://gateway.example.com/ws/mobile
223
- publicUrlFile: /etc/dsh-mobile-gateway/public-url
224
- pairingTtlMs: 300000
225
- allowQueryToken: false
141
+ ```bash
142
+ dsh plugin --profile web remove dsh-plugin-mobile-gateway
226
143
  ```
227
144
 
228
- 后置 patch 会替换整个配置段,因此覆盖时应保留所有需要的字段。
229
-
230
145
  ## 常见问题
231
146
 
232
- | 现象 | 原因与处理方式 |
147
+ | 现象 | 处理方式 |
233
148
  |---|---|
234
- | WebUI 没有“移动设备”入口 | 确认使用 `--profile web` 安装;执行 `--dump-config` 检查组合树,然后完整重启 `dsh web` |
235
- | iOS 连接提示 `503` | 移动网关尚未开启,回到 WebUI 开启“允许移动设备连接” |
236
- | iOS 连接提示 `401` | 配对码过期、长期凭证无效或设备已被吊销;删除客户端旧凭证后重新配对 |
237
- | 真机无法连接 `127.0.0.1` | `127.0.0.1` 在手机上不是电脑;局域网使用面板自动显示的 `ws://私有IP:3081/ws/mobile`,公网使用 `wss://` 地址 |
238
- | 同一 Wi-Fi 仍无法连接局域网地址 | 确认手机与电脑所在网络允许设备互访,并放行电脑入站 TCP 3081;访客 Wi-Fi 通常会启用客户端隔离 |
239
- | 一键配置无法识别公网 IP | 确认命令运行在腾讯云 CVM 内,或通过 `--ip <公网 IPv4>` 显式指定 |
240
- | Certbot 申请或续期失败 | 确认腾讯云安全组和服务器防火墙都允许入站 TCP 80/443,并确认公网 IP 没有变化 |
241
- | 想检查自动续期 | 执行 `sudo systemctl status dsh-mobile-gateway-cert-renew.timer` 和 `sudo npx --yes dsh-plugin-mobile-gateway status` |
242
- | 二维码无法再次使用 | 配对码设计为一次性且 5 分钟过期,重新生成即可 |
243
- | 修改配置后没有生效 | 插件与 profile composition 在启动时加载,需要重启 WebUI 进程 |
244
- | 需要排查服务端原因 | 查看 `/tmp/mobile-gateway.log`,其中包含连接、鉴权、查询与错误记录 |
245
-
246
- ## 安全说明
247
-
248
- - 不建议关闭设备鉴权。该开关仅用于本机 Debug,重启后会恢复安全默认值。
249
- - `/mgw/*` 默认只接受 loopback 请求,不应通过公网反向代理暴露。
250
- - 长期 token 默认禁止通过 URL query 传输,避免进入代理日志、浏览器历史或监控系统。
251
- - 配对二维码和长期 token 不会明文写入服务端磁盘。
149
+ | WebUI 没有“移动设备” | 确认安装在 `web` profile,并完整重启 `dsh web` |
150
+ | iOS 收到 `503` | 回到 WebUI 开启“允许移动设备连接” |
151
+ | iOS 收到 `401` | WebUI 重新生成二维码并配对 |
152
+ | 公网连接超时 | 检查云安全组、服务器防火墙和 TCP `80/443` |
153
+ | 公网地址没有自动显示 | 确认已执行 `setup --ip <公网 IP>`,然后重启 `dsh web` |
154
+ | 需要查看服务端日志 | 执行 `tail -f /tmp/mobile-gateway.log` |
252
155
 
253
156
  ## 源码开发
254
157
 
255
- 只有需要修改插件本身时才需要源码安装:
256
-
257
158
  ```bash
258
159
  dsh plugin --profile web add file:/absolute/path/to/dsh-plugin-mobile-gateway
160
+ npm test
259
161
  ```
260
162
 
261
- `file:` 是复制安装。修改源码后必须先 remove、再 add,并重启 WebUI;不要使用 `link:`,否则依赖可能从源码目录解析而导致 `ws` 等包无法找到。
262
-
263
- 测试命令:
264
-
265
- ```bash
266
- # 鉴权、配对与吊销
267
- NODE_PATH=/path/to/dsh/node_modules node test/auth.test.mjs
268
-
269
- # mock Harness + 真实 WebSocket 客户端的完整协议链路
270
- NODE_PATH=/path/to/dsh/node_modules node test/gateway.test.mjs
271
-
272
- # 公网 IP 安装器的参数、Nginx 隔离与续期配置
273
- node test/setup-ip.test.mjs
274
-
275
- # 独立局域网监听、强制鉴权与管理接口隔离
276
- node test/lan.test.mjs
277
- ```
278
-
279
- 版本历史与全部 WebSocket 消息类型见 [`PROTOCOL.md`](PROTOCOL.md)。
163
+ 源码修改后需要重新安装插件并重启 `dsh web`。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-plugin-mobile-gateway",
3
- "version": "0.6.0",
4
- "description": "Persistent WebSocket gateway for dsh: exposes /ws/mobile on the web server and forwards agent session output to connected mobile clients",
3
+ "version": "0.6.1",
4
+ "description": "update readme",
5
5
  "main": "lib/index.mjs",
6
6
  "files": [
7
7
  "bin",
@@ -1,135 +0,0 @@
1
- # 公网 IP 命令行配对指南
2
-
3
- 适用于通过 nvm 安装 Node.js、已经可以直接使用 `dsh` 命令的 Ubuntu/Debian 服务器。服务器端不需要打开 WebUI:终端会直接输出 iOS 所需的 Base64URL 配对字符串。
4
-
5
- ## 1. 放行公网端口
6
-
7
- 先在云安全组中放行 TCP `80` 和 `443`。不要开放 `3080`、`3081` 或 `/mgw/*`。
8
-
9
- 如果服务器启用了 UFW:
10
-
11
- ```bash
12
- sudo ufw allow 80/tcp
13
- sudo ufw allow 443/tcp
14
- ```
15
-
16
- ## 2. 安装插件和辅助命令
17
-
18
- ```bash
19
- dsh plugin --profile web add dsh-plugin-mobile-gateway@latest
20
- sudo apt-get update
21
- sudo apt-get install -y jq tmux
22
- ```
23
-
24
- ## 3. 配置公网 WSS
25
-
26
- 获取服务器公网 IPv4:
27
-
28
- ```bash
29
- PUBLIC_IP="$(curl -4 -fsS https://ifconfig.me)"
30
- printf 'Public IP: %s\n' "$PUBLIC_IP"
31
- ```
32
-
33
- 如果显示的不是服务器实际公网 IPv4,请手动执行 `PUBLIC_IP="实际公网IP"`。
34
-
35
- 因为 Node.js 来自 nvm,运行安装器时需要把当前 `PATH` 传给 `sudo`:
36
-
37
- ```bash
38
- sudo env "PATH=$PATH" npx --yes dsh-plugin-mobile-gateway@latest setup \
39
- --ip "$PUBLIC_IP" \
40
- --port 3080
41
- ```
42
-
43
- 安装成功后检查:
44
-
45
- ```bash
46
- sudo env "PATH=$PATH" npx --yes dsh-plugin-mobile-gateway@latest status
47
- ```
48
-
49
- 应显示:
50
-
51
- ```text
52
- wss://<公网IP>/ws/mobile
53
- ```
54
-
55
- ## 4. 启动 DSH
56
-
57
- ```bash
58
- tmux new -s dsh
59
- dsh web
60
- ```
61
-
62
- 看到 `dsh web: http://127.0.0.1:3080` 后,按 `Ctrl+B`,再按 `D`,让 DSH 在后台继续运行。
63
-
64
- ## 5. 在终端生成配对字符串
65
-
66
- 重新读取公网地址,并明确开启设备鉴权和移动网关:
67
-
68
- ```bash
69
- PUBLIC_IP="$(curl -4 -fsS https://ifconfig.me)"
70
- PUBLIC_URL="wss://$PUBLIC_IP/ws/mobile"
71
-
72
- curl -fsS -X POST http://127.0.0.1:3080/mgw/auth \
73
- -H 'Content-Type: application/json' \
74
- -d '{"enabled":true}'
75
-
76
- curl -fsS -X POST http://127.0.0.1:3080/mgw/gateway \
77
- -H 'Content-Type: application/json' \
78
- -d '{"enabled":true}'
79
- ```
80
-
81
- 生成一次性 Base64URL 配对字符串:
82
-
83
- ```bash
84
- PAIRING_TEXT="$(
85
- jq -nc --arg name 'iPhone' --arg url "$PUBLIC_URL" \
86
- '{name:$name,publicUrl:$url}' \
87
- | curl -fsS -X POST http://127.0.0.1:3080/mgw/pair \
88
- -H 'Content-Type: application/json' \
89
- --data-binary @- \
90
- | jq -r '.qrPayload'
91
- )"
92
-
93
- if [ -z "$PAIRING_TEXT" ] || [ "$PAIRING_TEXT" = 'null' ]; then
94
- echo '生成配对字符串失败,请检查 DSH 和插件日志'
95
- else
96
- printf '\n复制下面这一整行到 iPhone:\n\n%s\n\n' "$PAIRING_TEXT"
97
- fi
98
- ```
99
-
100
- 配对字符串只能使用一次,并在 5 分钟后过期。如果超时,重新执行本节最后两段命令。
101
-
102
- ## 6. 在 iPhone 完成绑定
103
-
104
- 1. 打开 iOS 客户端的“设备认证”。
105
- 2. 把终端输出的整行内容粘贴到“手动输入配对信息”。
106
- 3. 点击“配对并连接”或“重新配对并连接”。
107
- 4. 状态显示“已连接”后点击“完成”。
108
-
109
- iOS 会把长期设备凭证保存到 Keychain,之后启动时会自动重新连接,不需要再次执行配对。
110
-
111
- ## 7. 检查结果
112
-
113
- 服务器查看可信设备:
114
-
115
- ```bash
116
- curl -fsS http://127.0.0.1:3080/mgw/devices | jq
117
- ```
118
-
119
- 查看插件日志:
120
-
121
- ```bash
122
- tail -f /tmp/mobile-gateway.log
123
- ```
124
-
125
- 常见结果:
126
-
127
- - `503`:移动网关未开启,重新执行第 5 节的网关开启命令。
128
- - `401`:配对字符串过期、已使用或客户端凭证无效,重新生成配对字符串。
129
- - 公网连接超时:检查云安全组、UFW、Nginx,以及 TCP `80/443`。
130
-
131
- 查看后台 DSH:
132
-
133
- ```bash
134
- tmux attach -t dsh
135
- ```