This repository was archived by the owner on Nov 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathV2RayGen.py
executable file
·2733 lines (2304 loc) · 70 KB
/
V2RayGen.py
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
#!/usr/bin/env python3
# XRay Config Generator
# ------------------------------------------
# Author : SonyaCore
# Github : https://github.com/SonyaCore
# Licence : https://www.gnu.org/licenses/gpl-3.0.en.html
import os
import sys
import subprocess
import time
import uuid
import argparse
import base64
import json
import random
import string
import csv
import re
import platform
import ipaddress
from urllib.parse import unquote
from urllib.request import urlopen, Request
from urllib.error import HTTPError, URLError
from http.client import RemoteDisconnected
from binascii import Error
# -------------------------------- Constants --------------------------------- #
# Name
NAME = "XRayGen"
# Version
VERSION = "1.1.8"
# UUID Generation
UUID = uuid.uuid4()
# Config Name
CONFIGNAME = "config.json"
OBFS = "docker-compose.yml"
SELFSIGEND_CERT = "host.cert"
SELFSIGEND_KEY = "host.key"
# PORT
PORT = 80
# TLS
TLSTYPE = "none"
# Docker Compose FILE
DOCKERCOMPOSE = "docker-compose.yml"
# Client Side PORT
SOCKSPORT = 10808
HTTPPORT = 10809
## AGENT
AGENT_URL = "https://raw.githubusercontent.com/SonyaCore/V2RayGen/main/XRayAgent.py"
AGENT_PATH = "/tmp/agent.py"
# -------------------------------- Colors --------------------------------- #
# Color Format
green = "\u001b[32m"
yellow = "\u001b[33m"
blue = "\u001b[34m"
error = "\u001b[31m"
reset = "\u001b[0m"
# -------------------------------- Argument Parser --------------------------------- #
usage = "python3 {} {} <protocol> {} {} <optional args> {}".format(
NAME, error, reset, blue, reset
)
formatter = lambda prog: argparse.HelpFormatter(prog, max_help_position=64)
parser = argparse.ArgumentParser(prog=NAME, formatter_class=formatter, usage=usage)
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
raise argparse.ArgumentTypeError("Boolean value expected.")
parser.add_argument("--config", "-c", action="store_true", help="Creating only the Configuration file")
parser.add_argument("--agent", "-a", action="store_true", help="Launch XRayAgent")
parser.add_argument("--protocols", "-l", action="store_true", help="Show list of protocols")
quick = parser.add_argument_group("{}Protocols{}".format(green, reset))
quick.add_argument("--vmess", "-vm", action="store_true", help="Create VMess")
quick.add_argument("--vless", "-vl", action="store_true", help="Create VLess")
quick.add_argument("--trojan", "-tr", action="store_true", help="Create Trojan")
quick.add_argument("--shadowsocks", "-ss", action="store_true", help="Create ShadowSocks")
logdnsparser = parser.add_argument_group(
"{}XRay - Log & DNS Settings{}".format(green, reset)
)
logdnsparser.add_argument(
"--loglevel",
"-log",
action="store",
type=str,
metavar="",
help="Loglevel for Xray config. default: [warning]",
)
logdnsparser.add_argument(
"--dns", action="store", type=str, metavar="", help="Optional DNS. default: [nodns]"
)
routingparser = parser.add_argument_group("{}XRay - Routing{}".format(green, reset))
routingparser.add_argument(
"--block",
"--block-routing",
action="store_true",
help="Blocking Bittorrent and Ads in configuration. [default: False]",
)
routingparser.add_argument(
"--blockir",
"--block-ir",
action="store_true",
help="Blocking Bittorrent, Ads and Irnian IPs in configuration. [default: False]",
)
inboundsparser = parser.add_argument_group("{}XRay - Inbounds{}".format(green, reset))
inboundsparser.add_argument(
"--tls", "-t", action="store_true", help="Using TLS in specified protocol"
)
inboundsparser.add_argument(
"--xtls", "-xt", action="store_true", help="Using XTLS in specified protocol"
)
inboundsparser.add_argument(
"--port",
"-p",
action="store",
type=int,
metavar="",
help="Optional PORT for Xray Config. defualt: [80,443]",
)
inboundsparser.add_argument(
"--uuid",
"-u",
action="store",
type=str,
metavar="",
help="Optional UUID / ID for configuration. default: [random]",
default=UUID,
)
inboundsparser.add_argument(
"--alterid",
"-id",
action="store",
type=int,
metavar="",
help="Optional alterId for configuration. default: [0]",
default=0,
)
inboundsparser.add_argument(
"--insecure",
"--insecure-encryption",
action="store",
type=str2bool,
nargs="?",
metavar="",
const=True,
help="Disable Insecure Encryption. default: [True]",
default=True,
)
streamsettingsparser = parser.add_argument_group(
"{}XRay - Stream Settings{}".format(green, reset)
)
# streamsettingsparser.add_argument(
# "--http",
# "--http-stream",
# action="store_true",
# help="Using HTTP network stream. default: [WebSocket]",
# )
streamsettingsparser.add_argument(
"--tcp",
"--tcp-stream",
action="store_true",
help="Using TCP network stream. default: [WebSocket]",
)
streamsettingsparser.add_argument(
"--wspath",
"--websocket-path",
action="store",
type=str,
metavar="",
help="Optional WebSocket path. default: [/graphql]",
default="/graphql",
)
streamsettingsparser.add_argument(
"--header",
"--http-header",
action="store",
type=argparse.FileType("r"),
metavar="",
help="Optional JSON HTTPRequest Header.",
)
linkparser = parser.add_argument_group(
"{}XRay - Link Configuration{}".format(green, reset)
)
linkparser.add_argument(
"--linkname",
"-ln",
action="store",
type=str,
metavar="",
help="Name for Xray generated link. default: [xray]",
)
linkparser.add_argument(
"--qrcode",
"-qr",
action="store_true",
help="Generate QRCode for generated link.",
)
client = parser.add_argument_group("{}XRay Client Configuration{}".format(green, reset))
client.add_argument(
"--security",
"--client-security",
action="store",
type=str,
metavar="",
help="Security for Client-side JSON config. default: [auto]",
)
client.add_argument(
"--csocks",
"--clientsocks",
action="store",
type=int,
metavar="",
help="SOCKS port for Client-Side JSON config. default: [{}]".format(SOCKSPORT),
)
client.add_argument(
"--chttp",
"--clienthttp",
action="store",
type=int,
metavar="",
help="HTTP port for Client-Side JSON config. default: [{}]".format(HTTPPORT),
)
shadowsocks = parser.add_argument_group("{}ShadowSocks{}".format(green, reset))
shadowsocks.add_argument(
"--sspass",
"--shadowsocks-password",
action="store",
type=str,
metavar="",
help="Set Password for ShadowSocks. default: [random]",
)
shadowsocks.add_argument(
"--ssmethod",
"--shadowsocks-method",
action="store",
type=str,
metavar="",
help="Set Method for ShadowSocks. default: [2022-blake3-chacha20-poly1305]",
)
trojan = parser.add_argument_group("{}Trojan{}".format(green, reset))
trojan.add_argument(
"--tpass",
"--trojan-password",
action="store",
type=str,
metavar="",
help="Set Password for Trojan. default: [random]",
)
docker = parser.add_argument_group("{}Docker{}".format(green, reset))
docker.add_argument(
"--v2ray",
"-v2",
action="store_true",
required=False,
help="Use V2Ray insted of XRay",
)
docker.add_argument(
"--dockerfile",
action="store_true",
required=False,
help="Generate xray-core docker-compose file",
)
docker.add_argument(
"--ssdocker",
"--shadowsocks-dockerfile",
action="store_true",
required=False,
help="Generate ShadowSocks docker-compose file for shadowsocks-libev",
)
docker.add_argument(
"--dockerup",
action="store_true",
required=False,
help="Start docker-compose in system",
)
parseurl = parser.add_argument_group("{}Link Parse{}".format(green, reset))
parseurl.add_argument(
"--parse",
"--parseurl",
action="store",
type=str,
metavar="",
help="Parse encoded link. supported formats: [vmess://,ss://]",
)
parseurl.add_argument(
"--parseconfig",
"--readconfig",
action="store",
type=argparse.FileType("r"),
metavar="",
help="Parse Configuration file",
)
firewall = parser.add_argument_group("{}Firewall{}".format(green, reset))
firewall.add_argument(
"--firewall",
"-fw",
action="store_true",
help="Adding firewall rules after generating configuration",
)
inboundsparser = parser.add_argument_group("{}Google BBR{}".format(green, reset))
routingparser.add_argument(
"--bbr",
action="store_true",
help="Installing Google BBR on the server. [default: False]",
)
# xray.add_argument(
# "--domain",
# "--domain-websocket",
# action="store",
# type=str,
# metavar="",
# help="Use Domain insted of IP for WebSocket. default: [ServerIP]",
# )
opt = parser.add_argument_group("{}info{}".format(green, reset))
opt.add_argument("-v", "--version", action="version", version="%(prog)s " + VERSION)
# Arg Parse
args = parser.parse_args()
# ------------------------------ Miscellaneous ------------------------------- #
# Banner
def banner(t=0.0005):
data = """{}
__ __ _____ _____
\ \ / /| __ \ / ____|
\ V / | |__) |__ _ _ _| | __ ___ _ __
> < | _ // _` | | | | | |_ |/ _ \ '_ \
/ . \ | | \ \ (_| | |_| | |__| | __/ | | |
/_/ \_\|_| \_\__,_|\__, |\_____|\___|_| |_|
__/ |
|___/
{}""".format(
green, reset
)
for char in data:
sys.stdout.write(char)
time.sleep(t)
sys.stdout.write("\n")
sys.stdout.write("Version: " + VERSION)
sys.stdout.write("\n")
def python_version():
if sys.version_info < (3, 5):
raise Exception(
"Your Python version is too old. Please upgrade to version 3.5 or later."
)
else:
pass
def user_permission() -> None:
if os.getuid() == 0:
PRIVILEGE = green + "GRANTED" + reset
t = True
else:
PRIVILEGE = error + "DENIED" + reset
t = False
pass
print("ROOT PRIVILEGE : {}".format(PRIVILEGE))
if t == False:
print(
yellow
+ "WARNING : Some sections might not work without root permission"
+ reset
)
def docker_compose_version() -> str:
if sys.version_info < (3, 6):
return "v2.16.0"
else:
tag = "latest"
version = "name"
compose = Request(
"https://api.github.com/repos/docker/compose/releases/{}".format(tag),
headers={
"User-Agent": "Mozilla/5.0",
},
)
with urlopen(compose) as response:
return json.loads(response.read().decode())[version]
# Return IP
def ip():
"""
return actual IP of the server.
if there are multiple interfaces with private IP the public IP will be used for the config
"""
try:
url = "http://ip-api.com/json/?fields=query"
httprequest = Request(url, headers={"Accept": "application/json"})
with urlopen(httprequest) as response:
data = json.loads(response.read().decode())
return data["query"]
except HTTPError:
print(
error
+ "failed to send request to {} please check your connection".format(
url.split("/json")[0]
)
+ reset
)
sys.exit(1)
def get_random_charaters(length=24):
"""
Get random password pf length with letters, digits, and symbols
"""
characters = string.ascii_letters + string.digits
password = "".join(random.choice(characters) for i in range(length))
return password
def country():
"""
return Country Code of the server.
country code are used for detecting server location
if server are not in the filtered list nginx template will be generated
"""
try:
countrycode = get_country()
if countrycode not in ("IR", "CN", "VN"):
print(
yellow
+ "\n! You Are Using External Server [{}]\n".format(countrycode)
+ "Nginx Template:"
+ reset
)
print(nginx())
print(yellow + "! Append to /etc/nginx/nginx.conf" + reset)
except HTTPError:
print(
error
+ "failed to send request to {} please check your connection".format(
countrycode.split("/json")[0]
)
+ reset
)
sys.exit(1)
def get_country() -> str:
"""
return Country Code of the server.
"""
countrycode_url = "http://ip-api.com/json/?fields=countryCode"
httprequest = Request(countrycode_url, headers={"Accept": "application/json"})
with urlopen(httprequest) as response:
data = json.loads(response.read().decode())
return data["countryCode"]
def dnsselect():
"""
DNS Selection.
dnsselect are used for set a dns to the generated config
https://www.v2ray.com/en/configuration/dns.html#dnsobject
"""
global dnslist, NODNS, dnsserver
dnslist = ["both", "google", "cloudflare", "opendns", "quad9", "adguard", "nodns"]
dnsserver = {}
dnsserver[
0
] = """"dns": {
"servers": [
"8.8.8.8",
"1.1.1.1",
"4.2.2.4"
]
},"""
dnsserver[
1
] = """"dns": {
"servers": [
"8.8.8.8",
"4.2.2.4"
]
},"""
dnsserver[
2
] = """"dns": {
"servers": [
"1.1.1.1"
]
},"""
dnsserver[
3
] = """"dns": {
"servers": [
"208.67.222.222",
"208.67.220.220"
]
},"""
dnsserver[
4
] = """"dns": {
"servers": [
"9.9.9.9",
"149.112.112.112"
]
},"""
dnsserver[
5
] = """"dns": {
"servers": [
"94.140.14.14",
"94.140.15.15"
]
},"""
NODNS = ""
def get_distro() -> str:
"""
return distro name based on os-release info
"""
RELEASE_INFO = {}
with open("/etc/os-release") as f:
reader = csv.reader(f, delimiter="=")
for row in reader:
if row:
RELEASE_INFO[row[0]] = row[1]
return "{}".format(RELEASE_INFO["NAME"])
def create_key():
"""
create self signed key with openssl
"""
random_domain = get_random_charaters(8)
countrycode = get_country()
print(green)
subprocess.run(
"openssl req -new -newkey rsa:4096 -days 735 -nodes -x509 \
-subj '/C={}/ST=Denial/L=String/O=Dis/CN=www.{}.{}' -keyout {} -out {}".format(
countrycode, random_domain, countrycode, SELFSIGEND_KEY, SELFSIGEND_CERT
),
shell=True,
check=True,
)
print(reset)
def clearcmd() -> None:
version = platform.system()
if version in ("Linux", "Darwin"):
subprocess.run("clear")
elif version == "Windows":
subprocess.run("cls")
# def websocket_domaincheck(url = args.domain,t = 10) :
# """
# when using the domain for WebSocket the status code should be 400
# else exception will occur.
# """
# try:
# response = urlopen(f'{args.domain}{args.wspath}',timeout= t)
# except HTTPError as error:
# response_code = error.code
# print( blue + 'Domain status : '+ reset + str(response_code))
# if response_code == 400:
# return True
# else:
# raise URLError(error.reason)
def validate_email(email):
regex = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"
if re.fullmatch(regex, email):
pass
else:
sys.exit(
error
+ "ERROR : Invalid Email"
+ reset
+ " Please enter a valid email address"
)
def install_bbr() -> None:
subprocess.run(
"curl https://raw.githubusercontent.com/SonyaCore/across/master/bbr.sh | bash -",
shell=True,
check=True,
)
def openssl_rand(type, byte) -> str:
return (
subprocess.check_output("openssl rand -{} {}".format(type, byte), shell=True)
.decode("utf-8")
.strip("\n")
)
def launch_agent():
clearcmd()
subprocess_command = "curl -s {url} --output {path} && python3 {path}".format(
url=AGENT_URL, path=AGENT_PATH
)
subprocess.run(subprocess_command, check=True, shell=True)
os.remove(AGENT_PATH)
# -------------------------------- Global Variables --------------------------------- #
if args.v2ray:
PROTOCOL = "v2ray"
else:
PROTOCOL = "xray"
# Certificate location
crtkey = "/etc/{}/{}".format(PROTOCOL, SELFSIGEND_CERT)
hostkey = "/etc/{}/{}".format(PROTOCOL, SELFSIGEND_KEY)
# Outband protocols
outbound_list = ["freedom", "blackhole", "both"]
# link schematic
vmess_scheme = "vmess://"
shadowsocks_scheme = "ss://"
# TROJAN PASSWORD
trojanpassword = None
# Docker Compose Version
DOCKERCOMPOSEVERSION = docker_compose_version()
# Supported XRay Configuration Protocols
supported_typo = [
"vmessws",
"vmesswstls",
"vmesstcp",
"vmesstcptls",
"vlesswstls",
"vlesstcptls",
"vlesstcpxtls",
"shadowsockstcp",
"shadowsockstcptls",
"trojanwstls",
"trojantcptls",
"trojantcpxtls",
]
def protocol_map():
"""
Map user-entered arguments to supported protocols.
If unsupported protocols are entered, raise an exception with a list of available protocols,
prioritizing arguments with more parameters.
"""
# vmesstcptls
if all((args.vmess, args.tcp, args.tls)):
protocol_type = supported_typo[3]
# trojantcptls
elif all((args.trojan, args.tcp, args.tls)):
protocol_type = supported_typo[10]
# trojantcpxtls
elif all((args.trojan, args.tcp, args.xtls)):
protocol_type = supported_typo[11]
# vlesstcpxtls
elif all((args.vless, args.tcp, args.xtls)):
protocol_type = supported_typo[6]
# vmesstcp
elif all((args.vmess, args.tcp)):
protocol_type = supported_typo[2]
# trojantcptls
elif all((args.trojan, args.tcp)):
protocol_type = supported_typo[10]
# trojantcpxtls
elif all((args.trojan, args.xtls)):
protocol_type = supported_typo[11]
# vlesstcpxtls
elif all((args.vless, args.xtls)):
protocol_type = supported_typo[6]
# vlesstcptls
elif all((args.vless, args.tcp)):
protocol_type = supported_typo[5]
# shadowsockstcptls
elif all((args.shadowsocks, args.tls)):
protocol_type = supported_typo[8]
# vmesswstls
elif all((args.vmess, args.tls)):
protocol_type = supported_typo[1]
# shadowsockstcp
elif args.shadowsocks:
protocol_type = supported_typo[7]
# vmessws
elif args.vmess:
protocol_type = supported_typo[0]
# vlesswstls
elif args.vless:
protocol_type = supported_typo[4]
# trojanwstls
elif args.trojan:
protocol_type = supported_typo[9]
else:
raise Exception("Unsupported Protocol.\n{}".format(protocols_list()))
return protocol_type
def protocols_list() -> None:
print("LIST OF SUPPORTED PROTOCOLS")
print("Protocols like VLess or Trojan require TLS by default.")
params = {
"VMESS WS": "--vmess",
"VMESS WS TLS": "--vmess --tls",
"VMESS TCP": "--vmess --tcp",
"VMESS TCP TLS": "--vmess --tcp --tls",
"VLESS WS TLS": "--vless",
"VLESS TCP TLS": "--vless --tcp",
"VLESS TCP XTLS": "--vless --tcp --xtls",
"TROJAN WS TLS": "--trojan",
"TROJAN TCP TLS": "--trojan --tcp",
"TROJAN TCP XTLS": "--trojan --tcp",
"ShadowSocks TCP": "--shadowsocks",
"ShadowSocks TCP TLS": "--shadowsocks --tls",
}
for protocols, parameters in params.items():
print(green + protocols + reset, ":", yellow + parameters + reset)
# -------------------------------- VMess JSON --------------------------------- #
def xray_make():
"""
Make JSON config which reads --outband for making v2ray vmess config with specific protocol
https://www.v2ray.com/en/configuration/protocols/v2ray.html
"""
global proto_name
# Config Protocol Method
if proto_type == "vmessws":
proto_name = "VMESS + WS"
elif proto_type == "vmesswstls":
proto_name = "VMESS + WS + TLS"
elif proto_type == "vmesstcp":
proto_name = "VMESS + TCP"
elif proto_type == "vmesstcptls":
proto_name = "VMESS + TCP + TLS"
elif proto_type == "vlesswstls":
proto_name = "VLESS + WS + TLS"
elif proto_type == "vlesstcptls":
proto_name = "VLESS + TCP + TLS"
elif proto_type == "vlesstcpxtls":
proto_name = "VLESS + TCP + XTLS"
elif proto_type == "trojanwstls":
proto_name = "TROJAN + WS + TLS"
elif proto_type == "trojantcptls":
proto_name = "TROJAN + TCP + TLS"
elif proto_type == "trojantcpxtls":
proto_name = "TROJAN + TCP + XTLS"
elif proto_type == "shadowsockstcp":
proto_name = "SHADOWSOCKS + TCP"
elif proto_type == "shadowsockstcptls":
proto_name = "SHADOWSOCKS + TCP + TLS"
if proto_type.startswith("vmess"):
make_xray("vmess")
elif proto_type.startswith("vless"):
make_xray("vless")
elif proto_type.startswith("trojan"):
make_xray("trojan")
elif proto_type.startswith("shadowsocks"):
make_xray("shadowsocks")
print(
"{}! {}{}{}{} Config Generated.{}".format(
blue, green, proto_name, reset, blue, reset
)
)
if args.vless or args.trojan:
print(
"{}! By default TLS is being used for this Protocol{}".format(yellow, reset)
)
def xray_config(outband, protocol) -> str:
"""
Xray JSON config file template
"""
global NETSTREAM
if args.xtls:
print(
"{}! XTLS only supports (TCP,mKCP). Using TCP mode{}".format(yellow, reset)
)
if args.tls:
tls_config = tlssettings()
elif args.vless:
tls_config = tlssettings()
elif args.trojan:
tls_config = tlssettings()
else:
tls_config = notls()
if args.tcp or args.shadowsocks or args.xtls:
networkstream = tcp()
NETSTREAM = "TCP"
else:
networkstream = websocket_config(args.wspath)
NETSTREAM = "WebSocket"
if args.block or args.blockir:
routing_config = routing() + ","
sniffing_config = sniffing() + ","
else:
routing_config = ""
sniffing_config = ""
if args.tcp or args.shadowsocks or args.xtls:
# TCP stream settings
streamsettings = """
"streamSettings": {
%s,
%s,
"tcpSettings": %s
}
""" % (
networkstream,
tls_config,
args.header,
)
else:
# Normal stream settings
streamsettings = """
"streamSettings":{
%s,
%s,
"headersettings": %s
}
""" % (
networkstream,
tls_config,
args.header,
)
data = """{
%s
%s,
%s
"inbounds": [
{
%s
"port": %s,
%s,
%s
}
],
"outbounds": [
%s
]
}""" % (
DNS,
log(),
routing_config,
sniffing_config,
PORT,
protocol,
streamsettings,
outband,
)
return json.loads(data)
# -------------------------------- Xray Config --------------------------------- #
def make_xray(protocol):
"""
make xray config based on selected protocol
"""
outband_config = outband()
protocol_config = ""
if protocol == "vless":
protocol_config = vless_server_side()
elif protocol == "vmess":
protocol_config = vmess_server_side()
elif protocol == "trojan":
protocol_config = trojan_server_side()
elif protocol == "shadowsocks":
protocol_config = shadowsocks_server_side()
# Config Protocol Method
with open(CONFIGNAME, "w") as txt:
txt.write(
json.dumps(
xray_config(outband_config, protocol_config),
indent=2,
)
)
txt.close
def outband():
return freedom() + ",\n" + blackhole()
# -------------------------------- JSON Configuration --------------------------------- #
def vmess_server_side():
"""
vmess server side inbound configuration
https://xtls.github.io/config/inbounds/vmess.html
"""
vmess = """
"protocol": "vmess",
"allocate": {
"strategy": "always"