use route group to storage extra config

This commit is contained in:
yuzuki999
2023-06-25 08:22:05 +08:00
parent 9af5d1a6e7
commit 07b7ec9b3e
7 changed files with 100 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ package panel
import (
"fmt"
"github.com/Yuzuki616/V2bX/conf"
"github.com/goccy/go-json"
"reflect"
"regexp"
@@ -54,6 +55,7 @@ type NodeInfo struct {
Host string
Port int
Network string
ExtraConfig V2rayExtraConfig
NetworkSettings json.RawMessage
Tls bool
ServerName string
@@ -66,6 +68,13 @@ type NodeInfo struct {
PullInterval time.Duration
}
type V2rayExtraConfig struct {
EnableVless bool `json:"EnableVless"`
VlessFlow string `json:"VlessFlow"`
EnableReality bool `json:"EnableReality"`
RealityConfig conf.RealityConfig `json:"RealityConfig"`
}
func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
const path = "/api/v1/server/UniProxy/config"
r, err := c.client.
@@ -88,17 +97,30 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
if err != nil {
return nil, fmt.Errorf("decode common params error: %s", err)
}
var extra []byte
for i := range common.Routes { // parse rules from routes
if common.Routes[i].Action == "block" {
var matchs []string
if _, ok := common.Routes[i].Match.(string); ok {
matchs = strings.Split(common.Routes[i].Match.(string), ",")
} else {
matchs = common.Routes[i].Match.([]string)
var matchs []string
if _, ok := common.Routes[i].Match.(string); ok {
matchs = strings.Split(common.Routes[i].Match.(string), ",")
} else if _, ok = common.Routes[i].Match.([]string); ok {
matchs = common.Routes[i].Match.([]string)
} else {
temp := common.Routes[i].Match.([]interface{})
matchs = make([]string, len(temp))
for i := range temp {
matchs[i] = temp[i].(string)
}
}
switch common.Routes[i].Action {
case "block":
for _, v := range matchs {
node.Rules = append(node.Rules, regexp.MustCompile(v))
}
case "dns":
if matchs[0] != "extra" {
break
}
extra = []byte(strings.Join(matchs[1:], ""))
}
}
node.ServerName = common.ServerName
@@ -120,6 +142,12 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
if rsp.Tls == 1 {
node.Tls = true
}
if len(extra) != 0 {
err = json.Unmarshal(extra, &node.ExtraConfig)
if err != nil {
return nil, fmt.Errorf("decode v2ray extra error: %s", err)
}
}
case "shadowsocks":
rsp := ShadowsocksNodeRsp{}
err = json.Unmarshal(r.Body(), &rsp)