]> git.proxmox.com Git - pmg-api.git/commitdiff
integrate custom_check
authorStoiko Ivanov <s.ivanov@proxmox.com>
Wed, 13 Mar 2019 20:39:42 +0000 (21:39 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 14 Mar 2019 06:17:46 +0000 (07:17 +0100)
for virus and spam detection and records its time spend in the Statistics DB
and the log

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
PMG/RuleDB/Spam.pm
bin/pmg-smtp-filter

index 987b85d31be3c9522418e4fee91c59069940e640..feda0f38810244456197cb58f7d7d5cdeda10246 100644 (file)
@@ -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};
index 8bd77405ffd6b24495f51fd8c434fd33844c7c5a..31fddd59f4c6ce7a6d6f4f180005215245a8072d 100755 (executable)
@@ -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;