mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
update
initial support for hysteria update config update api change user email format ...
This commit is contained in:
@@ -7,9 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
"github.com/Yuzuki616/V2bX/common/file"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/Yuzuki616/V2bX/node/lego"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/core"
|
||||
@@ -23,7 +21,7 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
t := coreConf.TransportProtocol(nodeInfo.Network)
|
||||
in.StreamSetting = &coreConf.StreamConfig{Network: &t}
|
||||
var err error
|
||||
switch nodeInfo.NodeType {
|
||||
switch nodeInfo.Type {
|
||||
case "v2ray":
|
||||
err = buildV2ray(config, nodeInfo, in)
|
||||
case "trojan":
|
||||
@@ -31,14 +29,14 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
case "shadowsocks":
|
||||
err = buildShadowsocks(config, nodeInfo, in)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported node type: %s, Only support: V2ray, Trojan, Shadowsocks", nodeInfo.NodeType)
|
||||
return nil, fmt.Errorf("unsupported node type: %s, Only support: V2ray, Trojan, Shadowsocks", nodeInfo.Type)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Set server port
|
||||
in.PortList = &coreConf.PortList{
|
||||
Range: []coreConf.PortRange{{From: uint32(nodeInfo.ServerPort), To: uint32(nodeInfo.ServerPort)}},
|
||||
Range: []coreConf.PortRange{{From: uint32(nodeInfo.Port), To: uint32(nodeInfo.Port)}},
|
||||
}
|
||||
// Set Listen IP address
|
||||
ipAddress := net.ParseAddress(config.ListenIP)
|
||||
@@ -48,7 +46,7 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
Enabled: true,
|
||||
DestOverride: &coreConf.StringList{"http", "tls"},
|
||||
}
|
||||
if config.DisableSniffing {
|
||||
if config.XrayOptions.DisableSniffing {
|
||||
sniffingConfig.Enabled = false
|
||||
}
|
||||
in.SniffingConfig = sniffingConfig
|
||||
@@ -66,7 +64,7 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
AcceptProxyProtocol: config.EnableProxyProtocol} //Enable proxy protocol
|
||||
}
|
||||
// Set TLS or Reality settings
|
||||
if nodeInfo.Tls != 0 {
|
||||
if nodeInfo.Tls {
|
||||
if config.CertConfig == nil {
|
||||
return nil, errors.New("the CertConfig is not vail")
|
||||
}
|
||||
@@ -91,16 +89,11 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
}
|
||||
default:
|
||||
// Normal tls
|
||||
in.StreamSetting.Security = "tls"
|
||||
certFile, keyFile, err := getCertFile(config.CertConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
in.StreamSetting.TLSSettings = &coreConf.TLSConfig{
|
||||
Certs: []*coreConf.TLSCertConfig{
|
||||
{
|
||||
CertFile: certFile,
|
||||
KeyFile: keyFile,
|
||||
CertFile: config.CertConfig.CertFile,
|
||||
KeyFile: config.CertConfig.KeyFile,
|
||||
OcspStapling: 3600,
|
||||
},
|
||||
},
|
||||
@@ -111,24 +104,25 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
||||
// Support ProxyProtocol for any transport protocol
|
||||
if *in.StreamSetting.Network != "tcp" &&
|
||||
*in.StreamSetting.Network != "ws" &&
|
||||
*in.StreamSetting.Network != "" &&
|
||||
config.EnableProxyProtocol {
|
||||
sockoptConfig := &coreConf.SocketConfig{
|
||||
socketConfig := &coreConf.SocketConfig{
|
||||
AcceptProxyProtocol: config.EnableProxyProtocol,
|
||||
TFO: config.EnableTFO,
|
||||
TFO: config.XrayOptions.EnableTFO,
|
||||
} //Enable proxy protocol
|
||||
in.StreamSetting.SocketSettings = sockoptConfig
|
||||
in.StreamSetting.SocketSettings = socketConfig
|
||||
}
|
||||
in.Tag = tag
|
||||
return in.Build()
|
||||
}
|
||||
|
||||
func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error {
|
||||
if config.EnableVless {
|
||||
if config.XrayOptions.EnableVless {
|
||||
//Set vless
|
||||
inbound.Protocol = "vless"
|
||||
if config.EnableFallback {
|
||||
if config.XrayOptions.EnableFallback {
|
||||
// Set fallback
|
||||
fallbackConfigs, err := buildVlessFallbacks(config.FallBackConfigs)
|
||||
fallbackConfigs, err := buildVlessFallbacks(config.XrayOptions.FallBackConfigs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -185,9 +179,9 @@ func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound
|
||||
|
||||
func buildTrojan(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound *coreConf.InboundDetourConfig) error {
|
||||
inbound.Protocol = "trojan"
|
||||
if config.EnableFallback {
|
||||
if config.XrayOptions.EnableFallback {
|
||||
// Set fallback
|
||||
fallbackConfigs, err := buildTrojanFallbacks(config.FallBackConfigs)
|
||||
fallbackConfigs, err := buildTrojanFallbacks(config.XrayOptions.FallBackConfigs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -234,7 +228,7 @@ func buildShadowsocks(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, i
|
||||
settings.Users = append(settings.Users, defaultSSuser)
|
||||
settings.NetworkList = &coreConf.NetworkList{"tcp", "udp"}
|
||||
settings.IVCheck = true
|
||||
if config.DisableIVCheck {
|
||||
if config.XrayOptions.DisableIVCheck {
|
||||
settings.IVCheck = false
|
||||
}
|
||||
t := coreConf.TransportProtocol("tcp")
|
||||
@@ -247,30 +241,6 @@ func buildShadowsocks(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, i
|
||||
return nil
|
||||
}
|
||||
|
||||
func getCertFile(certConfig *conf.CertConfig) (certFile string, keyFile string, err error) {
|
||||
if certConfig.CertFile == "" || certConfig.KeyFile == "" {
|
||||
return "", "", fmt.Errorf("cert file path or key file path not exist")
|
||||
}
|
||||
switch certConfig.CertMode {
|
||||
case "file":
|
||||
return certConfig.CertFile, certConfig.KeyFile, nil
|
||||
case "dns", "http":
|
||||
if file.IsExist(certConfig.CertFile) && file.IsExist(certConfig.KeyFile) {
|
||||
return certConfig.CertFile, certConfig.KeyFile, nil
|
||||
}
|
||||
l, err := lego.New(certConfig)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("create lego object error: %s", err)
|
||||
}
|
||||
err = l.CreateCert()
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("create cert error: %s", err)
|
||||
}
|
||||
return certConfig.CertFile, certConfig.KeyFile, nil
|
||||
}
|
||||
return "", "", fmt.Errorf("unsupported certmode: %s", certConfig.CertMode)
|
||||
}
|
||||
|
||||
func buildVlessFallbacks(fallbackConfigs []conf.FallBackConfig) ([]*coreConf.VLessInboundFallback, error) {
|
||||
if fallbackConfigs == nil {
|
||||
return nil, fmt.Errorf("you must provide FallBackConfigs")
|
||||
|
||||
@@ -2,7 +2,6 @@ package builder
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
conf2 "github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/goccy/go-json"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
@@ -11,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// BuildOutbound build freedom outbund config for addoutbound
|
||||
func BuildOutbound(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
|
||||
func BuildOutbound(config *conf2.ControllerConfig, tag string) (*core.OutboundHandlerConfig, error) {
|
||||
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
||||
outboundDetourConfig.Protocol = "freedom"
|
||||
outboundDetourConfig.Tag = tag
|
||||
@@ -24,9 +23,9 @@ func BuildOutbound(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
||||
|
||||
// Freedom Protocol setting
|
||||
var domainStrategy = "Asis"
|
||||
if config.EnableDNS {
|
||||
if config.DNSType != "" {
|
||||
domainStrategy = config.DNSType
|
||||
if config.XrayOptions.EnableDNS {
|
||||
if config.XrayOptions.DNSType != "" {
|
||||
domainStrategy = config.XrayOptions.DNSType
|
||||
} else {
|
||||
domainStrategy = "UseIP"
|
||||
}
|
||||
@@ -37,7 +36,7 @@ func BuildOutbound(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
||||
var setting json.RawMessage
|
||||
setting, err := json.Marshal(proxySetting)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||
return nil, fmt.Errorf("marshal proxy config error: %s", err)
|
||||
}
|
||||
outboundDetourConfig.Settings = &setting
|
||||
return outboundDetourConfig.Build()
|
||||
|
||||
@@ -32,7 +32,7 @@ func BuildVmessUser(tag string, userInfo *panel.UserInfo) (user *protocol.User)
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: BuildUserTag(tag, userInfo), // Uid: InboundTag|email|uid
|
||||
Email: BuildUserTag(tag, userInfo.Uuid), // Uid: InboundTag|email
|
||||
Account: serial.ToTypedMessage(vmessAccount.Build()),
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func BuildVlessUser(tag string, userInfo *panel.UserInfo, xtls bool) (user *prot
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: BuildUserTag(tag, userInfo),
|
||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
||||
Account: serial.ToTypedMessage(vlessAccount),
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func BuildTrojanUser(tag string, userInfo *panel.UserInfo) (user *protocol.User)
|
||||
}
|
||||
return &protocol.User{
|
||||
Level: 0,
|
||||
Email: BuildUserTag(tag, userInfo),
|
||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
||||
Account: serial.ToTypedMessage(trojanAccount),
|
||||
}
|
||||
}
|
||||
@@ -115,8 +115,8 @@ func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey
|
||||
}
|
||||
}
|
||||
|
||||
func BuildUserTag(tag string, user *panel.UserInfo) string {
|
||||
return fmt.Sprintf("%s|%s|%d", tag, user.Uuid, user.Id)
|
||||
func BuildUserTag(tag string, uuid string) string {
|
||||
return fmt.Sprintf("%s|%s", tag, uuid)
|
||||
}
|
||||
|
||||
func getCipherFromString(c string) shadowsocks.CipherType {
|
||||
|
||||
Reference in New Issue
Block a user