-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.html
More file actions
754 lines (705 loc) · 47.7 KB
/
Copy pathdeploy.html
File metadata and controls
754 lines (705 loc) · 47.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IDM 部署配置生成器</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'system-ui', 'sans-serif'],
mono: ['JetBrains Mono', 'Consolas', 'monospace'],
},
colors: {
primary: {
DEFAULT: '#38bdf8',
foreground: '#0c1427',
},
background: '#0c1427',
surface: '#141d2f',
content: '#f1f5f9',
muted: '#64748b',
}
}
}
}
</script>
<style>
body { background: linear-gradient(135deg, #0c1427 0%, #1a1f35 100%); }
.glass { backdrop-filter: blur(12px); background: rgba(20, 29, 47, 0.8); }
.glow { box-shadow: 0 0 40px rgba(56, 189, 248, 0.15); }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.3); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(20, 29, 47, 0.5); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #38bdf8; border-radius: 4px; }
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.info-box { background: rgba(56, 189, 248, 0.08); border: 1px solid rgba(56, 189, 248, 0.2); }
</style>
</head>
<body class="min-h-screen text-content font-sans">
<div class="max-w-5xl mx-auto px-4 py-8">
<!-- Header -->
<header class="text-center mb-10">
<div class="inline-flex items-center gap-3 mb-4">
<div class="p-3 rounded-xl bg-primary/10">
<svg class="w-8 h-8 text-primary" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"/>
</svg>
</div>
<h1 class="text-4xl font-bold bg-gradient-to-r from-primary to-emerald-400 bg-clip-text text-transparent">IDM</h1>
</div>
<p class="text-muted text-lg">IP & DNS Manager · 部署配置生成器</p>
</header>
<!-- Main Form -->
<div class="space-y-6">
<!-- Section: Basic -->
<section class="glass rounded-2xl p-6 glow fade-in">
<h2 class="flex items-center gap-2 text-lg font-bold text-primary mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"/></svg>
基础配置
</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div>
<label class="block text-sm font-medium text-muted mb-2">服务端口</label>
<input type="number" id="port" value="8080" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">API Key <span class="text-xs text-muted/60">(自动生成或自定义)</span></label>
<div class="flex gap-2">
<input type="text" id="apiKey" class="flex-1 bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors" placeholder="点击生成">
<button onclick="generateApiKey()" class="px-4 py-2.5 bg-primary/20 hover:bg-primary/30 text-primary rounded-lg transition-colors text-sm font-medium">
生成
</button>
</div>
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">时区</label>
<select id="timezone" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content focus:border-primary transition-colors cursor-pointer">
<option value="Asia/Shanghai">Asia/Shanghai (北京时间)</option>
<option value="Asia/Hong_Kong">Asia/Hong_Kong</option>
<option value="Asia/Tokyo">Asia/Tokyo</option>
<option value="America/New_York">America/New_York</option>
<option value="Europe/London">Europe/London</option>
<option value="UTC">UTC</option>
</select>
</div>
<div class="md:col-span-2">
<label class="block text-sm font-medium text-muted mb-2">可信子网 (CIDR,逗号分隔)</label>
<input type="text" id="trustedSubnets" value="127.0.0.1/32, 192.168.1.0/24" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">这些 IP 范围内的请求无需 API Key 验证,且不受速率限制</p>
</div>
</div>
</section>
<!-- Section: Database -->
<section class="glass rounded-2xl p-6 glow fade-in">
<h2 class="flex items-center gap-2 text-lg font-bold text-primary mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"/></svg>
数据库配置
</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-medium text-muted mb-2">数据库类型</label>
<div class="flex gap-4">
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="dbType" value="sqlite" checked onchange="toggleDbConfig()" class="w-4 h-4 text-primary bg-surface border-white/20 focus:ring-primary">
<span class="text-content">SQLite <span class="text-xs text-muted">(推荐)</span></span>
</label>
<label class="flex items-center gap-2 cursor-pointer">
<input type="radio" name="dbType" value="postgres" onchange="toggleDbConfig()" class="w-4 h-4 text-primary bg-surface border-white/20 focus:ring-primary">
<span class="text-content">PostgreSQL</span>
</label>
</div>
</div>
<div>
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="includePostgres" class="w-4 h-4 text-primary bg-surface border-white/20 rounded focus:ring-primary">
<span class="text-sm text-muted">同时部署 PostgreSQL 容器 <span class="text-xs">(PostgreSQL 模式)</span></span>
</label>
</div>
</div>
<!-- SQLite Config -->
<div id="sqliteConfig" class="mt-4">
<label class="block text-sm font-medium text-muted mb-2">数据库文件路径</label>
<input type="text" id="dbPath" value="/data/idm.db" class="w-full md:w-1/2 bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
</div>
<!-- PostgreSQL Config -->
<div id="postgresConfig" class="mt-4 hidden space-y-4">
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label class="block text-sm font-medium text-muted mb-2">主机</label>
<input type="text" id="pgHost" value="postgres" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">端口</label>
<input type="number" id="pgPort" value="5432" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">数据库名</label>
<input type="text" id="pgDbName" value="idm" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">用户名</label>
<input type="text" id="pgUser" value="idm" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">密码</label>
<input type="password" id="pgPassword" value="idm_secret_password" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono text-sm focus:border-primary transition-colors">
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">SSL 模式</label>
<select id="pgSslMode" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content focus:border-primary transition-colors cursor-pointer">
<option value="disable">disable</option>
<option value="require">require</option>
<option value="verify-full">verify-full</option>
</select>
</div>
</div>
</div>
</section>
<!-- Section: Intervals -->
<section class="glass rounded-2xl p-6 glow fade-in">
<h2 class="flex items-center gap-2 text-lg font-bold text-primary mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
时间间隔配置
</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<div>
<label class="block text-sm font-medium text-muted mb-2">IP 检查间隔</label>
<input type="text" id="ipCheckInterval" value="5m" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
<p id="ipIntervalHint" class="text-xs text-muted/60 mt-1">格式: 30s, 5m, 1h</p>
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">DNS 更新间隔</label>
<input type="text" id="dnsUpdateInterval" value="1m" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">格式: 30s, 1m, 5m</p>
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">历史保留时间</label>
<input type="text" id="historyRetention" value="30d" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">格式: 7d, 30d, 1m, 1y</p>
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">历史清理间隔</label>
<input type="text" id="historyCleanup" value="1d" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">设为 0 禁用自动清理</p>
</div>
</div>
<!-- Interval Explanation -->
<div class="info-box rounded-xl p-4 mt-4">
<p class="text-sm text-primary/90">
<strong>说明:</strong>「历史保留时间」决定数据保留多久(如 30d = 保留 30 天内记录);「历史清理间隔」决定多久执行一次清理任务(如 1d = 每天清理过期数据)。
</p>
</div>
</section>
<!-- Section: Security -->
<section class="glass rounded-2xl p-6 glow fade-in">
<h2 class="flex items-center gap-2 text-lg font-bold text-primary mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/></svg>
安全配置
</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="flex items-center gap-3">
<input type="checkbox" id="rateLimitEnabled" checked class="w-5 h-5 text-primary bg-surface border-white/20 rounded focus:ring-primary">
<label for="rateLimitEnabled" class="text-content cursor-pointer">启用 API 速率限制</label>
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">最大请求数</label>
<input type="number" id="rateLimitRequests" value="100" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">建议: 50-200</p>
</div>
<div>
<label class="block text-sm font-medium text-muted mb-2">时间窗口</label>
<input type="text" id="rateLimitWindow" value="1m" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2.5 text-content font-mono focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">建议: 1m-5m</p>
</div>
</div>
<!-- Rate Limit Explanation -->
<div class="info-box rounded-xl p-4 mt-4">
<p class="text-sm text-primary/90 mb-2">
<strong>API 速率限制逻辑:</strong>同一 IP 在「时间窗口」内最多发送「最大请求数」个请求。超出后返回 <code class="px-1 py-0.5 bg-white/10 rounded text-xs">429 Too Many Requests</code>。
</p>
<ul class="text-sm text-muted mt-2 space-y-1 ml-4 list-disc">
<li>用于防止恶意用户大量请求消耗服务器资源</li>
<li>可信子网(Trusted Subnets)中的请求<strong class="text-content">不受限制</strong></li>
<li>建议值:严格 50/1m,默认 100/1m,宽松 200/1m</li>
</ul>
</div>
</section>
<!-- Section: IP Providers -->
<section class="glass rounded-2xl p-6 glow fade-in">
<h2 class="flex items-center gap-2 text-lg font-bold text-primary mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"/></svg>
IP 获取方式
</h2>
<!-- Priority Explanation -->
<div class="info-box rounded-xl p-4 mb-4">
<p class="text-sm text-primary/90 mb-2">
<strong>选择说明:</strong>
</p>
<ul class="text-sm text-muted mt-2 space-y-1 ml-4 list-disc">
<li>单选 <strong class="text-emerald-400">Router SSH</strong>:通过 SSH 连接路由器获取 IP,响应快、无外部依赖</li>
<li>单选 <strong class="text-blue-400">STUN</strong>:通过公共 STUN 服务器获取 IP,配置简单但有限频限制</li>
<li><strong class="text-amber-400">多选时 STUN 作为备用</strong>:优先使用 Router SSH,失败时自动回退到 STUN</li>
</ul>
</div>
<div class="space-y-4">
<!-- Router SSH (Primary - listed first but NOT checked by default) -->
<div class="bg-surface/30 rounded-xl p-4">
<div class="flex items-center justify-between mb-3">
<div class="flex items-center gap-3">
<input type="checkbox" id="routerSshEnabled" class="w-5 h-5 text-primary bg-surface border-white/20 rounded focus:ring-primary">
<label for="routerSshEnabled" class="font-medium text-content cursor-pointer">Router SSH</label>
<span class="text-xs px-2 py-0.5 bg-emerald-500/20 text-emerald-400 rounded">主方式</span>
</div>
</div>
<div class="ml-8 mb-3">
<p class="text-xs text-muted">通过 SSH 连接路由器获取公网 IP,支持 RouterOS / OpenWrt。本地路由器响应快,无外部依赖。最小检查间隔:<strong class="text-emerald-400">1秒</strong></p>
</div>
<div id="routerSshConfig" class="ml-8 hidden space-y-3">
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
<div>
<label class="block text-xs text-muted mb-1">路由器类型</label>
<select id="routerType" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content focus:border-primary">
<option value="routeros">RouterOS</option>
<option value="openwrt">OpenWrt</option>
</select>
</div>
<div>
<label class="block text-xs text-muted mb-1">主机</label>
<input type="text" id="routerHost" placeholder="192.168.1.1" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
<div>
<label class="block text-xs text-muted mb-1">端口</label>
<input type="number" id="routerPort" value="22" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
<div>
<label class="block text-xs text-muted mb-1">用户名</label>
<input type="text" id="routerUser" placeholder="admin" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
<div>
<label class="block text-xs text-muted mb-1">密码</label>
<input type="password" id="routerPassword" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
<div>
<label class="block text-xs text-muted mb-1">接口名称</label>
<input type="text" id="routerInterface" placeholder="wan / ether1" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
<div class="md:col-span-3">
<label class="block text-xs text-muted mb-1">Host Key (Base64) <span class="text-amber-400">必填</span></label>
<input type="text" id="routerHostKey" placeholder="运行 ssh-keyscan <路由器IP> 获取" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
<p class="text-xs text-amber-400/80 mt-1">必需。运行: ssh-keyscan -t rsa,ecdsa,ed25519 <路由器IP></p>
</div>
<div class="md:col-span-3">
<label class="block text-xs text-muted mb-1">SSH 私钥 <span class="text-blue-400">(可选,优先于密码)</span></label>
<textarea id="routerKey" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary h-20" placeholder="粘贴 SSH 私钥内容(支持 RSA/ECDSA/ed25519)"></textarea>
<p class="text-xs text-muted/60 mt-1">推荐使用 ed25519 私钥,更安全、更快。拖拽私钥文件到输入框可自动导入</p>
</div>
</div>
</div>
</div>
<!-- STUN (Backup - checked by default) -->
<div class="bg-surface/30 rounded-xl p-4">
<div class="flex items-center justify-between mb-3">
<div class="flex items-center gap-3">
<input type="checkbox" id="stunEnabled" checked class="w-5 h-5 text-primary bg-surface border-white/20 rounded focus:ring-primary">
<label for="stunEnabled" class="font-medium text-content cursor-pointer">STUN 服务器</label>
<span class="text-xs px-2 py-0.5 bg-blue-500/20 text-blue-400 rounded">备用方式</span>
</div>
</div>
<div class="ml-8 mb-3">
<p class="text-xs text-muted">通过 STUN 协议获取公网 IP。配置简单,但公共服务器有频率限制。最小检查间隔:<strong class="text-amber-400">30秒</strong>。多选时作为 Router SSH 的备用方案。</p>
</div>
<div class="ml-8 space-y-3">
<div>
<label class="block text-sm text-muted mb-2">自定义服务器 (留空使用默认列表)</label>
<input type="text" id="stunServers" placeholder="stun.l.google.com:19302, stun.cloudflare.com:3478" class="w-full bg-surface/50 border border-white/10 rounded-lg px-4 py-2 text-content font-mono text-sm focus:border-primary transition-colors">
<p class="text-xs text-muted/60 mt-1">默认: stun.l.google.com, stun1.l.google.com, stun.cloudflare.com 等</p>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs text-muted mb-1">超时时间</label>
<input type="text" id="stunTimeout" value="5s" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
<div>
<label class="block text-xs text-muted mb-1">最大重试次数</label>
<input type="number" id="stunMaxRetries" value="3" class="w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary">
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Section: Cloudflare -->
<section class="glass rounded-2xl p-6 glow fade-in">
<h2 class="flex items-center gap-2 text-lg font-bold text-primary mb-6">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 15a4 4 0 004 4h9a5 5 0 10-.1-9.999 5.002 5.002 0 10-9.78 2.096A4.001 4.001 0 003 15z"/></svg>
Cloudflare DNS 配置
</h2>
<!-- Cloudflare API Limit -->
<div class="info-box rounded-xl p-4 mb-4">
<p class="text-sm text-primary/90">
<strong>Cloudflare API 限制:</strong>所有用户(免费/付费)限制为 <strong>1200 次 / 5 分钟</strong>(即 240 次/分钟)。建议 DNS 更新间隔不低于 <strong class="text-amber-400">1m</strong>,实际 DNS TTL 通常为 300 秒,更短的间隔意义不大。
</p>
</div>
<div id="cfAccounts" class="space-y-4">
<!-- CF Account Template -->
</div>
<button onclick="addCfAccount()" class="mt-4 flex items-center gap-2 px-4 py-2 bg-primary/10 hover:bg-primary/20 text-primary rounded-lg transition-colors text-sm font-medium">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
添加 Cloudflare 账户
</button>
<p class="text-xs text-muted/60 mt-2">如果不需要自动更新 DNS,可以留空</p>
</section>
<!-- Generate Button -->
<div class="flex flex-col sm:flex-row gap-4 justify-center pt-6">
<button onclick="generateCompose()" class="px-8 py-4 bg-gradient-to-r from-primary to-emerald-400 hover:opacity-90 text-background font-bold rounded-xl transition-all shadow-lg shadow-primary/20 text-lg">
生成 docker-compose.yml
</button>
<button onclick="resetForm()" class="px-6 py-4 bg-surface/50 hover:bg-surface text-muted hover:text-content border border-white/10 rounded-xl transition-colors">
重置配置
</button>
</div>
</div>
<!-- Output Modal -->
<div id="outputModal" class="fixed inset-0 bg-black/70 backdrop-blur-sm z-50 hidden flex items-center justify-center p-4">
<div class="bg-surface rounded-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden flex flex-col">
<div class="flex items-center justify-between p-6 border-b border-white/10">
<h3 class="text-xl font-bold text-content">部署文件已生成</h3>
<button onclick="closeModal()" class="p-2 hover:bg-white/10 rounded-lg transition-colors">
<svg class="w-6 h-6 text-muted" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
</button>
</div>
<div class="flex-1 overflow-auto p-6 space-y-6">
<!-- docker-compose.yml -->
<div>
<div class="flex items-center justify-between mb-3">
<h4 class="font-bold text-primary">docker-compose.yml</h4>
<button onclick="downloadFile('docker-compose.yml', 'composeContent')" class="flex items-center gap-2 px-3 py-1.5 bg-primary/10 hover:bg-primary/20 text-primary rounded-lg text-sm transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/></svg>
下载
</button>
</div>
<pre id="composeContent" class="bg-background/50 rounded-xl p-4 text-sm font-mono text-content overflow-x-auto border border-white/5"></pre>
</div>
<!-- .env -->
<div>
<div class="flex items-center justify-between mb-3">
<h4 class="font-bold text-primary">.env</h4>
<button onclick="downloadFile('.env', 'envContent')" class="flex items-center gap-2 px-3 py-1.5 bg-primary/10 hover:bg-primary/20 text-primary rounded-lg text-sm transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/></svg>
下载
</button>
</div>
<pre id="envContent" class="bg-background/50 rounded-xl p-4 text-sm font-mono text-content overflow-x-auto border border-white/5"></pre>
</div>
<!-- Deploy Instructions -->
<div class="bg-emerald-500/10 border border-emerald-500/20 rounded-xl p-4">
<h4 class="font-bold text-emerald-400 mb-3">部署步骤</h4>
<ol class="list-decimal list-inside space-y-2 text-sm text-muted">
<li>下载 <code class="px-1.5 py-0.5 bg-white/5 rounded text-content">docker-compose.yml</code> 和 <code class="px-1.5 py-0.5 bg-white/5 rounded text-content">.env</code> 到同一目录</li>
<li>创建数据目录: <code class="px-1.5 py-0.5 bg-white/5 rounded text-content">mkdir -p data</code></li>
<li>启动服务: <code class="px-1.5 py-0.5 bg-white/5 rounded text-content">docker compose up -d</code></li>
<li>访问: <code class="px-1.5 py-0.5 bg-white/5 rounded text-content">http://localhost:端口</code></li>
</ol>
</div>
<div class="bg-amber-500/10 border border-amber-500/20 rounded-xl p-4">
<h4 class="font-bold text-amber-400 mb-2">安全提示</h4>
<ul class="list-disc list-inside space-y-1 text-sm text-muted">
<li>妥善保管 API Key 和 Cloudflare Token</li>
<li>不要将 <code class="px-1 py-0.5 bg-white/5 rounded text-content">.env</code> 文件提交到公开仓库</li>
<li>生产环境建议使用 HTTPS</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="text-center mt-12 text-muted text-sm">
<p>IDM · IP & DNS Manager</p>
<p class="mt-1 text-muted/60">Generated configuration files are ready for deployment</p>
</footer>
</div>
<script>
// Initialize
document.addEventListener('DOMContentLoaded', () => {
generateApiKey();
addCfAccount();
// Router SSH toggle
document.getElementById('routerSshEnabled').addEventListener('change', (e) => {
document.getElementById('routerSshConfig').classList.toggle('hidden', !e.target.checked);
updateIpIntervalHint();
});
// STUN toggle
document.getElementById('stunEnabled').addEventListener('change', (e) => {
updateIpIntervalHint();
});
updateIpIntervalHint();
});
// Update IP check interval hint based on selected IP providers
function updateIpIntervalHint() {
const routerSshEnabled = document.getElementById('routerSshEnabled').checked;
const stunEnabled = document.getElementById('stunEnabled').checked;
const hint = document.getElementById('ipIntervalHint');
if (routerSshEnabled && !stunEnabled) {
// Only Router SSH - can use 1s
hint.innerHTML = '格式: 1s, 30s, 5m, 1h <span class="text-emerald-400">(Router SSH: 最小 1s)</span>';
} else if (stunEnabled) {
// STUN enabled (with or without Router SSH as backup)
if (routerSshEnabled) {
hint.innerHTML = '格式: 1s, 30s, 5m, 1h <span class="text-amber-400">(STUN: 最小 30s, Router SSH: 最小 1s)</span>';
} else {
hint.innerHTML = '格式: 30s, 5m, 1h <span class="text-amber-400">(STUN: 最小 30s)</span>';
}
} else {
hint.textContent = '格式: 30s, 5m, 1h';
}
}
// Generate random API Key
function generateApiKey() {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let key = '';
for (let i = 0; i < 32; i++) {
key += chars.charAt(Math.floor(Math.random() * chars.length));
}
document.getElementById('apiKey').value = key;
}
// Toggle DB config visibility
function toggleDbConfig() {
const isPostgres = document.querySelector('input[name="dbType"]:checked').value === 'postgres';
document.getElementById('sqliteConfig').classList.toggle('hidden', isPostgres);
document.getElementById('postgresConfig').classList.toggle('hidden', !isPostgres);
}
// CF Account counter
let cfAccountCount = 0;
// Add Cloudflare Account
function addCfAccount() {
cfAccountCount++;
const container = document.getElementById('cfAccounts');
const div = document.createElement('div');
div.className = 'bg-surface/30 rounded-xl p-4 fade-in';
div.id = `cfAccount_${cfAccountCount}`;
div.innerHTML = `
<div class="flex items-center justify-between mb-3">
<input type="text" placeholder="账户名称" class="bg-transparent border-b border-white/20 focus:border-primary px-2 py-1 text-content font-medium focus:outline-none" value="Account ${cfAccountCount}">
<button onclick="removeElement('cfAccount_${cfAccountCount}')" class="p-1 hover:bg-red-500/20 rounded text-red-400 transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
</button>
</div>
<div class="space-y-3">
<div>
<label class="block text-xs text-muted mb-1">API Token</label>
<input type="password" class="cfToken w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary" placeholder="Cloudflare API Token">
</div>
<div>
<label class="block text-xs text-muted mb-1">域名区域 (每行一个: zone_name | records)</label>
<textarea class="cfZones w-full bg-surface/50 border border-white/10 rounded-lg px-3 py-2 text-sm text-content font-mono focus:border-primary h-20" placeholder="example.com | @, www, vpn another.com | @"></textarea>
</div>
</div>
`;
container.appendChild(div);
}
// Remove element
function removeElement(id) {
document.getElementById(id)?.remove();
}
// Reset form
function resetForm() {
if (confirm('确定要重置所有配置吗?')) {
location.reload();
}
}
// Generate docker-compose.yml
function generateCompose() {
const config = {
port: document.getElementById('port').value || '8080',
apiKey: document.getElementById('apiKey').value,
timezone: document.getElementById('timezone').value,
trustedSubnets: document.getElementById('trustedSubnets').value,
dbType: document.querySelector('input[name="dbType"]:checked').value,
dbPath: document.getElementById('dbPath').value,
pgHost: document.getElementById('pgHost').value,
pgPort: document.getElementById('pgPort').value,
pgDbName: document.getElementById('pgDbName').value,
pgUser: document.getElementById('pgUser').value,
pgPassword: document.getElementById('pgPassword').value,
pgSslMode: document.getElementById('pgSslMode').value,
ipCheckInterval: document.getElementById('ipCheckInterval').value,
dnsUpdateInterval: document.getElementById('dnsUpdateInterval').value,
historyRetention: document.getElementById('historyRetention').value,
historyCleanup: document.getElementById('historyCleanup').value,
rateLimitEnabled: document.getElementById('rateLimitEnabled').checked,
rateLimitRequests: document.getElementById('rateLimitRequests').value,
rateLimitWindow: document.getElementById('rateLimitWindow').value,
stunEnabled: document.getElementById('stunEnabled').checked,
stunServers: document.getElementById('stunServers').value,
stunTimeout: document.getElementById('stunTimeout')?.value || '5s',
stunMaxRetries: document.getElementById('stunMaxRetries')?.value || 3,
routerSshEnabled: document.getElementById('routerSshEnabled').checked,
routerType: document.getElementById('routerType').value,
routerHost: document.getElementById('routerHost').value,
routerPort: document.getElementById('routerPort').value,
routerUser: document.getElementById('routerUser').value,
routerPassword: document.getElementById('routerPassword').value,
routerKey: document.getElementById('routerKey')?.value || '',
routerInterface: document.getElementById('routerInterface').value,
routerHostKey: document.getElementById('routerHostKey').value,
includePostgres: document.getElementById('includePostgres').checked
};
// Build environment variables
let envVars = [];
envVars.push(` - PORT=${config.port}`);
envVars.push(` - TZ=${config.timezone}`);
envVars.push(` - API_KEY=${config.apiKey}`);
envVars.push(` - TRUSTED_SUBNETS=${config.trustedSubnets}`);
// Intervals
envVars.push(` - IP_CHECK_INTERVAL=${config.ipCheckInterval}`);
envVars.push(` - DNS_UPDATE_INTERVAL=${config.dnsUpdateInterval}`);
envVars.push(` - HISTORY_RETENTION=${config.historyRetention}`);
envVars.push(` - HISTORY_CLEANUP_INTERVAL=${config.historyCleanup}`);
// Rate limiting
envVars.push(` - RATE_LIMIT_ENABLED=${config.rateLimitEnabled}`);
envVars.push(` - RATE_LIMIT_REQUESTS=${config.rateLimitRequests}`);
envVars.push(` - RATE_LIMIT_WINDOW=${config.rateLimitWindow}`);
// IP Providers
envVars.push(` - STUN_ENABLED=${config.stunEnabled}`);
if (config.stunEnabled) {
if (config.stunServers) {
envVars.push(` - STUN_SERVERS=${config.stunServers}`);
}
envVars.push(` - STUN_TIMEOUT=${config.stunTimeout || '5s'}`);
envVars.push(` - STUN_MAX_RETRIES=${config.stunMaxRetries || 3}`);
}
envVars.push(` - ROUTER_SSH_ENABLED=${config.routerSshEnabled}`);
if (config.routerSshEnabled) {
envVars.push(` - ROUTER_TYPE=${config.routerType}`);
envVars.push(` - ROUTER_HOST=${config.routerHost}`);
envVars.push(` - ROUTER_PORT=${config.routerPort}`);
envVars.push(` - ROUTER_USER=${config.routerUser}`);
if (config.routerPassword) {
envVars.push(` - ROUTER_PASSWORD=${config.routerPassword}`);
}
if (config.routerKey) {
envVars.push(` - ROUTER_KEY=${config.routerKey.replace(/\n/g, '\\n')}`);
}
envVars.push(` - ROUTER_INTERFACE=${config.routerInterface}`);
envVars.push(` - ROUTER_HOST_KEY=${config.routerHostKey}`);
}
// Database config
if (config.dbType === 'postgres') {
envVars.push(` - DB_TYPE=postgres`);
envVars.push(` - DB_HOST=${config.pgHost}`);
envVars.push(` - DB_PORT=${config.pgPort}`);
envVars.push(` - DB_USER=${config.pgUser}`);
envVars.push(` - DB_PASSWORD=${config.pgPassword}`);
envVars.push(` - DB_NAME=${config.pgDbName}`);
envVars.push(` - DB_SSLMODE=${config.pgSslMode}`);
} else {
envVars.push(` - DB_TYPE=sqlite`);
envVars.push(` - DB_PATH=${config.dbPath}`);
}
// Build services
let services = [];
let networks = [' networks:', ' - idm-network'];
// Main service
let idmService = ` idm:
image: ghcr.io/404700/idm:latest
container_name: idm
restart: unless-stopped
user: "\${UID:-1000}:\${GID:-1000}"
environment:
${envVars.join('\n')}
volumes:
- ./data:/data:rw
ports:
- "${config.port}:${config.port}"
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://localhost:${config.port}/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
${networks.join('\n')}`;
services.push(idmService);
// PostgreSQL service if needed
if (config.dbType === 'postgres' && config.includePostgres) {
const pgService = ` postgres:
image: postgres:16-alpine
container_name: idm-postgres
restart: unless-stopped
environment:
- POSTGRES_USER=${config.pgUser}
- POSTGRES_PASSWORD=${config.pgPassword}
- POSTGRES_DB=${config.pgDbName}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${config.pgUser} -d ${config.pgDbName}"]
interval: 10s
timeout: 5s
retries: 5
${networks.join('\n')}`;
services.push(pgService);
}
// Build volumes section
let volumesSection = '';
if (config.dbType === 'postgres' && config.includePostgres) {
volumesSection = '\nvolumes:\n postgres_data:';
}
// Build docker-compose content
const composeContent = `# IDM Docker Compose Configuration
# Generated: ${new Date().toISOString()}
services:
${services.join('\n\n')}
${volumesSection}
networks:
idm-network:
driver: bridge
`;
// Build .env content
const envContent = `# IDM Environment Variables
# Generated: ${new Date().toISOString()}
# IMPORTANT: Keep this file secure and do not commit to public repositories!
# User ID (run: id -u)
UID=1000
# Group ID (run: id -g)
GID=1000
`;
// Display output
document.getElementById('composeContent').textContent = composeContent;
document.getElementById('envContent').textContent = envContent;
document.getElementById('outputModal').classList.remove('hidden');
}
// Close modal
function closeModal() {
document.getElementById('outputModal').classList.add('hidden');
}
// Download file
function downloadFile(filename, elementId) {
const content = document.getElementById(elementId).textContent;
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
// Close modal on escape
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeModal();
});
// Close modal on backdrop click
document.getElementById('outputModal').addEventListener('click', (e) => {
if (e.target === e.currentTarget) closeModal();
});
</script>
</body>
</html>