隧道管理 API
接口地址:
/proxy请求方式:
POSTContent-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 |
|---|---|---|---|
tcp | TCP 隧道 | 否 | 是 |
udp | UDP 隧道 | 否 | 是 |
http | HTTP 隧道 | 是 | 否 |
https | HTTPS 隧道 | 是 | 否 |
xtcp | P2P TCP(点对点,走密钥) | 否 | 是 |
stcp | P2P 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 用) |
sk | P2P 连接密钥 |
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=1typescript
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) |