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
|
@ -21,6 +21,8 @@ var CmdAPI = &base.Command{
|
|||
cmdAddOutbounds,
|
||||
cmdRemoveInbounds,
|
||||
cmdRemoveOutbounds,
|
||||
cmdInboundUser,
|
||||
cmdInboundUserCount,
|
||||
cmdAddRules,
|
||||
cmdRemoveRules,
|
||||
cmdSourceIpBlock,
|
||||
|
|
50
main/commands/all/api/inbound_user.go
Normal file
50
main/commands/all/api/inbound_user.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
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)
|
||||
}
|
45
main/commands/all/api/inbound_user_count.go
Normal file
45
main/commands/all/api/inbound_user_count.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
handlerService "github.com/xtls/xray-core/app/proxyman/command"
|
||||
"github.com/xtls/xray-core/main/commands/base"
|
||||
)
|
||||
|
||||
var cmdInboundUserCount = &base.Command{
|
||||
CustomFlags: true,
|
||||
UsageLine: "{{.Exec}} api inboundusercount [--server=127.0.0.1:8080] -tag=tag",
|
||||
Short: "Get Inbound User Count",
|
||||
Long: `
|
||||
Get User count 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
|
||||
Example:
|
||||
{{.Exec}} {{.LongName}} --server=127.0.0.1:8080 -tag="tag name"
|
||||
`,
|
||||
Run: executeInboundUserCount,
|
||||
}
|
||||
|
||||
func executeInboundUserCount(cmd *base.Command, args []string) {
|
||||
setSharedFlags(cmd)
|
||||
var tag string
|
||||
cmd.Flag.StringVar(&tag, "tag", "", "")
|
||||
cmd.Flag.Parse(args)
|
||||
|
||||
conn, ctx, close := dialAPIServer()
|
||||
defer close()
|
||||
|
||||
client := handlerService.NewHandlerServiceClient(conn)
|
||||
r := &handlerService.GetInboundUserRequest{
|
||||
Tag: tag,
|
||||
}
|
||||
resp, err := client.GetInboundUsersCount(ctx, r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to get inbound user count: %s", err)
|
||||
}
|
||||
showJSONResponse(resp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue