Skip to content

Commit

Permalink
fix mixed inbound data for json sub
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Nov 21, 2024
1 parent 056c458 commit f1b6c8a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
40 changes: 34 additions & 6 deletions backend/sub/jsonService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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 {
outTags = append(outTags, tag)
outbounds = append(outbounds, outbound)
// 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
Expand Down Expand Up @@ -173,9 +179,14 @@ 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
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)
}
}
}
}
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions frontend/src/layouts/modals/Inbound.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default {
HasInData: [
InTypes.SOCKS,
InTypes.HTTP,
InTypes.Mixed,
InTypes.Shadowsocks,
InTypes.VMess,
InTypes.ShadowTLS,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/plugins/outJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f1b6c8a

Please sign in to comment.