dsh-plugin-reverse-proxy 0.6.0 → 0.7.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 CHANGED
@@ -4,6 +4,23 @@
4
4
 
5
5
  ---
6
6
 
7
+ ## 0.7.0
8
+
9
+ **更新内容**
10
+ - 新增 **IPv6 监听开关**(默认关闭,位置在「局域网访问」总开关下方):打开后除了 IPv4 还会多绑一条 `[::]:<端口>`,
11
+ 走 IPv6 的同网络设备也能直接进后台。开启前先弹安全提示——很多宽带的 IPv6 没有 NAT,路由器放行、地址被扫到就可能从外面连进来。
12
+ - IPv6 开关同样受总开关约束:没开「局域网访问」时点不动、接口返回 400;关总开关会一并关掉 IPv6 监听。
13
+ 公网访问开着时,IPv6 来源也要过访问密钥,跟 IPv4 规则一致。
14
+ - 访问密钥输入框前新增 **「随机」按钮**:点一下自动填入 12 位随机密钥(小写字母 + 数字,去掉了容易看错的 i/l/o/0/1),
15
+ 再点「保存并开启」即可,不用自己想。
16
+ - 斜杠命令扩展:`/lan ipv6 on|off`(切换前回同一份安全提示)。
17
+ - 终端脚本扩展:`reproxy-lan ipv6 on|off`(先安全提示 → 输入 `yes` 确认;`status` 多一行 IPv6 状态)。
18
+ - 新增接口:`POST /reproxy-lan/ipv6`(`{enabled, confirm:true}`)。
19
+
20
+ **修复内容**
21
+ - IPv6 不再由 `cordis.patch.yml` 里的 `listenIpv6` 决定,改由运行时的 IPv6 开关决定,改配置不用再重启。
22
+ - 改 IPv6 / 公网 / 密钥只重建必要的监听,不会再出现「切一下开关整站断连一秒」。
23
+
7
24
  ## 0.6.0
8
25
 
9
26
  **更新内容**
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
- ## Five capabilities
58
+ ## Six 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).
@@ -154,7 +154,18 @@ 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. Access IPs and blacklist (off by default)
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. Access IPs and blacklist (off by default)
158
169
 
159
170
  - Lists every device that recently hit the port (IP, last seen, request count).
160
171
  - **Add** drops that IP into the blacklist; the device then gets a 403 page until you remove it.
@@ -171,7 +182,7 @@ reproxy-lan reset # shows what will be restored, then asks you to type yes
171
182
  Or `/lan reset` in chat, confirmed with `/lan reset yes`. Reset turns LAN access off, port back to 8080,
172
183
  blacklist off and clears the list — devices currently connected over 8080 drop immediately, by design.
173
184
 
174
- ### 5. Token-free login (version-gated)
185
+ ### 6. Token-free login (version-gated)
175
186
 
176
187
  Replaces the official `@deepseek-ai/dsh-client-connection` provider and skips BrowserAuth.
177
188
 
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,7 +154,7 @@ reproxy-lan --help
154
154
  总开关只管局域网。要让公网也能进来,再开一道闸——**公网开关 + 访问密钥**:
155
155
 
156
156
  - 设置页:**设置 → 局域网访问 → 公网访问**,填「访问密钥」(至少 5 位,只能英文字母和数字,拼音可以、符号不行),
157
- 点「保存并开启」;没有密钥时开关点不动(后端直接 400)。**没打开「局域网访问」总开关时公网开关也点不动**——端口只绑 127.0.0.1,开了也没人能连进来。
157
+ 密钥框前面有个 **「随机」** 按钮,点一下就自动填 12 位随机密钥(小写字母 + 数字);填好点「保存并开启」,没有密钥时开关点不动(后端直接 400)。**没打开「局域网访问」总开关时公网开关也点不动**——端口只绑 127.0.0.1,开了也没人能连进来。
158
158
  - 斜杠命令:`/lan public` 看状态、`/lan public on <密钥>` 开启、`/lan public off` 关闭、`/lan key <密钥>` 只换密钥。
159
159
  - 终端:`reproxy-lan public on`(**一键开启**:先看安全提示 → 输入访问密钥 → 输入 `yes` 确认,**总开关和公网开关会一起打开**)、`reproxy-lan public on <密钥>`(密钥直接写在命令里)、`reproxy-lan public off`、`reproxy-lan key <密钥>`;`reproxy-lan status` 里能看到公网状态与密钥掩码。
160
160
 
@@ -174,7 +174,18 @@ http://<公网IP>:<端口>/<访问密钥>
174
174
  > ⚠️ 两件事要记住:① 插件只负责「放行」,公网能不能进来还取决于路由器 / 防火墙有没有把端口映射出去;
175
175
  > ② 密钥等于钥匙,别发到群里、别写进截图、别贴在公开 issue 里。
176
176
 
177
- ### 4. 访问 IP 与黑名单(默认关闭)
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. 访问 IP 与黑名单(默认关闭)
178
189
 
179
190
  设置页还有一张「访问 IP」卡片:
180
191
 
@@ -201,7 +212,7 @@ reproxy-lan reset # 先给你看会重置什么,输入 yes 才执行
201
212
  > ⚠️ 不要拉黑「当前正在使用的这台设备」——后端会直接拒绝(400),回环地址 `127.0.0.1` 也不允许拉黑,
202
213
  > 免得管理员把自己锁在外面。真要封自己,先在另一台设备上操作。
203
214
 
204
- ### 5. 免 Token 登录(版本门控,命中才启用)
215
+ ### 6. 免 Token 登录(版本门控,命中才启用)
205
216
 
206
217
  替换官方 `@deepseek-ai/dsh-client-connection` 提供方,跳过 BrowserAuth:
207
218
  浏览器直接打开 Web 地址就能用。
Binary file
package/index.js CHANGED
@@ -28,6 +28,7 @@ import {
28
28
  effectiveListenHost,
29
29
  effectivePort,
30
30
  getLanState,
31
+ IPV6_WARNING_TEXT,
31
32
  LAN_WARNING_TEXT,
32
33
  MIN_KEY_LENGTH,
33
34
  PUBLIC_WARNING_TEXT,
@@ -37,6 +38,7 @@ import {
37
38
  onLanChange,
38
39
  setAccessKey,
39
40
  setBlacklistEnabled,
41
+ setIpv6,
40
42
  setLanAccess,
41
43
  setPublicAccess,
42
44
  setPort,
@@ -389,6 +391,40 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
389
391
  },
390
392
  }
391
393
 
394
+ /** IPv6 监听开关:同样要带 confirm,且总开关必须先开。 */
395
+ const routeIpv6 = {
396
+ kind: 'exact',
397
+ path: '/reproxy-lan/ipv6',
398
+ handler: async (req, res) => {
399
+ if (req.method !== 'POST') {
400
+ sendJson(res, 405, { ok: false, error: '只支持 POST' })
401
+ return
402
+ }
403
+ let body
404
+ try {
405
+ body = await readBody(req)
406
+ } catch (e) {
407
+ sendJson(res, 400, { ok: false, error: e.message })
408
+ return
409
+ }
410
+ if (body.confirm !== true) {
411
+ sendJson(res, 400, { ok: false, error: '缺少用户确认(confirm:true)', warning: IPV6_WARNING_TEXT })
412
+ return
413
+ }
414
+ if (typeof body.enabled !== 'boolean') {
415
+ sendJson(res, 400, { ok: false, error: 'enabled 必须是布尔值' })
416
+ return
417
+ }
418
+ try {
419
+ const next = setIpv6(body.enabled, 'settings')
420
+ log(body.enabled ? 'warn' : 'info', '设置页把 IPv6 监听' + (body.enabled ? '打开' : '关掉'))
421
+ sendJson(res, 200, { ...describeLanState(), warning: IPV6_WARNING_TEXT })
422
+ } catch (e) {
423
+ sendJson(res, 400, { ok: false, error: e.message })
424
+ }
425
+ },
426
+ }
427
+
392
428
  /** 公网开关:必须同时给合法密钥;缺密钥直接 400。 */
393
429
  const routePublic = {
394
430
  kind: 'exact',
@@ -416,7 +452,7 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
416
452
  try {
417
453
  const next = setPublicAccess(body.enabled, body.key, 'settings')
418
454
  log(body.enabled ? 'warn' : 'info', '设置页把公网访问' + (body.enabled ? '打开' : '关掉'))
419
- sendJson(res, 200, { ...next, warning: PUBLIC_WARNING_TEXT })
455
+ sendJson(res, 200, { ...describeLanState(), warning: PUBLIC_WARNING_TEXT })
420
456
  } catch (e) {
421
457
  sendJson(res, 400, { ok: false, error: e.message })
422
458
  }
@@ -459,6 +495,7 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
459
495
  ctx.effect(() => webServer.register(routeBlock))
460
496
  ctx.effect(() => webServer.register(routeUnblock))
461
497
  ctx.effect(() => webServer.register(routePublic))
498
+ ctx.effect(() => webServer.register(routeIpv6))
462
499
  ctx.effect(() => webServer.register(routeKey))
463
500
  } else {
464
501
  log('warn', 'webServer 不可用,设置页开关接口未注册')
@@ -472,23 +509,30 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
472
509
  return
473
510
  }
474
511
 
512
+ const v6LineOf = (s) => (s.ipv6 === true
513
+ ? 'IPv6 监听:已开启([::]:' + effectivePort() + ',走 IPv6 的设备也能进)'
514
+ : 'IPv6 监听:已关闭(只绑 IPv4)')
515
+
475
516
  const statusText = () => {
476
517
  const s = getLanState()
477
518
  const port = effectivePort()
478
519
  const head = s.lanAccess
479
520
  ? '局域网访问:已开启(监听 0.0.0.0:' + port + ',同网段设备可直接进入后台)'
480
521
  : '局域网访问:已关闭(只监听 127.0.0.1:' + port + ',只有本机能访问)'
522
+ const v6Line = s.ipv6
523
+ ? 'IPv6 监听:已开启([::]:' + port + ',走 IPv6 的设备也能进)'
524
+ : 'IPv6 监听:已关闭(只绑 IPv4)'
481
525
  const when = s.updatedAt ? '上次修改:' + s.updatedAt + '(' + (s.updatedBy || 'unknown') + ')' : '还没有改过,当前是默认值'
482
526
  const pub = s.publicAccess
483
527
  ? '公网访问:已开启(访问地址 http://<公网IP>:' + port + '/' + (s.accessKey || '') + ')'
484
528
  : '公网访问:已关闭(只有局域网内设备能访问)'
485
- return [head, pub, when].join('\n')
529
+ return [head, v6Line, pub, when].join('\n')
486
530
  }
487
531
 
488
532
  ctx.effect(() => commands.register({
489
533
  name: 'lan',
490
534
  description: '查看或切换局域网/公网访问开关、端口与访问密钥',
491
- input: { hint: 'yes | no | status | port <n> | public on <key> | public off | key <key>' },
535
+ input: { hint: 'yes | no | status | port <n> | ipv6 on|off | public on <key> | public off | key <key>' },
492
536
  recordInput: true,
493
537
  handler: ({ rawInput }) => {
494
538
  const arg = String(rawInput || '').trim().toLowerCase()
@@ -568,6 +612,27 @@ function registerLanControl(ctx, cfg, log, extra = {}) {
568
612
  log('warn', '命令行更新了公网访问密钥')
569
613
  return { kind: 'success', text: '密钥已更新。\n' + statusText() }
570
614
  }
615
+ if (arg.indexOf('ipv6') === 0) {
616
+ const value = arg.slice(4).trim().toLowerCase()
617
+ const state = getLanState()
618
+ if (value === '') {
619
+ return { kind: 'success', text: v6LineOf(state) + '\n\n用法:/lan ipv6 on 开启、/lan ipv6 off 关闭' }
620
+ }
621
+ if (value !== 'on' && value !== 'off') {
622
+ return { kind: 'error', text: '用法:/lan ipv6 on | off' }
623
+ }
624
+ const want = value === 'on'
625
+ if (want === (state.ipv6 === true)) {
626
+ return { kind: 'success', text: '已经是' + (want ? '开启' : '关闭') + '状态了。\n' + statusText() }
627
+ }
628
+ try {
629
+ setIpv6(want, 'command')
630
+ } catch (e) {
631
+ return { kind: 'error', text: e.message }
632
+ }
633
+ log(want ? 'warn' : 'info', '命令行把 IPv6 监听' + (want ? '打开' : '关掉'))
634
+ return { kind: 'success', text: (want ? IPV6_WARNING_TEXT + '\n\n已开启 IPv6 监听,正在重建监听。' : 'IPv6 监听已关闭。') + '\n' + statusText() }
635
+ }
571
636
  if (arg === 'reset') {
572
637
  return {
573
638
  kind: 'success',
@@ -937,16 +1002,19 @@ function applyProxy(ctx, config) {
937
1002
  // 记住「当前真正在监听」的地址:公网开关/密钥变化不该触发重建监听
938
1003
  let appliedHost = ''
939
1004
  let appliedPort = 0
1005
+ let appliedV6 = null
940
1006
 
941
1007
  const startHosts = () => {
942
1008
  // 端口可能在运行期被改过:每次重建监听都从状态文件取一次
943
1009
  cfg.listenPort = effectivePort()
944
1010
  const host = cfg.listenHost = effectiveListenHost()
1011
+ const wantV6 = getLanState().ipv6 === true
945
1012
  appliedHost = host
946
1013
  appliedPort = cfg.listenPort
1014
+ appliedV6 = wantV6
947
1015
  start(host)
948
1016
  // IPv6 用 ipv6Only,否则 Linux 双栈会把 0.0.0.0 占的端口算作冲突
949
- if (cfg.listenIpv6 && host === '0.0.0.0') {
1017
+ if (wantV6 && host === '0.0.0.0') {
950
1018
  try { start('::') } catch (e) { log('info', 'IPv6 监听跳过: ' + (e && e.message)) }
951
1019
  }
952
1020
  if (getLanState().lanAccess) {
@@ -968,7 +1036,8 @@ function applyProxy(ctx, config) {
968
1036
  // 公网开关、访问密钥、黑名单这些只影响请求判定,重建反而会让正在用的连接断掉
969
1037
  const host = effectiveListenHost()
970
1038
  const port = effectivePort()
971
- if (host === appliedHost && port === appliedPort) return
1039
+ const v6 = getLanState().ipv6 === true
1040
+ if (host === appliedHost && port === appliedPort && v6 === appliedV6) return
972
1041
  rebind()
973
1042
  })
974
1043
  } 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.6.0",
4
- "description": "DSH Web 局域网/公网访问插件:内置反向代理 + 免 Token 登录,手机同 Wi-Fi 直接打开后台;公网访问需开关 + 访问密钥(地址变成 /密钥);端口可改,带访问 IP 黑名单与一键重置。",
3
+ "version": "0.7.0",
4
+ "description": "DSH Web 局域网/公网访问插件:内置反向代理 + 免 Token 登录,手机同 Wi-Fi 直接打开后台;公网访问需开关 + 访问密钥(地址变成 /密钥,密钥可一键随机生成);可选 IPv6 监听;端口可改,带访问 IP 黑名单与一键重置。",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "exports": {
@@ -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}',
@@ -177,6 +203,11 @@ window.__ModuleLoader__.load({
177
203
  headers: { 'content-type': 'application/json' },
178
204
  body: JSON.stringify({ enabled, key, confirm: true })
179
205
  }).then((r) => r.json());
206
+ const writeIpv6 = (enabled) => fetch('/reproxy-lan/ipv6', {
207
+ method: 'POST',
208
+ headers: { 'content-type': 'application/json' },
209
+ body: JSON.stringify({ enabled, confirm: true })
210
+ }).then((r) => r.json());
180
211
  const writeKey = (key) => fetch('/reproxy-lan/key', {
181
212
  method: 'POST',
182
213
  headers: { 'content-type': 'application/json' },
@@ -200,6 +231,10 @@ window.__ModuleLoader__.load({
200
231
  const [pubBusy, setPubBusy] = React.useState(false);
201
232
  const [pubMsg, setPubMsg] = React.useState('');
202
233
  const [pubBad, setPubBad] = React.useState(false);
234
+ const [askV6, setAskV6] = React.useState(false);
235
+ const [v6Busy, setV6Busy] = React.useState(false);
236
+ const [v6Msg, setV6Msg] = React.useState('');
237
+ const [v6Bad, setV6Bad] = React.useState(false);
203
238
  React.useEffect(() => {
204
239
  let alive = true;
205
240
  readState().then((body) => {
@@ -267,6 +302,18 @@ window.__ModuleLoader__.load({
267
302
  setPubMsg(enabled ? '公网访问已开启,用下面那条地址访问' : '公网访问已关闭');
268
303
  }).catch((e) => fail(String((e && e.message) || e))).then(() => setPubBusy(false));
269
304
  };
305
+ const applyV6 = (enabled) => {
306
+ setV6Busy(true);
307
+ setV6Msg('');
308
+ setV6Bad(false);
309
+ writeIpv6(enabled).then((body) => {
310
+ const stateShaped = body && typeof body.ipv6 === 'boolean';
311
+ if (!body || (body.ok !== true && !stateShaped)) throw new Error((body && body.error) || '保存失败');
312
+ setState(body);
313
+ setAskV6(false);
314
+ setV6Msg(enabled ? 'IPv6 监听已开启,正在重建监听' : 'IPv6 监听已关闭');
315
+ }).catch((e) => { setV6Bad(true); setV6Msg(String((e && e.message) || e)); }).then(() => setV6Busy(false));
316
+ };
270
317
  const applyBlock = (ip) => {
271
318
  setIpBusy(ip);
272
319
  setIpMsg('');
@@ -348,6 +395,24 @@ window.__ModuleLoader__.load({
348
395
  }, h('i'))
349
396
  )
350
397
  ),
398
+ h('div', { className: 'reproxy-lan-row' },
399
+ h('div', null,
400
+ h('div', { className: 'reproxy-lan-title' }, 'IPv6 监听(默认关闭)'),
401
+ h('div', { className: 'reproxy-lan-desc' }, '开启后除了 IPv4,还会多绑一条 [::]:' + port + ',走 IPv6 的设备也能进。很多宽带的 IPv6 没有 NAT,外面的设备可能直接连进来 —— 不确定就先别开。')
402
+ ),
403
+ h('div', { className: 'reproxy-lan-ctl' },
404
+ h('span', { className: 'reproxy-lan-state' }, state !== null && state.ipv6 === true ? '已开启' : '已关闭'),
405
+ h('button', {
406
+ className: 'reproxy-lan-switch' + (state && state.ipv6 === true ? ' on' : ''),
407
+ type: 'button',
408
+ 'aria-pressed': state && state.ipv6 === true ? 'true' : 'false',
409
+ disabled: v6Busy || state === null || !on,
410
+ title: !on ? '先打开上面的「局域网访问」总开关' : (state && state.ipv6 === true ? '点击关闭 IPv6 监听' : '点击开启 IPv6 监听(会先弹出安全提示)'),
411
+ onClick: () => setAskV6(true)
412
+ }, h('i'))
413
+ )
414
+ ),
415
+ v6Msg === '' ? null : h('div', { className: v6Bad ? 'reproxy-lan-err' : 'reproxy-lan-ok' }, v6Msg),
351
416
  h('div', { className: 'reproxy-lan-row' },
352
417
  h('div', null,
353
418
  h('div', { className: 'reproxy-lan-title' }, '监听端口'),
@@ -378,6 +443,13 @@ window.__ModuleLoader__.load({
378
443
  h('div', { className: 'reproxy-lan-desc' }, '默认只放行局域网地址,公网 IP 会被拦下(403)。要允许公网访问,请开启这个开关并填写访问密钥——开启后访问地址会变成 http://<公网IP>:' + port + '/<访问密钥>,不知道密钥的人打开只会看到 404。'),
379
444
  state && state.publicAccess ? h('div', { className: 'reproxy-lan-meta', style: { marginTop: '10px' } }, '当前访问地址:http://<公网IP>:' + port + (state.accessPath || '/<访问密钥>')) : null,
380
445
  h('div', { className: 'reproxy-lan-port', style: { marginTop: '12px' } },
446
+ h('button', {
447
+ className: 'reproxy-lan-random',
448
+ type: 'button',
449
+ title: '生成一个 12 位随机访问密钥',
450
+ disabled: pubBusy || state === null,
451
+ onClick: () => { setKeyDraft(randomKey()); setPubMsg(''); setPubBad(false); }
452
+ }, '随机'),
381
453
  h('input', {
382
454
  className: 'reproxy-lan-input',
383
455
  style: { width: '180px', textAlign: 'left' },
@@ -449,6 +521,19 @@ window.__ModuleLoader__.load({
449
521
  '手机和电脑各开一个、或其中一个用无痕窗口,都不受影响。'
450
522
  ),
451
523
  error ? h('div', { className: 'reproxy-lan-err' }, error) : null,
524
+ askV6 ? h('div', { className: 'reproxy-lan-mask' },
525
+ h('div', { className: 'reproxy-lan-card' },
526
+ h('h3', null, IPV6_WARNING_TITLE),
527
+ h('p', null, IPV6_WARNING_LINES[0]),
528
+ h('p', null, IPV6_WARNING_LINES[1]),
529
+ h('p', null, IPV6_WARNING_LINES[2]),
530
+ h('p', null, h('strong', null, state && state.ipv6 === true ? '这次点击会关闭 IPv6 监听。' : '这次点击会额外绑定 [::],确定要继续吗?')),
531
+ h('div', { className: 'reproxy-lan-actions' },
532
+ h('button', { className: 'reproxy-lan-btn', type: 'button', disabled: v6Busy, onClick: () => setAskV6(false) }, '取消'),
533
+ h('button', { className: 'reproxy-lan-btn primary', type: 'button', disabled: v6Busy, onClick: () => applyV6(!(state && state.ipv6 === true)) }, v6Busy ? '处理中…' : '确定')
534
+ )
535
+ )
536
+ ) : null,
452
537
  asking ? h('div', { className: 'reproxy-lan-mask' },
453
538
  h('div', { className: 'reproxy-lan-card' },
454
539
  h('h3', null, LAN_WARNING_TITLE),