allow full config

This commit is contained in:
Hiddify
2024-04-08 09:52:31 +02:00
parent b265886306
commit dd0c3614c9
6 changed files with 27 additions and 15 deletions

View File

@@ -6,16 +6,17 @@ import (
)
type ConfigOptions struct {
LogLevel string `json:"log-level"`
EnableClashApi bool `json:"enable-clash-api"`
ClashApiPort uint16 `json:"clash-api-port"`
ClashApiSecret string `json:"web-secret"`
GeoIPPath string `json:"geoip-path"`
GeoSitePath string `json:"geosite-path"`
Rules []Rule `json:"rules"`
Warp WarpOptions `json:"warp"`
Mux MuxOptions `json:"mux"`
TLSTricks TLSTricks `json:"tls-tricks"`
EnableFullConfig bool `json:"enable-full-config"`
LogLevel string `json:"log-level"`
EnableClashApi bool `json:"enable-clash-api"`
ClashApiPort uint16 `json:"clash-api-port"`
ClashApiSecret string `json:"web-secret"`
GeoIPPath string `json:"geoip-path"`
GeoSitePath string `json:"geosite-path"`
Rules []Rule `json:"rules"`
Warp WarpOptions `json:"warp"`
Mux MuxOptions `json:"mux"`
TLSTricks TLSTricks `json:"tls-tricks"`
DNSOptions
InboundOptions
URLTestOptions

View File

@@ -29,9 +29,9 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
if err != nil {
return nil, err
}
return ParseConfigContent(string(content), debug)
return ParseConfigContent(string(content), debug, false)
}
func ParseConfigContent(contentstr string, debug bool) ([]byte, error) {
func ParseConfigContent(contentstr string, debug bool, enableFullConfig bool) ([]byte, error) {
content := []byte(contentstr)
var jsonObj map[string]interface{} = make(map[string]interface{})
@@ -43,7 +43,12 @@ func ParseConfigContent(contentstr string, debug bool) ([]byte, error) {
if tmpJsonObj["outbounds"] == nil {
jsonObj["outbounds"] = []interface{}{jsonObj}
} else {
jsonObj["outbounds"] = tmpJsonObj["outbounds"]
if enableFullConfig {
jsonObj = tmpJsonObj
} else {
jsonObj["outbounds"] = tmpJsonObj["outbounds"]
}
}
} else if jsonArray, ok := tmpJsonResult.([]map[string]interface{}); ok {
jsonObj["outbounds"] = jsonArray

2
go.mod
View File

@@ -49,6 +49,7 @@ require (
github.com/libdns/cloudflare v0.1.0 // indirect
github.com/libdns/libdns v0.2.1 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/macronut/godivert v0.0.0-20220121081532-78e5dd672daf // indirect
github.com/mholt/acmez v1.2.0 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/onsi/ginkgo/v2 v2.9.7 // indirect
@@ -89,6 +90,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
github.com/williamfhe/godivert v0.0.0-20181229124620-a48c5b872c73 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect

4
go.sum
View File

@@ -84,6 +84,8 @@ github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/macronut/godivert v0.0.0-20220121081532-78e5dd672daf h1:dBleIe0eYiqh4QxsuEwXheUKljUDD8xio4ndLImrHv4=
github.com/macronut/godivert v0.0.0-20220121081532-78e5dd672daf/go.mod h1:WBXFEDDmnnVWR14TQAvMxdaHrW7Ewbt7pNerMHiyNzY=
github.com/mholt/acmez v1.2.0 h1:1hhLxSgY5FvH5HCnGUuwbKY2VQVo8IU7rxXKSnZ7F30=
github.com/mholt/acmez v1.2.0/go.mod h1:VT9YwH1xgNX1kmYY89gY8xPJC84BFAisjo8Egigt4kE=
github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4=
@@ -191,6 +193,8 @@ github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923 h1:tHNk7XK9GkmKUR6Gh8gV
github.com/u-root/uio v0.0.0-20230220225925-ffce2a382923/go.mod h1:eLL9Nub3yfAho7qB0MzZizFhTU2QkLeoVsWdHtDW264=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/williamfhe/godivert v0.0.0-20181229124620-a48c5b872c73 h1:uTcyLPxotESVvsf6sWcw+6MyDAsuuI7Q2TJn+pWyt/c=
github.com/williamfhe/godivert v0.0.0-20181229124620-a48c5b872c73/go.mod h1:2A+pcb3S0puG6gpwq2d8+7HGgCWXyCBwnsv/n3abx4U=
github.com/xmdhs/clash2singbox v0.0.2 h1:/gxaFm8fmv+UcUZzK508Z0yR01wg1LHrrq872Qibk1I=
github.com/xmdhs/clash2singbox v0.0.2/go.mod h1:B5pbJCwIHhJg6YRPCT04EXw6XXNIIOllMfL3XyJ7ob8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=

View File

@@ -173,7 +173,7 @@ func Parse(in *pb.ParseRequest) (*pb.ParseResponse, error) {
}
config, err := config.ParseConfigContent(content, true)
config, err := config.ParseConfigContent(content, true, false)
if err != nil {
return &pb.ParseResponse{
ResponseCode: pb.ResponseCode_FAILED,

View File

@@ -143,7 +143,7 @@ func extractRefreshInterval(header http.Header, bodyStr string) (int, error) {
return 0, nil
}
func buildConfig(configContent string, options config.ConfigOptions) (string, error) {
parsedContent, err := config.ParseConfigContent(configContent, true)
parsedContent, err := config.ParseConfigContent(configContent, true, options.EnableFullConfig)
if err != nil {
return "", fmt.Errorf("failed to parse config content: %w", err)
}