use RRDs;
use Filesys::Df;
use Encode;
+use utf8;
+no utf8;
+
use HTML::Entities;
use PVE::ProcFSTools;
}
}
- if (!$smtp->mail($sender)) {
+ my $has_utf8_targets = 0;
+ foreach my $target (@$targets) {
+ if (utf8::is_utf8($target)) {
+ $has_utf8_targets = 1;
+ last;
+ }
+ }
+
+ my $mail_opts = " BODY=8BITMIME";
+ my $sender_addr;
+ if (utf8::is_utf8($sender)) {
+ $sender_addr = encode('UTF-8', $smtp->_addr($sender));
+ $mail_opts .= " SMTPUTF8";
+ } else {
+ $sender_addr = $smtp->_addr($sender);
+ $mail_opts .= " SMTPUTF8" if $has_utf8_targets;
+ }
+
+ if (!$smtp->_MAIL("FROM:" . $sender_addr . $mail_opts)) {
syslog('err', "smtp error - got: %s %s", $smtp->code, scalar ($smtp->message));
die "smtp from: ERROR";
}
- my $dsnopts = $nodsn ? {Notify => ['NEVER']} : {};
+ my $rcpt_opts = $nodsn ? " NOTIFY=NEVER" : "";
- if (!$smtp->to (@$targets, $dsnopts)) {
- syslog ('err', "smtp error - got: %s %s", $smtp->code, scalar($smtp->message));
- die "smtp to: ERROR";
+ foreach my $target (@$targets) {
+ my $rcpt_addr;
+ if (utf8::is_utf8($target)) {
+ $rcpt_addr = encode('UTF-8', $smtp->_addr($target));
+ } else {
+ $rcpt_addr = $smtp->_addr($target);
+ }
+ if (!$smtp->_RCPT("TO:" . $rcpt_addr . $rcpt_opts)) {
+ syslog ('err', "smtp error - got: %s %s", $smtp->code, scalar($smtp->message));
+ die "smtp to: ERROR";
+ }
}
# Output the head:
return $vinfo ? "$vinfo (clamav)" : undef;
}
+sub analyze_virus_avast {
+ my ($queue, $dname, $pmg_cfg) = @_;
+
+ my $timeout = 60*5;
+ my $vinfo;
+
+ my ($csec, $usec) = gettimeofday();
+
+ my $previous_alarm;
+
+ eval {
+
+ $previous_alarm = alarm($timeout);
+
+ $SIG{ALRM} = sub {
+ die "$queue->{logid}: Maximum time ($timeout sec) exceeded. " .
+ "virus analyze (avast) failed: ERROR";
+ };
+
+ open(my $cmd, '-|', '/bin/scan', $dname) ||
+ die "$queue->{logid}: can't exec avast scan: $! : ERROR";
+
+ my $response = '';
+ while (defined(my $line = <$cmd>)) {
+ if ($line =~ m/^$dname\s+(.*\S)\s*$/) {
+ # we just use the first detected virus name
+ $vinfo = $1 if !$vinfo;
+ }
+
+ $response .= $line;
+ }
+
+ close($cmd);
+
+ alarm(0); # avoid race conditions
+
+ if ($vinfo) {
+ syslog('info', "$queue->{logid}: virus detected: $vinfo (avast)");
+ }
+ };
+ my $err = $@;
+
+ alarm($previous_alarm);
+
+ my ($csec_end, $usec_end) = gettimeofday();
+ $queue->{ptime_clam} =
+ int (($csec_end-$csec)*1000 + ($usec_end - $usec)/1000);
+
+ if ($err) {
+ syslog ('err', $err);
+ $vinfo = undef;
+ $queue->{errors} = 1;
+ }
+
+ return undef if !$vinfo;
+
+ $queue->{vinfo_avast} = $vinfo;
+
+ return "$vinfo (avast)";
+}
+
sub analyze_virus {
my ($queue, $filename, $pmg_cfg, $testmode) = @_;
# TODO: support other virus scanners?
- # always scan with clamav
- return analyze_virus_clam($queue, $filename, $pmg_cfg);
+ if ($testmode) {
+ my $vinfo_clam = analyze_virus_clam($queue, $filename, $pmg_cfg);
+ my $vinfo_avast = analyze_virus_avast($queue, $filename, $pmg_cfg);
+
+ return $vinfo_avast || $vinfo_clam;
+ }
+
+ my $enable_avast = $pmg_cfg->get('admin', 'avast');
+
+ if ($enable_avast) {
+ if (my $vinfo = analyze_virus_avast($queue, $filename, $pmg_cfg)) {
+ return $vinfo;
+ }
+ }
+
+ my $enable_clamav = $pmg_cfg->get('admin', 'clamav');
+
+ if ($enable_clamav) {
+ if (my $vinfo = analyze_virus_clam($queue, $filename, $pmg_cfg)) {
+ return $vinfo;
+ }
+ }
+
+ return undef;
}
sub magic_mime_type_for_file {