fix sing-box client dns

This commit is contained in:
Alireza Ahmadi
2024-07-04 11:29:02 +02:00
parent 209561497a
commit e1aaa3d748
2 changed files with 57 additions and 43 deletions
+4 -16
View File
@@ -147,10 +147,11 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
newOut[key] = value newOut[key] = value
} }
// Change and push copied config // Change and push copied config
newOut["server"] = addr["server"].(string) newOut["server"], _ = addr["server"].(string)
port := addr["server_port"].(float64) port, _ := addr["server_port"].(float64)
newOut["server_port"] = int(port) newOut["server_port"] = int(port)
newTag := fmt.Sprintf("%d.%s", index+1, tag) remark, _ := addr["remark"].(string)
newTag := fmt.Sprintf("%d.%s%s", index+1, tag, remark)
outTags = append(outTags, newTag) outTags = append(outTags, newTag)
newOut["tag"] = newTag newOut["tag"] = newTag
outbounds = append(outbounds, newOut) outbounds = append(outbounds, newOut)
@@ -193,19 +194,6 @@ func (j *JsonService) addDefaultOutbounds(outbounds *[]map[string]interface{}, o
func (j *JsonService) addOthers(jsonConfig *map[string]interface{}) error { func (j *JsonService) addOthers(jsonConfig *map[string]interface{}) error {
rules := []interface{}{ rules := []interface{}{
map[string]interface{}{
"type": "logical",
"mode": "or",
"rules": []interface{}{
map[string]interface{}{
"port": 53,
},
map[string]interface{}{
"protocol": "dns",
},
},
"outbound": "dns-out",
},
map[string]interface{}{ map[string]interface{}{
"clash_mode": "Direct", "clash_mode": "Direct",
"outbound": "direct", "outbound": "direct",
+53 -27
View File
@@ -115,41 +115,56 @@ export default {
defaultDns: { defaultDns: {
"servers": [ "servers": [
{ {
"tag": "ProxyDns", "address": "tcp://8.8.8.8",
"address": "8.8.8.8", "detour": "proxy",
"detour": "proxy" "address_resolver": "local-dns",
"tag": "proxy-dns"
}, },
{ {
"tag": "block", "tag": "local-dns",
"address": "rcode://success" "address": "local",
"detour": "direct"
},
{
"address": "rcode://success",
"tag": "block"
} }
], ],
"rules": [ "rules": [
{ {
"clash_mode": "Global", "clash_mode": "Global",
"server": "ProxyDns" "source_ip_cidr": [
"172.19.0.0/30"
],
"server": "proxy-dns"
},
{
"source_ip_cidr": [
"172.19.0.0/30"
],
"server": "proxy-dns"
} }
], ],
"final": "ProxyDns", "final": "local-dns",
"strategy": "prefer_ipv4" "strategy": "prefer_ipv4"
}, },
geositeList: [ geositeList: [
{ title: "Private", value: "geosite-private" }, { title: "Private", value: "geosite-private" },
{ title: "Ads", value: "geosite-ads" }, { title: "Ads", value: "geosite-ads" },
{ title: "Iran", value: "geosite-ir" }, { title: "🇮🇷 Iran", value: "geosite-ir" },
{ title: "China", value: "geosite-cn" }, { title: "🇨🇳 China", value: "geosite-cn" },
{ title: "Vietnam", value: "geosite-vn" }, { title: "🇻🇳 Vietnam", value: "geosite-vn" },
], ],
geoList: [ geoList: [
{ title: "DNS-Private", value: "geoip-private" }, { title: "Site-Private", value: "geoip-private" },
{ title: "IP-Private", value: "geosite-private" }, { title: "IP-Private", value: "geosite-private" },
{ title: "DNS-Ads", value: "geosite-ads" }, { title: "Site-Ads", value: "geosite-ads" },
{ title: "DNS-Iran", value: "geosite-ir" }, { title: "🇮🇷 Site-Iran", value: "geosite-ir" },
{ title: "IP-Iran", value: "geoip-ir" }, { title: "🇮🇷 IP-Iran", value: "geoip-ir" },
{ title: "DNS-China", value: "geosite-cn" }, { title: "🇨🇳 Site-China", value: "geosite-cn" },
{ title: "IP-China", value: "geoip-cn" }, { title: "🇨🇳 IP-China", value: "geoip-cn" },
{ title: "DNS-Vietnam", value: "geosite-vn" }, { title: "🇻🇳 Site-Vietnam", value: "geosite-vn" },
{ title: "IP-Vietnam", value: "geoip-vn" }, { title: "🇻🇳 IP-Vietnam", value: "geoip-vn" },
], ],
geo: [ geo: [
{ {
@@ -225,7 +240,18 @@ export default {
}, },
enableDns: { enableDns: {
get() :boolean { return this.subJsonExt?.dns != undefined }, get() :boolean { return this.subJsonExt?.dns != undefined },
set(v:boolean) { v ? this.subJsonExt.dns = this.defaultDns : delete this.subJsonExt.dns } set(v:boolean) {
if (v) {
this.subJsonExt.dns = this.defaultDns
if (this.rules == undefined) this.subJsonExt.rules = []
this.subJsonExt.rules.unshift({ protocol: "dns", outbound: "dns-out" })
} else {
delete this.subJsonExt.dns
const ruleDnsIndex = this.subJsonExt?.rules?.findIndex((r:any) => r.protocol = "dns" && r.outbound == "dns-out")
if (ruleDnsIndex >= 0) this.subJsonExt.rules.splice(ruleDnsIndex,1)
if (this.rules.length == 0) delete this.subJsonExt.rules
}
}
}, },
enableExp: { enableExp: {
get() :boolean { return this.subJsonExt?.experimental != undefined }, get() :boolean { return this.subJsonExt?.experimental != undefined },
@@ -237,34 +263,34 @@ export default {
set(v:string) { this.dns.servers[0].address = v.length>0 ? v : "8.8.8.8" } set(v:string) { this.dns.servers[0].address = v.length>0 ? v : "8.8.8.8" }
}, },
directDns: { directDns: {
get() :string { return this.dns?.servers?.findLast((d:any) => d.tag == "DirectDns")?.address?? "" }, get() :string { return this.dns?.servers?.findLast((d:any) => d.tag == "direct-dns")?.address?? "" },
set(v:string) { set(v:string) {
const sIndex = this.dns.servers.findIndex((d:any) => d.tag == "DirectDns") const sIndex = this.dns.servers.findIndex((d:any) => d.tag == "direct-dns")
if (v?.length>0) { if (v?.length>0) {
if (sIndex === -1) { if (sIndex === -1) {
this.dns.servers.push({ tag: "DirectDns", address: v, detour: "direct" }) this.dns.servers.push({ tag: "direct-dns", address: v, detour: "direct" })
this.dns.rules.push({ clash_mode: "Direct", server: "DirectDns" }) this.dns.rules.push({ clash_mode: "Direct", server: "direct-dns" })
} else { } else {
this.dns.servers[sIndex].address = v this.dns.servers[sIndex].address = v
} }
} else { } else {
this.dns.servers.splice(sIndex,1) this.dns.servers.splice(sIndex,1)
this.dns.rules = this.dns.rules.filter((r:any) => r.server != "DirectDns") this.dns.rules = this.dns.rules.filter((r:any) => r.server != "direct-dns")
} }
}, },
}, },
dnsToDirect: { dnsToDirect: {
get() :string[] { get() :string[] {
const ruleIndex = this.dns?.rules?.findIndex((r:any) => r.server == "DirectDns" && Object.hasOwn(r,'rule_set')) const ruleIndex = this.dns?.rules?.findIndex((r:any) => r.server == "direct-dns" && Object.hasOwn(r,'rule_set'))
return ruleIndex >= 0 ? this.dns.rules[ruleIndex].rule_set : [] return ruleIndex >= 0 ? this.dns.rules[ruleIndex].rule_set : []
}, },
set(v:string[]) { set(v:string[]) {
const ruleIndex = this.dns?.rules?.findIndex((r:any) => r.server == "DirectDns" && Object.hasOwn(r,'rule_set')) const ruleIndex = this.dns?.rules?.findIndex((r:any) => r.server == "direct-dns" && Object.hasOwn(r,'rule_set'))
if (v.length>0) { if (v.length>0) {
if (ruleIndex >= 0){ if (ruleIndex >= 0){
this.dns.rules[ruleIndex].rule_set = v this.dns.rules[ruleIndex].rule_set = v
} else { } else {
this.dns.rules.push({ rule_set: v, server: "DirectDns" }) this.dns.rules.push({ rule_set: v, server: "direct-dns" })
} }
} else { } else {
if (ruleIndex != -1) this.dns.rules.splice(ruleIndex,1) if (ruleIndex != -1) this.dns.rules.splice(ruleIndex,1)