forked from MartineauUK/wireguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wg_manager.asp
1371 lines (1261 loc) · 61 KB
/
wg_manager.asp
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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Expires" CONTENT="-1">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="icon" href="images/favicon.png">
<title><#833#> - WireGuard® Client</title>
<link rel="stylesheet" href="index_style.css">
<link rel="stylesheet" href="form_style.css">
<style>
p{
font-weight: bolder;
}
.collapsible {
color: white;
padding: 0px;
width: 100%;
border: none;
text-align: left;
outline: none;
cursor: pointer;
}
</style>
<!--<script src="/js/jquery.js"></script>-->
<script language="JavaScript" type="text/javascript" src="/state.js"></script>
<script language="JavaScript" type="text/javascript" src="/general.js"></script>
<script language="JavaScript" type="text/javascript" src="/popup.js"></script>
<script language="JavaScript" type="text/javascript" src="/help.js"></script>
<script language="JavaScript" type="text/javascript" src="/validator.js"></script>
<script language="JavaScript" type="text/javascript" src="/client_function.js"></script>
<script language="JavaScript" type="text/javascript" type="text/javascript" src="/form.js"></script>
<script language="JavaScript" type="text/javascript" src="js/httpApi.js"></script>
<script language="JavaScript" type="text/javascript" src="js/qrcode.min.js"></script>
<script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>
<!--<script language="JavaScript" type="text/javascript" src="/ext/shared-jy/jquery.js"></script>-->
<script language="JavaScript" type="text/javascript" src="/ext/wireguard/ExecuteResults.js"></script>
<!--<script language="JavaScript" type="text/javascript" src="/ext/wireguard/ExecutedTS.js"></script>-->
<style>
#wgm_QRCode_block{
position: absolute;
width: 230px;
height: 260px;
background-color: #444f53;
padding: 3px 3px;
margin-top: -40px;
}
</style>
<style>
#wgm_QRCode_block2{
position: absolute;
width: 230px;
height: 260px;
background-color: #444f53;
padding: 3px 3px;
margin-top: -40px;
}
</style>
<!-- https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_tooltip-->
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 230px;
background-color: #4D595D;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #4D595D transparent transparent transparent;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
<script>
<% get_wgc_parameter(); %>
var custom_settings = <% get_custom_settings(); %>;
var wgcindex = "<% nvram_get("wgmc_unit"); %>";
var wgsindex = "<% nvram_get("wgms_unit"); %>";
window.onresize = function(thisblock) {
cal_panel_block("wgm_QRCode_block", 0.18);
}
function initial(){
show_menu();
/* As per RMerlin Wiki https://github.com/RMerl/asuswrt-merlin.ng/wiki/Addons-API */
if (custom_settings.wgm_version == undefined)
document.getElementById('wgm_version').value = "N/A";
else
document.getElementById('wgm_version').value = custom_settings.wgm_version;
if (custom_settings.wgm_Kernel == undefined)
document.getElementById('wgm_Kernel').value = "N/A";
else
document.getElementById('wgm_Kernel').value = custom_settings.wgm_Kernel;
if (document.getElementById("wgm_ExecuteResultsBase64").innerHTML == "Pending............") {
UpdateResults();
document.getElementById("wgm_ExecuteResultsBase64").innerHTML == "Ready"
}
if (custom_settings.wgm_Execute_Result == undefined)
document.getElementById("wgm_ExecuteResultsBase64").innerHTML = "N/A"
else
document.getElementById("wgm_ExecuteResultsBase64").innerHTML = atob(custom_settings.wgm_Execute_Result);
GetConfigSettings();
document.getElementById('wgm_WebUI_Import').textContent = "";
var wgm_ver = document.getElementById('wgm_version').value;
if (wgm_ver.includes("b"))
repository = "dev";
else
repository = "main";
$("thead").click(function(){
$(this).siblings().toggle("fast");
})
$(".default-collapsed").trigger("click");
let cookie = getCookie("firsttime");
//if (cookie == "") {
// cookie doesn't exist, create it now
setCookie("firsttime", "1");
cookie = getCookie("ToggleCommandInterface");
if ( cookie != "1") {
setCookie("ToggleCommandInterface", "1"); // collapse it
Toggle("ToggleCommandInterface", "CMD_tab");
} else {
document.getElementById("CMD_tab").style.color = "lightgreen";
}
cookie = getCookie("ToggleControlCommands");
if ( cookie != "1") {
setCookie("ToggleControlCommands", "1");
//Toggle("ToggleControlCommands", "Controls_tab");
document.getElementById("Controls_tab").style.color = "lightgreen";
} else {
document.getElementById("Controls_tab").style.color = "lightblue";
}
cookie = getCookie("ToggleClientPeerConfiguration");
if ( cookie != "1") {
setCookie("ToggleClientPeerConfiguration", "1"); // collapse it
Toggle("ToggleClientPeerConfiguration", "ClientPeer_tab");
} else {
document.getElementById("ClientPeer_tab").style.color = "lightgreen";
}
cookie = getCookie("ToggleServerPeerConfiguration");
if ( cookie != "1") {
setCookie("ToggleServerPeerConfiguration", "1"); // collapse it
Toggle("ToggleServerPeerConfiguration", "ServerPeer_tab");
} else {
document.getElementById("ServerPeer_tab").style.color = "lightgreen";
}
setCookie("ToggleDevicePeer", "0");
document.getElementById("DevicePeer_tab").style.color = "grey";
//Toggle("ToggleDevicePeer");
cookie = getCookie("ToggleVPNDirector");
if ( cookie != "1") {
setCookie("ToggleVPNDirector", "1"); // collapse it
Toggle("ToggleVPNDirector", "VPNDirector_tab");
} else {
document.getElementById("VPNDirector_tab").style.color = "lightgreen";
}
setCookie("ToggleIPSET", "0");
//Toggle("ToggleIPSET");
document.getElementById("IPSET_tab").style.color = "grey";
setCookie("TogglePassthru", "0");
//Toggle("TogglePassthru");
document.getElementById("Passthru_tab").style.color = "grey";
cookie = getCookie("ToggleConfigurationOptions");
if ( cookie != "1") {
setCookie("ToggleConfigurationOptions", "1"); // collapse it
Toggle("ToggleConfigurationOptions", "Options_tab");
} else {
document.getElementById("Options_tab").style.color = "lightgreen";
}
cookie = getCookie("ToggleDiagnostics");
if ( cookie != "1") {
setCookie("ToggleDiagnostics", "1"); // collapse it
Toggle("ToggleDiagnostics", "Diags_tab");
} else {
document.getElementById("Diags_tab").style.color = "lightgreen";
}
//}
/* else {
debugger;
// not first visit.....
}*/
}
function Toggle(clickthis,tabName,scrollto) {
document.getElementById(clickthis).click();
let cookie = getCookie(tabName);
if (cookie == "1") {
setCookie(tabName, "0")
document.getElementById(tabName).style.color = "lightblue";
//setFocusOnDivWithId('WgmTabViewAutoScroll')
} else {
setCookie(tabName, "1")
document.getElementById(tabName).style.color = "lightgreen";
debugger;
if (scrollto != undefined && scrollto != null ) {
setFocusOnDivWithId(scrollto);
}
}
}
function setFocusOnDivWithId(elementId) {
document.getElementById(elementId).scrollIntoView();
}
function UpdateResults(){
document.getElementById("wgm_ExecuteResultsBase64").innerHTML = atob(custom_settings.wgm_Execute_Result);
document.getElementById("wgm_ExecuteRC").innerHTML = custom_settings.wgm_ExecuteRC;
}
function CMDExecute(){
HideCMDRC();
ShowCMDEexecuting();
/* As per RMerlin Wiki https://github.com/RMerl/asuswrt-merlin.ng/wiki/Addons-API */
/* Retrieve value from input fields, and store in object */
custom_settings.wgm_Execute = document.getElementById('wgm_Execute').value;
custom_settings.wgm_ExecuteRC = "Pending.....";
/* Store object as a string in the amng_custom hidden input field */
document.getElementById('amng_custom').value = JSON.stringify(custom_settings);
if(validForm()){
debugger;
if (custom_settings.wgm_Execute == "stop" || custom_settings.wgm_Execute == "start") {
/*document.action_wait.value = "3"; */
showLoading();
}
/*alert("Confirmation prompts such as\n\t\t'Are you sure you want to DELETE a Peer?\nobviously cannot be manually answered, so an affirmative auto reply\n\t\t'Y'\nwill be used'.\n\nSimilarly if you create a new Road-Warrior 'device' Peer, the Parent 'server' Peer will be automatically restarted so it can listen for the new Road-Warrior 'device' Peer, which may interrupt other Road-Warrior 'device' connections");*/
document.form.submit();
/*sleepThenAct();*/
UpdateResults();
}
}
function CMDExecuteARG(command){
ShowCMDEexecuting();
custom_settings.wgm_Execute = command;
custom_settings.wgm_ExecuteRC = "Pending.....";
/* Store object as a string in the amng_custom hidden input field */
document.getElementById('amng_custom').value = JSON.stringify(custom_settings);
if(validForm()){
if (custom_settings.wgm_Execute == "stop" || custom_settings.wgm_Execute == "start") {
/*document.action_wait.value = "3";*/
showLoading();
}
document.form.submit();
/*sleepThenAct();*/
UpdateResults();
}
}
function CMDExecutePeerImport(command){
ShowCMDEexecuting();
custom_settings.wgm_ExecuteRC = "Pending.....";
var importType="";
if (document.getElementById('wgm_ImportServer_enabled').checked) {
importType="type=server"
}
if (document.getElementById('wgm_WebUI_Import').textContent == undefined)
custom_settings.wgm_Execute = "import " + document.getElementById('wgm_PeerImport').value + " " + importType;
else
custom_settings.wgm_Execute = "WebUI_Import " + btoa(document.getElementById('wgm_WebUI_Import').textContent + " " + importType);
/* Store object as a string in the amng_custom hidden input field */
document.getElementById('amng_custom').value = JSON.stringify(custom_settings);
if(validForm()){
showLoading();
document.form.submit();
/*sleepThenAct();*/
UpdateResults();
}
document.getElementById('wgm_WebUI_Import').textContent = ""
}
function SwitchClientState(){
var Connected = "<% nvram_get("wgmc_enable"); %>";
var PeerDefined = "<% nvram_get("wgmc_unit"); %>";
if (PeerDefined != "") {
if (Connected == "1") {
CMDExecuteARG("stop wg1" + PeerDefined);
} else {
CMDExecuteARG("start wg1" + PeerDefined);
}
} else {
alert("***ERROR: 'client' Peer not configured");
}
}
function SwitchServerState(){
var Connected = "<% nvram_get("wgms_enable"); %>";
var PeerDefined = "<% nvram_get("wgms_unit"); %>";
if (PeerDefined != "") {
if (Connected == "1") {
CMDExecuteARG("stop wg2" + PeerDefined);
} else {
CMDExecuteARG("start wg2" + PeerDefined);
}
} else {
alert("***ERROR: 'server' Peer not configured");
}
}
function ModifyPeerState(action,peer){
if (peer == "wg1") {
var PeerDefined = "<% nvram_get("wgmc_unit"); %>";
var list = document.getElementsByName('wgmc_unit');
} else {
var PeerDefined = "<% nvram_get("wgms_unit"); %>";
var list = document.getElementsByName('wgms_unit');
}
if (PeerDefined != "") {
CMDExecuteARG(action + " " + peer + PeerDefined);
} else {
alert("***ERROR: Peer " + peer + "x NOT configured");
}
}
function applyRule(){
if(validForm()){
/*showLoading();*/
document.form.submit();
}
}
function validForm(){
return true;
}
function sleepFor(sleepDuration){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){
/* Do nothing */
}
}
function sleepThenAct(){
sleepFor(2000);
console.log("Hello, JavaScript sleep!");
}
function change_wgmc_unit(unit){
document.chg_wgmc.wgmc_unit.value=unit.toString();
CMDExecuteARG('export wg1' + unit);
}
function ShowQRCode() {
$('#wgm_QRCode_block').show();
cal_panel_block("wgm_QRCode_block", 0.18);
}
function HideQRCode(){
$('#wgm_QRCode_block').hide();
}
function change_wgms_unit(unit){
document.chg_wgms.wgms_unit.value=unit.toString();
CMDExecuteARG('export wg2' + unit);
}
function ShowCMDEexecuting() {
$('#imgExecuting').show();
/*document.getElementById("imgExecuting").style.visibility = "visible";*/
}
function HideCMDEexecuting(){
$('#imgExecuting').hide();
/*document.getElementById("imgExecuting").style.visibility = "visible";*/
}
function ShowCMDRC() {
$('#wgm_ExecuteRC').show();
/*document.getElementById("imgExecuting").style.visibility = "visible";*/
}
function HideCMDRC(){
$('#wgm_ExecuteRC').hide();
/*document.getElementById("imgExecuting").style.visibility = "visible";*/
}
function ShowWinFile() {
$('#wgm_WinFile_block').show();
cal_panel_block("wgm_WinFile_block", 0.18);
}
function HideWinFile(){
$('#wgm_WinFile_block').hide();
}
function GetConfigSettings() {
$.ajax({
url: "/ext/wireguard/config.htm",
dataType: "text",
cache: !1,
error: function(t) {
setTimeout(GetConfigSettings, 1e3)
},
success: function(data) {
for (var configdata = data.split("\n"), configdata = configdata.filter(Boolean), i = 0; i < configdata.length; i++) {
/*https://stackoverflow.com/questions/58718800/how-to-set-radio-button-by-default-based-on-variable-value*/
if (configdata[i] == "WEBUI"){
$('#wgm_WEBUI').prop('checked',true);
}
if (configdata[i] == "USE_ENTWARE_KERNEL_MODULE"){
$('#wgm_USE_ENTWARE_KERNEL_MODULE_enabled').prop('checked',true);
}
if (configdata[i] == "NOIPV6"){
$('#wgm_NOIPV6_enabled').prop('checked',true);
}
if (configdata[i] == "DISABLE_FLOW_CACHE"){
$('#wgm_DISABLE_FLOW_CACHE_enabled').prop('checked',true);
}
if (configdata[i] == "NOCOLOR"){
$('#wgm_NOCOLOR_enabled').prop('checked',true);
}
if (configdata[i] == "NOMENU"){
$('#wgm_NOMENU_enabled').prop('checked',true);
}
if (configdata[i] == "ROGUE220IGNORE"){
$('#wgm_ROGUE220IGNORE_enabled').prop('checked',true);
}
if (configdata[i] == "ROGUE220DELETE"){
$('#wgm_ROGUE220DELETE_enabled').prop('checked',true);
}
if (configdata[i] == "KILLSWITCH"){
$('#wgm_KILLSWITCH_enabled').prop('checked',true);
}
}
}
})
}
// https://www.w3schools.com/js/js_cookies.asp
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
</script>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=300,width=400,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<script>
// https://sebhastian.com/javascript-confirmation-yes-no/
function confirmPeerDelete(wgPeer) {
let confirmAction = confirm("Confirm OK to DELETE Peer: '" + wgPeer + "'");
if (confirmAction) {
CMDExecuteARG("peer " + wgPeer + " del");
} else {
alert("DELETE Peer: '" + wgPeer + "' request cancelled");
}
}
</script>
<script>
function confirmDescFieldUpdate(comment) {
let confirmAction = confirm("Confirm OK to Update 'Annotate/Tag' to " + comment + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " comment " + comment);
} else {
alert("Update 'Annotate/Tag' cancelled!");
}
}
</script>
<script>
function confirmAutoFieldUpdate(auto) {
let confirmAction = confirm("Confirm OK to Update 'Auto-Start Type' to '" + auto + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " auto=" + auto);
} else {
alert("Update 'Auto-Start' cancelled!");
}
}
</script>
<script>
function confirmServerAutoFieldUpdate(auto) {
let confirmAction = confirm("Confirm OK to Update 'Auto-Start Type' to '" + auto + "'");
if (confirmAction) {
CMDExecuteARG("peer wg2" + wgcindex + " auto=" + auto);
} else {
alert("Update 'Auto-Start' cancelled!");
}
}
</script>
<script>
function confirmAddressFieldUpdate(address) {
let confirmAction = confirm("Confirm OK to Update 'Address' to '" + address + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " ip=" + address);
} else {
alert("Update 'Address' cancelled!");
}
}
</script>
<script>
function confirmDNSFieldUpdate(dns) {
let confirmAction = confirm("Confirm OK to Update 'DNS' to '" + dns + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " dns=" + dns);
} else {
alert("Update 'DNS' cancelled!");
}
}
</script>
<script>
function confirmPreSharedKeyFieldUpdate(psk_value) {
let confirmAction = confirm("Confirm OK to Update 'Preshared Key' to '" + psk_value + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " psk=" + psk_value);
} else {
alert("Update 'Preshared Key' cancelled!");
}
}
</script>
<script>
function confirmAllowedIPsFieldUpdate(allowedips) {
let confirmAction = confirm("Confirm OK to Update 'Allowed IPs' to '" + allowedips + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " allowedips=" + allowedips);
} else {
alert("Update 'Allowed IPs' cancelled!");
}
}
</script>
<script>
function confirmEndpointAddressFieldUpdate(ep_addr) {
let confirmAction = confirm("Confirm OK to Update 'Endpoint Address' to '" + ep_addr + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " endpoint=" + ep_addr + ":" + document.getElementById('wgc_ep_port').value);
} else {
alert("Update 'Endpoint Address' cancelled!");
}
}
</script>
<script>
function confirmEndpointPortFieldUpdate(epp_value) {
let confirmAction = confirm("Confirm OK to Update 'Endpoint Port' to '" + epp_value + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " endpoint=" + document.getElementById('wgc_ep_addr').value + ":" + epp_value);
} else {
alert("Update 'Endpoint Port' cancelled!");
}
}
</script>
<script>
function confirmPersistentKeepAliveFieldUpdate(pka_value) {
let confirmAction = confirm("Confirm OK to Update 'Persistent Keep Alive' to '" + pka_value + "'");
if (confirmAction) {
CMDExecuteARG("peer wg1" + wgcindex + " psk=" + pka_value);
} else {
alert("Update 'Persistent Keep Alive' cancelled!");
}
}
</script>
<script>
function cloneVPNDirector() {
var SRCFilter = ""
var DSTPeer = ""
debugger;
if (document.getElementById('wgm_VPNDirector_SRCFilter').value != "No Source Filter") {
SRCFilter = document.getElementById('wgm_VPNDirector_SRCFilter').value
if (SRCFilter.length > 3)
SRCFilter = SRCFilter.slice(5)
//else
//SRCFilter = "wan"
}
debugger;
CMDExecuteARG('vpndirector clone ' + SRCFilter + " " + DSTPeer);
}
</script>
<script>
function confirmDeleteVPNDirector() {
let confirmAction = confirm("Confirm OK to DELETE ALL 'VPN Director' Policy Routing rules");
if (confirmAction) {
CMDExecuteARG('vpndirector delete');
} else {
alert("DELETE ALL 'VPN Director' Policy Routing rules cancelled!");
}
}
</script>
</head>
<body onload="initial();" onunLoad="setCookie('firsttime'); return unload_body();" class="bg">
<div id="TopBanner"></div>
<div id="Loading" class="popup_bg"></div>
<iframe name="hidden_frame" id="hidden_frame" src="" width="0" height="0" frameborder="0"></iframe>
<form method="post" name="form" id="ruleForm" action="/start_apply.htm" target="hidden_frame">
<input type="hidden" name="productid" value="<% nvram_get("productid"); %>">
<input type="hidden" name="current_page" value="wg_manager.asp">
<input type="hidden" name="next_page" value="wg_manager.asp">
<input type="hidden" name="modified" value="0">
<input type="hidden" name="first_time" value="">
<input type="hidden" name="action_mode" value="apply">
<input type="hidden" name="action_script" value="restart_wg_manager|serviceevent">
<input type="hidden" name="action_wait" value="1">
<input type="hidden" name="preferred_lang" id="preferred_lang" value="<% nvram_get("preferred_lang"); %>">
<input type="hidden" name="firmver" value="<% nvram_get("firmver"); %>">
<input type="hidden" name="amng_custom" id="amng_custom" value="">
<table class="content" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="17"> </td>
<td valign="top" width="202">
<div id="mainMenu"></div>
<div id="subMenu"></div>
</td>
<td valign="top">
<div id="tabMenu" class="submenuBlock"></div>
<table width="98%" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" >
<table width="760px" border="0" cellpadding="4" cellspacing="0" class="FormTitle" id="FormTitle">
<tbody>
<tr>
<td bgcolor="#4D595D" valign="top" >
<div> </div>
<div class="formfonttitle">VPN - WireGuard® Manager© v1.04 by Martineau</div>
<div id="divSwitchMenu" style="margin-top:-40px;float:right;"></div
<div style="margin:10px 0 10px 5px;" class="splitLine" id="WgmTabViewAutoScroll"></div>
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" bordercolor="#6b8fa3" class="FormTable">
<tr>
<th>WireGuard® Manager Version</th>
<td>
<input type="text" readonly maxlength="7" class="input_6_table" id="wgm_version">
</td>
<td align="center">
<input type="button" class="button_gen" onclick="JavaScript:newPopup('https://github.com/MartineauUK/wireguard/commits/' + repository + '/wg_manager.sh');" value="Change Log" id="btnShowHelp" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);">
</td>
<td colspan="2" align="center">
<input type="button" class="button_gen" onclick="JavaScript:newPopup('/ext/wireguard/help.htm');" value="Help" id="btnShowHelp" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);">
</td>
</tr>
<tr>
<th>WireGuard® Kernel Module version</th>
<td>
<input type="text" readonly maxlength="30" class="input_12_table" id="wgm_Kernel">
</td>
</tr>
</table>
<div> </div>
<div class="formfonttitle">WireGuard® Manager©</div>
<!--<div style="margin-top:;" >-->
<div id="wgmtabMenu" class="submenuBlock" align="center">
<div>
<table>
<tbody>
<tr>
<hr>
<td>
<div class="tab" onclick="Toggle('ToggleCommandInterface','CMD_tab');" title="wg_manager.asp" id="CMD_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>CMD</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleControlCommands', 'Controls_tab', 'ControlsViewAutoScroll');" title="wg_manager.asp" id="Controls_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Control Peers</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleClientPeerConfiguration', 'ClientPeer_tab', 'ClientViewAutoScroll');" title="wg_manager.asp" id="ClientPeer_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Client Peer</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleServerPeerConfiguration', 'ServerPeer_tab', 'ServerViewAutoScroll');" title="wg_manager.asp" id="ServerPeer_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Server Peer</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleDevicePeerConfiguration', 'DevicePeer_tab');" title="wg_manager.asp" id="DevicePeer_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Road-Warrior Peer</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleVPNDirector', 'VPNDirector_tab', 'VPNDirectorViewAutoScroll');" title="wg_manager.asp" id="VPNDirector_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>VPNDirector</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleIPSET', 'IPSET_tab');" title="wg_manager.asp" id="IPSET_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>IPSET</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('TogglePassthru', 'Passthru_tab');" title="wg_manager.asp" id="Passthru_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Passthru'</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleConfigurationOptions', 'Options_tab', 'OptionsViewAutoScroll');" title="wg_manager.asp" id="Options_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Options</span></div>
</td>
<td>
<div class="tab" onclick="Toggle('ToggleDiagnostics', 'Diags_tab', 'DiagViewAutoScroll');" title="wg_manager.asp" id="Diags_tab" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"><span>Diags</span></div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div style="line-height:8px;"> </div>
<hr>
<table id="WgcBasicTable" width="100%" border="1" align="center" cellpadding="4" cellspacing="0" class="FormTable SettingsTable">
<thead class="collapsible">
<tr><td id="ToggleCommandInterface" colspan="2">Command Interface</td></tr>
</thead>
<tbody>
<!--<tr>
<td colspan="2">WireGuard® Manager© Command</td>
</tr>-->
<td colspan="2" class="execbutton">
<label>wgm </label>
<input type="text" maxlength="100" class="input_32_table" id="wgm_Execute">
<img id="imgExecuting" style="vertical-align: middle; display: none;" src="images/InternetScan.gif">
<input type="button" class="button_gen" onclick="CMDExecute();" value="Execute" id="btnCMDExecute" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<label>RC= </label>
<input type="text" readonly maxlength="6" class="input_6_table" id="wgm_ExecuteRC">
<input type="button" onClick="location.href=location.href" value="Refresh Results" class="button_gen" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);">
</td>
<tr>
<td colspan="2">Command Execute Output</td>
</tr>
<tr>
<td style="padding: 0px;">
<div style="color:#FFCC00;"><input type="checkbox" checked id="auto_refresh">Auto refresh</div>
<!--Syslog text area definition-->
<!--<textarea cols="63" rows="27" wrap="off" readonly="readonly" id="textarea" class="textarea_ssh_table" style="width:99%; font-family:'Courier New', Courier, mono; font-size:11px;">#TOP of Syslog</textarea>-->
<!--<textarea cols="63" rows="27" wrap="off" readonly="readonly" id="wgm_ExecuteResultsBase64" class="textarea_ssh_table" style="width:99%; font-family:'Courier New', Courier, mono; font-size:13px;">#TOP of Syslog</textarea>-->
<textarea cols="63" rows="27" wrap="off" readonly="readonly" id="wgm_ExecuteResultsBase64" class="textarea_ssh_table" style="width:99%; font-family:'Courier New', Helvetica, MS UI Gothic, MS P Gothic, Microsoft Yahei UI, sans-serif; font-size:13px;">#TOP of Syslog</textarea>
</tr>
</tbody>
</table>
<!--====================================================Peer Control (Import etc.)==========================================================-->
<table width="100%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#4D595D" class="FormTable">
<thead class="collapsible">
<tr><td colspan="4" id="ToggleControlCommands">Peer control Commands</td></tr>
</thead>
<tbody>
</tr>
<td colspan="2">
<input type="text" maxlength="30" class="input_32_table" id="wgm_PeerImport">
<legend>Import from <% nvram_get("productid"); %> Directory '/opt/etc/wireguard.d/'<legend>
</td>
<td rowspan="2">
<input type="radio" name="wgm_IMPORT" id="wgm_ImportClient_enabled" class="input" value="enable" checked="">
<label for="XIMPORT_PEER">Client</label>
<br>
<input type="radio" name="wgm_IMPORT" id="wgm_ImportServer_enabled" class="input" value="disable">
<label for="XIMPORT_PEER">Server</label>
</td>
<td rowspan="2">
<input type="button" class="button_gen" onclick="CMDExecutePeerImport();" value="Import" id="btnClientImport" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
</td>
</tr>
<div style="line-height:10px;" id="ControlsViewAutoScroll"> </div>
<tr>
<td colspan="4" class="buttongen">
<label>Upload from Local: ==> </label>
<input type="file" name="inputfile" id="inputfile">
<!--<legend>Upload from local PC<legend>-->
<br>
<pre id="wgm_WebUI_Import"></pre>
<script type="text/javascript">
document.getElementById('inputfile').addEventListener('change', function() {
var fr=new FileReader();
fr.onload=function(){
document.getElementById('wgm_WebUI_Import')
.textContent=fr.result;
}
fr.readAsText(this.files[0]);
})
</script>
</td>
<tr id="wg_export_setting">
<th>Export configuration file</th>
<td colspan="3">
<input class="button_gen" type="button" value="<#1509#>" onClick="exportConfig();" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);"/>
</td>
</tr>
</tr>
<tr>
<td class="settingname">DEFINED Peers</td>
<td colspan="3">
<input type="button" class="button_gen" onclick="CMDExecuteARG('diag peers');" value="Show ALL" id="btnDiagPeers" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);">
</td>
</tr>
<tr>
<td class="settingname">ACTIVE Peers</td>
<td colspan="3">
<input type="button" class="button_gen" onclick="CMDExecuteARG('list');" value="Show ALL" id="btnListPeers" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);">
</td>
</tr>
<tr>
<td>ALL Peers </td>
<td colspan="3">
<input type="button" class="button_gen" onclick="CMDExecuteARG('stop');" value="Stop" id="btnStopPeers" style="color: indianred; background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="CMDExecuteARG('start');" value="Start" id="btnStartPeers" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="CMDExecuteARG('restart');" value="Restart" id="btnRestartPeers" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
</td>
</tr>
<tr>
<td>Category: 'clients'</td>
<td colspan="3">
<input type="button" class="button_gen" onclick="CMDExecuteARG('stop clients');" value="Stop" id="btnStopCategoryClients" style="color: indianred; background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="CMDExecuteARG('start clients');" value="Start" id="btnStartCategoryClients" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="CMDExecuteARG('restart clients');" value="Restart" id="btnRestartCategoryClients" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
</td>
</tr>
<tr>
<td>Category: 'servers'</td>
<td colspan="3">
<input type="button" class="button_gen" onclick="CMDExecuteARG('stop servers');" value="Stop" id="btnStopCategoryServers" style="color: indianred; background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="CMDExecuteARG('start servers');" value="Start" id="btnStartCategoryServers" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="CMDExecuteARG('restart servers');" value="Restart" id="btnRestartCategoryServers" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
</td>
</tr>
</tbody>
</table>
<!--====================================================Client Configuration==========================================================-->
<div style="line-height:10px;" id="ClientViewAutoScroll"> </div>
<table id="ClientPeerTable" width="100%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#4D595D" class="FormTable">
<thead>
<tr>
<td colspan="2" id="ToggleClientPeerConfiguration">Client Peer Configuration</td>
</tr>
</thead>
<tbody>
<tr id="wgmc_unit_field" class="rept ew">
<th>Select Client Index</th>
<td>
<select name="wgmc_unit" class="input_option" onChange="change_wgmc_unit(this.value);">
<option class="content_input_fd" value="1" <% nvram_match("wgmc_unit", "1", "selected"); %>>1</option>
<option class="content_input_fd" value="2" <% nvram_match("wgmc_unit", "2", "selected"); %>>2</option>
<option class="content_input_fd" value="3" <% nvram_match("wgmc_unit", "3", "selected"); %>>3</option>
<option class="content_input_fd" value="4" <% nvram_match("wgmc_unit", "4", "selected"); %>>4</option>
<option class="content_input_fd" value="5" <% nvram_match("wgmc_unit", "5", "selected"); %>>5</option>
<option class="content_input_fd" value="6" <% nvram_match("wgmc_unit", "6", "selected"); %>>6</option>
<option class="content_input_fd" value="7" <% nvram_match("wgmc_unit", "7", "selected"); %>>7</option>
<option class="content_input_fd" value="8" <% nvram_match("wgmc_unit", "8", "selected"); %>>8</option>
<option class="content_input_fd" value="9" <% nvram_match("wgmc_unit", "9", "selected"); %>>9</option>
</select>
</td>
</tr>
<tr>
<th>Description</th>
<td>
<input type="text" maxlength="40" name="wgc_desc" id="wgc_desc" onChange="confirmDescFieldUpdate(this.value);" class="input_32_table" value="<% nvram_get("wgmc_desc"); %>" autocorrect="off" autocapitalize="off"></input>
</td>
</tr>
<tr id="wgc_auto_field" class="rept ew">
<th>Auto start Type</th>
<td>
<select name="wgmc_auto_type" class="input_option" onChange="confirmAutoFieldUpdate(this.value);">
<option value="Y" <% nvram_match("wgmc_auto", "Y", "selected"); %>>Auto Start</option>
<option value="N" <% nvram_match("wgmc_auto", "N", "selected"); %>>DISABLED</option>
<option value="P" <% nvram_match("wgmc_auto", "P", "selected"); %>>Policy Mode</option>
<option value="S" <% nvram_match("wgmc_auto", "S", "selected"); %>>Site to Site</option>
<option value="W" <% nvram_match("wgmc_auto", "W", "selected"); %>>WG-Quick</option>
</select>
</td>
</tr>
<tr id="wgmc_status">
<th><div class="tooltip"><#3179#><span class="tooltiptext">For convenience, you can instantly change the connection state<br>by clicking the checkbox !</span></div></th>
<td>
<input type="checkbox" value="1" onclick="SwitchClientState();" name="wgmc_enable" class="input" <% nvram_match("wgmc_enable", "1", "checked"); %>><#188#></input>
</td>
</tr>
<tr>
<td colspan="4">
<input type="button" class="button_gen" onclick="ModifyPeerState('stop', 'wg1');" value="Stop" id="btnStopWGClient" style="width: 123px; color: indianred; background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="ModifyPeerState('start', 'wg1');" value="Start" id="btnStartWGClient" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="ModifyPeerState('restart', 'wg1');" value="Restart" id="btnRestartWGClient" style="background: linear-gradient(rgb(34, 164, 21) 0%, rgb(34, 164, 21) 100%);">
<input type="button" class="button_gen" onclick="confirmPeerDelete('wg1' + wgcindex);" value="Delete" id="btnDeleteWGClient" style="background: linear-gradient(rgb(234, 45, 8) 0%, rgb(234, 45, 8) 100%);">
<input type="button" class="button_gen" onClick="ShowQRCode('wg11');" value="QR Code" style="background: linear-gradient(rgb(9, 99, 156) 0%, rgb(0, 48, 71) 100%);"/>
<div id="wgm_QRCode_block" style="display:none">
<div style="display:flex; align-items: center;">
<div style="width:20px;height:20px;background-image:url('images/New_ui/disable.svg');cursor:pointer" onclick="HideQRCode();"></div>
</div>
<div id="qrcode"></div>
<script type="text/javascript">
new QRCode(document.getElementById("qrcode"), "<% nvram_get("wgmc_desc"); %>" + "\n[Interface]" + "\nPrivateKey = " + "<% nvram_get("wgmc_priv"); %>" + "\nAddress = " + "<% nvram_get("wgmc_addr"); %>" + "\nDNS = " + "<% nvram_get("wgmc_dns"); %>" + "\n\n[Peer]" + "\nPublicKey = " + "<% nvram_get("wgmc_ppub"); %>" + "\nAllowedIPs = " + "<% nvram_get("wgmc_aips"); %>" + "\nEndPoint = " + "<% nvram_get("wgmc_ep_addr"); %>" + ":" + "<% nvram_get("wgmc_ep_port"); %>" );
</script>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="background: linear-gradient(to bottom, #92A0A5 0%, #66757C 100%)">Interface</td>
</tr>
<tr>
<th>Private Key</th>
<td>
<input type="text" readonly maxlength="63" name="wgc_priv" id="wgc_priv" onChange="confirmPrivateKeyFieldUpdate(this.value);" class="input_32_table" value="<% nvram_get("wgmc_priv"); %>" autocorrect="off" autocapitalize="off"></input>
</td>
</tr>
<tr>
<th>Address</th>
<td>
<input type="text" maxlength="39" name="wgc_addr" id="wgc_addr" onChange="confirmAddressFieldUpdate(this.value);" class="input_32_table" value="<% nvram_get("wgmc_addr"); %>" autocorrect="off" autocapitalize="off"></input>
</td>
</tr>
<tr>
<th>DNS Server (Optional)</th>
<td>
<input type="text" maxlength="39" name="wgc_dns" id="wgc_dns" onChange="confirmDNSFieldUpdate(this.value);"class="input_32_table" value="<% nvram_get("wgmc_dns"); %>" autocorrect="off" autocapitalize="off"></input>
</td>
</tr>
<tr>
<th><div class="tooltip">MTU<span class="tooltiptext">WireGuard® will auto determine the<br>MTU if not specified<br><br>IPv4 = 1440<br>IPv6 = 1420<br>IPv4 PPoE = 1432<br>IPv6 PPoE = 1412<br><br>Some WireGuard® ISPs custom MTU<br>e.g. TorGuard = 1292<br><br>Another common value is 1380<br><br>Minimum accepted is 1280</span></div></th>
<td>
<input type="text" maxlength="39" name="wgc_mtu" id="wgc_mtu" onChange="confirmMTUFieldUpdate(this.value);"class="input_32_table" value="<% nvram_get("wgmc_mtu"); %>" autocorrect="off" autocapitalize="off"></input>
</td>
</tr>
<tr>