6 TELEPORT CORE JSON RPC
Apex Liu edited this page 2018-04-26 10:28:07 +08:00
This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

TELEPORT CORE JSON-RPC

本文详细描述teleport core服务提供的RPC接口。

TELEPORT CORE服务默认在 127.0.0.1:52080 上监听,其访问格式如下:

注意参数部分params是经过urlencode后的json格式的字符串。

GET 方式

  • URL格式 http://127.0.0.1:52080/rpc?params
  • 示例:curl http://127.0.0.1:52080/rpc?{"method":"enc","param":{"p":"a message"}}
  • 实际请求:curl http://127.0.0.1:52080/rpc?%7B%22method%22%3A%22enc%22%2C%22param%22%3A%7B%22p%22%3A%22a%20message%22%7D%7D

POST方式

  • URL格式 http://127.0.0.1:52080/rpc
  • 示例:curl -X POST --data '{"method":"enc","param":{"p":"a message"}}' http://127.0.0.1:52080/rpc
  • 实际请求:curl -X POST --data %7B%22method%22%3A%22enc%22%2C%22param%22%3A%7B%22p%22%3A%22a%20message%22%7D%7D http://127.0.0.1:52080/rpc

所有的返回数据均为json格式其中包含code域指明执行情况,如果有附加返回数据,则包含在data域中。如果发生错误,则code域为非0值并由可选message域指明错误原因。例如:

// 成功返回
{
  "code": 0,
  "data": {
    "sid": "123456abcd"
  }
}

// 失败返回
{
  "code": 4,
  "message": "无法创建指定目录。"
}

JSON-RPC methods

JSON RPC API Reference

get_config

获取core服务的各个协议的配置信息例如是否启用、监听端口号等。

参数

无参数

返回

各个协议的配置信息,参见示例。

示例

// Result
{
  "code": 0,
  "data": {
    "ssh": {
      "enable": true,
      "ip": "0.0.0.0",
      "port": 52189
    },
    "rdp": {
      "enable": false,
      "ip": "0.0.0.0",
      "port": 52089
    }
  }
}

request_session

申请一个会话ID供web服务调用。每当获取一个会话IDweb服务均会将其记录到一个表中备用。

认证ID是由远程主机信息、认证信息等关联映射后生成的一个ID将一个主机授权给一个用户将产生一个认证ID。

参数

  1. authid - 认证ID十进制数字

返回

  1. sid - 一个十六进制字符串形式的会话ID。

示例

// Request
{
  "authid": 12345
}

// Result
{
  "code": 0,
  "data": {
    "sid": "0123abcdef"
  }
}

enc

加密一个字符串,常用于加密远程主机账号的密码或私钥。

参数

  1. p - 被加密的明文p表示plain-text

返回

  1. c - 加密后密文按base64编码形式给出c表示cipher-text

示例

// Request
{
  "p": "my-password"
}

// Result
{
  "code": 0,
  "data": {
    "c": "GHux0lCLMnSYVZYlOloKc86qIwAjfQTQUeev2WpM7Ds="
  }
}

status

获取core服务的工作状态和基本信息。

参数

无参数。

返回

  1. up - 服务已运行时间(秒)
  2. connections - 当前连接数

示例

// Result
{
  "code": 0,
  "data": {
    "up": 138437,
    "connections": 52
  }
}

exit

退出服务。

参数

无参数。

返回

无返回数据。