Fix25.1: стабилизирован auth_id flow и unlimited-семантика, усилен bootstrap secrets

This commit is contained in:
2026-05-09 00:45:20 +05:00
parent d73bab99ec
commit 7a64d76d08
4 changed files with 83 additions and 26 deletions
+16 -14
View File
@@ -83,10 +83,7 @@ func saveAccountTraffic(apiPort int64, trafficStatsSecret string) {
peer, peerErr := dao.GetPeer("auth_id = ?", key)
if peerErr != nil {
peer, peerErr = dao.GetPeer("name = ?", key)
if peerErr != nil {
continue
}
continue
}
if peer.Id == nil {
continue
@@ -133,32 +130,37 @@ func kickAccount(apiPort int64, trafficStatsSecret string) {
}
if len(users) > 0 {
i := 0
usernames := make([]string, len(users))
authIDs := make([]string, len(users))
for k := range users {
usernames[i] = k
authIDs[i] = k
i++
}
usernameLists := util.SplitArr(usernames, 10)
authIDLists := util.SplitArr(authIDs, 10)
var wg sync.WaitGroup
for _, usernameList := range usernameLists {
for _, authIDList := range authIDLists {
wg.Add(1)
go func(usernameList []string) {
go func(authIDList []string) {
defer wg.Done()
now := time.Now().UnixMilli()
peers, err := dao.ListPeer("name in ? and (disabled = 1 or (quota_bytes > 0 and quota_bytes < download_bytes + upload_bytes) or ? > expires_at or ? < banned_until)", usernameList, now, now)
peers, err := dao.ListPeer(`auth_id in ? and (
disabled = 1
or (quota_bytes > 0 and quota_bytes < download_bytes + upload_bytes)
or (expires_at > 0 and ? > expires_at)
or ? < banned_until
)`, authIDList, now, now)
if err != nil {
return
}
kickUsernames := make([]string, len(peers))
kickAuthIDs := make([]string, len(peers))
j := 0
for _, item := range peers {
kickUsernames[j] = *item.Name
kickAuthIDs[j] = *item.AuthId
j++
}
if err = proxy.NewHysteria2Api(apiPort).KickUsers(kickUsernames, trafficStatsSecret); err != nil {
if err = proxy.NewHysteria2Api(apiPort).KickUsers(kickAuthIDs, trafficStatsSecret); err != nil {
return
}
}(usernameList)
}(authIDList)
}
wg.Wait()
}
+12 -6
View File
@@ -5,7 +5,6 @@ import (
"hy2xs-admin/dao"
"hy2xs-admin/model/constant"
"hy2xs-admin/proxy"
"hy2xs-admin/util"
"net"
"net/url"
"os"
@@ -36,8 +35,15 @@ func Hysteria2Auth(conPass string) (int64, string, error) {
}
now := time.Now().UnixMilli()
secretDigest := util.PeerSecretDigest(conPass)
peer, err := dao.GetPeer("secret_digest = ? and disabled = 0 and (quota_bytes < 0 or quota_bytes > download_bytes + upload_bytes) and ? < expires_at and ? > banned_until", secretDigest, now, now)
secretDigest, digestErr := PeerSecretDigest(conPass)
if digestErr != nil {
return 0, "", digestErr
}
peer, err := dao.GetPeer(`secret_digest = ?
and disabled = 0
and (quota_bytes < 0 or quota_bytes > download_bytes + upload_bytes)
and (expires_at = 0 or ? < expires_at)
and ? > banned_until`, secretDigest, now, now)
if err != nil {
return 0, "", err
}
@@ -47,12 +53,12 @@ func Hysteria2Auth(conPass string) (int64, string, error) {
if err != nil {
return 0, "", err
}
device, exist := onlineUsers[*peer.Name]
device, exist := onlineUsers[*peer.AuthId]
if exist && *peer.MaxDevices <= device {
return 0, "", errors.New("device limited")
}
return *peer.Id, *peer.Name, nil
return *peer.Id, *peer.AuthId, nil
}
func Hysteria2Online() (map[string]int64, error) {
@@ -88,7 +94,7 @@ func Hysteria2Kick(ids []int64, kickUtilTime int64) error {
}
var keys []string
for _, item := range peers {
keys = append(keys, *item.Name)
keys = append(keys, *item.AuthId)
}
apiPort, err := GetHysteria2ApiPort()
if err != nil {