mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
use route group to storage extra config
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user