Skip to content

隧道管理 API ​

接口地址: /proxy

请求方式: POST Content-Type: application/json;charset=UTF-8(forcedown 除外)

API 列表 ​

序号接口type 值需要 CSRF
1添加隧道add是
2编辑隧道edit是
3删除隧道remove是
4列出隧道list是
5获取配置文件config是
6启用 / 禁用隧道toggle是
7检查隧道在线状态check是
8强制下线forcedown是(form 格式)

隧道类型 ​

类型说明是否需要 domain是否需要 remote_port
tcpTCP 隧道否是
udpUDP 隧道否是
httpHTTP 隧道是否
httpsHTTPS 隧道是否
xtcpP2P TCP(点对点,走密钥)否是
stcpP2P STCP(密钥保护,访问方也需配置)否否

1. 添加隧道 ​

type: add

参数必填说明
csrf是CSRF Token
proxy_name是隧道名称
proxy_type是tcp / udp / http / https / xtcp / stcp
local_ip是本地 IP,如 127.0.0.1
local_port是本地端口
remote_port否远程端口(http / https 可不填)
use_encryption否是否加密,"true" / "false"
use_compression否是否压缩,"true" / "false"
sk否连接密钥(P2P / xtcp / stcp 用)
node是节点 ID
domain否域名(http / https 必填)
json
{
  "type": "add",
  "csrf": "Token值",
  "proxy_name": "my-web",
  "proxy_type": "http",
  "local_ip": "127.0.0.1",
  "local_port": 8080,
  "use_encryption": "true",
  "use_compression": "false",
  "node": "1",
  "domain": "example.com"
}

TIP

前端隧道表单支持「随机名称」「随机端口」,随机端口会依据所选节点的端口范围(port_range)生成;节点未配置范围时给出提示。

2. 编辑隧道 ​

type: edit

json
{
  "type": "edit",
  "csrf": "Token值",
  "id": "1",
  "proxy_name": "my-web-updated",
  "proxy_type": "http",
  "local_ip": "127.0.0.1",
  "local_port": 8081,
  "use_encryption": "false",
  "use_compression": "true",
  "node": "1",
  "domain": "example.com"
}

3. 删除隧道 ​

type: remove

json
{ "type": "remove", "csrf": "Token值", "id": "1" }

4. 列出隧道 ​

type: list

json
{ "type": "list", "csrf": "Token值" }

指定单条:

json
{ "type": "list", "csrf": "Token值", "id": "1" }

返回:

json
{
  "status": 200,
  "proxies": [
    {
      "id": "1",
      "proxy_name": "my-web",
      "proxy_type": "http",
      "local_ip": "127.0.0.1",
      "local_port": "8080",
      "remote_port": "",
      "use_encryption": "true",
      "use_compression": "false",
      "domain": "example.com",
      "sk": "",
      "status": "true",
      "node": "1",
      "node_name": "香港节点",
      "node_domain": "hk.example.com",
      "lastupdate": "1700000000"
    }
  ]
}
字段说明
status隧道是否启用("true" / "false")
node_name节点名称(展示用)
node_domain节点域名(生成 serverAddr 用)
skP2P 连接密钥
lastupdate最后更新时间戳

WARNING

不带 id 调用时,后端可能先输出 PHP Warning(Undefined array key "id")再输出 JSON。前端响应拦截器会自动剥离 JSON 前缀后重新解析。

5. 获取配置文件 ​

type: config

参数必填说明
format是ini / toml
csrf是CSRF Token
node否节点 ID(生成整节点配置)
proxy否隧道 ID(生成单隧道配置)
json
{
  "type": "config",
  "format": "toml",
  "csrf": "Token值",
  "proxy": "1"
}

前端「导出配置文件」使用 toml 格式,生成内容形如:

toml
serverAddr = "hk.example.com"
serverPort = 7000

[[proxies]]
name = "my-web"
type = "http"
localIP = "127.0.0.1"
localPort = 8080
customDomains = ["example.com"]

6. 启用 / 禁用隧道 ​

type: toggle

json
{ "type": "toggle", "csrf": "Token值", "id": "1", "toggle": "true" }
json
{ "type": "toggle", "csrf": "Token值", "id": "1", "toggle": "false" }

7. 检查隧道在线状态 ​

type: check

json
{ "type": "check", "csrf": "Token值", "id": "1" }

在线:

json
{ "status": 200, "message": "隧道在线.", "ostatus": "online" }

离线:

json
{ "status": 500, "message": "隧道离线.", "ostatus": "offline" }

前端 api.checkProxyStatus() 已封装,但当前隧道列表页的状态以后端 list 返回的 status 字段为准,未主动调用该接口。

8. 强制下线 ​

type: forcedown

请求格式不同

该接口使用 application/x-www-form-urlencoded,前端通过 new URLSearchParams({ type, csrf, id }) 提交。

type=forcedown&csrf=Token值&id=1
typescript
const res = await inst.post('/proxy', new URLSearchParams({ type: 'forcedown', csrf, id }), {
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})

前端封装 ​

typescript
await api.addProxy(csrf, { proxy_name, proxy_type, local_ip, local_port, node, domain })
await api.editProxy(csrf, id, { proxy_name, local_port })
await api.deleteProxy(csrf, id)
const list = await api.listProxies(csrf)              // 或 api.listProxies(csrf, id)
const config = await api.getProxyConfig(csrf, 'toml', undefined, id)
await api.toggleProxy(csrf, id, true)
const status = await api.checkProxyStatus(csrf, id)
await api.forceDownProxy(csrf, id)

与其他接口的关系 ​

场景接口
导出 / 下载配置文件/proxy type=config
一键启动(不需要下载配置)简单启动 API(/esirun.php)
用 P2P 隧道开联机房间联机大厅 API(/oh.php)

相关页面 ​

基于 MIT 许可证发布