dsh-plugin-console-oh 0.0.0-stage → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -2
- package/cordis.patch.yml +16 -0
- package/lib/client.js +451 -0
- package/lib/index.js +1414 -0
- package/lib/server.mjs +718 -0
- package/lib/tunnel.mjs +238 -0
- package/lib/vendor/README.md +11 -0
- package/lib/vendor/dijkstrajs/LICENSE.md +19 -0
- package/lib/vendor/dijkstrajs/index.js +165 -0
- package/lib/vendor/dijkstrajs/package.json +5 -0
- package/lib/vendor/qrcode/LICENSE +10 -0
- package/lib/vendor/qrcode/core/alignment-pattern.js +83 -0
- package/lib/vendor/qrcode/core/alphanumeric-data.js +59 -0
- package/lib/vendor/qrcode/core/bit-buffer.js +37 -0
- package/lib/vendor/qrcode/core/bit-matrix.js +65 -0
- package/lib/vendor/qrcode/core/byte-data.js +30 -0
- package/lib/vendor/qrcode/core/error-correction-code.js +135 -0
- package/lib/vendor/qrcode/core/error-correction-level.js +50 -0
- package/lib/vendor/qrcode/core/finder-pattern.js +22 -0
- package/lib/vendor/qrcode/core/format-info.js +29 -0
- package/lib/vendor/qrcode/core/galois-field.js +69 -0
- package/lib/vendor/qrcode/core/kanji-data.js +54 -0
- package/lib/vendor/qrcode/core/mask-pattern.js +234 -0
- package/lib/vendor/qrcode/core/mode.js +167 -0
- package/lib/vendor/qrcode/core/numeric-data.js +43 -0
- package/lib/vendor/qrcode/core/polynomial.js +62 -0
- package/lib/vendor/qrcode/core/qrcode.js +495 -0
- package/lib/vendor/qrcode/core/reed-solomon-encoder.js +56 -0
- package/lib/vendor/qrcode/core/regex.js +31 -0
- package/lib/vendor/qrcode/core/segments.js +330 -0
- package/lib/vendor/qrcode/core/utils.js +63 -0
- package/lib/vendor/qrcode/core/version-check.js +9 -0
- package/lib/vendor/qrcode/core/version.js +163 -0
- package/lib/vendor/qrcode/index.js +20 -0
- package/lib/vendor/qrcode/package.json +5 -0
- package/lib/vendor/qrcode/renderer/svg-tag.js +81 -0
- package/lib/vendor/qrcode/renderer/utils.js +99 -0
- package/package.json +64 -4
package/lib/server.mjs
ADDED
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
// DSH 控制台 · 手机侧服务(局域网 + 隧道)
|
|
2
|
+
// 目标:零依赖,Node 20+,只做四件事——配对、列会话、读对话、下指令。
|
|
3
|
+
//
|
|
4
|
+
// 安全取舍(都按"默认最严"来):
|
|
5
|
+
// · 默认只监听 127.0.0.1,要用局域网得手动打开(公网走隧道,本机这一段不出网卡)
|
|
6
|
+
// · 访问码只存 sha256,state.json 泄露也拿不到可用的码
|
|
7
|
+
// · 访问码 30 天过期;面板可以单独踢掉某一台设备
|
|
8
|
+
// · 配对失败有全局锁定,6 位码不可枚举
|
|
9
|
+
// · 不返回 Access-Control-Allow-Origin;不支持 ?token=(避免进日志/历史)
|
|
10
|
+
// · 只读模式:打开后手机只能读会话、停止生成,不能发消息
|
|
11
|
+
import http from 'node:http'
|
|
12
|
+
import crypto from 'node:crypto'
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import os from 'node:os'
|
|
15
|
+
import path from 'node:path'
|
|
16
|
+
|
|
17
|
+
export const VERSION = '0.6.2'
|
|
18
|
+
|
|
19
|
+
const CODE_TTL_MS = 15 * 60 * 1000
|
|
20
|
+
const TICKET_TTL_MS = 2 * 60 * 1000
|
|
21
|
+
const TOKEN_TTL_MS = 30 * 24 * 60 * 60 * 1000
|
|
22
|
+
const SESSION_CACHE_MS = 2500
|
|
23
|
+
const MAX_BODY = 20 * 1024 * 1024
|
|
24
|
+
const FAIL_WINDOW_MS = 15 * 60 * 1000
|
|
25
|
+
const FAIL_LIMIT_PER_IP = 10
|
|
26
|
+
const FAIL_LIMIT_GLOBAL = 5
|
|
27
|
+
const LOCK_MS = 15 * 60 * 1000
|
|
28
|
+
|
|
29
|
+
function nowIso() { return new Date().toISOString() }
|
|
30
|
+
|
|
31
|
+
function lanList() {
|
|
32
|
+
const out = []
|
|
33
|
+
const ifs = os.networkInterfaces()
|
|
34
|
+
for (const name of Object.keys(ifs)) {
|
|
35
|
+
for (const one of ifs[name] || []) {
|
|
36
|
+
if (!one || one.family !== 'IPv4' || one.internal) continue
|
|
37
|
+
// 虚拟网卡/自动地址对手机毫无意义,列出来只会让人填错
|
|
38
|
+
if (one.address.startsWith('169.254.')) continue
|
|
39
|
+
if (one.address.startsWith('192.168.56.')) continue // VirtualBox host-only
|
|
40
|
+
if (one.address.startsWith('10.0.2.')) continue // VirtualBox NAT
|
|
41
|
+
let rank = 2
|
|
42
|
+
if (one.address.startsWith('192.168.137.')) rank = 3 // Windows 热点排最后
|
|
43
|
+
else if (/wlan|wi-?fi|无线/i.test(name)) rank = 0
|
|
44
|
+
out.push({ ip: one.address, iface: name, rank })
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
out.sort((a, b) => a.rank - b.rank)
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function lanAddrs() { return lanList().map((x) => x.ip) }
|
|
52
|
+
|
|
53
|
+
function sha256(s) { return crypto.createHash('sha256').update(String(s)).digest('hex') }
|
|
54
|
+
|
|
55
|
+
// 对 Buffer(二进制)正确哈希——sha256() 会把入参 String() 化,对字节内容是错的
|
|
56
|
+
function sha256buf(b) { return crypto.createHash('sha256').update(b).digest('hex') }
|
|
57
|
+
|
|
58
|
+
// 回给手机的错误文案:抹掉本地路径、截断,别把内部结构送出去
|
|
59
|
+
function safeMsg(e) {
|
|
60
|
+
let m = String((e && e.message) || e || '')
|
|
61
|
+
m = m.replace(/[A-Za-z]:\\[^\s"']+/g, '<path>')
|
|
62
|
+
m = m.replace(/\/(?:[\w.-]+\/){2,}[\w.-]+/g, '<path>')
|
|
63
|
+
return m.length > 160 ? m.slice(0, 160) + '…' : m
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function readBody(req) {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
let size = 0
|
|
69
|
+
const chunks = []
|
|
70
|
+
req.on('data', (c) => {
|
|
71
|
+
size += c.length
|
|
72
|
+
if (size > MAX_BODY) { reject(new Error('请求体过大')); req.destroy(); return }
|
|
73
|
+
chunks.push(c)
|
|
74
|
+
})
|
|
75
|
+
req.on('end', () => {
|
|
76
|
+
const raw = Buffer.concat(chunks).toString('utf8')
|
|
77
|
+
if (!raw) return resolve({})
|
|
78
|
+
try { resolve(JSON.parse(raw)) } catch (e) { reject(new Error('请求体不是 JSON')) }
|
|
79
|
+
})
|
|
80
|
+
req.on('error', reject)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 故意不发 CORS 头:面板同源,手机是原生 HTTP 客户端,都不需要
|
|
85
|
+
function sendJson(res, status, payload) {
|
|
86
|
+
res.writeHead(status, {
|
|
87
|
+
'content-type': 'application/json; charset=utf-8',
|
|
88
|
+
'cache-control': 'no-store',
|
|
89
|
+
'x-content-type-options': 'nosniff'
|
|
90
|
+
})
|
|
91
|
+
res.end(JSON.stringify(payload))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 落地页不含主机名、不含内网 IP、不含端口——公网上谁拿到地址都读不到信息
|
|
95
|
+
const LANDING = `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">
|
|
96
|
+
<meta name="viewport" content="width=device-width,initial-scale=1"><title>DSH 控制台</title>
|
|
97
|
+
<style>
|
|
98
|
+
:root{color-scheme:dark}
|
|
99
|
+
body{margin:0;min-height:100vh;display:grid;place-items:center;background:#0e0f12;color:#f4f5f7;
|
|
100
|
+
font:15px/1.7 -apple-system,"HarmonyOS Sans SC","Segoe UI",sans-serif}
|
|
101
|
+
.card{padding:26px 30px;border:1px solid #2a2d34;border-radius:26px;background:#17181c;text-align:center}
|
|
102
|
+
.dot{display:inline-block;width:7px;height:7px;border-radius:50%;background:#3ecf8e;margin-right:8px;vertical-align:2px}
|
|
103
|
+
p{margin:8px 0 0;color:#9ba0aa;font-size:13px}
|
|
104
|
+
</style></head><body><div class="card">
|
|
105
|
+
<div style="font-size:12px;color:#9ba0aa"><span class="dot"></span>服务在线</div>
|
|
106
|
+
<p>请在手机上的「DSH 控制台」里扫码或输入配对码。</p>
|
|
107
|
+
</div></body></html>`
|
|
108
|
+
|
|
109
|
+
export function createConsoleServer(opts) {
|
|
110
|
+
const bridge = opts.bridge
|
|
111
|
+
const dataDir = opts.dataDir
|
|
112
|
+
const log = typeof opts.log === 'function' ? opts.log : () => {}
|
|
113
|
+
const tunnel = opts.tunnel || null
|
|
114
|
+
const wantPort = Number(opts.port) || 8909
|
|
115
|
+
const nodeName = String(opts.name || os.hostname() || 'DSH 电脑')
|
|
116
|
+
|
|
117
|
+
const statePath = path.join(dataDir, 'state.json')
|
|
118
|
+
let devices = []
|
|
119
|
+
// 公网 / 局域网各一个码,互不复用:任意时刻两者都不会相同
|
|
120
|
+
let codes = { lan: { code: '', exp: 0 }, wan: { code: '', exp: 0 } }
|
|
121
|
+
let remotePair = false
|
|
122
|
+
let readOnly = false
|
|
123
|
+
let lanAccess = false
|
|
124
|
+
let tunnelAuto = false
|
|
125
|
+
let server = null
|
|
126
|
+
let boundPort = 0
|
|
127
|
+
let bindHost = '127.0.0.1'
|
|
128
|
+
let startedAt = 0
|
|
129
|
+
const fails = new Map()
|
|
130
|
+
const tickets = new Map()
|
|
131
|
+
let sessionCache = { at: 0, list: [] }
|
|
132
|
+
|
|
133
|
+
// ── 持久化 ────────────────────────────────────────────────────────────
|
|
134
|
+
let needSave = false
|
|
135
|
+
try {
|
|
136
|
+
fs.mkdirSync(dataDir, { recursive: true })
|
|
137
|
+
if (fs.existsSync(statePath)) {
|
|
138
|
+
const j = JSON.parse(fs.readFileSync(statePath, 'utf8'))
|
|
139
|
+
if (Array.isArray(j.devices)) {
|
|
140
|
+
// 老版本存的是明文 token,这里顺手迁移成 hash
|
|
141
|
+
if (j.devices.some((d) => d && (typeof d.token === 'string' || typeof d.ip === 'string'))) needSave = true
|
|
142
|
+
devices = j.devices
|
|
143
|
+
.filter((d) => d && (typeof d.hash === 'string' || typeof d.token === 'string'))
|
|
144
|
+
.map((d) => ({
|
|
145
|
+
id: String(d.id || crypto.randomBytes(6).toString('hex')),
|
|
146
|
+
hash: typeof d.hash === 'string' ? d.hash : sha256(d.token),
|
|
147
|
+
label: String(d.label || '手机'),
|
|
148
|
+
at: Number(d.at) || Date.now(),
|
|
149
|
+
exp: Number(d.exp) || (Number(d.at) || Date.now()) + TOKEN_TTL_MS,
|
|
150
|
+
// 信任直连:设备公钥(SPKI DER)的 sha256。有它 = 这台设备可以免扫码换新访问码
|
|
151
|
+
pk: typeof d.pk === 'string' ? d.pk : '',
|
|
152
|
+
// 首次入网方式:'scan' = 走过扫码/配对码。公网信任直连只对 scan 设备放行
|
|
153
|
+
origin: typeof d.origin === 'string' ? d.origin : 'scan'
|
|
154
|
+
}))
|
|
155
|
+
}
|
|
156
|
+
if (j.remotePair === true) remotePair = true
|
|
157
|
+
if (j.readOnly === true) readOnly = true
|
|
158
|
+
if (j.lanAccess === true) lanAccess = true
|
|
159
|
+
if (j.tunnelAuto === true) tunnelAuto = true
|
|
160
|
+
}
|
|
161
|
+
} catch (e) { log('[state] 读取失败:' + ((e && e.message) || e)) }
|
|
162
|
+
|
|
163
|
+
function save() {
|
|
164
|
+
try {
|
|
165
|
+
fs.writeFileSync(statePath, JSON.stringify({ devices, remotePair, readOnly, lanAccess, tunnelAuto, savedAt: nowIso() }, null, 2))
|
|
166
|
+
} catch (e) { log('[state] 写入失败:' + ((e && e.message) || e)) }
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (needSave) {
|
|
170
|
+
save()
|
|
171
|
+
log('[state] 已把明文访问码迁移为 sha256')
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function liveCode(scope) {
|
|
175
|
+
const rec = codes[scope]
|
|
176
|
+
return rec && rec.code && Date.now() <= rec.exp ? rec.code : ''
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function newCode(scope) {
|
|
180
|
+
const target = scope === 'lan' ? 'lan' : 'wan'
|
|
181
|
+
const other = target === 'wan' ? 'lan' : 'wan'
|
|
182
|
+
let v = ''
|
|
183
|
+
// 与另一入口在有效期内的码撞了就重取,保证两个码永远不同
|
|
184
|
+
do {
|
|
185
|
+
v = String(crypto.randomInt(100000, 1000000))
|
|
186
|
+
} while (other && v === liveCode(other))
|
|
187
|
+
codes[target] = { code: v, exp: Date.now() + CODE_TTL_MS }
|
|
188
|
+
log('[pair] ' + (target === 'wan' ? '公网' : '局域网') + '配对码已生成,15 分钟内有效')
|
|
189
|
+
return v
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function issueToken(label, ip, pkHash, origin) {
|
|
193
|
+
const raw = crypto.randomBytes(24).toString('hex')
|
|
194
|
+
const now = Date.now()
|
|
195
|
+
devices = devices.filter((d) => d.label !== label).slice(-19)
|
|
196
|
+
const rec = {
|
|
197
|
+
id: crypto.randomBytes(6).toString('hex'),
|
|
198
|
+
hash: sha256(raw),
|
|
199
|
+
label: String(label || '手机'),
|
|
200
|
+
at: now,
|
|
201
|
+
exp: now + TOKEN_TTL_MS,
|
|
202
|
+
pk: typeof pkHash === 'string' && pkHash.length > 0 ? pkHash : '',
|
|
203
|
+
origin: origin === 'scan' ? 'scan' : ''
|
|
204
|
+
}
|
|
205
|
+
devices.push(rec)
|
|
206
|
+
save()
|
|
207
|
+
return raw
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function revokeDevice(id) {
|
|
211
|
+
const before = devices.length
|
|
212
|
+
devices = devices.filter((d) => d.id !== String(id || ''))
|
|
213
|
+
if (devices.length !== before) save()
|
|
214
|
+
return before - devices.length
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// ── 信任直连(我的电脑)────────────────────────────────────────────────
|
|
218
|
+
// 已配对设备留有公钥(设备记录的 pk 字段)。token 失效/过期后,
|
|
219
|
+
// 手机用设备私钥对 ts|rand 签名即可换新访问码,不用再扫码。
|
|
220
|
+
// 安全设计:桌面只存公钥哈希(同 token 的 sha256 取舍);签名带时间戳 + 一次性缓存防重放;
|
|
221
|
+
// 面板「踢掉设备」删除整条设备记录,信任随之吊销。
|
|
222
|
+
const REAUTH_WINDOW_MS = 60 * 1000
|
|
223
|
+
const seenSigs = new Map()
|
|
224
|
+
|
|
225
|
+
function sigUsed(key) {
|
|
226
|
+
const now = Date.now()
|
|
227
|
+
for (const [k, exp] of seenSigs) if (exp <= now) seenSigs.delete(k)
|
|
228
|
+
if (seenSigs.has(key)) return true
|
|
229
|
+
seenSigs.set(key, now + 2 * REAUTH_WINDOW_MS)
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// cryptoFramework 的 ECC 签名输出格式(DER / ieee-p1363)与摘要行为随 API 版本有差异,
|
|
234
|
+
// 这里把「签名编码 × 摘要语义」的组合都试一遍,客户端不需要关心细节:
|
|
235
|
+
// sha256+msg:端上内部做了 SHA256;null+sha256(msg):端上自己预摘要后签摘要值;null+msg:端上直接签原文
|
|
236
|
+
function sigOk(pubKey, msgBuf, sig) {
|
|
237
|
+
const digest = crypto.createHash('sha256').update(msgBuf).digest()
|
|
238
|
+
const variants = [
|
|
239
|
+
{ alg: 'sha256', data: msgBuf },
|
|
240
|
+
{ alg: null, data: digest },
|
|
241
|
+
{ alg: null, data: msgBuf }
|
|
242
|
+
]
|
|
243
|
+
for (const v of variants) {
|
|
244
|
+
for (const enc of ['der', 'ieee-p1363']) {
|
|
245
|
+
try {
|
|
246
|
+
const key = enc === 'der' ? pubKey : { key: pubKey, dsaEncoding: 'ieee-p1363' }
|
|
247
|
+
if (crypto.verify(v.alg, v.data, key, sig)) return true
|
|
248
|
+
} catch (e) { /* 换下一种组合继续试 */ }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return false
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function issueTicket() {
|
|
255
|
+
const now = Date.now()
|
|
256
|
+
for (const [k, v] of tickets) if (v.exp <= now) tickets.delete(k)
|
|
257
|
+
const t = 'pt_' + crypto.randomBytes(16).toString('hex')
|
|
258
|
+
tickets.set(t, { exp: now + TICKET_TTL_MS })
|
|
259
|
+
return t
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function redeemTicket(t) {
|
|
263
|
+
const key = String(t || '')
|
|
264
|
+
const rec = tickets.get(key)
|
|
265
|
+
if (!rec) return false
|
|
266
|
+
tickets.delete(key)
|
|
267
|
+
return rec.exp > Date.now()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function candidates() {
|
|
271
|
+
const out = []
|
|
272
|
+
const t = tunnel ? tunnel.status() : null
|
|
273
|
+
if (t && t.state === 'up' && t.url) out.push(t.url)
|
|
274
|
+
if (lanAccess) for (const ip of lanAddrs()) out.push('http://' + ip + ':' + (boundPort || wantPort))
|
|
275
|
+
return out
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function baseUrl() {
|
|
279
|
+
const list = candidates()
|
|
280
|
+
return list.length > 0 ? list[0] : ''
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// 二维码里 u 是首选地址,c 是备选列表(逗号分隔)
|
|
284
|
+
function pairLink() {
|
|
285
|
+
const list = candidates()
|
|
286
|
+
if (list.length === 0) return ''
|
|
287
|
+
const rest = list.slice(1)
|
|
288
|
+
let link = 'dshconsole://pair?u=' + encodeURIComponent(list[0]) + '&k=' + issueTicket() + '&n=' + encodeURIComponent(nodeName)
|
|
289
|
+
if (rest.length > 0) link += '&c=' + encodeURIComponent(rest.join(','))
|
|
290
|
+
return link
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function isWan(req) {
|
|
294
|
+
const xff = req.headers['x-forwarded-for']
|
|
295
|
+
return typeof xff === 'string' && xff.trim() !== ''
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function isLoopback(req) {
|
|
299
|
+
const a = req.socket && req.socket.remoteAddress ? String(req.socket.remoteAddress) : ''
|
|
300
|
+
return a === '127.0.0.1' || a === '::1' || a === '::ffff:127.0.0.1'
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// 限流键:直连时用 socket 地址(伪造不了);走自己的隧道时用 XFF 最后一段(Cloudflare 追加的真实来源)。
|
|
304
|
+
// 这样每个真实来源各自一个桶,谁也别想靠刷错码把别人锁死。
|
|
305
|
+
function peerOf(req) {
|
|
306
|
+
if (!isLoopback(req)) {
|
|
307
|
+
const a = req.socket && req.socket.remoteAddress ? String(req.socket.remoteAddress) : 'unknown'
|
|
308
|
+
return a
|
|
309
|
+
}
|
|
310
|
+
const xff = req.headers['x-forwarded-for']
|
|
311
|
+
if (typeof xff === 'string' && xff.trim() !== '') {
|
|
312
|
+
const parts = xff.split(',')
|
|
313
|
+
return String(parts[parts.length - 1]).trim() || 'tunnel'
|
|
314
|
+
}
|
|
315
|
+
return 'local'
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function tooMany(key) {
|
|
319
|
+
const rec = fails.get(key)
|
|
320
|
+
if (!rec) return false
|
|
321
|
+
if (Date.now() - rec.at > FAIL_WINDOW_MS) { fails.delete(key); return false }
|
|
322
|
+
return rec.n >= FAIL_LIMIT_PER_IP
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function markFail(key) {
|
|
326
|
+
const now = Date.now()
|
|
327
|
+
const rec = fails.get(key)
|
|
328
|
+
if (!rec || now - rec.at > FAIL_WINDOW_MS) fails.set(key, { n: 1, at: now })
|
|
329
|
+
else { rec.n += 1; rec.at = now }
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function markOk(key) {
|
|
333
|
+
fails.delete(key)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function authed(req) {
|
|
337
|
+
const t = req.headers['x-console-token']
|
|
338
|
+
if (typeof t !== 'string' || t.trim() === '') return null
|
|
339
|
+
const h = sha256(t.trim())
|
|
340
|
+
const now = Date.now()
|
|
341
|
+
for (const d of devices) {
|
|
342
|
+
if (d.hash.length !== h.length) continue
|
|
343
|
+
if (!crypto.timingSafeEqual(Buffer.from(d.hash, 'utf8'), Buffer.from(h, 'utf8'))) continue
|
|
344
|
+
if (d.exp <= now) return { expired: true }
|
|
345
|
+
return d
|
|
346
|
+
}
|
|
347
|
+
return null
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function sessions(force) {
|
|
351
|
+
if (!force && Date.now() - sessionCache.at < SESSION_CACHE_MS) return sessionCache.list
|
|
352
|
+
const list = await bridge.listSessions()
|
|
353
|
+
sessionCache = { at: Date.now(), list: Array.isArray(list) ? list : [] }
|
|
354
|
+
return sessionCache.list
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// ── 路由 ─────────────────────────────────────────────────────────────
|
|
358
|
+
async function handle(req, res) {
|
|
359
|
+
const url = new URL(req.url || '/', 'http://127.0.0.1')
|
|
360
|
+
const p = url.pathname.replace(/\/+$/, '') || '/'
|
|
361
|
+
|
|
362
|
+
if (p === '/' && req.method === 'GET') {
|
|
363
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' })
|
|
364
|
+
res.end(LANDING)
|
|
365
|
+
return
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (p === '/health') {
|
|
369
|
+
// 诊断字段:给手机端「网络诊断」用。只含低敏环境描述(运行时长 / 隧道状态 / 开关),
|
|
370
|
+
// 不含端口、主机名、局域网地址、隧道 URL、令牌与设备记录——免鉴权端点按最小暴露原则。
|
|
371
|
+
const t = tunnel ? tunnel.status() : { state: 'off' }
|
|
372
|
+
return sendJson(res, 200, {
|
|
373
|
+
ok: true,
|
|
374
|
+
app: 'dsh-console-oh',
|
|
375
|
+
version: VERSION,
|
|
376
|
+
uptimeSec: startedAt > 0 ? Math.round((Date.now() - startedAt) / 1000) : 0,
|
|
377
|
+
readOnly,
|
|
378
|
+
remotePair,
|
|
379
|
+
lanAccess,
|
|
380
|
+
tunnelState: t.state
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// 配对:唯一一条不需要访问码的写路由
|
|
385
|
+
if (p === '/v1/pair' && req.method === 'POST') {
|
|
386
|
+
const ip = peerOf(req)
|
|
387
|
+
if (tooMany(ip)) return sendJson(res, 429, { ok: false, error: '尝试次数过多,请 15 分钟后再试' })
|
|
388
|
+
if (isWan(req) && !remotePair) {
|
|
389
|
+
return sendJson(res, 403, { ok: false, error: '公网配对未开启,请在电脑端面板打开「异地配对」', reason: 'remote-pair-off' })
|
|
390
|
+
}
|
|
391
|
+
let body = {}
|
|
392
|
+
try { body = await readBody(req) } catch (e) { return sendJson(res, 400, { ok: false, error: e.message }) }
|
|
393
|
+
const got = String(body.code || '').replace(/\D/g, '')
|
|
394
|
+
if (got.length !== 6) return sendJson(res, 400, { ok: false, error: '配对码是 6 位数字', reason: 'bad-format' })
|
|
395
|
+
// 码和入口必须对上:公网走隧道(有 x-forwarded-for),局域网直连
|
|
396
|
+
const scope = isWan(req) ? 'wan' : 'lan'
|
|
397
|
+
if (body.channel && String(body.channel) !== scope) {
|
|
398
|
+
markFail(ip)
|
|
399
|
+
return sendJson(res, 403, { ok: false, error: '这是' + (String(body.channel) === 'wan' ? '公网' : '局域网') + '配对码,入口不对', reason: 'channel-mismatch' })
|
|
400
|
+
}
|
|
401
|
+
if (got === liveCode(scope === 'wan' ? 'lan' : 'wan')) {
|
|
402
|
+
markFail(ip)
|
|
403
|
+
return sendJson(res, 403, { ok: false, error: '公网和局域网的配对码不能混用', reason: 'code-channel-mismatch' })
|
|
404
|
+
}
|
|
405
|
+
if (got !== liveCode(scope)) {
|
|
406
|
+
markFail(ip)
|
|
407
|
+
return sendJson(res, 403, { ok: false, error: '配对码不对或已过期', reason: 'code-mismatch' })
|
|
408
|
+
}
|
|
409
|
+
markOk(ip)
|
|
410
|
+
const label = String(body.label || '鸿蒙手机').slice(0, 40)
|
|
411
|
+
const token = issueToken(label, ip, '', 'scan')
|
|
412
|
+
codes[scope] = { code: '', exp: 0 }
|
|
413
|
+
newCode(scope)
|
|
414
|
+
let dsh = { ok: false, error: '' }
|
|
415
|
+
try { dsh = await bridge.health() } catch (e) { dsh = { ok: false, error: safeMsg(e) } }
|
|
416
|
+
return sendJson(res, 200, {
|
|
417
|
+
ok: true, token,
|
|
418
|
+
node: { name: nodeName, platform: process.platform, dsh },
|
|
419
|
+
tunnel: tunnel ? tunnel.status() : null
|
|
420
|
+
})
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// 二维码里的一次性票据换访问码:不用输地址、不用输 6 位码
|
|
424
|
+
if (p === '/v1/pair/ticket' && req.method === 'POST') {
|
|
425
|
+
const ip = peerOf(req)
|
|
426
|
+
if (tooMany(ip)) return sendJson(res, 429, { ok: false, error: '尝试次数过多,请 15 分钟后再试' })
|
|
427
|
+
let body = {}
|
|
428
|
+
try { body = await readBody(req) } catch (e) { return sendJson(res, 400, { ok: false, error: e.message }) }
|
|
429
|
+
if (!redeemTicket(body.ticket)) {
|
|
430
|
+
markFail(ip)
|
|
431
|
+
return sendJson(res, 403, { ok: false, error: '二维码已过期,在电脑上点一下刷新', reason: 'ticket-expired' })
|
|
432
|
+
}
|
|
433
|
+
markOk(ip)
|
|
434
|
+
const label = String(body.label || '鸿蒙手机').slice(0, 40)
|
|
435
|
+
const token = issueToken(label, ip, '', 'scan')
|
|
436
|
+
let dsh = { ok: false, error: '' }
|
|
437
|
+
try { dsh = await bridge.health() } catch (e) { dsh = { ok: false, error: safeMsg(e) } }
|
|
438
|
+
return sendJson(res, 200, {
|
|
439
|
+
ok: true, token,
|
|
440
|
+
node: { name: nodeName, platform: process.platform, dsh },
|
|
441
|
+
tunnel: tunnel ? tunnel.status() : null
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 信任直连:设备私钥签名换新访问码,免扫码。走公网也放行——
|
|
446
|
+
// 能通过私钥签名就证明是已受信的设备,不依赖网络位置;面板踢设备即吊销。
|
|
447
|
+
if (p === '/v1/reauth' && req.method === 'POST') {
|
|
448
|
+
const ip = peerOf(req)
|
|
449
|
+
if (tooMany(ip)) return sendJson(res, 429, { ok: false, error: '尝试次数过多,请 15 分钟后再试' })
|
|
450
|
+
let body = {}
|
|
451
|
+
try { body = await readBody(req) } catch (e) { return sendJson(res, 400, { ok: false, error: e.message }) }
|
|
452
|
+
const pubB64 = String(body.pub || '')
|
|
453
|
+
const ts = Number(body.ts) || 0
|
|
454
|
+
const rand = String(body.rand || '')
|
|
455
|
+
const sigB64 = String(body.sig || '')
|
|
456
|
+
const noTrust = { ok: false, error: '这台手机还没建立信任,先用配对码连一次,连上后电脑会记住它', reason: 'no-trust' }
|
|
457
|
+
if (pubB64.length === 0 || pubB64.length > 1024 || sigB64.length === 0 || sigB64.length > 512) {
|
|
458
|
+
markFail(ip)
|
|
459
|
+
return sendJson(res, 403, noTrust)
|
|
460
|
+
}
|
|
461
|
+
if (rand.length < 8 || rand.length > 128 || Math.abs(Date.now() - ts) > REAUTH_WINDOW_MS) {
|
|
462
|
+
markFail(ip)
|
|
463
|
+
return sendJson(res, 403, { ok: false, error: '请求已过期,再点一次「我的电脑」', reason: 'stale' })
|
|
464
|
+
}
|
|
465
|
+
let dev = null
|
|
466
|
+
let pubKey = null
|
|
467
|
+
try {
|
|
468
|
+
const pubDer = Buffer.from(pubB64, 'base64')
|
|
469
|
+
if (pubDer.length > 0 && pubDer.length < 512) {
|
|
470
|
+
dev = devices.find((d) => d.pk === sha256buf(pubDer)) || null
|
|
471
|
+
if (dev) pubKey = crypto.createPublicKey({ key: pubDer, format: 'der', type: 'spki' })
|
|
472
|
+
}
|
|
473
|
+
} catch (e) { dev = null }
|
|
474
|
+
if (!dev || !pubKey) {
|
|
475
|
+
markFail(ip)
|
|
476
|
+
return sendJson(res, 403, noTrust)
|
|
477
|
+
}
|
|
478
|
+
// 规则:新设备首次公网连接必须先完成扫码验证(origin=scan 由配对码/扫码票据路径打上)
|
|
479
|
+
if (isWan(req) && dev.origin !== 'scan') {
|
|
480
|
+
markFail(ip)
|
|
481
|
+
return sendJson(res, 403, { ok: false, error: '新设备首次公网连接必须先完成扫码配对', reason: 'first-scan-required' })
|
|
482
|
+
}
|
|
483
|
+
const msgBuf = Buffer.from(ts + '|' + rand, 'utf8')
|
|
484
|
+
const sig = Buffer.from(sigB64, 'base64')
|
|
485
|
+
if (sigUsed(sha256(sigB64 + '|' + msgBuf.toString('utf8'))) || !sigOk(pubKey, msgBuf, sig)) {
|
|
486
|
+
markFail(ip)
|
|
487
|
+
return sendJson(res, 403, { ok: false, error: '信任校验没通过,用配对码重连一次即可', reason: 'sig-mismatch' })
|
|
488
|
+
}
|
|
489
|
+
markOk(ip)
|
|
490
|
+
const token = issueToken(dev.label, ip, dev.pk, dev.origin === 'scan' ? 'scan' : '')
|
|
491
|
+
let dsh = { ok: false, error: '' }
|
|
492
|
+
try { dsh = await bridge.health() } catch (e) { dsh = { ok: false, error: safeMsg(e) } }
|
|
493
|
+
return sendJson(res, 200, {
|
|
494
|
+
ok: true, token,
|
|
495
|
+
node: { name: nodeName, platform: process.platform, dsh },
|
|
496
|
+
tunnel: tunnel ? tunnel.status() : null
|
|
497
|
+
})
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const dev = authed(req)
|
|
501
|
+
if (dev && dev.expired) return sendJson(res, 401, { ok: false, error: '访问码已过期,请重新配对' })
|
|
502
|
+
if (!dev) return sendJson(res, 401, { ok: false, error: '未配对或访问码已失效' })
|
|
503
|
+
|
|
504
|
+
if (p === '/v1/info' && req.method === 'GET') {
|
|
505
|
+
let list = []
|
|
506
|
+
let dsh = { ok: false, error: '' }
|
|
507
|
+
try { dsh = await bridge.health() } catch (e) { dsh = { ok: false, error: safeMsg(e) } }
|
|
508
|
+
try { list = await sessions(false) } catch (e) { list = [] }
|
|
509
|
+
return sendJson(res, 200, {
|
|
510
|
+
ok: true,
|
|
511
|
+
node: { name: nodeName, platform: process.platform },
|
|
512
|
+
dsh,
|
|
513
|
+
readOnly,
|
|
514
|
+
sessions: {
|
|
515
|
+
count: list.length,
|
|
516
|
+
running: list.filter((s) => s && s.running).length
|
|
517
|
+
},
|
|
518
|
+
modesRev: typeof bridge.modesRev === 'function' ? bridge.modesRev() : 0,
|
|
519
|
+
tunnel: tunnel ? tunnel.status() : null,
|
|
520
|
+
device: { label: dev.label, since: dev.at }
|
|
521
|
+
})
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (p === '/v1/sessions' && req.method === 'GET') {
|
|
525
|
+
const list = await sessions(true)
|
|
526
|
+
return sendJson(res, 200, { ok: true, count: list.length, sessions: list })
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// 交付文件下载:AI 用 present 发给用户的文件。
|
|
530
|
+
// path 必须是本会话交付列表里的成员(服务端重新从会话事件校验),防止接口被当任意文件读取器。
|
|
531
|
+
if (p === '/v1/file' && req.method === 'GET') {
|
|
532
|
+
const sessionId = String(url.searchParams.get('sessionId') || '')
|
|
533
|
+
const fp = String(url.searchParams.get('path') || '')
|
|
534
|
+
if (sessionId === '' || fp === '') return sendJson(res, 400, { ok: false, error: '缺少 sessionId 或 path' })
|
|
535
|
+
let list = []
|
|
536
|
+
try { list = await bridge.deliverables(sessionId) } catch (e) { return sendJson(res, 500, { ok: false, error: safeMsg(e) }) }
|
|
537
|
+
const hit = list.find((f) => f.path === fp)
|
|
538
|
+
if (hit === undefined) return sendJson(res, 404, { ok: false, error: '文件不在本会话的交付列表里' })
|
|
539
|
+
let st = null
|
|
540
|
+
try { st = fs.statSync(hit.path) } catch (_) { return sendJson(res, 404, { ok: false, error: '文件在电脑上已不存在' }) }
|
|
541
|
+
if (!st.isFile()) return sendJson(res, 404, { ok: false, error: '目标不是常规文件' })
|
|
542
|
+
res.writeHead(200, {
|
|
543
|
+
'content-type': 'application/octet-stream',
|
|
544
|
+
'content-length': st.size,
|
|
545
|
+
'cache-control': 'no-store',
|
|
546
|
+
'x-file-name': encodeURIComponent(hit.name)
|
|
547
|
+
})
|
|
548
|
+
const stream = fs.createReadStream(hit.path)
|
|
549
|
+
stream.on('error', () => { try { res.destroy() } catch (_) { } })
|
|
550
|
+
stream.pipe(res)
|
|
551
|
+
return
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// 信任凭据注册:已配对设备把设备公钥挂到自己的设备记录上(可重复调用换新钥)
|
|
555
|
+
if (p === '/v1/device-key' && req.method === 'POST') {
|
|
556
|
+
let body = {}
|
|
557
|
+
try { body = await readBody(req) } catch (e) { return sendJson(res, 400, { ok: false, error: e.message }) }
|
|
558
|
+
const pubB64 = String(body.pub || '')
|
|
559
|
+
if (pubB64.length === 0 || pubB64.length > 1024) return sendJson(res, 400, { ok: false, error: '公钥格式不对' })
|
|
560
|
+
try {
|
|
561
|
+
const pubDer = Buffer.from(pubB64, 'base64')
|
|
562
|
+
if (pubDer.length === 0 || pubDer.length >= 512) throw new Error('bad')
|
|
563
|
+
crypto.createPublicKey({ key: pubDer, format: 'der', type: 'spki' })
|
|
564
|
+
dev.pk = sha256buf(pubDer)
|
|
565
|
+
save()
|
|
566
|
+
log('[trust] 设备「' + dev.label + '」已登记信任公钥')
|
|
567
|
+
return sendJson(res, 200, { ok: true })
|
|
568
|
+
} catch (e) {
|
|
569
|
+
return sendJson(res, 400, { ok: false, error: '公钥格式不对' })
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// 模式清单:官方两个 + 桌面端模式插件提供的全部预设,实时(rev 变即刷新)
|
|
574
|
+
if (p === '/v1/modes' && req.method === 'GET') {
|
|
575
|
+
try {
|
|
576
|
+
if (typeof bridge.modes !== 'function') return sendJson(res, 200, { ok: false, error: '这个版本不支持模式', modes: [] })
|
|
577
|
+
const m = await bridge.modes()
|
|
578
|
+
return sendJson(res, 200, Object.assign({ ok: true }, m))
|
|
579
|
+
} catch (e) {
|
|
580
|
+
return sendJson(res, 200, { ok: false, error: safeMsg(e), modes: [] })
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (p === '/v1/models' && req.method === 'GET') {
|
|
585
|
+
const sessionId = String(url.searchParams.get('sessionId') || '')
|
|
586
|
+
if (sessionId === '') return sendJson(res, 400, { ok: false, error: '缺少 sessionId' })
|
|
587
|
+
try {
|
|
588
|
+
const models = await bridge.command('models', { sessionId })
|
|
589
|
+
return sendJson(res, 200, Object.assign({ ok: true }, models))
|
|
590
|
+
} catch (e) {
|
|
591
|
+
return sendJson(res, 200, { ok: false, error: safeMsg(e), groups: [] })
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const mTurns = p.match(/^\/v1\/sessions\/([^/]+)\/turns$/)
|
|
596
|
+
if (mTurns && req.method === 'GET') {
|
|
597
|
+
const id = decodeURIComponent(mTurns[1])
|
|
598
|
+
const detail = await bridge.turns(id)
|
|
599
|
+
return sendJson(res, 200, Object.assign({ ok: true }, detail))
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (p === '/v1/cmd' && req.method === 'POST') {
|
|
603
|
+
let body = {}
|
|
604
|
+
try { body = await readBody(req) } catch (e) { return sendJson(res, 400, { ok: false, error: e.message }) }
|
|
605
|
+
const op = String(body.op || '')
|
|
606
|
+
if (!op) return sendJson(res, 400, { ok: false, error: '缺少 op' })
|
|
607
|
+
if (readOnly && op !== 'cancel') {
|
|
608
|
+
return sendJson(res, 403, { ok: false, error: '电脑开着只读模式,手机只能看不能发' })
|
|
609
|
+
}
|
|
610
|
+
try {
|
|
611
|
+
const result = await bridge.command(op, body.payload || {})
|
|
612
|
+
if (op === 'send' || op === 'cancel') sessionCache.at = 0
|
|
613
|
+
return sendJson(res, 200, { ok: true, result })
|
|
614
|
+
} catch (e) {
|
|
615
|
+
return sendJson(res, 500, { ok: false, error: safeMsg(e) })
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
return sendJson(res, 404, { ok: false, error: '没有这个接口' })
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function listen(host) {
|
|
623
|
+
return new Promise((resolve, reject) => {
|
|
624
|
+
const onReq = (req, res) => {
|
|
625
|
+
Promise.resolve()
|
|
626
|
+
.then(() => handle(req, res))
|
|
627
|
+
.catch((e) => {
|
|
628
|
+
log('[http] ' + ((e && e.stack) || e))
|
|
629
|
+
if (!res.headersSent) sendJson(res, 500, { ok: false, error: safeMsg(e) })
|
|
630
|
+
else try { res.end() } catch (_) { }
|
|
631
|
+
})
|
|
632
|
+
}
|
|
633
|
+
const tryListen = (port, left) => {
|
|
634
|
+
const s = http.createServer(onReq)
|
|
635
|
+
s.once('error', (e) => {
|
|
636
|
+
if (e && e.code === 'EADDRINUSE' && left > 0) { tryListen(port + 1, left - 1); return }
|
|
637
|
+
reject(e)
|
|
638
|
+
})
|
|
639
|
+
s.listen(port, host, () => {
|
|
640
|
+
server = s
|
|
641
|
+
boundPort = port
|
|
642
|
+
bindHost = host
|
|
643
|
+
startedAt = Date.now()
|
|
644
|
+
if (!liveCode('lan')) newCode('lan')
|
|
645
|
+
if (!liveCode('wan')) newCode('wan')
|
|
646
|
+
log('[http] 监听 ' + host + ':' + port + (port !== wantPort ? '(' + wantPort + ' 被占用,已顺延)' : ''))
|
|
647
|
+
resolve(port)
|
|
648
|
+
})
|
|
649
|
+
}
|
|
650
|
+
tryListen(wantPort, 12)
|
|
651
|
+
})
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
async function start() {
|
|
655
|
+
return listen(lanAccess ? '0.0.0.0' : '127.0.0.1')
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function stop() {
|
|
659
|
+
return new Promise((resolve) => {
|
|
660
|
+
if (!server) return resolve()
|
|
661
|
+
try { server.close(() => resolve()) } catch (e) { resolve() }
|
|
662
|
+
try {
|
|
663
|
+
if (typeof server.closeIdleConnections === 'function') server.closeIdleConnections()
|
|
664
|
+
if (typeof server.closeAllConnections === 'function') server.closeAllConnections()
|
|
665
|
+
} catch (_) { }
|
|
666
|
+
server = null
|
|
667
|
+
})
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// 切换局域网监听:要重启监听器,端口可能顺延
|
|
671
|
+
async function setLanAccess(v) {
|
|
672
|
+
const want = !!v
|
|
673
|
+
if (want === lanAccess) return panelState()
|
|
674
|
+
lanAccess = want
|
|
675
|
+
save()
|
|
676
|
+
await stop()
|
|
677
|
+
try { await start() } catch (e) { log('[http] 重新监听失败:' + ((e && e.message) || e)) }
|
|
678
|
+
return panelState()
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function panelState() {
|
|
682
|
+
const t = tunnel ? tunnel.status() : null
|
|
683
|
+
return {
|
|
684
|
+
ok: true,
|
|
685
|
+
name: nodeName,
|
|
686
|
+
version: VERSION,
|
|
687
|
+
port: boundPort || wantPort,
|
|
688
|
+
bind: bindHost,
|
|
689
|
+
lanAccess,
|
|
690
|
+
lan: lanAccess ? lanAddrs() : [],
|
|
691
|
+
lanNamed: lanAccess ? lanList().map((x) => ({ ip: x.ip, iface: x.iface })) : [],
|
|
692
|
+
codes: {
|
|
693
|
+
lan: { code: liveCode('lan'), expiresAt: liveCode('lan') ? codes.lan.exp : 0 },
|
|
694
|
+
wan: { code: liveCode('wan'), expiresAt: liveCode('wan') ? codes.wan.exp : 0 }
|
|
695
|
+
},
|
|
696
|
+
remotePair,
|
|
697
|
+
readOnly,
|
|
698
|
+
tunnel: t,
|
|
699
|
+
tunnelAuto,
|
|
700
|
+
publicUrl: baseUrl(),
|
|
701
|
+
devices: devices.map((d) => ({ id: d.id, label: d.label, at: d.at, exp: d.exp, trusted: !!d.pk })),
|
|
702
|
+
paired: devices.length
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
return {
|
|
707
|
+
start, stop, panelState, newCode, pairLink, revokeDevice, setLanAccess,
|
|
708
|
+
setRemotePair(v) { remotePair = !!v; save(); log('[pair] 异地配对 ' + (remotePair ? '开' : '关')); return remotePair },
|
|
709
|
+
getRemotePair() { return remotePair },
|
|
710
|
+
setReadOnly(v) { readOnly = !!v; save(); log('[mode] 只读 ' + (readOnly ? '开' : '关')); return readOnly },
|
|
711
|
+
getReadOnly() { return readOnly },
|
|
712
|
+
setTunnelAuto(v) { tunnelAuto = !!v; save(); return tunnelAuto },
|
|
713
|
+
getTunnelAuto() { return tunnelAuto },
|
|
714
|
+
getLanAccess() { return lanAccess },
|
|
715
|
+
get port() { return boundPort || wantPort },
|
|
716
|
+
devices() { return devices.slice() }
|
|
717
|
+
}
|
|
718
|
+
}
|