From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 74ACB1FF0AF for ; Fri, 20 Nov 2026 10:53:10 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 662D821747; Fri, 20 Nov 2026 10:52:44 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager v4 2/3] api: provide UI versions via index and /nodes/{node}/version Date: Fri, 20 Nov 2026 10:46:38 +0100 Message-ID: <20261120095235.1143525-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261120095235.1143525-1-d.csapak@proxmox.com> References: <20261120095235.1143525-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.221 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: NARB2H4DVHYVSI7RQWTS2MN7SEXHIBIP X-Message-ID-Hash: NARB2H4DVHYVSI7RQWTS2MN7SEXHIBIP X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a version string from the UI packages, so that the UI can easily detect when the versions of the backend differ from the ones the page was loaded with. Generate the string via a shared `ui_version` helper that takes no arguments, so that the index and API always produce the same string. Cache the pwt versions locally for as long as the mtime does not change. Stat'ing should be cached by the underlying filesystem and be very cheap. This way we don't hit the file read on every call. Signed-off-by: Dominik Csapak --- PVE/API2/Nodes.pm | 14 +++++++++++++- PVE/API2Tools.pm | 30 +++++++++++++++++++++++++++--- PVE/Service/pveproxy.pm | 3 +++ www/index.html.tpl | 3 ++- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index b34d992c..ddbf7544 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -320,12 +320,24 @@ __PACKAGE__->register_method({ type => 'string', description => 'The short git commit hash ID from which this version was build', }, + 'ui-version' => { + type => 'string', + optional => 1, + description => + 'A string generated from UI package versions, to detect changes.', + }, }, }, code => sub { my ($resp, $param) = @_; - return PVE::pvecfg::version_info(); + my $res = PVE::pvecfg::version_info(); + + if (my $ui_version = PVE::API2Tools::ui_version()) { + $res->{'ui-version'} = $ui_version; + } + + return $res; }, }); diff --git a/PVE/API2Tools.pm b/PVE/API2Tools.pm index c53ec03f..dcd3dc36 100644 --- a/PVE/API2Tools.pm +++ b/PVE/API2Tools.pm @@ -18,6 +18,7 @@ use PVE::RPCEnvironment; use PVE::SafeSyslog; use PVE::Storage::Plugin; use PVE::Tools; +use PVE::pvecfg; # each rrd key for a resource will only exist once. The key format might be different though. Therefore return on first hit sub get_rrd_key { @@ -280,10 +281,33 @@ sub pwt_base_dir { return $PWT_BASE_DIR; } +my $pwt_version_cache = {}; + sub read_pwt_version { - my $wtversionraw = PVE::File::file_read_first_line($PWT_FILE) // ''; - my $wtversion = $wtversionraw =~ m|^// (.*)$| ? $1 : ''; - return $wtversion; + my $st = stat($PWT_FILE); + my $mtime = $st ? $st->mtime() : 0; + + if ( + !defined($pwt_version_cache->{version}) + || $pwt_version_cache->{mtime} != $mtime + ) { + my $wtversionraw = PVE::File::file_read_first_line($PWT_FILE) // ''; + my $wtversion = $wtversionraw =~ m|^// (.*)$| ? $1 : ''; + $pwt_version_cache->{version} = $wtversion; + $pwt_version_cache->{mtime} = $mtime; + } + + return $pwt_version_cache->{version}; +} + +# returns a combined pve-manager and proxmox-widget-toolkit version string +# or undef if the pwt version was not readable or parseable +sub ui_version { + my $manager_version = PVE::pvecfg::version_text(); + my $pwt_version = read_pwt_version(); + return undef if !$pwt_version; + + return "$manager_version-$pwt_version"; } 1; diff --git a/PVE/Service/pveproxy.pm b/PVE/Service/pveproxy.pm index dc97f815..40c07ff6 100755 --- a/PVE/Service/pveproxy.pm +++ b/PVE/Service/pveproxy.pm @@ -264,6 +264,8 @@ sub get_index { my $wtversion = PVE::API2Tools::read_pwt_version(); + my $uiversion = PVE::API2Tools::ui_version(); + # while we could use the actual pkg version (e.g., shipped as pkg-version file in each # respective package's /usr/share/ folder, this way it should also work when using make # install to directly install to local root filesystem. @@ -287,6 +289,7 @@ sub get_index { debug => $debug, version => "$version", wtversion => $wtversion, + uiversion => $uiversion, theme => $theme, consenttext => $consent_text, i18n_js_mtime => $i18n_js_mtime, diff --git a/www/index.html.tpl b/www/index.html.tpl index 125c1046..466418ca 100644 --- a/www/index.html.tpl +++ b/www/index.html.tpl @@ -48,7 +48,8 @@ NodeArch: '[% arch %]', UserName: '[% username %]', CSRFPreventionToken: '[% token %]', - ConsentText: '[% consenttext.squote %]' + ConsentText: '[% consenttext.squote %]', + UIVersion: '[% uiversion %]', }; -- 2.47.3