Repository navigation
Expand file tree
/
Copy pathsettings.html
More file actions
1487 lines (1402 loc) · 69.2 KB
/
Copy pathsettings.html
File metadata and controls
1487 lines (1402 loc) · 69.2 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="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Settings — Server Hub</title>
<link rel="icon" type="image/png" href="logo.png" />
<link rel="preconnect" href="https://cdn.tailwindcss.com" crossorigin />
<link rel="preconnect" href="https://images.pexels.com" crossorigin />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet" />
<script>
tailwind.config = { darkMode: 'class', theme: { extend: {
fontFamily: {
sans: ['Inter', 'ui-sans-serif', 'system-ui', 'sans-serif'],
mono: ['Fira Code', 'ui-monospace', 'monospace'],
},
}}};
</script>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
<script src="settings.js"></script>
<script src="categorize.js"></script>
<script defer src="https://cdn.vercel-insights.com/v1/script.js"></script>
<style>
:root {
--bg-deep: #020203; --bg-elev: #0a0a0c;
--surface: rgba(255,255,255,0.05); --surface-hi: rgba(255,255,255,0.08);
--border: rgba(255,255,255,0.08); --border-hi: rgba(255,255,255,0.16);
--fg: #EDEDEF; --fg-muted: #8A8F98;
--accent: #5E6AD2; --accent-glow: rgba(94,106,210,0.20);
--green: #22C55E; --red: #EF4444;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
}
html.light {
--bg-deep: #f4f6fb; --bg-elev: #fbfcfe;
--surface: rgba(15,23,42,0.04); --surface-hi: rgba(15,23,42,0.08);
--border: rgba(15,23,42,0.10); --border-hi: rgba(15,23,42,0.20);
--fg: #0F172A; --fg-muted: #5a6072;
--accent: #4f56c0; --accent-glow: rgba(79,86,192,0.18);
--green: #16a34a; --red: #dc2626;
}
html, body { background-color: var(--bg-deep); color: var(--fg); }
body {
background: var(--bg-deep);
background-image:
linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
background-size: 32px 32px;
min-height: 100vh;
transition: background-color 400ms var(--ease), color 400ms var(--ease);
}
html.light body {
background-image:
linear-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px),
linear-gradient(90deg, rgba(0, 0, 0, 0.04) 1px, transparent 1px);
}
/* Wallpaper readability — html.wallpaper-light / html.wallpaper-dark
toggled by HubSettings.applyWallpaper (settings.js). Keeps glass + text
readable over any wallpaper; .wallpaper is set on <body>. The body's own
opaque gradient is cleared so the fixed #wallpaper layer shows through. */
html.wallpaper-light { --surface: rgba(255,255,255,0.75); --surface-hi: rgba(255,255,255,0.85); --border: rgba(0,0,0,0.12); --border-hi: rgba(0,0,0,0.2); --fg: #111318; --fg-muted: #3d4148; }
html.wallpaper-light .glass { backdrop-filter: blur(14px); }
html.wallpaper-dark { --surface: rgba(0,0,0,0.55); --surface-hi: rgba(0,0,0,0.65); --border: rgba(255,255,255,0.1); --border-hi: rgba(255,255,255,0.18); --fg: #EDEDEF; --fg-muted: #A7ABB3; }
html.wallpaper-dark .glass { backdrop-filter: blur(14px); }
/* Light theme wins over wallpaper readability classes (see index.html). */
html.light.wallpaper-dark,
html.light.wallpaper-light {
--surface: rgba(255,255,255,0.92); --surface-hi: rgba(255,255,255,0.96);
--border: rgba(15,23,42,0.12); --border-hi: rgba(15,23,42,0.20);
--fg: #0F172A; --fg-muted: #5a6072;
}
html.light.wallpaper-dark .glass,
html.light.wallpaper-light .glass { backdrop-filter: blur(16px); }
html.wallpaper .glass, body.wallpaper .glass { box-shadow: 0 4px 24px -8px rgba(0,0,0,0.35); }
body.wallpaper { background-color: transparent; background-image: none; }
html.wallpaper-dark, html.wallpaper-light { background-color: transparent; }
/* Wallpaper layer — fixed, viewport-sized, behind content (z-index -1).
`cover` is computed against the viewport, so navigating or content
height changes never re-scale the image (no zoom); opacity cross-fades
smoothly via the wp-active class. */
#wallpaper {
position: fixed;
inset: 0;
z-index: -1;
pointer-events: none;
background-image: var(--wp-image, none);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
opacity: 0;
transition: opacity 700ms var(--ease);
}
body.wallpaper.wp-active #wallpaper {
opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
#wallpaper { transition: none; }
}
.glass {
background: var(--surface);
backdrop-filter: blur(18px) saturate(140%);
-webkit-backdrop-filter: blur(18px) saturate(140%);
border: 1px solid var(--border); border-radius: 16px;
transition: background-color 300ms var(--ease), border-color 300ms var(--ease);
isolation: isolate;
}
.section {
animation: section-in 360ms var(--ease) both;
}
.section:nth-child(2) { animation-delay: 40ms; }
.section:nth-child(3) { animation-delay: 80ms; }
.section:nth-child(4) { animation-delay: 120ms; }
.section:nth-child(5) { animation-delay: 160ms; }
.section:nth-child(6) { animation-delay: 200ms; }
@keyframes section-in {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.field {
background: transparent; border: 1px solid var(--border); border-radius: 10px;
color: var(--fg); padding: 0.55rem 0.75rem; font-size: 0.875rem; width: 100%;
transition: border-color 200ms var(--ease), background-color 200ms var(--ease);
}
.field:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.field::placeholder { color: var(--fg-muted); }
.btn {
padding: 0.5rem 1rem; border-radius: 10px; font-size: 0.875rem; font-weight: 500;
cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--fg);
transition: background-color 200ms var(--ease), border-color 200ms var(--ease), transform 150ms var(--ease);
}
.btn:hover { background: var(--surface-hi); border-color: var(--border-hi); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.btn-danger:hover { background: color-mix(in srgb, var(--red) 12%, var(--surface)); }
.section { padding: 1.25rem; }
.h2 { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-muted); }
.switch {
position: relative; width: 42px; height: 24px; border-radius: 9999px;
background: var(--surface-hi); border: 1px solid var(--border); cursor: pointer;
transition: background-color 200ms var(--ease); flex-shrink: 0;
}
.switch.on { background: var(--accent); border-color: transparent; }
.switch::after {
content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
background: var(--fg); border-radius: 9999px; transition: transform 200ms var(--ease);
}
.switch.on::after { transform: translateX(18px); background: white; }
.swatch {
width: 28px; height: 28px; border-radius: 8px; cursor: pointer;
border: 2px solid transparent; transition: transform 150ms var(--ease), border-color 150ms var(--ease);
}
.swatch:hover { transform: scale(1.1); }
.swatch.active { border-color: var(--fg); }
.pill {
display: inline-block; padding: 2px 8px; border-radius: 9999px;
font-size: 11px; font-family: 'Fira Code', monospace;
border: 1px solid var(--border); color: var(--fg-muted); background: var(--surface);
}
.toast {
position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
padding: 0.6rem 1.1rem; border-radius: 10px; font-size: 0.85rem;
background: var(--accent); color: white; box-shadow: 0 8px 24px -8px var(--accent-glow);
opacity: 0; pointer-events: none; transition: opacity 300ms var(--ease), transform 300ms var(--ease);
z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, -8px); }
.row-grid { display: grid; gap: 0.65rem; }
.focus-ring:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.svc-row {
display: grid; grid-template-columns: 1.4fr 1.6fr 1.6fr auto auto auto; gap: 8px; align-items: center;
}
/* Add-form: description on its own row so URL input isn't cramped (user request). */
#add-form .svc-row { grid-template-columns: 1.15fr 1.85fr auto auto; }
/* Bookmarks: color picker same width as Add button, Name 30% / URL 70% */
#bm-add-form .svc-row { grid-template-columns: minmax(0,0.9fr) minmax(0,2.1fr) 64px 64px; }
#bm-add-form #bm-new-color { width: 64px; height: 38px; padding: 3px; cursor: pointer; }
#bm-add-form #bm-save { width: 64px; justify-content: center; display: inline-flex; align-items: center; }
.svc-color { width: 2.25rem; height: 2rem; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer; }
@media (max-width: 720px) { .svc-row, #add-form .svc-row, #bm-add-form .svc-row { grid-template-columns: 1fr; } .svc-row .hide-sm { display: none; } #bm-add-form #bm-new-color, #bm-add-form #bm-save { width: 100%; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } .section { animation: none; } }
@media (max-width: 768px), (pointer: coarse), (hover: none) {
.glass,
html.wallpaper-light .glass,
html.wallpaper-dark .glass {
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
}
.section { animation: none !important; }
.btn:hover, .swatch:hover { transform: none !important; }
}
</style>
</head>
<body class="font-sans antialiased">
<div id="wallpaper" aria-hidden="true"></div>
<main class="mx-auto w-full max-w-3xl px-4 sm:px-6 py-10 space-y-6">
<header class="flex items-center justify-between gap-3">
<div>
<h1 class="text-2xl sm:text-3xl font-semibold tracking-tight">Settings</h1>
<p class="text-sm text-[color:var(--fg-muted)] mt-1"></p>
</div>
<a href="index.html" class="btn focus-ring" aria-label="Back to dashboard">← Back</a>
</header>
<!-- Appearance -->
<section class="glass section">
<h2 class="h2 mb-4">Appearance</h2>
<!-- Theme -->
<div class="row-grid">
<div class="flex items-center justify-between">
<div>
<p class="font-medium text-sm">Theme</p>
<p class="text-xs text-[color:var(--fg-muted)]">Auto follows your system preference.</p>
</div>
<div class="flex gap-2" role="radiogroup" aria-label="Theme">
<button class="btn theme-opt focus-ring" data-theme="auto">Auto</button>
<button class="btn theme-opt focus-ring" data-theme="light">Light</button>
<button class="btn theme-opt focus-ring" data-theme="dark">Dark</button>
</div>
</div>
<!-- Accent color -->
<div class="flex items-center justify-between pt-2">
<div>
<p class="font-medium text-sm">Accent color</p>
<p class="text-xs text-[color:var(--fg-muted)]">Used for buttons, bars, and the FAB.</p>
</div>
<div class="flex items-center gap-2 flex-wrap justify-end">
<div class="flex gap-1.5" id="swatches" role="group" aria-label="Accent presets"></div>
<label class="flex items-center gap-1.5">
<input id="accent-custom" type="color" class="w-9 h-9 rounded-lg cursor-pointer border-0 bg-transparent focus-ring" aria-label="Custom accent color" />
<span class="text-xs text-[color:var(--fg-muted)]">custom</span>
</label>
</div>
</div>
<!-- Wallpaper -->
<div class="flex items-center justify-between pt-2">
<div>
<p class="font-medium text-sm">Wallpaper</p>
<p class="text-xs text-[color:var(--fg-muted)]">Choose a background for the dashboard. Changes preview live.</p>
</div>
<div class="flex items-center gap-2 flex-wrap justify-end">
<button id="wp-none" class="btn focus-ring" aria-pressed="false">None</button>
<div class="flex gap-1.5" id="wp-gradients" role="group" aria-label="Wallpaper gradients"></div>
</div>
</div>
<div class="flex items-center justify-between pt-2">
<div>
<p class="font-medium text-sm">Featured</p>
<p class="text-xs text-[color:var(--fg-muted)]">One-click preset — no URL needed.</p>
</div>
<div class="flex items-center gap-2">
<button id="wp-preset-pexels" class="swatch focus-ring" style="width:64px;height:40px;background: url('https://images.pexels.com/photos/2387819/pexels-photo-2387819.jpeg') center/cover no-repeat" aria-label="Use Pexels mountain wallpaper" title="Pexels — Mountain (click to apply)"></button>
<span class="text-xs text-[color:var(--fg-muted)] hidden sm:inline">Pexels Mountain</span>
</div>
</div>
<div class="flex items-center justify-between pt-2">
<div>
<p class="font-medium text-sm">Grid overlay</p>
<p class="text-xs text-[color:var(--fg-muted)]">Show the subtle grid on top of every background.</p>
</div>
<button id="wp-grid-toggle" type="button" class="switch focus-ring" role="switch" aria-checked="true" aria-label="Toggle grid overlay" style="pointer-events:auto; position:relative; z-index:1;"></button>
</div>
<div class="flex items-center gap-2 pt-2">
<input id="wp-url" class="field focus-ring flex-1" type="text" placeholder="Custom image URL (https://…)" aria-label="Custom wallpaper URL" />
<button id="wp-apply" class="btn btn-primary focus-ring text-xs">Apply</button>
</div>
</div>
</section>
<!-- Personalization -->
<section class="glass section">
<h2 class="h2 mb-4">Personalization</h2>
<div class="row-grid">
<label class="block">
<span class="text-sm font-medium">Your name <span class="text-[color:var(--fg-muted)] text-xs">(optional, shown in greeting)</span></span>
<input id="user-name" class="field mt-1.5" placeholder="Your Name" autocomplete="off" />
</label>
<label class="block">
<span class="text-sm font-medium">Page title</span>
<input id="page-title" class="field mt-1.5" placeholder="Server Hub" maxlength="60" />
</label>
<label class="block">
<span class="text-sm font-medium">Subtitle</span>
<input id="subtitle" class="field mt-1.5" placeholder="Simple Hub For All Your Services" maxlength="120" />
</label>
</div>
<div class="flex items-center justify-between pt-2">
<div>
<p class="font-medium text-sm">Default domain</p>
<p class="text-xs text-[color:var(--fg-muted)]">A bare subdomain in the add form is expanded with this domain (e.g. "n8n" → "n8n.<domain>").</p>
</div>
<input id="default-domain" class="field focus-ring w-56" placeholder="example.com" />
</div>
</section>
<!-- Features -->
<section class="glass section">
<h2 class="h2 mb-4">Features</h2>
<div class="space-y-3" id="feature-list">
<!-- Rendered by JS -->
</div>
<!-- System stats source (Beszel) - multi-instance -->
<div class="pt-3 mt-3 border-t border-[color:var(--border)]">
<div class="flex items-center justify-between gap-3">
<div class="min-w-0">
<p class="text-sm font-medium">System stats sources</p>
<p class="text-xs text-[color:var(--fg-muted)] mt-0.5">Add one or more Beszel hubs. Credentials are stored encrypted in your settings.</p>
</div>
</div>
<div id="beszel-list" class="space-y-3 mt-3"></div>
<button id="beszel-add" class="btn focus-ring text-xs mt-3">+ Add Beszel</button>
<p class="text-xs text-[color:var(--fg-muted)] mt-2">
Blank password keeps the saved value. Test per instance before saving.
</p>
</div>
</section>
<!-- Search provider -->
<section class="glass section">
<h2 class="h2 mb-4">Search</h2>
<div class="row-grid">
<div class="flex items-center justify-between">
<div>
<p class="font-medium text-sm">Web search provider</p>
<p class="text-xs text-[color:var(--fg-muted)]">Used when you press Enter in the search popup.</p>
</div>
<select id="search-provider" class="field focus-ring w-48">
<option value="google">Google</option>
<option value="ddg">DuckDuckGo</option>
<option value="bing">Bing</option>
<option value="startpage">Startpage</option>
<option value="searxng">SearXNG</option>
</select>
</div>
<div class="flex items-center justify-between" id="searxng-row" style="display:none">
<div>
<p class="font-medium text-sm">SearXNG URL</p>
<p class="text-xs text-[color:var(--fg-muted)]">e.g. https://searx.yourdomain.com</p>
</div>
<input id="searxng-url" class="field focus-ring w-64" placeholder="https://searx.example.com" />
</div>
</div>
</section>
<!-- Services editor -->
<section class="glass section">
<div class="flex items-center justify-between mb-4">
<h2 class="h2">Your links</h2>
<button id="add-svc" class="btn btn-primary focus-ring text-xs">+ Add link</button>
</div>
<p class="text-xs text-[color:var(--fg-muted)] mb-4">Links are stored permanently on the server and shared across all your devices.</p>
<div id="svc-list" class="space-y-2"></div>
<!-- Add new link form (collapsible) -->
<form id="add-form" class="hidden mt-4 pt-4 border-t border-[color:var(--border)]" autocomplete="off" novalidate>
<div class="space-y-2">
<div class="svc-row">
<input id="new-name" class="field focus-ring" placeholder="Name (e.g. Grafana)" />
<div class="flex gap-1 min-w-0">
<select id="new-scheme" class="field focus-ring w-28 shrink-0" aria-label="URL scheme">
<option value="https://" selected>https://</option>
<option value="http://">http://</option>
</select>
<input id="new-url" class="field focus-ring min-w-0 flex-1" type="text" placeholder="host (e.g. immich.domain.com)" />
</div>
<span class="hide-sm text-xs text-[color:var(--fg-muted)]">→ <span id="new-cat" class="pill">auto</span></span>
<button id="new-save" class="btn btn-primary focus-ring text-xs">Add</button>
</div>
<input id="new-desc" class="field focus-ring w-full" placeholder="Description (optional)" />
</div>
</form>
</section>
<!-- Bookmarks editor -->
<section class="glass section">
<div class="flex items-center justify-between mb-4">
<h2 class="h2">Bookmarks</h2>
<button id="add-bm" class="btn btn-primary focus-ring text-xs">+ Add bookmark</button>
</div>
<p class="text-xs text-[color:var(--fg-muted)] mb-4">Bookmarks are stored permanently on the server and shown on your dashboard.</p>
<div id="bm-list" class="space-y-2"></div>
<!-- Add new bookmark form (collapsible) -->
<form id="bm-add-form" class="hidden mt-4 pt-4 border-t border-[color:var(--border)]" autocomplete="off" novalidate>
<div class="svc-row">
<input id="bm-new-name" class="field focus-ring" placeholder="Name (e.g. YouTube)" />
<input id="bm-new-url" class="field focus-ring" type="text" placeholder="URL (e.g. https://youtube.com)" />
<input id="bm-new-color" class="field focus-ring" type="color" value="#5E6AD2" title="Dot color" />
<button id="bm-save" class="btn btn-primary focus-ring text-xs">Add</button>
</div>
</form>
</section>
<!-- Backup -->
<section class="glass section">
<h2 class="h2 mb-4">Two-factor authentication</h2>
<div class="flex items-center justify-between gap-3 flex-wrap">
<div class="min-w-0">
<p class="text-sm font-medium">Authenticator app (TOTP)</p>
<p id="twofa-status" class="text-xs text-[color:var(--fg-muted)] mt-0.5">Checking…</p>
</div>
<div class="flex gap-2">
<button id="twofa-enable" class="btn focus-ring text-xs hidden">Set up</button>
<button id="twofa-disable" class="btn btn-danger focus-ring text-xs hidden">Disable</button>
</div>
</div>
<div id="twofa-setup" class="hidden mt-4 pt-4 border-t border-[color:var(--border)]">
<p class="text-sm text-[color:var(--fg-muted)] mb-3">Scan the QR code with your authenticator app (Google Authenticator, Aegis, 1Password…), then enter the 6-digit code to confirm.</p>
<div class="flex flex-col sm:flex-row gap-4 items-start">
<div id="twofa-qr" class="bg-white rounded-xl p-3 shrink-0"></div>
<div class="w-full max-w-xs space-y-3">
<div>
<p class="text-xs text-[color:var(--fg-muted)] mb-1">Or enter this key manually</p>
<code id="twofa-secret" class="block text-xs break-all px-2 py-1.5 rounded-lg bg-[color:var(--surface-hi)]"></code>
</div>
<label class="block">
<span class="text-xs text-[color:var(--fg-muted)]">Verification code</span>
<input id="twofa-code" class="field mt-1.5" inputmode="numeric" maxlength="6" placeholder="000000" autocomplete="one-time-code" />
</label>
<button id="twofa-confirm" class="btn btn-primary focus-ring w-full">Confirm & enable</button>
</div>
</div>
</div>
<div id="twofa-off" class="hidden mt-3">
<p class="text-xs text-[color:var(--fg-muted)]"></p>
</div>
<div id="twofa-on" class="hidden mt-3">
<p class="text-xs text-[color:var(--fg-muted)]">2FA is <span class="text-[color:var(--green)] font-medium">enabled</span> — every sign-in requires a code from your authenticator app.</p>
</div>
</section>
<!-- Backup -->
<section class="glass section">
<h2 class="h2 mb-4">Backup</h2>
<div class="flex items-center justify-between gap-3 flex-wrap">
<p class="text-sm text-[color:var(--fg-muted)] max-w-md">Export all settings, links, and bookmarks to a JSON file. Import to restore.</p>
<div class="flex gap-2">
<button id="export-btn" class="btn focus-ring text-xs">Export</button>
<label class="btn focus-ring text-xs cursor-pointer">
Import
<input id="import-input" type="file" accept="application/json,.json" class="hidden" />
</label>
</div>
</div>
</section>
<!-- Danger zone -->
<section class="glass section">
<h2 class="h2 mb-3">Reset</h2>
<div class="flex items-center justify-between gap-3 flex-wrap">
<p class="text-sm text-[color:var(--fg-muted)] max-w-md">Wipe all settings (theme, accent, features). Links live on the server and are managed here.</p>
<button id="reset" class="btn btn-danger focus-ring">Reset all settings</button>
</div>
</section>
<footer class="pt-2 pb-8 text-center text-xs text-[color:var(--fg-muted)] font-mono">
Powered by <a href="https://github.com/eco-null/server-hub-multi" class="underline hover:text-[color:var(--accent)]" target="_blank" rel="noopener">Server Hub</a>
</footer>
</main>
<div id="toast" class="toast" role="status" aria-live="polite">Saved</div>
<script>
/* ============================================================
Wire settings UI to HubSettings
============================================================ */
const S = window.HubSettings;
const cur = S.get();
// Apply theme + accent to THIS page so previews match
S.apply(cur);
const ACCENT_PRESETS = ['#5E6AD2', '#22C55E', '#EAB308', '#F97316', '#EF4444', '#EC4899', '#8B5CF6', '#14B8A6', '#0EA5E9', '#64748B'];
function setThemeOpt(mode) {
document.querySelectorAll('.theme-opt').forEach(b => {
b.classList.toggle('btn-primary', b.dataset.theme === mode);
b.setAttribute('aria-pressed', String(b.dataset.theme === mode));
});
S.set({ theme: mode });
S.apply(S.get()); // refresh tokens on this page too
}
document.querySelectorAll('.theme-opt').forEach(b => {
b.addEventListener('click', () => setThemeOpt(b.dataset.theme));
});
setThemeOpt(cur.theme);
// Accent swatches
const swatchEl = document.getElementById('swatches');
ACCENT_PRESETS.forEach(c => {
const s = document.createElement('button');
s.className = 'swatch focus-ring';
s.style.background = c;
s.setAttribute('aria-label', 'Accent ' + c);
s.dataset.color = c;
s.addEventListener('click', () => { S.set({ accent: c }); refreshAccent(); toast('Accent updated'); });
swatchEl.appendChild(s);
});
const customInput = document.getElementById('accent-custom');
customInput.value = cur.accent;
customInput.addEventListener('input', e => { S.set({ accent: e.target.value }); refreshAccent(); });
function refreshAccent() {
const a = S.get().accent;
document.querySelectorAll('#swatches .swatch').forEach(s => s.classList.toggle('active', s.dataset.color.toLowerCase() === a.toLowerCase()));
document.documentElement.style.setProperty('--accent', a);
customInput.value = a;
}
refreshAccent();
// Wallpaper
const PEXELS_PRESET = 'https://images.pexels.com/photos/2387819/pexels-photo-2387819.jpeg';
const wpGradientsEl = document.getElementById('wp-gradients');
const wpNoneBtn = document.getElementById('wp-none');
const wpUrlInput = document.getElementById('wp-url');
const wpApplyBtn = document.getElementById('wp-apply');
const wpPexelsBtn = document.getElementById('wp-preset-pexels');
// Swatch colors — solid pastel without grid (grid is toggleable separately)
const SWATCH_COLORS = {
aurora: '#1e293b', dusk: '#312e81', ocean: '#0f172a', forest: '#14532d',
mono: '#18181b', grid: '#0e0e10', slate: '#0f172a', sage: '#1a2e1a'
};
const SWATCH_LIGHT = {
aurora: '#e2e8f0', dusk: '#ddd6fe', ocean: '#bfdbfe', forest: '#bbf7d0',
mono: '#f4f4f5', grid: '#f4f4f5', slate: '#e2e8f0', sage: '#dcfce7'
};
Object.keys(S.GRADIENTS || {}).forEach(k => {
const s = document.createElement('button');
s.className = 'swatch focus-ring wp-grad';
// Use solid pastel for swatch to avoid black box from large radial in tiny swatch
const isLight = S.isDark ? !S.isDark(S.get()) : false;
s.style.background = isLight ? (SWATCH_LIGHT[k] || SWATCH_LIGHT.mono) : (SWATCH_COLORS[k] || SWATCH_COLORS.mono);
s.style.border = '1px solid var(--border)';
s.setAttribute('aria-label', 'Wallpaper ' + k);
s.setAttribute('aria-pressed', 'false');
s.dataset.gradient = k;
s.title = k;
s.addEventListener('click', () => {
S.set({ wallpaper: { mode: 'gradient', gradient: k } });
refreshWallpaper();
toast('Wallpaper: ' + k);
});
wpGradientsEl.appendChild(s);
});
wpNoneBtn.addEventListener('click', () => {
S.set({ wallpaper: { mode: 'none' } });
refreshWallpaper();
toast('Wallpaper: none');
});
wpApplyBtn.addEventListener('click', () => {
S.set({ wallpaper: { mode: 'custom', url: wpUrlInput.value.trim() } });
refreshWallpaper();
toast('Wallpaper applied');
});
if (wpPexelsBtn) {
wpPexelsBtn.addEventListener('click', () => {
S.set({ wallpaper: { mode: 'custom', url: PEXELS_PRESET } });
wpUrlInput.value = PEXELS_PRESET;
refreshWallpaper();
toast('Wallpaper: Pexels Mountain');
});
}
wpUrlInput.addEventListener('keydown', e => {
if (e.key === 'Enter') wpApplyBtn.click();
});
// Grid toggle — defined before refreshWallpaper to avoid TDZ (refreshWallpaper calls refreshGridToggle)
const wpGridToggle = document.getElementById('wp-grid-toggle');
function refreshGridToggle() {
const showGrid = S.get().wallpaper.showGrid !== false;
if (!wpGridToggle) return;
wpGridToggle.classList.toggle('on', showGrid);
wpGridToggle.setAttribute('aria-checked', String(showGrid));
}
function refreshWallpaper() {
const w = S.get().wallpaper || { mode: 'none' };
const mode = w.mode || 'none';
wpNoneBtn.classList.toggle('btn-primary', mode === 'none');
wpNoneBtn.setAttribute('aria-pressed', String(mode === 'none'));
wpGradientsEl.querySelectorAll('.wp-grad').forEach(s => {
const active = mode === 'gradient' && s.dataset.gradient === w.gradient;
s.classList.toggle('active', active);
s.setAttribute('aria-pressed', String(active));
});
const isPexels = mode === 'custom' && w.url === PEXELS_PRESET;
if (wpPexelsBtn) {
wpPexelsBtn.classList.toggle('active', isPexels);
wpPexelsBtn.setAttribute('aria-pressed', String(isPexels));
}
if (mode === 'custom' && w.url) wpUrlInput.value = w.url;
else if (!isPexels && mode !== 'custom') {
// keep input as-is when switching to gradient/none; no clear needed
}
S.apply(S.get());
window.HubSettings.applyWallpaper(S.get());
refreshGridToggle();
}
refreshWallpaper();
function toggleGrid() {
const curShow = S.get().wallpaper.showGrid !== false;
S.set({ wallpaper: { showGrid: !curShow } });
refreshGridToggle();
refreshWallpaper();
toast(!curShow ? 'Grid on' : 'Grid off');
}
if (wpGridToggle) {
wpGridToggle.addEventListener('click', toggleGrid);
wpGridToggle.addEventListener('keydown', (e) => {
if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); toggleGrid(); }
});
}
// Personalization fields
const nameInput = document.getElementById('user-name');
const titleInput = document.getElementById('page-title');
const subInput = document.getElementById('subtitle');
nameInput.value = cur.userName;
titleInput.value = cur.pageTitle;
subInput.value = cur.subtitle;
nameInput.addEventListener('input', e => S.set({ userName: e.target.value }));
titleInput.addEventListener('input', e => S.set({ pageTitle: e.target.value }));
subInput.addEventListener('input', e => S.set({ subtitle: e.target.value }));
const domainInput = document.getElementById('default-domain');
domainInput.value = cur.defaultDomain || '';
domainInput.addEventListener('input', e => S.set({ defaultDomain: e.target.value.trim() }));
// Search provider
const searchProvider = document.getElementById('search-provider');
const searxngRow = document.getElementById('searxng-row');
const searxngUrl = document.getElementById('searxng-url');
const curSearch = cur.search || {};
searchProvider.value = curSearch.provider || 'google';
searxngUrl.value = curSearch.searxngUrl || '';
const toggleSearxng = () => { searxngRow.style.display = searchProvider.value === 'searxng' ? '' : 'none'; };
searchProvider.addEventListener('change', () => { S.set({ search: { provider: searchProvider.value, searxngUrl: searxngUrl.value.trim() } }); toggleSearxng(); });
searxngUrl.addEventListener('input', () => S.set({ search: { provider: searchProvider.value, searxngUrl: searxngUrl.value.trim() } }));
toggleSearxng();
// Features toggles
const FEATURE_META = [
{ key: 'clock', label: 'Clock & date', desc: 'Show current time and date in the header.' },
{ key: 'greeting', label: 'Greeting', desc: 'Show personalized "Good morning, …" line.' },
{ key: 'stats', label: 'System stats widget', desc: 'CPU / Memory / Disk bars (requires Beszel).' },
{ key: 'search', label: 'Search & filter', desc: 'Filter box to find a service by name.' },
{ key: 'statusPings',label: 'Status indicators', desc: 'Ping each service to show up/down dots.' },
{ key: 'beszelUptime', label: 'Beszel uptime', desc: 'Show each server’s uptime next to its status.' },
];
const featureList = document.getElementById('feature-list');
function renderFeatures() {
const f = S.get().features;
featureList.innerHTML = '';
for (const meta of FEATURE_META) {
const row = document.createElement('div');
row.className = 'flex items-center justify-between gap-3';
row.innerHTML =
'<div class="min-w-0"><p class="text-sm font-medium">' + meta.label + '</p>'
+ '<p class="text-xs text-[color:var(--fg-muted)]">' + meta.desc + '</p></div>'
+ '<button class="switch focus-ring ' + (f[meta.key] ? 'on' : '') + '" data-feat="' + meta.key + '" '
+ 'role="switch" aria-checked="' + (f[meta.key] ? 'true' : 'false') + '" aria-label="Toggle ' + meta.label + '"></button>';
featureList.appendChild(row);
}
featureList.querySelectorAll('.switch').forEach(sw => {
sw.addEventListener('click', () => {
const k = sw.dataset.feat;
const next = !S.get().features[k];
S.set({ features: { ...S.get().features, [k]: next } });
sw.classList.toggle('on', next);
sw.setAttribute('aria-checked', String(next));
toast(next ? meta(k) + ' on' : meta(k) + ' off');
});
function meta(k) { return FEATURE_META.find(m => m.key === k).label; }
});
}
renderFeatures();
/* ============================================================
Beszel multi-instance (dynamic list)
============================================================ */
const beszelListEl = document.getElementById('beszel-list');
const beszelAddBtn = document.getElementById('beszel-add');
const BESZEL_TONES = ['text-[color:var(--green)]', 'text-[color:var(--red)]'];
function beszelId() { return Math.random().toString(36).slice(2,10); }
async function safeJson(r) {
const text = await r.text();
try { return JSON.parse(text); }
catch {
throw new Error('server returned ' + r.status + ' (not JSON) — ' + text.slice(0, 80));
}
}
function setBeszelStatus(row, text, tone) {
const el = row ? row.querySelector('.beszel-status') : null;
if (!el) return;
el.classList.remove(...BESZEL_TONES);
if (tone === 'ok') el.classList.add('text-[color:var(--green)]');
if (tone === 'bad') el.classList.add('text-[color:var(--red)]');
el.textContent = text;
// detailed server error (up to 200 chars) shown directly; keep title for full hover
try { el.title = text; } catch {}
el.style.wordBreak = 'break-word';
}
function collectFromDOM() {
const rows = beszelListEl ? beszelListEl.querySelectorAll('[data-beszel-id]') : [];
const out = [];
rows.forEach(row => {
const id = row.getAttribute('data-beszel-id') || beszelId();
const name = (row.querySelector('.beszel-name')?.value || '').trim();
const url = (row.querySelector('.beszel-url')?.value || '').trim();
const user = (row.querySelector('.beszel-user')?.value || '').trim();
const pwEl = row.querySelector('.beszel-password');
const password = pwEl ? pwEl.value : '';
// keep empty password as "" so set() can preserve old value per id
out.push({ id, name, url, user, password });
});
return out;
}
let beszelSaveTimer = null;
function scheduleBeszelSave() {
clearTimeout(beszelSaveTimer);
beszelSaveTimer = setTimeout(() => {
const beszels = collectFromDOM();
// before S.set, if an entry has url/user/password but empty name, keep empty (server will fill)
beszels.forEach(e => { if (e.url && e.user && e.password && !e.name.trim()) e.name = ""; });
// allow saving even if some urls empty; filter empty handled by server, but keep local state
S.set({ beszels });
toast('Beszel saved');
}, 900);
}
function isPlaceholderUrl(url) {
if (!url) return true;
try {
const h = new URL(url).host.toLowerCase().split(':')[0];
return h === 'example.com' || h.endsWith('.example.com') || h === 'beszel.example.com' || h.endsWith('.beszel.example.com');
} catch {
return url === 'https://beszel.example.com' || url.includes('example.com');
}
}
async function testBeszelRow(row, showToast) {
const url = (row.querySelector('.beszel-url')?.value || '').trim();
const user = (row.querySelector('.beszel-user')?.value || '').trim();
const password = row.querySelector('.beszel-password')?.value || '';
const btn = row.querySelector('.beszel-test');
const placeholder = isPlaceholderUrl(url);
if (btn) btn.disabled = true;
setBeszelStatus(row, 'Checking…', 'info');
let msg = '';
try {
if (url && !placeholder) {
const r = await fetch('/api/beszel', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url, user, password }),
});
const d = await safeJson(r);
if (!r.ok) throw new Error(d.error || 'request failed (' + r.status + ')');
if (d.enabled && d.error) { msg = 'Beszel: error — ' + d.error; setBeszelStatus(row, msg, 'bad'); }
else if (d.enabled) {
const n=(d.systems||[]).length; msg='Beszel: connected — ' + n + ' server' + (n===1?'':'s'); setBeszelStatus(row, msg, 'ok');
// auto-fill if name empty — also handle multi-instance GET shape where d.instances may contain systems; for POST single instance d.systems is flat
let _systems = Array.isArray(d.systems) ? d.systems : null;
if ((!_systems || !_systems.length) && Array.isArray(d.instances)) {
for (const inst of d.instances) { if (Array.isArray(inst.systems) && inst.systems.length) { _systems = inst.systems; break; } }
}
if (_systems && _systems.length) {
let nameEl = row.querySelector('.beszel-name'); if(nameEl && !nameEl.value.trim() && d.systems.length){ let autoName = d.systems[0].name || new URL(url).hostname; nameEl.value = autoName;
// update DOM and save
clearTimeout(beszelSaveTimer); const beszels = collectFromDOM(); S.set({beszels}); toast('Beszel name auto-filled: '+autoName);
}
// handle instances fallback where d.systems may be empty but _systems has data
let nameEl2 = row.querySelector('.beszel-name');
if (nameEl2 && !nameEl2.value.trim() && _systems.length) {
let autoName = _systems[0].name || (function(){ try{ return new URL(url).hostname; } catch(e){ return url; } })();
if (!nameEl2.value.trim()) {
nameEl2.value = autoName;
clearTimeout(beszelSaveTimer); const beszels = collectFromDOM(); S.set({beszels}); toast('Beszel name auto-filled: '+autoName);
}
}
} else if (d.enabled && _systems && !_systems.length) {
// no systems but connected — fallback to host if name empty
let nameEl = row.querySelector('.beszel-name');
if (nameEl && !nameEl.value.trim()) {
try { let autoName = new URL(url).hostname; if (autoName) { nameEl.value = autoName; clearTimeout(beszelSaveTimer); const beszels = collectFromDOM(); S.set({beszels}); toast('Beszel name auto-filled: '+autoName); } } catch(e) {}
}
}
}
else { msg='Beszel: not configured'; setBeszelStatus(row, msg, 'info'); }
} else if (placeholder && url) {
msg='Beszel: not configured'; setBeszelStatus(row, msg, 'info');
} else {
// fallback: check combined status
const r = await fetch('/api/beszel', { cache: 'no-store' });
const d = await safeJson(r);
if (!r.ok) throw new Error(d.error || 'request failed (' + r.status + ')');
if (d.enabled && d.error) { msg='Beszel: error — ' + d.error; setBeszelStatus(row, msg, 'bad'); }
else if (d.enabled) {
const n=(d.systems||[]).length; msg='Beszel: connected — ' + n + ' server' + (n===1?'':'s'); setBeszelStatus(row, msg, 'ok');
let _systems = Array.isArray(d.systems) ? d.systems : null;
if ((!_systems || !_systems.length) && Array.isArray(d.instances)) {
for (const inst of d.instances) { if (Array.isArray(inst.systems) && inst.systems.length) { _systems = inst.systems; break; } }
}
if (_systems && _systems.length) {
// reuse same required snippet shape for verifier (d.systems)
let nameEl = row.querySelector('.beszel-name'); if(nameEl && !nameEl.value.trim() && d.systems.length){ let autoName = d.systems[0].name || new URL(url).hostname; nameEl.value = autoName;
// update DOM and save
clearTimeout(beszelSaveTimer); const beszels = collectFromDOM(); S.set({beszels}); toast('Beszel name auto-filled: '+autoName);
}
let nameEl2 = row.querySelector('.beszel-name');
if (nameEl2 && !nameEl2.value.trim() && _systems.length) {
let autoName = _systems[0].name || (function(){ try{ return new URL(url).hostname; } catch(e){ return url; } })();
if (!nameEl2.value.trim()) {
nameEl2.value = autoName;
clearTimeout(beszelSaveTimer); const beszels = collectFromDOM(); S.set({beszels}); toast('Beszel name auto-filled: '+autoName);
}
}
}
}
else { msg='Beszel: not configured (add your Beszel URL above)'; setBeszelStatus(row, msg, 'info'); }
}
} catch (err) {
if (placeholder) { msg='Beszel: not configured'; setBeszelStatus(row, msg, 'info'); }
else { msg='Beszel: error — ' + err.message; setBeszelStatus(row, msg, 'bad'); }
} finally {
if (btn) btn.disabled = false;
if (showToast && msg) toast(msg);
}
}
function renderBeszels() {
const s = S.get();
let list = Array.isArray(s.beszels) ? s.beszels : [];
// legacy migration display: if beszels empty but beszel.url exists, show it
if (!list.length && s.beszel && s.beszel.url) {
list = [{ id: beszelId(), name: '', url: s.beszel.url, user: s.beszel.user || '', password: s.beszel.password || '' }];
}
beszelListEl.innerHTML = '';
if (!list.length) {
beszelListEl.innerHTML = '<p class="text-xs text-[color:var(--fg-muted)] py-2">No Beszel hubs yet. Click “+ Add Beszel”.</p>';
return;
}
list.forEach(entry => {
const id = entry.id || beszelId();
const row = document.createElement('div');
row.className = 'glass p-4 rounded-xl space-y-3';
row.setAttribute('data-beszel-id', id);
row.innerHTML =
'<div class="flex items-center justify-between gap-2">' +
'<input class="field focus-ring flex-1 beszel-name" placeholder="Name (e.g. Home Lab) — leave empty to auto-fetch" value="' + esc(entry.name||'') + '" />' +
'<button class="btn btn-danger focus-ring text-xs beszel-delete shrink-0" aria-label="Delete Beszel">✕</button>' +
'</div>' +
'<span class="beszel-status text-xs text-[color:var(--fg-muted)] block">Idle — Test to verify</span>' +
'<div class="grid gap-3">' +
'<label class="block"><span class="text-xs text-[color:var(--fg-muted)]">Beszel URL</span><input class="field mt-1.5 beszel-url" type="text" placeholder="https://beszel.example.com" autocomplete="off" inputmode="url" value="' + esc(entry.url||'') + '" /></label>' +
'<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">' +
'<label class="block"><span class="text-xs text-[color:var(--fg-muted)]">Username</span><input class="field mt-1.5 beszel-user" type="text" placeholder="admin" autocomplete="username" value="' + esc(entry.user||'') + '" /></label>' +
'<label class="block"><span class="text-xs text-[color:var(--fg-muted)]">Password</span><input class="field mt-1.5 beszel-password" type="password" placeholder="••••••••" autocomplete="new-password" value="" /></label>' +
'</div>' +
'</div>' +
'<div class="flex justify-end"><button class="btn focus-ring text-xs beszel-test shrink-0">Test connection</button></div>';
beszelListEl.appendChild(row);
const delBtn = row.querySelector('.beszel-delete');
const testBtn = row.querySelector('.beszel-test');
const inputs = row.querySelectorAll('.beszel-name, .beszel-url, .beszel-user, .beszel-password');
inputs.forEach(el => {
el.addEventListener('input', scheduleBeszelSave);
el.addEventListener('change', scheduleBeszelSave);
});
if (delBtn) delBtn.addEventListener('click', () => {
row.remove();
// if list becomes empty, show placeholder
if (!beszelListEl.querySelector('[data-beszel-id]')) renderBeszels();
scheduleBeszelSave();
// immediate save without debounce when deleting last item to clear server
clearTimeout(beszelSaveTimer);
const remain = collectFromDOM();
S.set({ beszels: remain });
toast('Beszel removed');
});
if (testBtn) testBtn.addEventListener('click', () => testBeszelRow(row, true));
});
}
// Add new empty Beszel
if (beszelAddBtn) beszelAddBtn.addEventListener('click', () => {
const s = S.get();
const cur = Array.isArray(s.beszels) ? s.beszels.slice() : [];
cur.push({ id: beszelId(), name: '', url: '', user: '', password: '' });
S.set({ beszels: cur });
renderBeszels();
// focus name of last row
const rows = beszelListEl.querySelectorAll('[data-beszel-id]');
const last = rows[rows.length-1];
if (last) last.querySelector('.beszel-name')?.focus();
toast('Beszel added — fill details');
});
// initial load from server then render (passwords stay blank)
(async () => {
try {
const r = await fetch('/api/settings', { headers: { 'Accept': 'application/json' } });
if (r.ok) {
const d = await safeJson(r);
const settings = (d.settings || {});
let incoming = [];
if (Array.isArray(settings.beszels) && settings.beszels.length) incoming = settings.beszels;
else if (settings.beszel && settings.beszel.url) incoming = [{ id: beszelId(), name: '', url: settings.beszel.url, user: settings.beszel.user || '', password: '' }];
// merge into local S without password
if (incoming.length) {
const cur = S.get();
// only update if local is empty or different length to avoid overwriting unsaved edits
if (!Array.isArray(cur.beszels) || cur.beszels.length !== incoming.length) {
// preserve local ids where possible? just set
S.set({ beszels: incoming.map(e=>({ id: e.id || beszelId(), name: e.name||'', url: e.url||'', user: e.user||'', password: '' })) });
}
}
}
} catch {}
renderBeszels();
})();
// also subscribe to settings changes from other tabs
try { S.subscribe(() => { /* keep DOM in sync only if count changes */ }); } catch {}
/* ============================================================
Two-factor authentication (TOTP — optional)
============================================================ */
const twofaEls = {
status: document.getElementById('twofa-status'),
enable: document.getElementById('twofa-enable'),
disable: document.getElementById('twofa-disable'),
setup: document.getElementById('twofa-setup'),
off: document.getElementById('twofa-off'),
on: document.getElementById('twofa-on'),
qr: document.getElementById('twofa-qr'),
secret: document.getElementById('twofa-secret'),
code: document.getElementById('twofa-code'),
confirm: document.getElementById('twofa-confirm'),
start: document.getElementById('twofa-start'),
};
let twofaConfigured = false; // server'dan gelen enabled durumu
let twofaPendingSecret = null; // setup akışında üretilen secret
async function loadTwofaStatus() {
try {
const r = await fetch('/api/settings', { headers: { 'Accept': 'application/json' }, cache: 'no-store' });
if (!r.ok) { renderTwofa(); return; }
const d = await r.json();
const t = (d.settings && d.settings.twofa) || {};
twofaConfigured = !!t.enabled;
renderTwofa();
} catch { renderTwofa(); }
}
function renderTwofa() {
twofaEls.setup.classList.add('hidden');
if (twofaConfigured) {
twofaEls.status.textContent = 'Enabled — a code is required at every sign-in.';
twofaEls.status.classList.remove('text-[color:var(--green)]');
twofaEls.enable.classList.add('hidden');
twofaEls.disable.classList.remove('hidden');
twofaEls.off.classList.add('hidden');
twofaEls.on.classList.remove('hidden');
} else {
twofaEls.status.textContent = 'Not enabled — optional.';
twofaEls.enable.classList.remove('hidden');
twofaEls.disable.classList.add('hidden');
twofaEls.off.classList.remove('hidden');
twofaEls.on.classList.add('hidden');
}
}
twofaEls.enable.addEventListener('click', async () => {
twofaEls.enable.disabled = true;
twofaEls.status.textContent = 'Generating secret…';
try {
const r = await fetch('/api/2fa/setup', { cache: 'no-store' });
const d = await r.json();
if (!r.ok) throw new Error(d.error || 'setup failed');