mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
API: Add new Get Inbound User (#3644)
* Add GetInboundUser in proto * Add get user logic for all existing inbounds * Add inbounduser command * Add option to get all users * Fix shadowsocks2022 config * Fix init users in shadowsocks2022 * Fix copy * Add inbound user count command This api costs much less than get inbound user, could be useful in some case * Update from latest main
This commit is contained in:
parent
b7aacd3245
commit
85a1c33709
30 changed files with 982 additions and 293 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/features/inbound"
|
||||
"github.com/xtls/xray-core/features/outbound"
|
||||
|
@ -98,6 +99,46 @@ func (s *handlerServer) AlterInbound(ctx context.Context, request *AlterInboundR
|
|||
return &AlterInboundResponse{}, operation.ApplyInbound(ctx, handler)
|
||||
}
|
||||
|
||||
func (s *handlerServer) GetInboundUsers(ctx context.Context, request *GetInboundUserRequest) (*GetInboundUserResponse, error) {
|
||||
handler, err := s.ihm.GetHandler(ctx, request.Tag)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to get handler: ", request.Tag).Base(err)
|
||||
}
|
||||
p, err := getInbound(handler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
um, ok := p.(proxy.UserManager)
|
||||
if !ok {
|
||||
return nil, errors.New("proxy is not a UserManager")
|
||||
}
|
||||
if len(request.Email) > 0 {
|
||||
return &GetInboundUserResponse{Users: []*protocol.User{protocol.ToProtoUser(um.GetUser(ctx, request.Email))}}, nil
|
||||
}
|
||||
var result = make([]*protocol.User, 0, 100)
|
||||
users := um.GetUsers(ctx)
|
||||
for _, u := range users {
|
||||
result = append(result, protocol.ToProtoUser(u))
|
||||
}
|
||||
return &GetInboundUserResponse{Users: result}, nil
|
||||
}
|
||||
|
||||
func (s *handlerServer) GetInboundUsersCount(ctx context.Context, request *GetInboundUserRequest) (*GetInboundUsersCountResponse, error) {
|
||||
handler, err := s.ihm.GetHandler(ctx, request.Tag)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to get handler: ", request.Tag).Base(err)
|
||||
}
|
||||
p, err := getInbound(handler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
um, ok := p.(proxy.UserManager)
|
||||
if !ok {
|
||||
return nil, errors.New("proxy is not a UserManager")
|
||||
}
|
||||
return &GetInboundUsersCountResponse{Count: um.GetUsersCount(ctx)}, nil
|
||||
}
|
||||
|
||||
func (s *handlerServer) AddOutbound(ctx context.Context, request *AddOutboundRequest) (*AddOutboundResponse, error) {
|
||||
if err := core.AddOutboundHandler(s.s, request.Outbound); err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue