Пример #1
0
def remove_user(uuid, email):
    channel = grpc.insecure_channel('%s:%s' % (SERVER_ADDRESS, SERVER_PORT))
    stub = command_pb2_grpc.HandlerServiceStub(channel)

    resp = stub.AlterInbound(
        command_pb2.AlterInboundRequest(
            tag=INBOUND_TAG,
            operation=typed_message_pb2.TypedMessage(
                type=command_pb2._REMOVEUSEROPERATION.full_name,
                value=command_pb2.RemoveUserOperation(
                    email=email).SerializeToString())))
    print(resp)
Пример #2
0
def add_inbound(tag):
    channel = grpc.insecure_channel('%s:%s' % (SERVER_ADDRESS, SERVER_PORT))
    stub = command_pb2_grpc.HandlerServiceStub(channel)

    resp = stub.AddInbound(
        command_pb2.AlterInboundRequest(
            inbound=config_pb2.InboundHandlerConfig(
                tag=tag,
                receiver_settings=typed_message_pb2.TypedMessage(
                    type=proxy_config_pb2._RECEIVERCONFIG.full_name,
                    value=proxy_config_pb2.ReceiverConfig(
                        port_range=port_pb2.PortRange(From=30, To=20),
                        listen=None,
                        allocation_strategy=None,
                        stream_settings=None,
                        receive_original_destination=None,
                        domain_override=None).SerializeToString()),
                proxy_settings=typed_message_pb2.TypedMessage(
                    type=command_pb2._ADDUSEROPERATION.full_name,
                    value=command_pb2.RemoveUserOperation(
                        email=email).SerializeToString()),
            )))
    print(resp)
Пример #3
0
 def remove_user(self, inbound_tag, email):
     """
     在一个传入连接中删除一个用户(仅支持 VMess)
     需几分钟生效,因为仅仅是把用户从用户列表中移除,没有移除对应的auth session,
     需要等这些session超时后,这个用户才会无法认证
     若email不存在,抛出EmailNotFoundError异常
     若inbound_tag不存在,抛出InboundNotFoundError异常
     """
     stub = command_pb2_grpc.HandlerServiceStub(self._channel)
     try:
         stub.AlterInbound(
             command_pb2.AlterInboundRequest(
                 tag=inbound_tag,
                 operation=to_typed_message(
                     command_pb2.RemoveUserOperation(email=email))))
     except _Rendezvous as e:
         details = e.details()
         if details.endswith(f"User {email} not found."):
             raise EmailNotFoundError(details, email)
         elif details.endswith(f"handler not found: {inbound_tag}"):
             raise InboundNotFoundError(details, inbound_tag)
         else:
             raise V2RayError(details)