From 19e5ac8a0c53c39318152f83b7189f3e12e066b3 Mon Sep 17 00:00:00 2001 From: cubemaze Date: Sun, 16 Jul 2023 12:11:18 +0800 Subject: [PATCH 1/5] chore: rollback reality config, it remains effective. --- conf/node.go | 13 +++++++++++++ core/xray/inbound.go | 20 +++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/conf/node.go b/conf/node.go index 939fabd..eca14be 100644 --- a/conf/node.go +++ b/conf/node.go @@ -23,12 +23,24 @@ type ControllerConfig struct { CertConfig *CertConfig `yaml:"CertConfig"` } +type RealityConfig struct { + Dest interface{} `yaml:"Dest" json:"Dest"` + Xver uint64 `yaml:"Xver" json:"Xver"` + ServerNames []string `yaml:"ServerNames" json:"ServerNames"` + PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"` + MinClientVer string `yaml:"MinClientVer" json:"MinClientVer"` + MaxClientVer string `yaml:"MaxClientVer" json:"MaxClientVer"` + MaxTimeDiff uint64 `yaml:"MaxTimeDiff" json:"MaxTimeDiff"` + ShortIds []string `yaml:"ShortIds" json:"ShortIds"` +} + type XrayOptions struct { EnableProxyProtocol bool `yaml:"EnableProxyProtocol"` EnableDNS bool `yaml:"EnableDNS"` DNSType string `yaml:"DNSType"` EnableUot bool `yaml:"EnableUot"` EnableTFO bool `yaml:"EnableTFO"` + EnableVless bool `yaml:"EnableVless"` DisableIVCheck bool `yaml:"DisableIVCheck"` DisableSniffing bool `yaml:"DisableSniffing"` EnableFallback bool `yaml:"EnableFallback"` @@ -97,4 +109,5 @@ type CertConfig struct { Provider string `yaml:"Provider"` // alidns, cloudflare, gandi, godaddy.... Email string `yaml:"Email"` DNSEnv map[string]string `yaml:"DNSEnv"` + RealityConfig *RealityConfig `yaml:"RealityConfig"` } diff --git a/core/xray/inbound.go b/core/xray/inbound.go index e25f358..11a429f 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -71,6 +71,24 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s } switch config.CertConfig.CertMode { case "none", "": // disable + case "reality": + // Reality + in.StreamSetting.Security = "reality" + d, err := json.Marshal(config.CertConfig.RealityConfig.Dest) + if err != nil { + return nil, fmt.Errorf("marshal reality dest error: %s", err) + } + in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ + Dest: d, + Xver: config.CertConfig.RealityConfig.Xver, + ServerNames: config.CertConfig.RealityConfig.ServerNames, + PrivateKey: config.CertConfig.RealityConfig.PrivateKey, + MinClientVer: config.CertConfig.RealityConfig.MinClientVer, + MaxClientVer: config.CertConfig.RealityConfig.MaxClientVer, + MaxTimeDiff: config.CertConfig.RealityConfig.MaxTimeDiff, + ShortIds: config.CertConfig.RealityConfig.ShortIds, + } + case "remote": default: if nodeInfo.ExtraConfig.EnableReality { rc := nodeInfo.ExtraConfig.RealityConfig @@ -120,7 +138,7 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s } func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error { - if nodeInfo.ExtraConfig.EnableVless { + if config.XrayOptions.EnableVless || nodeInfo.ExtraConfig.EnableVless { //Set vless inbound.Protocol = "vless" if config.XrayOptions.EnableFallback { From fec573cfce99f2efff8aa0a096564a0a36912023 Mon Sep 17 00:00:00 2001 From: cubemaze Date: Wed, 19 Jul 2023 12:28:56 +0800 Subject: [PATCH 2/5] chore: remove unused --- conf/node.go | 1 - core/xray/inbound.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/conf/node.go b/conf/node.go index eca14be..868bd83 100644 --- a/conf/node.go +++ b/conf/node.go @@ -40,7 +40,6 @@ type XrayOptions struct { DNSType string `yaml:"DNSType"` EnableUot bool `yaml:"EnableUot"` EnableTFO bool `yaml:"EnableTFO"` - EnableVless bool `yaml:"EnableVless"` DisableIVCheck bool `yaml:"DisableIVCheck"` DisableSniffing bool `yaml:"DisableSniffing"` EnableFallback bool `yaml:"EnableFallback"` diff --git a/core/xray/inbound.go b/core/xray/inbound.go index 11a429f..acf0560 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -138,7 +138,7 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s } func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error { - if config.XrayOptions.EnableVless || nodeInfo.ExtraConfig.EnableVless { + if nodeInfo.ExtraConfig.EnableVless { //Set vless inbound.Protocol = "vless" if config.XrayOptions.EnableFallback { From 7e0b9f694bddb6155df93ea6d110bc10bf76fa63 Mon Sep 17 00:00:00 2001 From: cubemaze Date: Wed, 19 Jul 2023 12:29:03 +0800 Subject: [PATCH 3/5] chore: readme --- example/config.yml.example | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/example/config.yml.example b/example/config.yml.example index 697ca57..b6098de 100644 --- a/example/config.yml.example +++ b/example/config.yml.example @@ -30,8 +30,6 @@ Nodes: EnableDNS: false # Use custom DNS config, Please ensure that you set the dns.json well DNSType: AsIs # AsIs, UseIP, UseIPv4, UseIPv6, DNS strategy EnableTFO: false # Enable TCP Fast Open - EnableVless: false # Enable Vless for V2ray Type - VlessFlow: "xtls-rprx-vision" # flow for vless, "xtls-rprx-vision" or "none" or "" EnableProxyProtocol: false # Only works for WebSocket and TCP EnableFallback: false # Only support for Trojan and Vless FallBackConfigs: # Support multiple fallbacks @@ -70,7 +68,7 @@ Nodes: SpeedLimit: 0 # Speed limit, Mbps ExpireTime: 0 # Time limit, sec. CertConfig: - CertMode: dns # Option about how to get certificate: none, file, http, dns, reality. Choose "none" will forcedly disable the tls config. + CertMode: dns # Option about how to get certificate: none, file, http, dns, reality, remote. Choose "none" will forcedly disable the tls config. CertDomain: "node1.test.com" # Domain to cert CertFile: /etc/XrayR/cert/node1.test.com.cert # Provided if the CertMode is file KeyFile: /etc/XrayR/cert/node1.test.com.key From d2ead10ddf831a054796254df23ab7c9c9000f26 Mon Sep 17 00:00:00 2001 From: cubemaze Date: Wed, 19 Jul 2023 23:41:42 +0800 Subject: [PATCH 4/5] fix: wrong typo --- api/panel/node.go | 12 ++++++------ core/xray/inbound.go | 11 +++++++---- core/xray/user.go | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/api/panel/node.go b/api/panel/node.go index 0519a8d..6089eeb 100644 --- a/api/panel/node.go +++ b/api/panel/node.go @@ -72,20 +72,20 @@ type NodeInfo struct { } type V2rayExtraConfig struct { - EnableVless bool `json:"EnableVless"` + EnableVless string `json:"EnableVless"` VlessFlow string `json:"VlessFlow"` - EnableReality bool `json:"EnableReality"` + EnableReality string `json:"EnableReality"` RealityConfig *RealityConfig `json:"RealityConfig"` } type RealityConfig struct { Dest interface{} `yaml:"Dest" json:"Dest"` - Xver uint64 `yaml:"Xver" json:"Xver"` + Xver string `yaml:"Xver" json:"Xver"` ServerNames []string `yaml:"ServerNames" json:"ServerNames"` PrivateKey string `yaml:"PrivateKey" json:"PrivateKey"` MinClientVer string `yaml:"MinClientVer" json:"MinClientVer"` MaxClientVer string `yaml:"MaxClientVer" json:"MaxClientVer"` - MaxTimeDiff uint64 `yaml:"MaxTimeDiff" json:"MaxTimeDiff"` + MaxTimeDiff string `yaml:"MaxTimeDiff" json:"MaxTimeDiff"` ShortIds []string `yaml:"ShortIds" json:"ShortIds"` } @@ -155,9 +155,9 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) { if err != nil { return nil, fmt.Errorf("decode v2ray extra error: %s", err) } - if node.ExtraConfig.EnableReality { + if node.ExtraConfig.EnableReality == "true" { if node.ExtraConfig.RealityConfig == nil { - node.ExtraConfig.EnableReality = false + node.ExtraConfig.EnableReality = "false" } else { key := crypt.GenX25519Private([]byte(strconv.Itoa(c.NodeId) + c.NodeType + c.Token + node.ExtraConfig.RealityConfig.PrivateKey)) diff --git a/core/xray/inbound.go b/core/xray/inbound.go index acf0560..4f6cbe6 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "errors" "fmt" + "strconv" "github.com/Yuzuki616/V2bX/api/panel" "github.com/Yuzuki616/V2bX/conf" @@ -90,21 +91,23 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s } case "remote": default: - if nodeInfo.ExtraConfig.EnableReality { + if nodeInfo.ExtraConfig.EnableReality == "true" { 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) } + Xver, _ := strconv.ParseUint(rc.Xver, 10, 64) + MaxTimeDiff, _ := strconv.ParseUint(rc.Xver, 10, 64) in.StreamSetting.REALITYSettings = &coreConf.REALITYConfig{ Dest: d, - Xver: rc.Xver, + Xver: Xver, ServerNames: rc.ServerNames, PrivateKey: rc.PrivateKey, MinClientVer: rc.MinClientVer, MaxClientVer: rc.MaxClientVer, - MaxTimeDiff: rc.MaxTimeDiff, + MaxTimeDiff: MaxTimeDiff, ShortIds: rc.ShortIds, } } else { @@ -138,7 +141,7 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s } func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error { - if nodeInfo.ExtraConfig.EnableVless { + if nodeInfo.ExtraConfig.EnableVless == "true" { //Set vless inbound.Protocol = "vless" if config.XrayOptions.EnableFallback { diff --git a/core/xray/user.go b/core/xray/user.go index f76f009..86d1f36 100644 --- a/core/xray/user.go +++ b/core/xray/user.go @@ -74,7 +74,7 @@ func (c *Core) AddUsers(p *vCore.AddUsersParams) (added int, err error) { users := make([]*protocol.User, 0, len(p.UserInfo)) switch p.NodeInfo.Type { case "v2ray": - if p.NodeInfo.ExtraConfig.EnableVless { + if p.NodeInfo.ExtraConfig.EnableVless == "true" { users = buildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow) } else { users = buildVmessUsers(p.Tag, p.UserInfo) From 1a56cc8c819e7da54bd5ec74fb21031e3fa567ed Mon Sep 17 00:00:00 2001 From: cubemaze Date: Thu, 20 Jul 2023 16:52:46 +0800 Subject: [PATCH 5/5] chore: cert mode logic --- core/xray/inbound.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/xray/inbound.go b/core/xray/inbound.go index 4f6cbe6..55e67b1 100644 --- a/core/xray/inbound.go +++ b/core/xray/inbound.go @@ -71,7 +71,8 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s return nil, errors.New("the CertConfig is not vail") } switch config.CertConfig.CertMode { - case "none", "": // disable + case "none", "": + break // disable case "reality": // Reality in.StreamSetting.Security = "reality" @@ -89,8 +90,8 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s MaxTimeDiff: config.CertConfig.RealityConfig.MaxTimeDiff, ShortIds: config.CertConfig.RealityConfig.ShortIds, } + break case "remote": - default: if nodeInfo.ExtraConfig.EnableReality == "true" { rc := nodeInfo.ExtraConfig.RealityConfig in.StreamSetting.Security = "reality" @@ -110,7 +111,10 @@ func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s MaxTimeDiff: MaxTimeDiff, ShortIds: rc.ShortIds, } - } else { + break + } + default: + { // Normal tls in.StreamSetting.Security = "tls" in.StreamSetting.TLSSettings = &coreConf.TLSConfig{