forked from mirror/serenity
Let setup dns can be editable
This commit is contained in:
parent
0a1889c438
commit
6066354b8c
@ -31,6 +31,7 @@ type _Template struct {
|
|||||||
CustomDNSServers []option.DNSServerOptions `json:"custom_dns_servers,omitempty"`
|
CustomDNSServers []option.DNSServerOptions `json:"custom_dns_servers,omitempty"`
|
||||||
DNS string `json:"dns,omitempty"`
|
DNS string `json:"dns,omitempty"`
|
||||||
DNSLocal string `json:"dns_local,omitempty"`
|
DNSLocal string `json:"dns_local,omitempty"`
|
||||||
|
DNSSetup string `json:"dns_setup,omitempty"`
|
||||||
EnableFakeIP bool `json:"enable_fakeip,omitempty"`
|
EnableFakeIP bool `json:"enable_fakeip,omitempty"`
|
||||||
DisableDNSLeak bool `json:"disable_dns_leak,omitempty"`
|
DisableDNSLeak bool `json:"disable_dns_leak,omitempty"`
|
||||||
PreDNSRules []option.DNSRule `json:"pre_dns_rules,omitempty"`
|
PreDNSRules []option.DNSRule `json:"pre_dns_rules,omitempty"`
|
||||||
@ -38,7 +39,7 @@ type _Template struct {
|
|||||||
CustomFakeIP *option.DNSFakeIPOptions `json:"custom_fakeip,omitempty"`
|
CustomFakeIP *option.DNSFakeIPOptions `json:"custom_fakeip,omitempty"`
|
||||||
CustomDNSTag string `json:"custom_dns_tag,omitempty"`
|
CustomDNSTag string `json:"custom_dns_tag,omitempty"`
|
||||||
CustomDNSLocalTag string `json:"custom_dns_local_tag,omitempty"`
|
CustomDNSLocalTag string `json:"custom_dns_local_tag,omitempty"`
|
||||||
CustomDNSLocalSetupTag string `json:"custom_dns_local_setup_tag,omitempty"`
|
CustomDNSSetupTag string `json:"custom_dns_setup_tag,omitempty"`
|
||||||
CustomDNSFakeIPTag string `json:"custom_dns_fakeip_tag,omitempty"`
|
CustomDNSFakeIPTag string `json:"custom_dns_fakeip_tag,omitempty"`
|
||||||
|
|
||||||
// Inbound
|
// Inbound
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
@ -22,6 +23,13 @@ func getOrDefault(v string, d string) string {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ifElse[T any](b bool, v1 T, v2 T) T {
|
||||||
|
if b {
|
||||||
|
return v1
|
||||||
|
}
|
||||||
|
return v2
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error {
|
func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error {
|
||||||
var (
|
var (
|
||||||
domainStrategy option.DomainStrategy
|
domainStrategy option.DomainStrategy
|
||||||
@ -45,11 +53,13 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
|
|||||||
|
|
||||||
dnsTag := getOrDefault(t.CustomDNSTag, DefaultDNSTag)
|
dnsTag := getOrDefault(t.CustomDNSTag, DefaultDNSTag)
|
||||||
dnsLocalTag := getOrDefault(t.CustomDNSLocalTag, DefaultDNSLocalTag)
|
dnsLocalTag := getOrDefault(t.CustomDNSLocalTag, DefaultDNSLocalTag)
|
||||||
dnsLocalSetupTag := getOrDefault(t.CustomDNSLocalSetupTag, DefaultDNSLocalSetupTag)
|
dnsSetupTag := getOrDefault(t.CustomDNSSetupTag, DefaultDNSSetupTag)
|
||||||
dnsFakeIPTag := getOrDefault(t.CustomDNSFakeIPTag, DefaultDNSFakeIPTag)
|
dnsFakeIPTag := getOrDefault(t.CustomDNSFakeIPTag, DefaultDNSFakeIPTag)
|
||||||
dns := getOrDefault(t.DNS, DefaultDNS)
|
dns := getOrDefault(t.DNS, DefaultDNS)
|
||||||
dnsLocal := getOrDefault(t.DNSLocal, DefaultDNSLocal)
|
dnsLocal := getOrDefault(t.DNSLocal, DefaultDNSLocal)
|
||||||
|
dnsSetup := getOrDefault(t.DNSSetup, DefaultDNSSetup)
|
||||||
directTag := getOrDefault(t.DirectTag, DefaultDirectTag)
|
directTag := getOrDefault(t.DirectTag, DefaultDirectTag)
|
||||||
|
dnsSetupDetour := ifElse(dnsSetup != "local", "", directTag)
|
||||||
|
|
||||||
options.DNS = &option.DNSOptions{
|
options.DNS = &option.DNSOptions{
|
||||||
Servers: []option.DNSServerOptions{},
|
Servers: []option.DNSServerOptions{},
|
||||||
@ -68,15 +78,21 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
|
|||||||
defaultDNSOptions.AddressResolver = dnsLocalTag
|
defaultDNSOptions.AddressResolver = dnsLocalTag
|
||||||
}
|
}
|
||||||
if t.RemoteResolve {
|
if t.RemoteResolve {
|
||||||
defaultDNSOptions.Detour = getOrDefault(t.DefaultTag, DefaultDefaultTag)
|
defaultDNSOptions.Detour = getOrDefault(t.DefaultTag, DefaultProxyTag)
|
||||||
}
|
}
|
||||||
options.DNS.Servers = append(options.DNS.Servers, defaultDNSOptions)
|
options.DNS.Servers = append(options.DNS.Servers, defaultDNSOptions)
|
||||||
|
|
||||||
|
dnsSetupUrl, err := url.Parse(dnsSetup)
|
||||||
|
if err != nil || BM.IsDomainName(dnsSetupUrl.Hostname()) {
|
||||||
|
return errors.New("dns_setup must be ip based dns or local")
|
||||||
|
}
|
||||||
|
|
||||||
if t.DisableTrafficBypass {
|
if t.DisableTrafficBypass {
|
||||||
options.DNS.Servers = append(options.DNS.Servers, option.DNSServerOptions{
|
options.DNS.Servers = append(options.DNS.Servers, option.DNSServerOptions{
|
||||||
Tag: dnsLocalTag,
|
Tag: dnsLocalTag,
|
||||||
Address: "local",
|
Address: dnsSetup,
|
||||||
Strategy: domainStrategyLocal,
|
Strategy: domainStrategyLocal,
|
||||||
|
Detour: dnsSetupDetour,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
localDNSOptions := []option.DNSServerOptions{{
|
localDNSOptions := []option.DNSServerOptions{{
|
||||||
@ -86,11 +102,12 @@ func (t *Template) renderDNS(metadata M.Metadata, options *option.Options) error
|
|||||||
Strategy: domainStrategyLocal,
|
Strategy: domainStrategyLocal,
|
||||||
}}
|
}}
|
||||||
if dnsLocalUrl, err := url.Parse(dnsLocal); err == nil && BM.IsDomainName(dnsLocalUrl.Hostname()) {
|
if dnsLocalUrl, err := url.Parse(dnsLocal); err == nil && BM.IsDomainName(dnsLocalUrl.Hostname()) {
|
||||||
localDNSOptions[0].AddressResolver = dnsLocalSetupTag
|
localDNSOptions[0].AddressResolver = dnsSetupTag
|
||||||
localDNSOptions = append(localDNSOptions, option.DNSServerOptions{
|
localDNSOptions = append(localDNSOptions, option.DNSServerOptions{
|
||||||
Tag: dnsLocalSetupTag,
|
Tag: dnsSetupTag,
|
||||||
Address: "local",
|
Address: dnsSetup,
|
||||||
Strategy: domainStrategyLocal,
|
Strategy: domainStrategyLocal,
|
||||||
|
Detour: dnsSetupDetour,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
options.DNS.Servers = append(options.DNS.Servers, localDNSOptions...)
|
options.DNS.Servers = append(options.DNS.Servers, localDNSOptions...)
|
||||||
|
@ -21,7 +21,7 @@ func (t *Template) renderOutbounds(metadata M.Metadata, options *boxOption.Optio
|
|||||||
disableRuleAction := t.DisableRuleAction || (metadata.Version != nil && metadata.Version.LessThan(semver.ParseVersion("1.11.0-alpha.7")))
|
disableRuleAction := t.DisableRuleAction || (metadata.Version != nil && metadata.Version.LessThan(semver.ParseVersion("1.11.0-alpha.7")))
|
||||||
defaultTag := t.DefaultTag
|
defaultTag := t.DefaultTag
|
||||||
if defaultTag == "" {
|
if defaultTag == "" {
|
||||||
defaultTag = DefaultDefaultTag
|
defaultTag = DefaultProxyTag
|
||||||
}
|
}
|
||||||
directTag := t.DirectTag
|
directTag := t.DirectTag
|
||||||
if directTag == "" {
|
if directTag == "" {
|
||||||
|
@ -102,7 +102,7 @@ func (t *Template) renderRoute(metadata M.Metadata, options *option.Options) err
|
|||||||
directTag = DefaultDirectTag
|
directTag = DefaultDirectTag
|
||||||
}
|
}
|
||||||
if defaultTag == "" {
|
if defaultTag == "" {
|
||||||
defaultTag = DefaultDefaultTag
|
defaultTag = DefaultProxyTag
|
||||||
}
|
}
|
||||||
options.Route.Rules = append(options.Route.Rules, option.Rule{
|
options.Route.Rules = append(options.Route.Rules, option.Rule{
|
||||||
Type: C.RuleTypeDefault,
|
Type: C.RuleTypeDefault,
|
||||||
|
@ -16,11 +16,12 @@ const (
|
|||||||
DefaultMixedPort = 8080
|
DefaultMixedPort = 8080
|
||||||
DefaultDNSTag = "default"
|
DefaultDNSTag = "default"
|
||||||
DefaultDNSLocalTag = "local"
|
DefaultDNSLocalTag = "local"
|
||||||
DefaultDNSLocalSetupTag = "local_setup"
|
DefaultDNSSetupTag = "local_setup"
|
||||||
DefaultDNSFakeIPTag = "remote"
|
DefaultDNSFakeIPTag = "remote"
|
||||||
DefaultDNS = "tls://8.8.8.8"
|
DefaultDNS = "tls://8.8.8.8"
|
||||||
DefaultDNSLocal = "https://223.5.5.5/dns-query"
|
DefaultDNSLocal = "https://223.5.5.5/dns-query"
|
||||||
DefaultDefaultTag = "default"
|
DefaultDNSSetup = "local"
|
||||||
|
DefaultProxyTag = "proxy"
|
||||||
DefaultDirectTag = "direct"
|
DefaultDirectTag = "direct"
|
||||||
DefaultBlockTag = "block"
|
DefaultBlockTag = "block"
|
||||||
DNSTag = "dns"
|
DNSTag = "dns"
|
||||||
|
Loading…
Reference in New Issue
Block a user