MDL-67504 antivirus_clamav: Add scanning tries option

This commit is contained in:
Nathan Nguyen 2020-02-24 09:40:57 +11:00
parent d7374522ed
commit 464bd7ecd5
3 changed files with 32 additions and 14 deletions

View File

@ -72,20 +72,28 @@ class scanner extends \core\antivirus\scanner {
// 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());

View File

@ -50,3 +50,7 @@ $string['tcpsockethostdesc'] = 'Domain name of the ClamAV server';
$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}';

View File

@ -67,4 +67,10 @@ if ($ADMIN->fulltree) {
$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));
}