From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C1D669B208 for ; Wed, 24 May 2023 15:58:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 750A81F82E for ; Wed, 24 May 2023 15:57:41 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 24 May 2023 15:57:38 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 7D80046E4F for ; Wed, 24 May 2023 15:57:34 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Wed, 24 May 2023 15:56:38 +0200 Message-Id: <20230524135649.934881-32-l.wagner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230524135649.934881-1-l.wagner@proxmox.com> References: <20230524135649.934881-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.156 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 pve-manager 31/42] api: apt: send notification via new notification module X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 May 2023 13:58:05 -0000 ... instead of using sendmail directly As of now, there is no way to configure a notification channel for APT notifications. Thus, the implementation simply creates an temporary channel with a sendmail endpoint sending mail to root. Signed-off-by: Lukas Wagner --- PVE/API2/APT.pm | 73 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm index 6694dbeb..c1b7ece5 100644 --- a/PVE/API2/APT.pm +++ b/PVE/API2/APT.pm @@ -19,6 +19,7 @@ use PVE::DataCenterConfig; use PVE::SafeSyslog; use PVE::INotify; use PVE::Exception; +use PVE::Notify; use PVE::RESTHandler; use PVE::RPCEnvironment; use PVE::API2Tools; @@ -272,6 +273,12 @@ __PACKAGE__->register_method({ return $pkglist; }}); +my $updates_available_subject_template = "New software packages available ({{hostname}})"; +my $updates_available_body_template = <register_method({ name => 'update_database', path => 'update', @@ -342,27 +349,71 @@ __PACKAGE__->register_method({ my $mailto = $rootcfg->{email}; if ($mailto) { - my $hostname = `hostname -f` || PVE::INotify::nodename(); - chomp $hostname; + # Add ephemeral sendmail endpoint/channel for backwards compatibility + # TODO: Make notification channel configurable, then the + # temporary endpoint/channel should not be necessary any more. + my $notification_config = PVE::Notify::read_config(); my $mailfrom = $dcconf->{email_from} || "root"; - my $subject = "New software packages available ($hostname)"; + $notification_config->add_sendmail_endpoint( + "anonymous-apt-sendmail", + [$mailto], + $mailfrom, + "" + ); + + $notification_config->add_channel("mail", ["anonymous-apt-sendmail"]); + + my $updates_table = { + schema => { + columns => [ + { + label => "Package", + id => "package", + }, + { + label => "Old Version", + id => "old-version", + }, + { + label => "New Version", + id => "new-version", + } + ] + }, + data => [] + }; - my $data = "The following updates are available:\n\n"; + my $hostname = `hostname -f` || PVE::INotify::nodename(); + chomp $hostname; my $count = 0; foreach my $p (sort {$a->{Package} cmp $b->{Package} } @$pkglist) { next if $p->{NotifyStatus} && $p->{NotifyStatus} eq $p->{Version}; $count++; - if ($p->{OldVersion}) { - $data .= "$p->{Package}: $p->{OldVersion} ==> $p->{Version}\n"; - } else { - $data .= "$p->{Package}: $p->{Version} (new)\n"; - } + + push @{$updates_table->{data}}, { + "package" => $p->{Package}, + "old-version" => $p->{OldVersion}, + "new-version" => $p->{Version} + + }; } return if !$count; - PVE::Tools::sendmail($mailto, $subject, $data, undef, $mailfrom, ''); + my $properties = { + updates => $updates_table, + hostname => $hostname, + }; + + PVE::Notify::send_notification( + "mail", + "info", + $updates_available_subject_template, + $updates_available_body_template, + $properties, + $notification_config + ); foreach my $pi (@$pkglist) { $pi->{NotifyStatus} = $pi->{Version}; @@ -378,6 +429,8 @@ __PACKAGE__->register_method({ }}); + + __PACKAGE__->register_method({ name => 'changelog', path => 'changelog', -- 2.30.2