From 7217974395a0114cbcf53abfef45e9f9b454488e Mon Sep 17 00:00:00 2001 From: ngfchl Date: Sat, 20 Jun 2026 00:13:13 +0800 Subject: [PATCH] =?UTF-8?q?update.=20=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E4=BB=A5=E5=8F=8A=20HTML=20=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/main.go | 69 +- cmd/server/templates/index.html | 2067 +++++++------------------------ server.yaml | 4 +- 3 files changed, 478 insertions(+), 1662 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 72b1e6b..1b39f2b 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -71,26 +71,22 @@ func resolvePath(baseDir, p string) string { // 配置结构 // ═══════════════════════════════════════════════ -type AuthConfig struct { - MinerID string `yaml:"miner_id"` - Password string `yaml:"password"` -} - type ServerConfig struct { - Listen string `yaml:"listen"` - DevicesFile string `yaml:"devices_file"` - Auth AuthConfig `yaml:"auth"` - MinerUID string `yaml:"miner_uid"` - MinerAPIBase string `yaml:"miner_api_base"` - FetchInterval int `yaml:"fetch_interval"` - HistoryMax int `yaml:"history_max"` + Listen string `yaml:"listen"` + DevicesFile string `yaml:"devices_file"` + MinerUID string `yaml:"miner_uid"` + Password string `yaml:"password"` + MinerAPIBase string `yaml:"miner_api_base"` + FetchInterval int `yaml:"fetch_interval"` + HistoryMax int `yaml:"history_max"` } func defaultConfig() ServerConfig { return ServerConfig{ Listen: ":8080", DevicesFile: "data/devices.yaml", - Auth: AuthConfig{MinerID: "admin", Password: "123456"}, + MinerUID: "", + Password: "123456", MinerAPIBase: "https://pool.kryptex.com/prl/api/v3/miner/workers", FetchInterval: 30, HistoryMax: 200, @@ -195,11 +191,8 @@ func fillDefaults(cfg *ServerConfig) { if cfg.DevicesFile == "" { cfg.DevicesFile = "data/devices.yaml" } - if cfg.Auth.MinerID == "" { - cfg.Auth.MinerID = "admin" - } - if cfg.Auth.Password == "" { - cfg.Auth.Password = "123456" + if cfg.Password == "" { + cfg.Password = "123456" } if cfg.MinerAPIBase == "" { cfg.MinerAPIBase = "https://pool.kryptex.com/prl/api/v3/miner/workers" @@ -318,15 +311,16 @@ type BrowserCmd struct { // ═══════════════════════════════════════════════ type Hub struct { - mu sync.RWMutex - fileMu sync.Mutex - records map[string]*DeviceRecord - live map[string]json.RawMessage - monitors map[*websocket.Conn]struct{} - miningData map[string]*MiningData - hashHist map[string][]HashratePoint - devicesAbs string - config ServerConfig + mu sync.RWMutex + fileMu sync.Mutex + records map[string]*DeviceRecord + live map[string]json.RawMessage + monitors map[*websocket.Conn]struct{} + miningData map[string]*MiningData + hashHist map[string][]HashratePoint + devicesAbs string + config ServerConfig + lastWorkerCount int } func NewHub(cfg ServerConfig, devicesAbs string) *Hub { @@ -623,7 +617,13 @@ func (h *Hub) fetchMinerData(url string) { h.mu.RUnlock() h.broadcast(BrowserMsg{Type: "mining", Machine: w.Worker, Mining: md, History: hist}) } - logInfo("miner", "更新 %d 个 worker", len(apiResp.Results)) + h.mu.Lock() + cnt := len(apiResp.Results) + if cnt != h.lastWorkerCount { + logInfo("miner", "worker 数量变更: %d → %d", h.lastWorkerCount, cnt) + h.lastWorkerCount = cnt + } + h.mu.Unlock() } // ═══════════════════════════════════════════════ @@ -639,6 +639,13 @@ var upgrader = websocket.Upgrader{ func handleAgent(conn *websocket.Conn, hub *Hub) { defer conn.Close() addr := conn.RemoteAddr().String() + hub.mu.RLock() + monCnt := len(hub.monitors) + hub.mu.RUnlock() + if monCnt == 0 { + logInfo("agent", "拒绝 %s (无浏览器连接)", addr) + return + } logInfo("agent+", "%s", addr) defer logInfo("agent-", "%s", addr) for { @@ -677,7 +684,7 @@ func handleMonitor(conn *websocket.Conn, hub *Hub) { } // 校验 - if cmd.MinerID == hub.config.Auth.MinerID && cmd.Password == hub.config.Auth.Password { + if cmd.MinerID == hub.config.MinerUID && cmd.Password == hub.config.Password { authOK = true break } @@ -784,9 +791,9 @@ func main() { if len(uid) > 22 { uid = uid[:22] + "..." } - fmt.Printf(" ║ Miner : %-29s║\n", uid) + fmt.Printf(" ║ Miner UID : %-29s║\n", uid) } else { - fmt.Println(" ║ Miner : 未配置 ║") + fmt.Println(" ║ Miner UID : 未配置 ║") } fmt.Println(" ╚═══════════════════════════════════════════╝") fmt.Println() diff --git a/cmd/server/templates/index.html b/cmd/server/templates/index.html index af38b47..6ff1f3e 100644 --- a/cmd/server/templates/index.html +++ b/cmd/server/templates/index.html @@ -4,1653 +4,464 @@ Hardware Monitor - - + + + - - -
- -
- - - -