mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
fix block routes
This commit is contained in:
parent
bb430dbb8d
commit
d98ec9f61c
@ -4,6 +4,7 @@ import (
|
||||
"github.com/goccy/go-json"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NodeInfo struct {
|
||||
@ -60,12 +61,13 @@ func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
|
||||
nodeInfo.NodeId = c.NodeId
|
||||
nodeInfo.NodeType = c.NodeType
|
||||
for i := range nodeInfo.Routes { // parse rules from routes
|
||||
r := &nodeInfo.Routes[i]
|
||||
if r.Action == "block" {
|
||||
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
|
||||
ID: r.Id,
|
||||
Pattern: regexp.MustCompile(r.Match),
|
||||
})
|
||||
if nodeInfo.Routes[i].Action == "block" {
|
||||
for _, v := range strings.Split(nodeInfo.Routes[i].Match, ",") {
|
||||
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
|
||||
ID: nodeInfo.Routes[i].Id,
|
||||
Pattern: regexp.MustCompile(v),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeInfo.Routes = nil
|
||||
|
@ -41,14 +41,14 @@ func New(server *core.Core, api panel.Panel, config *conf.ControllerConfig) *Nod
|
||||
func (c *Node) Start() error {
|
||||
c.clientInfo = c.apiClient.Describe()
|
||||
// First fetch Node Info
|
||||
newNodeInfo, err := c.apiClient.GetNodeInfo()
|
||||
var err error
|
||||
c.nodeInfo, err = c.apiClient.GetNodeInfo()
|
||||
if err != nil {
|
||||
return fmt.Errorf("get node info failed: %s", err)
|
||||
}
|
||||
c.nodeInfo = newNodeInfo
|
||||
c.Tag = c.buildNodeTag()
|
||||
// Add new tag
|
||||
err = c.addNewTag(newNodeInfo)
|
||||
err = c.addNewTag(c.nodeInfo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("add new tag failed: %s", err)
|
||||
}
|
||||
@ -60,7 +60,7 @@ func (c *Node) Start() error {
|
||||
if len(c.userList) == 0 {
|
||||
return errors.New("add users failed: not have any user")
|
||||
}
|
||||
err = c.addNewUser(c.userList, newNodeInfo)
|
||||
err = c.addNewUser(c.userList, c.nodeInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -69,7 +69,7 @@ func (c *Node) Start() error {
|
||||
}
|
||||
// Add Rule Manager
|
||||
if !c.DisableGetRule {
|
||||
if err := c.server.UpdateRule(c.Tag, newNodeInfo.Rules); err != nil {
|
||||
if err := c.server.UpdateRule(c.Tag, c.nodeInfo.Rules); err != nil {
|
||||
log.Printf("Update rule filed: %s", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user