fix mixed inbound data for json sub

This commit is contained in:
Alireza Ahmadi
2024-11-21 22:51:14 +01:00
parent 056c458753
commit f1b6c8a131
3 changed files with 36 additions and 7 deletions
+31 -3
View File
@@ -128,7 +128,7 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
protocol, _ := outbound["type"].(string)
config, _ := configs[protocol].(map[string]interface{})
for key, value := range config {
if key != "alterId" && key != "name" && key != "username" {
if key != "alterId" && key != "name" {
outbound[key] = value
}
}
@@ -138,10 +138,16 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
if err != nil {
return nil, nil, err
}
tag := outbound["tag"].(string)
tag, _ := outbound["tag"].(string)
if len(addrs) == 0 {
// For mixed protocol, use separated socks and http
if protocol == "mixed" {
outbound["tag"] = tag
j.pushMixed(&outbounds, &outTags, outbound)
} else {
outTags = append(outTags, tag)
outbounds = append(outbounds, outbound)
}
} else {
for index, addr := range addrs {
// Copy original config
@@ -173,12 +179,17 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
}
remark, _ := addr["remark"].(string)
newTag := fmt.Sprintf("%d.%s%s", index+1, tag, remark)
outTags = append(outTags, newTag)
newOut["tag"] = newTag
// For mixed protocol, use separated socks and http
if protocol == "mixed" {
j.pushMixed(&outbounds, &outTags, newOut)
} else {
outTags = append(outTags, newTag)
outbounds = append(outbounds, newOut)
}
}
}
}
return &outbounds, &outTags, nil
}
@@ -265,3 +276,20 @@ func (j *JsonService) addOthers(jsonConfig *map[string]interface{}) error {
return nil
}
func (j *JsonService) pushMixed(outbounds *[]map[string]interface{}, outTags *[]string, out map[string]interface{}) {
socksOut := make(map[string]interface{}, 1)
httpOut := make(map[string]interface{}, 1)
for key, value := range out {
socksOut[key] = value
httpOut[key] = value
}
socksTag := fmt.Sprintf("%s-socks", out["tag"])
httpTag := fmt.Sprintf("%s-http", out["tag"])
socksOut["type"] = "socks"
httpOut["type"] = "http"
socksOut["tag"] = socksTag
httpOut["tag"] = httpTag
*outbounds = append(*outbounds, socksOut, httpOut)
*outTags = append(*outTags, socksTag, httpTag)
}
+1
View File
@@ -126,6 +126,7 @@ export default {
HasInData: [
InTypes.SOCKS,
InTypes.HTTP,
InTypes.Mixed,
InTypes.Shadowsocks,
InTypes.VMess,
InTypes.ShadowTLS,
+1 -1
View File
@@ -15,7 +15,7 @@ export function fillData(out: any, inbound: Inbound, tlsClient: any) {
out.server = location.hostname
out.server_port = inbound.listen_port
switch(inbound.type){
case InTypes.HTTP || InTypes.SOCKS:
case InTypes.HTTP: case InTypes.SOCKS: case InTypes.Mixed:
return
case InTypes.Shadowsocks:
shadowsocksOut(out, <Shadowsocks>inbound)