Skip to content

Commit

Permalink
MDL-67504 antivirus_clamav: Add scanning tries option
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Mar 1, 2020
1 parent d737452 commit 464bd7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/antivirus/clamav/classes/scanner.php
Expand Up @@ -72,20 +72,28 @@ public function scan_file($file, $filename) {

// We can do direct stream scanning if unixsocket or tcpsocket running methods are in use,
// if not, use default process.
$runningmethod = $this->get_config('runningmethod');
switch ($runningmethod) {
case 'unixsocket':
case 'tcpsocket':
$return = $this->scan_file_execute_socket($file, $runningmethod);
break;
case 'commandline':
$return = $this->scan_file_execute_commandline($file);
break;
default:
// This should not happen.
debugging('Unknown running method.');
return self::SCAN_RESULT_ERROR;
}
$maxtries = get_config('antivirus_clamav', 'tries');
$tries = 0;
do {
$runningmethod = $this->get_config('runningmethod');
$tries++;
switch ($runningmethod) {
case 'unixsocket':
case 'tcpsocket':
$return = $this->scan_file_execute_socket($file, $runningmethod);
break;
case 'commandline':
$return = $this->scan_file_execute_commandline($file);
break;
default:
// This should not happen.
throw new \coding_exception('Unknown running method.');
}
} while ($return == self::SCAN_RESULT_ERROR && $tries < $maxtries);

$notice = get_string('tries_notice', 'antivirus_clamav',
['tries' => $tries, 'notice' => $this->get_scanning_notice()]);
$this->set_scanning_notice($notice);

if ($return === self::SCAN_RESULT_ERROR) {
$this->message_admins($this->get_scanning_notice());
Expand Down
4 changes: 4 additions & 0 deletions lib/antivirus/clamav/lang/en/antivirus_clamav.php
Expand Up @@ -50,3 +50,7 @@
$string['tcpsocketport'] = 'TCP socket port';
$string['tcpsocketportdesc'] = 'The port to use when connecting to ClamAV';
$string['unknownerror'] = 'There was an unknown error with ClamAV.';
$string['tries'] = 'Scanning attempts';
$string['tries_desc'] = 'Number of attempts clamav will try when there is an error during scanning process';
$string['tries_notice'] = 'Clamav scanning has tried {$a->tries} time(s).
{$a->notice}';
6 changes: 6 additions & 0 deletions lib/antivirus/clamav/settings.php
Expand Up @@ -67,4 +67,10 @@
$settings->add(new admin_setting_configselect('antivirus_clamav/clamfailureonupload',
new lang_string('clamfailureonupload', 'antivirus_clamav'),
new lang_string('configclamfailureonupload', 'antivirus_clamav'), 'donothing', $options));

// Number of attempts clamav will try when there is error during a scanning process.
$options = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5);
$settings->add(new admin_setting_configselect('antivirus_clamav/tries',
new lang_string('tries', 'antivirus_clamav'),
new lang_string('tries_desc', 'antivirus_clamav'), 1, $options));
}

0 comments on commit 464bd7e

Please sign in to comment.