1
1
( new URL ( window . location . href ) ) . searchParams . forEach ( ( x , y ) => {
2
2
let el = document . getElementsByName ( y ) [ 0 ] ;
3
- if ( el )
4
- el . value = x ;
3
+ if ( el ) {
4
+ console . log ( el . type ) ;
5
+ if ( el . type == "checkbox" ) {
6
+ el . checked = ( x == "on" ) ;
7
+ el . dispatchEvent ( new InputEvent ( 'change' ) ) ;
8
+ }
9
+ else el . value = x ;
10
+ }
5
11
} ) ;
6
12
7
13
// Make the result section disappear when changing relevant input fields
@@ -10,9 +16,11 @@ for (var element of document.getElementById("relevant_for_clientconfig").getElem
10
16
}
11
17
12
18
function genCfg ( ) {
19
+ if ( document . getElementsByName ( "pka" ) [ 0 ] . checked ) genPsk ( ) ;
13
20
let results = document . getElementById ( 'results' ) ;
14
21
results . setAttribute ( "style" , "" ) ;
15
22
let kp = wireguard . generateKeypair ( ) ;
23
+ document . getElementById ( "puk" ) . value = kp . publicKey ;
16
24
let fd = new FormData ( document . getElementById ( 'params' ) ) ;
17
25
let clientcfg = [
18
26
"[Interface]" ,
@@ -79,6 +87,15 @@ function genPsk() {
79
87
pkfield . dispatchEvent ( new InputEvent ( 'beforeinput' ) ) ;
80
88
}
81
89
90
+ function generateCN ( ) {
91
+ d = new Date ( ) ;
92
+ var datestring = d . getFullYear ( ) . toString ( ) . substring ( 2 ) + "-" + ( "0" + ( d . getMonth ( ) + 1 ) ) . slice ( - 2 ) + "-" + ( "0" + d . getDate ( ) ) . slice ( - 2 ) +
93
+ "_" + ( "0" + d . getHours ( ) ) . slice ( - 2 ) + "-" + ( "0" + d . getMinutes ( ) ) . slice ( - 2 ) + "-" + ( "0" + d . getSeconds ( ) ) . slice ( - 2 ) ;
94
+ let cnfield = document . getElementsByName ( 'cn' ) [ 0 ] ;
95
+ cnfield . value = 'user_' + datestring ;
96
+ cnfield . dispatchEvent ( new InputEvent ( 'beforeinput' ) ) ;
97
+ }
98
+
82
99
function copycl ( text ) {
83
100
navigator . clipboard . writeText ( text ) . then ( function ( ) {
84
101
console . log ( 'Async: Copying to clipboard was successful!' ) ;
@@ -170,7 +187,9 @@ function getIP() {
170
187
try {
171
188
res = JSON . parse ( xmlHttp . responseText ) ;
172
189
if ( res . error || ! res . ip ) throw ""
173
- document . getElementsByName ( 'ca' ) [ 0 ] . value = res . ip ;
190
+ let cafield = document . getElementsByName ( 'ca' ) [ 0 ] ;
191
+ cafield . value = res . ip ;
192
+ cafield . dispatchEvent ( new InputEvent ( 'beforeinput' ) ) ;
174
193
document . getElementById ( 'err' ) . innerHTML = "Get unused IP: success" ;
175
194
document . getElementById ( 'err' ) . setAttribute ( "style" , "background-color: rgb(100, 255, 100)" ) ;
176
195
}
@@ -200,7 +219,8 @@ function pushconfig() {
200
219
"&key=" + encodeURIComponent ( document . getElementsByName ( 'osk' ) [ 0 ] . value ) +
201
220
"&secret=" + encodeURIComponent ( document . getElementsByName ( 'oss' ) [ 0 ] . value ) +
202
221
"&PeerName=" + encodeURIComponent ( document . getElementsByName ( 'cn' ) [ 0 ] . value ) +
203
- "&pubkey=" + encodeURIComponent ( document . getElementsByName ( 'puk' ) [ 0 ] . value ) +
222
+ "&pubkey=" + encodeURIComponent ( document . getElementById ( 'puk' ) . value ) +
223
+ "&pskey=" + encodeURIComponent ( document . getElementsByName ( 'pk' ) [ 0 ] . value ) +
204
224
"&ServerUUID=" + encodeURIComponent ( document . getElementsByName ( 'owg' ) [ 0 ] . value ) +
205
225
"&tunnelAddress=" + encodeURIComponent ( document . getElementsByName ( 'ca' ) [ 0 ] . value ) , true ) ;
206
226
xmlHttp . responseType = "JSON" ;
@@ -225,9 +245,3 @@ function pushconfig() {
225
245
226
246
}
227
247
228
- function generateCN ( ) {
229
- d = new Date ( ) ;
230
- var datestring = d . getFullYear ( ) . toString ( ) . substring ( 2 ) + "-" + ( "0" + ( d . getMonth ( ) + 1 ) ) . slice ( - 2 ) + "-" + ( "0" + d . getDate ( ) ) . slice ( - 2 ) +
231
- "_" + ( "0" + d . getHours ( ) ) . slice ( - 2 ) + "-" + ( "0" + d . getMinutes ( ) ) . slice ( - 2 ) + "-" + ( "0" + d . getSeconds ( ) ) . slice ( - 2 ) ;
232
- document . getElementsByName ( 'cn' ) [ 0 ] . value = 'user_' + datestring ;
233
- }
0 commit comments