dsh-mobile-ios 0.2.16 → 0.2.18
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/LICENSE +21 -21
- package/README.md +311 -284
- package/cordis.patch.yml +20 -20
- package/entries/plugin.mjs +197 -223
- package/entries/sidecar.mjs +92 -111
- package/lib/client.js +1754 -1621
- package/lib/vendor/qrcode-generator.cjs +2297 -2297
- package/lib/vendor/qrcode-utf8.cjs +26 -26
- package/package.json +3 -2
- package/src/adapter/artifacts.mjs +235 -235
- package/src/adapter/cordis-host.mjs +1444 -1225
- package/src/adapter/mock-host.mjs +498 -430
- package/src/adapter/mux-host.mjs +99 -99
- package/src/adapter/session-history.mjs +241 -241
- package/src/cloudflare.mjs +735 -698
- package/src/dns-label.mjs +32 -32
- package/src/dns-probe.mjs +110 -110
- package/src/file-log.mjs +68 -68
- package/src/gateway.mjs +285 -285
- package/src/host-name.mjs +42 -0
- package/src/pairing.mjs +300 -300
- package/src/protocol.mjs +59 -59
- package/src/provision-local.mjs +883 -560
- package/src/provision-select.mjs +105 -0
- package/src/rest.mjs +958 -894
- package/src/ring.mjs +148 -148
- package/src/server.mjs +246 -246
- package/src/tunnel-error.mjs +91 -0
- package/src/tunnel-state.mjs +122 -0
- package/src/tunnel.mjs +544 -544
- package/src/version.mjs +24 -24
- package/src/ws.mjs +332 -332
- package/src/zone-health.mjs +430 -251
package/src/provision-local.mjs
CHANGED
|
@@ -1,560 +1,883 @@
|
|
|
1
|
-
// provision-local.mjs — 用 cloudflared 自己的证书开通固定地址(本地管理型隧道)
|
|
2
|
-
//
|
|
3
|
-
// 为什么要有这条路:zone 级 API Token 不是谁手边都有,也不该为了一次开通就建一个。
|
|
4
|
-
// `cloudflared tunnel login` 会在本机写一份 zone 范围的 cert.pem;之后 create / route dns
|
|
5
|
-
// 都用它完成,全程不需要我们接触 API Token。
|
|
6
|
-
//
|
|
7
|
-
// 与 token 形态(cloudflare.mjs)的差别只有一个:cloudflared 用 `--config` 指向本地
|
|
8
|
-
// ingress 配置 + credentials 文件,而不是 `TUNNEL_TOKEN` 环境变量。对外接口保持一致:
|
|
9
|
-
// ensure({ port }) → { hostname, url, tunnelId, created }
|
|
10
|
-
// credential({ port }) → { hostname, configFile }
|
|
11
|
-
//
|
|
12
|
-
// 安全边界:
|
|
13
|
-
// · cert.pem 属于 zone 级凭据,绝不复制、绝不外发;这里只检查它存在;
|
|
14
|
-
// · credentials 文件同理,只把**路径**写进配置,不读内容、不进日志;
|
|
15
|
-
// · 配置与状态文件都 0600。
|
|
16
|
-
|
|
17
|
-
import crypto from 'node:crypto';
|
|
18
|
-
import fs from 'node:fs';
|
|
19
|
-
import os from 'node:os';
|
|
20
|
-
import path from 'node:path';
|
|
21
|
-
import { execFile as nodeExecFile } from 'node:child_process';
|
|
22
|
-
import { promisify } from 'node:util';
|
|
23
|
-
import { fail } from './protocol.mjs';
|
|
24
|
-
import { deriveSubdomain, isValidLabel } from './dns-label.mjs';
|
|
25
|
-
import { dnsWarningFor, evaluateDnsAnswer, probeDns, resolveNs } from './dns-probe.mjs';
|
|
26
|
-
import { cnameBelongsTo, readZoneCert } from './zone-health.mjs';
|
|
27
|
-
import { findCloudflared } from './tunnel.mjs';
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
get
|
|
151
|
-
if (this.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
get
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
async #
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
//
|
|
478
|
-
//
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
//
|
|
511
|
-
//
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
1
|
+
// provision-local.mjs — 用 cloudflared 自己的证书开通固定地址(本地管理型隧道)
|
|
2
|
+
//
|
|
3
|
+
// 为什么要有这条路:zone 级 API Token 不是谁手边都有,也不该为了一次开通就建一个。
|
|
4
|
+
// `cloudflared tunnel login` 会在本机写一份 zone 范围的 cert.pem;之后 create / route dns
|
|
5
|
+
// 都用它完成,全程不需要我们接触 API Token。
|
|
6
|
+
//
|
|
7
|
+
// 与 token 形态(cloudflare.mjs)的差别只有一个:cloudflared 用 `--config` 指向本地
|
|
8
|
+
// ingress 配置 + credentials 文件,而不是 `TUNNEL_TOKEN` 环境变量。对外接口保持一致:
|
|
9
|
+
// ensure({ port }) → { hostname, url, tunnelId, created }
|
|
10
|
+
// credential({ port }) → { hostname, configFile }
|
|
11
|
+
//
|
|
12
|
+
// 安全边界:
|
|
13
|
+
// · cert.pem 属于 zone 级凭据,绝不复制、绝不外发;这里只检查它存在;
|
|
14
|
+
// · credentials 文件同理,只把**路径**写进配置,不读内容、不进日志;
|
|
15
|
+
// · 配置与状态文件都 0600。
|
|
16
|
+
|
|
17
|
+
import crypto from 'node:crypto';
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import os from 'node:os';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { execFile as nodeExecFile } from 'node:child_process';
|
|
22
|
+
import { promisify } from 'node:util';
|
|
23
|
+
import { fail } from './protocol.mjs';
|
|
24
|
+
import { deriveSubdomain, isValidLabel } from './dns-label.mjs';
|
|
25
|
+
import { dnsWarningFor, evaluateDnsAnswer, probeDns, resolveNs } from './dns-probe.mjs';
|
|
26
|
+
import { cnameBelongsTo, readZoneCert } from './zone-health.mjs';
|
|
27
|
+
import { findCloudflared } from './tunnel.mjs';
|
|
28
|
+
import { explainTunnelFailure } from './tunnel-error.mjs';
|
|
29
|
+
import { hasLocalCredentials, isForeignState, machineIdentity, readState, writeState } from './tunnel-state.mjs';
|
|
30
|
+
|
|
31
|
+
const execFileAsync = promisify(nodeExecFile);
|
|
32
|
+
const CLI_TIMEOUT_MS = 45_000;
|
|
33
|
+
// 凭据预检的缓存时长:够短(重新 login 后一分钟内生效),够长(不会每次开隧道都打 API)。
|
|
34
|
+
const AUTH_TTL_MS = 120_000;
|
|
35
|
+
|
|
36
|
+
const UUID_PATTERN = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 这条隧道是否还活着(未删除)。
|
|
40
|
+
*
|
|
41
|
+
* 坑:`cloudflared tunnel list --output json` 对**未删除**的隧道给的是 Go 的零值时间
|
|
42
|
+
* `"deleted_at": "0001-01-01T00:00:00Z"`,既不是 null 也不是空串。所以 `!t.deleted_at`
|
|
43
|
+
* 会把账号里每一条活隧道都判成已删除 —— 后果是「按名查找」永远落空,每次开通都去
|
|
44
|
+
* create 然后撞 `tunnel with name already exists`(0.2.12 现场就是这个)。
|
|
45
|
+
* 判定必须同时接受:字段缺失 / null / 空串 / 零值时间。
|
|
46
|
+
*/
|
|
47
|
+
function isLiveTunnel(t) {
|
|
48
|
+
if (!t || !t.id) return false;
|
|
49
|
+
const deleted = t.deleted_at;
|
|
50
|
+
if (!deleted) return true;
|
|
51
|
+
return String(deleted).startsWith('0001-01-01');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 状态读写统一走 tunnel-state.mjs:那里同时负责「这份状态是不是本机的」,
|
|
55
|
+
// 否则跨机拷贝的 tunnel-named.json 会让新机器对外宣称一个指向旧机器的地址。
|
|
56
|
+
|
|
57
|
+
/** cloudflared 的 ingress 配置文件。ports/hostname 变一次就要重写一次。 */
|
|
58
|
+
export function renderConfig({ tunnelId, credentialsFile, hostname, port }) {
|
|
59
|
+
return [
|
|
60
|
+
`# generated by dsh-mobile — 端口变化会重写本文件;不要手改`,
|
|
61
|
+
`tunnel: ${tunnelId}`,
|
|
62
|
+
`credentials-file: ${credentialsFile}`,
|
|
63
|
+
'',
|
|
64
|
+
'ingress:',
|
|
65
|
+
` - hostname: ${hostname}`,
|
|
66
|
+
` service: http://127.0.0.1:${port}`,
|
|
67
|
+
' - service: http_status:404',
|
|
68
|
+
'',
|
|
69
|
+
].join('\n');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* zone 诊断结果的**展示副本**:只留结论与 NS 名字。
|
|
74
|
+
*
|
|
75
|
+
* zoneId / accountId 这类内部标识一律不落状态文件、不进面板——
|
|
76
|
+
* 面板只需要知道「归谁、对不对」,不需要也不该拿到账号坐标。
|
|
77
|
+
*/
|
|
78
|
+
export function sanitizeZone(zone) {
|
|
79
|
+
if (!zone || typeof zone !== 'object') return null;
|
|
80
|
+
const list = (v) => (Array.isArray(v) ? v.map((x) => String(x).toLowerCase()).filter(Boolean).slice(0, 4) : []);
|
|
81
|
+
return {
|
|
82
|
+
code: zone.code || 'unknown',
|
|
83
|
+
status: zone.status || null,
|
|
84
|
+
expectedNs: list(zone.expectedNs),
|
|
85
|
+
publicNs: list(zone.publicNs),
|
|
86
|
+
zoneName: zone.zoneName || null,
|
|
87
|
+
accountName: zone.accountName || null,
|
|
88
|
+
checkedAt: new Date().toISOString(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class LocalProvisioner {
|
|
93
|
+
constructor({
|
|
94
|
+
baseDomain = 'matrixboard.cn',
|
|
95
|
+
prefix = 'dsh',
|
|
96
|
+
executable = 'cloudflared',
|
|
97
|
+
stateFile = null,
|
|
98
|
+
configFile = null,
|
|
99
|
+
seed = null,
|
|
100
|
+
homeDir = os.homedir(),
|
|
101
|
+
log = () => {},
|
|
102
|
+
run = null,
|
|
103
|
+
// 可注入:解析 cloudflared 时用的环境(PATH / HOME)。测试必须能隔离真实 PATH。
|
|
104
|
+
env = process.env,
|
|
105
|
+
// 可注入:测试里不该真发 DNS 查询(会等 NXDOMAIN 重试,还依赖外网)
|
|
106
|
+
probe = null,
|
|
107
|
+
// 可注入:解析失败时进一步问「这个域名现在归哪个 Cloudflare 账号」。
|
|
108
|
+
// 不注入就不诊断(测试/离线场景保持零网络依赖);生产由 createProvisioner 注入。
|
|
109
|
+
zoneDiagnose = null,
|
|
110
|
+
// 可注入:开通前查这条 hostname 现在指向哪条隧道,避免多机互相覆盖。
|
|
111
|
+
ownerLookup = null,
|
|
112
|
+
// 可注入:开通前预检「这本 cert.pem 能不能写这个域名的 DNS」。
|
|
113
|
+
// 不注入就不预检(测试/离线保持零网络依赖);生产由 createProvisioner 注入。
|
|
114
|
+
verifyAccess = null,
|
|
115
|
+
// 可注入:本机主机名(只用于状态里记录机器身份,便于排障时看出「拷来的状态」)
|
|
116
|
+
hostname = null,
|
|
117
|
+
} = {}) {
|
|
118
|
+
this.baseDomain = String(baseDomain).replace(/^\./, '').toLowerCase();
|
|
119
|
+
this.prefix = prefix;
|
|
120
|
+
this.executable = executable;
|
|
121
|
+
this.stateFile = stateFile;
|
|
122
|
+
this.configFile = configFile || path.join(path.dirname(stateFile || path.join(homeDir, 'x')), 'tunnel-config.yml');
|
|
123
|
+
this.seed = seed;
|
|
124
|
+
this.homeDir = homeDir;
|
|
125
|
+
this.env = env;
|
|
126
|
+
this.log = log;
|
|
127
|
+
this._state = undefined;
|
|
128
|
+
this._machine = undefined;
|
|
129
|
+
this._auth = null; // { at, fp, verdict } —— 凭据预检结果缓存(不含 token)
|
|
130
|
+
this.hostnameHint = hostname;
|
|
131
|
+
// 可注入,测试里不必真起 cloudflared
|
|
132
|
+
this.run = run || this.#exec;
|
|
133
|
+
this.probe = probe || probeDns;
|
|
134
|
+
this.zoneDiagnose = zoneDiagnose;
|
|
135
|
+
this.ownerLookup = ownerLookup;
|
|
136
|
+
this.verifyAccess = verifyAccess;
|
|
137
|
+
this._zone = null; // 最近一次 zone 诊断结论(不含凭据)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get kind() {
|
|
141
|
+
return 'local';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get state() {
|
|
145
|
+
if (this._state === undefined) this._state = readState(this.stateFile, this.log);
|
|
146
|
+
return this._state;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** 本机身份(首次调用会生成 machine-id);目录不可写时为 null。 */
|
|
150
|
+
get machine() {
|
|
151
|
+
if (this._machine === undefined) {
|
|
152
|
+
try {
|
|
153
|
+
this._machine = machineIdentity({ stateFile: this.stateFile, hostname: this.hostnameHint });
|
|
154
|
+
} catch {
|
|
155
|
+
this._machine = null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return this._machine;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get configured() {
|
|
162
|
+
// 本地形态只要证书在就算可开通;已开通则要配置与凭据都在
|
|
163
|
+
if (this.state?.configFile) return true;
|
|
164
|
+
return fs.existsSync(path.join(this.homeDir, '.cloudflared', 'cert.pem'));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 最近一次凭据预检结论(面板展示用;未预检过为 null)。不含 token。 */
|
|
168
|
+
get credentials() {
|
|
169
|
+
if (!this._auth?.verdict) return null;
|
|
170
|
+
return this.#authSnapshot(this._auth.verdict);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
#authSnapshot(verdict) {
|
|
174
|
+
if (!verdict) return null;
|
|
175
|
+
return {
|
|
176
|
+
state: verdict.state || 'unknown',
|
|
177
|
+
blocking: Boolean(verdict.blocking),
|
|
178
|
+
hint: verdict.hint ?? null,
|
|
179
|
+
accountName: verdict.accountName ?? null,
|
|
180
|
+
zoneName: verdict.zoneName ?? null,
|
|
181
|
+
zoneStatus: verdict.zoneStatus ?? null,
|
|
182
|
+
checkedAt: this._auth?.at ? new Date(this._auth.at).toISOString() : null,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#certFingerprint() {
|
|
187
|
+
const file = path.join(this.homeDir, '.cloudflared', 'cert.pem');
|
|
188
|
+
try {
|
|
189
|
+
const st = fs.statSync(file);
|
|
190
|
+
return `${st.size}:${Math.round(st.mtimeMs)}`;
|
|
191
|
+
} catch {
|
|
192
|
+
return 'none';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 凭据预检:当前 cert.pem 能不能管理 baseDomain。
|
|
198
|
+
*
|
|
199
|
+
* 只在**要写 Cloudflare** 的路径上作为硬门槛;日常启动命中缓存时只用于提示,
|
|
200
|
+
* 绝不因为「账号对不上」去拦一个本来能跑的隧道(cloudflared 运行时只需要
|
|
201
|
+
* credentials 文件,不需要 cert.pem)。
|
|
202
|
+
*/
|
|
203
|
+
async checkCredentials({ force = false } = {}) {
|
|
204
|
+
if (typeof this.verifyAccess !== 'function') {
|
|
205
|
+
return { state: 'unknown', blocking: false, hint: null, accountName: null, checkedAt: null };
|
|
206
|
+
}
|
|
207
|
+
const fp = this.#certFingerprint();
|
|
208
|
+
const now = Date.now();
|
|
209
|
+
if (!force && this._auth && this._auth.fp === fp && now - this._auth.at < AUTH_TTL_MS) {
|
|
210
|
+
return this.#authSnapshot(this._auth.verdict);
|
|
211
|
+
}
|
|
212
|
+
let verdict = null;
|
|
213
|
+
try {
|
|
214
|
+
verdict = await this.verifyAccess({ homeDir: this.homeDir, baseDomain: this.baseDomain });
|
|
215
|
+
} catch (err) {
|
|
216
|
+
verdict = { state: 'unknown', blocking: false, hint: null, detail: err?.message || String(err) };
|
|
217
|
+
}
|
|
218
|
+
if (!verdict || typeof verdict !== 'object') verdict = { state: 'unknown', blocking: false, hint: null };
|
|
219
|
+
this._auth = { at: now, fp, verdict };
|
|
220
|
+
if (verdict.blocking) this.log(`tunnel 凭据预检未通过(${verdict.state}):${verdict.hint || ''}`);
|
|
221
|
+
return this.#authSnapshot(verdict);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** 凭据不可用时抛出的统一错误(带可执行修法)。 */
|
|
225
|
+
#credentialError(verdict) {
|
|
226
|
+
const hint = verdict?.hint || '当前登录的 Cloudflare 账号无法管理这个域名';
|
|
227
|
+
const exe = findCloudflared(this.executable, this.env) || findCloudflared('auto', this.env) || this.executable;
|
|
228
|
+
const account = verdict?.accountName ? `(当前证书属于 ${verdict.accountName})` : '';
|
|
229
|
+
return fail(4021, `${hint}${account}`, {
|
|
230
|
+
detail: `在这台电脑的终端执行:${exe} tunnel login,`
|
|
231
|
+
+ `在浏览器里选择持有 ${this.baseDomain} 的账号完成授权(会覆盖 ~/.cloudflared/cert.pem),`
|
|
232
|
+
+ '然后回到面板重新点「开启远程」。重装插件、重启宿主、改 NS 都不能替代这一步。',
|
|
233
|
+
reason: 'credentials',
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
get notConfiguredMessage() {
|
|
238
|
+
return '主机还没有登录 Cloudflare';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
get notConfiguredDetail() {
|
|
242
|
+
const exe = findCloudflared(this.executable, this.env) || findCloudflared('auto', this.env) || this.executable;
|
|
243
|
+
return `在这台电脑的终端执行:${exe} tunnel login(浏览器里选 ${this.baseDomain} 授权)`;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 安装完成后回填刚下载的可执行文件路径。
|
|
248
|
+
*
|
|
249
|
+
* 必要性:插件启动那一刻就决定了本实例用哪个 executable,而「自动安装」发生在启动
|
|
250
|
+
* 之后。新机器(尤其 Windows)上 PATH 里没有 cloudflared,回填前开通会在
|
|
251
|
+
* `execFile('cloudflared.exe')` 直接 ENOENT —— 用户看到的是「装好了但开通失败」。
|
|
252
|
+
*/
|
|
253
|
+
useExecutable(executable) {
|
|
254
|
+
if (executable) this.executable = executable;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 解析本次真正要执行的 cloudflared。
|
|
259
|
+
*
|
|
260
|
+
* 用发现链而不是信任构造参数:安装落点(组件目录)并不在 PATH 里,裸名字在 Windows
|
|
261
|
+
* 上会直接 ENOENT,在 macOS 上则要依赖用户 brew 装过。发现链已经把三处都覆盖了。
|
|
262
|
+
*/
|
|
263
|
+
#resolveExecutable() {
|
|
264
|
+
const found = findCloudflared(this.executable, this.env) || findCloudflared('auto', this.env);
|
|
265
|
+
if (!found) {
|
|
266
|
+
throw fail(4021, '主机未安装 cloudflared,无法开通固定地址', {
|
|
267
|
+
detail: process.platform === 'win32'
|
|
268
|
+
? '在面板点「安装 cloudflared 并开启远程」自动下载,或手动安装后把目录加入 PATH'
|
|
269
|
+
: '执行 `brew install cloudflared`,或设置 CLOUDFLARED_BIN 指向可执行文件',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return found;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** 公网当前 NS(查询失败就当没有:少一句提示不该让整条诊断崩掉)。 */
|
|
276
|
+
async #publicNs() {
|
|
277
|
+
try {
|
|
278
|
+
return await resolveNs(this.baseDomain);
|
|
279
|
+
} catch {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* 解析自检 + (失败时)zone 归因。
|
|
286
|
+
*
|
|
287
|
+
* 只把「解析不到」当作需要归因的信号:解析成功时多问一次 Cloudflare 只是浪费
|
|
288
|
+
* 一次往返,而失败时那句笼统的「pending」正是把人带偏的根源——域名可能已经被
|
|
289
|
+
* 另一个 Cloudflare 账号接管(zone moved),改 NS、重装、重启都不可能修好。
|
|
290
|
+
*/
|
|
291
|
+
async #evaluate(hostname, tunnelId) {
|
|
292
|
+
const verdict = evaluateDnsAnswer(await this.probe(hostname), tunnelId);
|
|
293
|
+
if (verdict.ok || typeof this.zoneDiagnose !== 'function') {
|
|
294
|
+
this._zone = null; // 通了就别留着上一次的故障结论
|
|
295
|
+
return { verdict, zone: null };
|
|
296
|
+
}
|
|
297
|
+
let zone = null;
|
|
298
|
+
try {
|
|
299
|
+
zone = sanitizeZone(await this.zoneDiagnose({
|
|
300
|
+
homeDir: this.homeDir,
|
|
301
|
+
baseDomain: this.baseDomain,
|
|
302
|
+
publicNs: await this.#publicNs(),
|
|
303
|
+
dnsOk: false,
|
|
304
|
+
}));
|
|
305
|
+
} catch {
|
|
306
|
+
zone = null; // 「不知道」比「猜一个」诚实
|
|
307
|
+
}
|
|
308
|
+
this._zone = zone;
|
|
309
|
+
return { verdict, zone };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
status() {
|
|
313
|
+
const s = this.state;
|
|
314
|
+
// credentials 是「预检结论」,未预检过就是 null——面板据此决定要不要提示
|
|
315
|
+
// 「账号对不上」。它不是开通状态的替代品:隧道能跑 ≠ 能改写 DNS。
|
|
316
|
+
const credentials = this.credentials;
|
|
317
|
+
if (!s) return { kind: 'local', provisioned: false, hostname: null, url: null, tunnelId: null, credentials };
|
|
318
|
+
return {
|
|
319
|
+
kind: 'local',
|
|
320
|
+
provisioned: true,
|
|
321
|
+
hostname: s.hostname,
|
|
322
|
+
url: `https://${s.hostname}`,
|
|
323
|
+
tunnelId: s.tunnelId,
|
|
324
|
+
port: s.port ?? null,
|
|
325
|
+
// null = 还没验过(老状态文件);false = 验过但公网没有——面板必须提示,别让人扫码扫到空气
|
|
326
|
+
dnsOk: s.dnsOk ?? null,
|
|
327
|
+
dnsCheckedAt: s.dnsCheckedAt ?? null,
|
|
328
|
+
// 失败原因归到 zone 层(moved / pending / ns-mismatch / unresolved),
|
|
329
|
+
// 面板据此给出**不同**的修法,而不是一律「等 NS 生效」。
|
|
330
|
+
zone: s.zone ?? this._zone ?? null,
|
|
331
|
+
warning: dnsWarningFor(s),
|
|
332
|
+
credentials,
|
|
333
|
+
createdAt: s.createdAt ?? null,
|
|
334
|
+
updatedAt: s.updatedAt ?? null,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 面板「重新检测解析」:强制重探一次并写回状态,不做任何缓存短路。
|
|
340
|
+
*
|
|
341
|
+
* 为什么必须有这条路:dnsOk=false 是持久化结论,而面板在 false 时禁用了
|
|
342
|
+
* 「开启远程」按钮——原来唯一的重探入口就在 ensure() 里,按钮一点就点不到,
|
|
343
|
+
* 于是 NS 改好了也永远停在「解析异常」,只能删状态文件才恢复(自锁死)。
|
|
344
|
+
*/
|
|
345
|
+
async recheckDns() {
|
|
346
|
+
// 顺手强制刷一次凭据预检:用户改完账号跑 login 后,面板点「重新检测」就应
|
|
347
|
+
// 立刻看到结论变化(cert.pem 指纹变了会自动失效缓存,这里再加一层强制)。
|
|
348
|
+
const credentials = await this.checkCredentials({ force: true });
|
|
349
|
+
const s = this.state;
|
|
350
|
+
if (!s?.hostname) return { provisioned: false, ok: false, tampered: false, warning: null, publicNs: [], zone: null, credentials };
|
|
351
|
+
const { verdict, zone } = await this.#evaluate(s.hostname, s.tunnelId);
|
|
352
|
+
const next = {
|
|
353
|
+
...s,
|
|
354
|
+
dnsOk: verdict.ok,
|
|
355
|
+
dnsTampered: verdict.tampered,
|
|
356
|
+
dnsCheckedAt: new Date().toISOString(),
|
|
357
|
+
zone,
|
|
358
|
+
};
|
|
359
|
+
this._state = next;
|
|
360
|
+
writeState(this.stateFile, next);
|
|
361
|
+
return {
|
|
362
|
+
provisioned: true,
|
|
363
|
+
hostname: next.hostname,
|
|
364
|
+
ok: Boolean(verdict.ok),
|
|
365
|
+
tampered: Boolean(verdict.tampered),
|
|
366
|
+
expected: verdict.expected ?? null,
|
|
367
|
+
target: verdict.target ?? null,
|
|
368
|
+
warning: dnsWarningFor(next),
|
|
369
|
+
checkedAt: next.dnsCheckedAt,
|
|
370
|
+
zone,
|
|
371
|
+
credentials,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* 清空本机的固定地址状态(面板「重置本机隧道状态」)。
|
|
377
|
+
*
|
|
378
|
+
* 用途:状态文件被跨机拷贝、或结构损坏到无法自愈时,给用户一条不用手改文件系统的出路。
|
|
379
|
+
* 边界(刻意保守):
|
|
380
|
+
* · 只删**本模块自己写的**两个文件(状态 + ingress 配置),不碰 cert.pem;
|
|
381
|
+
* · 不删 Cloudflare 上的隧道与 DNS 记录——那是用户账号资产,删了不可恢复;
|
|
382
|
+
* · 幂等:反复调用都返回成功,不会因为文件已不在而报错。
|
|
383
|
+
*/
|
|
384
|
+
async reset() {
|
|
385
|
+
const removed = [];
|
|
386
|
+
const targets = [this.stateFile, this.state?.configFile || this.configFile];
|
|
387
|
+
for (const file of targets) {
|
|
388
|
+
if (!file) continue;
|
|
389
|
+
try {
|
|
390
|
+
if (fs.statSync(file).isFile()) {
|
|
391
|
+
fs.unlinkSync(file);
|
|
392
|
+
removed.push(path.basename(file));
|
|
393
|
+
}
|
|
394
|
+
} catch {
|
|
395
|
+
/* 不存在即目标状态 */
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const hadState = Boolean(this.state?.hostname);
|
|
399
|
+
if (hadState) {
|
|
400
|
+
this.log(`tunnel 已重置本机固定地址状态(原地址 ${this.state.hostname},Cloudflare 侧的隧道与记录未删除)`);
|
|
401
|
+
}
|
|
402
|
+
this._state = null;
|
|
403
|
+
this._auth = null;
|
|
404
|
+
this._zone = null;
|
|
405
|
+
return { reset: true, hadState, removed, hostname: null, provisioned: false };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async #exec(args) {
|
|
409
|
+
const { stdout, stderr } = await execFileAsync(this.#resolveExecutable(), args, {
|
|
410
|
+
timeout: CLI_TIMEOUT_MS,
|
|
411
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
412
|
+
env: process.env,
|
|
413
|
+
});
|
|
414
|
+
return `${stdout || ''}${stderr || ''}`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async #assertLogin() {
|
|
418
|
+
const cert = path.join(this.homeDir, '.cloudflared', 'cert.pem');
|
|
419
|
+
if (!fs.existsSync(cert)) throw fail(4021, this.notConfiguredMessage, { detail: this.notConfiguredDetail });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** 当前授权账号下的隧道列表;拿不到就返回 null(调用方必须当「未知」处理,不能当「没有」)。 */
|
|
423
|
+
async #listTunnels() {
|
|
424
|
+
let raw;
|
|
425
|
+
try {
|
|
426
|
+
raw = await this.run(['tunnel', 'list', '--output', 'json']);
|
|
427
|
+
} catch {
|
|
428
|
+
return null; // 老版本不支持 --output,或网络/凭据问题;交给 create 的报错去说明
|
|
429
|
+
}
|
|
430
|
+
const start = raw.indexOf('[');
|
|
431
|
+
if (start < 0) return null;
|
|
432
|
+
try {
|
|
433
|
+
const list = JSON.parse(raw.slice(start));
|
|
434
|
+
return Array.isArray(list) ? list : null;
|
|
435
|
+
} catch {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
async #findTunnelByName(label) {
|
|
441
|
+
const list = await this.#listTunnels();
|
|
442
|
+
if (!list) return null; // 老版本不支持 --output;交给 create 的报错去说明
|
|
443
|
+
const hit = list.find((t) => isLiveTunnel(t) && t.name === label);
|
|
444
|
+
return hit?.id ? { id: hit.id } : null;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* 这条 tunnel 是否还在当前授权账号里。
|
|
449
|
+
* true / false 之外还有 null(查不到)——null 必须当作「可能还在」,别因为一次网络抖动
|
|
450
|
+
* 就把用户正常的隧道判死重建。返回 undefined 表示根本没 id 可查。
|
|
451
|
+
*/
|
|
452
|
+
async #tunnelInAccount(tunnelId) {
|
|
453
|
+
if (!tunnelId) return undefined;
|
|
454
|
+
const list = await this.#listTunnels();
|
|
455
|
+
if (!list) return null;
|
|
456
|
+
return list.some((t) => isLiveTunnel(t) && t.id === tunnelId);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** 状态里记的地址是否仍属当前域名(运营换 baseDomain 后旧地址要重写)。 */
|
|
460
|
+
#hostnameBelongs(hostname) {
|
|
461
|
+
const h = String(hostname || '').toLowerCase();
|
|
462
|
+
return h.endsWith(`.${this.baseDomain}`) && h.length > this.baseDomain.length + 1;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** 写状态时顺带记下本机身份:下次从别处拷来的状态就能被识别出来。 */
|
|
466
|
+
#withMachine(state) {
|
|
467
|
+
const m = this.machine;
|
|
468
|
+
if (!m) return state;
|
|
469
|
+
const prev = state?.machine;
|
|
470
|
+
if (prev?.id === m.id && prev?.hostname === m.hostname) return state;
|
|
471
|
+
return { ...state, machine: { id: m.id, hostname: m.hostname } };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async ensure({ port, force = false } = {}) {
|
|
475
|
+
if (!Number.isInteger(port) || port <= 0) throw fail(4400, '开通隧道需要有效端口');
|
|
476
|
+
const account = readZoneCert({ homeDir: this.homeDir })?.accountId || null;
|
|
477
|
+
// 记下进入本次调用前的地址:跨机状态/凭据缺失会把 cached 清空,
|
|
478
|
+
// 用这个变量才能如实回答「地址有没有变」(changed 供调用方记日志/判断漂移)。
|
|
479
|
+
const previousHostname = this.state?.hostname || null;
|
|
480
|
+
let cached = this.state;
|
|
481
|
+
let rebuild = false;
|
|
482
|
+
|
|
483
|
+
// ── 0) 状态归属校验(跨机拷贝是「分发后分配不出地址」的第二大来源)──
|
|
484
|
+
// · machine.id 不是本机 → 整份作废,重新分配地址(不能对外宣称别人的地址);
|
|
485
|
+
// · tunnel 凭据文件不在了 → 状态在本机跑不起来,同样重新分配。
|
|
486
|
+
if (cached && isForeignState(cached, this.machine)) {
|
|
487
|
+
this.log(`tunnel 状态来自另一台电脑(${String(cached.machine?.id || '').slice(0, 8)}… ≠ ${String(this.machine?.id || '').slice(0, 8)}…),重新分配固定地址`);
|
|
488
|
+
cached = null;
|
|
489
|
+
} else if (cached?.tunnelId && !hasLocalCredentials(cached)) {
|
|
490
|
+
this.log('tunnel 状态里的 tunnel 凭据文件已不存在,重新分配固定地址');
|
|
491
|
+
cached = null;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// 域名变更(运营换 baseDomain):子域可沿用,但要按新域名重写地址与记录
|
|
495
|
+
if (cached?.hostname && !this.#hostnameBelongs(cached.hostname)) {
|
|
496
|
+
if (cached.subdomain && isValidLabel(cached.subdomain)) {
|
|
497
|
+
this.log(`tunnel 记录的地址 ${cached.hostname} 不属于当前域名 ${this.baseDomain},按原前缀重写`);
|
|
498
|
+
cached = { ...cached, hostname: `${cached.subdomain}.${this.baseDomain}`, dnsOk: null, zone: null };
|
|
499
|
+
rebuild = true;
|
|
500
|
+
} else {
|
|
501
|
+
this.log('tunnel 记录的地址与当前域名不符且前缀不可用,重新分配');
|
|
502
|
+
cached = null;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// ── 1) 账号可能变过(域名迁到另一个 Cloudflare 账号后重新 login 就是这种情况)──
|
|
507
|
+
// 旧 tunnel 属于上一个账号,继续拿它的 id 去 route dns 只会得到 "tunnel not found",
|
|
508
|
+
// 或者更糟——静默写不进去却以为自己开通成功。真判定有两条线:
|
|
509
|
+
// 1) 状态文件记了 account 且与当前 cert 不一致 → 确知换了账号;
|
|
510
|
+
// 2) 没记(0.2.11 之前的状态文件没有这个字段)→ 直接问 Cloudflare 这条 tunnel
|
|
511
|
+
// 还在不在当前账号(`tunnel list --output json`)。
|
|
512
|
+
// 注意线 2) 只在「不知道归属」时才走:两种情况都清楚了还去拉子进程,会让面板每次
|
|
513
|
+
// 点开通都多几百毫秒(tunnel-named 里「重复开通不再调 CLI」这条契约就是拦这个的)。
|
|
514
|
+
// 账号变了就当新装:重建隧道、保留同一个子域(地址不变,用户不用重新记/重新扫码)。
|
|
515
|
+
if (cached?.tunnelId) {
|
|
516
|
+
const knownMismatch = Boolean(cached.account && account && cached.account !== account);
|
|
517
|
+
// 只有「当前证书能读出账号,但状态文件没记」才算归属未知。反过来若连证书都解析
|
|
518
|
+
// 不出账号(cert.pem 被换过/格式不同),那属于凭据异常,此时去 list 再拿不到就
|
|
519
|
+
// 判重建会变成反复重建隧道 —— 比保留旧 id 危险得多,所以这种情况直接信任缓存。
|
|
520
|
+
const unknownOwner = Boolean(account) && !cached.account;
|
|
521
|
+
const alive = knownMismatch
|
|
522
|
+
? false
|
|
523
|
+
: unknownOwner ? await this.#tunnelInAccount(cached.tunnelId) : true;
|
|
524
|
+
if (knownMismatch || alive === false) {
|
|
525
|
+
this.log(knownMismatch
|
|
526
|
+
? `tunnel 授权账号已变更(${String(cached.account).slice(0, 8)}… → ${String(account).slice(0, 8)}…),重建隧道`
|
|
527
|
+
: `tunnel ${String(cached.tunnelId).slice(0, 8)}… 不在当前授权账号里,重建隧道`);
|
|
528
|
+
rebuild = true;
|
|
529
|
+
cached = {
|
|
530
|
+
...cached,
|
|
531
|
+
account,
|
|
532
|
+
tunnelId: null,
|
|
533
|
+
credentialsFile: null,
|
|
534
|
+
configFile: null,
|
|
535
|
+
dnsOk: null,
|
|
536
|
+
dnsTampered: false,
|
|
537
|
+
zone: null,
|
|
538
|
+
};
|
|
539
|
+
} else if (alive === true && cached.account !== account) {
|
|
540
|
+
// 校验通过:把归属记下来。否则每次开通都因为「不知道归谁」再问一遍 Cloudflare,
|
|
541
|
+
// 白白多一个子进程的延迟(这条路径就是给老状态文件补账的)。
|
|
542
|
+
cached = { ...cached, account };
|
|
543
|
+
this._state = this.#withMachine(cached);
|
|
544
|
+
writeState(this.stateFile, this._state);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// 走完整开通:缓存里的 port/hostname 看着都可用,但它们描述的是上一个账号的隧道,
|
|
548
|
+
// 跳过缓存才不会「解析通了就以为没事」。
|
|
549
|
+
if (!force && !rebuild && cached?.hostname && cached.port === port) {
|
|
550
|
+
// 老状态文件没有 machine 字段:命中缓存时顺手认领(一次性,之后就是本机状态)
|
|
551
|
+
if (!cached.machine && this.machine) {
|
|
552
|
+
cached = this.#withMachine(cached);
|
|
553
|
+
this._state = cached;
|
|
554
|
+
writeState(this.stateFile, cached);
|
|
555
|
+
}
|
|
556
|
+
// 与 BaseProvisioner 同策略:没确认过就现场验一次(含防篡改评估)
|
|
557
|
+
if (cached.dnsOk !== true) {
|
|
558
|
+
const { verdict, zone } = await this.#evaluate(cached.hostname, cached.tunnelId);
|
|
559
|
+
const next = this.#withMachine({
|
|
560
|
+
...cached,
|
|
561
|
+
dnsOk: verdict.ok,
|
|
562
|
+
dnsTampered: verdict.tampered,
|
|
563
|
+
dnsCheckedAt: new Date().toISOString(),
|
|
564
|
+
zone,
|
|
565
|
+
});
|
|
566
|
+
this._state = next;
|
|
567
|
+
writeState(this.stateFile, next);
|
|
568
|
+
return {
|
|
569
|
+
hostname: next.hostname,
|
|
570
|
+
url: `https://${next.hostname}`,
|
|
571
|
+
tunnelId: next.tunnelId,
|
|
572
|
+
created: false,
|
|
573
|
+
changed: false,
|
|
574
|
+
dnsOk: next.dnsOk,
|
|
575
|
+
zone,
|
|
576
|
+
warning: dnsWarningFor(next),
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
return {
|
|
580
|
+
hostname: cached.hostname,
|
|
581
|
+
url: `https://${cached.hostname}`,
|
|
582
|
+
tunnelId: cached.tunnelId,
|
|
583
|
+
created: false,
|
|
584
|
+
changed: false,
|
|
585
|
+
dnsOk: cached.dnsOk ?? null,
|
|
586
|
+
warning: dnsWarningFor(cached),
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
await this.#assertLogin();
|
|
590
|
+
|
|
591
|
+
// 端口顺延:tunnel 与 DNS 都不用动,只重写本地 ingress 配置。
|
|
592
|
+
// 不走这一步就会为了换个端口重新 route dns(多余的一次 CF 写入)。
|
|
593
|
+
if (!force && cached?.tunnelId && cached.hostname && cached.credentialsFile) {
|
|
594
|
+
fs.mkdirSync(path.dirname(this.configFile), { recursive: true, mode: 0o700 });
|
|
595
|
+
fs.writeFileSync(this.configFile, renderConfig({
|
|
596
|
+
tunnelId: cached.tunnelId,
|
|
597
|
+
credentialsFile: cached.credentialsFile,
|
|
598
|
+
hostname: cached.hostname,
|
|
599
|
+
port,
|
|
600
|
+
}), { mode: 0o600 });
|
|
601
|
+
const next = this.#withMachine({ ...cached, port, updatedAt: new Date().toISOString() });
|
|
602
|
+
this._state = next;
|
|
603
|
+
writeState(this.stateFile, next);
|
|
604
|
+
return {
|
|
605
|
+
hostname: next.hostname,
|
|
606
|
+
url: `https://${next.hostname}`,
|
|
607
|
+
tunnelId: next.tunnelId,
|
|
608
|
+
created: false,
|
|
609
|
+
changed: false,
|
|
610
|
+
dnsOk: next.dnsOk ?? null,
|
|
611
|
+
warning: dnsWarningFor(next),
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// ── 以下每一步都要写 Cloudflare:先在本地把凭据问清楚 ──
|
|
616
|
+
// 这一步就是 2026-11-21 事故的正解:跨账号的 cert.pem 能列/建隧道,只有写 DNS 才失败,
|
|
617
|
+
// 等 CLI 报错时用户已经拿到「隧道正常」的假象。预检把失败提前到**任何写入之前**,
|
|
618
|
+
// 并直接说清「用哪个账号重跑 login」。网络不可达时结论是 unknown,不拦(降级原则)。
|
|
619
|
+
const auth = await this.checkCredentials();
|
|
620
|
+
if (auth.blocking) throw this.#credentialError(auth);
|
|
621
|
+
|
|
622
|
+
const installationId = cached?.installationId || crypto.randomBytes(16).toString('hex');
|
|
623
|
+
const label = cached?.subdomain || deriveSubdomain(this.seed || installationId, { prefix: this.prefix });
|
|
624
|
+
if (!isValidLabel(label)) throw fail(4400, `派生出的子域不合法:${label}`);
|
|
625
|
+
const hostname = `${label}.${this.baseDomain}`;
|
|
626
|
+
|
|
627
|
+
let tunnelId = cached?.tunnelId || null;
|
|
628
|
+
let created = false;
|
|
629
|
+
if (!tunnelId) {
|
|
630
|
+
const found = await this.#findTunnelByName(label);
|
|
631
|
+
if (found) {
|
|
632
|
+
tunnelId = found.id;
|
|
633
|
+
} else {
|
|
634
|
+
let out;
|
|
635
|
+
try {
|
|
636
|
+
out = await this.run(['tunnel', 'create', label]);
|
|
637
|
+
} catch (err) {
|
|
638
|
+
// 建隧道也会因为凭据/账号问题失败:同样把真实原因透传出来,不要只留一行命令回显
|
|
639
|
+
const explained = explainTunnelFailure(err, {
|
|
640
|
+
baseDomain: this.baseDomain,
|
|
641
|
+
operation: 'create-tunnel',
|
|
642
|
+
accountName: auth.accountName || null,
|
|
643
|
+
exe: this.#exeLabel(),
|
|
644
|
+
});
|
|
645
|
+
this.log(`tunnel 创建隧道失败 ${explained.reason} ${explained.message}`);
|
|
646
|
+
throw fail(4500, explained.message, {
|
|
647
|
+
detail: explained.detail,
|
|
648
|
+
reason: explained.reason,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
const m = UUID_PATTERN.exec(out);
|
|
652
|
+
if (!m) throw fail(4500, 'cloudflared 没有返回 tunnel id', { detail: String(out).slice(-300) });
|
|
653
|
+
tunnelId = m[1];
|
|
654
|
+
created = true;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
const credentialsFile = path.join(this.homeDir, '.cloudflared', `${tunnelId}.json`);
|
|
659
|
+
if (!fs.existsSync(credentialsFile)) {
|
|
660
|
+
throw fail(4500, '找不到 tunnel 凭据文件', {
|
|
661
|
+
detail: `期望在 ${path.basename(credentialsFile)};重新执行 cloudflared tunnel create ${label}`,
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// 多机共用同一个 Cloudflare 账号时,`--overwrite-dns` 会**静默**把别人的地址抢走:
|
|
666
|
+
// A 机本来能用,B 机一开通 A 机就断,两边面板却都显示「成功」。
|
|
667
|
+
// 有凭据就先看这条 hostname 现在归谁,抢址直接报错,绝不静默覆盖。
|
|
668
|
+
if (typeof this.ownerLookup === 'function') {
|
|
669
|
+
let owner = null;
|
|
670
|
+
try {
|
|
671
|
+
owner = await this.ownerLookup({ homeDir: this.homeDir, baseDomain: this.baseDomain, hostname });
|
|
672
|
+
} catch {
|
|
673
|
+
owner = null; // 查不到归属时退回旧行为,别让诊断把开通卡死
|
|
674
|
+
}
|
|
675
|
+
if (owner && !cnameBelongsTo(owner, tunnelId)) {
|
|
676
|
+
this.log(`tunnel 拒绝覆盖 ${hostname}:当前指向 ${owner},本机隧道 ${tunnelId}`);
|
|
677
|
+
throw fail(4021, `固定地址 ${hostname} 已被另一条隧道占用`, {
|
|
678
|
+
detail: `该地址当前指向 ${owner}。通常是另一台电脑用了同一份安装标识(或状态文件被复制)。`
|
|
679
|
+
+ '本机已停止覆盖它:请在那台设备上重新开通以换一个地址,或先删掉这条 DNS 记录再重试。',
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// --overwrite-dns:重复开通时把记录改到当前 tunnel,而不是报「已存在」
|
|
685
|
+
try {
|
|
686
|
+
await this.run(['tunnel', 'route', 'dns', '--overwrite-dns', label, hostname]);
|
|
687
|
+
} catch (err) {
|
|
688
|
+
// 关键修复:不再 `split('\n')[0]`。真实原因在第二行
|
|
689
|
+
// (`Failed to add route: code: 10000, reason: Authentication error`),
|
|
690
|
+
// 旧代码把它丢掉,只留下 `Command failed: …` 的命令回显,患者无从下手。
|
|
691
|
+
const explained = explainTunnelFailure(err, {
|
|
692
|
+
baseDomain: this.baseDomain,
|
|
693
|
+
operation: 'route-dns',
|
|
694
|
+
accountName: auth.accountName || null,
|
|
695
|
+
exe: this.#exeLabel(),
|
|
696
|
+
});
|
|
697
|
+
this.log(`tunnel 写 DNS 失败 ${explained.reason}${explained.code ? ` code=${explained.code}` : ''} ${explained.message}`);
|
|
698
|
+
throw fail(4500, explained.message, {
|
|
699
|
+
detail: explained.detail,
|
|
700
|
+
reason: explained.reason,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
fs.mkdirSync(path.dirname(this.configFile), { recursive: true, mode: 0o700 });
|
|
705
|
+
fs.writeFileSync(this.configFile, renderConfig({ tunnelId, credentialsFile, hostname, port }), { mode: 0o600 });
|
|
706
|
+
try { fs.chmodSync(this.configFile, 0o600); } catch { /* 已 0600 */ }
|
|
707
|
+
|
|
708
|
+
const now = new Date().toISOString();
|
|
709
|
+
// 开通即自检:DNS 写成功 ≠ 公网能解析(pending / moved zone 就是这么骗人的);
|
|
710
|
+
// CNAME 被改指到别的隧道同样不放行(防劫持评估见 dns-probe.evaluateDnsAnswer)
|
|
711
|
+
const { verdict, zone } = await this.#evaluate(hostname, tunnelId);
|
|
712
|
+
const warning = dnsWarningFor({ dnsOk: verdict.ok, dnsTampered: verdict.tampered, zone });
|
|
713
|
+
if (verdict.tampered) {
|
|
714
|
+
this.log(`tunnel 警告 固定地址解析被改指 ${hostname} → ${verdict.target}(期望 ${verdict.expected}),拒绝下发该地址`);
|
|
715
|
+
} else if (verdict.ok) {
|
|
716
|
+
this.log(`tunnel 固定地址已可解析 ${hostname}(${verdict.kind} ${verdict.records.join(',')})`);
|
|
717
|
+
} else {
|
|
718
|
+
this.log(`tunnel 警告 固定地址写入成功但公网解析不到 ${hostname}`);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
const next = this.#withMachine({
|
|
722
|
+
...cached,
|
|
723
|
+
installationId,
|
|
724
|
+
// 记下这本证书属于哪个 Cloudflare 账号:下次若换了账号,能识别出「旧隧道不再可用」
|
|
725
|
+
account: account || cached?.account || null,
|
|
726
|
+
subdomain: label,
|
|
727
|
+
hostname,
|
|
728
|
+
tunnelId,
|
|
729
|
+
credentialsFile,
|
|
730
|
+
configFile: this.configFile,
|
|
731
|
+
port,
|
|
732
|
+
dnsOk: verdict.ok,
|
|
733
|
+
dnsTampered: verdict.tampered,
|
|
734
|
+
dnsCheckedAt: now,
|
|
735
|
+
zone,
|
|
736
|
+
createdAt: cached?.createdAt ?? now,
|
|
737
|
+
updatedAt: now,
|
|
738
|
+
});
|
|
739
|
+
this._state = next;
|
|
740
|
+
writeState(this.stateFile, next);
|
|
741
|
+
this.log(`tunnel 固定地址就绪 ${hostname}(${created ? '新建' : '复用'},本地管理型)`);
|
|
742
|
+
return {
|
|
743
|
+
hostname,
|
|
744
|
+
url: `https://${hostname}`,
|
|
745
|
+
tunnelId,
|
|
746
|
+
created,
|
|
747
|
+
changed: Boolean(previousHostname && previousHostname !== hostname),
|
|
748
|
+
dnsOk: verdict.ok,
|
|
749
|
+
zone,
|
|
750
|
+
warning,
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/** 面板/报错里展示用的 cloudflared 名字(找不到时退回配置值,不发明路径)。 */
|
|
755
|
+
#exeLabel() {
|
|
756
|
+
return findCloudflared(this.executable, this.env) || findCloudflared('auto', this.env) || this.executable;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
async credential({ port }) {
|
|
760
|
+
await this.ensure({ port });
|
|
761
|
+
if (!this.state?.configFile) throw fail(4500, '隧道配置缺失,请重新开通固定地址');
|
|
762
|
+
return { hostname: this.state.hostname, configFile: this.state.configFile };
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* 只读本地状态的开通器(cert.pem 不在了 / 被删了也能继续用固定地址)。
|
|
768
|
+
*
|
|
769
|
+
* 为什么需要:本地管理型的 ingress 与 tunnel 凭据(<uuid>.json)都在本机,
|
|
770
|
+
* 日常启动**不需要** zone 凭据——cert.pem 只在开通时用来写 DNS。
|
|
771
|
+
* 早先这种情况会掉回 Quick Tunnel(随机地址),用户会以为「固定地址丢了」。
|
|
772
|
+
*
|
|
773
|
+
* 边界:
|
|
774
|
+
* · 绝不写 DNS、绝不建隧道(没有 zone 凭据,做不到也不该假装做到);
|
|
775
|
+
* · 端口变了只重写本地 ingress(纯本地操作,安全);
|
|
776
|
+
* · 状态必须属于本机、凭据文件必须存在,否则 configured=false(不冒充别人的地址)。
|
|
777
|
+
*/
|
|
778
|
+
export class LocalStateProvisioner {
|
|
779
|
+
constructor({ stateFile = null, configFile = null, baseDomain = 'matrixboard.cn', log = () => {}, homeDir = os.homedir() } = {}) {
|
|
780
|
+
this.stateFile = stateFile;
|
|
781
|
+
this.configFile = configFile || (stateFile ? path.join(path.dirname(stateFile), 'tunnel-config.yml') : null);
|
|
782
|
+
this.baseDomain = String(baseDomain || '').replace(/^\./, '').toLowerCase();
|
|
783
|
+
this.log = log;
|
|
784
|
+
this.homeDir = homeDir;
|
|
785
|
+
this._state = undefined;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
get kind() {
|
|
789
|
+
return 'state';
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
get state() {
|
|
793
|
+
if (this._state === undefined) this._state = readState(this.stateFile, this.log);
|
|
794
|
+
return this._state;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
get configured() {
|
|
798
|
+
const s = this.state;
|
|
799
|
+
if (!s?.hostname || !s.configFile || !s.credentialsFile) return false;
|
|
800
|
+
if (isForeignState(s, machineIdentity({ stateFile: this.stateFile }))) return false;
|
|
801
|
+
if (!fs.existsSync(s.configFile)) return false;
|
|
802
|
+
return hasLocalCredentials(s);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
get credentials() {
|
|
806
|
+
return null;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/** 没有 cert.pem 也就没有写入能力:这里只保证「能起隧道」。 */
|
|
810
|
+
async ensure({ port } = {}) {
|
|
811
|
+
const s = this.state;
|
|
812
|
+
if (!s?.hostname || !s.configFile) throw fail(4021, '这台主机还没有可复用的固定地址');
|
|
813
|
+
if (Number.isInteger(port) && port > 0 && port !== s.port) {
|
|
814
|
+
try {
|
|
815
|
+
fs.mkdirSync(path.dirname(s.configFile), { recursive: true, mode: 0o700 });
|
|
816
|
+
fs.writeFileSync(s.configFile, renderConfig({
|
|
817
|
+
tunnelId: s.tunnelId,
|
|
818
|
+
credentialsFile: s.credentialsFile,
|
|
819
|
+
hostname: s.hostname,
|
|
820
|
+
port,
|
|
821
|
+
}), { mode: 0o600 });
|
|
822
|
+
const next = { ...s, port, updatedAt: new Date().toISOString() };
|
|
823
|
+
this._state = next;
|
|
824
|
+
writeState(this.stateFile, next);
|
|
825
|
+
this.log(`tunnel 端口顺延 ${s.port} → ${port}(本地 ingress 已重写,DNS 未改动)`);
|
|
826
|
+
} catch (err) {
|
|
827
|
+
this.log(`tunnel 重写 ingress 失败:${err.message}`);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return {
|
|
831
|
+
hostname: s.hostname,
|
|
832
|
+
url: `https://${s.hostname}`,
|
|
833
|
+
tunnelId: s.tunnelId,
|
|
834
|
+
created: false,
|
|
835
|
+
changed: false,
|
|
836
|
+
dnsOk: s.dnsOk ?? null,
|
|
837
|
+
warning: dnsWarningFor(s),
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
async credential({ port } = {}) {
|
|
842
|
+
const r = await this.ensure({ port });
|
|
843
|
+
return { hostname: r.hostname, configFile: this.state?.configFile };
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** 与 LocalProvisioner.reset 同语义:只清本机状态与 ingress,不碰 Cloudflare 侧。 */
|
|
847
|
+
async reset() {
|
|
848
|
+
const removed = [];
|
|
849
|
+
const hadState = Boolean(this.state?.hostname);
|
|
850
|
+
for (const file of [this.stateFile, this.state?.configFile || this.configFile]) {
|
|
851
|
+
if (!file) continue;
|
|
852
|
+
try {
|
|
853
|
+
if (fs.statSync(file).isFile()) {
|
|
854
|
+
fs.unlinkSync(file);
|
|
855
|
+
removed.push(path.basename(file));
|
|
856
|
+
}
|
|
857
|
+
} catch { /* 不存在即目标状态 */ }
|
|
858
|
+
}
|
|
859
|
+
if (hadState) this.log('tunnel 已重置本机固定地址状态(Cloudflare 侧的隧道与记录未删除)');
|
|
860
|
+
this._state = null;
|
|
861
|
+
return { reset: true, hadState, removed, hostname: null, provisioned: false };
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
status() {
|
|
865
|
+
const s = this.state;
|
|
866
|
+
if (!s) return { kind: 'state', provisioned: false, hostname: null, url: null, tunnelId: null };
|
|
867
|
+
return {
|
|
868
|
+
kind: 'state',
|
|
869
|
+
provisioned: true,
|
|
870
|
+
hostname: s.hostname,
|
|
871
|
+
url: `https://${s.hostname}`,
|
|
872
|
+
tunnelId: s.tunnelId,
|
|
873
|
+
port: s.port ?? null,
|
|
874
|
+
dnsOk: s.dnsOk ?? null,
|
|
875
|
+
dnsCheckedAt: s.dnsCheckedAt ?? null,
|
|
876
|
+
zone: s.zone ?? null,
|
|
877
|
+
warning: dnsWarningFor(s),
|
|
878
|
+
credentials: null,
|
|
879
|
+
createdAt: s.createdAt ?? null,
|
|
880
|
+
updatedAt: s.updatedAt ?? null,
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
}
|