-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy path_worker.js
More file actions
1292 lines (1135 loc) · 58.9 KB
/
_worker.js
File metadata and controls
1292 lines (1135 loc) · 58.9 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
// <!--liMil-->Donate liMil: TDncy4ESqxsjL2fTv2fFauAnwah7EERrSt , https://nowpayments.io/donation/limil <!--liMil-END-->.
// @ts-ignore
function MainConfig() {
globalThis.uzerID = "12345678-1111-1234-1234-1234567890ab";
globalThis.qrexyIP = atob('Y2lwLnRyb25iYW5rLnNpdGU=');
}
function WebConfig() {
globalThis.ThisVersion = "3.4.2";
globalThis.AccessSubscription = "_SubscriptionURL_";
globalThis.AccessAdvancedConfig = "_AdvancedConfigURL_";
globalThis.fpaths = 'js,css,assets,wp-content,themes,app,cdn,jquery,live'; //Path URL: First folder in Sub
globalThis.CleanIPDomain = "time.is";
}
export default {
async fetch(request, env) {
try {
MainConfig();
globalThis.UzKey = env.UUID || globalThis.uzerID;
globalThis.CLxIP = env.PROXYIP || globalThis.qrexyIP;
if (!isValidUUID(globalThis.UzKey))
throw new Error(`First register the UID.`);
const url = new URL(request.url);
globalThis.pathName = url.pathname;
if(globalThis.pathName.startsWith("/url-")){
var TnlSecKey = "/url-"+globalThis.UzKey.split('-')[0]+"/";
if(globalThis.pathName.startsWith(TnlSecKey)){
return await hTnlReq(request, globalThis.pathName.replaceAll(TnlSecKey, ""));
}
}
const upgradeHeader = request.headers.get('Upgrade');
if (!upgradeHeader || upgradeHeader !== 'websocket') {
WebConfig();
globalThis.hostName = request.headers.get('Host');
if(globalThis.AccessAdvancedConfig == "_"+"AdvancedConfigURL"+"_"){globalThis.AccessAdvancedConfig = globalThis.UzKey;}
if(globalThis.AccessSubscription == "_"+"SubscriptionURL"+"_"){globalThis.AccessSubscription = 'sub/'+globalThis.UzKey;}
const GetParams = new URLSearchParams(url.search);
globalThis.GetPath = GetParams.get("path");
globalThis.CnfgName = globalThis.hostName.split('.')[0];
switch (globalThis.pathName) {
case '/':
return await MyHomeGame();
case `/${globalThis.AccessSubscription}`:
return await getVVConfig();
case `/${globalThis.AccessAdvancedConfig}`:
return await AdvancedConfig();
default:
return new Response('Not found', { status: 404 });
}
} else {
return await vOWSHandler(request);
}
} catch (err) {
/** @type {Error} */ let e = err;
return new Response(e.toString());
}
},
};
import { connect } from 'cloudflare:sockets';
async function vOWSHandler(request) {
const webSocketPair = new WebSocketPair();
const [client, webSocket] = Object.values(webSocketPair);
webSocket.accept();
let address = '';
let portWithRandomLog = '';
const log = (/** @type {string} */ info, /** @type {string | undefined} */ event) => {
console.log(`[${address}:${portWithRandomLog}] ${info}`, event || '');
};
const earlyDataHeader = request.headers.get('sec-websocket-protocol') || '';
const readableWebSocketStream = mkRdWSktStrm(webSocket, earlyDataHeader, log);
let remoteSocketWapper = {
value: null,
};
let udpStreamWrite = null;
let isDns = false;
readableWebSocketStream.pipeTo(new WritableStream({
async write(chunk, controller) {
if (isDns && udpStreamWrite) {
return udpStreamWrite(chunk);
}
if (remoteSocketWapper.value) {
const writer = remoteSocketWapper.value.writable.getWriter()
await writer.write(chunk);
writer.releaseLock();
return;
}
const {
hasError,
message,
portRemote = 443,
addressRemote = '',
rawDataIndex,
vVvVersion = new Uint8Array([0, 0]),
isUDP,
} = prssVvHeader(chunk, globalThis.UzKey);
address = addressRemote;
portWithRandomLog = `${portRemote}--${Math.random()} ${isUDP ? 'udp ' : 'tcp '
} `;
if (hasError) {
throw new Error(message);
return;
}
if (isUDP) {
if (portRemote === 53) {
isDns = true;
} else {
throw new Error('UDP use only enable for DNS which is port 53');
return;
}
}
const vvResponseHeader = new Uint8Array([vVvVersion[0], 0]);
const rawClientData = chunk.slice(rawDataIndex);
if (isDns) {
const { write } = await hUOBnd(webSocket, vvResponseHeader, log);
udpStreamWrite = write;
udpStreamWrite(rawClientData);
return;
}
hTOBound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, vvResponseHeader, log);
},
close() {
//log(`readWbSktStrm is x`);
},
abort(reason) {
//log(`readWbSktStrm is abrt`, JSON.stringify(reason));
},
})).catch((err) => {
//log('readWbSktStrm piTo err', err);
});
return new Response(null, {
status: 101,
webSocket: client,
});
}
async function hTOBound(remoteSocket, addressRemote, portRemote, rawClientData, webSocket, vvResponseHeader, log,) {
async function connectAndWrite(address, port) {
if (/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(address))
address = `${atob("d3d3Lg==")}${address}${atob("LnNzbGlwLmlv")}`;
const tcpSocket = connect({
hostname: address,
port: port,
});
remoteSocket.value = tcpSocket;
//log(`connected to ${address}:${port}`);
const writer = tcpSocket.writable.getWriter();
await writer.write(rawClientData);
writer.releaseLock();
return tcpSocket;
}
async function retry() {
const pnlPxIP = globalThis.pathName.split("/")[2];
const pnlPxIPs = pnlPxIP ? atob(pnlPxIP).split(",") : void 0;
const rmtPyIP = pnlPxIPs ? pnlPxIPs[Math.floor(Math.random() * pnlPxIPs.length)] : globalThis.CLxIP || addressRemote;
const tcpSocket = await connectAndWrite(rmtPyIP, portRemote)
tcpSocket.closed.catch(error => {
//console.log('retry tcpSocket closed error', error);
}).finally(() => {
safeCloseWebSocket(webSocket);
})
rmtSkt2WS(tcpSocket, webSocket, vvResponseHeader, null, log);
}
const tcpSocket = await connectAndWrite(addressRemote, portRemote);
rmtSkt2WS(tcpSocket, webSocket, vvResponseHeader, retry, log);
}
function mkRdWSktStrm(webSocketServer, earlyDataHeader, log) {
let readableStreamCancel = false;
const stream = new ReadableStream({
start(controller) {
webSocketServer.addEventListener('message', (event) => {
if (readableStreamCancel) {
return;
}
const message = event.data;
controller.enqueue(message);
});
webSocketServer.addEventListener('close', () => {
safeCloseWebSocket(webSocketServer);
if (readableStreamCancel) {
return;
}
controller.close();
}
);
webSocketServer.addEventListener('error', (err) => {
//log('webSocketServer has error');
controller.error(err);
}
);
const { earlyData, error } = base64ToArrayBuffer(earlyDataHeader);
if (error) {
controller.error(error);
} else if (earlyData) {
controller.enqueue(earlyData);
}
},
pull(controller) {
},
cancel(reason) {
if (readableStreamCancel) {
return;
}
//log(`ReadableStream was canceled, due to ${reason}`)
readableStreamCancel = true;
safeCloseWebSocket(webSocketServer);
}
});
return stream;
}
function prssVvHeader(vVvBuffer,UrKey) {
if (vVvBuffer.byteLength < 24) {
return {
hasError: true,
message: 'invalid data',
};
}
const version = new Uint8Array(vVvBuffer.slice(0, 1));
let isValidUser = false;
let isUDP = false;
if (stringify(new Uint8Array(vVvBuffer.slice(1, 17))) === UrKey) {
isValidUser = true;
}
if (!isValidUser) {
return {
hasError: true,
message: 'invalid user',
};
}
const optLength = new Uint8Array(vVvBuffer.slice(17, 18))[0];
const command = new Uint8Array(
vVvBuffer.slice(18 + optLength, 18 + optLength + 1)
)[0];
if (command === 1) {
} else if (command === 2) {
isUDP = true;
} else {
return {
hasError: true,
message: `command ${command} is not support, command 01-tcp,02-udp,03-mux`,
};
}
const portIndex = 18 + optLength + 1;
const portBuffer = vVvBuffer.slice(portIndex, portIndex + 2);
const portRemote = new DataView(portBuffer).getUint16(0);
let addressIndex = portIndex + 2;
const addressBuffer = new Uint8Array(
vVvBuffer.slice(addressIndex, addressIndex + 1)
);
const addressType = addressBuffer[0];
let addressLength = 0;
let addressValueIndex = addressIndex + 1;
let addressValue = '';
switch (addressType) {
case 1:
addressLength = 4;
addressValue = new Uint8Array(
vVvBuffer.slice(addressValueIndex, addressValueIndex + addressLength)
).join('.');
break;
case 2:
addressLength = new Uint8Array(
vVvBuffer.slice(addressValueIndex, addressValueIndex + 1)
)[0];
addressValueIndex += 1;
addressValue = new TextDecoder().decode(
vVvBuffer.slice(addressValueIndex, addressValueIndex + addressLength)
);
break;
case 3:
addressLength = 16;
const dataView = new DataView(
vVvBuffer.slice(addressValueIndex, addressValueIndex + addressLength)
);
const ipv6 = [];
for (let i = 0; i < 8; i++) {
ipv6.push(dataView.getUint16(i * 2).toString(16));
}
addressValue = ipv6.join(':');
break;
default:
return {
hasError: true,
message: `invild addressType is ${addressType}`,
};
}
if (!addressValue) {
return {
hasError: true,
message: `addressValue is empty, addressType is ${addressType}`,
};
}
return {
hasError: false,
addressRemote: addressValue,
addressType,
portRemote,
rawDataIndex: addressValueIndex + addressLength,
vVvVersion: version,
isUDP,
};
}
async function rmtSkt2WS(remoteSocket, webSocket, vvResponseHeader, retry, log) {
let remoteChunkCount = 0;
let chunks = [];
let vVvHeader = vvResponseHeader;
let hasIncomingData = false;
await remoteSocket.readable
.pipeTo(
new WritableStream({
start() {
},
async write(chunk, controller) {
hasIncomingData = true;
if (webSocket.readyState !== WS_READY_STATE_OPEN) {
controller.error(
'webSocket.readyState is not open, maybe close'
);
}
if (vVvHeader) {
webSocket.send(await new Blob([vVvHeader, chunk]).arrayBuffer());
vVvHeader = null;
} else {
webSocket.send(chunk);
}
},
close() {
//log(`remoteConnection!.readable is close with hasIncomingData is ${hasIncomingData}`);
},
abort(reason) {
console.error(`rmtConct!.redbl X`, reason);
},
})
)
.catch((error) => {
console.error(
`rmtSkt2WS has exception `,
error.stack || error
);
safeCloseWebSocket(webSocket);
});
if (hasIncomingData === false && retry) {
//log(`retry`)
retry();
}
}
function base64ToArrayBuffer(base64Str) {
if (!base64Str) {
return { error: null };
}
try {
base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
const decode = atob(base64Str);
const arryBuffer = Uint8Array.from(decode, (c) => c.charCodeAt(0));
return { earlyData: arryBuffer.buffer, error: null };
} catch (error) {
return { error };
}
}
function isValidUUID(uuid) {
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return uuidRegex.test(uuid);
}
const WS_READY_STATE_OPEN = 1;
const WS_READY_STATE_CLOSING = 2;
function safeCloseWebSocket(socket) {
try {
if (socket.readyState === WS_READY_STATE_OPEN || socket.readyState === WS_READY_STATE_CLOSING) {
socket.close();
}
} catch (error) {
console.error('loadingLargeFile error', error);
}
}
const byteToHex = [];
for (let i = 0; i < 256; ++i) {
byteToHex.push((i + 256).toString(16).slice(1));
}
function unsafeStringify(arr, offset = 0) {
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
}
function stringify(arr, offset = 0) {
const uuid = unsafeStringify(arr, offset);
if (!isValidUUID(uuid)) {
throw TypeError("Stringified UUID is invalid");
}
return uuid;
}
async function hUOBnd(webSocket, vvResponseHeader, log) {
let isvVvHeaderSent = false;
const transformStream = new TransformStream({
start(controller) {
},
transform(chunk, controller) {
for (let index = 0; index < chunk.byteLength;) {
const lengthBuffer = chunk.slice(index, index + 2);
const udpPakcetLength = new DataView(lengthBuffer).getUint16(0);
const udpData = new Uint8Array(
chunk.slice(index + 2, index + 2 + udpPakcetLength)
);
index = index + 2 + udpPakcetLength;
controller.enqueue(udpData);
}
},
flush(controller) {
}
});
transformStream.readable.pipeTo(new WritableStream({
async write(chunk) {
const resp = await fetch('https://1.1.1.1/dns-query',
{
method: 'POST',
headers: {
'content-type': 'application/dns-message',
},
body: chunk,
})
const dnsQueryResult = await resp.arrayBuffer();
const udpSize = dnsQueryResult.byteLength;
const udpSizeBuffer = new Uint8Array([(udpSize >> 8) & 0xff, udpSize & 0xff]);
if (webSocket.readyState === WS_READY_STATE_OPEN) {
//log(`doh success and dns message length is ${udpSize}`);
if (isvVvHeaderSent) {
webSocket.send(await new Blob([udpSizeBuffer, dnsQueryResult]).arrayBuffer());
} else {
webSocket.send(await new Blob([vvResponseHeader, udpSizeBuffer, dnsQueryResult]).arrayBuffer());
isvVvHeaderSent = true;
}
}
}
})).catch((error) => {
//log('dns udp has error' + error)
});
const writer = transformStream.writable.getWriter();
return {
write(chunk) {
writer.write(chunk);
}
};
}
async function hTnlReq(request, targetUrl) {
const url = new URL(request.url);
//let targetUrl = url.pathname.slice(1);
if(targetUrl.startsWith("aHR0")){
targetUrl = atob(targetUrl);
}
try {
new URL(targetUrl);
} catch (e) {
return new Response('Invalid URL provided.', { status: 400 });
}
const modifiedRequest = new Request(targetUrl + url.search, {
method: request.method,
headers: request.headers,
body: request.body,
redirect: request.redirect,
credentials: request.credentials,
});
return await fetch(modifiedRequest);
}
async function resolveDNS(domain) {
const dohURL2 = "https://cloudflare-dns.com/dns-query";
const dohURLv4 = `${dohURL2}?name=${encodeURIComponent(domain)}&type=A`;
const dohURLv6 = `${dohURL2}?name=${encodeURIComponent(domain)}&type=AAAA`;
try {
const [ipv4Response, ipv6Response] = await Promise.all([
fetch(dohURLv4, { headers: { accept: "application/dns-json" } }),
fetch(dohURLv6, { headers: { accept: "application/dns-json" } })
]);
const ipv4Addresses = await ipv4Response.json();
const ipv6Addresses = await ipv6Response.json();
const ipv4 = ipv4Addresses.Answer ? ipv4Addresses.Answer.map((record) => record.data) : [];
const ipv6 = ipv6Addresses.Answer ? ipv6Addresses.Answer.map((record) => record.data) : [];
return { ipv4, ipv6 };
} catch (error) {
console.error("Error resolving DNS:", error);
throw new Error(`An error occurred while resolving DNS - ${error}`);
}
}
async function AdvancedConfig() {
const pxipdomain = atob('Y2lwLnRyb25iYW5rLnNpdGU=');
const dnsdomain1 = await resolveDNS(globalThis.hostName);
const dnsdomain2 = await resolveDNS(globalThis.CleanIPDomain);
const dnsdomain4 = [...dnsdomain1.ipv4, ...dnsdomain2.ipv4];
const dnsdomain6 = [...dnsdomain1.ipv6, ...dnsdomain2.ipv6];
var TnlSecKey = "url-"+globalThis.UzKey.split('-')[0]+"/";
var addresslist = "<datalist id='addresslist'><option value='"+globalThis.hostName+"'><option value='www.speedtest.net'>";
for (var ip4 of dnsdomain4) {
if(ip4.slice(-1) == "."){ip4 = ip4.substr(0,ip4.length - 1);}
addresslist += "<option value='"+ip4+"'>";
}
for (var ip6 of dnsdomain6) {
if(ip6.slice(-1) == "."){continue;}
addresslist += "<option value='["+ip6+"]'>";
}
addresslist += "</datalist>";
const AdvancedPage = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Advanced Config Generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
:root{--color:black;--primary-color:#09639f;--background-color:#fff;--container-background-color:#f9f9f9;--line-background-color:#f2f2f2;--text-color:#333;--border-color:#ddd}
body,html{height:100%;margin:0}
body{font-family:system-ui;background-color:var(--background-color);color:var(--text-color);display:flex;justify-content:center;align-items:start;}
body.dark-mode{--color: white;--primary-color: #09639F;--background-color: #121212;--line-background-color: #252525;--container-background-color: #121212;--text-color: #DFDFDF;--border-color: #353535;}
.container{background:var(--container-background-color);padding:20px;border:1px solid var(--border-color);border-radius:10px;box-shadow:0 2px 4px rgba(0,0,0,.1);width:90%;max-width:940px;margin: 10px 0;}
.line,button{padding:10px}
.line,textarea{border-radius:5px}
h1,a{color:var(--primary-color);}
.line{margin:15px 0;background-color:var(--line-background-color);font-family:monospace;font-size:1rem;word-wrap:break-word;line-height: 1.7rem;}
.help{font-size:.8rem}
textarea{margin:10px 0;width:98%;height:3.5rem}
button{margin-top:15px;font-size:16px;font-weight:600;border:none;border-radius:5px;color:#fff;background-color:var(--primary-color);cursor:pointer;transition:background-color .3s}
button:hover{background-color:#2980b9}
label{display: inline-block;}
#qrcode-container {display: none;place-content: space-around center;align-items: center;position: fixed;z-index: 1;width: 100%;height: 100%;background-color:#000000cc;}
.qrcode{padding: 5px;border-radius: 5px;border: 1px solid var(--border-color);overflow: auto;} h1,h2,h3{margin: 0;}
input,select,textarea{padding:2px 5px;border:1px solid var(--border-color);border-radius:5px;font-size:14px;color:var(--text-color);background-color:var(--background-color);box-sizing:border-box;transition:border-color .5s}
input[disabled]{background-color: var(--line-background-color);color: var(--background-color);border: 1px dashed var(--background-color);}
.floating-button {position: fixed;bottom: 20px;left: 20px;background-color: var(--color);color: #888;border: none;border-radius: 50%;width: 60px;height: 60px;font-size: 24px;cursor: pointer;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);transition: background-color 0.3s, transform 0.3s;}
.floating-button:hover{transform:scale(1.1);}
details { border-bottom: 1px solid var(--border-color);margin-bottom:10px;padding-bottom:10px;}
summary {font-weight: bold;cursor: pointer;text-align: center;text-wrap: nowrap;}
summary::marker { font-size: 1.5rem; color: var(--primary-color); }
summary h2 { display: inline-flex; }
.red, red {color:red;text-shadow: #000 0 0 0px;}
.green, green {color:#16c60c;text-shadow: #000 0 0 0px;}
</style>
</head>
<body>
<div class="container">
<h1>🗽 Free Internet ${globalThis.ThisVersion} 🐉</h1>
<div class="line help">
<b>Your IP</b>
@
<b>Cloudflare:</b> <span id="clipdata">---</b></span>
||
<b>Others:</b> <span id="otipdata">---</span>
<button type="button" id="ipbtn" onclick="GetIPs();" style="margin: 0;padding: 3px 10px;">Get</button>
</div>
<details open>
<summary><h2>Config</h2></summary>
<div class="line">
<label for="address">Address: <input type="text" id="address" name="address" title="Config Address" placeholder="SubDomin.pages.dev" value="" onchange="chkaddress()" list="addresslist"/></label>
${addresslist}
|
<label for="custom">Custom<input type="checkbox" id="custom" name="custom" onchange="cstm()"></label>
<label for="host">Host: <input type="text" id="host" name="host" title="Config Host" placeholder="" value="" disabled /></label>
<label for="sni">SNI: <input type="text" id="sni" name="sni" title="Config SNI" placeholder="" value="" disabled /></label>
</div>
<div class="line">
<label for="pxip">${atob('UHJveHlJUA')}: <input type="text" id="pxip" name="pxip" title="" placeholder="" value="" list="pxiplist"/></label>
<datalist id="pxiplist">
<option value="${pxipdomain}">
<option value="${atob('YnBiLnlvdXNlZi5pc2VnYXJvLmNvbQ==')}">
<option value="${atob('cHJveHlpcC5hbWNsdWJzLmtvem93LmNvbQ==')}">
<option value="${atob('cHJveHlpcC5meHhrLmRlZHluLmlv')}">
</datalist>
Choose IP from <a target="_blank" href="https://www.nslookup.io/domains/${pxipdomain}/dns-records/">${pxipdomain}</a>
</div>
<div class="help">
<b>${atob('UHJveHlJUA')} Notice</b>
<br />
* you can use multiple IP separate with comma (,) like [ <i>141.148.187.195</i><b>,</b><i>129.146.46.164</i> ]. system will choose one randomly for every request.
<br />
* you can use domain directly like [ <i>${pxipdomain}</i> ].
<br />
* this IP will use just on servers and sites using Cloudflare. for other site like (youtube) system use random ip and cant change.
</div>
<div class="line">
<label for="port">Port:
<select id="port" title="" name="port" onchange="">
<option value="443" selected="selected">443</option>
<option value="8443">8443</option>
<option value="2053">2053</option>
<option value="2083">2083</option>
<option value="2087">2087</option>
<option value="2096">2096</option>
</select>
</label>
<label for="fingerprint">FingerPrint:
<select id="fingerprint" title="" name="fingerprint" onchange="">
<option value="chrome" selected="selected">Chrome</option>
<option value="firefox">FireFox</option>
<option value="safari">Safari</option>
<option value="ios">iOS</option>
<option value="android">Android</option>
<option value="edge">Edge</option>
<option value="Randomized">randomized</option>
<option value="0"> </option>
</select>
</label>
</div>
<div class="line">
<button type="button" id="generate" onclick="generate()">Generate</button>
<button type="button" id="copy" onclick="copyToClipboard('config')">Copy Config</button>
<button type="button" id="qrconfig" onclick="openQR('config')">QR Code</button>
<br />
<textarea id="config"></textarea>
</div>
<div class="line">
<h3>Default Subscription:
<button type="button" id="copysub" onclick="copyToClipboard('subscription')">Copy</button>
<button type="button" id="qrsub" onclick="openQR('subscription')">QR Code</button>
</h3>
<div class="help">Subscription ${atob('UHJveHlJUA')}: <span style="font-weight:bold;" id="subscriptionpxip">${pxipdomain}</span></div>
<span id="subscriptionshow">https://${globalThis.hostName}/${globalThis.AccessSubscription}#${globalThis.CnfgName}</span>
<input type="hidden" id="subscription" value="https://${globalThis.hostName}/${globalThis.AccessSubscription}#${globalThis.CnfgName}">
</div>
</details>
<details>
<summary><h2>Tunneling Through</h2></summary>
<div class="line">
<label for="tnlconfig" style="width:100%">Config: <input type="text" id="tnlconfig" name="tnlconfig" title="Remote Config" placeholder="${atob('dmxlc3M=')}://..." value="" style="width:90%"/></label>
</div>
<div class="help">
▶️ <b>For static IP:</b> you can use X-UI, Hiddify config or get <a href="https://www.google.com/search?q=free+${atob('dmxlc3M=')}+${atob('dm1lc3M=')}" target="_blank">free config</a>.
<br><br>
<h3>Limitation:</h3>
<ul>
<li>
✅ <b>Supported Protocols:</b> <green>${atob('VkxFU1M=')}</green>, <green>${atob('Vk1FU1M=')}</green>, and <green>${atob('VHJvamFu')}</green>.
</li><li>
✅ <b>Supported Transmission:</b> <green>WebSocket</green> only.
</li><li>
🚫 <b>IP Addresses <red>NOT</red> Supported:</b>
<ul><li>
Cloudflare does not support using an IP address as the server address.
</li><li>
To use an IP, consider <b>IP.sslip.io</b> as a domain alternative.
</li></ul>
</li><li>
🔒 <b>If using TLS:</b>
<ul><li>
Ensure your domain is correctly pointed to your server and has an active SSL certificate.
</li></ul>
</li>
</ul>
</div>
<div class="line">
<button type="button" id="tnlcnfgenerate" onclick="tnlcnfgenerate()">ReConfig</button>
<button type="button" id="tnlcnfcopy" onclick="copyToClipboard('tnlreconfig')">Copy</button>
<button type="button" id="tnlcnfqrconfig" onclick="openQR('tnlreconfig')">QR Code</button>
<br />
<textarea id="tnlreconfig"></textarea>
<div class="help" id="tnlhelp"></div>
</div>
</details>
<div class="help">
<center><a href="https://github.com/liMilCo/Free-Internet"><img src="https://github.githubassets.com/favicons/favicon.png" style="vertical-align: middle;" /> Free Internet 🐉</a></center>
</div>
</div>
<div id="qrcode-container" onclick="closeQR()"></div>
<button id="darkModeToggle" class="floating-button">🌎</button>
<script>
let defalt_address = "${globalThis.hostName}";
let defalt_pxip = "${globalThis.CLxIP}";
let defalt_uuid = "${globalThis.UzKey}";
let defalt_AcsSub = "${globalThis.AccessSubscription}";
let defalt_CnfgName = "${globalThis.CnfgName}";
const fpathss = "${globalThis.fpaths}";
const fpath = fpathss.split(',');
const subpath = 'https://'+defalt_address+'/'+defalt_AcsSub+'#'+defalt_CnfgName;
localStorage.getItem('darkMode') === 'enabled' && document.body.classList.add('dark-mode');
var address = document.getElementById("address");
var custom = document.getElementById("custom");
var host = document.getElementById("host");
var sni = document.getElementById("sni");
var pxip = document.getElementById("pxip");
var port = document.getElementById("port");
var fingerprint = document.getElementById("fingerprint");
var config = document.getElementById("config");
const darkModeToggle = document.getElementById('darkModeToggle');
function load_defalt(){
address.value = defalt_address;
host.value = defalt_address;
sni.value = defalt_address;
pxip.value = defalt_pxip;
GetIPs();
darkModeToggle.addEventListener('click', () => {
const isDarkMode = document.body.classList.toggle('dark-mode');
localStorage.setItem('darkMode', isDarkMode ? 'enabled' : 'disabled');
darkModeToggle.innerHTML = (isDarkMode ? '🌞' : '🌙');
});
GetLocalStorage();
DetailsBoxShow();
}
function cstm(){
if(custom.checked){
host.disabled = "";
sni.disabled = "";
}else{
host.disabled = "disabled";
sni.disabled = "disabled";
}
}
function copyToClipboard(elementId) {
const textToCopy = document.getElementById(elementId).value; //textContent
navigator.clipboard.writeText(textToCopy)
.then(() => alert('Config copied to clipboard!'))
.catch(err => console.error('Failed to copy text:', err));
}
function chkaddress(){
if (address.value !== defalt_address){
custom.checked = true;
}else{
custom.checked = false;
}
cstm();
}
function generate(){
var caddress = address.value;
var cport = port.value;
var cfingerprint = '';
var chost = '';
var csni = '';
var cpath = '%3Fed%3D2048';
if(custom.checked){
chost = "&host="+host.value;
csni = "&sni="+sni.value;
}
if(fingerprint.value != 0){
cfingerprint = "&fp="+fingerprint.value;
}
if (pxip.value && pxip.value !== defalt_pxip){
var pxipath = (btoa(pxip.value.replace(/ /g, ''))).replace(/=/g, '%3D');
cpath = fpath[Math.floor(Math.random() * fpath.length)]+"%2F"+pxipath+"%2F%3Fed%3D2048";
SetSub('https://'+defalt_address+'/'+defalt_AcsSub+'?path='+pxipath+'#'+defalt_CnfgName);
document.getElementById("subscriptionpxip").innerHTML = pxip.value;
}else{
SetSub(subpath);
document.getElementById("subscriptionpxip").innerHTML = defalt_pxip + " (defalt)";
}
config.value = atob("dmxlc3M=")+"://"+defalt_uuid+"@"+caddress+":"+cport+"?encryption=none&security=tls"+chost+""+cfingerprint+"&alpn=h2%2Chttp%2F1.1&type=ws"+csni+"&path=%2F"+cpath+"#%F0%9F%90%B2%20"+defalt_CnfgName;
}
const SetSub = (suburl) => {
if(!suburl){suburl = subpath;}
document.getElementById("subscriptionshow").innerHTML = suburl;
document.getElementById("subscription").value = suburl;
}
const closeQR = () => {
let qrcodeContainer = document.getElementById("qrcode-container");
qrcodeContainer.style.display = "none";
qrcodeContainer.innerHTML = "";
}
const openQR = (id) => {
let url = document.getElementById(id).value;
if(!url){return;}
let qrcodeContainer = document.getElementById("qrcode-container");
qrcodeContainer.innerHTML = "";
qrcodeContainer.style.display = "flex";
let qrcodeDiv = document.createElement("div");
qrcodeDiv.className = "qrcode";
qrcodeDiv.style.backgroundColor = "#ffffff";
new QRCode(qrcodeDiv, {
text: url,
width: 256,
height: 256,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
});
qrcodeContainer.appendChild(qrcodeDiv);
}
const GetIPs = async () => {
document.getElementById('otipdata').innerHTML = document.getElementById('clipdata').innerHTML = '---';
const ipResponse = await fetch('https://ipwho.is/' + '?nocache=' + Date.now(), { cache: "no-store" });
const ipResponseObj = await ipResponse.json();
var ipdataun = ipResponseObj.ip + ' <b>'+ipResponseObj.country+' ('+ipResponseObj.country_code+') </b>';
document.getElementById('otipdata').innerHTML = ipdataun;
const cfIPresponse = await fetch('https://ipv4.icanhazip.com/?nocache=' + Date.now(), { cache: "no-store" });
const cfIP = await cfIPresponse.text();
const cfResponse = await fetch('https://ipwho.is/' + cfIP + '?nocache=' + Date.now(), { cache: "no-store" });
const cfResponseObj = await cfResponse.json();
var ipdatacf = cfIP + ' <b>'+cfResponseObj.country+' ('+cfResponseObj.country_code+') </b>';
document.getElementById('clipdata').innerHTML = ipdatacf; //parse
}
///////////////////////////////////////////////////////////
// Tnl-Config ////////////////////////////////////////////
var defalt_tnlsec = "${TnlSecKey}";
var tnlconfig = document.getElementById("tnlconfig");
var tnlreconfig = document.getElementById("tnlreconfig");
var tnlhelp = document.getElementById("tnlhelp");
var tnlPreName = "🗽 Tnl🞂 ";
async function tnlcnfgenerate(){
let VlConfig = {};
let TnlError = {};
var ConfigMode;
if(!tnlconfig.value){return;}
if(tnlconfig.value.startsWith("${atob('dmxlc3M=')}") || tnlconfig.value.startsWith("${atob('dHJvamFu')}") ){
VlConfig = GetVlConfig(tnlconfig.value);
ConfigMode = "vl";
}else if(tnlconfig.value.startsWith("${atob('dm1lc3M=')}")){
VlConfig = GetVmConfig(tnlconfig.value);
ConfigMode = "vm";
}else{
alert("⚠️ Supported Protocols: ${atob('VkxFU1M=')}, ${atob('Vk1FU1M=')}, and ${atob('VHJvamFu')}.");
}
VlConfig.base.sni = VlConfig.base.sni ? VlConfig.base.sni.toLowerCase() : "";
VlConfig.base.host = VlConfig.base.host ? VlConfig.base.sni.toLowerCase() : "";
if (/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(VlConfig.base.address)){
VlConfig.base.address = VlConfig.base.address+atob("LnNzbGlwLmlv");
TnlError.address_is_ip = true;
}else{
if(VlConfig.base.sni && (VlConfig.base.address !== VlConfig.base.sni)){TnlError.address_not_sni = true;}
}
var new_path_http = "http";
if(VlConfig.base.security){if(VlConfig.base.security == "tls"){new_path_http = "https";TnlError.security_is_tls = true;}}
var new_path_path = VlConfig.base.path ? VlConfig.base.path : "/";
VlConfig.base.path = "/"+defalt_tnlsec+btoa(new_path_http+"://"+VlConfig.base.address+":"+VlConfig.base.port+new_path_path);//
if(TnlError.security_is_tls && (TnlError.address_is_ip || TnlError.address_not_sni)){
var new_path_sni = "/"+defalt_tnlsec+btoa(new_path_http+"://"+VlConfig.base.sni+":"+VlConfig.base.port+new_path_path);
}
if(VlConfig.base.type !== "ws"){TnlError.type_not_ws = true;}
var active_address = VlConfig.base.sni || VlConfig.base.host || VlConfig.base.address;
if(active_address == defalt_address || active_address.includes(defalt_address)){TnlError.config_is_self = true;}
if(new_path_path.includes(defalt_tnlsec)){TnlError.config_is_selftnl = true;}
if(active_address.includes("pages.dev") || active_address.includes("workers.dev") ){TnlError.config_is_worker = true;}
var TnlIsGood = SetTnlNotice(TnlError, VlConfig);
if(!TnlIsGood){return;}
var NewTnlConfig;
tnlreconfig.value = "";
if((TnlError.address_is_ip && !VlConfig.base.sni) || (!TnlError.address_is_ip)){
tnlreconfig.value += SetConfig(ConfigMode, VlConfig)+"\\n";
}
if(new_path_sni){
VlConfig.base.path = new_path_sni;
tnlreconfig.value += SetConfig(ConfigMode, VlConfig)+"\\n";
}
localStorage.setItem(tnlconfig.id, tnlconfig.value);
}
function SetConfig(ConfigMode, VlConfig){
if(ConfigMode == "vl"){
return SetVlConfig(VlConfig);
}else if(ConfigMode == "vm"){
return SetVmConfig(VlConfig);
}
}
function SetTnlNotice(TnlError, VlConfig){
var NewError = "";
if(TnlError.config_is_selftnl){
alert("⚠️ Do NOT use Tnl inside itself ! ☠️");
return false;
}
if(TnlError.config_is_self){
alert("⚠️ Do NOT use my config for Tnl ! 😱");
return false;
}
tnlhelp.innerHTML = "<h3>Notice:</h3>";
if(TnlError.type_not_ws){
tnlhelp.innerHTML += "⚠️ <b>Config Transmission is NOT <red>WebSocket</red></b>, Tnl-config is unlikely to work.<br/>";
}
if(VlConfig.base.security == "reality"){
tnlhelp.innerHTML += "⚠️ <b>Config Security is <red>reality</red></b>, Tnl-config is unlikely to work.<br/>";
}
if(TnlError.address_is_ip){
if(TnlError.security_is_tls && VlConfig.base.sni){
tnlhelp.innerHTML += "⚠️ <b>Config has an IP as address</b>, so we use SNI (<a href='http://"+VlConfig.base.sni+"' target='_blank'>"+VlConfig.base.sni+"</a>) as config address.<br/>";
}else{
tnlhelp.innerHTML += "⚠️ <b>Config has an IP as address</b>, so we use <a href='http://"+VlConfig.base.address+"' target='_blank'>"+VlConfig.base.address+"</a> as a domain alternative.<br/>";
if(TnlError.security_is_tls){
tnlhelp.innerHTML += "⚠️ <b>Config use TLS</b>, get an active SSL certificate for "+VlConfig.base.address+".<br/>";
}
}
}else{
if(TnlError.security_is_tls && TnlError.address_not_sni){
tnlhelp.innerHTML += "⚠️ <b>The sni config is different from the address</b>, two Tnl-config generated: one use address ("+VlConfig.base.address+") second use SNI ("+VlConfig.base.sni+").<br/>";
}
}
if(TnlError.config_is_worker){
tnlhelp.innerHTML += "⚠️ <b>It is not recommended to use <red>CL-Worker</red> configurations</b>.<br/>";
}
tnlhelp.innerHTML += "<green>🗽 Tnl-Config generated successfully.</green>";
return true;
}
function SetVmConfig(SetConfig){
var NewConfig;
SetConfig.data.path = SetConfig.base.path;
SetConfig.data.sni = SetConfig.data.host = SetConfig.data.add = defalt_address;
SetConfig.data.port = "443";
SetConfig.data.ps = unescape(encodeURIComponent(tnlPreName))+SetConfig.base.name;
if(SetConfig.data.security !== "tls"){