mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-08 05:19:54 +00:00
update: support v2board v1.7.2 routes structure
After update this version, the v2board version must >= 1.7.2 release
This commit is contained in:
parent
0c2d03f3e0
commit
d44fa11eee
@ -1 +1,8 @@
|
|||||||
package newV2board
|
package newV2board
|
||||||
|
|
||||||
|
type route struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
Match []string `json:"match"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
ActionValue *string `json:"action_value"`
|
||||||
|
}
|
||||||
|
@ -257,30 +257,18 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
|
|||||||
|
|
||||||
// GetNodeRule implements the API interface
|
// GetNodeRule implements the API interface
|
||||||
func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
|
func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
|
||||||
|
var routes []route
|
||||||
|
b, _ := c.resp.Load().(*simplejson.Json).Get("routes").MarshalJSON()
|
||||||
|
json.Unmarshal(b, &routes)
|
||||||
|
|
||||||
ruleList := c.LocalRuleList
|
ruleList := c.LocalRuleList
|
||||||
|
|
||||||
nodeInfoResponse := c.resp.Load().(*simplejson.Json)
|
for i := range routes {
|
||||||
for i, rule := range nodeInfoResponse.Get("routes").MustArray() {
|
if routes[i].Action == "block" {
|
||||||
r := rule.(map[string]any)
|
ruleList = append(ruleList, api.DetectRule{
|
||||||
if r["action"] == "block" {
|
ID: i,
|
||||||
// todo remove at 2023.6.1, compatible with 1.7.1
|
Pattern: regexp.MustCompile(strings.Join(routes[i].Match, "|")),
|
||||||
switch r["match"].(type) {
|
})
|
||||||
case []any:
|
|
||||||
var s []string
|
|
||||||
for i := range r["match"].([]any) {
|
|
||||||
s = append(s, r["match"].([]any)[i].(string))
|
|
||||||
}
|
|
||||||
ruleList = append(ruleList, api.DetectRule{
|
|
||||||
ID: i,
|
|
||||||
Pattern: regexp.MustCompile(strings.Join(s, "|")),
|
|
||||||
})
|
|
||||||
case string:
|
|
||||||
s := r["match"].(string)
|
|
||||||
ruleList = append(ruleList, api.DetectRule{
|
|
||||||
ID: i,
|
|
||||||
Pattern: regexp.MustCompile(strings.ReplaceAll(s, ",", "|")),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,12 +397,15 @@ func (c *APIClient) parseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseDNSConfig(nodeInfoResponse *simplejson.Json) (nameServerList []*conf.NameServerConfig) {
|
func parseDNSConfig(nodeInfoResponse *simplejson.Json) (nameServerList []*conf.NameServerConfig) {
|
||||||
for _, rule := range nodeInfoResponse.Get("routes").MustArray() {
|
var routes []route
|
||||||
r := rule.(map[string]any)
|
b, _ := nodeInfoResponse.Get("routes").MarshalJSON()
|
||||||
if r["action"] == "dns" {
|
json.Unmarshal(b, &routes)
|
||||||
|
|
||||||
|
for i := range routes {
|
||||||
|
if routes[i].Action == "dns" {
|
||||||
nameServerList = append(nameServerList, &conf.NameServerConfig{
|
nameServerList = append(nameServerList, &conf.NameServerConfig{
|
||||||
Address: &conf.Address{Address: net.ParseAddress(r["action_value"].(string))},
|
Address: &conf.Address{Address: net.ParseAddress(*routes[i].ActionValue)},
|
||||||
Domains: strings.Split(r["match"].(string), ","),
|
Domains: routes[i].Match,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user