@@ -107,8 +107,36 @@ def to_mtproto(self, template_json):
107
107
routing_bind ["inboundTag" ][0 ] = self .group_tag
108
108
rules .append (routing_bind )
109
109
110
+ def to_kcp (self , header_type ):
111
+ self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
112
+ type_str = "none"
113
+ if "utp" in header_type :
114
+ type_str = "utp"
115
+ elif "srtp" in header_type :
116
+ type_str = "srtp"
117
+ elif "dtls" in header_type :
118
+ type_str = "dtls"
119
+ elif "wechat" in header_type :
120
+ type_str = "wechat-video"
121
+ elif "wireguard" in header_type :
122
+ type_str = "wireguard"
123
+ self .part_json ["streamSettings" ]["kcpSettings" ]["header" ]["type" ] = type_str
124
+
125
+ def to_vmess (self , header_type ):
126
+ self .to_kcp (header_type )
127
+ self .part_json ["protocol" ] = "vmess"
128
+ self .part_json ["settings" ] = {
129
+ "clients" : [
130
+ {
131
+ "alterId" : 0 ,
132
+ "id" : str (uuid .uuid1 ())
133
+ }
134
+ ]
135
+ }
136
+
110
137
def write (self , ** kw ):
111
138
security_backup , tls_settings_backup , origin_protocol , domain = "" , "" , None , ""
139
+ no_tls_group = (StreamType .MTPROTO , StreamType .SS )
112
140
113
141
if self .part_json ['protocol' ] == 'shadowsocks' :
114
142
origin_protocol = StreamType .SS
@@ -126,7 +154,7 @@ def write(self, **kw):
126
154
elif self .part_json ['protocol' ] == 'trojan' :
127
155
origin_protocol = StreamType .TROJAN
128
156
129
- if origin_protocol != StreamType . MTPROTO and origin_protocol != StreamType . SS :
157
+ if origin_protocol not in no_tls_group :
130
158
security_backup = self .part_json ["streamSettings" ]["security" ]
131
159
if origin_protocol == StreamType .VLESS_XTLS :
132
160
tls_settings_backup = self .part_json ["streamSettings" ]["xtlsSettings" ]
@@ -139,36 +167,8 @@ def write(self, **kw):
139
167
if origin_protocol == StreamType .MTPROTO and origin_protocol != self .stream_type :
140
168
clean_mtproto_tag (self .config , self .group_index )
141
169
142
- #原来是socks/mtproto/shadowsocks/vless/trojan/xtls协议 则先切换为标准的inbound
143
- if origin_protocol in (StreamType .MTPROTO , StreamType .SOCKS , StreamType .SS , StreamType .VLESS_TLS , StreamType .VLESS_TCP , StreamType .TROJAN , StreamType .VLESS_XTLS ):
144
- vmess = self .load_template ('server.json' )
145
- vmess ["inbounds" ][0 ]["port" ] = self .part_json ["port" ]
146
- if "allocate" in self .part_json :
147
- vmess ["inbounds" ][0 ]["allocate" ] = self .part_json ["allocate" ]
148
- self .part_json = vmess ["inbounds" ][0 ]
149
-
150
- if self .stream_type == StreamType .KCP :
151
- self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
152
-
153
- elif self .stream_type == StreamType .KCP_UTP :
154
- self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
155
- self .part_json ["streamSettings" ]["kcpSettings" ]["header" ]["type" ] = "utp"
156
-
157
- elif self .stream_type == StreamType .KCP_SRTP :
158
- self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
159
- self .part_json ["streamSettings" ]["kcpSettings" ]["header" ]["type" ] = "srtp"
160
-
161
- elif self .stream_type == StreamType .KCP_WECHAT :
162
- self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
163
- self .part_json ["streamSettings" ]["kcpSettings" ]["header" ]["type" ] = "wechat-video"
164
-
165
- elif self .stream_type == StreamType .KCP_DTLS :
166
- self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
167
- self .part_json ["streamSettings" ]["kcpSettings" ]["header" ]["type" ] = "dtls"
168
-
169
- elif self .stream_type == StreamType .KCP_WG :
170
- self .part_json ["streamSettings" ] = self .load_template ('kcp.json' )
171
- self .part_json ["streamSettings" ]["kcpSettings" ]["header" ]["type" ] = "wireguard"
170
+ if "KCP" in self .stream_type .name :
171
+ self .to_vmess (self .stream_type .value )
172
172
173
173
elif self .stream_type == StreamType .TCP :
174
174
self .part_json ["streamSettings" ] = self .load_template ('tcp.json' )
@@ -215,7 +215,7 @@ def write(self, **kw):
215
215
ws ["wsSettings" ]["headers" ]["Host" ] = kw ['host' ]
216
216
self .part_json ["streamSettings" ] = ws
217
217
218
- elif self . stream_type in ( StreamType . VLESS_TCP , StreamType . VLESS_TLS , StreamType . VLESS_XTLS , StreamType . VLESS_WS ) :
218
+ elif "vless" in self . stream_type . value :
219
219
vless = self .load_template ('vless.json' )
220
220
vless ["clients" ][0 ]["id" ] = str (uuid .uuid1 ())
221
221
if self .stream_type == StreamType .VLESS_XTLS :
@@ -230,12 +230,15 @@ def write(self, **kw):
230
230
if "host" in kw :
231
231
ws ["wsSettings" ]["headers" ]["Host" ] = kw ['host' ]
232
232
self .part_json ["streamSettings" ] = ws
233
+ elif self .stream_type in (StreamType .VLESS_KCP , StreamType .VLESS_UTP , StreamType .VLESS_SRTP , StreamType .VLESS_DTLS , StreamType .VLESS_WECHAT , StreamType .VLESS_WG ):
234
+ self .to_kcp (self .stream_type .value )
235
+ self .part_json ["streamSettings" ]["kcpSettings" ]["seed" ] = '' .join (random .sample (string .ascii_letters + string .digits , 8 ))
233
236
else :
234
237
self .part_json ["streamSettings" ] = self .load_template ('tcp.json' )
235
238
self .save ()
236
239
alpn = ["http/1.1" ]
237
240
# tls的设置
238
- if self .stream_type != StreamType .VLESS_TCP :
241
+ if self .stream_type in ( StreamType .VLESS_XTLS , StreamType . VLESS_WS , StreamType . VLESS_TLS ) :
239
242
if not "certificates" in tls_settings_backup :
240
243
from ..config_modify .tls import TLSModifier
241
244
if self .stream_type == StreamType .VLESS_XTLS :
@@ -291,18 +294,16 @@ def write(self, **kw):
291
294
self .part_json ["streamSettings" ]["security" ] = "xtls"
292
295
self .part_json ["streamSettings" ]["xtlsSettings" ] = tls_settings_backup
293
296
del self .part_json ["streamSettings" ]["tlsSettings" ]
294
- elif (self .stream_type != StreamType .MTPROTO and origin_protocol != StreamType .MTPROTO
295
- and self .stream_type != StreamType .SS and origin_protocol != StreamType .SS ):
297
+ elif self .stream_type not in no_tls_group and origin_protocol not in no_tls_group :
296
298
self .part_json ["streamSettings" ]["security" ] = "tls" if security_backup == "xtls" else security_backup
297
299
self .part_json ["streamSettings" ]["tlsSettings" ] = tls_settings_backup
298
300
299
- if domain :
301
+ if domain and self . stream_type not in no_tls_group :
300
302
self .part_json ["domain" ] = domain
301
303
302
- apln_list = (StreamType .VLESS_TLS , StreamType .VLESS_TCP , StreamType .TROJAN , StreamType .VLESS_XTLS )
303
- if origin_protocol in apln_list and self .stream_type not in apln_list :
304
- if "alpn" in self .part_json ["streamSettings" ]["tlsSettings" ]:
305
- del self .part_json ["streamSettings" ]["tlsSettings" ]["alpn" ]
304
+ apln_list = (StreamType .VLESS_TLS , StreamType .TROJAN , StreamType .VLESS_XTLS )
305
+ if "streamSettings" in self .part_json and "alpn" in self .part_json ["streamSettings" ]["tlsSettings" ] and self .stream_type not in apln_list :
306
+ del self .part_json ["streamSettings" ]["tlsSettings" ]["alpn" ]
306
307
307
308
self .config ["inbounds" ][self .group_index ] = self .part_json
308
309
self .save ()
0 commit comments