# example postscreen log entry for RBL rejects
# Aug 29 08:00:36 proxmox postfix/postscreen[11266]: NOQUEUE: reject: RCPT from [x.x.x.x]:1234: 550 5.7.1 Service unavailable; client [x.x.x.x] blocked using zen.spamhaus.org; from=<xxxx>, to=<yyyy>, proto=ESMTP, helo=<zzz>
+ # example for PREGREET reject
+ # Dec 7 06:57:11 proxmox postfix/postscreen[32084]: PREGREET 14 after 0.23 from [x.x.x.x]:63492: EHLO yyyyy\r\n
+
my $identifier = 'postfix/postscreen';
- my $count = 0;
+ my $rbl_count = 0;
+ my $pregreet_count = 0;
my $parser = sub {
my $line = shift;
return;
}
- return if $line !~ m/\s$identifier\[\d+\]:\sNOQUEUE:\sreject:.*550 5.7.1 Service unavailable;/;
- $count++;
+ if ($line =~ m/\s$identifier\[\d+\]:\sNOQUEUE:\sreject:.*550 5.7.1 Service unavailable;/) {
+ $rbl_count++;
+ } elsif ($line =~ m/\s$identifier\[\d+\]:\sPREGREET\s\d+\safter\s/) {
+ $pregreet_count++;
+ }
};
# limit to last 5000 lines to avoid long delays
PVE::Tools::run_command($cmd, outfunc => $parser);
- return $count;
+ return ($rbl_count, $pregreet_count);
}
my $hwaddress;
sub update_rbl_stats {
my ($dbh, $lcid) = @_;
- my $rblcount = PMG::Utils::scan_journal_for_rbl_rejects();
- return if !$rblcount;
+ my ($rbl_count, $pregreet_count) = PMG::Utils::scan_journal_for_rbl_rejects();
+ return if !$rbl_count && !$pregreet_count;
my $timezone = tz_local_offset();;
my $hour = int((time() + $timezone)/3600) * 3600;
my $sth = $dbh->prepare(
- 'INSERT INTO LocalStat (Time, RBLCount, CID, MTime) ' .
- 'VALUES (?, ?, ?, EXTRACT(EPOCH FROM now())) ' .
+ 'INSERT INTO LocalStat (Time, RBLCount, PregreetCount, CID, MTime) ' .
+ 'VALUES (?, ?, ?, ?, EXTRACT(EPOCH FROM now())) ' .
'ON CONFLICT (Time, CID) DO UPDATE SET ' .
'RBLCount = LocalStat.RBLCount + excluded.RBLCount, ' .
+ 'PregreetCount = LocalStat.PregreetCount + excluded.PregreetCount, ' .
'MTime = excluded.MTime');
- $sth->execute($hour, $rblcount, $lcid);
+ $sth->execute($hour, $rbl_count, $pregreet_count, $lcid);
$sth->finish();
};