[pmg-devel] [RFC pmg-api 2/2] integrate custom_check
Stoiko Ivanov
s.ivanov at proxmox.com
Wed Mar 13 21:39:42 CET 2019
for virus and spam detection and records its time spend in the Statistics DB
and the log
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
PMG/RuleDB/Spam.pm | 11 +++++++++++
bin/pmg-smtp-filter | 26 ++++++++++++++++----------
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/PMG/RuleDB/Spam.pm b/PMG/RuleDB/Spam.pm
index 987b85d..feda0f3 100644
--- a/PMG/RuleDB/Spam.pm
+++ b/PMG/RuleDB/Spam.pm
@@ -359,6 +359,17 @@ sub analyze_spam {
push @$sa_scores, { score => $score, rule => $rule, desc => $descr };
}
+ if (my $hit = $queue->{spam_custom}) {
+ my $score += $queue->{spam_custom};
+ my $descr = "Custom Check Script";
+ my $rule = 'CustomCheck';
+ $sa_score += $score;
+ $list .= $list ? ",$rule" : $rule;
+ $list .= $list ? ",$rule" : $rule;
+ $loglist .= $loglist ? ",$rule($score)" : "$rule($score)";
+ push @$sa_scores, { score => $score, rule => $rule, desc => $descr };
+ }
+
my ($csec, $usec) = gettimeofday ();
my $spamtest = $queue->{sa};
diff --git a/bin/pmg-smtp-filter b/bin/pmg-smtp-filter
index 8bd7740..31fddd5 100755
--- a/bin/pmg-smtp-filter
+++ b/bin/pmg-smtp-filter
@@ -172,10 +172,11 @@ sub get_prox_vars {
$vars->{__spaminfo} = $spaminfo;
if ($opt_testmode) {
- if ($queue->{vinfo_clam} || $queue->{vinfo_avast}) {
+ if ($queue->{vinfo_clam} || $queue->{vinfo_avast} || $queue->{vinfo_custom}) {
$vars->{'VIRUS_INFO'} = "Virus Info:";
$vars->{'VIRUS_INFO'} .= " clam: $queue->{vinfo_clam}" if $queue->{vinfo_clam};
$vars->{'VIRUS_INFO'} .= " avast: $queue->{vinfo_avast}" if $queue->{vinfo_avast};
+ $vars->{'VIRUS_INFO'} .= " custom: $queue->{vinfo_custom}" if $queue->{vinfo_custom};
} else {
$vars->{'VIRUS_INFO'} = '';
}
@@ -670,17 +671,21 @@ sub handle_smtp {
# (SPAM analyzer is run on demand later)
# on error: log error messages
-
- # test for virus first
- my $vinfo = PMG::Utils::analyze_virus(
+ # run custom script first
+ my ($vinfo, $custom_spaminfo) = PMG::Utils::analyze_custom_check(
$queue, $queue->{dataname}, $pmg_cfg, $opt_testmode);
- if ($vinfo && $vinfo =~ m/^Heuristics\.(.+)$/) {
- my $hit = $1;
- $queue->{clamav_heuristic} = $hit;
- $vinfo = undef;
- }
+ # test for virus if none found
+ if (!defined($vinfo)) {
+ $vinfo = PMG::Utils::analyze_virus(
+ $queue, $queue->{dataname}, $pmg_cfg, $opt_testmode);
+ if ($vinfo && $vinfo =~ m/^Heuristics\.(.+)$/) {
+ my $hit = $1;
+ $queue->{clamav_heuristic} = $hit;
+ $vinfo = undef;
+ }
+ }
$queue->{vinfo} = $vinfo;
# always add this headers to incoming mails
@@ -816,8 +821,9 @@ sub handle_smtp {
my $ptspam = ($queue->{ptime_spam} || 0)/1000;
my $ptclam = ($queue->{ptime_clam} || 0)/1000;
+ my $ptcustom = ($queue->{ptime_custom} || 0)/1000;
- $self->log(3, "$queue->{logid}: processing time: ${time_total} seconds ($ptspam, $ptclam)");
+ $self->log(3, "$queue->{logid}: processing time: ${time_total} seconds ($ptspam, $ptclam, $ptcustom)");
$msginfo->{test_fh}->close if $opt_testmode;
--
2.11.0
More information about the pmg-devel
mailing list