fix user tag

This commit is contained in:
yuzuki999 2023-06-19 10:31:42 +08:00
parent adf5c60c2a
commit 95a141ef59
9 changed files with 16 additions and 38 deletions

View File

@ -41,11 +41,6 @@ type ShadowsocksNodeRsp struct {
ServerKey string `json:"server_key"` ServerKey string `json:"server_key"`
} }
type TrojanNodeRsp struct {
Host string `json:"host"`
ServerName string `json:"server_name"`
}
type HysteriaNodeRsp struct { type HysteriaNodeRsp struct {
UpMbps int `json:"up_mbps"` UpMbps int `json:"up_mbps"`
DownMbps int `json:"down_mbps"` DownMbps int `json:"down_mbps"`
@ -131,11 +126,6 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
node.ServerKey = rsp.ServerKey node.ServerKey = rsp.ServerKey
node.Cipher = rsp.Cipher node.Cipher = rsp.Cipher
case "trojan": case "trojan":
rsp := TrojanNodeRsp{}
err = json.Unmarshal(r.Body(), &rsp)
if err != nil {
return nil, fmt.Errorf("decode v2ray params error: %s", err)
}
case "hysteria": case "hysteria":
rsp := HysteriaNodeRsp{} rsp := HysteriaNodeRsp{}
err = json.Unmarshal(r.Body(), &rsp) err = json.Unmarshal(r.Body(), &rsp)

View File

@ -93,7 +93,7 @@ func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey
} }
return &protocol.User{ return &protocol.User{
Level: 0, Level: 0,
Email: tag, Email: BuildUserTag(tag, userInfo.Uuid),
Account: serial.ToTypedMessage(ssAccount), Account: serial.ToTypedMessage(ssAccount),
} }
} else { } else {

View File

@ -3,6 +3,7 @@ package hy
import ( import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/core" "github.com/Yuzuki616/V2bX/core"
) )
@ -30,15 +31,15 @@ func (h *Hy) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
return return
} }
func (h *Hy) DelUsers(users []string, tag string) error { func (h *Hy) DelUsers(users []panel.UserInfo, tag string) error {
v, e := h.servers.Load(tag) v, e := h.servers.Load(tag)
if !e { if !e {
return errors.New("the node is not have") return errors.New("the node is not have")
} }
s := v.(*Server) s := v.(*Server)
for i := range users { for i := range users {
s.users.Delete(users[i]) s.users.Delete(users[i].Uuid)
s.counter.Delete(users[i]) s.counter.Delete(base64.StdEncoding.EncodeToString([]byte(users[i].Uuid)))
} }
return nil return nil
} }

View File

@ -18,6 +18,6 @@ type Core interface {
DelNode(tag string) error DelNode(tag string) error
AddUsers(p *AddUsersParams) (added int, err error) AddUsers(p *AddUsersParams) (added int, err error)
GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
DelUsers(users []string, tag string) error DelUsers(users []panel.UserInfo, tag string) error
Protocols() []string Protocols() []string
} }

View File

@ -81,7 +81,7 @@ func (s *Selector) GetUserTraffic(tag, uuid string, reset bool) (up int64, down
return s.cores[t.(int)].GetUserTraffic(tag, uuid, reset) return s.cores[t.(int)].GetUserTraffic(tag, uuid, reset)
} }
func (s *Selector) DelUsers(users []string, tag string) error { func (s *Selector) DelUsers(users []panel.UserInfo, tag string) error {
t, e := s.nodes.Load(tag) t, e := s.nodes.Load(tag)
if !e { if !e {
return errors.New("the node is not have") return errors.New("the node is not have")

View File

@ -3,6 +3,7 @@ package xray
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/common/builder" "github.com/Yuzuki616/V2bX/common/builder"
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"
@ -25,13 +26,13 @@ func (c *Core) GetUserManager(tag string) (proxy.UserManager, error) {
return userManager, nil return userManager, nil
} }
func (c *Core) DelUsers(users []string, tag string) error { func (c *Core) DelUsers(users []panel.UserInfo, tag string) error {
userManager, err := c.GetUserManager(tag) userManager, err := c.GetUserManager(tag)
if err != nil { if err != nil {
return fmt.Errorf("get user manager error: %s", err) return fmt.Errorf("get user manager error: %s", err)
} }
for _, email := range users { for i := range users {
err = userManager.RemoveUser(context.Background(), email) err = userManager.RemoveUser(context.Background(), builder.BuildUserTag(tag, users[i].Uuid))
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,8 +1,8 @@
package limiter package limiter
import ( import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel" "github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/common/builder"
"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(fmt.Sprintf("%s|%s|%d", tag, userInfo.Uuid, userInfo.Id), userLimit) l.UserLimitInfo.Store(builder.BuildUserTag(tag, userInfo.Uuid), userLimit)
return nil return nil
} }

View File

@ -85,10 +85,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(fmt.Sprintf("%s|%s|%d", l.UserLimitInfo.Delete(builder.BuildUserTag(tag, deleted[i].Uuid))
tag,
deleted[i].Uuid,
deleted[i].Id))
} }
for i := range added { for i := range added {
if added[i].SpeedLimit != 0 { if added[i].SpeedLimit != 0 {
@ -97,10 +94,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(fmt.Sprintf("%s|%s|%d", l.UserLimitInfo.Store(builder.BuildUserTag(tag, added[i].Uuid), userLimit)
tag,
added[i].Uuid,
added[i].Id), userLimit)
} }
} }
return nil return nil

View File

@ -1,7 +1,6 @@
package node package node
import ( import (
"fmt"
"github.com/Yuzuki616/V2bX/common/task" "github.com/Yuzuki616/V2bX/common/task"
vCore "github.com/Yuzuki616/V2bX/core" vCore "github.com/Yuzuki616/V2bX/core"
"github.com/Yuzuki616/V2bX/limiter" "github.com/Yuzuki616/V2bX/limiter"
@ -116,14 +115,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
deleted, added := compareUserList(c.userList, newUserInfo) deleted, added := compareUserList(c.userList, newUserInfo)
if len(deleted) > 0 { if len(deleted) > 0 {
// have deleted users // have deleted users
deletedEmail := make([]string, len(deleted)) err = c.server.DelUsers(deleted, c.Tag)
for i := range deleted {
deletedEmail[i] = fmt.Sprintf("%s|%s|%d",
c.Tag,
(deleted)[i].Uuid,
(deleted)[i].Id)
}
err = c.server.DelUsers(deletedEmail, c.Tag)
if err != nil { if err != nil {
log.Printf("[%s] Del users error: %s", c.Tag, err) log.Printf("[%s] Del users error: %s", c.Tag, err)
} }