fix: trim regexp: prefix for rule

This commit is contained in:
pocketW 2022-08-22 22:09:54 +10:00
parent f29d2db235
commit 1ec1765517
2 changed files with 6 additions and 12 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"regexp" "regexp"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
@ -278,6 +279,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
defer c.access.Unlock() defer c.access.Unlock()
ruleListResponse := c.ConfigResp.Get("routing").Get("rules").GetIndex(1).Get("domain").MustStringArray() ruleListResponse := c.ConfigResp.Get("routing").Get("rules").GetIndex(1).Get("domain").MustStringArray()
for i, rule := range ruleListResponse { for i, rule := range ruleListResponse {
rule = strings.TrimPrefix(rule, "regexp:")
ruleListItem := api.DetectRule{ ruleListItem := api.DetectRule{
ID: i, ID: i,
Pattern: regexp.MustCompile(rule), Pattern: regexp.MustCompile(rule),

View File

@ -17,7 +17,6 @@ import (
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
// APIClient create an api client to the panel. // APIClient create an api client to the panel.
type APIClient struct { type APIClient struct {
client *resty.Client client *resty.Client
@ -273,6 +272,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
defer c.access.Unlock() defer c.access.Unlock()
ruleListResponse := c.ConfigResp.Get("routing").Get("rules").GetIndex(1).Get("domain").MustStringArray() ruleListResponse := c.ConfigResp.Get("routing").Get("rules").GetIndex(1).Get("domain").MustStringArray()
for i, rule := range ruleListResponse { for i, rule := range ruleListResponse {
rule = strings.TrimPrefix(rule, "regexp:")
ruleListItem := api.DetectRule{ ruleListItem := api.DetectRule{
ID: i, ID: i,
Pattern: regexp.MustCompile(rule), Pattern: regexp.MustCompile(rule),
@ -362,17 +362,9 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
TLSType = "xtls" TLSType = "xtls"
} }
inboundInfo := simplejson.New() tmpInboundInfo := nodeInfoResponse.Get("inbounds").MustArray()
if tmpInboundInfo, ok := nodeInfoResponse.CheckGet("inbound"); ok { marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{}))
inboundInfo = tmpInboundInfo inboundInfo, _ := simplejson.NewJson(marshalByte)
// Compatible with v2board 1.5.5-dev
} else if tmpInboundInfo, ok := nodeInfoResponse.CheckGet("inbounds"); ok {
tmpInboundInfo := tmpInboundInfo.MustArray()
marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{}))
inboundInfo, _ = simplejson.NewJson(marshalByte)
} else {
return nil, fmt.Errorf("Unable to find inbound(s) in the nodeInfo.")
}
port := uint32(inboundInfo.Get("port").MustUint64()) port := uint32(inboundInfo.Get("port").MustUint64())
transportProtocol := inboundInfo.Get("streamSettings").Get("network").MustString() transportProtocol := inboundInfo.Get("streamSettings").Get("network").MustString()