dsh-vpn 0.1.7 → 0.1.8
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 +12 -4
- package/assets/vpn-ops.md +3 -2
- package/lib/client.js +179 -7
- package/lib/index.js +224 -136
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-vpn
|
|
2
2
|
|
|
3
|
-
[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 插件:在**你自己的 VPS** 上一键部署加密的 VPN 服务,保护你的网络连接安全。在 dsh 里填好 VPS 的 IP
|
|
3
|
+
[DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 插件:在**你自己的 VPS** 上一键部署加密的 VPN 服务,保护你的网络连接安全。在 dsh 里填好 VPS 的 IP、端口、用户名和密码(或用密钥登录),一键部署 sing-box,然后扫二维码导入手机或电脑上的客户端。
|
|
4
4
|
|
|
5
5
|
## 用途:保护你的网络安全
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
## 特性
|
|
15
15
|
|
|
16
|
-
- **不依赖本机的 ssh 命令**:内置纯 JS 的 SSH 客户端([ssh2](https://github.com/mscdex/ssh2)
|
|
16
|
+
- **不依赖本机的 ssh 命令**:内置纯 JS 的 SSH 客户端([ssh2](https://github.com/mscdex/ssh2)),支持密码登录和密钥登录。
|
|
17
17
|
- **两种用法**:在设置页点按钮,或者直接对 agent 说“帮我装个节点”。
|
|
18
18
|
- **五种协议可选**:VLESS Reality、Hysteria2(默认)、TUIC v5、AnyTLS、Shadowsocks 2022。
|
|
19
19
|
- **免域名的正规证书**:可选 Let's Encrypt 为服务器 IP 签发的证书,所有客户端都能正常校验证书。
|
|
@@ -33,11 +33,18 @@ dsh plugin --profile web add dsh-vpn
|
|
|
33
33
|
|
|
34
34
|
在 VPN 设置里:
|
|
35
35
|
|
|
36
|
-
1. 填写服务器 IP、SSH
|
|
36
|
+
1. 填写服务器 IP、SSH 端口、用户名、密码,点「保存」和「测试连接」。服务器只允许密钥登录的,见下面的「密钥登录」。
|
|
37
37
|
2. 勾选要安装的协议,选择证书类型(推荐「IP 证书」),保存后点「安装 / 更新」。
|
|
38
38
|
3. 在「节点二维码」里点「刷新二维码」,用手机或电脑上的客户端扫码导入。
|
|
39
39
|
4. 服务器防火墙的端口由插件自动放行,不用手动操作;安装完成后提示框会列出放行了哪些端口。
|
|
40
40
|
|
|
41
|
+
**密钥登录**:服务器只允许密钥登录(或者你不想保存密码)时,把「登录方式」选成「密钥」。插件会生成一把专用钥匙(纯 JS 生成,不需要本机的 ssh-keygen),页面上显示它的公钥,任选一种办法放到服务器上:
|
|
42
|
+
|
|
43
|
+
- A. 粘到服务商后台的「SSH 密钥」里,重装系统时勾选它(新机器推荐);
|
|
44
|
+
- B. 已经能登录服务器的(网页控制台或别的终端),复制页面上的一行命令粘贴执行。
|
|
45
|
+
|
|
46
|
+
放好后点「保存」和「测试连接」。已经有自己的私钥、服务器上也放好了对应公钥的,展开「改用我自己已有的私钥」粘贴进去即可(支持带密码短语的私钥)。用非 root 用户时,「sudo 密码」一栏填该用户的 sudo 密码;root 或免密 sudo 不用填。
|
|
47
|
+
|
|
41
48
|
**找回已有节点**:如果重装过 dsh 或 dsh-vpn,本地保存的设置会丢失,但 VPS 上的节点还在。重新填写服务器 IP、端口、用户名和密码后点「保存」,插件会自动检查这台服务器上是否已有安装(也可以随时点「检查已有安装」)。找到后直接显示原来的节点二维码,并按服务器上的实际情况勾选协议和证书类型,已经导入手机或电脑客户端的配置可以继续使用,不用重新扫码。
|
|
42
49
|
|
|
43
50
|
页面第一行显示插件版本,有新版本时旁边会提示,点「更新」即可升级插件,重启 dsh 后生效(需要 dsh 0.2 及以上;更早的版本请在「设置 → 插件」中更新)。为了供应链安全,发布不足 24 小时的新版本会等满 24 小时再提供更新。
|
|
@@ -84,7 +91,8 @@ IP 证书由 sing-box 1.14 内置的 ACME 向 Let's Encrypt 申请([2026 年
|
|
|
84
91
|
|
|
85
92
|
| 方面 | 做法 |
|
|
86
93
|
|---|---|
|
|
87
|
-
|
|
|
94
|
+
| 密码和私钥 | 存在 dsh 凭据库(`$DSH_HOME/.credentials.yaml`,权限 0600),不写进配置文件;浏览器只能写入,读不回来(专用钥匙只向页面提供公钥) |
|
|
95
|
+
| 登录方式 | 只用你选定的一种:选了密钥就只用密钥,不会退回密码;不使用键盘交互登录或 ssh-agent |
|
|
88
96
|
| 接口鉴权 | 设置页的接口挂在 dsh 自己的 `/api` 下,复用 dsh 的登录 cookie 和防跨站、防 DNS rebinding 检查 |
|
|
89
97
|
| 主机指纹 | 首次连接时记录 SSH 主机指纹,之后指纹变化就拒绝连接,防止中间人截获密码 |
|
|
90
98
|
| sudo | 非 root 用户用 `sudo -S`:密码只经 stdin 传入,不会出现在命令行,也不会传给脚本 |
|
package/assets/vpn-ops.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# vpn-ops
|
|
2
2
|
|
|
3
|
-
Deploy and operate a personal, encrypted VPN (sing-box) on the user's own VPS. The plugin logs in over SSH with the password saved in dsh Settings (bottom-left gear) → VPN 设置. No local ssh client is needed.
|
|
3
|
+
Deploy and operate a personal, encrypted VPN (sing-box) on the user's own VPS. The plugin logs in over SSH with the password or key saved in dsh Settings (bottom-left gear) → VPN 设置. No local ssh client is needed.
|
|
4
4
|
|
|
5
5
|
## Purpose
|
|
6
6
|
|
|
@@ -33,7 +33,8 @@ The settings page offers **self-signed** (default) or **IP certificate** (recomm
|
|
|
33
33
|
|
|
34
34
|
| Error / symptom | Likely cause | What to do |
|
|
35
35
|
|---|---|---|
|
|
36
|
-
| `auth_failed` | Wrong username or password | User fixes it on the settings page |
|
|
36
|
+
| `auth_failed` | Wrong username or password, or the server only allows key login | User fixes it on the settings page (Login method → Key) |
|
|
37
|
+
| `key_rejected` | The server did not accept the key | User puts the public key shown on the settings page into authorized_keys |
|
|
37
38
|
| `host_key_mismatch` | Server reinstalled or replaced, or a man-in-the-middle | Ask whether the server was reinstalled. Only then may the user click 重置指纹 (Reset fingerprint) |
|
|
38
39
|
| `connect_failed` / `timeout` | Wrong IP or port, SSH not reachable, server down | Check the IP and SSH port on the settings page |
|
|
39
40
|
| `sudo_failed` | User is not root and lacks sudo, or the sudo password differs | Use root, or grant sudo |
|
package/lib/client.js
CHANGED
|
@@ -50,6 +50,8 @@ async function post(path, body = {}) {
|
|
|
50
50
|
var vpnApi = {
|
|
51
51
|
getSettings: () => post("/settings/get"),
|
|
52
52
|
saveSettings: (form) => post("/settings/save", form),
|
|
53
|
+
/** Public half of the plugin's dedicated key and the line that installs it. */
|
|
54
|
+
sshKey: () => post("/ssh-key"),
|
|
53
55
|
forgetHostKey: () => post("/host-key/forget"),
|
|
54
56
|
test: () => post("/test"),
|
|
55
57
|
status: () => post("/status"),
|
|
@@ -89,6 +91,26 @@ var zh = {
|
|
|
89
91
|
port: "SSH \u7AEF\u53E3",
|
|
90
92
|
username: "\u7528\u6237\u540D",
|
|
91
93
|
usernameHint: "\u5EFA\u8BAE\u7528 root\uFF1B\u5176\u4ED6\u7528\u6237\u9700\u8981\u6709 sudo \u6743\u9650\u3002",
|
|
94
|
+
authMethod: "\u767B\u5F55\u65B9\u5F0F",
|
|
95
|
+
authPassword: "\u5BC6\u7801",
|
|
96
|
+
authKey: "\u5BC6\u94A5\uFF08\u670D\u52A1\u5668\u53EA\u5141\u8BB8\u5BC6\u94A5\u767B\u5F55\u65F6\u9009\u8FD9\u4E2A\uFF09",
|
|
97
|
+
sudoPassword: "sudo \u5BC6\u7801\uFF08\u9009\u586B\uFF09",
|
|
98
|
+
sudoPasswordEmpty: "\u7528 root \u6216\u514D\u5BC6 sudo \u65F6\u4E0D\u7528\u586B",
|
|
99
|
+
keyIntro: "\u7528\u63D2\u4EF6\u7684\u4E13\u7528\u94A5\u5319\u767B\u5F55\u3002\u628A\u4E0B\u9762\u7684\u516C\u94A5\u653E\u5230\u670D\u52A1\u5668\u4E0A\uFF0C\u4EFB\u9009\u4E00\u79CD\u529E\u6CD5\uFF1A",
|
|
100
|
+
keyWayConsole: "A. \u670D\u52A1\u5546\u540E\u53F0\u6DFB\u52A0\uFF08\u65B0\u673A\u5668\u63A8\u8350\uFF09",
|
|
101
|
+
keyWayConsoleHint: "\u7C98\u5230\u670D\u52A1\u5546\u7684\u300CSSH \u5BC6\u94A5\u300D\u91CC\uFF0C\u91CD\u88C5\u7CFB\u7EDF\u65F6\u52FE\u9009\u5B83\u3002",
|
|
102
|
+
keyWayCommand: "B. \u5DF2\u7ECF\u80FD\u767B\u5F55\uFF08\u7F51\u9875\u63A7\u5236\u53F0\u6216\u522B\u7684\u7EC8\u7AEF\uFF09",
|
|
103
|
+
keyWayCommandHint: "\u4EE5 {user} \u8EAB\u4EFD\u767B\u5F55\u670D\u52A1\u5668\uFF0C\u7C98\u8D34\u6267\u884C\u8FD9\u4E00\u884C\u3002",
|
|
104
|
+
keyThen: "\u653E\u597D\u540E\u70B9\u300C\u4FDD\u5B58\u300D\uFF0C\u518D\u70B9\u300C\u6D4B\u8BD5\u8FDE\u63A5\u300D\u3002",
|
|
105
|
+
copyPublicKey: "\u590D\u5236\u516C\u94A5",
|
|
106
|
+
copyCommand: "\u590D\u5236\u547D\u4EE4",
|
|
107
|
+
ownKeyToggle: "\u6539\u7528\u6211\u81EA\u5DF1\u5DF2\u6709\u7684\u79C1\u94A5",
|
|
108
|
+
ownKeyBack: "\u6539\u56DE\u63D2\u4EF6\u4E13\u7528\u94A5\u5319",
|
|
109
|
+
ownKey: "\u6211\u81EA\u5DF1\u7684\u79C1\u94A5",
|
|
110
|
+
ownKeyHint: "\u7C98\u8D34 OpenSSH \u6216 PEM \u683C\u5F0F\u7684\u79C1\u94A5\uFF08\u670D\u52A1\u5668\u4E0A\u5DF2\u7ECF\u653E\u4E86\u5B83\u5BF9\u5E94\u7684\u516C\u94A5\uFF09\u3002\u53EA\u4FDD\u5B58\u5728\u672C\u673A dsh \u7684\u51ED\u636E\u5E93\u91CC\uFF0C\u4E0D\u4F1A\u663E\u793A\u56DE\u9875\u9762\u3002",
|
|
111
|
+
ownKeySaved: "\u5DF2\u4FDD\u5B58\uFF08\u7559\u7A7A\u5219\u4E0D\u4FEE\u6539\uFF09",
|
|
112
|
+
passphrase: "\u79C1\u94A5\u5BC6\u7801\u77ED\u8BED\uFF08\u9009\u586B\uFF09",
|
|
113
|
+
passphraseHint: "\u79C1\u94A5\u6CA1\u6709\u52A0\u5BC6\u5C31\u4E0D\u7528\u586B",
|
|
92
114
|
password: "\u5BC6\u7801",
|
|
93
115
|
passwordSaved: "\u5DF2\u4FDD\u5B58\uFF08\u7559\u7A7A\u5219\u4E0D\u4FEE\u6539\uFF09",
|
|
94
116
|
passwordEmpty: "\u767B\u5F55 VPS \u7684\u5BC6\u7801",
|
|
@@ -152,7 +174,8 @@ var zh = {
|
|
|
152
174
|
fwStatus: "\u670D\u52A1\u5668\u9632\u706B\u5899\uFF08{backend}\uFF09\u5DF2\u653E\u884C {count} \u4E2A\u7AEF\u53E3\uFF0C\u91CD\u542F\u540E\u81EA\u52A8\u6062\u590D\u3002",
|
|
153
175
|
cloudHint: "\u5982\u679C\u4E91\u670D\u52A1\u5546\u6709\u5B89\u5168\u7EC4\uFF08\u963F\u91CC\u4E91\u3001\u817E\u8BAF\u4E91\u3001AWS \u7B49\uFF09\uFF0C\u8FD9\u4E9B\u7AEF\u53E3\u8FD8\u9700\u5728\u5176\u63A7\u5236\u53F0\u653E\u884C\u3002",
|
|
154
176
|
"err.not_configured": "\u8BF7\u5148\u586B\u5199\u5E76\u4FDD\u5B58\u670D\u52A1\u5668\u4FE1\u606F\u3002",
|
|
155
|
-
"err.auth_failed": "SSH \u767B\u5F55\u5931\u8D25\uFF1A\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF\u3002",
|
|
177
|
+
"err.auth_failed": "SSH \u767B\u5F55\u5931\u8D25\uFF1A\u7528\u6237\u540D\u6216\u5BC6\u7801\u9519\u8BEF\u3002\u5982\u679C\u670D\u52A1\u5668\u53EA\u5141\u8BB8\u5BC6\u94A5\u767B\u5F55\uFF0C\u8BF7\u628A\u300C\u767B\u5F55\u65B9\u5F0F\u300D\u6539\u6210\u300C\u5BC6\u94A5\u300D\u3002",
|
|
178
|
+
"err.key_rejected": "SSH \u767B\u5F55\u5931\u8D25\uFF1A\u670D\u52A1\u5668\u6CA1\u6709\u63A5\u53D7\u8FD9\u628A\u94A5\u5319\u3002\u8BF7\u786E\u8BA4\u516C\u94A5\u5DF2\u653E\u5230\u8BE5\u7528\u6237\u7684 ~/.ssh/authorized_keys \u91CC\uFF0C\u7528\u6237\u540D\u586B\u5199\u6B63\u786E\u3002",
|
|
156
179
|
"err.host_key_mismatch": "\u670D\u52A1\u5668\u6307\u7EB9\u4E0E\u4E0A\u6B21\u4E0D\u540C\uFF0C\u5DF2\u62D2\u7EDD\u8FDE\u63A5\u3002\u5982\u679C\u4F60\u91CD\u88C5\u4E86\u7CFB\u7EDF\u6216\u6362\u4E86\u673A\u5668\uFF0C\u8BF7\u70B9\u300C\u91CD\u7F6E\u6307\u7EB9\u300D\u540E\u91CD\u8BD5\u3002",
|
|
157
180
|
"err.connect_failed": "\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668\uFF1A{message}",
|
|
158
181
|
"err.timeout": "\u64CD\u4F5C\u8D85\u65F6\u3002",
|
|
@@ -170,6 +193,8 @@ var zh = {
|
|
|
170
193
|
"field.port": "SSH \u7AEF\u53E3\u9700\u5728 1\u201365535 \u4E4B\u95F4\u3002",
|
|
171
194
|
"field.username": "\u7528\u6237\u540D\u683C\u5F0F\u4E0D\u6B63\u786E\u3002",
|
|
172
195
|
"field.password": "\u8BF7\u586B\u5199\u5BC6\u7801\u3002",
|
|
196
|
+
"field.auth": "\u767B\u5F55\u65B9\u5F0F\u4E0D\u6B63\u786E\u3002",
|
|
197
|
+
"field.privateKey": "\u79C1\u94A5\u65E0\u6CD5\u4F7F\u7528\uFF1A\u683C\u5F0F\u4E0D\u5BF9\uFF0C\u6216\u8005\u5BC6\u7801\u77ED\u8BED\u4E0D\u6B63\u786E\u3002",
|
|
173
198
|
"field.protocols": "\u8BF7\u81F3\u5C11\u52FE\u9009\u4E00\u4E2A\u534F\u8BAE\u3002",
|
|
174
199
|
"field.linkAddress": "\u8282\u70B9\u5730\u5740\u683C\u5F0F\u4E0D\u6B63\u786E\u3002",
|
|
175
200
|
"field.certMode": "IP \u8BC1\u4E66\u9700\u8981\u7528 IP \u5730\u5740\u4F5C\u4E3A\u8282\u70B9\u5730\u5740\uFF1A\u8BF7\u628A\u300C\u8282\u70B9\u5730\u5740\u300D\u7559\u7A7A\uFF08\u4F7F\u7528\u670D\u52A1\u5668 IP\uFF09\u6216\u586B\u5199 IP\uFF0C\u6216\u6539\u7528\u81EA\u7B7E\u8BC1\u4E66\u3002"
|
|
@@ -195,6 +220,26 @@ var en = {
|
|
|
195
220
|
port: "SSH port",
|
|
196
221
|
username: "Username",
|
|
197
222
|
usernameHint: "root is recommended; other users need sudo.",
|
|
223
|
+
authMethod: "Login method",
|
|
224
|
+
authPassword: "Password",
|
|
225
|
+
authKey: "Key (choose this if the server only allows key login)",
|
|
226
|
+
sudoPassword: "sudo password (optional)",
|
|
227
|
+
sudoPasswordEmpty: "Not needed for root or passwordless sudo",
|
|
228
|
+
keyIntro: "Log in with the plugin's dedicated key. Put the public key below on the server, either way:",
|
|
229
|
+
keyWayConsole: "A. Add it in your provider's console (recommended for new machines)",
|
|
230
|
+
keyWayConsoleHint: `Paste it into your provider's "SSH keys" and select it when reinstalling the OS.`,
|
|
231
|
+
keyWayCommand: "B. If you can already log in (web console or another terminal)",
|
|
232
|
+
keyWayCommandHint: "Log in to the server as {user} and paste and run this line.",
|
|
233
|
+
keyThen: "Then click Save, then Test connection.",
|
|
234
|
+
copyPublicKey: "Copy public key",
|
|
235
|
+
copyCommand: "Copy command",
|
|
236
|
+
ownKeyToggle: "Use my own existing private key instead",
|
|
237
|
+
ownKeyBack: "Back to the plugin's dedicated key",
|
|
238
|
+
ownKey: "My own private key",
|
|
239
|
+
ownKeyHint: "Paste an OpenSSH or PEM private key whose public key is already on the server. It is kept only in dsh's local credential store and never shown again.",
|
|
240
|
+
ownKeySaved: "Saved (leave blank to keep)",
|
|
241
|
+
passphrase: "Key passphrase (optional)",
|
|
242
|
+
passphraseHint: "Leave empty if the key is not encrypted",
|
|
198
243
|
password: "Password",
|
|
199
244
|
passwordSaved: "Saved (leave blank to keep)",
|
|
200
245
|
passwordEmpty: "Password for the VPS",
|
|
@@ -258,7 +303,8 @@ var en = {
|
|
|
258
303
|
fwStatus: "Server firewall ({backend}) has {count} ports opened; re-applied after reboots.",
|
|
259
304
|
cloudHint: "If your cloud provider has a security group (Aliyun, Tencent Cloud, AWS\u2026), also open these ports in its console.",
|
|
260
305
|
"err.not_configured": "Fill in and save the server details first.",
|
|
261
|
-
"err.auth_failed": "SSH login failed: wrong username or password.",
|
|
306
|
+
"err.auth_failed": "SSH login failed: wrong username or password. If the server only allows key login, set Login method to Key.",
|
|
307
|
+
"err.key_rejected": "SSH login failed: the server did not accept the key. Check that the public key is in that user's ~/.ssh/authorized_keys and the username is right.",
|
|
262
308
|
"err.host_key_mismatch": 'The server fingerprint changed, so the connection was refused. If you reinstalled or replaced the server, click "Reset fingerprint" and retry.',
|
|
263
309
|
"err.connect_failed": "Cannot connect to the server: {message}",
|
|
264
310
|
"err.timeout": "The operation timed out.",
|
|
@@ -276,6 +322,8 @@ var en = {
|
|
|
276
322
|
"field.port": "The SSH port must be 1\u201365535.",
|
|
277
323
|
"field.username": "The username is not valid.",
|
|
278
324
|
"field.password": "Enter the password.",
|
|
325
|
+
"field.auth": "Unknown login method.",
|
|
326
|
+
"field.privateKey": "The private key cannot be used: wrong format or wrong passphrase.",
|
|
279
327
|
"field.protocols": "Select at least one protocol.",
|
|
280
328
|
"field.linkAddress": "The node address is not valid.",
|
|
281
329
|
"field.certMode": 'An IP certificate needs an IP address as the node address: leave "Node address" empty (uses the server IP) or enter an IP, or use self-signed.'
|
|
@@ -317,6 +365,20 @@ var STYLES = `
|
|
|
317
365
|
.dshvpn-qr { background: #fff; padding: 6px; border-radius: 6px; line-height: 0; align-self: center; }
|
|
318
366
|
.dshvpn-qr svg { width: 180px; height: 180px; }
|
|
319
367
|
.dshvpn-link { display: block; max-width: 100%; max-height: 3.2em; overflow: hidden; color: var(--dsw-alias-label-secondary, #666); }
|
|
368
|
+
.dshvpn-auth { display: flex; flex-direction: column; gap: 6px; }
|
|
369
|
+
.dshvpn-auth-options { display: flex; flex-wrap: wrap; gap: 18px; }
|
|
370
|
+
.dshvpn-grid .dshvpn-auth-options label.dshvpn-radio { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; }
|
|
371
|
+
.dshvpn-auth-options .dshvpn-radio input { margin: 0; }
|
|
372
|
+
.dshvpn-keypanel { display: flex; flex-direction: column; gap: 10px; }
|
|
373
|
+
.dshvpn-keypanel p { margin: 0; }
|
|
374
|
+
.dshvpn-keycard { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 10px;
|
|
375
|
+
border: 1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3)); }
|
|
376
|
+
.dshvpn-copyable { display: flex; align-items: flex-start; gap: 8px; }
|
|
377
|
+
.dshvpn-copyable code { flex: 1; min-width: 0; font-size: 12px; word-break: break-all; white-space: pre-wrap; padding: 6px 8px; border-radius: 6px;
|
|
378
|
+
background: var(--dsw-alias-bg-layer-2, rgba(127,127,127,.12)); }
|
|
379
|
+
.dshvpn-disclosure { align-self: flex-start; border: none; background: transparent; color: inherit; padding: 0; cursor: pointer; font-size: 12.5px; opacity: .75; }
|
|
380
|
+
.dshvpn-textarea { width: 100%; box-sizing: border-box; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 8px; border-radius: 8px; resize: vertical;
|
|
381
|
+
color: inherit; background: transparent; border: 1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3)); }
|
|
320
382
|
.dshvpn-section { display: flex; flex-direction: column; gap: 16px; }
|
|
321
383
|
.dshvpn-section-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
|
|
322
384
|
.dshvpn-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
|
|
@@ -1044,6 +1106,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
1044
1106
|
var ERROR_KEYS = /* @__PURE__ */ new Set([
|
|
1045
1107
|
"not_configured",
|
|
1046
1108
|
"auth_failed",
|
|
1109
|
+
"key_rejected",
|
|
1047
1110
|
"host_key_mismatch",
|
|
1048
1111
|
"connect_failed",
|
|
1049
1112
|
"timeout",
|
|
@@ -1057,16 +1120,28 @@ var ERROR_KEYS = /* @__PURE__ */ new Set([
|
|
|
1057
1120
|
"port80_in_use",
|
|
1058
1121
|
"cert_failed"
|
|
1059
1122
|
]);
|
|
1060
|
-
var FIELD_KEYS = /* @__PURE__ */ new Set(["host", "port", "username", "password", "protocols", "linkAddress", "certMode"]);
|
|
1123
|
+
var FIELD_KEYS = /* @__PURE__ */ new Set(["host", "port", "username", "password", "auth", "privateKey", "protocols", "linkAddress", "certMode"]);
|
|
1061
1124
|
function errorText(t, f) {
|
|
1062
1125
|
if (f.error === "invalid" && f.field !== void 0 && FIELD_KEYS.has(f.field)) return t(`field.${f.field}`);
|
|
1063
1126
|
const key = ERROR_KEYS.has(f.error) ? `err.${f.error}` : "err.other";
|
|
1064
1127
|
return t(key, { message: f.message ?? f.error });
|
|
1065
1128
|
}
|
|
1066
1129
|
function formOf(s) {
|
|
1067
|
-
return {
|
|
1130
|
+
return {
|
|
1131
|
+
host: s.host,
|
|
1132
|
+
port: s.port,
|
|
1133
|
+
username: s.username,
|
|
1134
|
+
password: "",
|
|
1135
|
+
auth: s.auth,
|
|
1136
|
+
privateKey: "",
|
|
1137
|
+
passphrase: "",
|
|
1138
|
+
clearPrivateKey: false,
|
|
1139
|
+
protocols: [...s.protocols],
|
|
1140
|
+
certMode: s.certMode,
|
|
1141
|
+
linkAddress: s.linkAddress
|
|
1142
|
+
};
|
|
1068
1143
|
}
|
|
1069
|
-
var sameForm = (a, b) => a.host === b.host && a.port === b.port && a.username === b.username && a.password === b.password && a.linkAddress === b.linkAddress && a.certMode === b.certMode && a.protocols.join() === [...b.protocols].join();
|
|
1144
|
+
var sameForm = (a, b) => a.host === b.host && a.port === b.port && a.username === b.username && a.password === b.password && a.auth === b.auth && a.privateKey === b.privateKey && a.passphrase === b.passphrase && a.clearPrivateKey === b.clearPrivateKey && a.linkAddress === b.linkAddress && a.certMode === b.certMode && a.protocols.join() === [...b.protocols].join();
|
|
1070
1145
|
function Checkbox({ label, checked, disabled, onChange }) {
|
|
1071
1146
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "dshvpn-checkbox", children: [
|
|
1072
1147
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "checkbox", checked, disabled, onChange: (e) => {
|
|
@@ -1075,6 +1150,93 @@ function Checkbox({ label, checked, disabled, onChange }) {
|
|
|
1075
1150
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label })
|
|
1076
1151
|
] });
|
|
1077
1152
|
}
|
|
1153
|
+
function Copyable({ text, label, t }) {
|
|
1154
|
+
const [copied, setCopied] = (0, import_react.useState)(false);
|
|
1155
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshvpn-copyable", children: [
|
|
1156
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: text }),
|
|
1157
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { size: "sm", variant: "outline", onClick: () => {
|
|
1158
|
+
void (0, import_dsh_client_ui_primitives.writeClipboard)(text).then(() => {
|
|
1159
|
+
setCopied(true);
|
|
1160
|
+
setTimeout(() => {
|
|
1161
|
+
setCopied(false);
|
|
1162
|
+
}, 1500);
|
|
1163
|
+
});
|
|
1164
|
+
}, children: copied ? t("copied") : label })
|
|
1165
|
+
] });
|
|
1166
|
+
}
|
|
1167
|
+
function KeyPanel({ t, api, form, saved, set, setForm }) {
|
|
1168
|
+
const [key, setKey] = (0, import_react.useState)(null);
|
|
1169
|
+
const ownStored = saved.hasPrivateKey && !form.clearPrivateKey;
|
|
1170
|
+
const [own, setOwn] = (0, import_react.useState)(ownStored);
|
|
1171
|
+
(0, import_react.useEffect)(() => {
|
|
1172
|
+
let live = true;
|
|
1173
|
+
void api.sshKey().then((r) => {
|
|
1174
|
+
if (live && r.ok) setKey(r);
|
|
1175
|
+
});
|
|
1176
|
+
return () => {
|
|
1177
|
+
live = false;
|
|
1178
|
+
};
|
|
1179
|
+
}, [api]);
|
|
1180
|
+
const preparing = t("working");
|
|
1181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshvpn-keypanel dshvpn-wide", children: [
|
|
1182
|
+
!own && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
1183
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dshvpn-muted", children: t("keyIntro") }),
|
|
1184
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshvpn-keycard", children: [
|
|
1185
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: t("keyWayConsole") }),
|
|
1186
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { className: "dshvpn-muted", children: t("keyWayConsoleHint") }),
|
|
1187
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Copyable, { t, text: key?.publicKey ?? preparing, label: t("copyPublicKey") })
|
|
1188
|
+
] }),
|
|
1189
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshvpn-keycard", children: [
|
|
1190
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: t("keyWayCommand") }),
|
|
1191
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { className: "dshvpn-muted", children: t("keyWayCommandHint", { user: form.username || "root" }) }),
|
|
1192
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Copyable, { t, text: key?.command ?? preparing, label: t("copyCommand") })
|
|
1193
|
+
] }),
|
|
1194
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { className: "dshvpn-muted", children: t("keyThen") })
|
|
1195
|
+
] }),
|
|
1196
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dshvpn-disclosure", onClick: () => {
|
|
1197
|
+
if (own) {
|
|
1198
|
+
setOwn(false);
|
|
1199
|
+
setForm({ ...form, privateKey: "", passphrase: "", clearPrivateKey: saved.hasPrivateKey });
|
|
1200
|
+
} else {
|
|
1201
|
+
setOwn(true);
|
|
1202
|
+
setForm({ ...form, clearPrivateKey: false });
|
|
1203
|
+
}
|
|
1204
|
+
}, children: own ? `\u25BE ${t("ownKeyBack")}` : `\u25B8 ${t("ownKeyToggle")}` }),
|
|
1205
|
+
own && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshvpn-keycard", children: [
|
|
1206
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: t("ownKey") }),
|
|
1207
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { className: "dshvpn-muted", children: t("ownKeyHint") }),
|
|
1208
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1209
|
+
"textarea",
|
|
1210
|
+
{
|
|
1211
|
+
className: "dshvpn-textarea",
|
|
1212
|
+
rows: 5,
|
|
1213
|
+
spellCheck: false,
|
|
1214
|
+
autoComplete: "off",
|
|
1215
|
+
value: form.privateKey,
|
|
1216
|
+
placeholder: ownStored ? t("ownKeySaved") : "-----BEGIN OPENSSH PRIVATE KEY-----",
|
|
1217
|
+
onChange: (e) => {
|
|
1218
|
+
set("privateKey", e.target.value);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
),
|
|
1222
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [
|
|
1223
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("passphrase") }),
|
|
1224
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1225
|
+
import_dsh_client_ui_primitives.Input,
|
|
1226
|
+
{
|
|
1227
|
+
type: "password",
|
|
1228
|
+
value: form.passphrase,
|
|
1229
|
+
autoComplete: "new-password",
|
|
1230
|
+
placeholder: t("passphraseHint"),
|
|
1231
|
+
onChange: (e) => {
|
|
1232
|
+
set("passphrase", e.target.value);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
)
|
|
1236
|
+
] })
|
|
1237
|
+
] })
|
|
1238
|
+
] });
|
|
1239
|
+
}
|
|
1078
1240
|
function QrCard({ item, t }) {
|
|
1079
1241
|
const [copied, setCopied] = (0, import_react.useState)(false);
|
|
1080
1242
|
const info = PROTOCOLS.find((p) => p.id === item.id);
|
|
@@ -1232,20 +1394,30 @@ ${t("cloudHint")}`;
|
|
|
1232
1394
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { className: "dshvpn-muted", children: t("usernameHint") })
|
|
1233
1395
|
] }),
|
|
1234
1396
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [
|
|
1235
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("password") }),
|
|
1397
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: form.auth === "key" ? t("sudoPassword") : t("password") }),
|
|
1236
1398
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1237
1399
|
import_dsh_client_ui_primitives.Input,
|
|
1238
1400
|
{
|
|
1239
1401
|
type: "password",
|
|
1240
1402
|
value: form.password,
|
|
1241
1403
|
autoComplete: "new-password",
|
|
1242
|
-
placeholder: saved.hasPassword ? t("passwordSaved") : t("passwordEmpty"),
|
|
1404
|
+
placeholder: saved.hasPassword ? t("passwordSaved") : form.auth === "key" ? t("sudoPasswordEmpty") : t("passwordEmpty"),
|
|
1243
1405
|
onChange: (e) => {
|
|
1244
1406
|
set("password", e.target.value);
|
|
1245
1407
|
}
|
|
1246
1408
|
}
|
|
1247
1409
|
)
|
|
1248
1410
|
] }),
|
|
1411
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dshvpn-wide dshvpn-auth", children: [
|
|
1412
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("authMethod") }),
|
|
1413
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dshvpn-auth-options", children: ["password", "key"].map((m) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "dshvpn-radio", children: [
|
|
1414
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "radio", name: "dshvpn-auth", checked: form.auth === m, disabled, onChange: () => {
|
|
1415
|
+
set("auth", m);
|
|
1416
|
+
} }),
|
|
1417
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: m === "key" ? t("authKey") : t("authPassword") })
|
|
1418
|
+
] }, m)) })
|
|
1419
|
+
] }),
|
|
1420
|
+
form.auth === "key" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KeyPanel, { t, api, form, saved, set, setForm }),
|
|
1249
1421
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "dshvpn-wide", children: [
|
|
1250
1422
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("linkAddress") }),
|
|
1251
1423
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Input, { value: form.linkAddress, placeholder: form.host, onChange: (e) => {
|
package/lib/index.js
CHANGED
|
@@ -20164,6 +20164,150 @@ var require_lib2 = __commonJS({
|
|
|
20164
20164
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
20165
20165
|
import Schema from "@deepseek-ai/schemastery";
|
|
20166
20166
|
|
|
20167
|
+
// src/ssh.ts
|
|
20168
|
+
var import_ssh2 = __toESM(require_lib2(), 1);
|
|
20169
|
+
import { createHash } from "node:crypto";
|
|
20170
|
+
var SshError = class extends Error {
|
|
20171
|
+
constructor(code, message, details = {}) {
|
|
20172
|
+
super(message);
|
|
20173
|
+
this.code = code;
|
|
20174
|
+
this.details = details;
|
|
20175
|
+
this.name = "SshError";
|
|
20176
|
+
}
|
|
20177
|
+
code;
|
|
20178
|
+
details;
|
|
20179
|
+
};
|
|
20180
|
+
function privateKeyProblem(key, passphrase) {
|
|
20181
|
+
const parsed = import_ssh2.utils.parseKey(key, passphrase || void 0);
|
|
20182
|
+
const first = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
20183
|
+
if (first instanceof Error) return first.message;
|
|
20184
|
+
if (!first || !first.isPrivateKey()) return "not a private key";
|
|
20185
|
+
return void 0;
|
|
20186
|
+
}
|
|
20187
|
+
function generateKeyPair(comment) {
|
|
20188
|
+
for (let i = 0; i < 20; i++) {
|
|
20189
|
+
const k = import_ssh2.utils.generateKeyPairSync("ed25519", { comment });
|
|
20190
|
+
try {
|
|
20191
|
+
if (privateKeyProblem(k.private) === void 0) return { privateKey: k.private, publicKey: k.public.trim() };
|
|
20192
|
+
} catch {
|
|
20193
|
+
}
|
|
20194
|
+
}
|
|
20195
|
+
throw new Error("could not generate a usable SSH key");
|
|
20196
|
+
}
|
|
20197
|
+
function fingerprint(key) {
|
|
20198
|
+
return `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
|
|
20199
|
+
}
|
|
20200
|
+
var STDERR_TAIL = 8e3;
|
|
20201
|
+
var SshSession = class _SshSession {
|
|
20202
|
+
constructor(client, hostKey) {
|
|
20203
|
+
this.client = client;
|
|
20204
|
+
this.hostKey = hostKey;
|
|
20205
|
+
}
|
|
20206
|
+
client;
|
|
20207
|
+
hostKey;
|
|
20208
|
+
static async open(target, signal, timeoutMs = 2e4) {
|
|
20209
|
+
signal.throwIfAborted();
|
|
20210
|
+
const client = new import_ssh2.Client();
|
|
20211
|
+
let seen;
|
|
20212
|
+
const config = {
|
|
20213
|
+
host: target.host,
|
|
20214
|
+
port: target.port,
|
|
20215
|
+
username: target.username,
|
|
20216
|
+
// Exactly one method: the key, or the password. Never keyboard-interactive or agents.
|
|
20217
|
+
...target.privateKey ? { privateKey: target.privateKey, ...target.passphrase ? { passphrase: target.passphrase } : {} } : { password: target.password },
|
|
20218
|
+
readyTimeout: timeoutMs,
|
|
20219
|
+
tryKeyboard: false,
|
|
20220
|
+
hostVerifier: (key) => {
|
|
20221
|
+
seen = fingerprint(key);
|
|
20222
|
+
return target.hostKey === void 0 || target.hostKey === seen;
|
|
20223
|
+
}
|
|
20224
|
+
};
|
|
20225
|
+
return await new Promise((resolve, reject) => {
|
|
20226
|
+
const onAbort = () => {
|
|
20227
|
+
client.end();
|
|
20228
|
+
reject(new SshError("cancelled", "cancelled"));
|
|
20229
|
+
};
|
|
20230
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
20231
|
+
client.once("ready", () => {
|
|
20232
|
+
signal.removeEventListener("abort", onAbort);
|
|
20233
|
+
resolve(new _SshSession(client, seen ?? ""));
|
|
20234
|
+
});
|
|
20235
|
+
client.once("error", (err) => {
|
|
20236
|
+
signal.removeEventListener("abort", onAbort);
|
|
20237
|
+
client.end();
|
|
20238
|
+
if (target.hostKey !== void 0 && seen !== void 0 && seen !== target.hostKey) {
|
|
20239
|
+
reject(new SshError(
|
|
20240
|
+
"host_key_mismatch",
|
|
20241
|
+
`host key changed: expected ${target.hostKey}, got ${seen}`,
|
|
20242
|
+
{ expected: target.hostKey, actual: seen }
|
|
20243
|
+
));
|
|
20244
|
+
} else if (err.level === "client-authentication") {
|
|
20245
|
+
reject(target.privateKey ? new SshError("key_rejected", `SSH login failed: ${target.username}@${target.host} did not accept the key`) : new SshError("auth_failed", "SSH login failed: wrong username or password"));
|
|
20246
|
+
} else if (err.level === "client-timeout") {
|
|
20247
|
+
reject(new SshError("timeout", `timed out connecting to ${target.host}:${target.port}`));
|
|
20248
|
+
} else {
|
|
20249
|
+
reject(new SshError("connect_failed", `cannot connect to ${target.host}:${target.port}: ${err.message}`));
|
|
20250
|
+
}
|
|
20251
|
+
});
|
|
20252
|
+
client.connect(config);
|
|
20253
|
+
});
|
|
20254
|
+
}
|
|
20255
|
+
/** Run one command; `stdin` is written then closed. Never uses a pty. */
|
|
20256
|
+
async exec(command, stdin, signal) {
|
|
20257
|
+
signal.throwIfAborted();
|
|
20258
|
+
const stream = await new Promise((resolve, reject) => {
|
|
20259
|
+
this.client.exec(command, (err, s) => {
|
|
20260
|
+
if (err) reject(err);
|
|
20261
|
+
else resolve(s);
|
|
20262
|
+
});
|
|
20263
|
+
});
|
|
20264
|
+
let stdout = "";
|
|
20265
|
+
let stderr = "";
|
|
20266
|
+
stream.setEncoding("utf8");
|
|
20267
|
+
stream.on("data", (chunk) => {
|
|
20268
|
+
stdout += chunk;
|
|
20269
|
+
});
|
|
20270
|
+
stream.stderr.setEncoding("utf8");
|
|
20271
|
+
stream.stderr.on("data", (chunk) => {
|
|
20272
|
+
stderr = (stderr + chunk).slice(-STDERR_TAIL);
|
|
20273
|
+
});
|
|
20274
|
+
let cleanup = () => {
|
|
20275
|
+
};
|
|
20276
|
+
try {
|
|
20277
|
+
const code = await new Promise((resolve, reject) => {
|
|
20278
|
+
const onAbort = () => {
|
|
20279
|
+
reject(signal.reason ?? new SshError("cancelled", "cancelled"));
|
|
20280
|
+
stream.close();
|
|
20281
|
+
this.client.end();
|
|
20282
|
+
};
|
|
20283
|
+
const onGone = () => {
|
|
20284
|
+
reject(new SshError("connect_failed", "connection closed during command"));
|
|
20285
|
+
};
|
|
20286
|
+
cleanup = () => {
|
|
20287
|
+
signal.removeEventListener("abort", onAbort);
|
|
20288
|
+
this.client.off("close", onGone);
|
|
20289
|
+
};
|
|
20290
|
+
if (signal.aborted) {
|
|
20291
|
+
onAbort();
|
|
20292
|
+
return;
|
|
20293
|
+
}
|
|
20294
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
20295
|
+
this.client.once("close", onGone);
|
|
20296
|
+
stream.once("close", (c) => {
|
|
20297
|
+
resolve(c ?? null);
|
|
20298
|
+
});
|
|
20299
|
+
stream.end(stdin);
|
|
20300
|
+
});
|
|
20301
|
+
return { code, stdout, stderr };
|
|
20302
|
+
} finally {
|
|
20303
|
+
cleanup();
|
|
20304
|
+
}
|
|
20305
|
+
}
|
|
20306
|
+
close() {
|
|
20307
|
+
this.client.end();
|
|
20308
|
+
}
|
|
20309
|
+
};
|
|
20310
|
+
|
|
20167
20311
|
// src/protocols.ts
|
|
20168
20312
|
var PROTOCOLS = [
|
|
20169
20313
|
{ id: "reality", name: "VLESS Reality", transport: "TCP", insecureLink: false, defaultSelected: true },
|
|
@@ -20203,6 +20347,8 @@ var EMPTY_VIEW = {
|
|
|
20203
20347
|
port: 22,
|
|
20204
20348
|
username: "root",
|
|
20205
20349
|
hasPassword: false,
|
|
20350
|
+
auth: "password",
|
|
20351
|
+
hasPrivateKey: false,
|
|
20206
20352
|
protocols: [...DEFAULT_PROTOCOLS],
|
|
20207
20353
|
certMode: "self",
|
|
20208
20354
|
linkAddress: "",
|
|
@@ -20216,6 +20362,8 @@ function publicView(s) {
|
|
|
20216
20362
|
port: s.port,
|
|
20217
20363
|
username: s.username,
|
|
20218
20364
|
hasPassword: s.password !== "",
|
|
20365
|
+
auth: s.auth,
|
|
20366
|
+
hasPrivateKey: s.privateKey !== void 0,
|
|
20219
20367
|
protocols: s.protocols,
|
|
20220
20368
|
certMode: s.certMode,
|
|
20221
20369
|
linkAddress: s.linkAddress ?? "",
|
|
@@ -20229,8 +20377,23 @@ function applyInput(current, input) {
|
|
|
20229
20377
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new SettingsError("port", "port must be 1-65535");
|
|
20230
20378
|
const username = String(input.username ?? "").trim();
|
|
20231
20379
|
if (!USERNAME.test(username)) throw new SettingsError("username", `invalid username: ${username}`);
|
|
20380
|
+
const auth = input.auth ?? current?.auth ?? "password";
|
|
20381
|
+
if (auth !== "password" && auth !== "key") throw new SettingsError("auth", `unknown login method: ${auth}`);
|
|
20232
20382
|
const password = input.password ? String(input.password) : current?.password ?? "";
|
|
20233
|
-
if (password === "") throw new SettingsError("password", "password is required");
|
|
20383
|
+
if (auth === "password" && password === "") throw new SettingsError("password", "password is required");
|
|
20384
|
+
let privateKey = input.clearPrivateKey ? void 0 : current?.privateKey;
|
|
20385
|
+
let passphrase = input.clearPrivateKey ? void 0 : current?.passphrase;
|
|
20386
|
+
if (input.privateKey && String(input.privateKey).trim() !== "") {
|
|
20387
|
+
privateKey = `${String(input.privateKey).trim()}
|
|
20388
|
+
`;
|
|
20389
|
+
passphrase = input.passphrase ? String(input.passphrase) : void 0;
|
|
20390
|
+
} else if (input.passphrase && privateKey) {
|
|
20391
|
+
passphrase = String(input.passphrase);
|
|
20392
|
+
}
|
|
20393
|
+
if (privateKey !== void 0) {
|
|
20394
|
+
const problem = privateKeyProblem(privateKey, passphrase);
|
|
20395
|
+
if (problem) throw new SettingsError("privateKey", `unusable private key: ${problem}`);
|
|
20396
|
+
}
|
|
20234
20397
|
if (!Array.isArray(input.protocols)) throw new SettingsError("protocols", "protocols must be a list");
|
|
20235
20398
|
const protocols = [...new Set(input.protocols)];
|
|
20236
20399
|
if (protocols.length === 0) throw new SettingsError("protocols", "select at least one protocol");
|
|
@@ -20249,12 +20412,29 @@ function applyInput(current, input) {
|
|
|
20249
20412
|
port,
|
|
20250
20413
|
username,
|
|
20251
20414
|
password,
|
|
20415
|
+
auth,
|
|
20416
|
+
privateKey,
|
|
20417
|
+
passphrase,
|
|
20252
20418
|
protocols,
|
|
20253
20419
|
certMode,
|
|
20254
20420
|
linkAddress: linkAddress || void 0,
|
|
20255
20421
|
hostKey: sameMachine ? current.hostKey : void 0
|
|
20256
20422
|
};
|
|
20257
20423
|
}
|
|
20424
|
+
var MemoryKeyStore = class {
|
|
20425
|
+
constructor(make) {
|
|
20426
|
+
this.make = make;
|
|
20427
|
+
}
|
|
20428
|
+
make;
|
|
20429
|
+
pair;
|
|
20430
|
+
get() {
|
|
20431
|
+
return Promise.resolve(this.pair ??= this.make());
|
|
20432
|
+
}
|
|
20433
|
+
};
|
|
20434
|
+
function authorizedKeysCommand(publicKey) {
|
|
20435
|
+
const safe = publicKey.trim().replace(/'/g, "'\\''");
|
|
20436
|
+
return `mkdir -p ~/.ssh && chmod 700 ~/.ssh && { grep -qxF '${safe}' ~/.ssh/authorized_keys 2>/dev/null || echo '${safe}' >> ~/.ssh/authorized_keys; } && chmod 600 ~/.ssh/authorized_keys`;
|
|
20437
|
+
}
|
|
20258
20438
|
|
|
20259
20439
|
// src/api.ts
|
|
20260
20440
|
var API_BASE = "/api/dsh-vpn";
|
|
@@ -20291,6 +20471,11 @@ function apiHandlers(service, uiLang, onUiLang, updater) {
|
|
|
20291
20471
|
});
|
|
20292
20472
|
return { ok: true, settings: publicView(saved) };
|
|
20293
20473
|
},
|
|
20474
|
+
// The dedicated key's public half and the line that installs it; never the private key.
|
|
20475
|
+
"/ssh-key": async () => {
|
|
20476
|
+
const { publicKey } = await service.keys.get();
|
|
20477
|
+
return { ok: true, publicKey, command: authorizedKeysCommand(publicKey) };
|
|
20478
|
+
},
|
|
20294
20479
|
"/host-key/forget": async () => {
|
|
20295
20480
|
await service.store.update((cur) => cur && { ...cur, hostKey: void 0 });
|
|
20296
20481
|
return { ok: true, settings: publicView(await service.store.get()) };
|
|
@@ -20335,135 +20520,6 @@ function registerApi(ctx, service, uiLang, onUiLang, updater) {
|
|
|
20335
20520
|
|
|
20336
20521
|
// src/remote.ts
|
|
20337
20522
|
import { readFile } from "node:fs/promises";
|
|
20338
|
-
|
|
20339
|
-
// src/ssh.ts
|
|
20340
|
-
var import_ssh2 = __toESM(require_lib2(), 1);
|
|
20341
|
-
import { createHash } from "node:crypto";
|
|
20342
|
-
var SshError = class extends Error {
|
|
20343
|
-
constructor(code, message, details = {}) {
|
|
20344
|
-
super(message);
|
|
20345
|
-
this.code = code;
|
|
20346
|
-
this.details = details;
|
|
20347
|
-
this.name = "SshError";
|
|
20348
|
-
}
|
|
20349
|
-
code;
|
|
20350
|
-
details;
|
|
20351
|
-
};
|
|
20352
|
-
function fingerprint(key) {
|
|
20353
|
-
return `SHA256:${createHash("sha256").update(key).digest("base64").replace(/=+$/, "")}`;
|
|
20354
|
-
}
|
|
20355
|
-
var STDERR_TAIL = 8e3;
|
|
20356
|
-
var SshSession = class _SshSession {
|
|
20357
|
-
constructor(client, hostKey) {
|
|
20358
|
-
this.client = client;
|
|
20359
|
-
this.hostKey = hostKey;
|
|
20360
|
-
}
|
|
20361
|
-
client;
|
|
20362
|
-
hostKey;
|
|
20363
|
-
static async open(target, signal, timeoutMs = 2e4) {
|
|
20364
|
-
signal.throwIfAborted();
|
|
20365
|
-
const client = new import_ssh2.Client();
|
|
20366
|
-
let seen;
|
|
20367
|
-
const config = {
|
|
20368
|
-
host: target.host,
|
|
20369
|
-
port: target.port,
|
|
20370
|
-
username: target.username,
|
|
20371
|
-
password: target.password,
|
|
20372
|
-
readyTimeout: timeoutMs,
|
|
20373
|
-
// Password only: never fall back to keyboard-interactive prompts or agents.
|
|
20374
|
-
tryKeyboard: false,
|
|
20375
|
-
hostVerifier: (key) => {
|
|
20376
|
-
seen = fingerprint(key);
|
|
20377
|
-
return target.hostKey === void 0 || target.hostKey === seen;
|
|
20378
|
-
}
|
|
20379
|
-
};
|
|
20380
|
-
return await new Promise((resolve, reject) => {
|
|
20381
|
-
const onAbort = () => {
|
|
20382
|
-
client.end();
|
|
20383
|
-
reject(new SshError("cancelled", "cancelled"));
|
|
20384
|
-
};
|
|
20385
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
20386
|
-
client.once("ready", () => {
|
|
20387
|
-
signal.removeEventListener("abort", onAbort);
|
|
20388
|
-
resolve(new _SshSession(client, seen ?? ""));
|
|
20389
|
-
});
|
|
20390
|
-
client.once("error", (err) => {
|
|
20391
|
-
signal.removeEventListener("abort", onAbort);
|
|
20392
|
-
client.end();
|
|
20393
|
-
if (target.hostKey !== void 0 && seen !== void 0 && seen !== target.hostKey) {
|
|
20394
|
-
reject(new SshError(
|
|
20395
|
-
"host_key_mismatch",
|
|
20396
|
-
`host key changed: expected ${target.hostKey}, got ${seen}`,
|
|
20397
|
-
{ expected: target.hostKey, actual: seen }
|
|
20398
|
-
));
|
|
20399
|
-
} else if (err.level === "client-authentication") {
|
|
20400
|
-
reject(new SshError("auth_failed", "SSH login failed: wrong username or password"));
|
|
20401
|
-
} else if (err.level === "client-timeout") {
|
|
20402
|
-
reject(new SshError("timeout", `timed out connecting to ${target.host}:${target.port}`));
|
|
20403
|
-
} else {
|
|
20404
|
-
reject(new SshError("connect_failed", `cannot connect to ${target.host}:${target.port}: ${err.message}`));
|
|
20405
|
-
}
|
|
20406
|
-
});
|
|
20407
|
-
client.connect(config);
|
|
20408
|
-
});
|
|
20409
|
-
}
|
|
20410
|
-
/** Run one command; `stdin` is written then closed. Never uses a pty. */
|
|
20411
|
-
async exec(command, stdin, signal) {
|
|
20412
|
-
signal.throwIfAborted();
|
|
20413
|
-
const stream = await new Promise((resolve, reject) => {
|
|
20414
|
-
this.client.exec(command, (err, s) => {
|
|
20415
|
-
if (err) reject(err);
|
|
20416
|
-
else resolve(s);
|
|
20417
|
-
});
|
|
20418
|
-
});
|
|
20419
|
-
let stdout = "";
|
|
20420
|
-
let stderr = "";
|
|
20421
|
-
stream.setEncoding("utf8");
|
|
20422
|
-
stream.on("data", (chunk) => {
|
|
20423
|
-
stdout += chunk;
|
|
20424
|
-
});
|
|
20425
|
-
stream.stderr.setEncoding("utf8");
|
|
20426
|
-
stream.stderr.on("data", (chunk) => {
|
|
20427
|
-
stderr = (stderr + chunk).slice(-STDERR_TAIL);
|
|
20428
|
-
});
|
|
20429
|
-
let cleanup = () => {
|
|
20430
|
-
};
|
|
20431
|
-
try {
|
|
20432
|
-
const code = await new Promise((resolve, reject) => {
|
|
20433
|
-
const onAbort = () => {
|
|
20434
|
-
reject(signal.reason ?? new SshError("cancelled", "cancelled"));
|
|
20435
|
-
stream.close();
|
|
20436
|
-
this.client.end();
|
|
20437
|
-
};
|
|
20438
|
-
const onGone = () => {
|
|
20439
|
-
reject(new SshError("connect_failed", "connection closed during command"));
|
|
20440
|
-
};
|
|
20441
|
-
cleanup = () => {
|
|
20442
|
-
signal.removeEventListener("abort", onAbort);
|
|
20443
|
-
this.client.off("close", onGone);
|
|
20444
|
-
};
|
|
20445
|
-
if (signal.aborted) {
|
|
20446
|
-
onAbort();
|
|
20447
|
-
return;
|
|
20448
|
-
}
|
|
20449
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
20450
|
-
this.client.once("close", onGone);
|
|
20451
|
-
stream.once("close", (c) => {
|
|
20452
|
-
resolve(c ?? null);
|
|
20453
|
-
});
|
|
20454
|
-
stream.end(stdin);
|
|
20455
|
-
});
|
|
20456
|
-
return { code, stdout, stderr };
|
|
20457
|
-
} finally {
|
|
20458
|
-
cleanup();
|
|
20459
|
-
}
|
|
20460
|
-
}
|
|
20461
|
-
close() {
|
|
20462
|
-
this.client.end();
|
|
20463
|
-
}
|
|
20464
|
-
};
|
|
20465
|
-
|
|
20466
|
-
// src/remote.ts
|
|
20467
20523
|
var SCRIPT_URL = new URL("../scripts/vpn.sh", import.meta.url);
|
|
20468
20524
|
var RESULT_PREFIX = "DSH_VPN_RESULT=";
|
|
20469
20525
|
var LOG_TAIL = 4e3;
|
|
@@ -20527,8 +20583,11 @@ var NotConfiguredError = class extends Error {
|
|
|
20527
20583
|
this.name = "NotConfiguredError";
|
|
20528
20584
|
}
|
|
20529
20585
|
};
|
|
20530
|
-
function targetOf(s) {
|
|
20531
|
-
|
|
20586
|
+
async function targetOf(s, keys) {
|
|
20587
|
+
const base = { host: s.host, port: s.port, username: s.username, password: s.password, hostKey: s.hostKey };
|
|
20588
|
+
if (s.auth !== "key") return base;
|
|
20589
|
+
if (s.privateKey !== void 0) return { ...base, privateKey: s.privateKey, passphrase: s.passphrase };
|
|
20590
|
+
return { ...base, privateKey: (await keys.get()).privateKey };
|
|
20532
20591
|
}
|
|
20533
20592
|
function resolveProtocols(requested, fallback) {
|
|
20534
20593
|
const list = requested && requested.length > 0 ? [...new Set(requested)] : [...fallback];
|
|
@@ -20543,12 +20602,14 @@ function failure(err) {
|
|
|
20543
20602
|
return { ok: false, error: "internal", message: err instanceof Error ? err.message : String(err) };
|
|
20544
20603
|
}
|
|
20545
20604
|
var VpnService = class {
|
|
20546
|
-
constructor(store, config) {
|
|
20605
|
+
constructor(store, config, keys = new MemoryKeyStore(() => generateKeyPair("dsh-vpn"))) {
|
|
20547
20606
|
this.store = store;
|
|
20548
20607
|
this.config = config;
|
|
20608
|
+
this.keys = keys;
|
|
20549
20609
|
}
|
|
20550
20610
|
store;
|
|
20551
20611
|
config;
|
|
20612
|
+
keys;
|
|
20552
20613
|
queue = Promise.resolve();
|
|
20553
20614
|
async settings() {
|
|
20554
20615
|
const s = await this.store.get();
|
|
@@ -20569,7 +20630,7 @@ var VpnService = class {
|
|
|
20569
20630
|
return this.exclusive(async () => {
|
|
20570
20631
|
try {
|
|
20571
20632
|
const s = await this.settings();
|
|
20572
|
-
const res = await runVpnScript(action, args(s), targetOf(s), signal, this.config.timeoutMs);
|
|
20633
|
+
const res = await runVpnScript(action, args(s), await targetOf(s, this.keys), signal, this.config.timeoutMs);
|
|
20573
20634
|
await this.pin(s, res.hostKey);
|
|
20574
20635
|
if (!res.result) {
|
|
20575
20636
|
const sudo = /incorrect password|a password is required|not in the sudoers|may not run sudo/i.test(res.log);
|
|
@@ -20656,7 +20717,7 @@ var VpnService = class {
|
|
|
20656
20717
|
let session;
|
|
20657
20718
|
try {
|
|
20658
20719
|
const s = await this.settings();
|
|
20659
|
-
session = await SshSession.open(targetOf(s), signal);
|
|
20720
|
+
session = await SshSession.open(await targetOf(s, this.keys), signal);
|
|
20660
20721
|
const asRoot = s.username === "root";
|
|
20661
20722
|
const cmd = `echo "uid=$(${asRoot ? "" : `sudo -S -p '' `}id -u)"; echo "sys=$(uname -srm)"`;
|
|
20662
20723
|
const res = await session.exec(cmd, asRoot ? "" : `${s.password}
|
|
@@ -20694,6 +20755,9 @@ function parse(payload) {
|
|
|
20694
20755
|
port: p.port,
|
|
20695
20756
|
username: p.username,
|
|
20696
20757
|
password: p.password,
|
|
20758
|
+
auth: p.auth === "key" ? "key" : "password",
|
|
20759
|
+
privateKey: typeof p.privateKey === "string" ? p.privateKey : void 0,
|
|
20760
|
+
passphrase: typeof p.passphrase === "string" ? p.passphrase : void 0,
|
|
20697
20761
|
protocols: protocols.length > 0 ? protocols : ["reality", "hy2"],
|
|
20698
20762
|
certMode: p.certMode === "ip" ? "ip" : "self",
|
|
20699
20763
|
linkAddress: typeof p.linkAddress === "string" ? p.linkAddress : void 0,
|
|
@@ -20717,6 +20781,26 @@ var CredentialSettingsStore = class {
|
|
|
20717
20781
|
});
|
|
20718
20782
|
}
|
|
20719
20783
|
};
|
|
20784
|
+
var SSH_KEY = credentialKey("dsh-vpn", "ssh-key");
|
|
20785
|
+
var CredentialKeyStore = class {
|
|
20786
|
+
constructor(ctx) {
|
|
20787
|
+
this.ctx = ctx;
|
|
20788
|
+
}
|
|
20789
|
+
ctx;
|
|
20790
|
+
async get() {
|
|
20791
|
+
let pair;
|
|
20792
|
+
await this.ctx.credentials.modifyRecord(SSH_KEY, async (record) => {
|
|
20793
|
+
const p = record?.kind === "grant" ? record.payload : null;
|
|
20794
|
+
if (typeof p?.privateKey === "string" && typeof p.publicKey === "string") {
|
|
20795
|
+
pair = { privateKey: p.privateKey, publicKey: p.publicKey };
|
|
20796
|
+
return void 0;
|
|
20797
|
+
}
|
|
20798
|
+
pair = generateKeyPair("dsh-vpn");
|
|
20799
|
+
return { kind: "grant", payload: { ...pair } };
|
|
20800
|
+
});
|
|
20801
|
+
return pair;
|
|
20802
|
+
}
|
|
20803
|
+
};
|
|
20720
20804
|
var UI_LANG_KEY = credentialKey("dsh-vpn", "ui-locale");
|
|
20721
20805
|
async function readUiLang(ctx) {
|
|
20722
20806
|
const record = await ctx.credentials.readRecord(UI_LANG_KEY);
|
|
@@ -20942,7 +21026,11 @@ function toToolValue(r, uiLang) {
|
|
|
20942
21026
|
};
|
|
20943
21027
|
}
|
|
20944
21028
|
function apply(ctx, config) {
|
|
20945
|
-
const service = new VpnService(
|
|
21029
|
+
const service = new VpnService(
|
|
21030
|
+
new CredentialSettingsStore(ctx),
|
|
21031
|
+
{ timeoutMs: config.timeoutMs, acmeProvider: config.acmeProvider },
|
|
21032
|
+
new CredentialKeyStore(ctx)
|
|
21033
|
+
);
|
|
20946
21034
|
const uiLang = new UiLang();
|
|
20947
21035
|
readUiLang(ctx).then((lang) => {
|
|
20948
21036
|
if (lang && !uiLang.reported) uiLang.set(lang);
|
package/package.json
CHANGED