update: Add support NewV2board api block rules

This commit is contained in:
Senis John 2022-12-07 23:26:09 +08:00
parent e774d5c822
commit 676365b13b
No known key found for this signature in database
GPG Key ID: 845E9E4727C3E1A4

View File

@ -248,20 +248,18 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
// GetNodeRule implements the API interface
func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
ruleList := c.LocalRuleList
if c.NodeType != "V2ray" {
return &ruleList, nil
}
// V2board only support the rule for v2ray
nodeInfoResponse := c.resp.Load().(*simplejson.Json) // todo waiting v2board send configuration
for i, rule := range nodeInfoResponse.Get("rules").MustStringArray() {
rule = strings.TrimPrefix(rule, "regexp:")
nodeInfoResponse := c.resp.Load().(*simplejson.Json)
for i, rule := range nodeInfoResponse.Get("routes").MustArray() {
r := rule.(map[string]any)
if r["action"] == "block" {
ruleListItem := api.DetectRule{
ID: i,
Pattern: regexp.MustCompile(rule),
Pattern: regexp.MustCompile(r["match"].(string)),
}
ruleList = append(ruleList, ruleListItem)
}
}
return &ruleList, nil
}