From 579290044fe859e676636b3dca2ed539f6481f55 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Sun, 8 Mar 2026 23:36:38 +0100 Subject: [PATCH] aSAD --- modules/pi_control/pages/hosts.php | 10 +++++----- tools/pi_control/check_updates.php | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/pi_control/pages/hosts.php b/modules/pi_control/pages/hosts.php index bccf75a..cc3b682 100644 --- a/modules/pi_control/pages/hosts.php +++ b/modules/pi_control/pages/hosts.php @@ -46,8 +46,8 @@ if (isset($_GET['update_json'])) { $settings = modules()->settings('pi_control'); $strictHostKey = !empty($settings['terminal_strict_hostkey']); - $updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; apt-get -s upgrade 2>/dev/null | grep \"^Inst \" || true'"; - $upgradeCmd = "sh -lc 'current=\"$(. /etc/os-release 2>/dev/null && echo \"$VERSION_CODENAME\")\"; if [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2; exit}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; echo \"__CURRENT__=$current\"; echo \"__LATEST__=$latest\"; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'"; + $updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; if sudo apt update -qq >/dev/null 2>&1; then count=$(apt-get -s dist-upgrade | grep -c \"^Inst \"); if [ \"$count\" -gt 0 ]; then echo \"__UPDATE__=1\"; else echo \"__UPDATE__=0\"; fi; echo \"__COUNT__=$count\"; else echo \"__ERR__APT_UPDATE\"; exit 3; fi'"; + $upgradeCmd = "sh -lc 'id=\"$(. /etc/os-release 2>/dev/null && echo \"${ID:-}\")\"; current=\"$(. /etc/os-release 2>/dev/null && echo \"${VERSION_CODENAME:-}\")\"; if [ \"$id\" != \"debian\" ] || [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'"; [$updExit, $updOut, $updErr] = runSshCommandCapture($host, $updateCmd, $strictHostKey, 20); $updOutStr = (string)$updOut; @@ -55,9 +55,9 @@ if (isset($_GET['update_json'])) { $updateCount = null; $updatePreview = ''; if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) { - $lines = array_values(array_filter(preg_split('/\r?\n/', $updOutStr))); - $updateCount = count($lines); - $updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : ''; + if (preg_match('/^__COUNT__=(\d+)$/m', $updOutStr, $m)) { + $updateCount = (int)$m[1]; + } } [$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25); diff --git a/tools/pi_control/check_updates.php b/tools/pi_control/check_updates.php index c416a54..7e209dd 100644 --- a/tools/pi_control/check_updates.php +++ b/tools/pi_control/check_updates.php @@ -13,8 +13,8 @@ $table = fn(string $name) => module_fn($module, 'table', $name); $settings = modules()->settings($module); $strictHostKey = !empty($settings['terminal_strict_hostkey']); -$updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; apt-get -s upgrade 2>/dev/null | grep \"^Inst \" || true'"; -$upgradeCmd = "sh -lc 'current=\"$(. /etc/os-release 2>/dev/null && echo \"$VERSION_CODENAME\")\"; if [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2; exit}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; echo \"__CURRENT__=$current\"; echo \"__LATEST__=$latest\"; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'"; +$updateCmd = "sh -lc 'if ! command -v apt-get >/dev/null 2>&1; then echo \"__ERR__NO_APT\"; exit 2; fi; if sudo apt update -qq >/dev/null 2>&1; then count=$(apt-get -s dist-upgrade | grep -c \"^Inst \"); if [ \"$count\" -gt 0 ]; then echo \"__UPDATE__=1\"; else echo \"__UPDATE__=0\"; fi; echo \"__COUNT__=$count\"; else echo \"__ERR__APT_UPDATE\"; exit 3; fi'"; +$upgradeCmd = "sh -lc 'id=\"$(. /etc/os-release 2>/dev/null && echo \"${ID:-}\")\"; current=\"$(. /etc/os-release 2>/dev/null && echo \"${VERSION_CODENAME:-}\")\"; if [ \"$id\" != \"debian\" ] || [ -z \"$current\" ]; then echo \"__ERR__NO_CODENAME\"; exit 2; fi; latest=\"$( (command -v curl >/dev/null 2>&1 && curl -fsSL https://deb.debian.org/debian/dists/stable/Release) || (command -v wget >/dev/null 2>&1 && wget -qO- https://deb.debian.org/debian/dists/stable/Release) )\"; latest=\"$(printf \"%s\" \"$latest\" | awk -F\": \" \"/^Codename:/{print $2}\")\"; if [ -z \"$latest\" ]; then echo \"__ERR__NO_LATEST\"; exit 3; fi; if [ \"$current\" != \"$latest\" ]; then echo \"__UPGRADE__=1\"; else echo \"__UPGRADE__=0\"; fi'"; $driver = (string)$pdo->getAttribute(PDO::ATTR_DRIVER_NAME); $nowExpr = $driver === 'pgsql' ? 'NOW()' : "DATETIME('now')"; @@ -31,9 +31,9 @@ foreach ($hosts as $host) { $updateCount = null; $updatePreview = ''; if ($updExit === 0 && !str_contains($updOutStr, '__ERR__')) { - $lines = array_values(array_filter(preg_split('/\r?\n/', $updOutStr))); - $updateCount = count($lines); - $updatePreview = $updateCount ? implode("\n", array_slice($lines, 0, 6)) : ''; + if (preg_match('/^__COUNT__=(\d+)$/m', $updOutStr, $m)) { + $updateCount = (int)$m[1]; + } } [$upgExit, $upgOut, $upgErr] = runSshCommandCapture($host, $upgradeCmd, $strictHostKey, 25);