From ef29e4501e072d159db78b7d364bfaaa87afa8d6 Mon Sep 17 00:00:00 2001 From: ForestL <45709305+ForestL18@users.noreply.github.com> Date: Thu, 13 Feb 2025 17:25:45 +0800 Subject: [PATCH] chore: complete classical rule parse error log (#1839) --- docs/config.yaml | 3 ++- rules/parser.go | 4 +++- rules/provider/classical_strategy.go | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/config.yaml b/docs/config.yaml index 2c2f3f43..ad77debb 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -61,7 +61,7 @@ external-controller-tls: 0.0.0.0:9443 # RESTful API HTTPS 监听地址,需要 # RESTful API CORS标头配置 external-controller-cors: allow-origins: - - * + - "*" allow-private-network: true # RESTful API Unix socket 监听地址( windows版本大于17063也可以使用,即大于等于1803/RS4版本即可使用 ) @@ -78,6 +78,7 @@ external-controller-pipe: \\.\pipe\mihomo # 配置 WEB UI 目录,使用 http://{{external-controller}}/ui 访问 external-ui: /path/to/ui/folder/ external-ui-name: xd +# 目前支持下载zip,tgz格式的压缩包 external-ui-url: "https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip" # 在RESTful API端口上开启DOH服务器 diff --git a/rules/parser.go b/rules/parser.go index 83325433..f4e945c9 100644 --- a/rules/parser.go +++ b/rules/parser.go @@ -81,8 +81,10 @@ func ParseRule(tp, payload, target string, params []string, subRules map[string] case "MATCH": parsed = RC.NewMatch(target) parseErr = nil + case "": + parseErr = fmt.Errorf("missing subsequent parameters: %s", payload) default: - parseErr = fmt.Errorf("unsupported rule type %s", tp) + parseErr = fmt.Errorf("unsupported rule type: %s", tp) } if parseErr != nil { diff --git a/rules/provider/classical_strategy.go b/rules/provider/classical_strategy.go index 205a8e59..95a772e8 100644 --- a/rules/provider/classical_strategy.go +++ b/rules/provider/classical_strategy.go @@ -59,7 +59,7 @@ func (c *classicalStrategy) Insert(rule string) { r, err := c.parse(ruleType, rule, "", params) if err != nil { - log.Warnln("parse rule error:[%s]", err.Error()) + log.Warnln("parse classical rule error: %s", err.Error()) } else { if r.ShouldResolveIP() { c.shouldResolveIP = true @@ -83,7 +83,7 @@ func ruleParse(ruleRaw string) (string, string, []string) { return item[0], item[1], nil } else if len(item) > 2 { if item[0] == "NOT" || item[0] == "OR" || item[0] == "AND" || item[0] == "SUB-RULE" || item[0] == "DOMAIN-REGEX" || item[0] == "PROCESS-NAME-REGEX" || item[0] == "PROCESS-PATH-REGEX" { - return item[0], strings.Join(item[1:len(item)], ","), nil + return item[0], strings.Join(item[1:], ","), nil } else { return item[0], item[1], item[2:] } @@ -95,8 +95,8 @@ func ruleParse(ruleRaw string) (string, string, []string) { func NewClassicalStrategy(parse func(tp, payload, target string, params []string, subRules map[string][]C.Rule) (parsed C.Rule, parseErr error)) *classicalStrategy { return &classicalStrategy{rules: []C.Rule{}, parse: func(tp, payload, target string, params []string) (parsed C.Rule, parseErr error) { switch tp { - case "MATCH": - return nil, fmt.Errorf("unsupported rule type on rule-set") + case "MATCH", "RULE-SET", "SUB-RULE": + return nil, fmt.Errorf("unsupported rule type on classical rule-set: %s", tp) default: return parse(tp, payload, target, params, nil) }