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 5E47F91DA4 for ; Mon, 27 Mar 2023 17:20:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 961C3D4F8 for ; Mon, 27 Mar 2023 17:19:25 +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 ; Mon, 27 Mar 2023 17:19:23 +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 0E50446FF7 for ; Mon, 27 Mar 2023 17:19:23 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Mon, 27 Mar 2023 17:18:54 +0200 Message-Id: <20230327151857.495565-16-l.wagner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327151857.495565-1-l.wagner@proxmox.com> References: <20230327151857.495565-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.169 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 Subject: [pve-devel] [PATCH pve-manager 15/18] 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: Mon, 27 Mar 2023 15:20:22 -0000 ... instead of using sendmail directly As with the VZDump patch, the changes were implemented in such a way that existing mail notifications continue to work as before. Here this means that if root@pam has an email address configured, we add an ephemeral sendmail endpoint for that email address. Potential side effect: If there is another sendmail endpoint configured in notifications.cfg which also sends to root@pam, root may receive two emails. Signed-off-by: Lukas Wagner --- PVE/API2/APT.pm | 55 ++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm index 6694dbeb..543037de 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::Notification; use PVE::RESTHandler; use PVE::RPCEnvironment; use PVE::API2Tools; @@ -341,34 +342,46 @@ __PACKAGE__->register_method({ my $rootcfg = $usercfg->{users}->{'root@pam'} || {}; my $mailto = $rootcfg->{email}; + my $config = PVE::Notification::config(); + if ($mailto) { - my $hostname = `hostname -f` || PVE::INotify::nodename(); - chomp $hostname; my $mailfrom = $dcconf->{email_from} || "root"; - my $subject = "New software packages available ($hostname)"; - - my $data = "The following updates are available:\n\n"; - - 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"; - } - } + # add ephemeral sendmail endpoint, in order to not break existing + # mail notifications. The changed config is not persisted. + # TODO: Remove in PVE x.y ? + $config->add_sendmail_endpoint( + "legacy-apt-sendmail", + [$mailto], + $mailfrom, + ""); + + } - return if !$count; + my $hostname = `hostname -f` || PVE::INotify::nodename(); + chomp $hostname; + my $subject = "New software packages available ($hostname)"; - PVE::Tools::sendmail($mailto, $subject, $data, undef, $mailfrom, ''); + my $data = "The following updates are available:\n\n"; - foreach my $pi (@$pkglist) { - $pi->{NotifyStatus} = $pi->{Version}; + 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"; } - PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist)); } + + return if !$count; + + PVE::Notification::info($subject, $data, $config); + + foreach my $pi (@$pkglist) { + $pi->{NotifyStatus} = $pi->{Version}; + } + PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist)); } return; -- 2.30.2