MDL-69522 antivirus: Added ability for scanners to set found message

This commit is contained in:
Peter Burnett
2020-12-07 14:44:24 +10:00
parent 7fa836cf36
commit c426b09d0d
2 changed files with 33 additions and 2 deletions
+23 -2
View File
@@ -106,7 +106,18 @@ class manager {
if ($deleteinfected) {
unlink($file);
}
throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => $filename));
// Get custom message to display to user from antivirus engine.
$displaymessage = $antivirus->get_virus_found_message();
$placeholders = array_merge(['item' => $filename], $displaymessage['placeholders']);
throw new \core\antivirus\scanner_exception(
$displaymessage['string'],
'',
$placeholders,
null,
$displaymessage['component']
);
} else if ($result === $antivirus::SCAN_RESULT_ERROR) {
// Here we need to generate a different incident based on an error.
$incidentdetails = $antivirus->get_incident_details($file, $filename, $notice, false);
@@ -163,7 +174,17 @@ class manager {
$event = \core\event\virus_infected_data_detected::create($params);
$event->trigger();
throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => get_string('datastream', 'antivirus')));
// Get custom message to display to user from antivirus engine.
$displaymessage = $antivirus->get_virus_found_message();
$placeholders = array_merge(['item' => get_string('datastream', 'antivirus')], $displaymessage['placeholders']);
throw new \core\antivirus\scanner_exception(
$displaymessage['string'],
'',
$placeholders,
null,
$displaymessage['component']
);
} else if ($result === $antivirus::SCAN_RESULT_ERROR) {
// Here we need to generate a different incident based on an error.
$incidentdetails = $antivirus->get_incident_details('', $filename, $notice, false);
+10
View File
@@ -238,4 +238,14 @@ abstract class scanner {
public function get_messages() : array {
return $this->messages;
}
/**
* Getter method for the antivirus message displayed in the exception.
*
* @return array array of string and component to pass to exception constructor.
*/
public function get_virus_found_message() {
// Base antivirus found string.
return ['string' => 'virusfound', 'component' => 'antivirus', 'placeholders' => []];
}
}