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:
@@ -8,79 +8,111 @@ import (
|
||||
type UpdateInfo struct {
|
||||
UpdateAvailable bool `json:"update_available"`
|
||||
PendingCount int `json:"pending_count"`
|
||||
SecurityCount int `json:"security_count"`
|
||||
Updates []PendingUpdateInfo `json:"updates"`
|
||||
}
|
||||
|
||||
type PendingUpdateInfo struct {
|
||||
Package string `json:"package"`
|
||||
Arch string `json:"arch"`
|
||||
CurrentVer string `json:"current_version"`
|
||||
NewVer string `json:"new_version"`
|
||||
Repository string `json:"repository"`
|
||||
Security bool `json:"security"`
|
||||
}
|
||||
|
||||
func CollectUpdates() *UpdateInfo {
|
||||
updates := &UpdateInfo{
|
||||
UpdateAvailable: false,
|
||||
PendingCount: 0,
|
||||
SecurityCount: 0,
|
||||
Updates: []PendingUpdateInfo{},
|
||||
}
|
||||
|
||||
// apt list --upgradable 2>/dev/null
|
||||
|
||||
// apt list --upgradable, LC_ALL=C erzwingt englische Ausgabe
|
||||
cmd := exec.Command("/usr/bin/apt", "list", "--upgradable")
|
||||
cmd.Env = append(cmd.Env, "LC_ALL=C", "LANG=C", "PATH=/usr/bin:/bin")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
// Fallback: apt-check falls verfügbar
|
||||
return collectUpdatesAptCheck()
|
||||
}
|
||||
|
||||
|
||||
lines := strings.Split(string(output), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.HasPrefix(line, "WARNING:") || strings.HasPrefix(line, "Listing...") {
|
||||
continue
|
||||
}
|
||||
|
||||
// Format: package/suite version [upgradable from: old-version]
|
||||
// Beispiel: curl/focal-updates 7.68.0-1ubuntu2.7 amd64 [upgradable from: 7.68.0-1ubuntu2.6]
|
||||
|
||||
|
||||
// Format: package/suite new-version arch [upgradable from: old-version]
|
||||
// Beispiel: curl/focal-security 7.68.0-1ubuntu2.7 amd64 [upgradable from: 7.68.0-1ubuntu2.6]
|
||||
if !strings.Contains(line, "[upgradable from:") {
|
||||
continue
|
||||
}
|
||||
|
||||
// Package-Name extrahieren (bis zum ersten /)
|
||||
|
||||
// Package-Name und Suite trennen
|
||||
parts := strings.SplitN(line, "/", 2)
|
||||
if len(parts) < 2 {
|
||||
continue
|
||||
}
|
||||
packageName := parts[0]
|
||||
|
||||
// Neue Version extrahieren (zwischen / und [upgradable from:)
|
||||
|
||||
remaining := parts[1]
|
||||
beforeUpgradable := strings.Split(remaining, " [upgradable from:")
|
||||
// Suite ist das erste Wort vor dem Leerzeichen
|
||||
suiteParts := strings.SplitN(remaining, " ", 2)
|
||||
suite := suiteParts[0]
|
||||
// Repository: letzter Teil der Suite (z.B. "focal-security/main" → "main")
|
||||
// oder einfach die Suite selbst
|
||||
repository := suite
|
||||
if idx := strings.LastIndex(suite, "/"); idx >= 0 {
|
||||
repository = suite[idx+1:]
|
||||
}
|
||||
|
||||
// Security erkennen: Suite enthält "security"
|
||||
// Beispiel: bookworm-security, trixie-security, buster/updates
|
||||
suiteLower := strings.ToLower(suite)
|
||||
isSecurity := strings.Contains(suiteLower, "security") ||
|
||||
strings.HasSuffix(suiteLower, "/updates")
|
||||
|
||||
// Rest nach Suite parsen: "new-version arch [upgradable from: old-version]"
|
||||
afterSuite := ""
|
||||
if len(suiteParts) > 1 {
|
||||
afterSuite = suiteParts[1]
|
||||
}
|
||||
|
||||
beforeUpgradable := strings.SplitN(afterSuite, " [upgradable from:", 2)
|
||||
if len(beforeUpgradable) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
// Neue Version ist im ersten Teil, aber wir müssen die Architektur entfernen
|
||||
versionParts := strings.Fields(beforeUpgradable[0])
|
||||
if len(versionParts) < 1 {
|
||||
continue
|
||||
|
||||
versionAndArch := strings.Fields(strings.TrimSpace(beforeUpgradable[0]))
|
||||
newVersion := ""
|
||||
arch := ""
|
||||
if len(versionAndArch) >= 1 {
|
||||
newVersion = versionAndArch[0]
|
||||
}
|
||||
newVersion := versionParts[0]
|
||||
|
||||
// Alte Version extrahieren (zwischen "from:" und "]")
|
||||
oldVersionPart := beforeUpgradable[1]
|
||||
oldVersion := strings.TrimSuffix(strings.TrimSpace(oldVersionPart), "]")
|
||||
|
||||
if len(versionAndArch) >= 2 {
|
||||
arch = versionAndArch[1]
|
||||
}
|
||||
|
||||
oldVersion := strings.TrimSuffix(strings.TrimSpace(beforeUpgradable[1]), "]")
|
||||
|
||||
updates.Updates = append(updates.Updates, PendingUpdateInfo{
|
||||
Package: packageName,
|
||||
Arch: arch,
|
||||
CurrentVer: oldVersion,
|
||||
NewVer: newVersion,
|
||||
Repository: repository,
|
||||
Security: isSecurity,
|
||||
})
|
||||
if isSecurity {
|
||||
updates.SecurityCount++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updates.PendingCount = len(updates.Updates)
|
||||
updates.UpdateAvailable = updates.PendingCount > 0
|
||||
|
||||
|
||||
return updates
|
||||
}
|
||||
|
||||
@@ -89,34 +121,34 @@ func collectUpdatesAptCheck() *UpdateInfo {
|
||||
updates := &UpdateInfo{
|
||||
UpdateAvailable: false,
|
||||
PendingCount: 0,
|
||||
SecurityCount: 0,
|
||||
Updates: []PendingUpdateInfo{},
|
||||
}
|
||||
|
||||
// /usr/lib/update-notifier/apt-check
|
||||
|
||||
cmd := exec.Command("/usr/lib/update-notifier/apt-check")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
// Noch ein Fallback: apt-get -s upgrade
|
||||
return collectUpdatesAptGetSimulate()
|
||||
}
|
||||
|
||||
// apt-check gibt "updates;security-updates" auf stderr aus
|
||||
|
||||
result := strings.TrimSpace(string(output))
|
||||
parts := strings.SplitN(result, ";", 2)
|
||||
|
||||
|
||||
if len(parts) >= 1 && parts[0] != "0" {
|
||||
// Packages verfügbar, aber keine Details ohne apt list
|
||||
updates.UpdateAvailable = true
|
||||
updates.PendingCount = 1 // Platzhalter
|
||||
updates.PendingCount = 1
|
||||
updates.Updates = []PendingUpdateInfo{
|
||||
{
|
||||
Package: "system-updates",
|
||||
Arch: "",
|
||||
CurrentVer: "various",
|
||||
NewVer: "available",
|
||||
Repository: "unknown",
|
||||
Security: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return updates
|
||||
}
|
||||
|
||||
@@ -125,38 +157,36 @@ func collectUpdatesAptGetSimulate() *UpdateInfo {
|
||||
updates := &UpdateInfo{
|
||||
UpdateAvailable: false,
|
||||
PendingCount: 0,
|
||||
SecurityCount: 0,
|
||||
Updates: []PendingUpdateInfo{},
|
||||
}
|
||||
|
||||
// apt-get -s upgrade (simulate)
|
||||
|
||||
cmd := exec.Command("/usr/bin/apt-get", "-s", "upgrade")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return updates
|
||||
}
|
||||
|
||||
|
||||
lines := strings.Split(string(output), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
// Suche nach "Inst package-name" Zeilen
|
||||
if strings.HasPrefix(line, "Inst ") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) >= 3 {
|
||||
packageName := fields[1]
|
||||
|
||||
// Sehr simple Erkennung, bessere Parsing schwierig ohne apt list
|
||||
updates.Updates = append(updates.Updates, PendingUpdateInfo{
|
||||
Package: packageName,
|
||||
Package: fields[1],
|
||||
Arch: "",
|
||||
CurrentVer: "unknown",
|
||||
NewVer: "available",
|
||||
Repository: "unknown",
|
||||
Security: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updates.PendingCount = len(updates.Updates)
|
||||
updates.UpdateAvailable = updates.PendingCount > 0
|
||||
|
||||
|
||||
return updates
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user