Skip to content

Commit

Permalink
chore: complete classical rule parse error log (#1839)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestL18 authored Feb 13, 2025
1 parent d1d846f commit ef29e45
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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版本即可使用 )
Expand All @@ -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服务器
Expand Down
4 changes: 3 additions & 1 deletion rules/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions rules/provider/classical_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:]
}
Expand All @@ -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)
}
Expand Down

0 comments on commit ef29e45

Please sign in to comment.