Skip to content

Conversation

vrnobody
Copy link
Contributor

@vrnobody vrnobody commented Jul 26, 2025

这个 PR 添加 adu 和 rmu 两个管理 inbound 用户的命令行 API。支持 vless, vmess, trojan, ss 四种协议。
主要给个人使用,机场有自己的面板应该不需要这个功能。

$ ./xray help api adu
usage: xray api adu [--server=127.0.0.1:8080] <c1.json> [c2.json]...

Add users to inbounds.
Arguments:
        -s, -server
                The API server address. Default 127.0.0.1:8080
        -t, -timeout
                Timeout seconds to call API. Default 3
Example:
    xray api adu --server=127.0.0.1:8080  c1.json c2.json
$ ./xray help api rmu
usage: xray api rmu [--server=127.0.0.1:8080] -tag=tag <email1> [email2]...

Remove users from inbounds.
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:
    xray api rmu --server=127.0.0.1:8080 -tag="vless-in" "xray@love.com" ...
详细用法示例:

config.json

{
    "api": {
        "tag": "api",
        "listen": "127.0.0.1:2025",
        "services": [
            "HandlerService"
        ]
    },
    "inbounds": [
        {
            "tag": "serv",
            "protocol": "vless",
            "listen": "127.0.0.1",
            "port": 2000,
            "settings": {
                "decryption": "none",
                "clients": [
                    {
                        "email": "user1@xray.com",
                        "id": "74641c58-9e0b-41d4-8a24-78c48c54152f"
                    }
                ]
            }
        }
    ]
}

user2.json

{
    "inbounds": [
        {
            "tag": "serv",
            "protocol": "vless",
            "listen": "127.0.0.1",
            "port": 2000,
            "settings": {
                "decryption": "none",
                "clients": [
                    {
                        "email": "user2@xray.com",
                        "id": "64bf49d6-4179-47fc-8e08-d8f5d8d0dd47"
                    }
                ]
            }
        }
    ]
}

首次添加用户2

$ ./xray api adu -s 127.0.0.1:2025 user2.json
processing inbound: serv
add user: user2@xray.com
result: ok
Added 1 user(s) in total.

再次添加用户2

$ cat user2.json | ./xray api adu -s 127.0.0.1:2025 stdin:
processing inbound: serv
add user: user2@xray.com
rpc error: code = Unknown desc = proxy/vless: User user2@xray.com already exists.
Added 0 user(s) in total.

查询当前用户

$ ./xray api inbounduser -s 127.0.0.1:2025 -tag "serv"
{
    "users": [
        {
            "account": {
                "_TypedMessage_": "xray.proxy.vless.Account",
                "id": "74641c58-9e0b-41d4-8a24-78c48c54152f"
            },
            "email": "user1@xray.com"
        },
        {
            "account": {
                "_TypedMessage_": "xray.proxy.vless.Account",
                "id": "64bf49d6-4179-47fc-8e08-d8f5d8d0dd47"
            },
            "email": "user2@xray.com"
        }
    ]
}

删除用户2

$ ./xray api rmu -s 127.0.0.1:2025 -tag="serv" "user2@xray.com"
remove user: user2@xray.com
Removed 1 user(s) in total.

再次查询

$ ./xray api inbounduser -s 127.0.0.1:2025 -tag "serv"
{
    "users": [
        {
            "account": {
                "_TypedMessage_": "xray.proxy.vless.Account",
                "id": "74641c58-9e0b-41d4-8a24-78c48c54152f"
            },
            "email": "user1@xray.com"
        }
    ]
}

@RPRX
Copy link
Member

RPRX commented Jul 26, 2025

除了 ECH 外的新功能放以后的版本吧

@RPRX
Copy link
Member

RPRX commented Jul 26, 2025

但我又觉得这代码没影响其它代码,可以合,有要改的地方以后的版本可以再改

@vrnobody 可以合了吗

@RPRX RPRX changed the title Command: Add adu/rmu inbound user management API commands. Commands: Add adu/rmu inbound user management to API Jul 26, 2025
@RPRX RPRX merged commit 3fe02a6 into XTLS:main Jul 26, 2025
39 checks passed
maoxikun pushed a commit to maoxikun/Xray-core that referenced this pull request Aug 23, 2025
Co-authored-by: nobody <nobody@nowhere.mars>
(cherry picked from commit 3fe02a6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants