- 新增 /api/admin/vpn/diag 端点,检测 TUN 创建能力、root、CAP_NET_ADMIN、ip_forward、MASQUERADE - Linux 下解析 /proc/self/status CapEff 位判断 CAP_NET_ADMIN,读 /proc/sys/net/ipv4/ip_forward,执行 iptables 检查 MASQUERADE - 非 Linux 平台显示"仅 Linux 适用" - 前端 VpnView 新增系统环境检测卡片,每项以勾叉标识并附修复提示
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package vpn
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
)
|
|
|
|
type DiagResult struct {
|
|
Platform string `json:"platform"`
|
|
IsRoot bool `json:"is_root"`
|
|
HasCapNetAdmin *bool `json:"has_cap_net_admin"`
|
|
CapNetAdminNote string `json:"cap_net_admin_note,omitempty"`
|
|
IPForward *bool `json:"ip_forward"`
|
|
IPForwardNote string `json:"ip_forward_note,omitempty"`
|
|
Masquerade *bool `json:"masquerade"`
|
|
MasqueradeNote string `json:"masquerade_note,omitempty"`
|
|
TUNCreate string `json:"tun_create"`
|
|
TUNRunning bool `json:"tun_running"`
|
|
TUNName string `json:"tun_name,omitempty"`
|
|
}
|
|
|
|
func Diag(svc *VpnService) DiagResult {
|
|
r := DiagResult{Platform: runtime.GOOS, IsRoot: os.Getuid() == 0}
|
|
|
|
if svc != nil {
|
|
svc.mu.RLock()
|
|
r.TUNRunning = svc.running
|
|
if svc.tun != nil {
|
|
r.TUNName = svc.tun.Name()
|
|
}
|
|
svc.mu.RUnlock()
|
|
}
|
|
|
|
if r.TUNRunning {
|
|
r.TUNCreate = "ok: " + r.TUNName
|
|
} else {
|
|
r.TUNCreate = testTUNCreate()
|
|
}
|
|
|
|
fillPlatformDiag(&r)
|
|
return r
|
|
}
|
|
|
|
func testTUNCreate() string {
|
|
t, err := CreateTUN("")
|
|
if err != nil {
|
|
return "fail: " + err.Error()
|
|
}
|
|
name := t.Name()
|
|
_ = t.Close()
|
|
return "ok: " + name
|
|
}
|