dsh-plugin-reverse-proxy 0.7.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 +20 -0
- package/README.en.md +31 -4
- package/README.md +31 -4
- package/index.js +133 -0
- package/package.json +2 -2
- package/vendor/skip/client.js +69 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@
|
|
|
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
|
+
|
|
7
27
|
## 0.7.0
|
|
8
28
|
|
|
9
29
|
**更新内容**
|
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
|
|
|
@@ -165,7 +165,17 @@ Right below the main switch there is an **IPv6 listener** toggle. When enabled,
|
|
|
165
165
|
|
|
166
166
|
Terminal: `reproxy-lan ipv6 on` / `reproxy-lan ipv6 off`; slash command: `/lan ipv6 on|off`.
|
|
167
167
|
|
|
168
|
-
### 5.
|
|
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)
|
|
169
179
|
|
|
170
180
|
- Lists every device that recently hit the port (IP, last seen, request count).
|
|
171
181
|
- **Add** drops that IP into the blacklist; the device then gets a 403 page until you remove it.
|
|
@@ -182,7 +192,7 @@ reproxy-lan reset # shows what will be restored, then asks you to type yes
|
|
|
182
192
|
Or `/lan reset` in chat, confirmed with `/lan reset yes`. Reset turns LAN access off, port back to 8080,
|
|
183
193
|
blacklist off and clears the list — devices currently connected over 8080 drop immediately, by design.
|
|
184
194
|
|
|
185
|
-
###
|
|
195
|
+
### 7. Token-free login (version-gated)
|
|
186
196
|
|
|
187
197
|
Replaces the official `@deepseek-ai/dsh-client-connection` provider and skips BrowserAuth.
|
|
188
198
|
|
|
@@ -209,6 +219,23 @@ Replaces the official `@deepseek-ai/dsh-client-connection` provider and skips Br
|
|
|
209
219
|
|
|
210
220
|
---
|
|
211
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
|
+
|
|
212
239
|
## Scope
|
|
213
240
|
|
|
214
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
|
|
|
@@ -156,7 +156,7 @@ reproxy-lan --help
|
|
|
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
|
|
|
@@ -185,7 +185,17 @@ http://<公网IP>:<端口>/<访问密钥>
|
|
|
185
185
|
|
|
186
186
|
终端:`reproxy-lan ipv6 on` / `reproxy-lan ipv6 off`(先看提示,再输入 `yes`);斜杠命令 `/lan ipv6 on|off`。
|
|
187
187
|
|
|
188
|
-
### 5.
|
|
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 与黑名单(默认关闭)
|
|
189
199
|
|
|
190
200
|
设置页还有一张「访问 IP」卡片:
|
|
191
201
|
|
|
@@ -212,7 +222,7 @@ reproxy-lan reset # 先给你看会重置什么,输入 yes 才执行
|
|
|
212
222
|
> ⚠️ 不要拉黑「当前正在使用的这台设备」——后端会直接拒绝(400),回环地址 `127.0.0.1` 也不允许拉黑,
|
|
213
223
|
> 免得管理员把自己锁在外面。真要封自己,先在另一台设备上操作。
|
|
214
224
|
|
|
215
|
-
###
|
|
225
|
+
### 7. 免 Token 登录(版本门控,命中才启用)
|
|
216
226
|
|
|
217
227
|
替换官方 `@deepseek-ai/dsh-client-connection` 提供方,跳过 BrowserAuth:
|
|
218
228
|
浏览器直接打开 Web 地址就能用。
|
|
@@ -238,6 +248,23 @@ reproxy-lan reset # 先给你看会重置什么,输入 yes 才执行
|
|
|
238
248
|
|
|
239
249
|
---
|
|
240
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
|
+
|
|
241
268
|
## 适用范围
|
|
242
269
|
|
|
243
270
|
| 场景 | 能不能用 |
|
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 {
|
|
@@ -134,6 +137,60 @@ function isImmutableAsset(url) {
|
|
|
134
137
|
* 两边都改同一份 lan-access 状态文件,所以永远同步;改完立刻重建监听。
|
|
135
138
|
*/
|
|
136
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
|
+
|
|
137
194
|
export function isPrivateIp(value) {
|
|
138
195
|
const ip = normalizeIp(value)
|
|
139
196
|
if (ip === '') return false
|
|
@@ -155,6 +212,33 @@ export function isPrivateIp(value) {
|
|
|
155
212
|
return false
|
|
156
213
|
}
|
|
157
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
|
+
|
|
158
242
|
function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
159
243
|
const sendJson = (res, status, body) => {
|
|
160
244
|
const raw = JSON.stringify(body)
|
|
@@ -425,6 +509,54 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
425
509
|
},
|
|
426
510
|
}
|
|
427
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
|
+
|
|
428
560
|
/** 公网开关:必须同时给合法密钥;缺密钥直接 400。 */
|
|
429
561
|
const routePublic = {
|
|
430
562
|
kind: 'exact',
|
|
@@ -497,6 +629,7 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
|
|
|
497
629
|
ctx.effect(() => webServer.register(routePublic))
|
|
498
630
|
ctx.effect(() => webServer.register(routeIpv6))
|
|
499
631
|
ctx.effect(() => webServer.register(routeKey))
|
|
632
|
+
ctx.effect(() => webServer.register(routeAddresses))
|
|
500
633
|
} else {
|
|
501
634
|
log('warn', 'webServer 不可用,设置页开关接口未注册')
|
|
502
635
|
}
|
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 直接打开后台;公网访问需开关 + 访问密钥(地址变成 /密钥,密钥可一键随机生成);可选 IPv6 监听;端口可改,带访问 IP
|
|
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
|
@@ -145,13 +145,19 @@ window.__ModuleLoader__.load({
|
|
|
145
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)}',
|
|
146
146
|
'.reproxy-lan-note b{color:var(--dsw-alias-label-primary,#e8ebf2);font-weight:600}',
|
|
147
147
|
'.reproxy-lan-err{font-size:12px;color:#ff6b6b}',
|
|
148
|
-
'.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}',
|
|
149
152
|
'.reproxy-lan-scroll::-webkit-scrollbar{width:8px}',
|
|
150
153
|
'.reproxy-lan-scroll::-webkit-scrollbar-thumb{background:rgba(255,255,255,.16);border-radius:999px}',
|
|
151
154
|
'.reproxy-lan-group{display:flex;flex-direction:column;gap:6px}',
|
|
152
155
|
'.reproxy-lan-grouphead{display:flex;align-items:center;gap:8px;margin:2px 0 2px}',
|
|
153
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)}',
|
|
154
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}',
|
|
155
161
|
'.reproxy-lan-empty{font-size:12px;color:var(--dsw-alias-label-secondary,#8b90a0);padding:2px 0 6px}',
|
|
156
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}',
|
|
157
163
|
'.reproxy-lan-list{margin-top:10px;display:flex;flex-direction:column;gap:6px}',
|
|
@@ -208,6 +214,7 @@ window.__ModuleLoader__.load({
|
|
|
208
214
|
headers: { 'content-type': 'application/json' },
|
|
209
215
|
body: JSON.stringify({ enabled, confirm: true })
|
|
210
216
|
}).then((r) => r.json());
|
|
217
|
+
const readAddresses = () => fetch('/reproxy-lan/addresses', { headers: { accept: 'application/json' }, cache: 'no-store' }).then((r) => r.json());
|
|
211
218
|
const writeKey = (key) => fetch('/reproxy-lan/key', {
|
|
212
219
|
method: 'POST',
|
|
213
220
|
headers: { 'content-type': 'application/json' },
|
|
@@ -235,6 +242,8 @@ window.__ModuleLoader__.load({
|
|
|
235
242
|
const [v6Busy, setV6Busy] = React.useState(false);
|
|
236
243
|
const [v6Msg, setV6Msg] = React.useState('');
|
|
237
244
|
const [v6Bad, setV6Bad] = React.useState(false);
|
|
245
|
+
const [addresses, setAddresses] = React.useState([]);
|
|
246
|
+
const [copied, setCopied] = React.useState('');
|
|
238
247
|
React.useEffect(() => {
|
|
239
248
|
let alive = true;
|
|
240
249
|
readState().then((body) => {
|
|
@@ -244,7 +253,44 @@ window.__ModuleLoader__.load({
|
|
|
244
253
|
}).catch((e) => { if (alive) setError(String((e && e.message) || e)); });
|
|
245
254
|
return () => { alive = false; };
|
|
246
255
|
}, []);
|
|
247
|
-
//
|
|
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 秒轻量刷新(只读,不写盘)
|
|
248
294
|
React.useEffect(() => {
|
|
249
295
|
let alive = true;
|
|
250
296
|
const load = () => readClients().then((body) => {
|
|
@@ -482,6 +528,27 @@ window.__ModuleLoader__.load({
|
|
|
482
528
|
pubMsg === '' ? null : h('div', { className: pubBad ? 'reproxy-lan-err' : 'reproxy-lan-ok', style: { marginTop: '8px' } }, pubMsg)
|
|
483
529
|
)
|
|
484
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
|
+
),
|
|
485
552
|
h('div', { className: 'reproxy-lan-row' },
|
|
486
553
|
h('div', { style: { width: '100%', minWidth: 0 } },
|
|
487
554
|
h('div', { className: 'reproxy-lan-title' }, '访问 IP'),
|