mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-02 06:48:14 -05:00
commit
720173f3f3
@ -2,13 +2,16 @@ package panel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
|
||||||
"github.com/goccy/go-json"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Yuzuki616/V2bX/common/crypt"
|
||||||
|
|
||||||
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
|
"github.com/goccy/go-json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommonNodeRsp struct {
|
type CommonNodeRsp struct {
|
||||||
@ -97,7 +100,6 @@ 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
|
||||||
var matchs []string
|
var matchs []string
|
||||||
if _, ok := common.Routes[i].Match.(string); ok {
|
if _, ok := common.Routes[i].Match.(string); ok {
|
||||||
@ -117,10 +119,6 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
node.Rules = append(node.Rules, regexp.MustCompile(v))
|
node.Rules = append(node.Rules, regexp.MustCompile(v))
|
||||||
}
|
}
|
||||||
case "dns":
|
case "dns":
|
||||||
if matchs[0] != "extra" {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
extra = []byte(strings.Join(matchs[1:], ""))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.ServerName = common.ServerName
|
node.ServerName = common.ServerName
|
||||||
@ -142,11 +140,14 @@ 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(rsp.NetworkSettings, &node.ExtraConfig)
|
||||||
err = json.Unmarshal(extra, &node.ExtraConfig)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("decode v2ray extra error: %s", err)
|
return nil, fmt.Errorf("decode v2ray extra error: %s", err)
|
||||||
}
|
}
|
||||||
|
if node.ExtraConfig.RealityConfig.PrivateKey != "" {
|
||||||
|
temp := crypt.GenShaHash([]byte(c.APIHost + c.Token))[:32]
|
||||||
|
temp, err = crypt.AesDecrypt(node.ExtraConfig.RealityConfig.PrivateKey, []byte(temp))
|
||||||
|
node.ExtraConfig.RealityConfig.PrivateKey = temp
|
||||||
}
|
}
|
||||||
case "shadowsocks":
|
case "shadowsocks":
|
||||||
rsp := ShadowsocksNodeRsp{}
|
rsp := ShadowsocksNodeRsp{}
|
||||||
|
@ -3,14 +3,15 @@ package panel
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
|
||||||
"github.com/go-resty/resty/v2"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Panel is the interface for different panel's api.
|
// Panel is the interface for different panel's api.
|
||||||
@ -18,7 +19,7 @@ import (
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
client *resty.Client
|
client *resty.Client
|
||||||
APIHost string
|
APIHost string
|
||||||
Key string
|
Token string
|
||||||
NodeType string
|
NodeType string
|
||||||
NodeId int
|
NodeId int
|
||||||
LocalRuleList []*regexp.Regexp
|
LocalRuleList []*regexp.Regexp
|
||||||
@ -48,7 +49,7 @@ func New(c *conf.ApiConfig) (*Client, error) {
|
|||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
|
||||||
}
|
}
|
||||||
// Create Key for each requests
|
// set params
|
||||||
client.SetQueryParams(map[string]string{
|
client.SetQueryParams(map[string]string{
|
||||||
"node_type": c.NodeType,
|
"node_type": c.NodeType,
|
||||||
"node_id": strconv.Itoa(c.NodeID),
|
"node_id": strconv.Itoa(c.NodeID),
|
||||||
@ -58,7 +59,7 @@ func New(c *conf.ApiConfig) (*Client, error) {
|
|||||||
localRuleList := readLocalRuleList(c.RuleListPath)
|
localRuleList := readLocalRuleList(c.RuleListPath)
|
||||||
return &Client{
|
return &Client{
|
||||||
client: client,
|
client: client,
|
||||||
Key: c.Key,
|
Token: c.Key,
|
||||||
APIHost: c.APIHost,
|
APIHost: c.APIHost,
|
||||||
NodeType: c.NodeType,
|
NodeType: c.NodeType,
|
||||||
NodeId: c.NodeID,
|
NodeId: c.NodeID,
|
||||||
|
@ -4,6 +4,9 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Yuzuki616/V2bX/common/crypt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/crypto/curve25519"
|
"golang.org/x/crypto/curve25519"
|
||||||
@ -22,6 +25,19 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func executeX25519() {
|
func executeX25519() {
|
||||||
|
var yes, key string
|
||||||
|
fmt.Println("要对私钥进行加密吗?(Y/n)")
|
||||||
|
fmt.Scan(&yes)
|
||||||
|
if strings.ToLower(yes) == "y" {
|
||||||
|
var temp string
|
||||||
|
fmt.Println("请输入Api接口地址:")
|
||||||
|
fmt.Scan(&temp)
|
||||||
|
key = temp
|
||||||
|
fmt.Println("请输入Api认证Token:")
|
||||||
|
fmt.Scan(&temp)
|
||||||
|
key += temp
|
||||||
|
key = crypt.GenShaHash([]byte(key))
|
||||||
|
}
|
||||||
var output string
|
var output string
|
||||||
var err error
|
var err error
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -45,9 +61,16 @@ func executeX25519() {
|
|||||||
output = Err("gen X25519 error: ", err)
|
output = Err("gen X25519 error: ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p := base64.RawURLEncoding.EncodeToString(privateKey)
|
||||||
output = fmt.Sprint("Private key: ",
|
output = fmt.Sprint("Private key: ",
|
||||||
base64.RawURLEncoding.EncodeToString(privateKey),
|
p,
|
||||||
"\nPublic key: ",
|
"\nPublic key: ",
|
||||||
base64.RawURLEncoding.EncodeToString(publicKey))
|
base64.RawURLEncoding.EncodeToString(publicKey))
|
||||||
|
if strings.ToLower(yes) == "y" {
|
||||||
|
key, err = crypt.AesEncrypt([]byte(p), []byte(key[:32]))
|
||||||
|
if err != nil {
|
||||||
|
output = Err("encrypt private key error: ", err)
|
||||||
|
}
|
||||||
|
output += "\n加密后的Private key:" + key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
package builder
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
|
||||||
"github.com/xtls/xray-core/common/serial"
|
|
||||||
"github.com/xtls/xray-core/infra/conf"
|
|
||||||
"github.com/xtls/xray-core/proxy/shadowsocks"
|
|
||||||
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
|
|
||||||
"github.com/xtls/xray-core/proxy/trojan"
|
|
||||||
"github.com/xtls/xray-core/proxy/vless"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func BuildVmessUsers(tag string, userInfo []panel.UserInfo) (users []*protocol.User) {
|
|
||||||
users = make([]*protocol.User, len(userInfo))
|
|
||||||
for i, user := range userInfo {
|
|
||||||
users[i] = BuildVmessUser(tag, &user)
|
|
||||||
}
|
|
||||||
return users
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildVmessUser(tag string, userInfo *panel.UserInfo) (user *protocol.User) {
|
|
||||||
vmessAccount := &conf.VMessAccount{
|
|
||||||
ID: userInfo.Uuid,
|
|
||||||
AlterIds: 0,
|
|
||||||
Security: "auto",
|
|
||||||
}
|
|
||||||
return &protocol.User{
|
|
||||||
Level: 0,
|
|
||||||
Email: BuildUserTag(tag, userInfo.Uuid), // Uid: InboundTag|email
|
|
||||||
Account: serial.ToTypedMessage(vmessAccount.Build()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildVlessUsers(tag string, userInfo []panel.UserInfo, flow string) (users []*protocol.User) {
|
|
||||||
users = make([]*protocol.User, len(userInfo))
|
|
||||||
for i := range userInfo {
|
|
||||||
users[i] = BuildVlessUser(tag, &(userInfo)[i], flow)
|
|
||||||
}
|
|
||||||
return users
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildVlessUser(tag string, userInfo *panel.UserInfo, flow string) (user *protocol.User) {
|
|
||||||
vlessAccount := &vless.Account{
|
|
||||||
Id: userInfo.Uuid,
|
|
||||||
}
|
|
||||||
vlessAccount.Flow = flow
|
|
||||||
return &protocol.User{
|
|
||||||
Level: 0,
|
|
||||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
|
||||||
Account: serial.ToTypedMessage(vlessAccount),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildTrojanUsers(tag string, userInfo []panel.UserInfo) (users []*protocol.User) {
|
|
||||||
users = make([]*protocol.User, len(userInfo))
|
|
||||||
for i := range userInfo {
|
|
||||||
users[i] = BuildTrojanUser(tag, &(userInfo)[i])
|
|
||||||
}
|
|
||||||
return users
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildTrojanUser(tag string, userInfo *panel.UserInfo) (user *protocol.User) {
|
|
||||||
trojanAccount := &trojan.Account{
|
|
||||||
Password: userInfo.Uuid,
|
|
||||||
}
|
|
||||||
return &protocol.User{
|
|
||||||
Level: 0,
|
|
||||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
|
||||||
Account: serial.ToTypedMessage(trojanAccount),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func BuildSSUsers(tag string, userInfo []panel.UserInfo, cypher string, serverKey string) (users []*protocol.User) {
|
|
||||||
users = make([]*protocol.User, len(userInfo))
|
|
||||||
for i := range userInfo {
|
|
||||||
users[i] = BuildSSUser(tag, &userInfo[i], cypher, serverKey)
|
|
||||||
}
|
|
||||||
return users
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey string) (user *protocol.User) {
|
|
||||||
if serverKey == "" {
|
|
||||||
ssAccount := &shadowsocks.Account{
|
|
||||||
Password: userInfo.Uuid,
|
|
||||||
CipherType: getCipherFromString(cypher),
|
|
||||||
}
|
|
||||||
return &protocol.User{
|
|
||||||
Level: 0,
|
|
||||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
|
||||||
Account: serial.ToTypedMessage(ssAccount),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var keyLength int
|
|
||||||
switch cypher {
|
|
||||||
case "2022-blake3-aes-128-gcm":
|
|
||||||
keyLength = 16
|
|
||||||
case "2022-blake3-aes-256-gcm":
|
|
||||||
keyLength = 32
|
|
||||||
}
|
|
||||||
ssAccount := &shadowsocks_2022.User{
|
|
||||||
Key: base64.StdEncoding.EncodeToString([]byte(userInfo.Uuid[:keyLength])),
|
|
||||||
}
|
|
||||||
return &protocol.User{
|
|
||||||
Level: 0,
|
|
||||||
Email: BuildUserTag(tag, userInfo.Uuid),
|
|
||||||
Account: serial.ToTypedMessage(ssAccount),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func BuildUserTag(tag string, uuid string) string {
|
|
||||||
return fmt.Sprintf("%s|%s", tag, uuid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getCipherFromString(c string) shadowsocks.CipherType {
|
|
||||||
switch strings.ToLower(c) {
|
|
||||||
case "aes-128-gcm", "aead_aes_128_gcm":
|
|
||||||
return shadowsocks.CipherType_AES_128_GCM
|
|
||||||
case "aes-256-gcm", "aead_aes_256_gcm":
|
|
||||||
return shadowsocks.CipherType_AES_256_GCM
|
|
||||||
case "chacha20-poly1305", "aead_chacha20_poly1305", "chacha20-ietf-poly1305":
|
|
||||||
return shadowsocks.CipherType_CHACHA20_POLY1305
|
|
||||||
case "none", "plain":
|
|
||||||
return shadowsocks.CipherType_NONE
|
|
||||||
default:
|
|
||||||
return shadowsocks.CipherType_UNKNOWN
|
|
||||||
}
|
|
||||||
}
|
|
30
common/crypt/aes.go
Normal file
30
common/crypt/aes.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package crypt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/aes"
|
||||||
|
"encoding/base64"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AesEncrypt(data []byte, key []byte) (string, error) {
|
||||||
|
a, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
en := make([]byte, len(data))
|
||||||
|
a.Encrypt(en, data)
|
||||||
|
return base64.StdEncoding.EncodeToString(en), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AesDecrypt(data string, key []byte) (string, error) {
|
||||||
|
d, err := base64.StdEncoding.DecodeString(data)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
a, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
de := make([]byte, len(data))
|
||||||
|
a.Decrypt(de, d)
|
||||||
|
return string(de), nil
|
||||||
|
}
|
11
common/crypt/sha.go
Normal file
11
common/crypt/sha.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package crypt
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenShaHash(data []byte) string {
|
||||||
|
d := sha256.Sum256(data)
|
||||||
|
return hex.EncodeToString(d[:])
|
||||||
|
}
|
9
common/format/user.go
Normal file
9
common/format/user.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package format
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UserTag(tag string, uuid string) string {
|
||||||
|
return fmt.Sprintf("%s|%s", tag, uuid)
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package xray
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
@ -16,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildInbound build Inbound config for different protocol
|
// BuildInbound build Inbound config for different protocol
|
||||||
func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
|
func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
|
||||||
in := &coreConf.InboundDetourConfig{}
|
in := &coreConf.InboundDetourConfig{}
|
||||||
// Set network protocol
|
// Set network protocol
|
||||||
t := coreConf.TransportProtocol(nodeInfo.Network)
|
t := coreConf.TransportProtocol(nodeInfo.Network)
|
||||||
@ -102,7 +101,6 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
|||||||
RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
|
RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// use remote reality replace local config
|
// use remote reality replace local config
|
||||||
if nodeInfo.ExtraConfig.EnableReality {
|
if nodeInfo.ExtraConfig.EnableReality {
|
||||||
rc := nodeInfo.ExtraConfig.RealityConfig
|
rc := nodeInfo.ExtraConfig.RealityConfig
|
||||||
@ -122,6 +120,7 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
|||||||
ShortIds: rc.ShortIds,
|
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" &&
|
||||||
@ -194,6 +193,8 @@ func buildV2ray(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, inbound
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unmarshal grpc settings error: %s", err)
|
return fmt.Errorf("unmarshal grpc settings error: %s", err)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return errors.New("the network type is not vail")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/common/builder"
|
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/features/inbound"
|
"github.com/xtls/xray-core/features/inbound"
|
||||||
@ -12,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.ControllerConfig) error {
|
func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.ControllerConfig) error {
|
||||||
inboundConfig, err := builder.BuildInbound(config, info, tag)
|
inboundConfig, err := buildInbound(config, info, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("build inbound error: %s", err)
|
return fmt.Errorf("build inbound error: %s", err)
|
||||||
}
|
}
|
||||||
@ -20,7 +19,7 @@ func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.Controller
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("add inbound error: %s", err)
|
return fmt.Errorf("add inbound error: %s", err)
|
||||||
}
|
}
|
||||||
outBoundConfig, err := builder.BuildOutbound(config, tag)
|
outBoundConfig, err := buildOutbound(config, tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("build outbound error: %s", err)
|
return fmt.Errorf("build outbound error: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package builder
|
package xray
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildOutbound build freedom outbund config for addoutbound
|
// BuildOutbound build freedom outbund config for addoutbound
|
||||||
func BuildOutbound(config *conf2.ControllerConfig, tag string) (*core.OutboundHandlerConfig, error) {
|
func buildOutbound(config *conf2.ControllerConfig, tag string) (*core.OutboundHandlerConfig, error) {
|
||||||
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
||||||
outboundDetourConfig.Protocol = "freedom"
|
outboundDetourConfig.Protocol = "freedom"
|
||||||
outboundDetourConfig.Tag = tag
|
outboundDetourConfig.Tag = tag
|
65
core/xray/ss.go
Normal file
65
core/xray/ss.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package xray
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
|
"github.com/Yuzuki616/V2bX/common/format"
|
||||||
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
|
"github.com/xtls/xray-core/proxy/shadowsocks"
|
||||||
|
"github.com/xtls/xray-core/proxy/shadowsocks_2022"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildSSUsers(tag string, userInfo []panel.UserInfo, cypher string, serverKey string) (users []*protocol.User) {
|
||||||
|
users = make([]*protocol.User, len(userInfo))
|
||||||
|
for i := range userInfo {
|
||||||
|
users[i] = buildSSUser(tag, &userInfo[i], cypher, serverKey)
|
||||||
|
}
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey string) (user *protocol.User) {
|
||||||
|
if serverKey == "" {
|
||||||
|
ssAccount := &shadowsocks.Account{
|
||||||
|
Password: userInfo.Uuid,
|
||||||
|
CipherType: getCipherFromString(cypher),
|
||||||
|
}
|
||||||
|
return &protocol.User{
|
||||||
|
Level: 0,
|
||||||
|
Email: format.UserTag(tag, userInfo.Uuid),
|
||||||
|
Account: serial.ToTypedMessage(ssAccount),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var keyLength int
|
||||||
|
switch cypher {
|
||||||
|
case "2022-blake3-aes-128-gcm":
|
||||||
|
keyLength = 16
|
||||||
|
case "2022-blake3-aes-256-gcm":
|
||||||
|
keyLength = 32
|
||||||
|
}
|
||||||
|
ssAccount := &shadowsocks_2022.User{
|
||||||
|
Key: base64.StdEncoding.EncodeToString([]byte(userInfo.Uuid[:keyLength])),
|
||||||
|
}
|
||||||
|
return &protocol.User{
|
||||||
|
Level: 0,
|
||||||
|
Email: format.UserTag(tag, userInfo.Uuid),
|
||||||
|
Account: serial.ToTypedMessage(ssAccount),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCipherFromString(c string) shadowsocks.CipherType {
|
||||||
|
switch strings.ToLower(c) {
|
||||||
|
case "aes-128-gcm", "aead_aes_128_gcm":
|
||||||
|
return shadowsocks.CipherType_AES_128_GCM
|
||||||
|
case "aes-256-gcm", "aead_aes_256_gcm":
|
||||||
|
return shadowsocks.CipherType_AES_256_GCM
|
||||||
|
case "chacha20-poly1305", "aead_chacha20_poly1305", "chacha20-ietf-poly1305":
|
||||||
|
return shadowsocks.CipherType_CHACHA20_POLY1305
|
||||||
|
case "none", "plain":
|
||||||
|
return shadowsocks.CipherType_NONE
|
||||||
|
default:
|
||||||
|
return shadowsocks.CipherType_UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
28
core/xray/trojan.go
Normal file
28
core/xray/trojan.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package xray
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
|
"github.com/Yuzuki616/V2bX/common/format"
|
||||||
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
|
"github.com/xtls/xray-core/proxy/trojan"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildTrojanUsers(tag string, userInfo []panel.UserInfo) (users []*protocol.User) {
|
||||||
|
users = make([]*protocol.User, len(userInfo))
|
||||||
|
for i := range userInfo {
|
||||||
|
users[i] = buildTrojanUser(tag, &(userInfo)[i])
|
||||||
|
}
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildTrojanUser(tag string, userInfo *panel.UserInfo) (user *protocol.User) {
|
||||||
|
trojanAccount := &trojan.Account{
|
||||||
|
Password: userInfo.Uuid,
|
||||||
|
}
|
||||||
|
return &protocol.User{
|
||||||
|
Level: 0,
|
||||||
|
Email: format.UserTag(tag, userInfo.Uuid),
|
||||||
|
Account: serial.ToTypedMessage(trojanAccount),
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/common/builder"
|
"github.com/Yuzuki616/V2bX/common/format"
|
||||||
vCore "github.com/Yuzuki616/V2bX/core"
|
vCore "github.com/Yuzuki616/V2bX/core"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/proxy"
|
"github.com/xtls/xray-core/proxy"
|
||||||
@ -33,7 +33,7 @@ func (c *Core) DelUsers(users []panel.UserInfo, tag string) error {
|
|||||||
}
|
}
|
||||||
var up, down, user string
|
var up, down, user string
|
||||||
for i := range users {
|
for i := range users {
|
||||||
user = builder.BuildUserTag(tag, users[i].Uuid)
|
user = format.UserTag(tag, users[i].Uuid)
|
||||||
err = userManager.RemoveUser(context.Background(), user)
|
err = userManager.RemoveUser(context.Background(), user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -47,8 +47,8 @@ func (c *Core) DelUsers(users []panel.UserInfo, tag string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
func (c *Core) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
||||||
upName := "user>>>" + builder.BuildUserTag(tag, uuid) + ">>>traffic>>>uplink"
|
upName := "user>>>" + format.UserTag(tag, uuid) + ">>>traffic>>>uplink"
|
||||||
downName := "user>>>" + builder.BuildUserTag(tag, uuid) + ">>>traffic>>>downlink"
|
downName := "user>>>" + format.UserTag(tag, uuid) + ">>>traffic>>>downlink"
|
||||||
upCounter := c.shm.GetCounter(upName)
|
upCounter := c.shm.GetCounter(upName)
|
||||||
downCounter := c.shm.GetCounter(downName)
|
downCounter := c.shm.GetCounter(downName)
|
||||||
if reset {
|
if reset {
|
||||||
@ -77,22 +77,24 @@ func (c *Core) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
|||||||
p.NodeInfo.ExtraConfig.EnableVless {
|
p.NodeInfo.ExtraConfig.EnableVless {
|
||||||
if p.Config.XrayOptions.VlessFlow != "" {
|
if p.Config.XrayOptions.VlessFlow != "" {
|
||||||
if p.Config.XrayOptions.VlessFlow == p.NodeInfo.ExtraConfig.VlessFlow {
|
if p.Config.XrayOptions.VlessFlow == p.NodeInfo.ExtraConfig.VlessFlow {
|
||||||
users = builder.BuildVlessUsers(p.Tag, p.UserInfo, p.Config.XrayOptions.VlessFlow)
|
// local
|
||||||
|
users = buildVlessUsers(p.Tag, p.UserInfo, p.Config.XrayOptions.VlessFlow)
|
||||||
} else {
|
} else {
|
||||||
users = builder.BuildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow)
|
// remote
|
||||||
}
|
users = 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)
|
// remote
|
||||||
|
users = buildVlessUsers(p.Tag, p.UserInfo, p.NodeInfo.ExtraConfig.VlessFlow)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
users = buildVmessUsers(p.Tag, p.UserInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "trojan":
|
case "trojan":
|
||||||
users = builder.BuildTrojanUsers(p.Tag, p.UserInfo)
|
users = buildTrojanUsers(p.Tag, p.UserInfo)
|
||||||
case "shadowsocks":
|
case "shadowsocks":
|
||||||
users = builder.BuildSSUsers(p.Tag,
|
users = buildSSUsers(p.Tag,
|
||||||
p.UserInfo,
|
p.UserInfo,
|
||||||
p.NodeInfo.Cipher,
|
p.NodeInfo.Cipher,
|
||||||
p.NodeInfo.ServerKey)
|
p.NodeInfo.ServerKey)
|
||||||
|
51
core/xray/vmess.go
Normal file
51
core/xray/vmess.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package xray
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
|
"github.com/Yuzuki616/V2bX/common/format"
|
||||||
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
|
"github.com/xtls/xray-core/common/serial"
|
||||||
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
|
"github.com/xtls/xray-core/proxy/vless"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildVmessUsers(tag string, userInfo []panel.UserInfo) (users []*protocol.User) {
|
||||||
|
users = make([]*protocol.User, len(userInfo))
|
||||||
|
for i, user := range userInfo {
|
||||||
|
users[i] = buildVmessUser(tag, &user)
|
||||||
|
}
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildVmessUser(tag string, userInfo *panel.UserInfo) (user *protocol.User) {
|
||||||
|
vmessAccount := &conf.VMessAccount{
|
||||||
|
ID: userInfo.Uuid,
|
||||||
|
AlterIds: 0,
|
||||||
|
Security: "auto",
|
||||||
|
}
|
||||||
|
return &protocol.User{
|
||||||
|
Level: 0,
|
||||||
|
Email: format.UserTag(tag, userInfo.Uuid), // Uid: InboundTag|email
|
||||||
|
Account: serial.ToTypedMessage(vmessAccount.Build()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildVlessUsers(tag string, userInfo []panel.UserInfo, flow string) (users []*protocol.User) {
|
||||||
|
users = make([]*protocol.User, len(userInfo))
|
||||||
|
for i := range userInfo {
|
||||||
|
users[i] = buildVlessUser(tag, &(userInfo)[i], flow)
|
||||||
|
}
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildVlessUser(tag string, userInfo *panel.UserInfo, flow string) (user *protocol.User) {
|
||||||
|
vlessAccount := &vless.Account{
|
||||||
|
Id: userInfo.Uuid,
|
||||||
|
}
|
||||||
|
vlessAccount.Flow = flow
|
||||||
|
return &protocol.User{
|
||||||
|
Level: 0,
|
||||||
|
Email: format.UserTag(tag, userInfo.Uuid),
|
||||||
|
Account: serial.ToTypedMessage(vlessAccount),
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@ package limiter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/common/builder"
|
"github.com/Yuzuki616/V2bX/common/format"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ func (l *Limiter) AddDynamicSpeedLimit(tag string, userInfo *panel.UserInfo, lim
|
|||||||
DynamicSpeedLimit: limitNum,
|
DynamicSpeedLimit: limitNum,
|
||||||
ExpireTime: time.Now().Add(time.Duration(expire) * time.Second).Unix(),
|
ExpireTime: time.Now().Add(time.Duration(expire) * time.Second).Unix(),
|
||||||
}
|
}
|
||||||
l.UserLimitInfo.Store(builder.BuildUserTag(tag, userInfo.Uuid), userLimit)
|
l.UserLimitInfo.Store(format.UserTag(tag, userInfo.Uuid), userLimit)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/common/builder"
|
"github.com/Yuzuki616/V2bX/common/format"
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
"github.com/juju/ratelimit"
|
"github.com/juju/ratelimit"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -61,7 +61,7 @@ func AddLimiter(tag string, l *conf.LimitConfig, users []panel.UserInfo) *Limite
|
|||||||
SpeedLimit: users[i].SpeedLimit,
|
SpeedLimit: users[i].SpeedLimit,
|
||||||
ExpireTime: 0,
|
ExpireTime: 0,
|
||||||
}
|
}
|
||||||
info.UserLimitInfo.Store(builder.BuildUserTag(tag, users[i].Uuid), userLimit)
|
info.UserLimitInfo.Store(format.UserTag(tag, users[i].Uuid), userLimit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
limitLock.Lock()
|
limitLock.Lock()
|
||||||
@ -86,7 +86,7 @@ func UpdateLimiter(tag string, added []panel.UserInfo, deleted []panel.UserInfo)
|
|||||||
return fmt.Errorf("get limit error: %s", err)
|
return fmt.Errorf("get limit error: %s", err)
|
||||||
}
|
}
|
||||||
for i := range deleted {
|
for i := range deleted {
|
||||||
l.UserLimitInfo.Delete(builder.BuildUserTag(tag, deleted[i].Uuid))
|
l.UserLimitInfo.Delete(format.UserTag(tag, deleted[i].Uuid))
|
||||||
}
|
}
|
||||||
for i := range added {
|
for i := range added {
|
||||||
if added[i].SpeedLimit != 0 {
|
if added[i].SpeedLimit != 0 {
|
||||||
@ -95,7 +95,7 @@ func UpdateLimiter(tag string, added []panel.UserInfo, deleted []panel.UserInfo)
|
|||||||
SpeedLimit: added[i].SpeedLimit,
|
SpeedLimit: added[i].SpeedLimit,
|
||||||
ExpireTime: 0,
|
ExpireTime: 0,
|
||||||
}
|
}
|
||||||
l.UserLimitInfo.Store(builder.BuildUserTag(tag, added[i].Uuid), userLimit)
|
l.UserLimitInfo.Store(format.UserTag(tag, added[i].Uuid), userLimit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
10
node/cert.go
10
node/cert.go
@ -21,13 +21,17 @@ func (c *Controller) renewCertTask() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) requestCert() error {
|
func (c *Controller) requestCert() error {
|
||||||
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
|
|
||||||
return fmt.Errorf("cert file path or key file path not exist")
|
|
||||||
}
|
|
||||||
switch c.CertConfig.CertMode {
|
switch c.CertConfig.CertMode {
|
||||||
case "reality", "none", "":
|
case "reality", "none", "":
|
||||||
return nil
|
return nil
|
||||||
|
case "file":
|
||||||
|
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
|
||||||
|
return fmt.Errorf("cert file path or key file path not exist")
|
||||||
|
}
|
||||||
case "dns", "http":
|
case "dns", "http":
|
||||||
|
if c.CertConfig.CertFile == "" || c.CertConfig.KeyFile == "" {
|
||||||
|
return fmt.Errorf("cert file path or key file path not exist")
|
||||||
|
}
|
||||||
if file.IsExist(c.CertConfig.CertFile) && file.IsExist(c.CertConfig.KeyFile) {
|
if file.IsExist(c.CertConfig.CertFile) && file.IsExist(c.CertConfig.KeyFile) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user