Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC APIs for list of inbounds and users #2745

Open
miladrahimi opened this issue Nov 20, 2023 · 14 comments
Open

gRPC APIs for list of inbounds and users #2745

miladrahimi opened this issue Nov 20, 2023 · 14 comments
Labels
enhancement New feature or request

Comments

@miladrahimi
Copy link

miladrahimi commented Nov 20, 2023

There are gRPC APIs for adding, altering, and removing inbounds, outbounds, and users but I couldn't find any API for fetching the lists of defined inbounds, outbounds, or users, how can I fetch them?

@amir-devman
Copy link

amir-devman commented Nov 21, 2023

There are gRPC APIs for adding, altering, and removing inbounds, outbounds, and users but I couldn't find any API for fetching the lists of defined inbounds, outbounds, or users, how can I fetch them?

You can use protoc and grpc plugin on your desired language to auto generate Protobuffers with any language for example for PHP the command to generate proto buffs will be something like this

protoc \
  --proto_path=xray/proto \ # proto files path - can be xray-core repo path cloned
  --php_out=xray \
  --grpc_out=./xray \
  --plugin=protoc-gen-grpc=./grpc/cmake/build/grpc_php_plugin \ # path to grpc php plugin
  xray/proto/HandlerService.proto \ # some .proto files
  xray/proto/proxy/vless/inbound/config.proto \ # .proto files

You need to have GRPC compiled, then it'll generate php files regarding to protobufs

Final code use will be something like this

$grpcOptions = [
   'credentials' => ChannelCredentials::createInsecure()
];

$client = new HandlerServiceClient("{$server->ipv4}:{$server->port}", $grpcOptions);
$client->waitForReady(5 * 1000 * 1000); // microseconds

return $client->RemoveInbound(new RemoveInboundRequest([
  'tag' => 'vless-tcp'
]), [], [
  'timeout' => 5 * 1000 * 1000 // microseconds
]);

Take a look at these:
https://github.com/grpc/grpc/blob/master/BUILDING.md
https://protobuf.dev/reference/go/go-generated/

@miladrahimi
Copy link
Author

Thanks @amir-devman, I am familiar with gRPC, but there isn't an API available to retrieve a list of defined inbounds/outbounds/users. I'm looking for a method to access this specific list.

@amir-devman
Copy link

amir-devman commented Nov 21, 2023

Thanks @amir-devman, I am familiar with gRPC, but there isn't an API available to retrieve a list of defined inbounds/outbounds/users. I'm looking for a method to access this specific list.

HandlerService is all you need to look for inbound/outbound management
you can add or remove outbounds or add/remove users from an inbound with HandlerService.proto

service HandlerService {

As I've looked into xray-core source code I've only found this helpful for managing inbounds/outbounds/users

Only thing you can find on Project X document is ReflectionService API that only mentions what services are available which
one of them is HandlerService which you need.

I hope this helps.

@amir-devman
Copy link

@miladrahimi There's also another document with examples(golang):

https://github.com/XTLS/Xray-API-documents

@miladrahimi
Copy link
Author

I was hoping for a method or API, perhaps named listInbounds, that would allow me to view the inbounds already added. Unfortunately, such a feature seems to be missing. Nevertheless, I believe that there must be some alternative method.

@miladrahimi
Copy link
Author

@Fangliding Since there is no "List of inbounds" implemented in the Xray gRPC, I think it's not completed yet.

@Fangliding
Copy link
Member

@miladrahimi
Sorry, my fault

@Fangliding Fangliding closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2024
@yuhan6665
Copy link
Member

This is an important feature. Planning..

@yuhan6665 yuhan6665 reopened this Apr 14, 2024
@yuhan6665 yuhan6665 added the enhancement New feature or request label Apr 14, 2024
@egasvegas1109
Copy link

After all, how do I add clients to VLESS incoming connections? Use the HandlerService from this file

service HandlerService {
? And use the AlterInbound() method?

@yuhan6665
Copy link
Member

@mr1cloud
Copy link
Contributor

mr1cloud commented Feb 3, 2025

@miladrahimi Did I understand correctly that you are interested in implementing grpc functions that will allow you to view lists of defined inbounds, outbounds, or users?

@miladrahimi
Copy link
Author

@mr1cloud Yes, I believe there should be CRUD (Create, Read, Update, Delete) APIs for inbounds, outbounds, and users. This way, Xray panels won't need to interact with the Xray process (binary) to manage these entities. gRPC endpoints would be the ideal approach.

@iambabyninja
Copy link
Member

At the moment, we have a so-called central panel and a bunch of servers (nodes) running instances of Xray.

When launching the panel, we generate a configuration file based on the database and pass it to the node’s std.

After that, we perform basic CRUD operations via the API.
To execute these operations, we need to know the list of inbounds in advance.

For example, on the frontend, when assigning new inbounds to a user, I need to completely remove the old inbounds first. This means I have to find them somewhere before sending a request to add new ones.

It would be much more convenient to handle this almost directly within the core. That is, I could request all available inbounds from the core (getting a list of tags), then send a request to remove the user for each tag, and finally, send a request to add the user for the required tags.
Therefore, we spent a long time looking for endpoints of this type.

As a result, the possible solutions to the problem described above are:
1. A listAllInbounds method (retrieving all current inbounds from XRay Core).
2. A method to remove a user from all inbounds using only the user’s email.

@mr1cloud
Copy link
Contributor

@iambabyninja I am currently working on these issues, but due to the large number of tasks, this process will take longer than necessary. Stay tuned for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants