服务端代答主机指标与公网 IP 检测
mihomo 的管理接口只报自己的内存,CPU、主机内存、网关、内网地址只有 跑在同一台机器上的 Patchbay 服务端答得出,所以加 /api/host 由它代答。 /api/host/exit 把本机某个入站端口设成代理去访问 ip.sb——浏览器发不出 「经由某个端口」的请求,这条只能走服务端。
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
import listenerFields from '../shared/listener-fields.json' with { type: 'json' }
|
||||
import { applyConfig, listBackups, readConfig, restoreBackup } from './config-store.ts'
|
||||
import { hostInfo, probeExit } from './host.ts'
|
||||
import { kernelVersion, proxyGet, proxyWrite, selectProxy } from './kernel.ts'
|
||||
import { tokenFromRequest, tokenMatches } from './auth.ts'
|
||||
import type { ConfigObject } from '../vendor/config-editor/index.ts'
|
||||
@@ -180,6 +181,21 @@ function makeRoute(env: Env, token: string) {
|
||||
return result.ok ? json(result) : json(result, applyFailureStatus(result.stage))
|
||||
}
|
||||
|
||||
// ── 主机 ────────────────────────────────────────────
|
||||
// 服务端和内核在同一台机器上,所以主机指标由 Patchbay 自己代答
|
||||
if (path === '/api/host' && req.method === 'GET') {
|
||||
return json(await hostInfo())
|
||||
}
|
||||
|
||||
// 经由某个入站端口探测公网 IP。GET 但会发起真实的外网请求,和延迟测试同一类
|
||||
if (path === '/api/host/exit' && req.method === 'GET') {
|
||||
const port = Number(url.searchParams.get('port'))
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
||||
return json({ message: 'port 参数必须是 1-65535 的端口号' }, 400)
|
||||
}
|
||||
return json(await probeExit(port))
|
||||
}
|
||||
|
||||
// ── 内核 ────────────────────────────────────────────
|
||||
if (path === '/api/kernel' && req.method === 'GET') {
|
||||
return json(await kernelVersion(env))
|
||||
|
||||
Reference in New Issue
Block a user