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 +85 -201
- package/package.json +2 -2
- package/docs/public-ip-deployment-guide.md +0 -135
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="
|
|
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
|
-
|
|
7
|
+
让 iPhone 通过经过设备鉴权的 WebSocket 连接 DeepSeek Harness。安装后,Harness WebUI 左侧边栏会出现“移动设备”入口,可直接开启网关、生成配对二维码和管理可信设备。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- WebSocket:`/ws/mobile`
|
|
10
|
+
- 局域网:`ws://<局域网 IP>:3081/ws/mobile`
|
|
11
|
+
- 公网:`wss://<公网 IP>/ws/mobile`
|
|
12
|
+
- 协议文档:[PROTOCOL.md](PROTOCOL.md)
|
|
10
13
|
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
+
## 安装插件
|
|
21
32
|
|
|
22
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
如果希望固定版本,可以在包名后指定版本号:
|
|
39
|
+
安装后停止并重新启动 WebUI:
|
|
31
40
|
|
|
32
41
|
```bash
|
|
33
|
-
dsh
|
|
42
|
+
dsh web
|
|
34
43
|
```
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
dsh plugin --profile web add github:Clarklevis1995/dsh-plugin-mobile-gateway
|
|
40
|
-
```
|
|
45
|
+
打开 WebUI,确认左侧边栏底部出现“移动设备”。
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
## 局域网配对
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
适用于 DSH 电脑和 iPhone 位于同一个可互访的局域网。
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
59
|
+
如果系统防火墙拦截连接,只允许私有网络访问 TCP `3081`。不要把 3081 开放到公网。
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
## 公网 IP 配对
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
适用于带固定公网 IPv4 的 Ubuntu/Debian 服务器(其他发行版本可自行尝试)。Node.js 通过 nvm 安装时,也使用下面的命令。
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
ws://<运行 DSH 的电脑局域网 IP>:3081/ws/mobile
|
|
60
|
-
```
|
|
65
|
+
### 1. 配置端口
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
从云厂商控制台复制服务器的公网 IPv4,并在安全组中放行入站 TCP `80` 和 `443`。
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
不要开放 TCP `3080` 和 `3081`!!!
|
|
70
|
+
不要开放 TCP `3080` 和 `3081`!!!
|
|
71
|
+
不要开放 TCP `3080` 和 `3081`!!!
|
|
65
72
|
|
|
66
|
-
###
|
|
73
|
+
### 2. 配置公网入口
|
|
67
74
|
|
|
68
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
查看状态或移除安装器生成的公网入口:
|
|
83
|
+
安装器完成后,重新启动:
|
|
97
84
|
|
|
98
85
|
```bash
|
|
99
|
-
|
|
100
|
-
sudo npx --yes dsh-plugin-mobile-gateway remove
|
|
86
|
+
dsh web
|
|
101
87
|
```
|
|
102
88
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
#### 已有域名或反向代理
|
|
89
|
+
### 3. 打开远程 WebUI(使用端口转发,VSCode等IDE自带)
|
|
106
90
|
|
|
107
|
-
|
|
91
|
+
如果 WebUI 运行在远程服务器,在自己的电脑执行:
|
|
108
92
|
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
97
|
+
然后在本地浏览器打开:
|
|
120
98
|
|
|
121
99
|
```text
|
|
122
|
-
|
|
100
|
+
http://127.0.0.1:3080
|
|
123
101
|
```
|
|
124
102
|
|
|
125
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
113
|
+
二维码只能使用一次,并会在 5 分钟后过期;超时后在 WebUI 重新生成即可。
|
|
153
114
|
|
|
154
|
-
##
|
|
115
|
+
## 公网入口管理
|
|
155
116
|
|
|
156
|
-
|
|
117
|
+
查看状态:
|
|
157
118
|
|
|
158
|
-
```
|
|
159
|
-
|
|
119
|
+
```bash
|
|
120
|
+
sudo env "PATH=$PATH" npx --yes dsh-plugin-mobile-gateway@latest status
|
|
160
121
|
```
|
|
161
122
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
- 从可信设备列表删除该设备
|
|
165
|
-
- 立即关闭该设备现有的 WebSocket 连接
|
|
166
|
-
- 使该设备保存的长期凭证永久失效
|
|
167
|
-
|
|
168
|
-
被吊销的设备再次连接会收到 `401 Unauthorized`,需要重新配对。
|
|
169
|
-
|
|
170
|
-
## 更新插件(无需源码)
|
|
171
|
-
|
|
172
|
-
插件会被安装到 profile 中,不会自动更新。升级时重新安装最新 npm 版本并重启 WebUI:
|
|
123
|
+
移除公网入口:
|
|
173
124
|
|
|
174
125
|
```bash
|
|
175
|
-
|
|
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
|
-
|
|
129
|
+
## 更新插件
|
|
180
130
|
|
|
181
|
-
|
|
131
|
+
重新安装 npm 最新版本:
|
|
182
132
|
|
|
183
133
|
```bash
|
|
184
|
-
dsh plugin --profile web
|
|
134
|
+
dsh plugin --profile web add dsh-plugin-mobile-gateway@latest
|
|
185
135
|
```
|
|
186
136
|
|
|
187
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
235
|
-
| iOS
|
|
236
|
-
| iOS
|
|
237
|
-
|
|
|
238
|
-
|
|
|
239
|
-
|
|
|
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
|
-
|
|
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.
|
|
4
|
-
"description": "
|
|
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
|
-
```
|