fix: bugs
This commit is contained in:
@@ -73,12 +73,14 @@ func BuildConfig(configOpt ConfigOptions, input option.Options) (*option.Options
|
||||
DNSClientOptions: option.DNSClientOptions{
|
||||
IndependentCache: configOpt.IndependentDNSCache,
|
||||
},
|
||||
Final: "dns-remote",
|
||||
Servers: []option.DNSServerOptions{
|
||||
{
|
||||
Tag: "dns-remote",
|
||||
Address: configOpt.RemoteDnsAddress,
|
||||
AddressResolver: "dns-direct",
|
||||
Strategy: configOpt.RemoteDnsDomainStrategy,
|
||||
Detour: "proxy",
|
||||
},
|
||||
{
|
||||
Tag: "dns-direct",
|
||||
|
||||
@@ -94,12 +94,15 @@ func isOutboundReality(base option.Outbound) bool {
|
||||
}
|
||||
|
||||
func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbound, string, error) {
|
||||
var serverDomain string
|
||||
var outbound option.Outbound
|
||||
|
||||
formatErr := func(err error) error {
|
||||
return fmt.Errorf("error patching outbound[%s][%s]: %w", base.Tag, base.Type, err)
|
||||
}
|
||||
err := patchWarp(&base)
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
var outbound option.Outbound
|
||||
|
||||
jsonData, err := base.MarshalJSON()
|
||||
if err != nil {
|
||||
@@ -111,7 +114,7 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
|
||||
var serverDomain string
|
||||
if server, ok := obj["server"].(string); ok {
|
||||
if server != "" && net.ParseIP(server) == nil {
|
||||
serverDomain = fmt.Sprintf("full:%s", server)
|
||||
@@ -134,15 +137,11 @@ func patchOutbound(base option.Outbound, configOpt ConfigOptions) (*option.Outbo
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
err = patchWarp(outbound)
|
||||
if err != nil {
|
||||
return nil, "", formatErr(err)
|
||||
}
|
||||
|
||||
return &outbound, serverDomain, nil
|
||||
}
|
||||
|
||||
func patchWarp(base option.Outbound) error {
|
||||
func patchWarp(base *option.Outbound) error {
|
||||
if base.Type == C.TypeCustom {
|
||||
if warp, ok := base.CustomOptions["warp"].(map[string]interface{}); ok {
|
||||
key, _ := warp["key"].(string)
|
||||
@@ -151,6 +150,7 @@ func patchWarp(base option.Outbound) error {
|
||||
fakePackets, _ := warp["fake_packets"].(string)
|
||||
warpConfig, err := generateWarp(key, host, uint16(port))
|
||||
if err != nil {
|
||||
fmt.Printf("Error generating warp config: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"os"
|
||||
|
||||
"github.com/hiddify/ray2sing/ray2sing"
|
||||
@@ -23,21 +24,23 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var jsonObj map[string]interface{}
|
||||
|
||||
fmt.Printf("Convert using json\n")
|
||||
jsonDecoder := json.NewDecoder(SJ.NewCommentFilter(bytes.NewReader(content)))
|
||||
if err := jsonDecoder.Decode(&jsonObj); err == nil {
|
||||
if jsonObj["outbounds"] == nil {
|
||||
return nil, fmt.Errorf("[SingboxParser] no outbounds found")
|
||||
}
|
||||
return validateResult(content, "SingboxParser")
|
||||
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
|
||||
return validateResult(newContent, "SingboxParser")
|
||||
}
|
||||
|
||||
fmt.Printf("Convert using v2ray\n")
|
||||
v2rayStr, err := ray2sing.Ray2Singbox(string(content))
|
||||
if err == nil {
|
||||
return validateResult([]byte(v2rayStr), "V2rayParser")
|
||||
}
|
||||
|
||||
fmt.Printf("Convert using clash\n")
|
||||
clashObj := clash.Clash{}
|
||||
if err := yaml.Unmarshal(content, &clashObj); err == nil && clashObj.Proxies != nil {
|
||||
if len(clashObj.Proxies) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user