dsh-plugin-reverse-proxy 0.6.0 → 0.8.0
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/CHANGELOG.md +37 -0
- package/README.en.md +42 -4
- package/README.md +43 -5
- package/assets/settings-lan-access.jpg +0 -0
- package/index.js +207 -5
- package/lan-access.js +25 -1
- package/package.json +2 -2
- package/vendor/skip/client.js +154 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,43 @@
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
## 0.8.0
|
|
8
|
+
|
|
9
|
+
**更新内容**
|
|
10
|
+
- 设置页新增 **「外部访问地址」卡片**(在「公网访问」下面):一眼看出这台机器现在能怎么访问进来 —— 内网 IPv4、内网 IPv6、公网 IPv4、公网 IPv6 各一条,地址按你当前设置的端口实时拼好,端口一改这里立刻跟着变。
|
|
11
|
+
- 每条地址右边一个 **「复制」** 按钮(手机上点不动就长按地址手动复制,卡片里也写了这句提示)。
|
|
12
|
+
- 公网访问开着时,公网那两条会带上访问密钥,是能直接粘进浏览器/发给自己的完整 URL;没开时给出提示而不是空白。
|
|
13
|
+
- 拿不到公网 IPv4(运营商 NAT / CGNAT)或没有公网 IPv6 时,只在对应那行给一句说明,不会整张卡片消失。
|
|
14
|
+
- IPv6 地址只挑**可用时间最长**的那条(读 `ip -6 addr` 的 `valid_lft`),并自动跳过 `lo` / docker / veth / bridge / tun / tap / wireguard / tailscale 等虚拟网卡和容器网段,只显示这台机器真正对外的地址。
|
|
15
|
+
|
|
16
|
+
**修复内容**
|
|
17
|
+
- 「公网 IPv4」探测走 `https://api.ipify.org`,2.5 秒超时、结果缓存 10 分钟,断网时不会卡住设置页。
|
|
18
|
+
- **访问 IP / 黑名单列表滑不动**:滚动容器是 `display:flex;flex-direction:column`,子项默认 `flex-shrink:1` 会被压扁而不是溢出,于是「看着有滚动条却动不了」。改成 `display:block` + `.reproxy-lan-scroll>*{flex:0 0 auto}`,并加 `touch-action:pan-y` 与 `-webkit-overflow-scrolling:touch`,手机上也顺了。
|
|
19
|
+
|
|
20
|
+
**终端(0.8.0 一并更新)**
|
|
21
|
+
- 新增 `reproxy-lan addresses`:随时列出当前所有可访问地址(内网/公网 IPv4+IPv6,公网那两条带密钥)。
|
|
22
|
+
- `reproxy-lan public on` 简化:安全提示 → 输入 `yes` → 自动生成 12 位随机密钥 → 打开总开关与公网开关 → 直接打印访问地址。
|
|
23
|
+
- `reproxy-lan public off` 只关公网开关,密钥保留、局域网访问不受影响;本就是关的就直接说一声退出。
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 0.7.0
|
|
28
|
+
|
|
29
|
+
**更新内容**
|
|
30
|
+
- 新增 **IPv6 监听开关**(默认关闭,位置在「局域网访问」总开关下方):打开后除了 IPv4 还会多绑一条 `[::]:<端口>`,
|
|
31
|
+
走 IPv6 的同网络设备也能直接进后台。开启前先弹安全提示——很多宽带的 IPv6 没有 NAT,路由器放行、地址被扫到就可能从外面连进来。
|
|
32
|
+
- IPv6 开关同样受总开关约束:没开「局域网访问」时点不动、接口返回 400;关总开关会一并关掉 IPv6 监听。
|
|
33
|
+
公网访问开着时,IPv6 来源也要过访问密钥,跟 IPv4 规则一致。
|
|
34
|
+
- 访问密钥输入框前新增 **「随机」按钮**:点一下自动填入 12 位随机密钥(小写字母 + 数字,去掉了容易看错的 i/l/o/0/1),
|
|
35
|
+
再点「保存并开启」即可,不用自己想。
|
|
36
|
+
- 斜杠命令扩展:`/lan ipv6 on|off`(切换前回同一份安全提示)。
|
|
37
|
+
- 终端脚本扩展:`reproxy-lan ipv6 on|off`(先安全提示 → 输入 `yes` 确认;`status` 多一行 IPv6 状态)。
|
|
38
|
+
- 新增接口:`POST /reproxy-lan/ipv6`(`{enabled, confirm:true}`)。
|
|
39
|
+
|
|
40
|
+
**修复内容**
|
|
41
|
+
- IPv6 不再由 `cordis.patch.yml` 里的 `listenIpv6` 决定,改由运行时的 IPv6 开关决定,改配置不用再重启。
|
|
42
|
+
- 改 IPv6 / 公网 / 密钥只重建必要的监听,不会再出现「切一下开关整站断连一秒」。
|
|
43
|
+
|
|
7
44
|
## 0.6.0
|
|
8
45
|
|
|
9
46
|
**更新内容**
|
package/README.en.md
CHANGED
|
@@ -55,7 +55,7 @@ No GUI around? The same switch works from a terminal (`yes` is required) — see
|
|
|
55
55
|
</p>
|
|
56
56
|
---
|
|
57
57
|
|
|
58
|
-
##
|
|
58
|
+
## Seven capabilities
|
|
59
59
|
|
|
60
60
|
> Since 0.3.5: the settings switch is purple, and the **listening port** is editable
|
|
61
61
|
> (default 8080, applied on save, kept across restarts).
|
|
@@ -136,7 +136,7 @@ To open it to the internet, add a second gate — **public switch + access key**
|
|
|
136
136
|
- Settings: **Settings → LAN access → Public access**, type an access key (5–64 characters, letters and digits only;
|
|
137
137
|
pinyin is fine, symbols are not), then hit **Save and enable**. The switch will not turn on without a key.
|
|
138
138
|
- Slash command: `/lan public` (status), `/lan public on <key>`, `/lan public off`, `/lan key <key>`.
|
|
139
|
-
- Terminal: `reproxy-lan public on <key>`, `reproxy-lan public off
|
|
139
|
+
- Terminal: `reproxy-lan public on` (shows the warning, asks for `yes`, then **generates a random 12-character key**, opens the main + public switches and prints the reachable URLs), `reproxy-lan public on <key>`, `reproxy-lan public off` (closes the public switch only, key kept), `reproxy-lan key <key>`, `reproxy-lan addresses` (list every reachable URL at any time); `status` shows the masked key.
|
|
140
140
|
|
|
141
141
|
The URL becomes:
|
|
142
142
|
|
|
@@ -154,7 +154,28 @@ in the URL. A request with no key, or the wrong key, gets a **404** — it does
|
|
|
154
154
|
> ⚠️ Two things to keep in mind: (1) this plugin only *allows* traffic — reaching it from the internet still depends on
|
|
155
155
|
> your router / firewall port forwarding; (2) treat the key like a key — don't paste it into group chats, screenshots or issues.
|
|
156
156
|
|
|
157
|
-
### 4.
|
|
157
|
+
### 4. IPv6 listener (off by default)
|
|
158
|
+
|
|
159
|
+
Right below the main switch there is an **IPv6 listener** toggle. When enabled, the proxy binds an extra `[::]:<port>`:
|
|
160
|
+
|
|
161
|
+
- Devices on the same network that use **IPv6** (most phones and many ISP links prefer IPv6) can open `http://[ipv6-address]:<port>` directly.
|
|
162
|
+
- It follows the main switch: it is disabled while "LAN access" is off (the API answers 400), and turning the main switch off disables IPv6 too.
|
|
163
|
+
- It follows public access as well: when public access is on, IPv6 sources must present the access key, same as IPv4.
|
|
164
|
+
- A warning dialog appears first: **many ISP IPv6 links have no NAT**, so if your router lets traffic through and the address gets scanned, outside devices may reach you. Leave it off if unsure.
|
|
165
|
+
|
|
166
|
+
Terminal: `reproxy-lan ipv6 on` / `reproxy-lan ipv6 off`; slash command: `/lan ipv6 on|off`.
|
|
167
|
+
|
|
168
|
+
### 5. External addresses (one glance, ready to copy)
|
|
169
|
+
|
|
170
|
+
Below "Public access" there is an **External addresses** card that works out how this machine can be reached right now:
|
|
171
|
+
|
|
172
|
+
- One row each for **LAN IPv4 / LAN IPv6 / public IPv4 / public IPv6**, built with the port you actually configured (change the port and the rows follow immediately).
|
|
173
|
+
- When public access is on, the public rows include the access key, so they are complete URLs you can paste straight into a browser; when it is off you get a hint instead of a dead link.
|
|
174
|
+
- Missing public addresses are explained per row: IPv4 is usually carrier NAT / CGNAT ("forward the port on your router first"), IPv6 means "this machine only has a LAN IPv6".
|
|
175
|
+
- Only real interfaces are listed: `lo`, docker, veth, bridges, tun/tap, WireGuard, Tailscale and container subnets are skipped, and the IPv6 row picks the address with the **longest lifetime**.
|
|
176
|
+
- A **Copy** button sits on each row; if copying does nothing on a phone, long-press the address — the card says so too.
|
|
177
|
+
|
|
178
|
+
### 6. Access IPs and blacklist (off by default)
|
|
158
179
|
|
|
159
180
|
- Lists every device that recently hit the port (IP, last seen, request count).
|
|
160
181
|
- **Add** drops that IP into the blacklist; the device then gets a 403 page until you remove it.
|
|
@@ -171,7 +192,7 @@ reproxy-lan reset # shows what will be restored, then asks you to type yes
|
|
|
171
192
|
Or `/lan reset` in chat, confirmed with `/lan reset yes`. Reset turns LAN access off, port back to 8080,
|
|
172
193
|
blacklist off and clears the list — devices currently connected over 8080 drop immediately, by design.
|
|
173
194
|
|
|
174
|
-
###
|
|
195
|
+
### 7. Token-free login (version-gated)
|
|
175
196
|
|
|
176
197
|
Replaces the official `@deepseek-ai/dsh-client-connection` provider and skips BrowserAuth.
|
|
177
198
|
|
|
@@ -198,6 +219,23 @@ Replaces the official `@deepseek-ai/dsh-client-connection` provider and skips Br
|
|
|
198
219
|
|
|
199
220
|
---
|
|
200
221
|
|
|
222
|
+
## Why the marketplace marks "executes assembled code at runtime"
|
|
223
|
+
|
|
224
|
+
The marketplace detail page scans every package statically (the "What it does" block), and ours lights up `Execution → runs code assembled at runtime`. It is accurate, but the reason is mundane: the bundle contains four `eval` / `new Function` sites.
|
|
225
|
+
|
|
226
|
+
| Where | Code | Origin |
|
|
227
|
+
|---|---|---|
|
|
228
|
+
| `vendor/skip/gate.js:125` | `new Function('ctx', 'expr', 'with (ctx) { return eval(expr) }')(ctx, GATE_PROBE_EXPRESSION)` | This plugin's own compatibility probe: `disabled:` entries in `cordis.patch.yml` are expressions, and matching one at runtime requires evaluating it — same semantics as DSH's own loader |
|
|
229
|
+
| `vendor/skip/client.js:5654` | `new Function("return " + schema.callback)()` | DSH's official schemastery build, vendored as part of the official client bundle |
|
|
230
|
+
| `vendor/skip/client.js:12138` | same | same |
|
|
231
|
+
| `vendor/skip/client.js:13639` | same | same |
|
|
232
|
+
|
|
233
|
+
In other words: **the plugin never downloads or remote-loads code**. The flag is a pattern match on "string executed as function", which is why "Network access" and "Reads/writes local files" light up too (`net` / `fs` calls).
|
|
234
|
+
|
|
235
|
+
Removing the flag entirely would mean dropping the vendored official frontend — i.e. no settings panel — so we keep it and explain it here.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
201
239
|
## Scope
|
|
202
240
|
|
|
203
241
|
| Where | Supported |
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ dsh plugin --profile web add dsh-plugin-reverse-proxy # 推荐:npm 包,免
|
|
|
50
50
|
|
|
51
51
|
---
|
|
52
52
|
|
|
53
|
-
##
|
|
53
|
+
## 七个能力
|
|
54
54
|
|
|
55
55
|
> 0.3.5 起:设置页开关换成紫色,**监听端口**也能自己填了(默认 8080,保存即生效,重启保留)。
|
|
56
56
|
|
|
@@ -154,9 +154,9 @@ reproxy-lan --help
|
|
|
154
154
|
总开关只管局域网。要让公网也能进来,再开一道闸——**公网开关 + 访问密钥**:
|
|
155
155
|
|
|
156
156
|
- 设置页:**设置 → 局域网访问 → 公网访问**,填「访问密钥」(至少 5 位,只能英文字母和数字,拼音可以、符号不行),
|
|
157
|
-
|
|
157
|
+
密钥框前面有个 **「随机」** 按钮,点一下就自动填 12 位随机密钥(小写字母 + 数字);填好点「保存并开启」,没有密钥时开关点不动(后端直接 400)。**没打开「局域网访问」总开关时公网开关也点不动**——端口只绑 127.0.0.1,开了也没人能连进来。
|
|
158
158
|
- 斜杠命令:`/lan public` 看状态、`/lan public on <密钥>` 开启、`/lan public off` 关闭、`/lan key <密钥>` 只换密钥。
|
|
159
|
-
- 终端:`reproxy-lan public on`(**一键开启**:先看安全提示 →
|
|
159
|
+
- 终端:`reproxy-lan public on`(**一键开启**:先看安全提示 → 输入 `yes` → **自动生成 12 位随机密钥**,总开关和公网开关一起打开,成功后直接把可访问地址列出来)、`reproxy-lan public on <密钥>`(用自己指定的密钥)、`reproxy-lan public off`(只关公网开关,密钥保留)、`reproxy-lan key <密钥>`、`reproxy-lan addresses`(随时列出所有可访问地址);`reproxy-lan status` 里能看到公网状态与密钥掩码。
|
|
160
160
|
|
|
161
161
|
开启后访问地址变成:
|
|
162
162
|
|
|
@@ -174,7 +174,28 @@ http://<公网IP>:<端口>/<访问密钥>
|
|
|
174
174
|
> ⚠️ 两件事要记住:① 插件只负责「放行」,公网能不能进来还取决于路由器 / 防火墙有没有把端口映射出去;
|
|
175
175
|
> ② 密钥等于钥匙,别发到群里、别写进截图、别贴在公开 issue 里。
|
|
176
176
|
|
|
177
|
-
### 4.
|
|
177
|
+
### 4. IPv6 监听(默认关闭)
|
|
178
|
+
|
|
179
|
+
总开关下面还有一个 **IPv6 监听** 开关,默认关着。打开后插件除了绑 IPv4,还会多绑一条 `[::]:<端口>`:
|
|
180
|
+
|
|
181
|
+
- 同网络里**走 IPv6** 的设备(很多手机、运营商宽带默认就是 IPv6 优先)不用你折腾,直接用 `http://[IPv6地址]:<端口>` 就能进后台。
|
|
182
|
+
- 跟总开关联动:没开「局域网访问」时这个开关点不动(后端 400);关总开关会把它一起关掉。
|
|
183
|
+
- 跟公网访问联动:公网开着时,IPv6 来源同样要过访问密钥,规则和 IPv4 一样。
|
|
184
|
+
- 打开前会弹一次安全提示:**不少宽带的 IPv6 没有 NAT**,路由器放行、地址被扫到,外面的设备也可能连进来。不确定就先别开。
|
|
185
|
+
|
|
186
|
+
终端:`reproxy-lan ipv6 on` / `reproxy-lan ipv6 off`(先看提示,再输入 `yes`);斜杠命令 `/lan ipv6 on|off`。
|
|
187
|
+
|
|
188
|
+
### 5. 外部访问地址(一屏看清怎么连)
|
|
189
|
+
|
|
190
|
+
「公网访问」下面还有一张 **「外部访问地址」** 卡片,把「现在能怎么访问进来」直接算好、拼好给你:
|
|
191
|
+
|
|
192
|
+
- **内网 IPv4 / 内网 IPv6 / 公网 IPv4 / 公网 IPv6** 各一条,端口按你当前设置实时拼(改端口后立刻跟着变,不会还写着 8080)。
|
|
193
|
+
- 公网那两条在「公网访问」开着时会带上访问密钥,是能直接粘进浏览器的完整 URL;没开就只给一句提示,不会给你一条打不开的地址。
|
|
194
|
+
- 拿不到公网地址也照常显示这一行:IPv4 多半是运营商 NAT / CGNAT(写清「先在路由器做端口映射」),IPv6 则是「这台机器只有内网 IPv6」。
|
|
195
|
+
- 只有真正对外的网卡才列出来:`lo`、docker、veth、bridge、tun/tap、WireGuard、Tailscale、容器网段这些虚拟接口一律跳过;IPv6 有多条时挑**可用时间最长**的那条。
|
|
196
|
+
- 每条右边一个「复制」按钮;手机上复制没反应就长按地址手动选——卡片底部也写着这句。
|
|
197
|
+
|
|
198
|
+
### 6. 访问 IP 与黑名单(默认关闭)
|
|
178
199
|
|
|
179
200
|
设置页还有一张「访问 IP」卡片:
|
|
180
201
|
|
|
@@ -201,7 +222,7 @@ reproxy-lan reset # 先给你看会重置什么,输入 yes 才执行
|
|
|
201
222
|
> ⚠️ 不要拉黑「当前正在使用的这台设备」——后端会直接拒绝(400),回环地址 `127.0.0.1` 也不允许拉黑,
|
|
202
223
|
> 免得管理员把自己锁在外面。真要封自己,先在另一台设备上操作。
|
|
203
224
|
|
|
204
|
-
###
|
|
225
|
+
### 7. 免 Token 登录(版本门控,命中才启用)
|
|
205
226
|
|
|
206
227
|
替换官方 `@deepseek-ai/dsh-client-connection` 提供方,跳过 BrowserAuth:
|
|
207
228
|
浏览器直接打开 Web 地址就能用。
|
|
@@ -227,6 +248,23 @@ reproxy-lan reset # 先给你看会重置什么,输入 yes 才执行
|
|
|
227
248
|
|
|
228
249
|
---
|
|
229
250
|
|
|
251
|
+
## 关于商场扫描器标的「会在运行时执行拼出来的代码」
|
|
252
|
+
|
|
253
|
+
插件商场的详情页会给每个包做静态扫描(「它会做什么」那一块),我们的包被点亮了一条 `执行 → 会在运行时执行拼出来的代码`。这是真的,但来源说清楚就不吓人了——包里有四处 `eval` / `new Function`:
|
|
254
|
+
|
|
255
|
+
| 位置 | 代码 | 来源 |
|
|
256
|
+
|---|---|---|
|
|
257
|
+
| `vendor/skip/gate.js:125` | `new Function('ctx', 'expr', 'with (ctx) { return eval(expr) }')(ctx, GATE_PROBE_EXPRESSION)` | 本插件自己的兼容档位探测:`cordis.patch.yml` 里 `disabled:` 是表达式字符串,判断它该命中哪一档只能在运行时求值,语义与 DSH 自己的 loader 相同 |
|
|
258
|
+
| `vendor/skip/client.js:5654` | `new Function("return " + schema.callback)()` | DSH 官方 schemastery 的打包产物,整套 vendor 进来的官方 client bundle |
|
|
259
|
+
| `vendor/skip/client.js:12138` | 同上 | 同上 |
|
|
260
|
+
| `vendor/skip/client.js:13639` | 同上 | 同上 |
|
|
261
|
+
|
|
262
|
+
换句话说:**插件不会下载任何代码来跑**,也没有远程加载;被标亮是因为「字符串当函数跑」这种结构存在,扫描器按规则点亮。同一张卡上的「会联网」「会读写本机文件」也是同理(`net` / `fs` 调用)。
|
|
263
|
+
|
|
264
|
+
如果想彻底不出现这条,只能不 vendor 官方前端——那设置页就没了,所以这里选择保留并说明。
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
230
268
|
## 适用范围
|
|
231
269
|
|
|
232
270
|
| 场景 | 能不能用 |
|
|
Binary file
|
package/index.js
CHANGED
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
import crypto from 'node:crypto'
|
|
20
20
|
import http from 'node:http'
|
|
21
|
+
import https from 'node:https'
|
|
21
22
|
import net from 'node:net'
|
|
23
|
+
import os from 'node:os'
|
|
24
|
+
import { execFileSync } from 'node:child_process'
|
|
22
25
|
import zlib from 'node:zlib'
|
|
23
26
|
import { apply as applyTrustedConnection } from './vendor/skip/host.js'
|
|
24
27
|
import {
|
|
@@ -28,6 +31,7 @@ import {
|
|
|
28
31
|
effectiveListenHost,
|
|
29
32
|
effectivePort,
|
|
30
33
|
getLanState,
|
|
34
|
+
IPV6_WARNING_TEXT,
|
|
31
35
|
LAN_WARNING_TEXT,
|
|
32
36
|
MIN_KEY_LENGTH,
|
|
33
37
|
PUBLIC_WARNING_TEXT,
|
|
@@ -37,6 +41,7 @@ import {
|
|
|
37
41
|
onLanChange,
|
|
38
42
|
setAccessKey,
|
|
39
43
|
setBlacklistEnabled,
|
|
44
|
+
setIpv6,
|
|
40
45
|
setLanAccess,
|
|
41
46
|
setPublicAccess,
|
|
42
47
|
setPort,
|
|
@@ -132,6 +137,60 @@ function isImmutableAsset(url) {
|
|
|
132
137
|
* 两边都改同一份 lan-access 状态文件,所以永远同步;改完立刻重建监听。
|
|
133
138
|
*/
|
|
134
139
|
/** 内网/本机地址判定:总开关开着但没开公网时,只放行这些来源。 */
|
|
140
|
+
/** 虚拟网卡 / 容器的名字:这些地址对「别人怎么访问这台机器」没有意义,直接跳过。 */
|
|
141
|
+
const VIRTUAL_IFACE = /^(lo|docker|veth|br-|virbr|vmnet|vboxnet|tun|tap|wg|tailscale|zt|utun|ip6tnl|sit|dummy|cni|flannel|kube|lxc|podman|ham)/i
|
|
142
|
+
|
|
143
|
+
/** 读 `ip -6 addr` 的 valid_lft,用来挑「活得最久」的那条 IPv6。失败就返回空表。 */
|
|
144
|
+
function ipv6Lifetimes() {
|
|
145
|
+
const map = new Map()
|
|
146
|
+
try {
|
|
147
|
+
const out = execFileSync('ip', ['-6', 'addr', 'show', 'scope', 'global'], {
|
|
148
|
+
encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'],
|
|
149
|
+
})
|
|
150
|
+
let current = ''
|
|
151
|
+
for (const line of out.split('\n')) {
|
|
152
|
+
const a = line.match(/inet6\s+([0-9a-fA-F:]+)\/\d+/)
|
|
153
|
+
if (a) { current = a[1].toLowerCase(); continue }
|
|
154
|
+
const v = line.match(/valid_lft\s+(\d+)sec/)
|
|
155
|
+
if (v && current) { map.set(current, Number(v[1])); current = '' }
|
|
156
|
+
}
|
|
157
|
+
} catch { /* 没有 ip 命令就退化为主序 */ }
|
|
158
|
+
return map
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 收集「这台机器真正的」访问地址:跳过回环、虚拟网卡、链路本地。 */
|
|
162
|
+
export function collectAddresses() {
|
|
163
|
+
const lifetimes = ipv6Lifetimes()
|
|
164
|
+
const lan4 = []
|
|
165
|
+
const lan6 = []
|
|
166
|
+
const wan6 = []
|
|
167
|
+
const ifaces = os.networkInterfaces()
|
|
168
|
+
for (const [name, list] of Object.entries(ifaces)) {
|
|
169
|
+
if (!list || VIRTUAL_IFACE.test(name)) continue
|
|
170
|
+
for (const item of list) {
|
|
171
|
+
if (item.internal) continue
|
|
172
|
+
const addr = normalizeIp(item.address)
|
|
173
|
+
if (addr === '') continue
|
|
174
|
+
if (net.isIPv4(addr)) {
|
|
175
|
+
if (!isPrivateIp(addr)) continue // 只认内网 IPv4,公网 IPv4 由出口探测拿
|
|
176
|
+
lan4.push({ address: addr, iface: name, lifetime: 0 })
|
|
177
|
+
continue
|
|
178
|
+
}
|
|
179
|
+
const lower = addr.toLowerCase()
|
|
180
|
+
if (lower.startsWith('fe8') || lower.startsWith('fe9') || lower.startsWith('fea') || lower.startsWith('feb')) continue // 链路本地
|
|
181
|
+
if (lower === '::1') continue
|
|
182
|
+
const lifetime = lifetimes.get(lower) ?? 0
|
|
183
|
+
if (lower.startsWith('fc') || lower.startsWith('fd')) {
|
|
184
|
+
lan6.push({ address: addr, iface: name, lifetime })
|
|
185
|
+
} else {
|
|
186
|
+
wan6.push({ address: addr, iface: name, lifetime }) // 2000::/3 全局
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const byLife = (a, b) => b.lifetime - a.lifetime
|
|
191
|
+
return { lan4: lan4.sort(byLife), lan6: lan6.sort(byLife), wan6: wan6.sort(byLife) }
|
|
192
|
+
}
|
|
193
|
+
|
|
135
194
|
export function isPrivateIp(value) {
|
|
136
195
|
const ip = normalizeIp(value)
|
|
137
196
|
if (ip === '') return false
|
|
@@ -153,6 +212,33 @@ export function isPrivateIp(value) {
|
|
|
153
212
|
return false
|
|
154
213
|
}
|
|
155
214
|
|
|
215
|
+
/** 探测出口公网 IPv4(拿不到就返回 null)。结果缓存 10 分钟,别每次开设置页都去求一次。 */
|
|
216
|
+
let wan4Cache = { at: 0, value: null }
|
|
217
|
+
export async function probeWan4({ force = false } = {}) {
|
|
218
|
+
const now = Date.now()
|
|
219
|
+
if (!force && now - wan4Cache.at < 600000) return wan4Cache.value
|
|
220
|
+
const value = await new Promise((resolve) => {
|
|
221
|
+
let settled = false
|
|
222
|
+
const done = (v) => { if (!settled) { settled = true; resolve(v) } }
|
|
223
|
+
try {
|
|
224
|
+
const req = https.get('https://api.ipify.org?format=text', (res) => {
|
|
225
|
+
if (res.statusCode !== 200) { res.resume(); return done(null) }
|
|
226
|
+
let body = ''
|
|
227
|
+
res.setEncoding('utf8')
|
|
228
|
+
res.on('data', (chunk) => { if (body.length < 64) body += chunk })
|
|
229
|
+
res.on('end', () => {
|
|
230
|
+
const ip = normalizeIp(body.trim())
|
|
231
|
+
done(net.isIPv4(ip) ? ip : null)
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
req.setTimeout(2500, () => { req.destroy(); done(null) })
|
|
235
|
+
req.on('error', () => done(null))
|
|
236
|
+
} catch { done(null) }
|
|
237
|
+
})
|
|
238
|
+
wan4Cache = { at: now, value }
|
|
239
|
+
return value
|
|
240
|
+
}
|
|
241
|
+
|
|
156
242
|
function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
157
243
|
const sendJson = (res, status, body) => {
|
|
158
244
|
const raw = JSON.stringify(body)
|
|
@@ -389,6 +475,88 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
389
475
|
},
|
|
390
476
|
}
|
|
391
477
|
|
|
478
|
+
/** IPv6 监听开关:同样要带 confirm,且总开关必须先开。 */
|
|
479
|
+
const routeIpv6 = {
|
|
480
|
+
kind: 'exact',
|
|
481
|
+
path: '/reproxy-lan/ipv6',
|
|
482
|
+
handler: async (req, res) => {
|
|
483
|
+
if (req.method !== 'POST') {
|
|
484
|
+
sendJson(res, 405, { ok: false, error: '只支持 POST' })
|
|
485
|
+
return
|
|
486
|
+
}
|
|
487
|
+
let body
|
|
488
|
+
try {
|
|
489
|
+
body = await readBody(req)
|
|
490
|
+
} catch (e) {
|
|
491
|
+
sendJson(res, 400, { ok: false, error: e.message })
|
|
492
|
+
return
|
|
493
|
+
}
|
|
494
|
+
if (body.confirm !== true) {
|
|
495
|
+
sendJson(res, 400, { ok: false, error: '缺少用户确认(confirm:true)', warning: IPV6_WARNING_TEXT })
|
|
496
|
+
return
|
|
497
|
+
}
|
|
498
|
+
if (typeof body.enabled !== 'boolean') {
|
|
499
|
+
sendJson(res, 400, { ok: false, error: 'enabled 必须是布尔值' })
|
|
500
|
+
return
|
|
501
|
+
}
|
|
502
|
+
try {
|
|
503
|
+
const next = setIpv6(body.enabled, 'settings')
|
|
504
|
+
log(body.enabled ? 'warn' : 'info', '设置页把 IPv6 监听' + (body.enabled ? '打开' : '关掉'))
|
|
505
|
+
sendJson(res, 200, { ...describeLanState(), warning: IPV6_WARNING_TEXT })
|
|
506
|
+
} catch (e) {
|
|
507
|
+
sendJson(res, 400, { ok: false, error: e.message })
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** 列出这台机器对外的可访问地址(内网/公网、IPv4/IPv6),端口用实时值。 */
|
|
513
|
+
const routeAddresses = {
|
|
514
|
+
kind: 'exact',
|
|
515
|
+
path: '/reproxy-lan/addresses',
|
|
516
|
+
handler: async (req, res) => {
|
|
517
|
+
if (req.method !== 'GET') {
|
|
518
|
+
sendJson(res, 405, { ok: false, error: '只支持 GET' })
|
|
519
|
+
return
|
|
520
|
+
}
|
|
521
|
+
const st = getLanState()
|
|
522
|
+
const port = effectivePort()
|
|
523
|
+
const key = st.publicAccess === true && typeof st.accessKey === 'string' ? st.accessKey : ''
|
|
524
|
+
const base = (host, isV6) => 'http://' + (isV6 ? '[' + host + ']' : host) + ':' + port
|
|
525
|
+
const picked = collectAddresses()
|
|
526
|
+
const lan4 = picked.lan4[0]
|
|
527
|
+
const lan6 = picked.lan6[0]
|
|
528
|
+
const wan6 = picked.wan6[0]
|
|
529
|
+
const rows = []
|
|
530
|
+
|
|
531
|
+
rows.push(lan4
|
|
532
|
+
? { id: 'lan4', label: '内网 IPv4', url: base(lan4.address, false) + '/' }
|
|
533
|
+
: { id: 'lan4', label: '内网 IPv4', url: '', hint: '没检测到内网 IPv4(网线/Wi-Fi 断了吗?)' })
|
|
534
|
+
|
|
535
|
+
if (st.ipv6 === true) {
|
|
536
|
+
rows.push(lan6
|
|
537
|
+
? { id: 'lan6', label: '内网 IPv6', url: base(lan6.address, true) + '/', lifetime: lan6.lifetime }
|
|
538
|
+
: { id: 'lan6', label: '内网 IPv6', url: '', hint: '没检测到内网 IPv6 地址' })
|
|
539
|
+
} else {
|
|
540
|
+
rows.push({ id: 'lan6', label: '内网 IPv6', url: '', hint: 'IPv6 监听没开——打开上面的「IPv6 监听」后这里才会列出来。' })
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (st.publicAccess === true) {
|
|
544
|
+
const wan4 = await probeWan4()
|
|
545
|
+
rows.push(wan4
|
|
546
|
+
? { id: 'wan4', label: '公网 IPv4', url: base(wan4, false) + '/' + encodeURIComponent(key) }
|
|
547
|
+
: { id: 'wan4', label: '公网 IPv4', url: '', hint: '没取到公网 IPv4(多半在运营商 NAT / CGNAT 后面)。先在路由器做端口映射,或者改用 IPv6。' })
|
|
548
|
+
rows.push(wan6
|
|
549
|
+
? { id: 'wan6', label: '公网 IPv6', url: base(wan6.address, true) + '/' + encodeURIComponent(key), lifetime: wan6.lifetime }
|
|
550
|
+
: { id: 'wan6', label: '公网 IPv6', url: '', hint: '这台机器没有公网 IPv6(只有内网 IPv6)。' })
|
|
551
|
+
} else {
|
|
552
|
+
rows.push({ id: 'wan4', label: '公网 IPv4', url: '', hint: '公网访问没开。打开「公网访问」并设好密钥后,这里会出现带密钥的完整地址。' })
|
|
553
|
+
rows.push({ id: 'wan6', label: '公网 IPv6', url: '', hint: '公网访问没开。' })
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
sendJson(res, 200, { ok: true, port, ipv6: st.ipv6 === true, publicAccess: st.publicAccess === true, rows })
|
|
557
|
+
},
|
|
558
|
+
}
|
|
559
|
+
|
|
392
560
|
/** 公网开关:必须同时给合法密钥;缺密钥直接 400。 */
|
|
393
561
|
const routePublic = {
|
|
394
562
|
kind: 'exact',
|
|
@@ -416,7 +584,7 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
416
584
|
try {
|
|
417
585
|
const next = setPublicAccess(body.enabled, body.key, 'settings')
|
|
418
586
|
log(body.enabled ? 'warn' : 'info', '设置页把公网访问' + (body.enabled ? '打开' : '关掉'))
|
|
419
|
-
sendJson(res, 200, { ...
|
|
587
|
+
sendJson(res, 200, { ...describeLanState(), warning: PUBLIC_WARNING_TEXT })
|
|
420
588
|
} catch (e) {
|
|
421
589
|
sendJson(res, 400, { ok: false, error: e.message })
|
|
422
590
|
}
|
|
@@ -459,7 +627,9 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
459
627
|
ctx.effect(() => webServer.register(routeBlock))
|
|
460
628
|
ctx.effect(() => webServer.register(routeUnblock))
|
|
461
629
|
ctx.effect(() => webServer.register(routePublic))
|
|
630
|
+
ctx.effect(() => webServer.register(routeIpv6))
|
|
462
631
|
ctx.effect(() => webServer.register(routeKey))
|
|
632
|
+
ctx.effect(() => webServer.register(routeAddresses))
|
|
463
633
|
} else {
|
|
464
634
|
log('warn', 'webServer 不可用,设置页开关接口未注册')
|
|
465
635
|
}
|
|
@@ -472,23 +642,30 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
472
642
|
return
|
|
473
643
|
}
|
|
474
644
|
|
|
645
|
+
const v6LineOf = (s) => (s.ipv6 === true
|
|
646
|
+
? 'IPv6 监听:已开启([::]:' + effectivePort() + ',走 IPv6 的设备也能进)'
|
|
647
|
+
: 'IPv6 监听:已关闭(只绑 IPv4)')
|
|
648
|
+
|
|
475
649
|
const statusText = () => {
|
|
476
650
|
const s = getLanState()
|
|
477
651
|
const port = effectivePort()
|
|
478
652
|
const head = s.lanAccess
|
|
479
653
|
? '局域网访问:已开启(监听 0.0.0.0:' + port + ',同网段设备可直接进入后台)'
|
|
480
654
|
: '局域网访问:已关闭(只监听 127.0.0.1:' + port + ',只有本机能访问)'
|
|
655
|
+
const v6Line = s.ipv6
|
|
656
|
+
? 'IPv6 监听:已开启([::]:' + port + ',走 IPv6 的设备也能进)'
|
|
657
|
+
: 'IPv6 监听:已关闭(只绑 IPv4)'
|
|
481
658
|
const when = s.updatedAt ? '上次修改:' + s.updatedAt + '(' + (s.updatedBy || 'unknown') + ')' : '还没有改过,当前是默认值'
|
|
482
659
|
const pub = s.publicAccess
|
|
483
660
|
? '公网访问:已开启(访问地址 http://<公网IP>:' + port + '/' + (s.accessKey || '') + ')'
|
|
484
661
|
: '公网访问:已关闭(只有局域网内设备能访问)'
|
|
485
|
-
return [head, pub, when].join('\n')
|
|
662
|
+
return [head, v6Line, pub, when].join('\n')
|
|
486
663
|
}
|
|
487
664
|
|
|
488
665
|
ctx.effect(() => commands.register({
|
|
489
666
|
name: 'lan',
|
|
490
667
|
description: '查看或切换局域网/公网访问开关、端口与访问密钥',
|
|
491
|
-
input: { hint: 'yes | no | status | port <n> | public on <key> | public off | key <key>' },
|
|
668
|
+
input: { hint: 'yes | no | status | port <n> | ipv6 on|off | public on <key> | public off | key <key>' },
|
|
492
669
|
recordInput: true,
|
|
493
670
|
handler: ({ rawInput }) => {
|
|
494
671
|
const arg = String(rawInput || '').trim().toLowerCase()
|
|
@@ -568,6 +745,27 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
568
745
|
log('warn', '命令行更新了公网访问密钥')
|
|
569
746
|
return { kind: 'success', text: '密钥已更新。\n' + statusText() }
|
|
570
747
|
}
|
|
748
|
+
if (arg.indexOf('ipv6') === 0) {
|
|
749
|
+
const value = arg.slice(4).trim().toLowerCase()
|
|
750
|
+
const state = getLanState()
|
|
751
|
+
if (value === '') {
|
|
752
|
+
return { kind: 'success', text: v6LineOf(state) + '\n\n用法:/lan ipv6 on 开启、/lan ipv6 off 关闭' }
|
|
753
|
+
}
|
|
754
|
+
if (value !== 'on' && value !== 'off') {
|
|
755
|
+
return { kind: 'error', text: '用法:/lan ipv6 on | off' }
|
|
756
|
+
}
|
|
757
|
+
const want = value === 'on'
|
|
758
|
+
if (want === (state.ipv6 === true)) {
|
|
759
|
+
return { kind: 'success', text: '已经是' + (want ? '开启' : '关闭') + '状态了。\n' + statusText() }
|
|
760
|
+
}
|
|
761
|
+
try {
|
|
762
|
+
setIpv6(want, 'command')
|
|
763
|
+
} catch (e) {
|
|
764
|
+
return { kind: 'error', text: e.message }
|
|
765
|
+
}
|
|
766
|
+
log(want ? 'warn' : 'info', '命令行把 IPv6 监听' + (want ? '打开' : '关掉'))
|
|
767
|
+
return { kind: 'success', text: (want ? IPV6_WARNING_TEXT + '\n\n已开启 IPv6 监听,正在重建监听。' : 'IPv6 监听已关闭。') + '\n' + statusText() }
|
|
768
|
+
}
|
|
571
769
|
if (arg === 'reset') {
|
|
572
770
|
return {
|
|
573
771
|
kind: 'success',
|
|
@@ -937,16 +1135,19 @@ function applyProxy(ctx, config) {
|
|
|
937
1135
|
// 记住「当前真正在监听」的地址:公网开关/密钥变化不该触发重建监听
|
|
938
1136
|
let appliedHost = ''
|
|
939
1137
|
let appliedPort = 0
|
|
1138
|
+
let appliedV6 = null
|
|
940
1139
|
|
|
941
1140
|
const startHosts = () => {
|
|
942
1141
|
// 端口可能在运行期被改过:每次重建监听都从状态文件取一次
|
|
943
1142
|
cfg.listenPort = effectivePort()
|
|
944
1143
|
const host = cfg.listenHost = effectiveListenHost()
|
|
1144
|
+
const wantV6 = getLanState().ipv6 === true
|
|
945
1145
|
appliedHost = host
|
|
946
1146
|
appliedPort = cfg.listenPort
|
|
1147
|
+
appliedV6 = wantV6
|
|
947
1148
|
start(host)
|
|
948
1149
|
// IPv6 用 ipv6Only,否则 Linux 双栈会把 0.0.0.0 占的端口算作冲突
|
|
949
|
-
if (
|
|
1150
|
+
if (wantV6 && host === '0.0.0.0') {
|
|
950
1151
|
try { start('::') } catch (e) { log('info', 'IPv6 监听跳过: ' + (e && e.message)) }
|
|
951
1152
|
}
|
|
952
1153
|
if (getLanState().lanAccess) {
|
|
@@ -968,7 +1169,8 @@ function applyProxy(ctx, config) {
|
|
|
968
1169
|
// 公网开关、访问密钥、黑名单这些只影响请求判定,重建反而会让正在用的连接断掉
|
|
969
1170
|
const host = effectiveListenHost()
|
|
970
1171
|
const port = effectivePort()
|
|
971
|
-
|
|
1172
|
+
const v6 = getLanState().ipv6 === true
|
|
1173
|
+
if (host === appliedHost && port === appliedPort && v6 === appliedV6) return
|
|
972
1174
|
rebind()
|
|
973
1175
|
})
|
|
974
1176
|
} catch { /* 订阅失败不连坐 */ }
|
package/lan-access.js
CHANGED
|
@@ -41,6 +41,15 @@ export const PUBLIC_WARNING_LINES = [
|
|
|
41
41
|
export const PUBLIC_WARNING_TEXT = [PUBLIC_WARNING_TITLE, ...PUBLIC_WARNING_LINES].join('\n')
|
|
42
42
|
|
|
43
43
|
/** 安全提示文案:设置页弹窗与命令行共用同一份,避免两处说法不一致。 */
|
|
44
|
+
export const IPV6_WARNING_TITLE = '开启 IPv6 监听?'
|
|
45
|
+
export const IPV6_WARNING_LINES = [
|
|
46
|
+
'开启后除了 IPv4,还会多绑一条 [::]:端口 —— 同一网络里走 IPv6 的设备也能直接进入 DSH 后台。',
|
|
47
|
+
'很多宽带的 IPv6 本来就没有 NAT:只要路由器放行、地址被扫到,外面的设备也可能连进来,不像 IPv4 那样「没做端口映射就进不来」。',
|
|
48
|
+
'如果同时开了公网访问,IPv6 同样要过访问密钥;只开 IPv6 不开公网时,非内网来源仍按公网规则拦下(403)。',
|
|
49
|
+
'不确定就先别开:默认关闭,只监听本机最安全。',
|
|
50
|
+
]
|
|
51
|
+
export const IPV6_WARNING_TEXT = [IPV6_WARNING_TITLE, ...IPV6_WARNING_LINES].join('\n')
|
|
52
|
+
|
|
44
53
|
export const LAN_WARNING_TITLE = '对局域网开放访问?'
|
|
45
54
|
export const LAN_WARNING_LINES = [
|
|
46
55
|
'开启后,同一网络里的任何设备打开这台机器的 8080 端口,都能直接进入 DSH 后台,',
|
|
@@ -104,6 +113,7 @@ const DEFAULT_STATE = {
|
|
|
104
113
|
blockedIps: [],
|
|
105
114
|
publicAccess: false,
|
|
106
115
|
accessKey: '',
|
|
116
|
+
ipv6: false,
|
|
107
117
|
updatedAt: null,
|
|
108
118
|
updatedBy: null,
|
|
109
119
|
}
|
|
@@ -133,6 +143,8 @@ const readState = () => {
|
|
|
133
143
|
blockedIps: sanitizeBlocked(raw?.blockedIps),
|
|
134
144
|
publicAccess: raw?.publicAccess === true && key.ok,
|
|
135
145
|
accessKey: key.ok ? key.key : '',
|
|
146
|
+
// IPv6 只有总开关开着时才有意义:总开关关着,端口只绑 127.0.0.1
|
|
147
|
+
ipv6: raw?.ipv6 === true && raw?.lanAccess === true,
|
|
136
148
|
updatedAt: typeof raw?.updatedAt === 'string' ? raw.updatedAt : null,
|
|
137
149
|
updatedBy: typeof raw?.updatedBy === 'string' ? raw.updatedBy : null,
|
|
138
150
|
}
|
|
@@ -197,7 +209,7 @@ export const onLanChange = (listener) => {
|
|
|
197
209
|
* 关掉总开关时顺带把公网访问也关掉——端口都不朝外听了,留着公网开关只会让人误会。
|
|
198
210
|
*/
|
|
199
211
|
export const setLanAccess = (enabled, by = 'unknown') => (
|
|
200
|
-
enabled === true ? commit({ lanAccess: true }, by) : commit({ lanAccess: false, publicAccess: false }, by)
|
|
212
|
+
enabled === true ? commit({ lanAccess: true }, by) : commit({ lanAccess: false, publicAccess: false, ipv6: false }, by)
|
|
201
213
|
)
|
|
202
214
|
|
|
203
215
|
/** 改端口:校验 → 写盘 → 通知监听者(调用方负责确认端口没被占用)。 */
|
|
@@ -278,8 +290,17 @@ export const resetConfig = (by = 'unknown') => commit({
|
|
|
278
290
|
blockedIps: [],
|
|
279
291
|
publicAccess: false,
|
|
280
292
|
accessKey: '',
|
|
293
|
+
ipv6: false,
|
|
281
294
|
}, by)
|
|
282
295
|
|
|
296
|
+
export const setIpv6 = (enabled, by = 'unknown') => {
|
|
297
|
+
if (enabled === true && state.lanAccess !== true) {
|
|
298
|
+
// 总开关没开时只监听 127.0.0.1,IPv6 监听没有任何意义
|
|
299
|
+
throw new Error('请先开启「局域网访问」总开关:端口朝外监听由它管,IPv6 开关只决定要不要再绑一条 [::]。')
|
|
300
|
+
}
|
|
301
|
+
return commit({ ipv6: enabled === true }, by)
|
|
302
|
+
}
|
|
303
|
+
|
|
283
304
|
/** 盯住状态文件:命令行脚本 / 手动改 json 也能触发重建监听。 */
|
|
284
305
|
const startWatch = () => {
|
|
285
306
|
try {
|
|
@@ -293,6 +314,7 @@ const startWatch = () => {
|
|
|
293
314
|
&& next.blockedIps.join(',') === state.blockedIps.join(',')
|
|
294
315
|
&& next.publicAccess === state.publicAccess
|
|
295
316
|
&& next.accessKey === state.accessKey
|
|
317
|
+
&& next.ipv6 === state.ipv6
|
|
296
318
|
if (same) return
|
|
297
319
|
state = next
|
|
298
320
|
notify()
|
|
@@ -321,7 +343,9 @@ export const describeLanState = (port) => {
|
|
|
321
343
|
accessPath: current.publicAccess && current.accessKey !== '' ? '/' + current.accessKey : '',
|
|
322
344
|
keyHint: current.accessKey === '' ? '' : current.accessKey.slice(0, 2) + '***' + current.accessKey.slice(-1),
|
|
323
345
|
minKeyLength: MIN_KEY_LENGTH,
|
|
346
|
+
ipv6: current.ipv6,
|
|
324
347
|
warningPublic: PUBLIC_WARNING_TEXT,
|
|
348
|
+
warningIpv6: IPV6_WARNING_TEXT,
|
|
325
349
|
stateFile: STATE_FILE,
|
|
326
350
|
}
|
|
327
351
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-reverse-proxy",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH Web 局域网/公网访问插件:内置反向代理 + 免 Token 登录,手机同 Wi-Fi 直接打开后台;公网访问需开关 + 访问密钥(地址变成
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "DSH Web 局域网/公网访问插件:内置反向代理 + 免 Token 登录,手机同 Wi-Fi 直接打开后台;公网访问需开关 + 访问密钥(地址变成 /密钥,密钥可一键随机生成);可选 IPv6 监听;端口可改,带访问 IP 黑名单与一键重置;设置页直接列出这台机器当前的内网/公网访问地址(含密钥)并可一键复制。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"exports": {
|
package/vendor/skip/client.js
CHANGED
|
@@ -95,6 +95,29 @@ window.__ModuleLoader__.load({
|
|
|
95
95
|
'不需要 Token、不需要登录,等于把整台机器的控制权交给同一网段的所有人。',
|
|
96
96
|
'只在你信任当前 Wi-Fi / 局域网(比如家里、自己手机的热点)时才开启。'
|
|
97
97
|
];
|
|
98
|
+
const IPV6_WARNING_TITLE = '开启 IPv6 监听?';
|
|
99
|
+
const IPV6_WARNING_LINES = [
|
|
100
|
+
'开启后除了 IPv4,还会多绑一条 [::]:端口,同网络里走 IPv6 的设备也能直接进入 DSH 后台。',
|
|
101
|
+
'很多宽带的 IPv6 本来就没有 NAT:只要路由器放行、地址被扫到,外面的设备也可能连进来。',
|
|
102
|
+
'公网访问开着时,IPv6 同样要过访问密钥;不确定就先别开。'
|
|
103
|
+
];
|
|
104
|
+
// 按钮点一下就能得到一串随机密钥:小写字母 + 数字,12 位,远高于最少 5 位
|
|
105
|
+
const randomKey = () => {
|
|
106
|
+
const alphabet = 'abcdefghijkmnpqrstuvwxyz23456789';
|
|
107
|
+
let out = '';
|
|
108
|
+
try {
|
|
109
|
+
const buf = new Uint8Array(12);
|
|
110
|
+
(globalThis.crypto || {}).getRandomValues ? globalThis.crypto.getRandomValues(buf) : null;
|
|
111
|
+
for (let i = 0; i < buf.length; i += 1) {
|
|
112
|
+
out += buf[i] ? alphabet[buf[i] % alphabet.length] : alphabet[(Date.now() + i) % alphabet.length];
|
|
113
|
+
}
|
|
114
|
+
} catch (e) { out = ''; }
|
|
115
|
+
if (out.length !== 12) {
|
|
116
|
+
out = '';
|
|
117
|
+
for (let i = 0; i < 12; i += 1) out += alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
};
|
|
98
121
|
const STYLE = [
|
|
99
122
|
'.reproxy-lan{display:flex;flex-direction:column;gap:14px;padding:4px 0}',
|
|
100
123
|
'.reproxy-lan-row{display:flex;align-items:center;justify-content:space-between;gap:16px;border:1px solid var(--dsw-alias-border-l1,#333947);border-radius:10px;padding:14px 16px}',
|
|
@@ -110,6 +133,9 @@ window.__ModuleLoader__.load({
|
|
|
110
133
|
'.reproxy-lan-port{flex:none;display:flex;align-items:center;gap:10px}',
|
|
111
134
|
'.reproxy-lan-input{width:96px;padding:7px 10px;border-radius:8px;border:1px solid var(--dsw-alias-border-l1,#3a3f4b);background:rgba(0,0,0,.22);color:var(--dsw-alias-label-primary,#e6e8ee);font-size:13px;font-variant-numeric:tabular-nums;text-align:center}',
|
|
112
135
|
'.reproxy-lan-input:focus{outline:none;border-color:#8b5cf6}',
|
|
136
|
+
'.reproxy-lan-random{border-radius:8px;padding:7px 12px;font-size:13px;cursor:pointer;border:1px solid rgba(139,92,246,.55);background:rgba(139,92,246,.16);color:#c4b5fd;margin-right:8px;flex:none}',
|
|
137
|
+
'.reproxy-lan-random:hover{background:rgba(139,92,246,.26)}',
|
|
138
|
+
'.reproxy-lan-random[disabled]{opacity:.55;cursor:default}',
|
|
113
139
|
'.reproxy-lan-save{border-radius:8px;padding:7px 14px;font-size:13px;cursor:pointer;border:1px solid transparent;background:#8b5cf6;color:#fff}',
|
|
114
140
|
'.reproxy-lan-save:hover{background:#9b71f8}',
|
|
115
141
|
'.reproxy-lan-save[disabled]{opacity:.5;cursor:default}',
|
|
@@ -119,13 +145,19 @@ window.__ModuleLoader__.load({
|
|
|
119
145
|
'.reproxy-lan-note{margin-top:10px;padding:8px 10px;border-radius:8px;font-size:12px;line-height:1.75;color:var(--dsw-alias-label-secondary,#9aa0ad);background:rgba(255,255,255,.04);border:1px solid var(--dsw-alias-border-l1,#333947)}',
|
|
120
146
|
'.reproxy-lan-note b{color:var(--dsw-alias-label-primary,#e8ebf2);font-weight:600}',
|
|
121
147
|
'.reproxy-lan-err{font-size:12px;color:#ff6b6b}',
|
|
122
|
-
'.reproxy-lan-scroll{margin-top:10px;max-height:212px;overflow-y:auto;overflow-x:hidden;display:
|
|
148
|
+
'.reproxy-lan-scroll{margin-top:10px;max-height:212px;overflow-y:auto;overflow-x:hidden;display:block;padding:8px;border-radius:10px;border:1px solid var(--dsw-alias-border-l1,#333947);background:rgba(0,0,0,.16);overscroll-behavior:contain;-webkit-overflow-scrolling:touch;touch-action:pan-y;scrollbar-width:thin}',
|
|
149
|
+
'.reproxy-lan-scroll>*{flex:0 0 auto}',
|
|
150
|
+
'.reproxy-lan-scroll .reproxy-lan-row+.reproxy-lan-row{margin-top:6px}',
|
|
151
|
+
'.reproxy-lan-scroll.reproxy-lan-chips{display:flex;flex-direction:row;flex-wrap:wrap;gap:6px;max-height:104px}',
|
|
123
152
|
'.reproxy-lan-scroll::-webkit-scrollbar{width:8px}',
|
|
124
153
|
'.reproxy-lan-scroll::-webkit-scrollbar-thumb{background:rgba(255,255,255,.16);border-radius:999px}',
|
|
125
154
|
'.reproxy-lan-group{display:flex;flex-direction:column;gap:6px}',
|
|
126
155
|
'.reproxy-lan-grouphead{display:flex;align-items:center;gap:8px;margin:2px 0 2px}',
|
|
127
156
|
'.reproxy-lan-badge{flex:none;font-size:11px;line-height:1;padding:4px 8px;border-radius:999px;border:1px solid rgba(139,92,246,.5);color:#c4b5fd;background:rgba(139,92,246,.12)}',
|
|
128
157
|
'.reproxy-lan-badge.lan{border-color:rgba(94,224,138,.45);color:#8fe6b0;background:rgba(94,224,138,.1)}',
|
|
158
|
+
'.reproxy-lan-addr{display:flex;align-items:center;gap:10px;flex-wrap:wrap;font-size:13px;padding:4px 0}',
|
|
159
|
+
'.reproxy-lan-url{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px;color:var(--dsw-alias-label-primary,#e6e8ee);word-break:break-all}',
|
|
160
|
+
'.reproxy-lan-url.lan{color:#8fe6b0}',
|
|
129
161
|
'.reproxy-lan-empty{font-size:12px;color:var(--dsw-alias-label-secondary,#8b90a0);padding:2px 0 6px}',
|
|
130
162
|
'.reproxy-lan-ip{display:flex;align-items:center;gap:10px;font-size:13px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-primary,#e6e8ee);padding:2px 0}',
|
|
131
163
|
'.reproxy-lan-list{margin-top:10px;display:flex;flex-direction:column;gap:6px}',
|
|
@@ -177,6 +209,12 @@ window.__ModuleLoader__.load({
|
|
|
177
209
|
headers: { 'content-type': 'application/json' },
|
|
178
210
|
body: JSON.stringify({ enabled, key, confirm: true })
|
|
179
211
|
}).then((r) => r.json());
|
|
212
|
+
const writeIpv6 = (enabled) => fetch('/reproxy-lan/ipv6', {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
headers: { 'content-type': 'application/json' },
|
|
215
|
+
body: JSON.stringify({ enabled, confirm: true })
|
|
216
|
+
}).then((r) => r.json());
|
|
217
|
+
const readAddresses = () => fetch('/reproxy-lan/addresses', { headers: { accept: 'application/json' }, cache: 'no-store' }).then((r) => r.json());
|
|
180
218
|
const writeKey = (key) => fetch('/reproxy-lan/key', {
|
|
181
219
|
method: 'POST',
|
|
182
220
|
headers: { 'content-type': 'application/json' },
|
|
@@ -200,6 +238,12 @@ window.__ModuleLoader__.load({
|
|
|
200
238
|
const [pubBusy, setPubBusy] = React.useState(false);
|
|
201
239
|
const [pubMsg, setPubMsg] = React.useState('');
|
|
202
240
|
const [pubBad, setPubBad] = React.useState(false);
|
|
241
|
+
const [askV6, setAskV6] = React.useState(false);
|
|
242
|
+
const [v6Busy, setV6Busy] = React.useState(false);
|
|
243
|
+
const [v6Msg, setV6Msg] = React.useState('');
|
|
244
|
+
const [v6Bad, setV6Bad] = React.useState(false);
|
|
245
|
+
const [addresses, setAddresses] = React.useState([]);
|
|
246
|
+
const [copied, setCopied] = React.useState('');
|
|
203
247
|
React.useEffect(() => {
|
|
204
248
|
let alive = true;
|
|
205
249
|
readState().then((body) => {
|
|
@@ -209,7 +253,44 @@ window.__ModuleLoader__.load({
|
|
|
209
253
|
}).catch((e) => { if (alive) setError(String((e && e.message) || e)); });
|
|
210
254
|
return () => { alive = false; };
|
|
211
255
|
}, []);
|
|
212
|
-
//
|
|
256
|
+
// 外部访问地址:进面板先拉一次,之后每 8 秒刷(端口/开关一变就会跟着变)
|
|
257
|
+
React.useEffect(() => {
|
|
258
|
+
let alive = true;
|
|
259
|
+
const load = () => readAddresses().then((body) => {
|
|
260
|
+
if (!alive || !body || body.ok !== true) return;
|
|
261
|
+
setAddresses(Array.isArray(body.rows) ? body.rows : []);
|
|
262
|
+
}).catch(() => { /* 拉不到就保持上一份 */ });
|
|
263
|
+
load();
|
|
264
|
+
const timer = setInterval(load, 8000);
|
|
265
|
+
return () => { alive = false; clearInterval(timer); };
|
|
266
|
+
}, [state && state.port, state && state.ipv6, state && state.publicAccess]);
|
|
267
|
+
const copyRow = (row) => {
|
|
268
|
+
const text = String(row.url || '');
|
|
269
|
+
const ok = () => { setCopied(row.id); setTimeout(() => setCopied(''), 1600); };
|
|
270
|
+
const bad = () => { setCopied('fail'); setTimeout(() => setCopied(''), 2600); };
|
|
271
|
+
const manual = () => {
|
|
272
|
+
try {
|
|
273
|
+
const ta = document.createElement('textarea');
|
|
274
|
+
ta.value = text;
|
|
275
|
+
ta.setAttribute('readonly', 'readonly');
|
|
276
|
+
ta.style.position = 'fixed';
|
|
277
|
+
ta.style.top = '-1000px';
|
|
278
|
+
ta.style.opacity = '0';
|
|
279
|
+
document.body.appendChild(ta);
|
|
280
|
+
ta.select();
|
|
281
|
+
ta.setSelectionRange(0, text.length);
|
|
282
|
+
const done = document.execCommand('copy');
|
|
283
|
+
document.body.removeChild(ta);
|
|
284
|
+
if (done) ok(); else bad();
|
|
285
|
+
} catch (e) { bad(); }
|
|
286
|
+
};
|
|
287
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
288
|
+
navigator.clipboard.writeText(text).then(ok).catch(manual);
|
|
289
|
+
} else {
|
|
290
|
+
manual();
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
// 访问 IP 列表:进面板先拉一次,之后每 5 秒轻量刷新(只读,不写盘)
|
|
213
294
|
React.useEffect(() => {
|
|
214
295
|
let alive = true;
|
|
215
296
|
const load = () => readClients().then((body) => {
|
|
@@ -267,6 +348,18 @@ window.__ModuleLoader__.load({
|
|
|
267
348
|
setPubMsg(enabled ? '公网访问已开启,用下面那条地址访问' : '公网访问已关闭');
|
|
268
349
|
}).catch((e) => fail(String((e && e.message) || e))).then(() => setPubBusy(false));
|
|
269
350
|
};
|
|
351
|
+
const applyV6 = (enabled) => {
|
|
352
|
+
setV6Busy(true);
|
|
353
|
+
setV6Msg('');
|
|
354
|
+
setV6Bad(false);
|
|
355
|
+
writeIpv6(enabled).then((body) => {
|
|
356
|
+
const stateShaped = body && typeof body.ipv6 === 'boolean';
|
|
357
|
+
if (!body || (body.ok !== true && !stateShaped)) throw new Error((body && body.error) || '保存失败');
|
|
358
|
+
setState(body);
|
|
359
|
+
setAskV6(false);
|
|
360
|
+
setV6Msg(enabled ? 'IPv6 监听已开启,正在重建监听' : 'IPv6 监听已关闭');
|
|
361
|
+
}).catch((e) => { setV6Bad(true); setV6Msg(String((e && e.message) || e)); }).then(() => setV6Busy(false));
|
|
362
|
+
};
|
|
270
363
|
const applyBlock = (ip) => {
|
|
271
364
|
setIpBusy(ip);
|
|
272
365
|
setIpMsg('');
|
|
@@ -348,6 +441,24 @@ window.__ModuleLoader__.load({
|
|
|
348
441
|
}, h('i'))
|
|
349
442
|
)
|
|
350
443
|
),
|
|
444
|
+
h('div', { className: 'reproxy-lan-row' },
|
|
445
|
+
h('div', null,
|
|
446
|
+
h('div', { className: 'reproxy-lan-title' }, 'IPv6 监听(默认关闭)'),
|
|
447
|
+
h('div', { className: 'reproxy-lan-desc' }, '开启后除了 IPv4,还会多绑一条 [::]:' + port + ',走 IPv6 的设备也能进。很多宽带的 IPv6 没有 NAT,外面的设备可能直接连进来 —— 不确定就先别开。')
|
|
448
|
+
),
|
|
449
|
+
h('div', { className: 'reproxy-lan-ctl' },
|
|
450
|
+
h('span', { className: 'reproxy-lan-state' }, state !== null && state.ipv6 === true ? '已开启' : '已关闭'),
|
|
451
|
+
h('button', {
|
|
452
|
+
className: 'reproxy-lan-switch' + (state && state.ipv6 === true ? ' on' : ''),
|
|
453
|
+
type: 'button',
|
|
454
|
+
'aria-pressed': state && state.ipv6 === true ? 'true' : 'false',
|
|
455
|
+
disabled: v6Busy || state === null || !on,
|
|
456
|
+
title: !on ? '先打开上面的「局域网访问」总开关' : (state && state.ipv6 === true ? '点击关闭 IPv6 监听' : '点击开启 IPv6 监听(会先弹出安全提示)'),
|
|
457
|
+
onClick: () => setAskV6(true)
|
|
458
|
+
}, h('i'))
|
|
459
|
+
)
|
|
460
|
+
),
|
|
461
|
+
v6Msg === '' ? null : h('div', { className: v6Bad ? 'reproxy-lan-err' : 'reproxy-lan-ok' }, v6Msg),
|
|
351
462
|
h('div', { className: 'reproxy-lan-row' },
|
|
352
463
|
h('div', null,
|
|
353
464
|
h('div', { className: 'reproxy-lan-title' }, '监听端口'),
|
|
@@ -378,6 +489,13 @@ window.__ModuleLoader__.load({
|
|
|
378
489
|
h('div', { className: 'reproxy-lan-desc' }, '默认只放行局域网地址,公网 IP 会被拦下(403)。要允许公网访问,请开启这个开关并填写访问密钥——开启后访问地址会变成 http://<公网IP>:' + port + '/<访问密钥>,不知道密钥的人打开只会看到 404。'),
|
|
379
490
|
state && state.publicAccess ? h('div', { className: 'reproxy-lan-meta', style: { marginTop: '10px' } }, '当前访问地址:http://<公网IP>:' + port + (state.accessPath || '/<访问密钥>')) : null,
|
|
380
491
|
h('div', { className: 'reproxy-lan-port', style: { marginTop: '12px' } },
|
|
492
|
+
h('button', {
|
|
493
|
+
className: 'reproxy-lan-random',
|
|
494
|
+
type: 'button',
|
|
495
|
+
title: '生成一个 12 位随机访问密钥',
|
|
496
|
+
disabled: pubBusy || state === null,
|
|
497
|
+
onClick: () => { setKeyDraft(randomKey()); setPubMsg(''); setPubBad(false); }
|
|
498
|
+
}, '随机'),
|
|
381
499
|
h('input', {
|
|
382
500
|
className: 'reproxy-lan-input',
|
|
383
501
|
style: { width: '180px', textAlign: 'left' },
|
|
@@ -410,6 +528,27 @@ window.__ModuleLoader__.load({
|
|
|
410
528
|
pubMsg === '' ? null : h('div', { className: pubBad ? 'reproxy-lan-err' : 'reproxy-lan-ok', style: { marginTop: '8px' } }, pubMsg)
|
|
411
529
|
)
|
|
412
530
|
),
|
|
531
|
+
h('div', { className: 'reproxy-lan-row' },
|
|
532
|
+
h('div', { style: { width: '100%', minWidth: 0 } },
|
|
533
|
+
h('div', { className: 'reproxy-lan-title' }, '外部访问地址'),
|
|
534
|
+
h('div', { className: 'reproxy-lan-desc' }, '这台机器现在能怎么访问进来:内网/公网、IPv4/IPv6 各一条,端口按你设的实时值拼,开关一改就跟着变。点「复制」拿走整条地址。'),
|
|
535
|
+
h('div', { className: 'reproxy-lan-list', style: { marginTop: '10px' } },
|
|
536
|
+
addresses.length === 0
|
|
537
|
+
? h('div', { className: 'reproxy-lan-meta' }, '正在读取地址…')
|
|
538
|
+
: addresses.map((row) => h('div', { className: 'reproxy-lan-addr', key: row.id },
|
|
539
|
+
h('span', { className: 'reproxy-lan-badge' + (String(row.id).indexOf('lan') === 0 ? ' lan' : '') }, row.label),
|
|
540
|
+
row.url
|
|
541
|
+
? h('code', { className: 'reproxy-lan-url' + (String(row.id).indexOf('lan') === 0 ? ' lan' : '') }, row.url)
|
|
542
|
+
: h('span', { className: 'reproxy-lan-empty', style: { flex: '1 1 100%' } }, row.hint || '没有可用地址'),
|
|
543
|
+
row.url
|
|
544
|
+
? h('button', { className: 'reproxy-lan-add', type: 'button', onClick: () => copyRow(row) }, copied === row.id ? '已复制' : '复制')
|
|
545
|
+
: null
|
|
546
|
+
))
|
|
547
|
+
),
|
|
548
|
+
h('div', { className: 'reproxy-lan-meta', style: { marginTop: '8px' } }, '如果点「复制」没反应,请长按上面的地址手动复制。'),
|
|
549
|
+
copied === 'fail' ? h('div', { className: 'reproxy-lan-err', style: { marginTop: '6px' } }, '浏览器不让复制,请长按地址手动复制。') : null
|
|
550
|
+
)
|
|
551
|
+
),
|
|
413
552
|
h('div', { className: 'reproxy-lan-row' },
|
|
414
553
|
h('div', { style: { width: '100%', minWidth: 0 } },
|
|
415
554
|
h('div', { className: 'reproxy-lan-title' }, '访问 IP'),
|
|
@@ -449,6 +588,19 @@ window.__ModuleLoader__.load({
|
|
|
449
588
|
'手机和电脑各开一个、或其中一个用无痕窗口,都不受影响。'
|
|
450
589
|
),
|
|
451
590
|
error ? h('div', { className: 'reproxy-lan-err' }, error) : null,
|
|
591
|
+
askV6 ? h('div', { className: 'reproxy-lan-mask' },
|
|
592
|
+
h('div', { className: 'reproxy-lan-card' },
|
|
593
|
+
h('h3', null, IPV6_WARNING_TITLE),
|
|
594
|
+
h('p', null, IPV6_WARNING_LINES[0]),
|
|
595
|
+
h('p', null, IPV6_WARNING_LINES[1]),
|
|
596
|
+
h('p', null, IPV6_WARNING_LINES[2]),
|
|
597
|
+
h('p', null, h('strong', null, state && state.ipv6 === true ? '这次点击会关闭 IPv6 监听。' : '这次点击会额外绑定 [::],确定要继续吗?')),
|
|
598
|
+
h('div', { className: 'reproxy-lan-actions' },
|
|
599
|
+
h('button', { className: 'reproxy-lan-btn', type: 'button', disabled: v6Busy, onClick: () => setAskV6(false) }, '取消'),
|
|
600
|
+
h('button', { className: 'reproxy-lan-btn primary', type: 'button', disabled: v6Busy, onClick: () => applyV6(!(state && state.ipv6 === true)) }, v6Busy ? '处理中…' : '确定')
|
|
601
|
+
)
|
|
602
|
+
)
|
|
603
|
+
) : null,
|
|
452
604
|
asking ? h('div', { className: 'reproxy-lan-mask' },
|
|
453
605
|
h('div', { className: 'reproxy-lan-card' },
|
|
454
606
|
h('h3', null, LAN_WARNING_TITLE),
|