fix mixed inbound data for json sub
This commit is contained in:
@@ -128,7 +128,7 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
|
|||||||
protocol, _ := outbound["type"].(string)
|
protocol, _ := outbound["type"].(string)
|
||||||
config, _ := configs[protocol].(map[string]interface{})
|
config, _ := configs[protocol].(map[string]interface{})
|
||||||
for key, value := range config {
|
for key, value := range config {
|
||||||
if key != "alterId" && key != "name" && key != "username" {
|
if key != "alterId" && key != "name" {
|
||||||
outbound[key] = value
|
outbound[key] = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,10 +138,16 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
tag := outbound["tag"].(string)
|
tag, _ := outbound["tag"].(string)
|
||||||
if len(addrs) == 0 {
|
if len(addrs) == 0 {
|
||||||
outTags = append(outTags, tag)
|
// For mixed protocol, use separated socks and http
|
||||||
outbounds = append(outbounds, outbound)
|
if protocol == "mixed" {
|
||||||
|
outbound["tag"] = tag
|
||||||
|
j.pushMixed(&outbounds, &outTags, outbound)
|
||||||
|
} else {
|
||||||
|
outTags = append(outTags, tag)
|
||||||
|
outbounds = append(outbounds, outbound)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for index, addr := range addrs {
|
for index, addr := range addrs {
|
||||||
// Copy original config
|
// Copy original config
|
||||||
@@ -173,9 +179,14 @@ func (j *JsonService) getOutbounds(clientConfig json.RawMessage, inDatas *[]mode
|
|||||||
}
|
}
|
||||||
remark, _ := addr["remark"].(string)
|
remark, _ := addr["remark"].(string)
|
||||||
newTag := fmt.Sprintf("%d.%s%s", index+1, tag, remark)
|
newTag := fmt.Sprintf("%d.%s%s", index+1, tag, remark)
|
||||||
outTags = append(outTags, newTag)
|
|
||||||
newOut["tag"] = newTag
|
newOut["tag"] = newTag
|
||||||
outbounds = append(outbounds, newOut)
|
// 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,3 +276,20 @@ func (j *JsonService) addOthers(jsonConfig *map[string]interface{}) error {
|
|||||||
|
|
||||||
return nil
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ export default {
|
|||||||
HasInData: [
|
HasInData: [
|
||||||
InTypes.SOCKS,
|
InTypes.SOCKS,
|
||||||
InTypes.HTTP,
|
InTypes.HTTP,
|
||||||
|
InTypes.Mixed,
|
||||||
InTypes.Shadowsocks,
|
InTypes.Shadowsocks,
|
||||||
InTypes.VMess,
|
InTypes.VMess,
|
||||||
InTypes.ShadowTLS,
|
InTypes.ShadowTLS,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function fillData(out: any, inbound: Inbound, tlsClient: any) {
|
|||||||
out.server = location.hostname
|
out.server = location.hostname
|
||||||
out.server_port = inbound.listen_port
|
out.server_port = inbound.listen_port
|
||||||
switch(inbound.type){
|
switch(inbound.type){
|
||||||
case InTypes.HTTP || InTypes.SOCKS:
|
case InTypes.HTTP: case InTypes.SOCKS: case InTypes.Mixed:
|
||||||
return
|
return
|
||||||
case InTypes.Shadowsocks:
|
case InTypes.Shadowsocks:
|
||||||
shadowsocksOut(out, <Shadowsocks>inbound)
|
shadowsocksOut(out, <Shadowsocks>inbound)
|
||||||
|
|||||||
Reference in New Issue
Block a user