mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-02 06:48:14 -05:00
use route group to storage extra config
This commit is contained in:
parent
9af5d1a6e7
commit
07b7ec9b3e
@ -2,6 +2,7 @@ package panel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -54,6 +55,7 @@ type NodeInfo struct {
|
|||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
Network string
|
Network string
|
||||||
|
ExtraConfig V2rayExtraConfig
|
||||||
NetworkSettings json.RawMessage
|
NetworkSettings json.RawMessage
|
||||||
Tls bool
|
Tls bool
|
||||||
ServerName string
|
ServerName string
|
||||||
@ -66,6 +68,13 @@ type NodeInfo struct {
|
|||||||
PullInterval time.Duration
|
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) {
|
func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
||||||
const path = "/api/v1/server/UniProxy/config"
|
const path = "/api/v1/server/UniProxy/config"
|
||||||
r, err := c.client.
|
r, err := c.client.
|
||||||
@ -88,17 +97,30 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("decode common params error: %s", err)
|
return nil, fmt.Errorf("decode common params error: %s", err)
|
||||||
}
|
}
|
||||||
|
var extra []byte
|
||||||
for i := range common.Routes { // parse rules from routes
|
for i := range common.Routes { // parse rules from routes
|
||||||
if common.Routes[i].Action == "block" {
|
|
||||||
var matchs []string
|
var matchs []string
|
||||||
if _, ok := common.Routes[i].Match.(string); ok {
|
if _, ok := common.Routes[i].Match.(string); ok {
|
||||||
matchs = strings.Split(common.Routes[i].Match.(string), ",")
|
matchs = strings.Split(common.Routes[i].Match.(string), ",")
|
||||||
} else {
|
} else if _, ok = common.Routes[i].Match.([]string); ok {
|
||||||
matchs = common.Routes[i].Match.([]string)
|
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 {
|
for _, v := range matchs {
|
||||||
node.Rules = append(node.Rules, regexp.MustCompile(v))
|
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
|
node.ServerName = common.ServerName
|
||||||
@ -120,6 +142,12 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
if rsp.Tls == 1 {
|
if rsp.Tls == 1 {
|
||||||
node.Tls = true
|
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":
|
case "shadowsocks":
|
||||||
rsp := ShadowsocksNodeRsp{}
|
rsp := ShadowsocksNodeRsp{}
|
||||||
err = json.Unmarshal(r.Body(), &rsp)
|
err = json.Unmarshal(r.Body(), &rsp)
|
||||||
|
@ -102,6 +102,25 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// use remote reality replace local config
|
||||||
|
if nodeInfo.ExtraConfig.EnableReality {
|
||||||
|
rc := nodeInfo.ExtraConfig.RealityConfig
|
||||||
|
in.StreamSetting.Security = "reality"
|
||||||
|
d, err := json.Marshal(rc.Dest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("marshal reality dest error: %s", err)
|
||||||
|
}
|
||||||
|
in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{
|
||||||
|
Dest: d,
|
||||||
|
Xver: rc.Xver,
|
||||||
|
ServerNames: rc.ServerNames,
|
||||||
|
PrivateKey: rc.PrivateKey,
|
||||||
|
MinClientVer: rc.MinClientVer,
|
||||||
|
MaxClientVer: rc.MaxClientVer,
|
||||||
|
MaxTimeDiff: rc.MaxTimeDiff,
|
||||||
|
ShortIds: rc.ShortIds,
|
||||||
|
}
|
||||||
|
}
|
||||||
// Support ProxyProtocol for any transport protocol
|
// Support ProxyProtocol for any transport protocol
|
||||||
if *in.StreamSetting.Network != "tcp" &&
|
if *in.StreamSetting.Network != "tcp" &&
|
||||||
*in.StreamSetting.Network != "ws" &&
|
*in.StreamSetting.Network != "ws" &&
|
||||||
@ -117,7 +136,8 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error {
|
func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error {
|
||||||
if config.XrayOptions.EnableVless {
|
if config.XrayOptions.EnableVless ||
|
||||||
|
nodeInfo.ExtraConfig.EnableVless {
|
||||||
//Set vless
|
//Set vless
|
||||||
inbound.Protocol = "vless"
|
inbound.Protocol = "vless"
|
||||||
if config.XrayOptions.EnableFallback {
|
if config.XrayOptions.EnableFallback {
|
||||||
|
@ -14,8 +14,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const xtlsFLow = "xtls-rprx-vision"
|
|
||||||
|
|
||||||
func BuildVmessUsers(tag string, userInfo []panel.UserInfo) (users []*protocol.User) {
|
func BuildVmessUsers(tag string, userInfo []panel.UserInfo) (users []*protocol.User) {
|
||||||
users = make([]*protocol.User, len(userInfo))
|
users = make([]*protocol.User, len(userInfo))
|
||||||
for i, user := range userInfo {
|
for i, user := range userInfo {
|
||||||
@ -37,21 +35,19 @@ func BuildVmessUser(tag string, userInfo *panel.UserInfo) (user *protocol.User)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildVlessUsers(tag string, userInfo []panel.UserInfo, xtls bool) (users []*protocol.User) {
|
func BuildVlessUsers(tag string, userInfo []panel.UserInfo, flow string) (users []*protocol.User) {
|
||||||
users = make([]*protocol.User, len(userInfo))
|
users = make([]*protocol.User, len(userInfo))
|
||||||
for i := range userInfo {
|
for i := range userInfo {
|
||||||
users[i] = BuildVlessUser(tag, &(userInfo)[i], xtls)
|
users[i] = BuildVlessUser(tag, &(userInfo)[i], flow)
|
||||||
}
|
}
|
||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildVlessUser(tag string, userInfo *panel.UserInfo, xtls bool) (user *protocol.User) {
|
func BuildVlessUser(tag string, userInfo *panel.UserInfo, flow string) (user *protocol.User) {
|
||||||
vlessAccount := &vless.Account{
|
vlessAccount := &vless.Account{
|
||||||
Id: userInfo.Uuid,
|
Id: userInfo.Uuid,
|
||||||
}
|
}
|
||||||
if xtls {
|
vlessAccount.Flow = flow
|
||||||
vlessAccount.Flow = xtlsFLow
|
|
||||||
}
|
|
||||||
return &protocol.User{
|
return &protocol.User{
|
||||||
Level: 0,
|
Level: 0,
|
||||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
Email: BuildUserTag(tag, userInfo.Uuid),
|
||||||
|
18
conf/node.go
18
conf/node.go
@ -28,7 +28,7 @@ type XrayOptions struct {
|
|||||||
EnableDNS bool `yaml:"EnableDNS"`
|
EnableDNS bool `yaml:"EnableDNS"`
|
||||||
DNSType string `yaml:"DNSType"`
|
DNSType string `yaml:"DNSType"`
|
||||||
EnableVless bool `yaml:"EnableVless"`
|
EnableVless bool `yaml:"EnableVless"`
|
||||||
EnableXtls bool `yaml:"EnableXtls"`
|
VlessFlow string `json:"VlessFlow"`
|
||||||
EnableUot bool `yaml:"EnableUot"`
|
EnableUot bool `yaml:"EnableUot"`
|
||||||
EnableTFO bool `yaml:"EnableTFO"`
|
EnableTFO bool `yaml:"EnableTFO"`
|
||||||
DisableIVCheck bool `yaml:"DisableIVCheck"`
|
DisableIVCheck bool `yaml:"DisableIVCheck"`
|
||||||
@ -103,12 +103,12 @@ type CertConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RealityConfig struct {
|
type RealityConfig struct {
|
||||||
Dest interface{} `yaml:"Dest"`
|
Dest interface{} `yaml:"Dest" json:"Dest"`
|
||||||
Xver uint64 `yaml:"Xver"`
|
Xver uint64 `yaml:"Xver" json:"Xver"`
|
||||||
ServerNames []string `yaml:"ServerNames"`
|
ServerNames []string `yaml:"ServerNames" json:"ServerNames"`
|
||||||
PrivateKey string `yaml:"PrivateKey"`
|
PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"`
|
||||||
MinClientVer string `yaml:"MinClientVer"`
|
MinClientVer string `yaml:"MinClientVer" json:"MinClientVer"`
|
||||||
MaxClientVer string `yaml:"MaxClientVer"`
|
MaxClientVer string `yaml:"MaxClientVer" json:"MaxClientVer"`
|
||||||
MaxTimeDiff uint64 `yaml:"MaxTimeDiff"`
|
MaxTimeDiff uint64 `yaml:"MaxTimeDiff" json:"MaxTimeDiff"`
|
||||||
ShortIds []string `yaml:"ShortIds"`
|
ShortIds []string `yaml:"ShortIds" json:"ShortIds"`
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
package hy
|
package hy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
|
"github.com/Yuzuki616/V2bX/limiter"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"log"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServer(t *testing.T) {
|
func TestServer(t *testing.T) {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
s := NewServer("test")
|
limiter.Init()
|
||||||
|
l := limiter.AddLimiter("test", &conf.LimitConfig{}, nil)
|
||||||
|
s := NewServer("test", l)
|
||||||
t.Log(s.runServer(&panel.NodeInfo{
|
t.Log(s.runServer(&panel.NodeInfo{
|
||||||
Port: 11415,
|
Port: 1145,
|
||||||
UpMbps: 100,
|
UpMbps: 100,
|
||||||
DownMbps: 100,
|
DownMbps: 100,
|
||||||
HyObfs: "atresssdaaaadd",
|
HyObfs: "atresssdaaaadd",
|
||||||
@ -24,5 +30,13 @@ func TestServer(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
s.users.Store("test1111", struct{}{})
|
s.users.Store("test1111", struct{}{})
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
auth := base64.StdEncoding.EncodeToString([]byte("test1111"))
|
||||||
|
log.Println(auth)
|
||||||
|
log.Println(s.counter.getCounters(auth).UpCounter.Load())
|
||||||
|
}
|
||||||
|
}()
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,24 @@ func (c *Core) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
|||||||
users := make([]*protocol.User, 0, len(p.UserInfo))
|
users := make([]*protocol.User, 0, len(p.UserInfo))
|
||||||
switch p.NodeInfo.Type {
|
switch p.NodeInfo.Type {
|
||||||
case "v2ray":
|
case "v2ray":
|
||||||
if p.Config.XrayOptions.EnableXtls {
|
|
||||||
users = builder.BuildVlessUsers(p.Tag, p.UserInfo, true)
|
if p.Config.XrayOptions.EnableVless ||
|
||||||
|
p.NodeInfo.ExtraConfig.EnableVless {
|
||||||
|
|
||||||
|
if p.Config.XrayOptions.VlessFlow != "" {
|
||||||
|
if p.Config.XrayOptions.VlessFlow == p.NodeInfo.ExtraConfig.VlessFlow {
|
||||||
|
users = builder.BuildVlessUsers(p.Tag, p.UserInfo, p.Config.XrayOptions.VlessFlow)
|
||||||
|
} else {
|
||||||
|
users = builder.BuildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
users = builder.BuildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
users = builder.BuildVmessUsers(p.Tag, p.UserInfo)
|
users = builder.BuildVmessUsers(p.Tag, p.UserInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "trojan":
|
case "trojan":
|
||||||
users = builder.BuildTrojanUsers(p.Tag, p.UserInfo)
|
users = builder.BuildTrojanUsers(p.Tag, p.UserInfo)
|
||||||
case "shadowsocks":
|
case "shadowsocks":
|
||||||
|
@ -31,7 +31,7 @@ Nodes:
|
|||||||
DNSType: AsIs # AsIs, UseIP, UseIPv4, UseIPv6, DNS strategy
|
DNSType: AsIs # AsIs, UseIP, UseIPv4, UseIPv6, DNS strategy
|
||||||
EnableTFO: false # Enable TCP Fast Open
|
EnableTFO: false # Enable TCP Fast Open
|
||||||
EnableVless: false # Enable Vless for V2ray Type
|
EnableVless: false # Enable Vless for V2ray Type
|
||||||
EnableXtls: false # Enable xtls-rprx-vision, only vless
|
VlessFlow: "xtls-rprx-vision" # flow for vless, "xtls-rprx-vision" or "none" or ""
|
||||||
EnableProxyProtocol: false # Only works for WebSocket and TCP
|
EnableProxyProtocol: false # Only works for WebSocket and TCP
|
||||||
EnableFallback: false # Only support for Trojan and Vless
|
EnableFallback: false # Only support for Trojan and Vless
|
||||||
FallBackConfigs: # Support multiple fallbacks
|
FallBackConfigs: # Support multiple fallbacks
|
||||||
|
Loading…
Reference in New Issue
Block a user