From cdba25924e338647e45c3abb1a2d7afd19171ad3 Mon Sep 17 00:00:00 2001 From: Andrei Smaliak Date: Mon, 2 Nov 2026 07:16:40 +0100 Subject: [PATCH] Add Console client update control through the shared Debian updater --- docs/releases/console-3.1.32.md | 7 +++ docs/releases/stage-itscreen-1.0.40.md | 6 ++ stage-releases.json | 4 +- stage_itscreen/release-provenance.json | 2 +- stage_itscreen/updater/client_updater.py | 14 +++-- stage_itscreen/updater/test_client_updater.py | 19 +++++- stage_itscreen/version.json | 2 +- stage_ui/console_core/ARCHITECTURE.md | 11 ++++ stage_ui/console_core/backend/app.py | 39 +++++++++++- .../backend/test_client_update_ui.js | 18 ++++++ .../console_core/frontend/console.i18n.js | 12 ++++ stage_ui/console_core/frontend/console.js | 62 ++++++++++++++++++- stage_ui/console_core/frontend/index.html | 6 +- stage_ui/version.json | 2 +- 14 files changed, 188 insertions(+), 16 deletions(-) create mode 100644 docs/releases/console-3.1.32.md create mode 100644 docs/releases/stage-itscreen-1.0.40.md create mode 100644 stage_ui/console_core/backend/test_client_update_ui.js diff --git a/docs/releases/console-3.1.32.md b/docs/releases/console-3.1.32.md new file mode 100644 index 0000000..8fc7bf7 --- /dev/null +++ b/docs/releases/console-3.1.32.md @@ -0,0 +1,7 @@ +# Console 3.1.32 — client update control + +- It-Screen shows installed and available native client versions, update availability, progress and errors. +- Check and update delegates to the existing Debian updater socket; no duplicate download/install implementation. +- Opening the tab performs a check-only request; it never installs or changes automatic updates. Status polling updates only the version panel, preserving registration form edits. +- Authenticated API allowlists check-only/update; GET reads local updater state without external network requests. +- Requires stage_itscreen 1.0.40 for the snapshot/check-only protocol extension. Older services report an explicit error. diff --git a/docs/releases/stage-itscreen-1.0.40.md b/docs/releases/stage-itscreen-1.0.40.md new file mode 100644 index 0000000..0250931 --- /dev/null +++ b/docs/releases/stage-itscreen-1.0.40.md @@ -0,0 +1,6 @@ +# It-Screen stage 1.0.40 — Console update adapter + +- Extend the existing updater socket with snapshot and check_only commands for Console. +- Check-only never installs, including when automatic updates are enabled; manual update keeps the existing verified download, lock, rollback and startup checks. +- Expose queued/running state and errors without changing client version 5.1.55 or update preferences. +- Validation: 19 updater tests, frontend state tests and local ARM64 Console API checks. diff --git a/stage-releases.json b/stage-releases.json index e906070..aec3052 100644 --- a/stage-releases.json +++ b/stage-releases.json @@ -14,7 +14,7 @@ "version": "1.0.1" }, "stage_ui": { - "version": "3.1.31" + "version": "3.1.32" }, "stage_avahi": { "version": "1.0.0" @@ -23,7 +23,7 @@ "version": "1.0.0" }, "stage_itscreen": { - "version": "1.0.39" + "version": "1.0.40" }, "stage_reverse_tunnels": { "version": "1.0.2" diff --git a/stage_itscreen/release-provenance.json b/stage_itscreen/release-provenance.json index 2afcd4c..0dddccc 100644 --- a/stage_itscreen/release-provenance.json +++ b/stage_itscreen/release-provenance.json @@ -1,7 +1,7 @@ { "schema_version": 1, "client_version": "5.1.55", - "stage_version": "1.0.39", + "stage_version": "1.0.40", "platform": "linux", "architecture": "arm64", "source_repository": "https://git.iomatex.com/Development/It-screenClient.git", diff --git a/stage_itscreen/updater/client_updater.py b/stage_itscreen/updater/client_updater.py index 316d83a..78ae4d0 100644 --- a/stage_itscreen/updater/client_updater.py +++ b/stage_itscreen/updater/client_updater.py @@ -168,7 +168,7 @@ class Updater: return {'link': FEED, 'period': PERIOD, 'installed_version': self.installed, 'ready_version': self.ready, 'device_id': self.device_id, 'active_update': int(self.automatic), 'state_update': self.phase, - 'progress_download': self.progress} + 'progress_download': self.progress, 'error': self.error, 'busy': self.busy or not self.pending.empty()} def newer(self, data): if data['build_number'] != self.installed: @@ -331,7 +331,7 @@ class Updater: finally: candidate.unlink(missing_ok=True) - def check(self, install=False): + def check(self, install=False, check_only=False): self.busy = True candidate = None try: @@ -346,7 +346,7 @@ class Updater: self.status('not_required') return self.status('ready') - if not (install or self.automatic): + if check_only or not (install or self.automatic): return self.status('downloading') candidate = self.download(data) @@ -363,7 +363,7 @@ class Updater: while True: try: manual_install = self.pending.get(timeout=PERIOD) - self.check(install=manual_install) + self.check(install=manual_install is True, check_only=manual_install == "check_only") except queue.Empty: if self.automatic: self.check() @@ -395,7 +395,11 @@ class Handler(socketserver.StreamRequestHandler): try: data = json.loads(line) action, key = data.get('action'), data.get('key') - if action == 'get' and key in updater.values(): + if action == 'get' and key == 'snapshot': + self.send('snapshot', updater.values()) + elif action == 'check_only': + updater.request('check_only') + elif action == 'get' and key in updater.values(): self.send(key, updater.values()[key]) elif action == 'set' and key == 'active_update': updater.set_automatic(data.get('value')) diff --git a/stage_itscreen/updater/test_client_updater.py b/stage_itscreen/updater/test_client_updater.py index fc5209d..d5bb69b 100644 --- a/stage_itscreen/updater/test_client_updater.py +++ b/stage_itscreen/updater/test_client_updater.py @@ -29,6 +29,21 @@ class TestUpdater(unittest.TestCase): executable(self.binary, '5.1.54') self.u = c.Updater(self.binary,self.root/'state',self.root/'cache') + def test_console_check_never_installs_even_with_automatic_enabled(self): + self.u.automatic = True + with patch.object(self.u, 'manifest', return_value=manifest()), patch.object(self.u, 'download') as download: + self.u.check(check_only=True) + download.assert_not_called() + self.assertEqual(self.u.phase, 'ready') + self.assertTrue(self.u.automatic) + self.assertEqual(self.u.values()['ready_version'], 5010055) + + def test_console_pending_request_is_busy(self): + self.u.request('check_only') + self.assertTrue(self.u.values()['busy']) + self.assertEqual(self.u.pending.get_nowait(), 'check_only') + self.assertFalse(self.u.values()['busy']) + def test_socket_checkbox_and_fragmented_frames(self): import os import socket @@ -45,8 +60,10 @@ class TestUpdater(unittest.TestCase): client.settimeout(3);client.connect(path) stream=client.makefile('rwb',buffering=0) initial={} - for _ in range(8):initial.update(json.loads(stream.readline())) + for _ in range(len(self.u.values())):initial.update(json.loads(stream.readline())) self.assertEqual(initial['active_update'],0) + stream.write(b'{"action":"get","key":"snapshot"}\n') + self.assertEqual(json.loads(stream.readline())['snapshot']['installed_version'],5010054) stream.write(b'{"action":"set","key":"active_') stream.write(b'update","value":1}\n') self.assertEqual(json.loads(stream.readline()),{'active_update':1}) diff --git a/stage_itscreen/version.json b/stage_itscreen/version.json index 0b52bbd..4a62bf6 100644 --- a/stage_itscreen/version.json +++ b/stage_itscreen/version.json @@ -1,3 +1,3 @@ { - "version": "1.0.39" + "version": "1.0.40" } diff --git a/stage_ui/console_core/ARCHITECTURE.md b/stage_ui/console_core/ARCHITECTURE.md index d50321a..50ef176 100644 --- a/stage_ui/console_core/ARCHITECTURE.md +++ b/stage_ui/console_core/ARCHITECTURE.md @@ -65,3 +65,14 @@ never reports success. The firmware's power-cycle persistence is not asserted. UI uses existing field/select/actionRow/card classes and the shared body-mounted confirmation dialog. No new CSS or independent modal/serial transport is added. + +## Debian client updates (Console 3.1.32) + +The It-Screen panel uses authenticated GET/POST `/api/itscreen/update`. +`client_update_request` only adapts the existing `/tmp/itsupdater` socket; +`stage_itscreen/updater/client_updater.py` remains the single owner for feed +validation, version comparison, download, install locking and rollback. +GET reads a local snapshot; POST allowlists `check_only` and `update`. +Opening the tab checks without installation or changing the automatic flag. +The panel polls local state and replaces only its own markup, preserving form +focus and edits elsewhere. Stage 1.0.40 supplies the extended socket contract. diff --git a/stage_ui/console_core/backend/app.py b/stage_ui/console_core/backend/app.py index 2f990b4..77de4f1 100644 --- a/stage_ui/console_core/backend/app.py +++ b/stage_ui/console_core/backend/app.py @@ -60,7 +60,7 @@ APP_DIR = "/opt/iomatex-console" PUBLIC_DIR = os.path.join(APP_DIR, "public") PROVIDERS_DIR = os.path.join(APP_DIR, "providers.d") CONFIG_PATH = "/etc/iomatex/console.json" -UI_VERSION = "V 3.1.28" +UI_VERSION = "V 3.1.32" STORAGE_HEALTH_COMMAND = "/usr/local/sbin/iomatex-storage-health" ZONEINFO_ROOT = "/usr/share/zoneinfo" @@ -2977,6 +2977,27 @@ def get_itscreen_binary_candidates(): return [path for path in candidates if os.path.exists(path)] +def client_update_request(action=None): + """Console adapter only: the privileged updater owns feeds and installation.""" + if action not in (None, "check_only", "update"): + raise ValueError("Invalid client update action") + with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as connection: + connection.settimeout(3) + connection.connect("/tmp/itsupdater") + if action: + connection.sendall((json.dumps({"action": action}) + "\n").encode()) + connection.sendall(b'{"action":"get","key":"snapshot"}\n') + with connection.makefile("rb") as stream: + for _ in range(32): + line = stream.readline(65537) + if not line or len(line) > 65536: + break + payload = json.loads(line) + if "snapshot" in payload: + return {"ok": True, **payload["snapshot"]} + raise RuntimeError("Client updater is unavailable; update the It-Screen system stage") + + def get_itscreen_app_version(): version_re = re.compile(r"\b(\d+\.\d+\.\d+(?:\.\d+)?)\b") for binary_path in get_itscreen_binary_candidates(): @@ -3729,6 +3750,12 @@ class Handler(BaseHTTPRequestHandler): except Exception as exc: self.send_json({"ok": False, "error": str(exc)}, code=500) return + if parsed.path == "/api/itscreen/update": + try: + self.send_json(client_update_request()) + except Exception as exc: + self.send_json({"ok": False, "error": str(exc)}, code=503) + return if parsed.path == "/api/itscreen/status": try: self.send_json(build_itscreen_status_payload()) @@ -3827,6 +3854,16 @@ class Handler(BaseHTTPRequestHandler): return if not self.require_auth(parsed): return + if parsed.path == "/api/itscreen/update": + payload = self.read_json_body() + if not isinstance(payload, dict) or payload.get("action") not in ("check_only", "update"): + self.send_json({"ok": False, "error": "Invalid update action"}, code=400) + return + try: + self.send_json(client_update_request(payload["action"])) + except Exception as exc: + self.send_json({"ok": False, "error": str(exc)}, code=503) + return if parsed.path == "/api/onvif/probe": payload = self.read_json_body() if payload is None: diff --git a/stage_ui/console_core/backend/test_client_update_ui.js b/stage_ui/console_core/backend/test_client_update_ui.js new file mode 100644 index 0000000..f6938b7 --- /dev/null +++ b/stage_ui/console_core/backend/test_client_update_ui.js @@ -0,0 +1,18 @@ +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const vm = require('node:vm'); +const source = fs.readFileSync(__dirname + '/../frontend/console.js', 'utf8'); +const ctx = {state: {itscreen: {}}, t: s => s, esc: s => String(s).replaceAll('<', '<')}; +vm.createContext(ctx); +vm.runInContext(source.slice(source.indexOf(' function clientVersion('), source.indexOf(' async function loadClientUpdate(')), ctx); +for (const [phase, label] of [['ready', 'A new client version'], ['not_required', 'latest client version'], ['updating', 'Installing client'], ['error', 'Client update failed']]) { + ctx.state.itscreen.update = {state_update: phase, installed_version: 5010055, ready_version: 5010056, error: phase === 'error' ? '' : '', busy: phase === 'updating'}; + const html = ctx.renderClientUpdate(); + assert.ok(html.includes(label)); + assert.ok(html.includes('5.1.55')); + assert.ok(html.includes('5.1.56')); + assert.equal(html.includes(' disabled '), phase === 'updating'); + assert.ok(!html.includes('')); +} +assert.ok(source.includes('panel.innerHTML = renderClientUpdate()'), 'Polling updates only the updater panel, preserving form edits'); +console.log('Client update versions, available/current/error/busy states and local panel rendering passed'); diff --git a/stage_ui/console_core/frontend/console.i18n.js b/stage_ui/console_core/frontend/console.i18n.js index cd7293c..33edd25 100644 --- a/stage_ui/console_core/frontend/console.i18n.js +++ b/stage_ui/console_core/frontend/console.i18n.js @@ -12,6 +12,18 @@ ], translations: { ru: { + "Check and update client": "Проверить и обновить версию", + "Installed client": "Установленная версия клиента", + "Available client": "Доступная версия клиента", + "Checking client version...": "Проверяем версию клиента…", + "A new client version is available": "Доступна новая версия клиента", + "The latest client version is installed": "Установлена актуальная версия клиента", + "Downloading client update...": "Загрузка обновления клиента…", + "Installing client update...": "Установка обновления клиента…", + "Client updated": "Клиент обновлён", + "Client update failed": "Не удалось обновить клиент", + "Updates come from git.iomatex.com. The client restarts; registration and settings are preserved.": "Обновления загружаются с git.iomatex.com. Клиент перезапустится; регистрация и настройки сохранятся.", + "Input/output relationship": "Связь входов и реле", "Independent inputs and outputs": "Независимые входы и выходы", "Toggle with memory": "Переключение с фиксацией", diff --git a/stage_ui/console_core/frontend/console.js b/stage_ui/console_core/frontend/console.js index 42208df..471b720 100644 --- a/stage_ui/console_core/frontend/console.js +++ b/stage_ui/console_core/frontend/console.js @@ -49,7 +49,7 @@ { mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" }, { mode: "custom", label: "Custom", host: "" } ]; - const UI_VERSION = "V 3.1.28"; + const UI_VERSION = "V 3.1.32"; const ITSCREEN_LOG_INITIAL_LINES = 50; const ITSCREEN_LOG_BUFFER_LIMIT = 300; const ITSCREEN_LOG_BATCH_MS = 250; @@ -167,6 +167,9 @@ networkRequest: null, network: null, itscreen: { + update: null, + updateLoading: false, + updateCheckedAt: 0, loading: false, busyAction: "", data: null, @@ -3084,6 +3087,7 @@ +
${renderClientUpdate()}
${serviceWarnings.length ? `
${esc(t("Warnings"))}
    ${serviceWarnings.map((x) => `
  • ${esc(translateUiText(x))}
  • `).join("")}
` : ""} ${serviceErrors.length ? `
${esc(t("Errors"))}
    ${serviceErrors.map((x) => `
  • ${esc(translateUiText(x))}
  • `).join("")}
` : ""} ${service && service.status === "not_installed" ? `
${esc(t("It-screen service is not installed on this device."))}
` : ""} @@ -5199,6 +5203,7 @@ } async function loadItscreenInitialData(options = {}) { + if (state.activeTab === "tscreen") loadClientUpdate(Date.now() - state.itscreen.updateCheckedAt > 900000 ? "check_only" : null); const force = !!options.force; const maxAgeMs = Number.isFinite(options.maxAgeMs) ? options.maxAgeMs : 10000; if (!force && state.itscreen.request) return state.itscreen.request; @@ -5832,6 +5837,58 @@ state.itscreen.focused = !!focused; }; + function clientVersion(code) { + const n = Number(code); + return n > 0 ? `${Math.floor(n / 1000000)}.${Math.floor(n / 10000) % 100}.${n % 10000}` : "—"; + } + + function renderClientUpdate() { + const u = state.itscreen.update || {}; + const phase = u.state_update || "init"; + const labels = {init: "Checking client version...", check: "Checking client version...", + ready: "A new client version is available", not_required: "The latest client version is installed", + downloading: "Downloading client update...", updating: "Installing client update...", not_permitted: "Automatic updates are disabled", + updated: "Client updated", error: "Client update failed"}; + const busy = state.itscreen.updateLoading || u.busy; + return `
${esc(t("Installed client"))}
${esc(clientVersion(u.installed_version))}
+
${esc(t("Available client"))}
${esc(clientVersion(u.ready_version))}
+ +
+
${esc(t("Updates come from git.iomatex.com. The client restarts; registration and settings are preserved."))}
`; + } + + async function loadClientUpdate(action = null) { + if (state.itscreen.updateLoading) return; + const generation = state.sessionGeneration; + state.itscreen.updateLoading = true; + if (action) renderClientUpdateStatus(); + try { + const data = await fetchJson("/api/itscreen/update", action ? { + method: "POST", headers: {"Content-Type": "application/json"}, + body: JSON.stringify({action}) + } : {cache: "no-store"}); + if (generation !== state.sessionGeneration) return; + state.itscreen.update = data; + if (action) state.itscreen.updateCheckedAt = Date.now(); + } catch (error) { + if (generation !== state.sessionGeneration) return; + state.itscreen.update = {state_update: "error", error: error.message}; + } finally { + state.itscreen.updateLoading = false; + if (generation === state.sessionGeneration) renderClientUpdateStatus(); + } + } + + function renderClientUpdateStatus() { + const panel = document.getElementById("itscreenClientUpdate"); + if (panel && state.activeTab === "tscreen") panel.innerHTML = renderClientUpdate(); + } + + window.__clientUpdate = async function () { + if (state.itscreen.updateLoading || state.itscreen.busyAction || (state.itscreen.update || {}).busy) return; + await loadClientUpdate("update"); + }; + window.__itscreenRefresh = async function () { state.itscreen.busyAction = "refresh"; if (state.activeTab === "tscreen") renderActiveTab(); @@ -7040,5 +7097,8 @@ if (state.activeTab === "tscreen") return; loadForActiveTab({ preserveEditing: true }).catch(() => {}); }, 15000); + setInterval(() => { + if (state.auth.authenticated && state.activeTab === "tscreen") loadClientUpdate(); + }, 3000); setInterval(updateSessionMeter, 30000); })(); diff --git a/stage_ui/console_core/frontend/index.html b/stage_ui/console_core/frontend/index.html index 27fe291..8ed178b 100644 --- a/stage_ui/console_core/frontend/index.html +++ b/stage_ui/console_core/frontend/index.html @@ -23,7 +23,7 @@ } catch (error) {} })(); - +
@@ -109,7 +109,7 @@
- - + + diff --git a/stage_ui/version.json b/stage_ui/version.json index ec50c94..3627f51 100644 --- a/stage_ui/version.json +++ b/stage_ui/version.json @@ -1,3 +1,3 @@ { - "version": "3.1.31" + "version": "3.1.32" }