3 Commits

Author SHA1 Message Date
Flik
0a41e10793 feat(client, server): add client name handling and machine ID retrieval
Some checks failed
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-frontend (push) Has been cancelled
2026-01-27 08:56:05 +08:00
Flik
3386b0fcb6 fix(client): 移除日志前缀并改进代理配置处理
Some checks failed
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-frontend (push) Has been cancelled
- 移除了所有客户端日志消息中的 [Client] 前缀
- 修改 handleProxyConfig 函数以接收 stream 参数并添加延迟关闭
- 更新 sendProxyConfig 函数以等待客户端配置确认
- 改进了代理配置同步的可靠性
2026-01-23 18:10:51 +08:00
Flik
98a5525e6d feat(client): 添加服务端版本检查和客户端更新逻辑
Some checks failed
Build Multi-Platform Binaries / build-frontend (push) Successful in 27s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 1m24s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m33s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 1m18s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m40s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 1m16s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m40s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Failing after 1m39s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m49s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 1m26s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 1m53s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 1m16s
- 引入 getVersionInfo API 和服务端版本获取功能
- 实现版本比较算法用于判断更新需求
- 添加服务端版本加载和目标版本计算逻辑
- 更新客户端版本显示为可更新目标版本
- 优化样式表移除不透明背景设置
- 调整进度条外观样式增强视觉效果
2026-01-23 08:40:54 +08:00
15 changed files with 390 additions and 113 deletions

2
go.mod
View File

@@ -59,7 +59,7 @@ require (
github.com/quic-go/qpack v0.6.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.58.0 // indirect github.com/quic-go/quic-go v0.58.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/shoenig/go-m1cpu v0.1.7 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect github.com/tklauser/numcpus v0.6.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect

8
go.sum
View File

@@ -122,10 +122,10 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI=
github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk= github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk=
github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.7 h1:C76Yd0ObKR82W4vhfjZiCp0HxcSZ8Nqd84v+HZ0qyI0=
github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/go-m1cpu v0.1.7/go.mod h1:KkDOw6m3ZJQAPHbrzkZki4hnx+pDRR1Lo+ldA56wD5w=
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= github.com/shoenig/test v1.7.0 h1:eWcHtTXa6QLnBvm0jgEabMRN/uJ4DMV3M8xUGgRkZmk=
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/shoenig/test v1.7.0/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

View File

@@ -32,7 +32,6 @@ const (
reconnectDelay = 5 * time.Second reconnectDelay = 5 * time.Second
disconnectDelay = 3 * time.Second disconnectDelay = 3 * time.Second
udpBufferSize = 65535 udpBufferSize = 65535
idFileName = "id"
) )
// Client 隧道客户端 // Client 隧道客户端
@@ -40,6 +39,7 @@ type Client struct {
ServerAddr string ServerAddr string
Token string Token string
ID string ID string
Name string // 客户端名称(主机名)
TLSEnabled bool TLSEnabled bool
TLSConfig *tls.Config TLSConfig *tls.Config
DataDir string // 数据目录 DataDir string // 数据目录
@@ -61,23 +61,28 @@ func NewClient(serverAddr, token, id string) *Client {
// 确保数据目录存在 // 确保数据目录存在
if err := os.MkdirAll(dataDir, 0755); err != nil { if err := os.MkdirAll(dataDir, 0755); err != nil {
log.Printf("[Client] Failed to create data dir: %v", err) log.Printf("Failed to create data dir: %v", err)
} }
// ID 优先级:命令行参数 > 机器ID
if id == "" { if id == "" {
id = loadClientID(dataDir) id = getMachineID()
} }
// 获取主机名作为客户端名称
hostname, _ := os.Hostname()
// 初始化日志收集器 // 初始化日志收集器
logger, err := NewLogger(dataDir) logger, err := NewLogger(dataDir)
if err != nil { if err != nil {
log.Printf("[Client] Failed to initialize logger: %v", err) log.Printf("Failed to initialize logger: %v", err)
} }
return &Client{ return &Client{
ServerAddr: serverAddr, ServerAddr: serverAddr,
Token: token, Token: token,
ID: id, ID: id,
Name: hostname,
DataDir: dataDir, DataDir: dataDir,
runningPlugins: make(map[string]plugin.ClientPlugin), runningPlugins: make(map[string]plugin.ClientPlugin),
logger: logger, logger: logger,
@@ -94,27 +99,6 @@ func (c *Client) InitVersionStore() error {
return nil return nil
} }
// getIDFilePath 获取 ID 文件路径
func getIDFilePath(dataDir string) string {
return filepath.Join(dataDir, idFileName)
}
// loadClientID 从本地文件加载客户端 ID
func loadClientID(dataDir string) string {
data, err := os.ReadFile(getIDFilePath(dataDir))
if err != nil {
return ""
}
return string(data)
}
// saveClientID 保存客户端 ID 到本地文件
func saveClientID(dataDir, id string) {
if err := os.WriteFile(getIDFilePath(dataDir), []byte(id), 0600); err != nil {
log.Printf("[Client] Failed to save client ID: %v", err)
}
}
// SetPluginRegistry 设置插件注册表 // SetPluginRegistry 设置插件注册表
func (c *Client) SetPluginRegistry(registry *plugin.Registry) { func (c *Client) SetPluginRegistry(registry *plugin.Registry) {
c.pluginRegistry = registry c.pluginRegistry = registry
@@ -151,14 +135,14 @@ func (c *Client) logWarnf(format string, args ...interface{}) {
func (c *Client) Run() error { func (c *Client) Run() error {
for { for {
if err := c.connect(); err != nil { if err := c.connect(); err != nil {
c.logErrorf("[Client] Connect error: %v", err) c.logErrorf("Connect error: %v", err)
c.logf("[Client] Reconnecting in %v...", reconnectDelay) c.logf("Reconnecting in %v...", reconnectDelay)
time.Sleep(reconnectDelay) time.Sleep(reconnectDelay)
continue continue
} }
c.handleSession() c.handleSession()
c.logWarnf("[Client] Disconnected, reconnecting...") c.logWarnf("Disconnected, reconnecting...")
time.Sleep(disconnectDelay) time.Sleep(disconnectDelay)
} }
} }
@@ -181,6 +165,7 @@ func (c *Client) connect() error {
authReq := protocol.AuthRequest{ authReq := protocol.AuthRequest{
ClientID: c.ID, ClientID: c.ID,
Token: c.Token, Token: c.Token,
Name: c.Name,
OS: runtime.GOOS, OS: runtime.GOOS,
Arch: runtime.GOARCH, Arch: runtime.GOARCH,
Version: version.Version, Version: version.Version,
@@ -207,14 +192,13 @@ func (c *Client) connect() error {
return fmt.Errorf("auth failed: %s", authResp.Message) return fmt.Errorf("auth failed: %s", authResp.Message)
} }
// 如果服务端分配了新 ID则更新并保存 // 如果服务端分配了新 ID则更新
if authResp.ClientID != "" && authResp.ClientID != c.ID { if authResp.ClientID != "" && authResp.ClientID != c.ID {
c.ID = authResp.ClientID c.ID = authResp.ClientID
saveClientID(c.DataDir, c.ID) c.logf("ID updated to: %s", c.ID)
c.logf("[Client] New ID assigned and saved: %s", c.ID)
} }
c.logf("[Client] Authenticated as %s", c.ID) c.logf("Authenticated as %s", c.ID)
session, err := yamux.Client(conn, nil) session, err := yamux.Client(conn, nil)
if err != nil { if err != nil {
@@ -252,8 +236,7 @@ func (c *Client) handleStream(stream net.Conn) {
switch msg.Type { switch msg.Type {
case protocol.MsgTypeProxyConfig: case protocol.MsgTypeProxyConfig:
defer stream.Close() c.handleProxyConfig(stream, msg)
c.handleProxyConfig(msg)
case protocol.MsgTypeNewProxy: case protocol.MsgTypeNewProxy:
defer stream.Close() defer stream.Close()
c.handleNewProxy(stream, msg) c.handleNewProxy(stream, msg)
@@ -295,10 +278,12 @@ func (c *Client) handleStream(stream net.Conn) {
} }
// handleProxyConfig 处理代理配置 // handleProxyConfig 处理代理配置
func (c *Client) handleProxyConfig(msg *protocol.Message) { func (c *Client) handleProxyConfig(stream net.Conn, msg *protocol.Message) {
defer stream.Close()
var cfg protocol.ProxyConfig var cfg protocol.ProxyConfig
if err := msg.ParsePayload(&cfg); err != nil { if err := msg.ParsePayload(&cfg); err != nil {
c.logErrorf("[Client] Parse proxy config error: %v", err) c.logErrorf("Parse proxy config error: %v", err)
return return
} }
@@ -306,17 +291,21 @@ func (c *Client) handleProxyConfig(msg *protocol.Message) {
c.rules = cfg.Rules c.rules = cfg.Rules
c.mu.Unlock() c.mu.Unlock()
c.logf("[Client] Received %d proxy rules", len(cfg.Rules)) c.logf("Received %d proxy rules", len(cfg.Rules))
for _, r := range cfg.Rules { for _, r := range cfg.Rules {
c.logf("[Client] %s: %s:%d", r.Name, r.LocalIP, r.LocalPort) c.logf(" %s: %s:%d", r.Name, r.LocalIP, r.LocalPort)
} }
// 发送配置确认
ack := &protocol.Message{Type: protocol.MsgTypeProxyReady}
protocol.WriteMessage(stream, ack)
} }
// handleNewProxy 处理新代理请求 // handleNewProxy 处理新代理请求
func (c *Client) handleNewProxy(stream net.Conn, msg *protocol.Message) { func (c *Client) handleNewProxy(stream net.Conn, msg *protocol.Message) {
var req protocol.NewProxyRequest var req protocol.NewProxyRequest
if err := msg.ParsePayload(&req); err != nil { if err := msg.ParsePayload(&req); err != nil {
c.logErrorf("[Client] Parse new proxy request error: %v", err) c.logErrorf("Parse new proxy request error: %v", err)
return return
} }
@@ -331,14 +320,14 @@ func (c *Client) handleNewProxy(stream net.Conn, msg *protocol.Message) {
c.mu.RUnlock() c.mu.RUnlock()
if rule == nil { if rule == nil {
c.logWarnf("[Client] Unknown port %d", req.RemotePort) c.logWarnf("Unknown port %d", req.RemotePort)
return return
} }
localAddr := fmt.Sprintf("%s:%d", rule.LocalIP, rule.LocalPort) localAddr := fmt.Sprintf("%s:%d", rule.LocalIP, rule.LocalPort)
localConn, err := net.DialTimeout("tcp", localAddr, localDialTimeout) localConn, err := net.DialTimeout("tcp", localAddr, localDialTimeout)
if err != nil { if err != nil {
c.logErrorf("[Client] Connect %s error: %v", localAddr, err) c.logErrorf("Connect %s error: %v", localAddr, err)
return return
} }
@@ -448,24 +437,24 @@ func (c *Client) findRuleByPort(port int) *protocol.ProxyRule {
func (c *Client) handlePluginConfig(msg *protocol.Message) { func (c *Client) handlePluginConfig(msg *protocol.Message) {
var cfg protocol.PluginConfigSync var cfg protocol.PluginConfigSync
if err := msg.ParsePayload(&cfg); err != nil { if err := msg.ParsePayload(&cfg); err != nil {
c.logErrorf("[Client] Parse plugin config error: %v", err) c.logErrorf("Parse plugin config error: %v", err)
return return
} }
c.logf("[Client] Received config for plugin: %s", cfg.PluginName) c.logf("Received config for plugin: %s", cfg.PluginName)
// 应用配置到插件 // 应用配置到插件
if c.pluginRegistry != nil { if c.pluginRegistry != nil {
handler, err := c.pluginRegistry.GetClient(cfg.PluginName) handler, err := c.pluginRegistry.GetClient(cfg.PluginName)
if err != nil { if err != nil {
c.logWarnf("[Client] Plugin %s not found: %v", cfg.PluginName, err) c.logWarnf("Plugin %s not found: %v", cfg.PluginName, err)
return return
} }
if err := handler.Init(cfg.Config); err != nil { if err := handler.Init(cfg.Config); err != nil {
c.logErrorf("[Client] Plugin %s init error: %v", cfg.PluginName, err) c.logErrorf("Plugin %s init error: %v", cfg.PluginName, err)
return return
} }
c.logf("[Client] Plugin %s config applied", cfg.PluginName) c.logf("Plugin %s config applied", cfg.PluginName)
} }
} }
@@ -479,7 +468,7 @@ func (c *Client) handleClientPluginStart(stream net.Conn, msg *protocol.Message)
return return
} }
c.logf("[Client] Starting plugin %s for rule %s", req.PluginName, req.RuleName) c.logf("Starting plugin %s for rule %s", req.PluginName, req.RuleName)
// 获取插件 // 获取插件
if c.pluginRegistry == nil { if c.pluginRegistry == nil {
@@ -511,7 +500,7 @@ func (c *Client) handleClientPluginStart(stream net.Conn, msg *protocol.Message)
c.runningPlugins[key] = handler c.runningPlugins[key] = handler
c.pluginMu.Unlock() c.pluginMu.Unlock()
c.logf("[Client] Plugin %s started at %s", req.PluginName, localAddr) c.logf("Plugin %s started at %s", req.PluginName, localAddr)
c.sendPluginStatus(stream, req.PluginName, req.RuleName, true, localAddr, "") c.sendPluginStatus(stream, req.PluginName, req.RuleName, true, localAddr, "")
} }
@@ -553,7 +542,7 @@ func (c *Client) handleClientPluginConn(stream net.Conn, msg *protocol.Message)
c.pluginMu.RUnlock() c.pluginMu.RUnlock()
if !ok { if !ok {
c.logWarnf("[Client] Plugin %s (ID: %s) not running", req.PluginName, req.PluginID) c.logWarnf("Plugin %s (ID: %s) not running", req.PluginName, req.PluginID)
stream.Close() stream.Close()
return return
} }
@@ -572,7 +561,7 @@ func (c *Client) handleJSPluginInstall(stream net.Conn, msg *protocol.Message) {
return return
} }
c.logf("[Client] Installing JS plugin: %s (ID: %s)", req.PluginName, req.PluginID) c.logf("Installing JS plugin: %s (ID: %s)", req.PluginName, req.PluginID)
// 使用 PluginID 作为 key如果有否则回退到 pluginName:ruleName // 使用 PluginID 作为 key如果有否则回退到 pluginName:ruleName
key := req.PluginID key := req.PluginID
@@ -583,9 +572,9 @@ func (c *Client) handleJSPluginInstall(stream net.Conn, msg *protocol.Message) {
// 如果插件已经在运行,先停止它 // 如果插件已经在运行,先停止它
c.pluginMu.Lock() c.pluginMu.Lock()
if existingHandler, ok := c.runningPlugins[key]; ok { if existingHandler, ok := c.runningPlugins[key]; ok {
c.logf("[Client] Stopping existing plugin %s before reinstall", key) c.logf("Stopping existing plugin %s before reinstall", key)
if err := existingHandler.Stop(); err != nil { if err := existingHandler.Stop(); err != nil {
c.logErrorf("[Client] Stop existing plugin error: %v", err) c.logErrorf("Stop existing plugin error: %v", err)
} }
delete(c.runningPlugins, key) delete(c.runningPlugins, key)
} }
@@ -593,11 +582,11 @@ func (c *Client) handleJSPluginInstall(stream net.Conn, msg *protocol.Message) {
// 验证官方签名 // 验证官方签名
if err := c.verifyJSPluginSignature(req.PluginName, req.Source, req.Signature); err != nil { if err := c.verifyJSPluginSignature(req.PluginName, req.Source, req.Signature); err != nil {
c.logErrorf("[Client] JS plugin %s signature verification failed: %v", req.PluginName, err) c.logErrorf("JS plugin %s signature verification failed: %v", req.PluginName, err)
c.sendJSPluginResult(stream, req.PluginName, false, "signature verification failed: "+err.Error()) c.sendJSPluginResult(stream, req.PluginName, false, "signature verification failed: "+err.Error())
return return
} }
c.logf("[Client] JS plugin %s signature verified", req.PluginName) c.logf("JS plugin %s signature verified", req.PluginName)
// 创建 JS 插件 // 创建 JS 插件
jsPlugin, err := script.NewJSPlugin(req.PluginName, req.Source) jsPlugin, err := script.NewJSPlugin(req.PluginName, req.Source)
@@ -611,7 +600,7 @@ func (c *Client) handleJSPluginInstall(stream net.Conn, msg *protocol.Message) {
c.pluginRegistry.RegisterClient(jsPlugin) c.pluginRegistry.RegisterClient(jsPlugin)
} }
c.logf("[Client] JS plugin %s installed", req.PluginName) c.logf("JS plugin %s installed", req.PluginName)
// 保存版本信息(防止降级攻击) // 保存版本信息(防止降级攻击)
if c.versionStore != nil { if c.versionStore != nil {
@@ -644,13 +633,13 @@ func (c *Client) sendJSPluginResult(stream net.Conn, name string, success bool,
// startJSPlugin 启动 JS 插件 // startJSPlugin 启动 JS 插件
func (c *Client) startJSPlugin(handler plugin.ClientPlugin, req protocol.JSPluginInstallRequest) { func (c *Client) startJSPlugin(handler plugin.ClientPlugin, req protocol.JSPluginInstallRequest) {
if err := handler.Init(req.Config); err != nil { if err := handler.Init(req.Config); err != nil {
c.logErrorf("[Client] JS plugin %s init error: %v", req.PluginName, err) c.logErrorf("JS plugin %s init error: %v", req.PluginName, err)
return return
} }
localAddr, err := handler.Start() localAddr, err := handler.Start()
if err != nil { if err != nil {
c.logErrorf("[Client] JS plugin %s start error: %v", req.PluginName, err) c.logErrorf("JS plugin %s start error: %v", req.PluginName, err)
return return
} }
@@ -663,7 +652,7 @@ func (c *Client) startJSPlugin(handler plugin.ClientPlugin, req protocol.JSPlugi
c.runningPlugins[key] = handler c.runningPlugins[key] = handler
c.pluginMu.Unlock() c.pluginMu.Unlock()
c.logf("[Client] JS plugin %s (ID: %s) started at %s", req.PluginName, req.PluginID, localAddr) c.logf("JS plugin %s (ID: %s) started at %s", req.PluginName, req.PluginID, localAddr)
} }
// verifyJSPluginSignature 验证 JS 插件签名 // verifyJSPluginSignature 验证 JS 插件签名
@@ -741,13 +730,13 @@ func (c *Client) handleClientPluginStop(stream net.Conn, msg *protocol.Message)
if ok { if ok {
if err := handler.Stop(); err != nil { if err := handler.Stop(); err != nil {
c.logErrorf("[Client] Plugin %s stop error: %v", key, err) c.logErrorf("Plugin %s stop error: %v", key, err)
} }
delete(c.runningPlugins, key) delete(c.runningPlugins, key)
} }
c.pluginMu.Unlock() c.pluginMu.Unlock()
c.logf("[Client] Plugin %s stopped", key) c.logf("Plugin %s stopped", key)
c.sendPluginStatus(stream, req.PluginName, req.RuleName, false, "", "") c.sendPluginStatus(stream, req.PluginName, req.RuleName, false, "", "")
} }
@@ -758,7 +747,7 @@ func (c *Client) handleClientRestart(stream net.Conn, msg *protocol.Message) {
var req protocol.ClientRestartRequest var req protocol.ClientRestartRequest
msg.ParsePayload(&req) msg.ParsePayload(&req)
c.logf("[Client] Restart requested: %s", req.Reason) c.logf("Restart requested: %s", req.Reason)
// 发送响应 // 发送响应
resp := protocol.ClientRestartResponse{ resp := protocol.ClientRestartResponse{
@@ -771,7 +760,7 @@ func (c *Client) handleClientRestart(stream net.Conn, msg *protocol.Message) {
// 停止所有运行中的插件 // 停止所有运行中的插件
c.pluginMu.Lock() c.pluginMu.Lock()
for key, handler := range c.runningPlugins { for key, handler := range c.runningPlugins {
c.logf("[Client] Stopping plugin %s for restart", key) c.logf("Stopping plugin %s for restart", key)
handler.Stop() handler.Stop()
} }
c.runningPlugins = make(map[string]plugin.ClientPlugin) c.runningPlugins = make(map[string]plugin.ClientPlugin)
@@ -813,7 +802,7 @@ func (c *Client) handlePluginConfigUpdate(stream net.Conn, msg *protocol.Message
} }
c.pluginMu.RUnlock() c.pluginMu.RUnlock()
c.logf("[Client] Config update for plugin %s", key) c.logf("Config update for plugin %s", key)
if !ok { if !ok {
c.sendPluginConfigUpdateResult(stream, req.PluginName, req.RuleName, false, "plugin not running") c.sendPluginConfigUpdateResult(stream, req.PluginName, req.RuleName, false, "plugin not running")
@@ -824,7 +813,7 @@ func (c *Client) handlePluginConfigUpdate(stream net.Conn, msg *protocol.Message
// 停止并重启插件 // 停止并重启插件
c.pluginMu.Lock() c.pluginMu.Lock()
if err := handler.Stop(); err != nil { if err := handler.Stop(); err != nil {
c.logErrorf("[Client] Plugin %s stop error: %v", key, err) c.logErrorf("Plugin %s stop error: %v", key, err)
} }
delete(c.runningPlugins, key) delete(c.runningPlugins, key)
c.pluginMu.Unlock() c.pluginMu.Unlock()
@@ -845,7 +834,7 @@ func (c *Client) handlePluginConfigUpdate(stream net.Conn, msg *protocol.Message
c.runningPlugins[key] = handler c.runningPlugins[key] = handler
c.pluginMu.Unlock() c.pluginMu.Unlock()
c.logf("[Client] Plugin %s restarted at %s with new config", key, localAddr) c.logf("Plugin %s restarted at %s with new config", key, localAddr)
} }
c.sendPluginConfigUpdateResult(stream, req.PluginName, req.RuleName, true, "") c.sendPluginConfigUpdateResult(stream, req.PluginName, req.RuleName, true, "")
@@ -869,17 +858,17 @@ func (c *Client) handleUpdateDownload(stream net.Conn, msg *protocol.Message) {
var req protocol.UpdateDownloadRequest var req protocol.UpdateDownloadRequest
if err := msg.ParsePayload(&req); err != nil { if err := msg.ParsePayload(&req); err != nil {
c.logErrorf("[Client] Parse update request error: %v", err) c.logErrorf("Parse update request error: %v", err)
c.sendUpdateResult(stream, false, "invalid request") c.sendUpdateResult(stream, false, "invalid request")
return return
} }
c.logf("[Client] Update download requested: %s", req.DownloadURL) c.logf("Update download requested: %s", req.DownloadURL)
// 异步执行更新 // 异步执行更新
go func() { go func() {
if err := c.performSelfUpdate(req.DownloadURL); err != nil { if err := c.performSelfUpdate(req.DownloadURL); err != nil {
c.logErrorf("[Client] Update failed: %v", err) c.logErrorf("Update failed: %v", err)
} }
}() }()
@@ -898,7 +887,7 @@ func (c *Client) sendUpdateResult(stream net.Conn, success bool, message string)
// performSelfUpdate 执行自更新 // performSelfUpdate 执行自更新
func (c *Client) performSelfUpdate(downloadURL string) error { func (c *Client) performSelfUpdate(downloadURL string) error {
c.logf("[Client] Starting self-update from: %s", downloadURL) c.logf("Starting self-update from: %s", downloadURL)
// 使用共享的下载和解压逻辑 // 使用共享的下载和解压逻辑
binaryPath, cleanup, err := update.DownloadAndExtract(downloadURL, "client") binaryPath, cleanup, err := update.DownloadAndExtract(downloadURL, "client")
@@ -945,7 +934,7 @@ func (c *Client) performSelfUpdate(downloadURL string) error {
// 删除备份 // 删除备份
os.Remove(backupPath) os.Remove(backupPath)
c.logf("[Client] Update completed, restarting...") c.logf("Update completed, restarting...")
// 重启进程 // 重启进程
restartClientProcess(currentPath, c.ServerAddr, c.Token, c.ID) restartClientProcess(currentPath, c.ServerAddr, c.Token, c.ID)
@@ -956,7 +945,7 @@ func (c *Client) performSelfUpdate(downloadURL string) error {
func (c *Client) stopAllPlugins() { func (c *Client) stopAllPlugins() {
c.pluginMu.Lock() c.pluginMu.Lock()
for key, handler := range c.runningPlugins { for key, handler := range c.runningPlugins {
c.logf("[Client] Stopping plugin %s for update", key) c.logf("Stopping plugin %s for update", key)
handler.Stop() handler.Stop()
} }
c.runningPlugins = make(map[string]plugin.ClientPlugin) c.runningPlugins = make(map[string]plugin.ClientPlugin)
@@ -1122,7 +1111,7 @@ func (c *Client) handlePluginAPIRequest(stream net.Conn, msg *protocol.Message)
return return
} }
c.logf("[Client] Plugin API request: %s %s for plugin %s (ID: %s)", req.Method, req.Path, req.PluginName, req.PluginID) c.logf("Plugin API request: %s %s for plugin %s (ID: %s)", req.Method, req.Path, req.PluginName, req.PluginID)
// 查找运行中的插件 // 查找运行中的插件
c.pluginMu.RLock() c.pluginMu.RLock()
@@ -1185,7 +1174,7 @@ func (c *Client) handleSystemStatsRequest(stream net.Conn, msg *protocol.Message
stats, err := utils.GetSystemStats() stats, err := utils.GetSystemStats()
if err != nil { if err != nil {
log.Printf("[Client] Failed to get system stats: %v", err) log.Printf("Failed to get system stats: %v", err)
return return
} }

View File

@@ -0,0 +1,133 @@
package tunnel
import (
"crypto/sha256"
"encoding/hex"
"net"
"os"
"os/exec"
"runtime"
"strings"
)
// getMachineID 获取机器唯一标识
// 优先级系统机器ID > MAC地址哈希
func getMachineID() string {
// 尝试获取系统机器 ID
if id := getSystemMachineID(); id != "" {
return hashID(id)
}
// 备选:使用主网卡 MAC 地址
if id := getMACAddress(); id != "" {
return hashID(id)
}
// 都失败则返回空,让服务端生成
return ""
}
// getSystemMachineID 获取系统机器 ID
func getSystemMachineID() string {
switch runtime.GOOS {
case "linux":
return getLinuxMachineID()
case "darwin":
return getDarwinMachineID()
case "windows":
return getWindowsMachineID()
default:
return ""
}
}
// getLinuxMachineID 获取 Linux 机器 ID
func getLinuxMachineID() string {
// 优先读取 /etc/machine-id
if data, err := os.ReadFile("/etc/machine-id"); err == nil {
return strings.TrimSpace(string(data))
}
// 备选 /var/lib/dbus/machine-id
if data, err := os.ReadFile("/var/lib/dbus/machine-id"); err == nil {
return strings.TrimSpace(string(data))
}
return ""
}
// getDarwinMachineID 获取 macOS 机器 ID (IOPlatformUUID)
func getDarwinMachineID() string {
cmd := exec.Command("ioreg", "-rd1", "-c", "IOPlatformExpertDevice")
output, err := cmd.Output()
if err != nil {
return ""
}
// 解析 IOPlatformUUID
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if strings.Contains(line, "IOPlatformUUID") {
parts := strings.Split(line, "=")
if len(parts) == 2 {
uuid := strings.TrimSpace(parts[1])
uuid = strings.Trim(uuid, "\"")
return uuid
}
}
}
return ""
}
// getWindowsMachineID 获取 Windows 机器 ID
func getWindowsMachineID() string {
cmd := exec.Command("reg", "query",
`HKLM\SOFTWARE\Microsoft\Cryptography`,
"/v", "MachineGuid")
output, err := cmd.Output()
if err != nil {
return ""
}
// 解析注册表输出
lines := strings.Split(string(output), "\n")
for _, line := range lines {
if strings.Contains(line, "MachineGuid") {
fields := strings.Fields(line)
if len(fields) >= 3 {
return fields[len(fields)-1]
}
}
}
return ""
}
// getMACAddress 获取主网卡 MAC 地址
func getMACAddress() string {
interfaces, err := net.Interfaces()
if err != nil {
return ""
}
for _, iface := range interfaces {
// 跳过回环和无效接口
if iface.Flags&net.FlagLoopback != 0 {
continue
}
if iface.Flags&net.FlagUp == 0 {
continue
}
if len(iface.HardwareAddr) == 0 {
continue
}
// 返回第一个有效的 MAC 地址
return iface.HardwareAddr.String()
}
return ""
}
// hashID 对 ID 进行哈希处理,生成固定长度的客户端 ID
func hashID(id string) string {
hash := sha256.Sum256([]byte(id))
// 取前 16 个字符作为客户端 ID
return hex.EncodeToString(hash[:])[:16]
}

View File

@@ -115,7 +115,7 @@ func (h *ClientHandler) Get(c *gin.Context) {
return return
} }
online, lastPing, remoteAddr, clientOS, clientArch, clientVersion := h.app.GetServer().GetClientStatus(clientID) online, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion := h.app.GetServer().GetClientStatus(clientID)
// 复制插件列表 // 复制插件列表
plugins := make([]db.ClientPlugin, len(client.Plugins)) plugins := make([]db.ClientPlugin, len(client.Plugins))
@@ -145,9 +145,15 @@ func (h *ClientHandler) Get(c *gin.Context) {
} }
} }
// 如果客户端在线且有名称,优先使用在线名称
nickname := client.Nickname
if online && clientName != "" && nickname == "" {
nickname = clientName
}
resp := dto.ClientResponse{ resp := dto.ClientResponse{
ID: client.ID, ID: client.ID,
Nickname: client.Nickname, Nickname: nickname,
Rules: client.Rules, Rules: client.Rules,
Plugins: plugins, Plugins: plugins,
Online: online, Online: online,
@@ -242,8 +248,7 @@ func (h *ClientHandler) Delete(c *gin.Context) {
func (h *ClientHandler) PushConfig(c *gin.Context) { func (h *ClientHandler) PushConfig(c *gin.Context) {
clientID := c.Param("id") clientID := c.Param("id")
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID) if !h.app.GetServer().IsClientOnline(clientID) {
if !online {
ClientNotOnline(c) ClientNotOnline(c)
return return
} }
@@ -311,8 +316,7 @@ func (h *ClientHandler) Restart(c *gin.Context) {
func (h *ClientHandler) InstallPlugins(c *gin.Context) { func (h *ClientHandler) InstallPlugins(c *gin.Context) {
clientID := c.Param("id") clientID := c.Param("id")
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID) if !h.app.GetServer().IsClientOnline(clientID) {
if !online {
ClientNotOnline(c) ClientNotOnline(c)
return return
} }

View File

@@ -19,11 +19,13 @@ type AppInterface interface {
// ServerInterface 服务端接口 // ServerInterface 服务端接口
type ServerInterface interface { type ServerInterface interface {
GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientOS, clientArch, clientVersion string) IsClientOnline(clientID string) bool
GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion string)
GetAllClientStatus() map[string]struct { GetAllClientStatus() map[string]struct {
Online bool Online bool
LastPing string LastPing string
RemoteAddr string RemoteAddr string
Name string
OS string OS string
Arch string Arch string
Version string Version string

View File

@@ -177,8 +177,7 @@ func (h *JSPluginHandler) PushToClient(c *gin.Context) {
c.ShouldBindJSON(&pushReq) // 忽略错误,允许空请求体 c.ShouldBindJSON(&pushReq) // 忽略错误,允许空请求体
// 检查客户端是否在线 // 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID) if !h.app.GetServer().IsClientOnline(clientID) {
if !online {
ClientNotOnline(c) ClientNotOnline(c)
return return
} }

View File

@@ -35,8 +35,7 @@ func (h *LogHandler) StreamLogs(c *gin.Context) {
clientID := c.Param("id") clientID := c.Param("id")
// 检查客户端是否在线 // 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID) if !h.app.GetServer().IsClientOnline(clientID) {
if !online {
c.JSON(400, gin.H{"code": 400, "message": "client not online"}) c.JSON(400, gin.H{"code": 400, "message": "client not online"})
return return
} }

View File

@@ -371,8 +371,7 @@ func (h *PluginHandler) UpdateClientConfig(c *gin.Context) {
} }
// 如果客户端在线,同步配置 // 如果客户端在线,同步配置
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID) if h.app.GetServer().IsClientOnline(clientID) {
if online {
if err := h.app.GetServer().SyncPluginConfigToClient(clientID, pluginName, req.Config); err != nil { if err := h.app.GetServer().SyncPluginConfigToClient(clientID, pluginName, req.Config); err != nil {
PartialSuccess(c, gin.H{"status": "partial", "port_changed": portChanged}, "config saved but sync failed: "+err.Error()) PartialSuccess(c, gin.H{"status": "partial", "port_changed": portChanged}, "config saved but sync failed: "+err.Error())
return return

View File

@@ -45,8 +45,7 @@ func (h *PluginAPIHandler) ProxyRequest(c *gin.Context) {
} }
// 检查客户端是否在线 // 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(clientID) if !h.app.GetServer().IsClientOnline(clientID) {
if !online {
ClientNotOnline(c) ClientNotOnline(c)
return return
} }

View File

@@ -82,8 +82,7 @@ func (h *StoreHandler) Install(c *gin.Context) {
} }
// 检查客户端是否在线 // 检查客户端是否在线
online, _, _, _, _, _ := h.app.GetServer().GetClientStatus(req.ClientID) if !h.app.GetServer().IsClientOnline(req.ClientID) {
if !online {
ClientNotOnline(c) ClientNotOnline(c)
return return
} }

View File

@@ -83,6 +83,7 @@ type JSPluginEntry struct {
// ClientSession 客户端会话 // ClientSession 客户端会话
type ClientSession struct { type ClientSession struct {
ID string ID string
Name string // 客户端名称(主机名)
RemoteAddr string // 客户端 IP 地址 RemoteAddr string // 客户端 IP 地址
OS string // 客户端操作系统 OS string // 客户端操作系统
Arch string // 客户端架构 Arch string // 客户端架构
@@ -269,13 +270,21 @@ func (s *Server) handleConnection(conn net.Conn) {
// 检查客户端是否存在,不存在则自动创建 // 检查客户端是否存在,不存在则自动创建
exists, err := s.clientStore.ClientExists(clientID) exists, err := s.clientStore.ClientExists(clientID)
if err != nil || !exists { if err != nil || !exists {
newClient := &db.Client{ID: clientID, Rules: []protocol.ProxyRule{}} newClient := &db.Client{ID: clientID, Nickname: authReq.Name, Rules: []protocol.ProxyRule{}}
if err := s.clientStore.CreateClient(newClient); err != nil { if err := s.clientStore.CreateClient(newClient); err != nil {
log.Printf("[Server] Create client error: %v", err) log.Printf("[Server] Create client error: %v", err)
s.sendAuthResponse(conn, false, "failed to create client", "") s.sendAuthResponse(conn, false, "failed to create client", "")
return return
} }
log.Printf("[Server] New client registered: %s", clientID) log.Printf("[Server] New client registered: %s (%s)", clientID, authReq.Name)
} else if authReq.Name != "" {
// 客户端已存在,更新名称(如果提供了新名称)
if client, err := s.clientStore.GetClient(clientID); err == nil {
if client.Nickname == "" || client.Nickname != authReq.Name {
client.Nickname = authReq.Name
s.clientStore.UpdateClient(client)
}
}
} }
rules, _ := s.clientStore.GetClientRules(clientID) rules, _ := s.clientStore.GetClientRules(clientID)
@@ -290,11 +299,11 @@ func (s *Server) handleConnection(conn net.Conn) {
} }
security.LogAuthSuccess(clientIP, clientID) security.LogAuthSuccess(clientIP, clientID)
s.setupClientSession(conn, clientID, authReq.OS, authReq.Arch, authReq.Version, rules) s.setupClientSession(conn, clientID, authReq.Name, authReq.OS, authReq.Arch, authReq.Version, rules)
} }
// setupClientSession 建立客户端会话 // setupClientSession 建立客户端会话
func (s *Server) setupClientSession(conn net.Conn, clientID, clientOS, clientArch, clientVersion string, rules []protocol.ProxyRule) { func (s *Server) setupClientSession(conn net.Conn, clientID, clientName, clientOS, clientArch, clientVersion string, rules []protocol.ProxyRule) {
session, err := yamux.Server(conn, nil) session, err := yamux.Server(conn, nil)
if err != nil { if err != nil {
log.Printf("[Server] Yamux error: %v", err) log.Printf("[Server] Yamux error: %v", err)
@@ -309,6 +318,7 @@ func (s *Server) setupClientSession(conn net.Conn, clientID, clientOS, clientArc
cs := &ClientSession{ cs := &ClientSession{
ID: clientID, ID: clientID,
Name: clientName,
RemoteAddr: remoteAddr, RemoteAddr: remoteAddr,
OS: clientOS, OS: clientOS,
Arch: clientArch, Arch: clientArch,
@@ -348,7 +358,7 @@ func (s *Server) sendAuthResponse(conn net.Conn, success bool, message, clientID
return protocol.WriteMessage(conn, msg) return protocol.WriteMessage(conn, msg)
} }
// sendProxyConfig 发送代理配置 // sendProxyConfig 发送代理配置并等待客户端确认
func (s *Server) sendProxyConfig(session *yamux.Session, rules []protocol.ProxyRule) error { func (s *Server) sendProxyConfig(session *yamux.Session, rules []protocol.ProxyRule) error {
stream, err := session.Open() stream, err := session.Open()
if err != nil { if err != nil {
@@ -361,7 +371,20 @@ func (s *Server) sendProxyConfig(session *yamux.Session, rules []protocol.ProxyR
if err != nil { if err != nil {
return err return err
} }
return protocol.WriteMessage(stream, msg) if err := protocol.WriteMessage(stream, msg); err != nil {
return err
}
// 等待客户端确认
ack, err := protocol.ReadMessage(stream)
if err != nil {
return fmt.Errorf("wait config ack: %w", err)
}
if ack.Type != protocol.MsgTypeProxyReady {
return fmt.Errorf("unexpected ack type: %d", ack.Type)
}
return nil
} }
// registerClient 注册客户端 // registerClient 注册客户端
@@ -573,16 +596,24 @@ func (s *Server) sendHeartbeat(cs *ClientSession) bool {
} }
// GetClientStatus 获取客户端状态 // GetClientStatus 获取客户端状态
func (s *Server) GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientOS, clientArch, clientVersion string) { func (s *Server) GetClientStatus(clientID string) (online bool, lastPing, remoteAddr, clientName, clientOS, clientArch, clientVersion string) {
s.mu.RLock() s.mu.RLock()
defer s.mu.RUnlock() defer s.mu.RUnlock()
if cs, ok := s.clients[clientID]; ok { if cs, ok := s.clients[clientID]; ok {
cs.mu.Lock() cs.mu.Lock()
defer cs.mu.Unlock() defer cs.mu.Unlock()
return true, cs.LastPing.Format(time.RFC3339), cs.RemoteAddr, cs.OS, cs.Arch, cs.Version return true, cs.LastPing.Format(time.RFC3339), cs.RemoteAddr, cs.Name, cs.OS, cs.Arch, cs.Version
} }
return false, "", "", "", "", "" return false, "", "", "", "", "", ""
}
// IsClientOnline 检查客户端是否在线
func (s *Server) IsClientOnline(clientID string) bool {
s.mu.RLock()
defer s.mu.RUnlock()
_, ok := s.clients[clientID]
return ok
} }
// GetClientPluginStatus 获取客户端插件运行状态 // GetClientPluginStatus 获取客户端插件运行状态
@@ -633,6 +664,7 @@ func (s *Server) GetAllClientStatus() map[string]struct {
Online bool Online bool
LastPing string LastPing string
RemoteAddr string RemoteAddr string
Name string
OS string OS string
Arch string Arch string
Version string Version string
@@ -649,6 +681,7 @@ func (s *Server) GetAllClientStatus() map[string]struct {
Online bool Online bool
LastPing string LastPing string
RemoteAddr string RemoteAddr string
Name string
OS string OS string
Arch string Arch string
Version string Version string
@@ -660,6 +693,7 @@ func (s *Server) GetAllClientStatus() map[string]struct {
Online bool Online bool
LastPing string LastPing string
RemoteAddr string RemoteAddr string
Name string
OS string OS string
Arch string Arch string
Version string Version string
@@ -667,6 +701,7 @@ func (s *Server) GetAllClientStatus() map[string]struct {
Online: true, Online: true,
LastPing: cs.LastPing.Format(time.RFC3339), LastPing: cs.LastPing.Format(time.RFC3339),
RemoteAddr: cs.RemoteAddr, RemoteAddr: cs.RemoteAddr,
Name: cs.Name,
OS: cs.OS, OS: cs.OS,
Arch: cs.Arch, Arch: cs.Arch,
Version: cs.Version, Version: cs.Version,

View File

@@ -87,6 +87,7 @@ type Message struct {
type AuthRequest struct { type AuthRequest struct {
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
Token string `json:"token"` Token string `json:"token"`
Name string `json:"name,omitempty"` // 客户端名称(主机名)
OS string `json:"os,omitempty"` // 客户端操作系统 OS string `json:"os,omitempty"` // 客户端操作系统
Arch string `json:"arch,omitempty"` // 客户端架构 Arch string `json:"arch,omitempty"` // 客户端架构
Version string `json:"version,omitempty"` // 客户端版本 Version string `json:"version,omitempty"` // 客户端版本

View File

@@ -660,11 +660,12 @@ const handleDeletePlugin = (plugin: ClientPlugin) => {
刷新 刷新
</button> </button>
</div> </div>
<div class="card-body"> <div class="card-body system-stats-body">
<div v-if="!systemStats" class="empty-hint"> <Transition name="fade-slide" mode="out-in">
{{ loadingStats ? '加载中...' : '点击刷新获取状态' }} <div v-if="!systemStats" class="empty-hint" key="empty">
</div> {{ loadingStats ? '加载中...' : '点击刷新获取状态' }}
<template v-else> </div>
<div v-else class="system-stats-content" key="stats">
<div class="system-stat-item"> <div class="system-stat-item">
<span class="system-stat-label">CPU</span> <span class="system-stat-label">CPU</span>
<div class="progress-bar"> <div class="progress-bar">
@@ -692,7 +693,8 @@ const handleDeletePlugin = (plugin: ClientPlugin) => {
<div class="system-stat-detail"> <div class="system-stat-detail">
{{ formatBytes(systemStats.disk_used) }} / {{ formatBytes(systemStats.disk_total) }} {{ formatBytes(systemStats.disk_used) }} / {{ formatBytes(systemStats.disk_total) }}
</div> </div>
</template> </div>
</Transition>
</div> </div>
</div> </div>
@@ -917,9 +919,54 @@ const handleDeletePlugin = (plugin: ClientPlugin) => {
padding: 32px; padding: 32px;
} }
/* Hide particles */ /* Particles */
.particles { .particles {
display: none; position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
z-index: 0;
}
.particle {
position: absolute;
border-radius: 50%;
opacity: 0.15;
filter: blur(60px);
animation: float 20s ease-in-out infinite;
}
.particle-1 {
width: 350px;
height: 350px;
background: var(--color-accent);
top: -80px;
right: -80px;
}
.particle-2 {
width: 280px;
height: 280px;
background: #8b5cf6;
bottom: -40px;
left: -40px;
animation-delay: -5s;
}
.particle-3 {
width: 220px;
height: 220px;
background: var(--color-success);
top: 40%;
left: 30%;
animation-delay: -10s;
}
@keyframes float {
0%, 100% { transform: translate(0, 0) scale(1); }
25% { transform: translate(30px, -30px) scale(1.05); }
50% { transform: translate(-20px, 20px) scale(0.95); }
75% { transform: translate(-30px, -20px) scale(1.02); }
} }
.client-content { .client-content {
@@ -1042,6 +1089,7 @@ const handleDeletePlugin = (plugin: ClientPlugin) => {
display: grid; display: grid;
grid-template-columns: 300px 1fr; grid-template-columns: 300px 1fr;
gap: 24px; gap: 24px;
align-items: start;
} }
@media (max-width: 900px) { @media (max-width: 900px) {
@@ -1525,6 +1573,31 @@ const handleDeletePlugin = (plugin: ClientPlugin) => {
height: 16px; height: 16px;
} }
/* System Stats Transition */
.system-stats-body {
overflow: hidden;
}
.system-stats-content {
display: flex;
flex-direction: column;
}
.fade-slide-enter-active,
.fade-slide-leave-active {
transition: all 0.3s ease;
}
.fade-slide-enter-from {
opacity: 0;
transform: translateY(-10px);
}
.fade-slide-leave-to {
opacity: 0;
transform: translateY(10px);
}
/* System Stats */ /* System Stats */
.system-stat-item { .system-stat-item {
display: flex; display: flex;

View File

@@ -243,7 +243,52 @@ onMounted(() => {
/* Hide particles */ /* Hide particles */
.particles { .particles {
display: none; position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
z-index: 0;
}
.particle {
position: absolute;
border-radius: 50%;
opacity: 0.15;
filter: blur(60px);
animation: float 20s ease-in-out infinite;
}
.particle-1 {
width: 350px;
height: 350px;
background: var(--color-accent);
top: -80px;
right: -80px;
}
.particle-2 {
width: 280px;
height: 280px;
background: #8b5cf6;
bottom: -40px;
left: -40px;
animation-delay: -5s;
}
.particle-3 {
width: 220px;
height: 220px;
background: var(--color-success);
top: 40%;
left: 30%;
animation-delay: -10s;
}
@keyframes float {
0%, 100% { transform: translate(0, 0) scale(1); }
25% { transform: translate(30px, -30px) scale(1.05); }
50% { transform: translate(-20px, 20px) scale(0.95); }
75% { transform: translate(-30px, -20px) scale(1.02); }
} }
.settings-content { .settings-content {