11package share
22
33import (
4- "encoding/json"
54 "fmt"
65
76 "gopkg.in/yaml.v3"
87
98 "github.com/xtls/xray-core/infra/conf"
10- "github.com/xtls/xray-core/proxy/vless"
119)
1210
1311// https://github.com/MetaCubeX/mihomo/blob/Alpha/docs/config.yaml
@@ -17,14 +15,15 @@ type ClashYaml struct {
1715}
1816
1917type ClashProxy struct {
20- Name string `yaml:"name,omitempty"`
21- Type string `yaml:"type,omitempty"`
22- Server string `yaml:"server,omitempty"`
23- Port uint16 `yaml:"port,omitempty"`
24- Uuid string `yaml:"uuid,omitempty"`
25- Cipher string `yaml:"cipher,omitempty"`
26- Username string `yaml:"username,omitempty"`
27- Password string `yaml:"password,omitempty"`
18+ Name string `yaml:"name,omitempty"`
19+ Type string `yaml:"type,omitempty"`
20+ Server string `yaml:"server,omitempty"`
21+ Port uint16 `yaml:"port,omitempty"`
22+ Uuid string `yaml:"uuid,omitempty"`
23+ Cipher string `yaml:"cipher,omitempty"`
24+ Username string `yaml:"username,omitempty"`
25+ Password string `yaml:"password,omitempty"`
26+ Encryption string `yaml:"encryption,omitempty"`
2827
2928 Udp bool `yaml:"udp,omitempty"`
3029 UdpOverTcp bool `yaml:"udp-over-tcp,omitempty"`
@@ -155,15 +154,14 @@ func (proxy ClashProxy) shadowsocksOutbound() (*conf.OutboundDetourConfig, error
155154 outbound .Protocol = "shadowsocks"
156155 setOutboundName (outbound , proxy .Name )
157156
158- server := & conf.ShadowsocksServerTarget {}
159- server .Address = parseAddress (proxy .Server )
160- server .Port = proxy .Port
161- server .Cipher = proxy .Cipher
162- server .Password = proxy .Password
163- server .UoT = proxy .UdpOverTcp
157+ settings := conf.ShadowsocksClientConfig {}
164158
165- var settings conf.ShadowsocksClientConfig
166- settings .Servers = []* conf.ShadowsocksServerTarget {server }
159+ settings .Address = parseAddress (proxy .Server )
160+ settings .Port = proxy .Port
161+
162+ settings .Cipher = proxy .Cipher
163+ settings .Password = proxy .Password
164+ settings .UoT = proxy .UdpOverTcp
167165
168166 settingsRawMessage , err := convertJsonToRawMessage (settings )
169167 if err != nil {
@@ -218,22 +216,13 @@ func (proxy ClashProxy) vmessOutbound() (*conf.OutboundDetourConfig, error) {
218216 outbound .Protocol = "vmess"
219217 setOutboundName (outbound , proxy .Name )
220218
221- user := & conf.VMessAccount {}
222- user .ID = proxy .Uuid
223- user .Security = proxy .Cipher
224-
225- vnext := & conf.VMessOutboundTarget {}
226- vnext .Address = parseAddress (proxy .Server )
227- vnext .Port = proxy .Port
219+ settings := conf.VMessOutboundConfig {}
228220
229- userRawMessage , err := convertJsonToRawMessage (user )
230- if err != nil {
231- return nil , err
232- }
233- vnext .Users = []json.RawMessage {userRawMessage }
221+ settings .Address = parseAddress (proxy .Server )
222+ settings .Port = proxy .Port
234223
235- settings := conf. VMessOutboundConfig {}
236- settings .Receivers = [] * conf. VMessOutboundTarget { vnext }
224+ settings . ID = proxy . Uuid
225+ settings .Security = proxy . Cipher
237226
238227 settingsRawMessage , err := convertJsonToRawMessage (settings )
239228 if err != nil {
@@ -255,22 +244,16 @@ func (proxy ClashProxy) vlessOutbound() (*conf.OutboundDetourConfig, error) {
255244 outbound .Protocol = "vless"
256245 setOutboundName (outbound , proxy .Name )
257246
258- user := & vless.Account {}
259- user .Id = proxy .Uuid
260- user .Flow = proxy .Flow
247+ settings := conf.VLessOutboundConfig {}
261248
262- vnext := & conf.VLessOutboundVnext {}
263- vnext .Address = parseAddress (proxy .Server )
264- vnext .Port = proxy .Port
249+ settings .Address = parseAddress (proxy .Server )
250+ settings .Port = proxy .Port
265251
266- userRawMessage , err := convertJsonToRawMessage (user )
267- if err != nil {
268- return nil , err
252+ settings .Id = proxy .Uuid
253+ settings .Flow = proxy .Flow
254+ if len (proxy .Encryption ) > 0 {
255+ settings .Encryption = proxy .Encryption
269256 }
270- vnext .Users = []json.RawMessage {userRawMessage }
271-
272- settings := & conf.VLessOutboundConfig {}
273- settings .Vnext = []* conf.VLessOutboundVnext {vnext }
274257
275258 settingsRawMessage , err := convertJsonToRawMessage (settings )
276259 if err != nil {
@@ -292,22 +275,13 @@ func (proxy ClashProxy) socksOutbound() (*conf.OutboundDetourConfig, error) {
292275 outbound .Protocol = "socks"
293276 setOutboundName (outbound , proxy .Name )
294277
295- user := & conf.SocksAccount {}
296- user .Username = proxy .Username
297- user .Password = proxy .Password
278+ settings := conf.SocksClientConfig {}
298279
299- server := & conf.SocksRemoteConfig {}
300- server .Address = parseAddress (proxy .Server )
301- server .Port = proxy .Port
280+ settings .Address = parseAddress (proxy .Server )
281+ settings .Port = proxy .Port
302282
303- userRawMessage , err := convertJsonToRawMessage (user )
304- if err != nil {
305- return nil , err
306- }
307- server .Users = []json.RawMessage {userRawMessage }
308-
309- settings := & conf.SocksClientConfig {}
310- settings .Servers = []* conf.SocksRemoteConfig {server }
283+ settings .Username = proxy .Username
284+ settings .Password = proxy .Password
311285
312286 settingsRawMessage , err := convertJsonToRawMessage (settings )
313287 if err != nil {
@@ -329,13 +303,12 @@ func (proxy ClashProxy) trojanOutbound() (*conf.OutboundDetourConfig, error) {
329303 outbound .Protocol = "trojan"
330304 setOutboundName (outbound , proxy .Name )
331305
332- server := & conf.TrojanServerTarget {}
333- server . Address = parseAddress ( proxy . Server )
334- server . Port = proxy .Port
335- server . Password = proxy .Password
306+ settings := conf.TrojanClientConfig {}
307+
308+ settings . Address = parseAddress ( proxy .Server )
309+ settings . Port = proxy .Port
336310
337- settings := & conf.TrojanClientConfig {}
338- settings .Servers = []* conf.TrojanServerTarget {server }
311+ settings .Password = proxy .Password
339312
340313 settingsRawMessage , err := convertJsonToRawMessage (settings )
341314 if err != nil {
0 commit comments