diff --git a/changelog/highlights/299.json b/changelog/highlights/299.json new file mode 100644 index 000000000..5c888bdab --- /dev/null +++ b/changelog/highlights/299.json @@ -0,0 +1,29 @@ +{ + "de": { + "*": "Die Versionsseite zeigt Betriebssystem, Kernel und Systemprogramme des Nodes mit ihrer Version" + }, + "en": { + "*": "Show system versions on the versions page" + }, + "tour": { + "*": { + "steps": [ + { + "device": "any", + "need": "edit_setup", + "page": "versions", + "panel": "settings-panel", + "target": "versions-system", + "text": { + "de": "Hier stehen Betriebssystem, Kernel und die Systemprogramme des Nodes mit ihrer Version. Liegt ein Programm hinter der erwarteten Version, ist es als veraltet markiert.", + "en": "This card lists the operating system, the kernel and the system programs of the node with their version. A program behind the expected version is marked as outdated." + }, + "title": { + "de": "Systemversionen", + "en": "System versions" + } + } + ] + } + } +} diff --git a/dashboard/CHANGELOG.md b/dashboard/CHANGELOG.md index 3c231ef2d..5a8511ba6 100644 --- a/dashboard/CHANGELOG.md +++ b/dashboard/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v0.11.22-pre.36 (2026-11-06) +## v0.11.22-pre.37 (2026-11-06) ### Features @@ -35,6 +35,11 @@ - **autolearn:** The node records minute values and keeps every regulator step as a base for learning (#293) (19e65e7) - **autolearn:** Automation suggestions for surplus and load shifts are checked against your data (#295) (6c255ad) - **autolearn:** Learning functions can take minute values from Home Assistant (#294) (7aa657e) +- **monitoring:** Monitoring shows the forecast check, a year comparison and the learned values as a usual day (#297) (4f93975) +- **dashboard:** read the system package versions (8d025b3) +- **dashboard:** serve system versions to setup users (8e71270) +- **dashboard:** show the kernel and the Debian point release (93d002d) +- **dashboard:** show system versions on the versions page (#299) - **autolearn:** expose forecast days and the rules that read a learned value (25d731e) - **demo:** seed a forecast check and a year of season weeks (4a39a77) - **monitoring:** serve the forecast check and the season weeks from the api (d11383f) @@ -49,7 +54,6 @@ - **monitoring:** show learned values as a usual day (1749c86) - **monitoring:** style the usual day (72d192a) - **monitoring:** add a tour target to the forecast tab (ca4f7a0) -- **monitoring:** Monitoring shows the forecast check, a year comparison and the learned values as a usual day (#297) - **learnrec:** fetch minute values from Home Assistant through the companion (97e2665) - **learnrec:** pause the own recording while Home Assistant delivers minutes (4086c45) - **learnrec:** read own minutes first, then Home Assistant, and fetch gaps before the heavy run (44ee05d) @@ -350,6 +354,7 @@ - **storage:** wipe old file system signatures before formatting a stick (#245) (aeafa63) - **storage:** set up, back up and replug the additional drive reliably (#247) (b668394) - **automations:** correct the learning feature after the full review (#296) (88f3c75) +- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437) - **monitoring:** keep texts and locale out of the insight model (57e2a44) - **monitoring:** show the legend items for statistics weeks and gaps (82cde6e) - **monitoring:** route locale formatting through I18n (a664db2) @@ -358,7 +363,6 @@ - **monitoring:** keep the forecast view inside the screen and polish the usual day (7751f73) - **monitoring:** keep one gap between the cards of the forecast and learned views (3168e41) - **monitoring:** let the forecast view use the full tab width (2d6749e) -- **backup:** A restore stays in place even when the battery state cannot be written (#288) (e5c5437) - **learning:** reset every learned state through one registry (594282c) - **autolearn:** survive a detector panic and keep results of finished devices (102cad0) - **autolearn:** keep harm first, cap open suggestions and give every value a spread (bde4c6a) @@ -514,6 +518,7 @@ ### Tests +- **demo:** fake the system packages for the versions page (ca2dc1e) - **autolearn:** keep the cycle test window open until today (ab438d5) - **webui:** follow the template cache-bust mark (c30a3db) - **smoke:** probe the live push on the house load (5382341) @@ -536,6 +541,8 @@ ### Chores +- **dashboard:** bump the cache-bust marks for the system card (31ecbb8) +- **dashboard:** move the cache history rows to the current pre-release (8a60da5) - **monitoring:** drop the texts of the old learned values list (d6da484) - **webui:** bump cache marks for the monitoring assets (b29e739) - **webui:** bump the cache-bust marks for the learning review fixes (6c82592) diff --git a/dashboard/VERSION b/dashboard/VERSION index 6c762875e..61e24d2f4 100644 --- a/dashboard/VERSION +++ b/dashboard/VERSION @@ -1 +1 @@ -v0.11.22-pre.36 +v0.11.22-pre.37 diff --git a/dashboard/cmd/dashboard/main.go b/dashboard/cmd/dashboard/main.go index 16a1b448c..db2191282 100644 --- a/dashboard/cmd/dashboard/main.go +++ b/dashboard/cmd/dashboard/main.go @@ -1465,6 +1465,10 @@ func main() { Usage: storageUsage, }, InstallerStateDir: installerStateDir, + DpkgStatusPath: os.Getenv("ENERGY_NODE_DPKG_STATUS"), + OSReleasePath: os.Getenv("ENERGY_NODE_OS_RELEASE"), + DebianVersionPath: os.Getenv("ENERGY_NODE_DEBIAN_VERSION"), + KernelReleasePath: os.Getenv("ENERGY_NODE_KERNEL_RELEASE"), AppConfigPath: *configPath, BridgeTargetPath: cfg.Dashboard.MosquittoBridgeTarget, Tailscale: tailscaleClient, diff --git a/dashboard/internal/httpapi/httpapi.go b/dashboard/internal/httpapi/httpapi.go index 12a7db6b9..ca6600cfb 100644 --- a/dashboard/internal/httpapi/httpapi.go +++ b/dashboard/internal/httpapi/httpapi.go @@ -219,6 +219,15 @@ type RouterDependencies struct { // (installed-manifest.json, selection.json, changelog.json), aus dem die // Versionsseite liest. Leer heisst versions.DefaultStateDir. InstallerStateDir string + // DpkgStatusPath und OSReleasePath ersetzen fuer Demo und Smoke-Test die + // Dateien der Systemkarte der Versionsseite. Leer heisst die Vorgabe aus + // internal/versions. + DpkgStatusPath string + OSReleasePath string + // DebianVersionPath und KernelReleasePath ersetzen die Dateien mit dem + // Punkt-Release und dem laufenden Kernel. Leer heisst die Vorgabe. + DebianVersionPath string + KernelReleasePath string // Version ist die aus dashboard/VERSION plus Branch-Suffix gebaute // Versionskennung (siehe main.buildVersion), leer bzw. "dev" ausserhalb // von Release-Builds. @@ -355,7 +364,10 @@ func NewRouterWithDependencies(reg *registry.Registry, configs *config.Manager, if stateDir == "" { stateDir = versions.DefaultStateDir } - g.HandleFunc("/api/v1/versions", handleVersions(stateDir, dependencies.Version)) + g.HandleFunc("/api/v1/versions", handleVersions(stateDir, dependencies.Version, versions.SystemSources{ + DpkgStatus: dependencies.DpkgStatusPath, OSRelease: dependencies.OSReleasePath, + DebianVersion: dependencies.DebianVersionPath, KernelRelease: dependencies.KernelReleasePath, StateDir: stateDir, + })) g.HandleFunc("/api/v1/changelog", handleChangelog(stateDir)) g.HandleFunc("/api/v1/changelog/highlights", handleChangelogHighlights(stateDir)) if dependencies.UpdatesCache != nil { diff --git a/dashboard/internal/httpapi/versions.go b/dashboard/internal/httpapi/versions.go index b3d1f759d..ffbe5b9dd 100644 --- a/dashboard/internal/httpapi/versions.go +++ b/dashboard/internal/httpapi/versions.go @@ -5,6 +5,7 @@ import ( "net/http" "strconv" + "github.com/Developer-Simon/energy-node-dashboard/internal/auth" "github.com/Developer-Simon/energy-node-dashboard/internal/versions" "github.com/Developer-Simon/energy-node-webui/hostapi" ) @@ -12,7 +13,8 @@ import ( // handleVersions is GET /api/v1/versions: the bundle this node was installed // from and the version of every component in it. Readable by every signed-in // session, guests included -- it says nothing an operator may not see. -func handleVersions(stateDir, running string) http.HandlerFunc { +// The system field is the exception, see maySeeSystem. +func handleVersions(stateDir, running string, system versions.SystemSources) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { methodNotAllowed(w, http.MethodGet) @@ -23,10 +25,21 @@ func handleVersions(stateDir, running string) http.HandlerFunc { writeError(w, http.StatusInternalServerError, "versions_unreadable", "Versionsdaten konnten nicht gelesen werden") return } + if maySeeSystem(r) { + snapshot.System = versions.System(system) + } writeJSON(w, snapshot) } } +// maySeeSystem: operating system and package versions tell which known flaws +// apply, so a signed-in user needs edit_setup. Without a user in the context no +// gate applies, as before accounts existed. +func maySeeSystem(r *http.Request) bool { + user, ok := auth.UserFromContext(r.Context()) + return !ok || auth.HasRole(user, auth.RoleEditSetup) +} + // handleChangelog is GET /api/v1/changelog[?component=&bundles=]: the // installed changelog, optionally cut down to some components and to the // newest n bundle versions (0 or missing: all). diff --git a/dashboard/internal/httpapi/versions_system_test.go b/dashboard/internal/httpapi/versions_system_test.go new file mode 100644 index 000000000..6dc9c0a52 --- /dev/null +++ b/dashboard/internal/httpapi/versions_system_test.go @@ -0,0 +1,69 @@ +package httpapi + +import ( + "net/http" + "net/http/httptest" + "path/filepath" + "strings" + "testing" + + "github.com/Developer-Simon/energy-node-dashboard/internal/auth" + "github.com/Developer-Simon/energy-node-dashboard/internal/config" + "github.com/Developer-Simon/energy-node-dashboard/internal/registry" + "github.com/Developer-Simon/energy-node-dashboard/internal/settings" + "github.com/Developer-Simon/energy-node-dashboard/internal/versions" +) + +func systemTestSources(t *testing.T) versions.SystemSources { + t.Helper() + dir := t.TempDir() + writeState(t, dir, "status", "Package: caddy\nStatus: hold ok installed\nVersion: 2.6.2-5\n\n") + writeState(t, dir, "os-release", "NAME=Debian\nVERSION_ID=12\n") + writeState(t, dir, "debian_version", "12.11\n") + writeState(t, dir, "kernel", "6.12.47+rpt-rpi-v6\n") + return versions.SystemSources{ + DpkgStatus: filepath.Join(dir, "status"), OSRelease: filepath.Join(dir, "os-release"), + DebianVersion: filepath.Join(dir, "debian_version"), KernelRelease: filepath.Join(dir, "kernel"), StateDir: dir, + } +} + +func TestVersionsSystemNeedsEditSetup(t *testing.T) { + src := systemTestSources(t) + manager, err := auth.NewManager(filepath.Join(t.TempDir(), "users.json"), "admin", "secret") + if err != nil { + t.Fatal(err) + } + router := NewAuthenticatedRouter(registry.New(), config.NewManager(t.TempDir()), settings.NewStore(t.TempDir()), nil, nil, nil, nil, nil, RouterDependencies{ + Auth: manager, InstallerStateDir: src.StateDir, DpkgStatusPath: src.DpkgStatus, OSReleasePath: src.OSRelease, + DebianVersionPath: src.DebianVersion, KernelReleasePath: src.KernelRelease, + }) + + guest := getWith(router, loginAsGuest(t, router), "/api/v1/versions") + if guest.Code != http.StatusOK || strings.Contains(guest.Body.String(), `"system"`) { + t.Fatalf("guest: %d %s, want 200 without system", guest.Code, guest.Body.String()) + } + + cookie, _ := loginAsAdmin(t, router) + req := httptest.NewRequest(http.MethodGet, "/api/v1/versions", nil) + req.Header.Set("X-Forwarded-Proto", "https") + req.AddCookie(cookie) + rec := httptest.NewRecorder() + router.ServeHTTP(rec, req) + if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"id":"caddy","label":"Caddy","version":"2.6.2"`) { + t.Fatalf("admin: %d %s", rec.Code, rec.Body.String()) + } + for _, want := range []string{`"version":"12.11"`, `"id":"kernel","label":"Kernel","version":"6.12.47+rpt-rpi-v6"`} { + if !strings.Contains(rec.Body.String(), want) { + t.Fatalf("admin lacks %s: %s", want, rec.Body.String()) + } + } +} + +func TestVersionsSystemWithoutAccountsIsShown(t *testing.T) { + src := systemTestSources(t) + rec := httptest.NewRecorder() + handleVersions(src.StateDir, "v1.0.0", src)(rec, httptest.NewRequest(http.MethodGet, "/api/v1/versions", nil)) + if !strings.Contains(rec.Body.String(), `"system":[{"id":"os"`) { + t.Fatalf("body = %s", rec.Body.String()) + } +} diff --git a/dashboard/internal/versions/system.go b/dashboard/internal/versions/system.go new file mode 100644 index 000000000..987ffbe5c --- /dev/null +++ b/dashboard/internal/versions/system.go @@ -0,0 +1,232 @@ +package versions + +import ( + "bufio" + "encoding/json" + "os" + "path/filepath" + "strings" +) + +const ( + // DefaultDpkgStatus is dpkg's package database, readable by every user. + DefaultDpkgStatus = "/var/lib/dpkg/status" + // DefaultOSRelease names the distribution and its release. + DefaultOSRelease = "/etc/os-release" + // DefaultDebianVersion holds the point release, such as "12.11". + DefaultDebianVersion = "/etc/debian_version" + // DefaultKernelRelease is the release of the running kernel. + DefaultKernelRelease = "/proc/sys/kernel/osrelease" + // maxDpkgLine bounds one line of the database, far above real fields. + maxDpkgLine = 4 << 20 +) + +// SystemSources names the files System reads. An empty path means the default +// path. +type SystemSources struct { + DpkgStatus string + OSRelease string + DebianVersion string + KernelRelease string + StateDir string +} + +// SystemEntry is one row of the system card on the versions page. +type SystemEntry struct { + ID string `json:"id"` + Label string `json:"label"` + Version string `json:"version"` + Installed bool `json:"installed"` + // Pinned is the version the installed bundle pins, empty without a pin. + Pinned string `json:"pinned,omitempty"` + Outdated bool `json:"outdated"` +} + +// systemPackages are the Debian packages the node depends on, in page order. +var systemPackages = []struct{ id, label string }{ + {"caddy", "Caddy"}, + {"tailscale", "Tailscale"}, + {"mosquitto", "Mosquitto"}, + {"python3", "Python"}, +} + +// System reports the operating system, the running kernel and the system +// packages. What cannot be read is left out, so a machine without dpkg shows no +// package rows. +func System(src SystemSources) []SystemEntry { + if src.DpkgStatus == "" { + src.DpkgStatus = DefaultDpkgStatus + } + if src.OSRelease == "" { + src.OSRelease = DefaultOSRelease + } + if src.DebianVersion == "" { + src.DebianVersion = DefaultDebianVersion + } + if src.KernelRelease == "" { + src.KernelRelease = DefaultKernelRelease + } + var out []SystemEntry + if entry, ok := osEntry(src.OSRelease, src.DebianVersion); ok { + out = append(out, entry) + } + if entry, ok := kernelEntry(src.KernelRelease); ok { + out = append(out, entry) + } + installed, ok := dpkgVersions(src.DpkgStatus) + if !ok { + return out + } + pins := packagePins(src.StateDir) + for _, pkg := range systemPackages { + version, present := installed[pkg.id] + entry := SystemEntry{ID: pkg.id, Label: pkg.label, Version: upstreamVersion(version), Installed: present, Pinned: pins[pkg.id]} + entry.Outdated = present && isOlder(entry.Version, entry.Pinned) + out = append(out, entry) + } + return out +} + +// isOlder is true only when both versions start with a number and a is lower. +func isOlder(a, b string) bool { + return versionNumbers.MatchString(a) && versionNumbers.MatchString(b) && compareVersions(a, b) < 0 +} + +// upstreamVersion drops the epoch and the Debian revision of a dpkg version. +func upstreamVersion(version string) string { + if _, rest, found := strings.Cut(version, ":"); found { + version = rest + } + if i := strings.LastIndex(version, "-"); i >= 0 { + version = version[:i] + } + return version +} + +func kernelEntry(path string) (SystemEntry, bool) { + raw, err := os.ReadFile(path) + if err != nil { + return SystemEntry{}, false + } + release := strings.TrimSpace(string(raw)) + if release == "" { + return SystemEntry{}, false + } + return SystemEntry{ID: "kernel", Label: "Kernel", Version: release, Installed: true}, true +} + +// debianPointRelease returns the point release from debian_version when it +// belongs to the major release, such as "12.11" for "12". Otherwise, or when +// the file is missing, it returns "". +func debianPointRelease(path, major string) string { + if major == "" { + return "" + } + raw, err := os.ReadFile(path) + if err != nil { + return "" + } + point := strings.TrimSpace(string(raw)) + if point == major || strings.HasPrefix(point, major+".") { + return point + } + return "" +} + +func osEntry(path, debianVersionPath string) (SystemEntry, bool) { + raw, err := os.ReadFile(path) + if err != nil { + return SystemEntry{}, false + } + fields := map[string]string{} + for _, line := range strings.Split(string(raw), "\n") { + if key, value, found := strings.Cut(strings.TrimSpace(line), "="); found { + fields[key] = strings.Trim(value, `"'`) + } + } + label := fields["NAME"] + if label == "" { + label = "Linux" + } + version, codename := fields["VERSION_ID"], fields["VERSION_CODENAME"] + if point := debianPointRelease(debianVersionPath, version); point != "" { + version = point + } + switch { + case version == "": + version = codename + case codename != "": + version += " (" + codename + ")" + } + return SystemEntry{ID: "os", Label: label, Version: version, Installed: true}, true +} + +// dpkgVersions returns the version of every wanted package whose dpkg state +// ends in "installed" ("install ok installed", "hold ok installed"). ok is +// false when the database cannot be read. +func dpkgVersions(path string) (map[string]string, bool) { + file, err := os.Open(path) + if err != nil { + return nil, false + } + defer file.Close() + + wanted := map[string]bool{} + for _, pkg := range systemPackages { + wanted[pkg.id] = true + } + out := map[string]string{} + var name, status, version string + flush := func() { + state := strings.Fields(status) + if _, seen := out[name]; !seen && wanted[name] && len(state) > 0 && state[len(state)-1] == "installed" { + out[name] = version + } + name, status, version = "", "", "" + } + scanner := bufio.NewScanner(file) + scanner.Buffer(make([]byte, 64<<10), maxDpkgLine) + for scanner.Scan() { + line := scanner.Text() + if line == "" { + flush() + continue + } + // Continuation lines start with a space and match no field name. + switch key, value, _ := strings.Cut(line, ": "); key { + case "Package": + name = value + case "Status": + status = value + case "Version": + version = value + } + } + if scanner.Err() != nil { + return nil, false + } + flush() + return out, true +} + +// packagePins reads the package versions the installed bundle pins. A missing, +// old or broken manifest means no pins. +func packagePins(stateDir string) map[string]string { + out := map[string]string{} + raw, err := os.ReadFile(filepath.Join(stateDir, "installed-manifest.json")) + if err != nil { + return out + } + var manifest struct { + Packages map[string]struct { + Version string `json:"version"` + } `json:"packages"` + } + if json.Unmarshal(raw, &manifest) != nil { + return out + } + for name, pin := range manifest.Packages { + out[name] = pin.Version + } + return out +} diff --git a/dashboard/internal/versions/system_test.go b/dashboard/internal/versions/system_test.go new file mode 100644 index 000000000..9e4ffe2a0 --- /dev/null +++ b/dashboard/internal/versions/system_test.go @@ -0,0 +1,176 @@ +package versions_test + +import ( + "os" + "path/filepath" + "reflect" + "strings" + "testing" + + "github.com/Developer-Simon/energy-node-dashboard/internal/versions" +) + +const testOSRelease = "PRETTY_NAME=\"Raspbian GNU/Linux 12 (bookworm)\"\nNAME=\"Raspbian GNU/Linux\"\nVERSION_ID=\"12\"\nVERSION_CODENAME=bookworm\n" + +const testManifest = `{"version":"v0.11.20","packages":{"caddy":{"version":"2.11.9"},"tailscale":{"version":"1.62.0"}}}` + +func stanza(name, status, version string) string { + return "Package: " + name + "\nStatus: " + status + "\nVersion: " + version + "\nDescription: x\n more text\n Package: not-a-field\n\n" +} + +func systemSources(t *testing.T, dpkg, osRelease, manifest string) versions.SystemSources { + t.Helper() + dir := t.TempDir() + write := func(name, body string) string { + path := filepath.Join(dir, name) + if body != "" { + if err := os.WriteFile(path, []byte(body), 0o644); err != nil { + t.Fatal(err) + } + } + return path + } + write("installed-manifest.json", manifest) + return versions.SystemSources{ + DpkgStatus: write("status", dpkg), + OSRelease: write("os-release", osRelease), + DebianVersion: filepath.Join(dir, "debian_version"), + KernelRelease: filepath.Join(dir, "kernel"), + StateDir: dir, + } +} + +func byID(entries []versions.SystemEntry) map[string]versions.SystemEntry { + out := map[string]versions.SystemEntry{} + for _, entry := range entries { + out[entry.ID] = entry + } + return out +} + +func TestSystemListsOSAndPackagesAndMarksAnOutdatedPin(t *testing.T) { + dpkg := stanza("caddy", "hold ok installed", "2.6.2-5+deb12u1") + + stanza("tailscale", "hold ok installed", "1.62.0") + + stanza("mosquitto", "install ok installed", "1:2.0.11-1.2+deb12u1") + + stanza("python3", "install ok installed", "3.11.2-1+b1") + got := versions.System(systemSources(t, dpkg, testOSRelease, testManifest)) + want := []versions.SystemEntry{ + {ID: "os", Label: "Raspbian GNU/Linux", Version: "12 (bookworm)", Installed: true}, + {ID: "caddy", Label: "Caddy", Version: "2.6.2", Installed: true, Pinned: "2.11.9", Outdated: true}, + {ID: "tailscale", Label: "Tailscale", Version: "1.62.0", Installed: true, Pinned: "1.62.0"}, + {ID: "mosquitto", Label: "Mosquitto", Version: "2.0.11", Installed: true}, + {ID: "python3", Label: "Python", Version: "3.11.2", Installed: true}, + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("got %+v\nwant %+v", got, want) + } +} + +func TestSystemDoesNotMarkNewerEqualOrUncomparableVersions(t *testing.T) { + cases := map[string]string{"newer": "2.12.0-1", "equal with revision": "2.11.9-2", "no number": "unstable"} + for name, version := range cases { + got := byID(versions.System(systemSources(t, stanza("caddy", "install ok installed", version), "", testManifest))) + if got["caddy"].Outdated { + t.Errorf("%s: %q marked outdated", name, version) + } + } +} + +func TestSystemIgnoresPackageLeftovers(t *testing.T) { + dpkg := stanza("caddy", "deinstall ok config-files", "2.6.2-5") + stanza("tailscale", "install ok half-installed", "1.0.0") + got := byID(versions.System(systemSources(t, dpkg, "", testManifest))) + for _, id := range []string{"caddy", "tailscale"} { + entry := got[id] + if entry.Installed || entry.Version != "" || entry.Outdated || entry.Pinned == "" { + t.Errorf("%s = %+v, want not installed, no version, no mark, pin kept", id, entry) + } + } +} + +func TestSystemTakesTheInstalledStanzaOfAMultiarchPackage(t *testing.T) { + dpkg := stanza("python3", "deinstall ok config-files", "3.9.0-1") + stanza("python3", "install ok installed", "3.11.2-1") + got := byID(versions.System(systemSources(t, dpkg, "", ""))) + if !got["python3"].Installed || got["python3"].Version != "3.11.2" { + t.Fatalf("python3 = %+v", got["python3"]) + } +} + +func TestSystemSurvivesAVeryLongLine(t *testing.T) { + dpkg := "Package: big\nProvides: " + strings.Repeat("x", 200_000) + "\n\n" + stanza("caddy", "install ok installed", "2.11.9") + got := byID(versions.System(systemSources(t, dpkg, "", ""))) + if got["caddy"].Version != "2.11.9" { + t.Fatalf("caddy = %+v", got["caddy"]) + } +} + +func TestSystemKeepsRowsWithoutAUsableManifest(t *testing.T) { + for name, manifest := range map[string]string{"missing": "", "old": `{"version":"v0.9.0"}`, "broken": `{`} { + got := byID(versions.System(systemSources(t, stanza("caddy", "install ok installed", "2.6.2"), "", manifest))) + caddy := got["caddy"] + if !caddy.Installed || caddy.Pinned != "" || caddy.Outdated { + t.Errorf("%s: caddy = %+v", name, caddy) + } + } +} + +func TestSystemShowsOnlyWhatIsReadable(t *testing.T) { + onlyOS := versions.System(systemSources(t, "", testOSRelease, testManifest)) + if len(onlyOS) != 1 || onlyOS[0].ID != "os" { + t.Fatalf("without dpkg: %+v", onlyOS) + } + if got := versions.System(systemSources(t, "", "", testManifest)); len(got) != 0 { + t.Fatalf("nothing readable: %+v", got) + } + rolling := versions.System(systemSources(t, "", "NAME=Debian\nVERSION_CODENAME=forky\n", "")) + if len(rolling) != 1 || rolling[0].Version != "forky" { + t.Fatalf("without VERSION_ID: %+v", rolling) + } +} + +func withFile(t *testing.T, path, body string) { + t.Helper() + if err := os.WriteFile(path, []byte(body), 0o644); err != nil { + t.Fatal(err) + } +} + +func TestSystemShowsThePointRelease(t *testing.T) { + cases := map[string]struct{ file, want string }{ + "point release": {"12.11\n", "12.11 (bookworm)"}, + "equal": {"12\n", "12 (bookworm)"}, + "testing": {"trixie/sid\n", "12 (bookworm)"}, + "other counting": {"13.1\n", "12 (bookworm)"}, + "prefix only": {"120.1\n", "12 (bookworm)"}, + "empty": {"\n", "12 (bookworm)"}, + } + for name, c := range cases { + src := systemSources(t, "", testOSRelease, "") + withFile(t, src.DebianVersion, c.file) + got := byID(versions.System(src))["os"] + if got.Version != c.want { + t.Errorf("%s: os version = %q, want %q", name, got.Version, c.want) + } + } +} + +func TestSystemListsTheRunningKernelAfterTheOS(t *testing.T) { + src := systemSources(t, stanza("caddy", "install ok installed", "2.11.9"), testOSRelease, "") + withFile(t, src.KernelRelease, "6.12.47+rpt-rpi-v6\n") + got := versions.System(src) + want := versions.SystemEntry{ID: "kernel", Label: "Kernel", Version: "6.12.47+rpt-rpi-v6", Installed: true} + if len(got) < 3 || got[0].ID != "os" || got[1] != want || got[2].ID != "caddy" { + t.Fatalf("got %+v", got) + } +} + +func TestSystemKernelRowNeedsOnlyItsOwnFile(t *testing.T) { + src := systemSources(t, "", "", "") + withFile(t, src.KernelRelease, "6.1.0\n") + if got := versions.System(src); len(got) != 1 || got[0].ID != "kernel" { + t.Fatalf("kernel only: %+v", got) + } + withFile(t, src.KernelRelease, "\n") + if got := versions.System(src); len(got) != 0 { + t.Fatalf("empty kernel file: %+v", got) + } +} diff --git a/dashboard/internal/versions/versions.go b/dashboard/internal/versions/versions.go index 4167283ae..a3b348ca5 100644 --- a/dashboard/internal/versions/versions.go +++ b/dashboard/internal/versions/versions.go @@ -2,7 +2,8 @@ // came from, the version of every component in it, and what changed. It only // reads the files the updater and the installer leave in the installer state // directory (installed-manifest.json, selection.json, changelog.json); it -// never writes and never talks to GitHub. +// never writes and never talks to GitHub. The system card also reads dpkg's +// database, os-release, debian_version and the kernel release. package versions import ( @@ -83,6 +84,9 @@ type Snapshot struct { // (previous-manifest.json, kept by the updater and the installer). Nil on // a first install or before either kept one. Previous *Bundle `json:"previous"` + // System is the operating system and the system packages (System). Only + // set for sessions that may see them. + System []SystemEntry `json:"system,omitempty"` } type manifestFile struct { diff --git a/dashboard/internal/webui/cache-bust-history.csv b/dashboard/internal/webui/cache-bust-history.csv index 92992c44b..03d61511b 100644 --- a/dashboard/internal/webui/cache-bust-history.csv +++ b/dashboard/internal/webui/cache-bust-history.csv @@ -4,6 +4,8 @@ v0.11.22-pre.36,2026-11-23,js/monitoring-insight-model.js,1, v0.11.22-pre.36,2026-11-23,js/monitoring-insight.js,1, v0.11.22-pre.36,2026-11-23,js/monitoring-model.js,4, v0.11.22-pre.36,2026-11-23,js/monitoring.page.js,3, +v0.11.22-pre.37,2026-11-25,css/settings-controls.css,21,"settings, diagnostics: system card on the versions page" +v0.11.22-pre.37,2026-11-25,js/versions.page.js,11,"settings, diagnostics: system card on the versions page" v0.11.22-pre.35,2026-11-23,css/automations.css,25, v0.11.22-pre.35,2026-11-23,js/automation-suggestions.js,6, v0.11.22-pre.35,2026-11-23,js/automations.page.js,32, diff --git a/dashboard/internal/webui/catalogs/de.json b/dashboard/internal/webui/catalogs/de.json index e1ecc0fef..3d68e5293 100644 --- a/dashboard/internal/webui/catalogs/de.json +++ b/dashboard/internal/webui/catalogs/de.json @@ -4877,6 +4877,10 @@ "settings.versions.package.running": "Dashboard läuft als", "settings.versions.package.title": "Installiertes Paket", "settings.versions.package.version": "Paketversion", + "settings.versions.system.no_package": "kein Paket", + "settings.versions.system.outdated": "veraltet", + "settings.versions.system.pinned": "Soll {version}", + "settings.versions.system.title": "System", "settings.versions.unknown": "unbekannt", "settings.versions.updates.auto_check.help_aria": "Erklärung zur automatischen Prüfung", "settings.versions.updates.auto_check.label": "Automatisch auf Updates prüfen", diff --git a/dashboard/internal/webui/catalogs/en.json b/dashboard/internal/webui/catalogs/en.json index ccdcae798..683fc1c9b 100644 --- a/dashboard/internal/webui/catalogs/en.json +++ b/dashboard/internal/webui/catalogs/en.json @@ -4877,6 +4877,10 @@ "settings.versions.package.running": "Dashboard runs as", "settings.versions.package.title": "Installed package", "settings.versions.package.version": "Package version", + "settings.versions.system.no_package": "no package", + "settings.versions.system.outdated": "outdated", + "settings.versions.system.pinned": "expected {version}", + "settings.versions.system.title": "System", "settings.versions.unknown": "unknown", "settings.versions.updates.auto_check.help_aria": "About the automatic check", "settings.versions.updates.auto_check.label": "Check for updates automatically", diff --git a/dashboard/internal/webui/static/css/settings-controls.css b/dashboard/internal/webui/static/css/settings-controls.css index 2b575f222..35b1017b0 100644 --- a/dashboard/internal/webui/static/css/settings-controls.css +++ b/dashboard/internal/webui/static/css/settings-controls.css @@ -624,6 +624,29 @@ .version-name { flex: 1 1 8rem; min-width: 0; overflow-wrap: anywhere; color: var(--text); font-size: .92rem; } .version-name.is-off { color: var(--text-faint); } .version-note { color: var(--warn); } +/* Systemkarte: installierte Version und Soll bilden eine Einheit und brechen + gemeinsam um. Die Soll-Spalte behaelt auch leer ihre Breite, damit die + Versionen untereinander stehen. */ +.version-values { + display: flex; + align-items: baseline; + justify-content: flex-end; + gap: .6rem; + margin-left: auto; + white-space: nowrap; +} +.version-pin { + min-width: 6.5rem; + color: var(--text-muted); + font-size: .78rem; + font-weight: 450; + letter-spacing: .01em; + font-variant-numeric: tabular-nums; +} +.version-chip.is-warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; } +@media (prefers-contrast: more) { + .version-chip.is-warn { box-shadow: inset 0 0 0 1px var(--warn-line); } +} .release-list { padding: 0 0 .7rem; } .release + .release { margin-top: .8rem; } .release-title { margin: 0; font-size: .9rem; color: var(--text-strong); } diff --git a/dashboard/internal/webui/static/js/versions.page.js b/dashboard/internal/webui/static/js/versions.page.js index 9c9ef9398..ea4cc2007 100644 --- a/dashboard/internal/webui/static/js/versions.page.js +++ b/dashboard/internal/webui/static/js/versions.page.js @@ -58,6 +58,7 @@ bundle: null, running: {dashboard: ''}, components: [], + system: [], hasChangelog: false, // The bundle the node ran before its last version change, null when none is recorded. previous: null, @@ -99,6 +100,7 @@ this.components = body.components || []; this.hasChangelog = Boolean(body.has_changelog); this.previous = body.previous || null; + this.system = body.system || []; } catch (error) { this.error = error.message; } finally { @@ -262,6 +264,13 @@ } }, + // Version einer Zeile der Systemkarte. Ohne Paketeintrag kann das Programm + // trotzdem von Hand installiert sein, deshalb nicht "nicht installiert". + systemVersionText(entry) { + if (!entry.installed) return t('settings.versions.system.no_package'); + return entry.version || t('settings.versions.unknown'); + }, + // The releases of a component as the current view shows them. An // unflagged file is shown in full, there is nothing to pick from. shownReleases(id) { diff --git a/dashboard/internal/webui/templates/base.html b/dashboard/internal/webui/templates/base.html index ccdff6698..fe3a90303 100644 --- a/dashboard/internal/webui/templates/base.html +++ b/dashboard/internal/webui/templates/base.html @@ -239,14 +239,14 @@

{{t "no_access.title"}}

{{if and .Manager (index .Can "view_efficiency")}}

{{t "panel.efficiency_loading"}}

{{end}} {{if index .Can "view_monitoring"}}

{{t "panel.monitoring_loading"}}

{{end}} {{if .Manager}} -{{if index .Can "view_diagnostics"}}

{{t "panel.diagnostics_loading"}}

{{end}} +{{if index .Can "view_diagnostics"}}

{{t "panel.diagnostics_loading"}}

{{end}} {{if index .Can "view_config"}}

{{t "panel.config_loading"}}

{{end}} {{if index .Can "view_energy"}}

{{t "panel.energy_loading"}}

{{end}} {{if index .Can "view_device_map"}}

{{t "panel.devicemap_loading"}}

{{end}} -

{{t "panel.settings_loading"}}

+

{{t "panel.settings_loading"}}

{{if index .Can "view_automations"}} {{if index .InstalledServices "automation"}}

{{t "panel.automations_loading"}}

{{end}}{{end}} {{else}} -{{if index .Can "view_diagnostics"}}

{{t "panel.diagnostics_loading"}}

{{end}} +{{if index .Can "view_diagnostics"}}

{{t "panel.diagnostics_loading"}}

{{end}} {{end}}