Example #1
0
def add_user(uuid,
             email,
             security_type=SECURITY_TYPE_LEGACY,
             level=0,
             alter_id=32):
    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._ADDUSEROPERATION.full_name,
                value=command_pb2.AddUserOperation(user=user_pb2.User(
                    level=level,
                    email=email,
                    account=typed_message_pb2.TypedMessage(
                        type=account_pb2._ACCOUNT.full_name,
                        value=account_pb2.Account(
                            id=uuid,
                            alter_id=alter_id,
                            security_settings=headers_pb2.SecurityConfig(
                                type=security_type)).SerializeToString()))
                                                   ).SerializeToString())))
    print(resp)
Example #2
0
 def add_user(self, inbound_tag, user_id, email, level=0, alter_id=16):
     """
     在一个传入连接中添加一个用户(仅支持 VMess)
     若email已存在,抛出EmailExistsError异常
     若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.AddUserOperation(user=user_pb2.User(
                         email=email,
                         level=level,
                         account=to_typed_message(
                             account_pb2.Account(id=user_id,
                                                 alter_id=alter_id)))))))
         return user_id
     except _Rendezvous as e:
         details = e.details()
         if details.endswith(f"User {email} already exists."):
             raise EmailExistsError(details, email)
         elif details.endswith(f"handler not found: {inbound_tag}"):
             raise InboundNotFoundError(details, inbound_tag)
         else:
             raise V2RayError(details)
Example #3
0
 def add_inbound(self, tag, address, port, proxy: Proxy):
     """
     增加传入连接
     :param tag: 此传入连接的标识
     :param address: 监听地址
     :param port: 监听端口
     :param proxy: 代理配置
     """
     stub = command_pb2_grpc.HandlerServiceStub(self._channel)
     try:
         stub.AddInbound(
             command_pb2.AddInboundRequest(
                 inbound=core_config_pb2.InboundHandlerConfig(
                     tag=tag,
                     receiver_settings=to_typed_message(
                         proxyman_config_pb2.ReceiverConfig(
                             port_range=port_pb2.PortRange(
                                 From=port,
                                 To=port,
                             ),
                             listen=address_pb2.IPOrDomain(
                                 ip=ip2bytes(address),  # 4字节或16字节
                             ),
                             allocation_strategy=None,
                             stream_settings=None,
                             receive_original_destination=None,
                             domain_override=None,
                             sniffing_settings=None)),
                     proxy_settings=proxy.message)))
     except _InactiveRpcError as e:
         details = e.details()
         if details.endswith("address already in use"):
             raise AddressAlreadyInUseError(details, port)
         else:
             raise V2RayError(details)
Example #4
0
 def remove_inbound(self, tag):
     """删除传入连接"""
     stub = command_pb2_grpc.HandlerServiceStub(self._channel)
     try:
         stub.RemoveInbound(command_pb2.RemoveInboundRequest(tag=tag))
     except _Rendezvous as e:
         details = e.details()
         if details == 'not enough information for making a decision':
             raise InboundNotFoundError(details, tag)
         else:
             raise V2RayError(details)
Example #5
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)
Example #6
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)
Example #7
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)