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 9884B68D9A for ; Fri, 15 Jan 2021 11:03:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 894E02321A for ; Fri, 15 Jan 2021 11:02:44 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 id E7AE32320F for ; Fri, 15 Jan 2021 11:02:43 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id ACE7C447F7 for ; Fri, 15 Jan 2021 11:02:43 +0100 (CET) To: Stoiko Ivanov , pmg-devel@lists.proxmox.com References: <20201230171539.7644-1-s.ivanov@proxmox.com> <20201230171539.7644-3-s.ivanov@proxmox.com> From: Thomas Lamprecht Message-ID: <5c086b1d-86f6-77e2-1f44-302656162535@proxmox.com> Date: Fri, 15 Jan 2021 11:02:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Thunderbird/85.0 MIME-Version: 1.0 In-Reply-To: <20201230171539.7644-3-s.ivanov@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.050 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.237 Looks like a legit reply (A) 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [spamassassin.pm] Subject: Re: [pmg-devel] [PATCH pmg-api v2 2/4] api: spamassassin: read local channels X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Jan 2021 10:03:14 -0000 On 30.12.20 18:15, Stoiko Ivanov wrote: > Signed-off-by: Stoiko Ivanov > --- > v1->v2: > * changed the transliteration (tr///) to an equivalent more common s///= >=20 > src/PMG/API2/SpamAssassin.pm | 83 +++++++++++++++++++++---------------= > 1 file changed, 49 insertions(+), 34 deletions(-) >=20 > diff --git a/src/PMG/API2/SpamAssassin.pm b/src/PMG/API2/SpamAssassin.p= m > index eab02d9..6b9f8f9 100644 > --- a/src/PMG/API2/SpamAssassin.pm > +++ b/src/PMG/API2/SpamAssassin.pm > @@ -80,50 +80,65 @@ __PACKAGE__->register_method({ > my ($param) =3D @_; > =20 > my $saversion =3D $Mail::SpamAssassin::VERSION; > - my $channelfile =3D "/var/lib/spamassassin/$saversion/updates_spamass= assin_org.cf"; > + my $sa_update_dir =3D "/var/lib/spamassassin/$saversion/"; > + > + my $check_channel =3D sub { > + my ($channel) =3D @_; > + > + # see sa-update source: > + my $channel_file_base =3D $channel; > + $channel_file_base =3D~ s/[^A-Za-z0-9-]+/_/g; > + my $channelfile =3D "${sa_update_dir}${channel_file_base}.cf"; > + > + my $mtime =3D -1; > + my $version =3D -1; > + my $newversion =3D -1; > + > + if (-f $channelfile) { > + # stat metadata cf file > + $mtime =3D (stat($channelfile))[9]; # 9 is mtime > + > + # parse version from metadata cf file > + my $metadata =3D PVE::Tools::file_read_firstline($channelfile); > + if ($metadata =3D~ m/\s([0-9]+)$/) { > + $version =3D $1; > + } else { > + warn "invalid metadata in '$channelfile'\n"; I know it was already there, but this mayresults in a undef comparison when checking `if ($newversion > $version) {` below. I'd do a separate followup with that being fixed, e.g., by either prepend= ing the if check with a `!defined($version) || ...` check or setting it to -1000 = or so. > + } > + } > + # call sa-update to see if updates are available > =20 > - my $mtime =3D -1; > - my $version =3D -1; > - my $newversion =3D -1; > + my $cmd =3D "$SAUPDATE -v --checkonly --channel $channel"; > + PVE::Tools::run_command($cmd, noerr =3D> 1, logfunc =3D> sub { > + my ($line) =3D @_; > =20 > - if (-f $channelfile) { > - # stat metadata cf file > - $mtime =3D (stat($channelfile))[9]; # 9 is mtime > + if ($line =3D~ m/Update available for channel \S+: -?[0-9]+ -> ([0-9= ]+)/) { > + $newversion =3D $1; > + } > + }); > =20 > - # parse version from metadata cf file > - my $metadata =3D PVE::Tools::file_read_firstline($channelfile); > - if ($metadata =3D~ m/\s([0-9]+)$/) { > - $version =3D $1; > - } else { > - warn "invalid metadata in '$channelfile'\n"; > - } > - } > - # call sa-update to see if updates are available > + my $result =3D { > + channel =3D> $channel, > + }; > =20 > - my $cmd =3D "$SAUPDATE -v --checkonly"; > - PVE::Tools::run_command($cmd, noerr =3D> 1, logfunc =3D> sub { > - my ($line) =3D @_; > + $result->{version} =3D $version if $version > -1; > + $result->{update_version} =3D $newversion if $newversion > -1; > + $result->{last_updated} =3D $mtime if $mtime > -1; > =20 > - if ($line =3D~ m/Update available for channel \S+: -?[0-9]+ -> ([= 0-9]+)/) { > - $newversion =3D $1; > + if ($newversion > $version) { > + $result->{update_avail} =3D 1; > + } else { > + $result->{update_avail} =3D 0; > } > - }); > - > - my $result =3D { > - channel =3D> 'updates.spamassassin.org', > + return $result; > }; > =20 > - $result->{version} =3D $version if $version > -1; > - $result->{update_version} =3D $newversion if $newversion > -1; > - $result->{last_updated} =3D $mtime if $mtime > -1; > + my @channels =3D ('updates.spamassassin.org'); > =20 > - if ($newversion > $version) { > - $result->{update_avail} =3D 1; > - } else { > - $result->{update_avail} =3D 0; > - } > + my $localchannels =3D PMG::Utils::local_spamassassin_channels(); > + push(@channels, map { $_->{channelurl} } @$localchannels); > =20 > - return [$result]; > + return [ map { $check_channel->($_) } @channels]; this reads a bit weird, but can be OK as $check_channel does seem to catc= h all actual possible errors. > }}); > =20 > __PACKAGE__->register_method({ >=20