-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathapp_proxy.go
More file actions
58 lines (53 loc) · 1.73 KB
/
Copy pathapp_proxy.go
File metadata and controls
58 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"strings"
"time"
)
// app_proxy.go ── 上游代理状态查询(Wails binding 薄壳)。
//
// 实际解析 / 应用走 backend/services/transport_pool.go;
// 这里只把 TransportPool 的状态映射成前端 schema 暴露。
// 用户在 Dashboard 看一眼就知道当前请求走 clash / 系统代理 / 直连,
// 不用翻日志去猜「为啥我开了 clash 但请求还在被风控」。
// UpstreamProxyStatus 给前端展示当前上游代理出口。
type UpstreamProxyStatus struct {
// Source 取自 services.ProxySource:
// "direct" / "manual" / "clash+nodes" / "clash" / "env" / "unknown"
Source string `json:"source"`
// URL 已 redact 掉 userinfo (http://user:pass@host:port → http://***@host:port)。
// 空字符串 / "<direct>" 表示直连。
URL string `json:"url"`
// LastAppliedAt 上次成功 Refresh 的时间(RFC3339); zero = 还没探活过。
LastAppliedAt string `json:"last_applied_at"`
}
// GetUpstreamProxyStatus 返回 transportPool 的当前状态。
func (a *App) GetUpstreamProxyStatus() UpstreamProxyStatus {
if a.transportPool == nil {
return UpstreamProxyStatus{Source: "unknown"}
}
src := string(a.transportPool.Source())
if src == "" {
src = "unknown"
}
at := ""
if t := a.transportPool.ResolvedAt(); !t.IsZero() {
at = t.Format(time.RFC3339)
}
return UpstreamProxyStatus{
Source: src,
URL: redactProxyURL(a.transportPool.RawProxyURL()),
LastAppliedAt: at,
}
}
// redactProxyURL 隐藏代理 URL 里的 userinfo。
func redactProxyURL(s string) string {
if s == "" {
return "<direct>"
}
if i := strings.Index(s, "@"); i >= 0 {
if j := strings.Index(s, "://"); j >= 0 && j < i {
return s[:j+3] + "***@" + s[i+1:]
}
}
return s
}