PMG::RESTEnvironment->setup_default_cli_env();
}
-sub domain_regex {
- my ($domains) = @_;
-
- my @ra;
- foreach my $d (@$domains) {
- # skip domains with non-DNS name characters
- next if $d =~ m/[^A-Za-z0-9\-\.]/;
- if ($d =~ m/^\.(.*)$/) {
- my $dom = $1;
- $dom =~ s/\./\\\./g;
- push @ra, $dom;
- push @ra, "\.\*\\.$dom";
- } else {
- $d =~ s/\./\\\./g;
- push @ra, $d;
- }
- }
-
- my $re = join ('|', @ra);
-
- my $regex = qr/\@($re)$/i;
-
- return $regex;
-}
-
sub get_item_data {
my ($data, $ref) = @_;
$item->{spaminfo} = $ref->{info};
$item->{file} = $ref->{file};
- my $basehref = "$data->{protocol}://$data->{fqdn}:$data->{port}/quarantine";
+ my $basehref = "$data->{protocol_fqdn_port}/quarantine";
my $ticket = uri_escape($data->{ticket});
$item->{href} = "$basehref?ticket=$ticket&cselect=$item->{id}&date=$item->{date}";
my $role = $cinfo->{local}->{type} // '-';
if (!(($role eq '-') || ($role eq 'master'))) {
- die "local node is not mastern";
+ warn "local node is not master\n";
+ return;
}
my $cfg = PMG::Config->new();
my $dbh = PMG::DBTools::open_ruledb();
my $domains = PVE::INotify::read_file('domains');
- my $domainregex = domain_regex([keys %$domains]);
+ my $domainregex = PMG::Utils::domain_regex([keys %$domains]);
my $sth = $dbh->prepare(
"SELECT pmail, AVG(spamlevel) as spamlevel, count(*) FROM CMailStore, CMSReceivers " .
my $role = $cinfo->{local}->{type} // '-';
if (!(($role eq '-') || ($role eq 'master'))) {
- die "local node is not master - not sending spam report\n";
+ warn "local node is not master - not sending spam report\n";
+ return;
}
my $cfg = PMG::Config->new();
my $protocol = $cfg->get('spamquar', 'protocol') // 'https';
+ my $protocol_fqdn_port = "$protocol://$fqdn";
+ if (($protocol eq 'https' && $port != 443) ||
+ ($protocol eq 'http' && $port != 80)) {
+ $protocol_fqdn_port .= ":$port";
+ }
+
my $global_data = {
protocol => $protocol,
port => $port,
date => strftime("%F", localtime($end - 1)),
timespan => $timespan,
items => [],
+ protocol_fqdn_port => $protocol_fqdn_port,
};
my $mailfrom = $cfg->get ('spamquar', 'mailfrom') //
}
my $domains = PVE::INotify::read_file('domains');
- my $domainregex = domain_regex([keys %$domains]);
+ my $domainregex = PMG::Utils::domain_regex([keys %$domains]);
my $template = "spamreport-${reportstyle}.tt";
my $found = 0;
$sth->execute();
}
- my $lastref;
my $mailcount = 0;
my $creceiver = '';
my $data;
$data->{pmail} = $creceiver;
$data->{ticket} = PMG::Ticket::assemble_quarantine_ticket($data->{pmail});
my $esc_ticket = uri_escape($data->{ticket});
- $data->{managehref} = "$protocol://$fqdn:$port/quarantine?ticket=${esc_ticket}";
+ $data->{managehref} = "$protocol_fqdn_port/quarantine?ticket=${esc_ticket}";
}
push @{$data->{items}}, get_item_data($data, $ref);
$mailcount++;
- $lastref = $ref;
}
$sth->finish();
if (my $count = PMG::DBTools::purge_quarantine_database($dbh, 'V', $viruslifetime)) {
print STDERR "removed $count virus quarantine files\n";
}
+
+ if (my $count = PMG::DBTools::purge_quarantine_database($dbh, 'A', $spamlifetime)) {
+ print STDERR "removed $count attachment quarantine files\n";
+ }
}
test_quarantine_files($spamlifetime, $viruslifetime, $purge);