Xray-core/main/commands/all/api/inbound_user.go
yuhan6665 85a1c33709
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
2024-11-03 00:25:23 -04:00

51 lines
1.2 KiB
Go

package api
import (
handlerService "github.com/xtls/xray-core/app/proxyman/command"
"github.com/xtls/xray-core/main/commands/base"
)
var cmdInboundUser = &base.Command{
CustomFlags: true,
UsageLine: "{{.Exec}} api inbounduser [--server=127.0.0.1:8080] -tag=tag [-email=email]",
Short: "Get Inbound User",
Long: `
Get User info from an inbound.
Arguments:
-s, -server
The API server address. Default 127.0.0.1:8080
-t, -timeout
Timeout seconds to call API. Default 3
-tag
Inbound tag
-email
User email. If email is not given, will get all users
Example:
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name" -email="xray@love.com"
`,
Run: executeInboundUser,
}
func executeInboundUser(cmd *base.Command, args []string) {
setSharedFlags(cmd)
var tag string
var email string
cmd.Flag.StringVar(&tag, "tag", "", "")
cmd.Flag.StringVar(&email, "email", "", "")
cmd.Flag.Parse(args)
conn, ctx, close := dialAPIServer()
defer close()
client := handlerService.NewHandlerServiceClient(conn)
r := &handlerService.GetInboundUserRequest{
Tag: tag,
Email: email,
}
resp, err := client.GetInboundUsers(ctx, r)
if err != nil {
base.Fatalf("failed to get inbound user: %s", err)
}
showJSONResponse(resp)
}