forked from wg-easy/wg-easy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
1267 lines (1196 loc) · 54.8 KB
/
App.vue
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
<template>
<div>
<div v-cloak class="mx-auto mt-4 max-w-3xl px-3 container xs:mt-6 md:px-0">
<div v-if="authenticated === true">
<div class="flex flex-auto flex-col-reverse items-end items-center gap-3 xxs:flex-row">
<h1 class="mb-4 flex-grow self-start text-4xl font-medium dark:text-neutral-200">
<img src="/img/logo.png" width="32" class="dark:bg mr-2 inline align-middle" /><span class="align-middle">WireGuard</span>
</h1>
<div class="flex grow-0 items-end items-center self-end gap-3 xxs:self-center">
<!-- Dark / light theme -->
<button
class="h-8 w-8 flex items-center justify-center rounded-full bg-gray-200 transition dark:bg-neutral-700 hover:bg-gray-300 dark:hover:bg-neutral-600"
:title="$t(`theme.${uiTheme}`)"
@click="toggleTheme"
>
<svg
v-if="uiTheme === 'light'"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-5 w-5"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"
/>
</svg>
<svg
v-else-if="uiTheme === 'dark'"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-5 w-5 text-neutral-400"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"
/>
</svg>
<svg
v-else
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
viewBox="0 0 24 24"
class="h-5 w-5 fill-gray-600 dark:fill-neutral-400"
>
<path
d="M12,2.2c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S17.4,2.2,12,2.2z M3.8,12c0-4.5,3.7-8.2,8.2-8.2v16.5C7.5,20.2,3.8,16.5,3.8,12z"
/>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25"
/>
</svg>
</button>
<!-- Show / hide charts -->
<label
v-if="uiChartType > 0"
class="group h-8 w-8 inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full bg-gray-200 transition dark:bg-neutral-700 hover:bg-gray-300 dark:hover:bg-neutral-600"
:title="$t('toggleCharts')"
>
<input v-model="uiShowCharts" type="checkbox" value="" class="peer sr-only" @change="toggleCharts" />
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
stroke-width="1.5"
fill="currentColor"
class="peer h-5 w-5 fill-gray-400 transition dark:fill-neutral-600 peer-checked:fill-gray-600 group-hover:dark:fill-neutral-500 peer-checked:dark:fill-neutral-400"
>
<path
d="M18.375 2.25c-1.035 0-1.875.84-1.875 1.875v15.75c0 1.035.84 1.875 1.875 1.875h.75c1.035 0 1.875-.84 1.875-1.875V4.125c0-1.036-.84-1.875-1.875-1.875h-.75ZM9.75 8.625c0-1.036.84-1.875 1.875-1.875h.75c1.036 0 1.875.84 1.875 1.875v11.25c0 1.035-.84 1.875-1.875 1.875h-.75a1.875 1.875 0 0 1-1.875-1.875V8.625ZM3 13.125c0-1.036.84-1.875 1.875-1.875h.75c1.036 0 1.875.84 1.875 1.875v6.75c0 1.035-.84 1.875-1.875 1.875h-.75A1.875 1.875 0 0 1 3 19.875v-6.75Z"
/>
</svg>
</label>
<span
v-if="requiresPassword"
class="cursor-pointer text-sm text-gray-400 dark:text-neutral-400 hover:underline"
@click="logout"
>
{{ $t("logout") }}
<svg class="inline h-3" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
/>
</svg>
</span>
</div>
</div>
<div class="mb-5 text-sm text-gray-400 dark:text-neutral-400"></div>
<div
v-if="latestRelease"
class="font-small mb-10 rounded-md bg-red-800 p-4 text-sm text-white shadow-lg dark:bg-red-100 dark:text-red-600"
:title="`v${currentRelease} → v${latestRelease.version}`"
>
<div class="mx-auto flex flex-auto flex-row items-center container">
<div class="flex-grow">
<p class="font-bold">{{ $t("updateAvailable") }}</p>
<p>{{ latestRelease.changelog }}</p>
</div>
<a
href="https://github.com/wg-easy/wg-easy#updating"
target="_blank"
class="font-sm float-right flex-shrink-0 border-2 border-red-800 rounded-md bg-white p-3 text-red-800 font-semibold transition-all dark:border-red-600 hover:border-white dark:bg-red-100 hover:bg-red-800 dark:text-red-600 hover:text-white dark:hover:border-red-600 dark:hover:bg-red-600 dark:hover:text-red-100"
>
{{ $t("update") }} →
</a>
</div>
</div>
<div class="overflow-hidden rounded-lg bg-white shadow-md dark:bg-neutral-700">
<div class="flex flex-auto flex-row items-center border-b-2 border-gray-100 p-3 px-5 dark:border-neutral-600">
<div class="flex-grow">
<p class="text-2xl font-medium dark:text-neutral-200">{{ $t("clients") }}</p>
</div>
<div class="flex-shrink-0">
<button
class="inline-flex items-center border-2 border-gray-100 rounded px-4 py-2 text-gray-700 transition dark:border-neutral-600 hover:border-red-800 hover:bg-red-800 dark:text-neutral-200 hover:text-white"
@click="
clientCreate = true;
clientCreateName = '';
"
>
<svg class="mr-2 w-4" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
</svg>
<span class="text-sm">{{ $t("new") }}</span>
</button>
</div>
</div>
<div>
<!-- Client -->
<div
v-for="client in clients"
v-if="clients && clients.length > 0"
:key="client.id"
class="relative overflow-hidden border-b border-gray-100 border-solid last:border-b-0 dark:border-neutral-600"
>
<!-- Chart -->
<div v-if="uiChartType" class="absolute bottom-0 left-0 right-0 z-0 h-6">
<Apexchart width="100%" height="100%" :options="chartOptionsTX" :series="client.transferTxSeries"> </Apexchart>
</div>
<div v-if="uiChartType" class="absolute left-0 right-0 top-0 z-0 h-6">
<Apexchart
width="100%"
height="100%"
:options="chartOptionsRX"
:series="client.transferRxSeries"
style="transform: scaleY(-1)"
>
</Apexchart>
</div>
<div class="relative z-10 flex flex-col justify-between gap-3 px-3 py-3 sm:flex-row md:py-5">
<div class="w-full flex items-center gap-3 md:gap-4">
<!-- Avatar -->
<div class="relative mt-2 h-10 w-10 self-start rounded-full bg-gray-50">
<svg class="m-2 w-6 text-gray-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd" />
</svg>
<img v-if="client.avatar" :src="client.avatar" class="absolute left-0 top-0 w-10 rounded-full" />
<div v-if="client.latestHandshakeAt && new Date() - new Date(client.latestHandshakeAt) < 1000 * 60 * 10">
<div class="absolute h-4 w-4 animate-ping rounded-full bg-red-100 p-1 -bottom-1 -right-1 dark:bg-red-100"></div>
<div class="absolute bottom-0 right-0 h-2 w-2 rounded-full bg-red-800 dark:bg-red-600"></div>
</div>
</div>
<!-- Name & Info -->
<div class="xxs:flex-row w-full flex flex-col gap-2">
<!-- Name -->
<div class="flex flex-grow flex-col gap-1">
<div
class="group text-sm text-gray-700 md:text-base dark:text-neutral-200"
:title="$t('createdOn') + dateTime(new Date(client.createdAt))"
>
<!-- Show -->
<input
v-show="clientEditNameId === client.id"
:ref="`client-${client.id}-name`"
v-model="clientEditName"
class="w-30 border-2 border-gray-100 rounded px-1 outline-none dark:border-neutral-600 focus:border-gray-200 dark:bg-neutral-700 dark:focus:border-neutral-500 dark:placeholder:text-neutral-500"
@keyup.enter="
updateClientName(client, clientEditName);
clientEditName = null;
clientEditNameId = null;
"
@keyup.escape="
clientEditName = null;
clientEditNameId = null;
"
/>
<span v-show="clientEditNameId !== client.id" class="border-b-2 border-t-2 border-transparent">{{
client.name
}}</span>
<!-- Edit -->
<span
v-show="clientEditNameId !== client.id"
class="cursor-pointer opacity-0 transition-opacity group-hover:opacity-100"
@click="
clientEditName = client.name;
clientEditNameId = client.id;
setTimeout(() => $refs[`client-${client.id}-name`][0].select(), 1);
"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="inline h-4 w-4 align-middle opacity-25 hover:opacity-100"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
/>
</svg>
</span>
</div>
<!-- Address -->
<div class="block pb-1 text-xs text-gray-500 md:inline-block md:pb-0 dark:text-neutral-400">
<span class="group">
<!-- Show -->
<input
v-show="clientEditAddressId === client.id"
:ref="`client-${client.id}-address`"
v-model="clientEditAddress"
class="w-20 border-2 border-gray-100 rounded text-black outline-none dark:border-neutral-600 focus:border-gray-200 dark:bg-neutral-700 dark:text-neutral-300 dark:focus:border-neutral-500 dark:placeholder:text-neutral-500"
@keyup.enter="
updateClientAddress(client, clientEditAddress);
clientEditAddress = null;
clientEditAddressId = null;
"
@keyup.escape="
clientEditAddress = null;
clientEditAddressId = null;
"
/>
<span v-show="clientEditAddressId !== client.id" class="inline-block">{{ client.address }}</span>
<!-- Edit -->
<span
v-show="clientEditAddressId !== client.id"
class="cursor-pointer opacity-0 transition-opacity group-hover:opacity-100"
@click="
clientEditAddress = client.address;
clientEditAddressId = client.id;
setTimeout(() => $refs[`client-${client.id}-address`][0].select(), 1);
"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="inline h-4 w-4 align-middle opacity-25 hover:opacity-100"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
/>
</svg>
</span>
</span>
<!-- Inline Transfer TX -->
<span
v-if="!uiTrafficStats && client.transferTx"
class="whitespace-nowrap"
:title="$t('totalDownload') + bytes(client.transferTx)"
>
·
<svg class="inline h-3 align-middle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path
fill-rule="evenodd"
d="M16.707 10.293a1 1 0 010 1.414l-6 6a1 1 0 01-1.414 0l-6-6a1 1 0 111.414-1.414L9 14.586V3a1 1 0 012 0v11.586l4.293-4.293a1 1 0 011.414 0z"
clip-rule="evenodd"
/>
</svg>
{{ bytes(client.transferTxCurrent) }}/s
</span>
<!-- Inline Transfer RX -->
<span
v-if="!uiTrafficStats && client.transferRx"
class="whitespace-nowrap"
:title="$t('totalUpload') + bytes(client.transferRx)"
>
·
<svg class="inline h-3 align-middle" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path
fill-rule="evenodd"
d="M3.293 9.707a1 1 0 010-1.414l6-6a1 1 0 011.414 0l6 6a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L4.707 9.707a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>
</svg>
{{ bytes(client.transferRxCurrent) }}/s
</span>
<!-- Last seen -->
<span
v-if="client.latestHandshakeAt"
class="whitespace-nowrap text-gray-400 dark:text-neutral-500"
:title="$t('lastSeen') + dateTime(new Date(client.latestHandshakeAt))"
>
{{ !uiTrafficStats ? " · " : "" }}{{ timeago(new Date(client.latestHandshakeAt)) }}
</span>
</div>
</div>
<!-- Info -->
<div
v-if="uiTrafficStats"
class="mt-px flex shrink-0 items-center justify-end gap-2 text-xs text-gray-400 dark:text-neutral-400"
>
<!-- Transfer TX -->
<div v-if="client.transferTx" class="min-w-20 md:min-w-24">
<span class="flex gap-1" :title="$t('totalDownload') + bytes(client.transferTx)">
<svg
class="mt-0.5 inline h-3 align-middle"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M16.707 10.293a1 1 0 010 1.414l-6 6a1 1 0 01-1.414 0l-6-6a1 1 0 111.414-1.414L9 14.586V3a1 1 0 012 0v11.586l4.293-4.293a1 1 0 011.414 0z"
clip-rule="evenodd"
/>
</svg>
<div>
<span class="text-gray-700 dark:text-neutral-200">{{ bytes(client.transferTxCurrent) }}/s</span>
<!-- Total TX -->
<br /><span class="font-regular" style="font-size: 0.85em">{{ bytes(client.transferTx) }}</span>
</div>
</span>
</div>
<!-- Transfer RX -->
<div v-if="client.transferRx" class="min-w-20 md:min-w-24">
<span class="flex gap-1" :title="$t('totalUpload') + bytes(client.transferRx)">
<svg
class="mt-0.5 inline h-3 align-middle"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M3.293 9.707a1 1 0 010-1.414l6-6a1 1 0 011.414 0l6 6a1 1 0 01-1.414 1.414L11 5.414V17a1 1 0 11-2 0V5.414L4.707 9.707a1 1 0 01-1.414 0z"
clip-rule="evenodd"
/>
</svg>
<div>
<span class="text-gray-700 dark:text-neutral-200">{{ bytes(client.transferRxCurrent) }}/s</span>
<!-- Total RX -->
<br /><span class="font-regular" style="font-size: 0.85em">{{ bytes(client.transferRx) }}</span>
</div>
</span>
</div>
</div>
</div>
<!-- </div> -->
<!-- <div class="flex flex-grow items-center"> -->
</div>
<div class="flex items-center justify-end">
<div class="flex items-center justify-between gap-1 text-gray-400 dark:text-neutral-400">
<!-- Enable/Disable -->
<div
v-if="client.enabled === true"
:title="$t('disableClient')"
class="mr-1 inline-block h-6 w-10 cursor-pointer rounded-full bg-red-800 align-middle transition-all hover:bg-red-700"
@click="disableClient(client)"
>
<div class="m-1 ml-5 h-4 w-4 rounded-full bg-white"></div>
</div>
<div
v-if="client.enabled === false"
:title="$t('enableClient')"
class="mr-1 inline-block h-6 w-10 cursor-pointer rounded-full bg-gray-200 align-middle transition-all dark:bg-neutral-400 hover:bg-gray-300 dark:hover:bg-neutral-500"
@click="enableClient(client)"
>
<div class="m-1 h-4 w-4 rounded-full bg-white"></div>
</div>
<!-- Show QR -->
<button
:disabled="!client.downloadableConfig"
class="rounded bg-gray-100 p-2 align-middle transition dark:bg-neutral-600 dark:text-neutral-300"
:class="{
'hover:bg-red-800 dark:hover:bg-red-800 hover:text-white dark:hover:text-white': client.downloadableConfig,
'is-disabled': !client.downloadableConfig,
}"
:title="!client.downloadableConfig ? $t('noPrivKey') : $t('showQR')"
@click="qrcode = `./api/wireguard/client/${client.id}/qrcode.svg`"
>
<svg class="w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"
/>
</svg>
</button>
<!-- Download Config -->
<a
:disabled="!client.downloadableConfig"
:href="`./api/wireguard/client/${client.id}/configuration`"
:download="client.downloadableConfig ? 'configuration' : null"
class="inline-block rounded bg-gray-100 p-2 align-middle transition dark:bg-neutral-600 dark:text-neutral-300"
:class="{
'hover:bg-red-800 dark:hover:bg-red-800 hover:text-white dark:hover:text-white': client.downloadableConfig,
'is-disabled': !client.downloadableConfig,
}"
:title="!client.downloadableConfig ? $t('noPrivKey') : $t('downloadConfig')"
@click="
if (!client.downloadableConfig) {
$event.preventDefault();
}
"
>
<svg class="w-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<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>
</a>
<!-- Delete -->
<button
class="rounded bg-gray-100 p-2 align-middle transition dark:bg-neutral-600 hover:bg-red-800 dark:text-neutral-300 hover:text-white dark:hover:bg-red-800 dark:hover:text-white"
:title="$t('deleteClient')"
@click="clientDelete = client"
>
<svg class="w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path
fill-rule="evenodd"
d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z"
clip-rule="evenodd"
/>
</svg>
</button>
</div>
</div>
</div>
</div>
<div v-if="clients && clients.length === 0">
<p class="m-10 text-center text-sm text-gray-400 dark:text-neutral-400">
{{ $t("noClients") }}<br /><br />
<button
class="inline-flex items-center border-2 rounded border-none bg-red-800 px-4 py-2 text-white transition hover:bg-red-700"
@click="
clientCreate = true;
clientCreateName = '';
"
>
<svg class="mr-2 w-4" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
</svg>
<span class="text-sm">{{ $t("newClient") }}</span>
</button>
</p>
</div>
<div v-if="clients === null" class="p-5 text-gray-200 dark:text-red-300">
<svg class="mx-auto w-5 animate-spin" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
</div>
</div>
</div>
<!-- QR Code -->
<div v-if="qrcode">
<div class="fixed bottom-0 left-0 right-0 top-0 z-20 flex items-center justify-center bg-black bg-opacity-50">
<div class="relative rounded-md bg-white p-8 shadow-lg">
<button
class="absolute right-4 top-4 text-gray-600 dark:text-neutral-500 hover:text-gray-800 dark:hover:text-neutral-700"
@click="qrcode = null"
>
<svg class="w-8" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
<img :src="qrcode" />
</div>
</div>
</div>
<!-- Create Dialog -->
<div v-if="clientCreate" class="fixed inset-0 z-10 overflow-y-auto">
<div class="min-h-screen flex items-center justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
<!--
Background overlay, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0"
To: "opacity-100"
Leaving: "ease-in duration-200"
From: "opacity-100"
To: "opacity-0"
-->
<div class="fixed inset-0 transition-opacity" aria-hidden="true">
<div class="absolute inset-0 bg-gray-500 opacity-75 dark:bg-black dark:opacity-50"></div>
</div>
<!-- This element is to trick the browser into centering the modal contents. -->
<span class="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">​</span>
<!--
Modal panel, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0 tranneutral-y-4 sm:tranneutral-y-0 sm:scale-95"
To: "opacity-100 tranneutral-y-0 sm:scale-100"
Leaving: "ease-in duration-200"
From: "opacity-100 tranneutral-y-0 sm:scale-100"
To: "opacity-0 tranneutral-y-4 sm:tranneutral-y-0 sm:scale-95"
-->
<div
class="inline-block w-full transform overflow-hidden rounded-lg bg-white text-left align-bottom shadow-xl transition-all sm:my-8 sm:max-w-lg dark:bg-neutral-700 sm:align-middle"
role="dialog"
aria-modal="true"
aria-labelledby="modal-headline"
>
<div class="bg-white px-4 pb-4 pt-5 dark:bg-neutral-700 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div
class="mx-auto h-12 w-12 flex flex-shrink-0 items-center justify-center rounded-full bg-red-800 sm:mx-0 sm:h-10 sm:w-10"
>
<svg
class="h-6 w-6 text-white"
inline
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
</svg>
</div>
<div class="mt-3 flex-grow text-center sm:ml-4 sm:mt-0 sm:text-left">
<h3 id="modal-headline" class="text-lg text-gray-900 font-medium leading-6 dark:text-neutral-200">
{{ $t("newClient") }}
</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">
<input
v-model.trim="clientCreateName"
class="w-full border-2 border-gray-100 rounded p-2 outline-none dark:border-neutral-600 focus:border-gray-200 dark:bg-neutral-700 dark:text-neutral-200 focus:dark:border-neutral-500 dark:placeholder:text-neutral-400"
type="text"
:placeholder="$t('name')"
/>
</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse dark:bg-neutral-700 sm:px-6">
<button
v-if="clientCreateName.length > 0"
type="button"
class="w-full inline-flex justify-center border border-transparent rounded-md bg-red-800 px-4 py-2 text-base text-white font-medium shadow-sm sm:ml-3 sm:w-auto hover:bg-red-700 sm:text-sm focus:outline-none"
@click="
createClient();
clientCreate = null;
"
>
{{ $t("create") }}
</button>
<button
v-else
type="button"
class="w-full inline-flex cursor-not-allowed justify-center border border-transparent rounded-md bg-gray-200 px-4 py-2 text-base text-white font-medium shadow-sm sm:ml-3 sm:w-auto dark:bg-neutral-400 sm:text-sm dark:text-neutral-300"
>
{{ $t("create") }}
</button>
<button
type="button"
class="mt-3 w-full inline-flex justify-center border border-gray-300 rounded-md bg-white px-4 py-2 text-base text-gray-700 font-medium shadow-sm sm:ml-3 sm:mt-0 sm:w-auto dark:border-neutral-500 dark:bg-neutral-500 hover:bg-gray-50 sm:text-sm dark:text-neutral-50 focus:outline-none dark:hover:border-neutral-600 dark:hover:bg-neutral-600"
@click="clientCreate = null"
>
{{ $t("cancel") }}
</button>
</div>
</div>
</div>
</div>
<!-- Delete Dialog -->
<div v-if="clientDelete" class="fixed inset-0 z-10 overflow-y-auto">
<div class="min-h-screen flex items-center justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
<!--
Background overlay, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0"
To: "opacity-100"
Leaving: "ease-in duration-200"
From: "opacity-100"
To: "opacity-0"
-->
<div class="fixed inset-0 transition-opacity" aria-hidden="true">
<div class="absolute inset-0 bg-gray-500 opacity-75 dark:bg-black dark:opacity-50"></div>
</div>
<!-- This element is to trick the browser into centering the modal contents. -->
<span class="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">​</span>
<!--
Modal panel, show/hide based on modal state.
Entering: "ease-out duration-300"
From: "opacity-0 tranneutral-y-4 sm:tranneutral-y-0 sm:scale-95"
To: "opacity-100 tranneutral-y-0 sm:scale-100"
Leaving: "ease-in duration-200"
From: "opacity-100 tranneutral-y-0 sm:scale-100"
To: "opacity-0 tranneutral-y-4 sm:tranneutral-y-0 sm:scale-95"
-->
<div
class="inline-block w-full transform overflow-hidden rounded-lg bg-white text-left align-bottom shadow-xl transition-all sm:my-8 sm:max-w-lg dark:bg-neutral-700 sm:align-middle"
role="dialog"
aria-modal="true"
aria-labelledby="modal-headline"
>
<div class="bg-white px-4 pb-4 pt-5 dark:bg-neutral-700 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<div
class="mx-auto h-12 w-12 flex flex-shrink-0 items-center justify-center rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10"
>
<!-- Heroicon name: outline/exclamation -->
<svg
class="h-6 w-6 text-red-600"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
aria-hidden="true"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
/>
</svg>
</div>
<div class="mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left">
<h3 id="modal-headline" class="text-lg text-gray-900 font-medium leading-6 dark:text-neutral-200">
{{ $t("deleteClient") }}
</h3>
<div class="mt-2">
<p class="text-sm text-gray-500 dark:text-neutral-300">
{{ $t("deleteDialog1") }} <strong>{{ clientDelete.name }}</strong
>? {{ $t("deleteDialog2") }}
</p>
</div>
</div>
</div>
</div>
<div class="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse dark:bg-neutral-600 sm:px-6">
<button
type="button"
class="w-full inline-flex justify-center border border-transparent rounded-md bg-red-600 px-4 py-2 text-base text-white font-medium shadow-sm sm:ml-3 sm:w-auto dark:bg-red-600 hover:bg-red-700 sm:text-sm dark:text-white focus:outline-none dark:hover:bg-red-700"
@click="
deleteClient(clientDelete);
clientDelete = null;
"
>
{{ $t("deleteClient") }}
</button>
<button
type="button"
class="mt-3 w-full inline-flex justify-center border border-gray-300 rounded-md bg-white px-4 py-2 text-base text-gray-700 font-medium shadow-sm sm:ml-3 sm:mt-0 sm:w-auto dark:border-neutral-500 dark:bg-neutral-500 hover:bg-gray-50 sm:text-sm dark:text-neutral-50 focus:outline-none dark:hover:border-neutral-600 dark:hover:bg-neutral-600"
@click="clientDelete = null"
>
{{ $t("cancel") }}
</button>
</div>
</div>
</div>
</div>
</div>
<div v-if="authenticated === false">
<h1 class="my-16 text-center text-4xl text-gray-700 font-medium dark:text-neutral-200">
<img src="/img/logo.png" width="32" class="dark:bg inline align-middle" />
<span class="align-middle">WireGuard</span>
</h1>
<form class="mx-auto mt-10 w-64 overflow-hidden rounded-md bg-white p-5 shadow dark:bg-neutral-700" @submit="login">
<!-- Avatar -->
<div class="relative mx-auto mb-10 mt-5 h-20 w-20 overflow-hidden rounded-full bg-red-800 dark:bg-red-800">
<svg
class="m-5 h-10 w-10 text-white dark:text-white"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
>
<path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd" />
</svg>
</div>
<input
v-model="password"
type="password"
name="password"
:placeholder="$t('password')"
class="mb-5 w-full border-2 border-gray-100 rounded-lg px-3 py-2 text-sm text-gray-500 outline-none dark:border-neutral-800 focus:border-red-800 dark:bg-neutral-700 dark:text-gray-500 dark:focus:border-red-800 dark:placeholder:text-neutral-400"
/>
<button
v-if="authenticating"
class="w-full cursor-not-allowed rounded bg-red-800 py-2 text-sm text-white shadow dark:bg-red-800 dark:text-white"
>
<svg class="mx-auto w-5 animate-spin" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
</button>
<input
v-if="!authenticating && password"
type="submit"
class="w-full cursor-pointer rounded bg-red-800 py-2 text-sm text-white shadow transition dark:bg-red-800 hover:bg-red-700 dark:text-white dark:hover:bg-red-700"
:value="$t('signIn')"
/>
<input
v-if="!authenticating && !password"
type="submit"
class="w-full cursor-not-allowed rounded bg-gray-200 py-2 text-sm text-white shadow dark:bg-neutral-800 dark:text-white"
:value="$t('signIn')"
/>
</form>
</div>
<div v-if="authenticated === null" class="pb-12 pt-24 text-gray-300 dark:text-red-300">
<svg class="mx-auto w-5 animate-spin" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path
class="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
</div>
</div>
<p v-cloak class="m-10 text-center text-xs text-gray-300 dark:text-neutral-600">
<a class="hover:underline" target="_blank" href="https://github.com/wg-easy/wg-easy">WireGuard Easy</a> © 2021-2024 by
<a class="hover:underline" target="_blank" href="https://emilenijssen.nl/?ref=wg-easy">Emile Nijssen</a> is licensed under
<a class="hover:underline" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> ·
<a class="hover:underline" href="https://github.com/sponsors/WeeJeWel" target="_blank">{{ $t("donate") }}</a>
</p>
</div>
</template>
<script lang="ts">
import VueApexCharts from "vue-apexcharts";
import { format as timeagoFormat } from "timeago.js";
import API from "./js/api";
const UI_CHART_TYPES = [
{ type: false, strokeWidth: 0 },
{ type: "line", strokeWidth: 3 },
{ type: "area", strokeWidth: 0 },
{ type: "bar", strokeWidth: 0 },
];
const CHART_COLORS = {
rx: { light: "rgba(128,128,128,0.3)", dark: "rgba(255,255,255,0.3)" },
tx: { light: "rgba(128,128,128,0.4)", dark: "rgba(255,255,255,0.3)" },
gradient: { light: ["rgba(0,0,0,1.0)", "rgba(0,0,0,1.0)"], dark: ["rgba(128,128,128,0)", "rgba(128,128,128,0)"] },
};
export default {
components: {
Apexchart: VueApexCharts,
},
data() {
return {
authenticated: null,
authenticating: false,
password: null,
requiresPassword: null,
clients: null,
clientsPersist: {},
clientDelete: null,
clientCreate: null,
clientCreateName: "",
clientEditName: null,
clientEditNameId: null,
clientEditAddress: null,
clientEditAddressId: null,
qrcode: null,
currentRelease: null,
latestRelease: null,
uiTrafficStats: false,
uiChartType: 0,
uiShowCharts: localStorage.getItem("uiShowCharts") === "1",
uiTheme: localStorage.theme || "auto",
prefersDarkScheme: window.matchMedia("(prefers-color-scheme: dark)"),
chartOptions: {
chart: {
background: "transparent",
stacked: false,
toolbar: {
show: false,
},
animations: {
enabled: false,
},
parentHeightOffset: 0,
sparkline: {
enabled: true,
},
},
colors: [],
stroke: {
curve: "smooth",
},
fill: {
type: "gradient",
gradient: {
shade: "dark",
type: "vertical",
shadeIntensity: 0,
gradientToColors: CHART_COLORS.gradient[this.theme],
inverseColors: false,
opacityTo: 0,
stops: [0, 100],
},
},
dataLabels: {
enabled: false,
},
plotOptions: {
bar: {
horizontal: false,
},
},
xaxis: {
labels: {
show: false,
},
axisTicks: {
show: false,
},
axisBorder: {
show: false,
},
},
yaxis: {
labels: {
show: false,
},
min: 0,
},
tooltip: {
enabled: false,
},
legend: {
show: false,
},
grid: {
show: false,
padding: {
left: -10,
right: 0,
bottom: -15,
top: -15,
},
column: {
opacity: 0,
},
xaxis: {
lines: {
show: false,
},
},
},
},
};
},
computed: {
chartOptionsTX() {
const opts = {
...this.chartOptions,
colors: [CHART_COLORS.tx[this.theme]],
};
opts.chart.type = UI_CHART_TYPES[this.uiChartType].type || false;
opts.stroke.width = UI_CHART_TYPES[this.uiChartType].strokeWidth;
return opts;
},
chartOptionsRX() {
const opts = {
...this.chartOptions,
colors: [CHART_COLORS.rx[this.theme]],
};
opts.chart.type = UI_CHART_TYPES[this.uiChartType].type || false;
opts.stroke.width = UI_CHART_TYPES[this.uiChartType].strokeWidth;
return opts;
},
updateCharts() {
return this.uiChartType > 0 && this.uiShowCharts;
},
theme() {
if (this.uiTheme === "auto") {
return this.prefersDarkScheme.matches ? "dark" : "light";
}
return this.uiTheme;
},
},
mounted() {
this.prefersDarkScheme.addListener(this.handlePrefersChange);
this.setTheme(this.uiTheme);
this.api = new API();
this.api
.getSession()
.then((session) => {
this.authenticated = session.authenticated;
this.requiresPassword = session.requiresPassword;
this.refresh({
updateCharts: this.updateCharts,
}).catch((error) => {
alert(error.message || error.toString());
});
})
.catch((error) => {
alert(error.message || error.toString());
});
setInterval(() => {
this.refresh({
updateCharts: this.updateCharts,
}).catch(console.error);
}, 1000);
this.api
.getuiTrafficStats()
.then((res) => {
this.uiTrafficStats = res;
})
.catch(() => {
this.uiTrafficStats = false;
});
this.api
.getChartType()
.then((res) => {
this.uiChartType = Number.parseInt(res, 10);
})
.catch(() => {
this.uiChartType = 0;
});
Promise.resolve()
.then(async () => {
const currentRelease = await this.api.getRelease();
const latestRelease = await fetch("https://wg-easy.github.io/wg-easy/changelog.json")
.then(async (res) => res.json())
.then((releases) => {
const releasesArray = Object.entries(releases).map(([version, changelog]) => ({
version: Number.parseInt(version, 10),
changelog,
}));