调整status读取信息逻辑,现在的preview还不可用
This commit is contained in:
+91
-16
@@ -117,14 +117,63 @@ type PortStatus struct {
|
|||||||
|
|
||||||
// FRPCStatus 来自 frpc admin API 的状态响应
|
// FRPCStatus 来自 frpc admin API 的状态响应
|
||||||
type FRPCStatus struct {
|
type FRPCStatus struct {
|
||||||
Version string `json:"version"`
|
TCP []struct {
|
||||||
RunID string `json:"run_id"`
|
Name string `json:"name"`
|
||||||
Proxies []struct {
|
Type string `json:"type"`
|
||||||
Name string `json:"name"`
|
Status string `json:"status"`
|
||||||
Type string `json:"type"`
|
Err string `json:"err"`
|
||||||
Status string `json:"status"`
|
LocalAddr string `json:"local_addr"`
|
||||||
LocalAddr string `json:"local_addr"`
|
RemoteAddr string `json:"remote_addr"`
|
||||||
} `json:"proxies"`
|
} `json:"tcp"`
|
||||||
|
UDP []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
} `json:"udp"`
|
||||||
|
// frp 0.70.0 还支持其他协议类型,可根据需要扩展
|
||||||
|
HTTP []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
} `json:"http"`
|
||||||
|
HTTPS []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
} `json:"https"`
|
||||||
|
STCP []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
} `json:"stcp"`
|
||||||
|
XTCP []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
} `json:"xtcp"`
|
||||||
|
SUDP []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
} `json:"sudp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConflictInfo 冲突检测结果
|
// ConflictInfo 冲突检测结果
|
||||||
@@ -530,7 +579,8 @@ func (pm *ProcessManager) isProcessAlive(pid int) bool {
|
|||||||
// FRPReady 检测(使用 admin API)
|
// FRPReady 检测(使用 admin API)
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|
||||||
// isFRPReady 检测 frpc 是否已完全就绪(通过 admin API)
|
// isFRPReady 检测 frpc 是否已完全就绪
|
||||||
|
// 判定标准:至少有一个代理处于 running 状态
|
||||||
func (pm *ProcessManager) isFRPReady() bool {
|
func (pm *ProcessManager) isFRPReady() bool {
|
||||||
if pm.adminPort <= 0 {
|
if pm.adminPort <= 0 {
|
||||||
log.Printf("[DEBUG] FRPReady=false: admin_port 未配置")
|
log.Printf("[DEBUG] FRPReady=false: admin_port 未配置")
|
||||||
@@ -544,7 +594,7 @@ func (pm *ProcessManager) isFRPReady() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 方式2: admin API 检测(最可靠)
|
// 方式2: admin API 检测
|
||||||
url := fmt.Sprintf("http://127.0.0.1:%d/api/status", pm.adminPort)
|
url := fmt.Sprintf("http://127.0.0.1:%d/api/status", pm.adminPort)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), APITimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), APITimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -566,23 +616,48 @@ func (pm *ProcessManager) isFRPReady() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 JSON 确认返回有效
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[DEBUG] FRPReady=false: 读取响应失败: %v", err)
|
log.Printf("[DEBUG] FRPReady=false: 读取响应失败: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var status FRPCStatus
|
var status FRPCStatus
|
||||||
if err := json.Unmarshal(body, &status); err != nil {
|
if err := json.Unmarshal(body, &status); err != nil {
|
||||||
log.Printf("[DEBUG] FRPReady=false: 解析 JSON 失败: %v", err)
|
log.Printf("[DEBUG] FRPReady=false: 解析 JSON 失败: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if status.Version == "" {
|
|
||||||
log.Printf("[DEBUG] FRPReady=false: admin API 返回空版本")
|
// 检查是否有任何代理处于 running 状态
|
||||||
return false
|
// 遍历所有已知的代理类型
|
||||||
|
proxyLists := [][]struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Err string `json:"err"`
|
||||||
|
LocalAddr string `json:"local_addr"`
|
||||||
|
RemoteAddr string `json:"remote_addr"`
|
||||||
|
}{
|
||||||
|
status.TCP,
|
||||||
|
status.UDP,
|
||||||
|
status.HTTP,
|
||||||
|
status.HTTPS,
|
||||||
|
status.STCP,
|
||||||
|
status.XTCP,
|
||||||
|
status.SUDP,
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] FRPReady=true: admin API 可访问,版本: %s", status.Version)
|
|
||||||
return true
|
for _, proxies := range proxyLists {
|
||||||
|
for _, p := range proxies {
|
||||||
|
if p.Status == "running" {
|
||||||
|
log.Printf("[DEBUG] FRPReady=true: 代理 %s 状态为 running", p.Name)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] FRPReady=false: 没有代理处于 running 状态")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user