Merge branch 'MDL-67504-Master' of https://github.com/tuanngocnguyen/moodle
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 5 Mar 2020 02:46:37 +0000 (10:46 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 5 Mar 2020 02:46:37 +0000 (10:46 +0800)
lib/antivirus/clamav/classes/scanner.php
lib/antivirus/clamav/lang/en/antivirus_clamav.php
lib/antivirus/clamav/settings.php

index 380f60a..624abc4 100644 (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());
index 8e8cb1d..c9eeb6c 100644 (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}';
index 855ad7f..96b8dfd 100644 (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));
 }