feat: Updates-Tab, Aufgaben-Tab ProxmoxPanel, security_only Tasks, 3x Netzwerk-Charts, Updates-Spalte Übersicht, dist-upgrade, DeleteAgent cascades metrics
This commit is contained in:
+106
-1
@@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -40,6 +41,10 @@ func (h *Handler) HandleCommand(msg Message) {
|
||||
return
|
||||
case "agent_update":
|
||||
response = h.handleAgentUpdate(msg)
|
||||
case "update_check":
|
||||
response = h.handleUpdateCheck(msg)
|
||||
case "update":
|
||||
response = h.handleUpdate(msg)
|
||||
case "pty_start":
|
||||
response = h.handlePTYStart(msg)
|
||||
case "pty_stop":
|
||||
@@ -320,4 +325,104 @@ func (h *Handler) runCommand(command string, timeoutSec int) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, "/bin/sh", "-c", command)
|
||||
output, err := cmd.CombinedOutput()
|
||||
return string(output), err
|
||||
}
|
||||
}
|
||||
// handleUpdateCheck: apt update + Liste verfügbarer Pakete zurückgeben
|
||||
func (h *Handler) handleUpdateCheck(msg Message) Message {
|
||||
var response Message
|
||||
response.Type = "response"
|
||||
response.ID = msg.ID
|
||||
|
||||
log.Println("Update-Check gestartet (apt update)...")
|
||||
|
||||
// apt update (Paketlisten aktualisieren)
|
||||
_, err := h.runCommand("DEBIAN_FRONTEND=noninteractive apt-get update -q 2>&1", 120)
|
||||
if err != nil {
|
||||
log.Printf("apt update Fehler: %v", err)
|
||||
// Fehler ignorieren, apt update gibt oft non-zero bei Warnings zurück
|
||||
}
|
||||
|
||||
// Verfügbare Updates abfragen
|
||||
output, _ := h.runCommand("LC_ALL=C apt list --upgradable 2>/dev/null", 60)
|
||||
|
||||
// Security-Updates separat zählen
|
||||
secOutput, _ := h.runCommand("LC_ALL=C apt list --upgradable 2>/dev/null | grep -c security || true", 30)
|
||||
secCount := 0
|
||||
fmt.Sscanf(strings.TrimSpace(secOutput), "%d", &secCount)
|
||||
|
||||
// Pakete zählen (Zeilen ohne "Listing..." und Leerzeilen)
|
||||
lines := strings.Split(output, "\n")
|
||||
pkgCount := 0
|
||||
for _, l := range lines {
|
||||
l = strings.TrimSpace(l)
|
||||
if l != "" && !strings.HasPrefix(l, "Listing") && !strings.HasPrefix(l, "WARNING") {
|
||||
pkgCount++
|
||||
}
|
||||
}
|
||||
|
||||
response.Status = "ok"
|
||||
response.Data = map[string]interface{}{
|
||||
"update_available": pkgCount > 0,
|
||||
"pending_count": pkgCount,
|
||||
"security_count": secCount,
|
||||
"output": output,
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// handleUpdate: apt-get upgrade ausführen
|
||||
func (h *Handler) handleUpdate(msg Message) Message {
|
||||
var response Message
|
||||
response.Type = "response"
|
||||
response.ID = msg.ID
|
||||
|
||||
reboot := false
|
||||
if r, ok := msg.Params["reboot"].(bool); ok {
|
||||
reboot = r
|
||||
}
|
||||
securityOnly := false
|
||||
if s, ok := msg.Params["security_only"].(bool); ok {
|
||||
securityOnly = s
|
||||
}
|
||||
|
||||
log.Printf("Update gestartet (reboot=%v, security_only=%v)", reboot, securityOnly)
|
||||
|
||||
// apt update
|
||||
h.runCommand("DEBIAN_FRONTEND=noninteractive apt-get update -q 2>&1", 120)
|
||||
|
||||
// apt-get upgrade oder nur Security-Updates
|
||||
var upgradeCmd string
|
||||
if securityOnly {
|
||||
upgradeCmd = `DEBIAN_FRONTEND=noninteractive apt-get install -y --only-upgrade \
|
||||
$(LC_ALL=C apt list --upgradable 2>/dev/null | grep security | cut -d/ -f1 | tr '\n' ' ') 2>&1`
|
||||
} else {
|
||||
// dist-upgrade statt upgrade: löst auch neue Abhängigkeiten auf (nötig für Proxmox/PVE-Pakete)
|
||||
upgradeCmd = "DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y 2>&1"
|
||||
}
|
||||
|
||||
output, err := h.runCommand(upgradeCmd, 900)
|
||||
if err != nil {
|
||||
log.Printf("apt upgrade Fehler: %v", err)
|
||||
response.Status = "error"
|
||||
response.Error = fmt.Sprintf("Update fehlgeschlagen: %v", err)
|
||||
response.Data = map[string]interface{}{"output": output}
|
||||
return response
|
||||
}
|
||||
|
||||
log.Println("Update abgeschlossen")
|
||||
response.Status = "ok"
|
||||
response.Data = map[string]interface{}{
|
||||
"message": "Update erfolgreich",
|
||||
"output": output,
|
||||
"reboot": reboot,
|
||||
}
|
||||
|
||||
if reboot {
|
||||
log.Println("Reboot nach Update in 10 Sekunden...")
|
||||
go func() {
|
||||
time.Sleep(10 * time.Second)
|
||||
exec.Command("/sbin/shutdown", "-r", "now").Run()
|
||||
}()
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user