-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerator.py
271 lines (209 loc) · 9.18 KB
/
Generator.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
import json
import base64
def GetConfig(stream:dict, uuid: str, email: str, port: str, protocol: str, serverName: str):
# Your Remark
inboundSetting = json.loads(stream['streamSettings'])
remark = email
path = None
host = "none"
domainName = None
serviceName = None
headerType = None
alpn = None
kcpType = None
grpcSecurity = None
# Get Security
fingerPrint = ""
tls = inboundSetting["security"]
if tls == "reality":
fingerPrint = inboundSetting['realitySettings']['settings']['fingerprint']
global publicKey
publicKey = inboundSetting['realitySettings']['settings']['publicKey']
global shortIds
shortIds = inboundSetting['realitySettings']['shortIds'][0]
global spiderX
spiderX = inboundSetting['realitySettings']['settings']['spiderX']
global sni
sni = inboundSetting['realitySettings']['serverNames'][0]
if tls == "tls":
domainName = inboundSetting["tlsSettings"]["serverName"]
elif tls == "xtls":
domainName = inboundSetting["xtlsSettings"]["serverName"]
alpn = inboundSetting["tlsSettings"][0]["certificates"]["alpn"][0]
global allowInsecure
allowInsecure = inboundSetting["tlsSettings"][0]["certificates"]["allowInsecure"]
# Get Net Type Setting
netType = inboundSetting["network"]
if netType == "grpc":
serviceName = inboundSetting["grpcSettings"]["serviceName"]
grpcSecurity = inboundSetting["security"]
elif netType == "tcp":
headerType = inboundSetting["tcpSettings"]["header"]["type"]
if headerType != 'none':
path = inboundSetting["tcpSettings"]["header"]["request"]["path"][0]
try:
try:
host = inboundSetting["tcpSettings"]["header"]["request"]["headers"]["host"][0]
except:
host = inboundSetting["tcpSettings"]["header"]["request"]["headers"]["Host"][0]
except:
host = ""
elif netType == "ws":
path = inboundSetting["wsSettings"]["path"]
try:
host = inboundSetting["wsSettings"]["headers"]["host"]
except:
host=""
elif netType == "kcp":
kcpType = inboundSetting["kcpSettings"]["header"]["type"]
kcpSeed = inboundSetting["kcpSettings"]["seed"]
# Get Protocol . Final Step
if protocol == "shadowsocks":
setting = json.loads(stream['settings'])
confFirst = f"{setting['method']}:{setting['password']}:{uuid}"
Clients = ""
decoded_bytes = base64.urlsafe_b64encode(confFirst )
if tls == "tls":
conf += f"&security={tls}&fp={fingerPrint}&alpn={alpn}{'&allowInsecure=1' if allowInsecure ==True else'' }&sni={sni}"
if netType == "tcp" :
return (
f"{protocol}://{decoded_bytes}@{serverName}:{port}?type={netType}"
+ (
f"&headerType={headerType}&path={path if path != '' else '/'}&host={host}"
if headerType != "none"
else ""
)
+ f"{conf}#{remark}"
)
elif netType == "ws" or netType == "httpupgrade" or netType == "splithttp" :
return f"{protocol}://{uuid}@{serverName}:{port}?type={netType}&path={path if path!='' else '/'}&host={host}{conf}#{remark}"
elif netType == "kcp":
return f"{protocol}://{decoded_bytes}@{serverName}:{port}?type={netType}&security={tls}&headerType={kcpType}&seed={kcpSeed}#{remark}"
if netType == "grpc":
authority = inboundSetting['grpcSettings']['authority']
conf = f"&serviceName={serviceName}&authority={authority}" + conf
return (
f"{protocol}://{uuid}@{serverName}:{port}?type={netType}"
+ (
f"&headerType={headerType}&path={path if path != '' else '/'}&host={host}"
if headerType != "none"
else ""
)
+ f"{conf}#{remark}"
)
if protocol == "trojan":
conf = ""
if tls == "reality":
conf += f"&security={tls}&pbk={publicKey}&fp={fingerPrint}&sni={sni}&sid={shortIds}&spx={spiderX}"
if tls == "tls":
conf += f"&security={tls}&fp={fingerPrint}&alpn={alpn}{'&allowInsecure=1' if allowInsecure ==True else'' }&sni={sni}"
if netType == "tcp" :
return (
f"{protocol}://{uuid}@{serverName}:{port}?type={netType}"
+ (
f"&headerType={headerType}&path={path if path != '' else '/'}&host={host}"
if headerType != "none"
else ""
)
+ f"{conf}#{remark}"
)
elif netType == "ws" or netType == "httpupgrade" or netType == "splithttp" : return f"{protocol}://{uuid}@{serverName}:{port}?type={netType}&path={path if path!='' else '/'}&host={host}{conf}#{remark}"
elif netType == "kcp": return f"{protocol}://{uuid}@{serverName}:{port}?type={netType}&security={tls}&headerType={kcpType}&seed={kcpSeed}#{remark}"
if netType == "grpc":
authority = inboundSetting['grpcSettings']['authority']
conf = f"&serviceName={serviceName}&authority={authority}" + conf
return (
f"{protocol}://{uuid}@{serverName}:{port}?type={netType}"
+ (
f"&headerType={headerType}&path={path if path != '' else '/'}&host={host}"
if headerType != "none"
else ""
)
+ f"{conf}#{remark}"
)
elif protocol == "vless":
conf = ""
if netType == "tcp":
if tls == "xtls":
conf += f"&security={tls}&flow=xtls-rprx-direct"
if tls == "reality":
conf += f"&security={tls}&pbk={publicKey}&fp={fingerPrint}&sni={sni}&sid={shortIds}&spx={spiderX}"
if tls == "tls":
conf += f"&security={tls}&fp={fingerPrint}&alpn={alpn}{'&allowInsecure=1' if allowInsecure ==True else'' }&sni={sni}"
if host =="none" :
host=""
newConfig = (
f"{protocol}://{uuid}@{serverName}:{port}?type={netType}"
+ (
f"&headerType={headerType}&path={path if path != '' else '/'}&host={host}"
if headerType != "none"
else ""
)
+ f"{conf}#{remark}"
)
elif netType == "ws":
if tls == "tls":
conf += f"&security={tls}&fp={fingerPrint}&alpn={alpn}{'&allowInsecure=1' if allowInsecure == True else'' }&sni={sni}"
newConfig = f"{protocol}://{uuid}@{serverName}:{port}?type={netType}&path={path if path!='' else '/'}&host={host}{conf}#{remark} "
elif netType == "kcp":
newConfig = f"{protocol}://{uuid}@{serverName}:{port}?type={netType}&security={tls}&headerType={kcpType}&seed={kcpSeed}#{remark}"
elif netType == "grpc":
authority = inboundSetting['grpcSettings']['authority']
conf = f"&serviceName={serviceName}&authority={authority}" + conf
if tls == "xtls":
conf += "&flow=xtls-rprx-direct"
if tls == "reality":
conf += f"&security={tls}&pbk={publicKey}&fp={fingerPrint}&sni={sni}&sid={shortIds}&spx={spiderX}"
if tls == "tls":
conf += f"&security={tls}&fp={fingerPrint}&alpn={alpn}{'&allowInsecure=1' if allowInsecure ==True else'' }&sni={sni}"
newConfig = f"{protocol}://{uuid}@{serverName}:{port}?type={netType}&serviceName={serviceName}#{remark}"
elif protocol == "vmess":
vmessConf = {
"v": "2",
"ps": f"{remark}",
"add": serverName,
"port": int(port),
"id": uuid,
"aid": 0,
"net": netType,
"type": "none",
"tls": "none",
"path": "",
"host": ""
}
if headerType != None:
vmessConf["type"] = headerType
elif kcpType != None:
vmessConf["type"] = kcpType
else:
vmessConf["type"] = "none"
if host != None or host != "none":
vmessConf["host"] = host
if path == None or path == '':
vmessConf["path"] = "/"
else:
vmessConf["path"] = path
if tls == "" or tls =="none":
vmessConf["tls"] = "none"
else:
vmessConf["tls"] = tls
if headerType == "http":
vmessConf["path"] = "/"
vmessConf["type"] = headerType
if netType == "kcp":
if kcpSeed != None or kcpSeed != "":
vmessConf["path"] = kcpSeed
if netType == "grpc":
vmessConf['type'] = grpcSecurity
vmessConf['scy'] = 'auto'
if netType == "httpupgrade" or netType == "splithttp":
vmessConf['scy'] = 'auto'
res = json.dumps(vmessConf)
res =res[1:]
res = "{\n" + res.replace("}","\n}")
res = res.replace("," ,",\n ")
sample_string_bytes = res.encode("ascii")
base64_bytes = base64.b64encode(sample_string_bytes)
base64_string = base64_bytes.decode("ascii")
newConfig = f"vmess://{base64_string}"
return newConfig