feat(agent): v0.3.9 sync, UI details, self-update, centralized version

- Add agent/server startup sync (sync/sync_response)
- Centralize agent version in agent/VERSION + expose /api/agent/version
- Display agent version, nodeId and server version in local UI
- Add agent self-update detection/download/restart via helper scripts
- Run start/stop/delete/reset handlers in goroutines to avoid WebSocket blocking
- Update dashboard download links and SUIVI_VPN_ONDEMAND.md
- Document Podman stays installer-managed, not agent-updated
This commit is contained in:
EduBox Dev
2026-06-27 21:11:20 +00:00
parent cf8b66340a
commit e946b22a42
14 changed files with 613 additions and 59 deletions
+32
View File
@@ -56,6 +56,8 @@ func startUI(dataDir, nodeID, serverAddr string) {
return
}
// Expose a merged view with the agent version for the UI.
serverVersion := getServerAgentVersion()
updateAvailable := serverVersion != "" && serverVersion != version
response := map[string]interface{}{
"server": cfg.Server,
"headscale_url": cfg.HeadscaleURL,
@@ -63,6 +65,8 @@ func startUI(dataDir, nodeID, serverAddr string) {
"node_id": cfg.NodeID,
"data_dir": cfg.DataDir,
"version": version,
"server_version": serverVersion,
"update_available": updateAvailable,
}
json.NewEncoder(w).Encode(response)
case http.MethodPost:
@@ -104,6 +108,34 @@ func startUI(dataDir, nodeID, serverAddr string) {
}()
})
http.HandleFunc("/api/update", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
cfg, _, err := loadOrCreateConfig(dataDir)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
go func() {
broadcastUI(map[string]interface{}{
"action": "update_progress",
"percent": "10",
"message": "Téléchargement de la mise à jour...",
})
if err := startAgentUpdate(dataDir, cfg.Server); err != nil {
log.Printf("Agent update failed: %v", err)
broadcastUI(map[string]interface{}{
"action": "update_progress",
"percent": "0",
"message": "Échec de la mise à jour : " + err.Error(),
})
}
}()
w.WriteHeader(http.StatusNoContent)
})
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {