2022-07-28 11:00:05 -04:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-08-16 01:04:33 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/api/panel"
|
2022-07-28 11:00:05 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"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/trojan"
|
|
|
|
"github.com/xtls/xray-core/proxy/vless"
|
|
|
|
)
|
|
|
|
|
2022-10-09 20:59:00 -04:00
|
|
|
func (c *Node) buildVmessUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
2022-08-12 06:02:06 -04:00
|
|
|
users = make([]*protocol.User, len(userInfo))
|
|
|
|
for i, user := range userInfo {
|
2022-10-09 20:59:00 -04:00
|
|
|
users[i] = c.buildVmessUser(&user, 0)
|
2022-07-28 11:00:05 -04:00
|
|
|
}
|
|
|
|
return users
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildVmessUser(userInfo *panel.UserInfo, serverAlterID uint16) (user *protocol.User) {
|
2022-07-28 11:00:05 -04:00
|
|
|
vmessAccount := &conf.VMessAccount{
|
|
|
|
ID: userInfo.V2rayUser.Uuid,
|
|
|
|
AlterIds: serverAlterID,
|
|
|
|
Security: "auto",
|
|
|
|
}
|
2022-10-09 20:59:00 -04:00
|
|
|
return &protocol.User{
|
2022-07-28 11:00:05 -04:00
|
|
|
Level: 0,
|
|
|
|
Email: c.buildUserTag(userInfo), // Uid: InboundTag|email|uid
|
|
|
|
Account: serial.ToTypedMessage(vmessAccount.Build()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildVlessUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
2022-08-12 06:02:06 -04:00
|
|
|
users = make([]*protocol.User, len(userInfo))
|
|
|
|
for i := range userInfo {
|
|
|
|
users[i] = c.buildVlessUser(&(userInfo)[i])
|
2022-07-28 11:00:05 -04:00
|
|
|
}
|
|
|
|
return users
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildVlessUser(userInfo *panel.UserInfo) (user *protocol.User) {
|
2022-07-28 11:00:05 -04:00
|
|
|
vlessAccount := &vless.Account{
|
|
|
|
Id: userInfo.V2rayUser.Uuid,
|
|
|
|
Flow: "xtls-rprx-direct",
|
|
|
|
}
|
2022-10-09 20:59:00 -04:00
|
|
|
return &protocol.User{
|
2022-07-28 11:00:05 -04:00
|
|
|
Level: 0,
|
|
|
|
Email: c.buildUserTag(userInfo),
|
|
|
|
Account: serial.ToTypedMessage(vlessAccount),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildTrojanUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
2022-08-12 06:02:06 -04:00
|
|
|
users = make([]*protocol.User, len(userInfo))
|
|
|
|
for i := range userInfo {
|
|
|
|
users[i] = c.buildTrojanUser(&(userInfo)[i])
|
2022-07-28 11:00:05 -04:00
|
|
|
}
|
|
|
|
return users
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildTrojanUser(userInfo *panel.UserInfo) (user *protocol.User) {
|
2022-07-28 11:00:05 -04:00
|
|
|
trojanAccount := &trojan.Account{
|
|
|
|
Password: userInfo.TrojanUser.Password,
|
|
|
|
Flow: "xtls-rprx-direct",
|
|
|
|
}
|
2022-10-09 20:59:00 -04:00
|
|
|
return &protocol.User{
|
2022-07-28 11:00:05 -04:00
|
|
|
Level: 0,
|
|
|
|
Email: c.buildUserTag(userInfo),
|
|
|
|
Account: serial.ToTypedMessage(trojanAccount),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildSSUsers(userInfo []panel.UserInfo, cypher shadowsocks.CipherType) (users []*protocol.User) {
|
2022-08-12 06:02:06 -04:00
|
|
|
users = make([]*protocol.User, len(userInfo))
|
|
|
|
for i := range userInfo {
|
|
|
|
c.buildSSUser(&(userInfo)[i], cypher)
|
2022-07-28 11:00:05 -04:00
|
|
|
}
|
|
|
|
return users
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildSSUser(userInfo *panel.UserInfo, cypher shadowsocks.CipherType) (user *protocol.User) {
|
2022-07-28 11:00:05 -04:00
|
|
|
ssAccount := &shadowsocks.Account{
|
|
|
|
Password: userInfo.Secret,
|
|
|
|
CipherType: cypher,
|
|
|
|
}
|
2022-10-09 20:59:00 -04:00
|
|
|
return &protocol.User{
|
2022-07-28 11:00:05 -04:00
|
|
|
Level: 0,
|
|
|
|
Email: c.buildUserTag(userInfo),
|
|
|
|
Account: serial.ToTypedMessage(ssAccount),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 01:04:33 -04:00
|
|
|
func (c *Node) buildUserTag(user *panel.UserInfo) string {
|
2022-07-28 11:00:05 -04:00
|
|
|
return fmt.Sprintf("%s|%s|%d", c.Tag, user.GetUserEmail(), user.UID)
|
|
|
|
}
|