-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1181 lines (1040 loc) · 55.8 KB
/
index.html
File metadata and controls
1181 lines (1040 loc) · 55.8 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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ECUSTCIC 域名分发系统</title>
<link rel="icon" href="ecustcic.png" type="image/png">
<style>
[data-theme="dark"] {
--bg: #0f1117;
--bg-card: #1a1d27;
--bg-hover: #252833;
--border: #2d3041;
--text: #e4e6f0;
--text-dim: #8b8fa3;
--primary: #6366f1;
--primary-hover: #818cf8;
--danger: #ef4444;
--danger-hover: #f87171;
--success: #22c55e;
--warning: #f59e0b;
--overlay: rgba(0,0,0,0.6);
--badge-cf-bg: #f380201a; --badge-cf-fg: #f59e0b;
--badge-dp-bg: #22c55e1a; --badge-dp-fg: #22c55e;
--badge-ok-bg: #22c55e1a; --badge-ok-fg: #22c55e;
--badge-err-bg: #ef44441a; --badge-err-fg: #ef4444;
--badge-warn-bg: #f59e0b1a; --badge-warn-fg: #f59e0b;
--shadow: 0 2px 8px rgba(0,0,0,0.3);
}
[data-theme="light"] {
--bg: #f5f6fa;
--bg-card: #ffffff;
--bg-hover: #eef0f5;
--border: #dde1ea;
--text: #1a1d27;
--text-dim: #6b7280;
--primary: #6366f1;
--primary-hover: #4f46e5;
--danger: #ef4444;
--danger-hover: #dc2626;
--success: #16a34a;
--warning: #d97706;
--overlay: rgba(0,0,0,0.3);
--badge-cf-bg: #fef3c7; --badge-cf-fg: #92400e;
--badge-dp-bg: #dcfce7; --badge-dp-fg: #166534;
--badge-ok-bg: #dcfce7; --badge-ok-fg: #166534;
--badge-err-bg: #fee2e2; --badge-err-fg: #991b1b;
--badge-warn-bg: #fef3c7; --badge-warn-fg: #92400e;
--shadow: 0 2px 8px rgba(0,0,0,0.08);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
transition: background 0.3s, color 0.3s;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
.login-container {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 20px;
}
.login-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 16px;
padding: 48px;
max-width: 420px;
width: 100%;
text-align: center;
box-shadow: var(--shadow);
}
.login-card h1 { font-size: 28px; margin-bottom: 8px; }
.login-card p { color: var(--text-dim); margin-bottom: 32px; }
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 10px 20px;
border: 1px solid var(--border);
border-radius: 8px;
background: var(--bg-card);
color: var(--text);
font-size: 14px;
cursor: pointer;
transition: all 0.2s;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: transparent; border-color: var(--success); color: var(--success); }
.btn-success:hover { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-skin {
background: #4caf50;
border-color: #4caf50;
color: #fff;
padding: 12px 24px;
font-size: 16px;
width: 100%;
}
.btn-skin:hover { background: #43a047; }
.app { display: flex; min-height: 100vh; }
.sidebar {
width: 240px;
background: var(--bg-card);
border-right: 1px solid var(--border);
padding: 20px 0;
flex-shrink: 0;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 100;
transition: transform 0.3s;
}
.sidebar-brand {
padding: 0 20px 20px;
border-bottom: 1px solid var(--border);
margin-bottom: 12px;
}
.sidebar-brand h2 {
font-size: 20px;
line-height: 1;
background: linear-gradient(135deg, var(--primary), var(--primary-hover));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.sidebar-brand h2 img {
vertical-align: middle;
}
.sidebar-brand span { font-size: 12px; color: var(--text-dim); }
.nav-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 20px;
color: var(--text-dim);
cursor: pointer;
transition: all 0.2s;
font-size: 14px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { color: var(--primary); background: rgba(99, 102, 241, 0.1); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-section {
padding: 8px 20px 4px;
font-size: 11px;
color: var(--text-dim);
text-transform: uppercase;
letter-spacing: 1px;
margin-top: 8px;
}
.main { flex: 1; padding: 32px; margin-left: 240px; overflow-y: auto; min-height: 100vh; }
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 24px;
gap: 12px;
flex-wrap: wrap;
}
.page-header h1 { font-size: 24px; }
.top-bar {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
margin-bottom: 16px;
}
.theme-toggle {
width: 36px;
height: 36px;
border-radius: 50%;
border: 1px solid var(--border);
background: var(--bg-card);
color: var(--text);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s;
font-size: 16px;
}
.theme-toggle:hover { background: var(--bg-hover); }
.mobile-header {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
height: 56px;
background: var(--bg-card);
border-bottom: 1px solid var(--border);
z-index: 90;
padding: 0 16px;
align-items: center;
justify-content: space-between;
}
.mobile-header h2 {
font-size: 16px;
line-height: 1;
background: linear-gradient(135deg, var(--primary), var(--primary-hover));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.mobile-header h2 img {
vertical-align: middle;
}
.hamburger {
width: 36px;
height: 36px;
border: none;
background: transparent;
color: var(--text);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 22px;
}
.sidebar-backdrop {
display: none;
position: fixed;
inset: 0;
background: var(--overlay);
z-index: 99;
}
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 24px;
margin-bottom: 20px;
box-shadow: var(--shadow);
}
.card-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 500px; }
th, td {
padding: 12px 16px;
text-align: left;
border-bottom: 1px solid var(--border);
font-size: 14px;
}
th { color: var(--text-dim); font-weight: 500; font-size: 13px; }
.badge {
display: inline-block;
padding: 2px 8px;
border-radius: 4px;
font-size: 12px;
font-weight: 500;
white-space: nowrap;
}
.badge-cf { background: var(--badge-cf-bg); color: var(--badge-cf-fg); }
.badge-dp { background: var(--badge-dp-bg); color: var(--badge-dp-fg); }
.badge-active, .badge-approved { background: var(--badge-ok-bg); color: var(--badge-ok-fg); }
.badge-error, .badge-rejected { background: var(--badge-err-bg); color: var(--badge-err-fg); }
.badge-pending { background: var(--badge-warn-bg); color: var(--badge-warn-fg); }
.modal-overlay {
position: fixed;
inset: 0;
background: var(--overlay);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
padding: 20px;
}
.modal {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 32px;
max-width: 520px;
width: 100%;
max-height: 90vh;
overflow-y: auto;
box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 20px; font-size: 18px; }
.form-group { margin-bottom: 16px; }
.form-group label {
display: block;
font-size: 13px;
color: var(--text-dim);
margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
width: 100%;
padding: 10px 12px;
background: var(--bg);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text);
font-size: 14px;
outline: none;
transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-actions {
display: flex;
gap: 10px;
justify-content: flex-end;
margin-top: 20px;
flex-wrap: wrap;
}
.empty-state {
text-align: center;
padding: 48px 20px;
color: var(--text-dim);
}
.empty-state p { font-size: 14px; }
.user-info {
display: flex;
align-items: center;
gap: 10px;
padding: 16px 20px;
border-top: 1px solid var(--border);
margin-top: auto;
}
.user-info .name { font-size: 13px; }
.user-info .role { font-size: 11px; color: var(--text-dim); }
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 20px;
box-shadow: var(--shadow);
}
.stat-card .label { font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.toast {
position: fixed;
bottom: 24px;
right: 24px;
padding: 12px 20px;
border-radius: 8px;
font-size: 14px;
z-index: 2000;
animation: slideIn 0.3s ease;
max-width: calc(100vw - 48px);
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
@keyframes slideIn {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.hidden { display: none !important; }
.sidebar-inner { display: flex; flex-direction: column; height: 100%; }
@media (max-width: 768px) {
.mobile-header { display: flex; }
.sidebar {
transform: translateX(-100%);
}
.sidebar.open {
transform: translateX(0);
}
.sidebar-backdrop.open {
display: block;
}
.main {
margin-left: 0;
padding: 72px 16px 24px;
}
.main .top-bar { display: none; }
.login-card { padding: 32px 24px; }
.stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card { padding: 14px; }
.stat-card .value { font-size: 22px; }
.card { padding: 16px; }
.page-header h1 { font-size: 20px; }
.modal { padding: 20px; margin: 10px; }
.toast { bottom: 16px; right: 16px; left: 16px; max-width: none; }
table { min-width: 400px; }
}
@media (max-width: 480px) {
.stats { grid-template-columns: 1fr 1fr; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.actions-cell { flex-direction: column; gap: 4px; }
}
</style>
</head>
<body>
<div id="login-page" class="login-container">
<div class="login-card">
<img src="ecustcic.png" alt="NIC" style="height:48px;margin-bottom:8px">
<h1>NIC</h1>
<p>ECUSTCIC 域名分发系统</p>
<button class="btn btn-skin" onclick="loginWithSkin()">
<img src="ecustmc.jpeg" alt="" style="width:18px;height:18px;border-radius:50%;object-fit:cover">
使用 ECUSTMC 皮肤站登录
</button>
</div>
</div>
<div id="app" class="app hidden">
<div class="mobile-header" id="mobile-header">
<button class="hamburger" onclick="toggleSidebar()">☰</button>
<h2><img src="ecustcic.png" alt="" style="height:24px;vertical-align:middle;margin-right:6px">NIC</h2>
<button class="theme-toggle" onclick="toggleTheme()" id="theme-toggle-mobile">🌙</button>
</div>
<div class="sidebar-backdrop" id="sidebar-backdrop" onclick="closeSidebar()"></div>
<div class="sidebar" id="sidebar">
<div class="sidebar-inner">
<div class="sidebar-brand">
<h2><img src="ecustcic.png" alt="" style="height:28px;vertical-align:middle;margin-right:8px">NIC</h2>
<span>ECUSTCIC 域名分发系统</span>
</div>
<div class="nav-item active" data-page="dashboard" onclick="navigate('dashboard')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg>
仪表盘
</div>
<div class="nav-item" data-page="apply" onclick="navigate('apply')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>
申请域名
</div>
<div class="nav-item" data-page="my-applications" onclick="navigate('my-applications')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
我的申请
</div>
<div id="admin-nav" class="hidden">
<div class="nav-section">管理员</div>
<div class="nav-item" data-page="review" onclick="navigate('review')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 12l2 2 4-4"/><path d="M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z"/></svg>
审核申请
</div>
<div class="nav-item" data-page="providers" onclick="navigate('providers')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>
DNS 服务商
</div>
<div class="nav-item" data-page="domains" onclick="navigate('domains')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
根域名
</div>
<div class="nav-item" data-page="records" onclick="navigate('records')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
DNS 记录
</div>
<div class="nav-item" data-page="settings" onclick="navigate('settings')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>
系统设置
</div>
</div>
<div class="user-info" id="user-info"></div>
<div class="nav-item" style="border-top:1px solid var(--border);color:var(--error)" onclick="logout()">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
退出登录
</div>
</div>
</div>
<div class="main" id="main-content">
<div class="top-bar">
<button class="theme-toggle" onclick="toggleTheme()" id="theme-toggle-desktop">🌙</button>
</div>
</div>
</div>
<div id="modal-container" class="hidden"></div>
<script>
let token = null;
let currentUser = null;
let currentPage = 'dashboard';
let providersCache = [];
let domainsCache = [];
function getSystemTheme() {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
function getTheme() {
const saved = localStorage.getItem('theme');
if (saved) return saved;
return getSystemTheme();
}
function setTheme(theme, save) {
document.documentElement.setAttribute('data-theme', theme);
if (save !== false) localStorage.setItem('theme', theme);
const icon = theme === 'dark' ? '🌙' : '☀️';
const dt = document.getElementById('theme-toggle-desktop');
const mt = document.getElementById('theme-toggle-mobile');
if (dt) dt.textContent = icon;
if (mt) mt.textContent = icon;
}
function toggleTheme() {
const current = getTheme();
setTheme(current === 'dark' ? 'light' : 'dark', true);
}
setTheme(getTheme(), false);
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
if (!localStorage.getItem('theme')) {
setTheme(e.matches ? 'dark' : 'light', false);
}
});
function toggleSidebar() {
document.getElementById('sidebar').classList.toggle('open');
document.getElementById('sidebar-backdrop').classList.toggle('open');
}
function closeSidebar() {
document.getElementById('sidebar').classList.remove('open');
document.getElementById('sidebar-backdrop').classList.remove('open');
}
function getToken() {
if (token) return token;
const stored = localStorage.getItem('session_token');
if (stored) { token = stored; return stored; }
const params = new URLSearchParams(window.location.search);
const t = params.get('token');
if (t) {
token = t;
localStorage.setItem('session_token', t);
window.history.replaceState({}, '', window.location.pathname);
return t;
}
return null;
}
async function api(path, options = {}) {
const t = getToken();
const headers = { 'Content-Type': 'application/json', ...(options.headers || {}) };
if (t) headers['Authorization'] = `Bearer ${t}`;
const resp = await fetch(path, { ...options, headers });
if (resp.status === 401) {
localStorage.removeItem('session_token');
token = null;
currentUser = null;
showLogin();
throw new Error('Unauthorized');
}
return resp;
}
function showLogin() {
document.getElementById('login-page').classList.remove('hidden');
document.getElementById('app').classList.add('hidden');
}
function showApp() {
document.getElementById('login-page').classList.add('hidden');
document.getElementById('app').classList.remove('hidden');
}
function loginWithSkin() {
window.location.href = '/api/auth/login?redirect_uri=' + encodeURIComponent(window.location.origin);
}
async function logout() {
try { await api('/api/auth/logout', { method: 'POST' }); } catch(e) {}
localStorage.removeItem('session_token');
token = null;
currentUser = null;
showLogin();
}
function toast(msg, type = 'success') {
const el = document.createElement('div');
el.className = `toast toast-${type}`;
el.textContent = msg;
document.body.appendChild(el);
setTimeout(() => el.remove(), 3000);
}
function formatDate(ts) {
if (!ts) return '-';
return new Date(ts).toLocaleString('zh-CN');
}
function navigate(page) {
currentPage = page;
document.querySelectorAll('.nav-item').forEach(n => {
n.classList.toggle('active', n.dataset.page === page);
});
closeSidebar();
renderPage();
}
function wrapTable(html) {
return `<div class="table-wrap">${html}</div>`;
}
async function renderPage() {
const main = document.getElementById('main-content');
const topBar = '<div class="top-bar"><button class="theme-toggle" onclick="toggleTheme()" id="theme-toggle-desktop">' + (getTheme() === 'dark' ? '🌙' : '☀️') + '</button></div>';
switch(currentPage) {
case 'dashboard': await renderDashboard(main, topBar); break;
case 'apply': await renderApply(main, topBar); break;
case 'my-applications': await renderMyApplications(main, topBar); break;
case 'review': await renderReview(main, topBar); break;
case 'providers': await renderProviders(main, topBar); break;
case 'domains': await renderDomains(main, topBar); break;
case 'records': await renderRecords(main, topBar); break;
case 'settings': await renderSettings(main, topBar); break;
}
}
async function renderDashboard(el, topBar) {
const [domResp, appResp] = await Promise.all([api('/api/domains'), api('/api/applications')]);
const domData = await domResp.json();
const appData = await appResp.json();
domainsCache = domData.domains || [];
const apps = appData.applications || [];
const pending = apps.filter(a => a.status === 'pending').length;
const approved = apps.filter(a => a.status === 'approved').length;
const myApps = apps.filter(a => a.uid === currentUser.uid);
el.innerHTML = `
${topBar}
<div class="page-header"><h1>仪表盘</h1></div>
<div class="stats">
<div class="stat-card"><div class="label">可用根域名</div><div class="value">${domainsCache.length}</div></div>
<div class="stat-card"><div class="label">我的申请</div><div class="value">${myApps.length}</div></div>
${currentUser.isAdmin ? `
<div class="stat-card"><div class="label">待审核</div><div class="value" style="color:var(--warning)">${pending}</div></div>
<div class="stat-card"><div class="label">已通过</div><div class="value" style="color:var(--success)">${approved}</div></div>
` : ''}
</div>
<div class="card">
<div class="card-title">可用根域名</div>
${domainsCache.length ? wrapTable(`
<table>
<thead><tr><th>域名</th><th>描述</th><th>操作</th></tr></thead>
<tbody>
${domainsCache.map(d => `<tr><td>${d.root_domain}</td><td>${d.description || '-'}</td><td><button class="btn btn-sm btn-primary" onclick="navigate('apply')">申请子域名</button></td></tr>`).join('')}
</tbody>
</table>`) : '<div class="empty-state"><p>暂无可用域名</p></div>'}
</div>
${myApps.length ? `
<div class="card">
<div class="card-title">我的最近申请</div>
${wrapTable(`<table>
<thead><tr><th>域名</th><th>类型</th><th>值</th><th>状态</th><th>时间</th></tr></thead>
<tbody>
${myApps.slice(0, 5).map(a => `<tr>
<td>${a.subdomain}.${a.root_domain}</td><td>${a.type}</td>
<td style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${a.value}</td>
<td><span class="badge badge-${a.status}">${a.status === 'approved' ? '已通过' : a.status === 'rejected' ? '已拒绝' : '审核中'}</span></td>
<td>${formatDate(a.created)}</td>
</tr>`).join('')}
</tbody>
</table>`)}
</div>` : ''}
`;
}
async function renderApply(el, topBar) {
const [domResp, provResp] = await Promise.all([api('/api/domains'), api('/api/providers')]);
const domData = await domResp.json();
const provData = await provResp.json();
domainsCache = domData.domains || [];
providersCache = provData.providers || [];
if (!domainsCache.length) {
el.innerHTML = `${topBar}<div class="empty-state"><h2>暂无可用域名</h2><p>请等待管理员添加根域名</p></div>`;
return;
}
const firstDomain = domainsCache[0];
const firstProv = providersCache.find(p => p.id === firstDomain.provider_id);
const isCF = firstProv?.type === 'cloudflare';
el.innerHTML = `
${topBar}
<div class="page-header"><h1>申请子域名</h1></div>
<div class="card">
<div class="form-group"><label>根域名</label><select id="apply-domain" onchange="onApplyDomainChange()">${domainsCache.map(d => `<option value="${d.id}">${d.root_domain}${d.description ? ' - ' + d.description : ''}</option>`).join('')}</select></div>
<div class="form-group"><label>子域名</label><input id="apply-subdomain" placeholder="例如: myname, blog, www"><p style="font-size:12px;color:var(--text-dim);margin-top:4px">完整域名: <span id="apply-preview">${firstDomain.root_domain}</span></p><p id="apply-subdomain-hint" class="hidden" style="font-size:12px;color:var(--warning);margin-top:4px">SRV 记录子域名格式: _服务._协议,例如 _minecraft._tcp</p></div>
<div class="form-group"><label>记录类型</label><select id="apply-type" onchange="onTypeChange()"><option value="A">A (IPv4 地址)</option><option value="AAAA">AAAA (IPv6 地址)</option><option value="CNAME">CNAME (别名)</option><option value="TXT">TXT (文本记录)</option><option value="MX">MX (邮件交换)</option><option value="SRV">SRV (服务记录)</option></select></div>
<div class="form-group"><label>记录值</label><input id="apply-value" placeholder="例如: 1.2.3.4 或 example.com"></div>
<div id="apply-proxied-wrap" class="form-group" style="${isCF ? '' : 'display:none'}"><label style="display:flex;align-items:center;gap:8px;cursor:pointer;margin-bottom:0"><input type="checkbox" id="apply-proxied" style="width:auto;margin:0"> 开启 Cloudflare 代理(橙色云)</label><p style="font-size:12px;color:var(--text-dim);margin-top:4px">开启后流量将通过 Cloudflare 代理,支持 CDN 加速和 DDoS 防护,但部分服务(如邮件、游戏服务器)可能不兼容</p></div>
<div class="form-group"><label>申请理由</label><textarea id="apply-reason" placeholder="简要说明用途"></textarea></div>
<button class="btn btn-primary" onclick="submitApplication()">提交申请</button>
</div>
`;
const domainSelect = document.getElementById('apply-domain');
const subInput = document.getElementById('apply-subdomain');
const preview = document.getElementById('apply-preview');
function updatePreview() {
const dom = domainsCache.find(d => d.id === domainSelect.value);
const sub = subInput.value.trim();
preview.textContent = sub ? `${sub}.${dom?.root_domain || ''}` : (dom?.root_domain || '');
}
domainSelect.addEventListener('change', updatePreview);
subInput.addEventListener('input', updatePreview);
}
function onApplyDomainChange() {
const domainId = document.getElementById('apply-domain').value;
const dom = domainsCache.find(d => d.id === domainId);
const prov = providersCache.find(p => p.id === dom?.provider_id);
const wrap = document.getElementById('apply-proxied-wrap');
if (wrap) wrap.style.display = prov?.type === 'cloudflare' ? '' : 'none';
if (prov?.type !== 'cloudflare') {
const cb = document.getElementById('apply-proxied');
if (cb) cb.checked = false;
}
}
function onTypeChange() {
const type = document.getElementById('apply-type').value;
const hint = document.getElementById('apply-subdomain-hint');
const valueInput = document.getElementById('apply-value');
if (type === 'SRV') { hint.classList.remove('hidden'); valueInput.placeholder = '例如: 10 5 25565 target.example.com'; }
else { hint.classList.add('hidden'); valueInput.placeholder = '例如: 1.2.3.4 或 example.com'; }
const proxiedWrap = document.getElementById('apply-proxied-wrap');
const proxiedCb = document.getElementById('apply-proxied');
const noProxyTypes = ['TXT', 'MX', 'SRV'];
if (noProxyTypes.includes(type)) {
if (proxiedWrap) proxiedWrap.style.display = 'none';
if (proxiedCb) proxiedCb.checked = false;
} else {
const domainId = document.getElementById('apply-domain').value;
const dom = domainsCache.find(d => d.id === domainId);
const prov = providersCache.find(p => p.id === dom?.provider_id);
if (proxiedWrap) proxiedWrap.style.display = prov?.type === 'cloudflare' ? '' : 'none';
}
}
async function submitApplication() {
const domain_id = document.getElementById('apply-domain').value;
const subdomain = document.getElementById('apply-subdomain').value.trim();
const type = document.getElementById('apply-type').value;
const value = document.getElementById('apply-value').value.trim();
const reason = document.getElementById('apply-reason').value.trim();
const proxiedEl = document.getElementById('apply-proxied');
const proxied = proxiedEl && proxiedEl.checked;
if (!subdomain || !value) { toast('请填写子域名和记录值', 'error'); return; }
if (type === 'SRV') { if (!/^_[a-zA-Z0-9-]+\._[a-zA-Z0-9-]+/.test(subdomain)) { toast('SRV 子域名格式应为 _服务._协议', 'error'); return; } }
else { if (!/^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$/.test(subdomain)) { toast('子域名只能包含字母、数字和连字符', 'error'); return; } }
try {
const resp = await api('/api/applications', { method: 'POST', body: JSON.stringify({ domain_id, subdomain, type, value, reason, proxied }) });
if (!resp.ok) { const data = await resp.json(); toast(data.error || '提交失败', 'error'); return; }
toast('申请已提交,请等待审核');
navigate('my-applications');
} catch(e) { toast(e.message, 'error'); }
}
async function renderMyApplications(el, topBar) {
const resp = await api('/api/applications');
const data = await resp.json();
const apps = data.applications || [];
el.innerHTML = `
${topBar}
<div class="page-header"><h1>我的申请</h1></div>
<div class="card">
${apps.length ? wrapTable(`<table>
<thead><tr><th>域名</th><th>类型</th><th>值</th><th>申请理由</th><th>状态</th><th>时间</th><th>操作</th></tr></thead>
<tbody>${apps.map(a => `<tr>
<td>${a.subdomain}.${a.root_domain}</td><td>${a.type}${a.proxied ? ' <span style="font-size:11px;color:var(--warning)">☁ 代理</span>' : ''}</td>
<td style="max-width:180px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${a.value}">${a.value}</td>
<td style="max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${a.reason}">${a.reason || '-'}</td>
<td><span class="badge badge-${a.status}">${a.status === 'approved' ? '已通过' : a.status === 'rejected' ? '已拒绝' : '审核中'}</span>${a.status === 'rejected' && a.reject_reason ? `<p style="font-size:12px;color:var(--danger);margin-top:4px" title="${a.reject_reason}">${a.reject_reason.length > 30 ? a.reject_reason.slice(0, 30) + '...' : a.reject_reason}</p>` : ''}</td>
<td>${formatDate(a.created)}</td>
<td class="actions-cell">${a.status !== 'pending' ? `<button class="btn btn-sm btn-danger" onclick="deleteApplication('${a.id}')">删除</button>` : `<button class="btn btn-sm btn-danger" onclick="cancelApplication('${a.id}')">撤回</button>`}</td>
</tr>`).join('')}</tbody>
</table>`) : '<div class="empty-state"><p>暂无申请记录</p></div>'}
</div>
`;
}
async function cancelApplication(id) {
if (!confirm('确定要撤回此申请吗?')) return;
try {
const resp = await api(`/api/applications/${id}`, { method: 'DELETE' });
if (!resp.ok) { const data = await resp.json(); throw new Error(data.error || '操作失败'); }
toast('申请已撤回'); renderPage();
} catch(e) { toast(e.message, 'error'); }
}
async function deleteApplication(id) {
if (!confirm('确定要删除此申请记录吗?已通过的申请删除后将同时移除对应 DNS 记录。')) return;
try {
const resp = await api(`/api/applications/${id}`, { method: 'DELETE' });
if (!resp.ok) { const data = await resp.json(); throw new Error(data.error || '操作失败'); }
toast('已删除'); renderPage();
} catch(e) { toast(e.message, 'error'); }
}
async function checkDNS(domainId, subdomain, appId) {
const cell = document.getElementById(`dns-check-${appId}`);
if (!cell) return;
cell.innerHTML = '<span style="color:var(--text-dim);font-size:12px">检查中...</span>';
try {
const resp = await api(`/api/domains/${domainId}/check?subdomain=${encodeURIComponent(subdomain)}`);
const data = await resp.json();
if (data.records && data.records.length > 0) { cell.innerHTML = `<span class="badge badge-error" style="cursor:pointer" title="${data.records.map(r => r.type + ' → ' + r.value).join('\n')}">⚠ 已占用 (${data.records.length})</span>`; }
else if (data.error) { cell.innerHTML = `<span class="badge badge-pending" title="${data.error}">查询失败</span>`; }
else { cell.innerHTML = '<span class="badge badge-active">✓ 可用</span>'; }
} catch(e) { cell.innerHTML = '<span class="badge badge-pending">查询失败</span>'; }
}
async function renderReview(el, topBar) {
if (!currentUser.isAdmin) { el.innerHTML = `${topBar}<div class="empty-state"><h2>无权限</h2></div>`; return; }
const [appResp, domResp] = await Promise.all([api('/api/applications'), api('/api/domains')]);
const appData = await appResp.json();
const domData = await domResp.json();
domainsCache = domData.domains || [];
const apps = appData.applications || [];
const pending = apps.filter(a => a.status === 'pending');
const processed = apps.filter(a => a.status !== 'pending');
el.innerHTML = `
${topBar}
<div class="page-header"><h1>审核申请</h1></div>
<div class="card">
<div class="card-title">待审核 (${pending.length})</div>
${pending.length ? wrapTable(`<table>
<thead><tr><th>申请人</th><th>域名</th><th>类型</th><th>值</th><th>理由</th><th>DNS</th><th>时间</th><th>操作</th></tr></thead>
<tbody>${pending.map(a => `<tr id="review-row-${a.id}">
<td>${a.nickname} <span style="color:var(--text-dim);font-size:12px">(UID:${a.uid})</span></td>
<td>${a.subdomain}.${a.root_domain}</td><td>${a.type}${a.proxied ? ' <span style="font-size:11px;color:var(--warning)">☁ 代理</span>' : ''}</td>
<td style="max-width:180px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${a.value}">${a.value}</td>
<td style="max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${a.reason}">${a.reason || '-'}</td>
<td id="dns-check-${a.id}"><button class="btn btn-sm" onclick="checkDNS('${a.domain_id}','${a.subdomain}','${a.id}')">检查</button></td>
<td>${formatDate(a.created)}</td>
<td class="actions-cell"><button class="btn btn-sm btn-success" onclick="reviewApp('${a.id}','approve')">通过</button><button class="btn btn-sm btn-danger" onclick="showRejectModal('${a.id}')">拒绝</button></td>
</tr>`).join('')}</tbody>
</table>`) : '<div class="empty-state"><p>暂无待审核申请</p></div>'}
</div>
<div class="card">
<div class="card-title">已处理 (${processed.length})</div>
${processed.length ? wrapTable(`<table>
<thead><tr><th>申请人</th><th>域名</th><th>类型</th><th>值</th><th>状态</th><th>处理时间</th></tr></thead>
<tbody>${processed.map(a => `<tr>
<td>${a.nickname}</td><td>${a.subdomain}.${a.root_domain}</td><td>${a.type}${a.proxied ? ' <span style="font-size:11px;color:var(--warning)">☁ 代理</span>' : ''}</td>
<td style="max-width:180px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${a.value}</td>
<td><span class="badge badge-${a.status}">${a.status === 'approved' ? '已通过' : '已拒绝'}</span></td>
<td>${formatDate(a.reviewed_at)}</td>
</tr>`).join('')}</tbody>
</table>`) : '<div class="empty-state"><p>暂无已处理记录</p></div>'}
</div>
`;
}
function showRejectModal(id) {
const container = document.getElementById('modal-container');
container.classList.remove('hidden');
container.innerHTML = `<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal"><h3>拒绝申请</h3><div class="form-group"><label>拒绝理由</label><textarea id="reject-reason" placeholder="可选,说明拒绝原因"></textarea></div><div class="form-actions"><button class="btn" onclick="closeModal()">取消</button><button class="btn btn-danger" onclick="reviewApp('${id}','reject')">确认拒绝</button></div></div></div>`;
}
async function reviewApp(id, action) {
const body = { action };
if (action === 'reject') { const reason = document.getElementById('reject-reason'); if (reason) body.reason = reason.value.trim(); }
try {
const resp = await api(`/api/applications/${id}`, { method: 'POST', body: JSON.stringify(body) });
if (!resp.ok) { const data = await resp.json(); throw new Error(data.error || '操作失败'); }
toast(action === 'approve' ? '已通过' : '已拒绝'); closeModal(); renderPage();
} catch(e) { toast(e.message, 'error'); }
}
async function renderProviders(el, topBar) {
const resp = await api('/api/providers');
const data = await resp.json();
providersCache = data.providers || [];
el.innerHTML = `
${topBar}
<div class="page-header"><h1>DNS 服务商</h1><button class="btn btn-primary" onclick="showProviderModal()">+ 添加服务商</button></div>
<div class="card">
${providersCache.length ? wrapTable(`<table>
<thead><tr><th>名称</th><th>类型</th><th>创建时间</th><th>操作</th></tr></thead>
<tbody>${providersCache.map(p => `<tr><td>${p.name}</td><td><span class="badge ${p.type === 'cloudflare' ? 'badge-cf' : 'badge-dp'}">${p.type === 'cloudflare' ? 'Cloudflare' : 'DNSPod'}</span></td><td>${formatDate(p.created)}</td><td class="actions-cell"><button class="btn btn-sm" onclick="showProviderModal('${p.id}')">编辑</button><button class="btn btn-sm btn-danger" onclick="deleteProvider('${p.id}')">删除</button></td></tr>`).join('')}</tbody>
</table>`) : '<div class="empty-state"><p>暂无服务商</p></div>'}
</div>
`;
}
function showProviderModal(id) {
const provider = id ? providersCache.find(p => p.id === id) : null;
const isCf = provider ? provider.type === 'cloudflare' : true;
const container = document.getElementById('modal-container');
container.classList.remove('hidden');
container.innerHTML = `<div class="modal-overlay" onclick="if(event.target===this)closeModal()"><div class="modal">
<h3>${provider ? '编辑服务商' : '添加服务商'}</h3>
<div class="form-group"><label>名称</label><input id="prov-name" value="${provider?.name || ''}" placeholder="例如: 我的Cloudflare"></div>
<div class="form-group"><label>类型</label><select id="prov-type" onchange="toggleProviderFields()"><option value="cloudflare" ${isCf ? 'selected' : ''}>Cloudflare</option><option value="dnspod" ${!isCf ? 'selected' : ''}>DNSPod (腾讯云)</option></select></div>
<div id="cf-fields" style="display:${isCf ? 'block' : 'none'}"><div class="form-group"><label>Zone ID</label><input id="cf-zone-id" value="${provider?.config?.zone_id || ''}" placeholder="Cloudflare Zone ID"></div><div class="form-group"><label>API Token</label><input id="cf-api-token" type="password" value="${provider?.config?.api_token || ''}" placeholder="Cloudflare API Token"></div></div>
<div id="dp-fields" style="display:${!isCf ? 'block' : 'none'}"><div class="form-group"><label>SecretId</label><input id="dp-secret-id" value="${provider?.config?.secret_id || ''}" placeholder="腾讯云 SecretId"></div><div class="form-group"><label>SecretKey</label><input id="dp-secret-key" type="password" value="${provider?.config?.secret_key || ''}" placeholder="腾讯云 SecretKey"></div></div>
<div class="form-actions"><button class="btn" onclick="closeModal()">取消</button><button class="btn btn-primary" onclick="saveProvider('${id || ''}')">${provider ? '保存' : '创建'}</button></div>
</div></div>`;
}
function toggleProviderFields() {
const type = document.getElementById('prov-type').value;
document.getElementById('cf-fields').style.display = type === 'cloudflare' ? 'block' : 'none';