Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

gRPC APIs for list of inbounds and users

Open miladrahimi opened this issue 2 years ago • 14 comments

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?

miladrahimi avatar Nov 20 '23 09:11 miladrahimi

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/

amir-devman avatar Nov 21 '23 16:11 amir-devman

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.

miladrahimi avatar Nov 21 '23 20:11 miladrahimi

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 https://github.com/XTLS/Xray-core/blob/2570855cd780e34893ad31d8d5ff2338a396005a/app/proxyman/command/command.proto#L59

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 avatar Nov 21 '23 20:11 amir-devman

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

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

amir-devman avatar Nov 21 '23 20:11 amir-devman

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 avatar Nov 22 '23 09:11 miladrahimi

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

miladrahimi avatar Apr 14 '24 18:04 miladrahimi

@miladrahimi Sorry, my fault

Fangliding avatar Apr 14 '24 18:04 Fangliding

This is an important feature. Planning..

yuhan6665 avatar Apr 14 '24 20:04 yuhan6665

After all, how do I add clients to VLESS incoming connections? Use the HandlerService from this file https://github.com/XTLS/Xray-core/blob/2570855cd780e34893ad31d8d5ff2338a396005a/app/proxyman/command/command.proto#L59? And use the AlterInbound() method?

egasvegas1109 avatar Jul 29 '24 15:07 egasvegas1109

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

yuhan6665 avatar Jul 29 '24 15:07 yuhan6665