mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-50907 antivirus: Implement data stream scanning default process.
This commit is contained in:
parent
8504673116
commit
bd74bda383
@ -26,6 +26,7 @@ $string['actantivirushdr'] = 'Available antivirus plugins';
|
||||
$string['antiviruses'] = 'Antivirus plugins';
|
||||
$string['antivirussettings'] = 'Manage antivirus plugins';
|
||||
$string['configantivirusplugins'] = 'Please choose the antivirus plugins you wish to use and arrange them in order of being applied.';
|
||||
$string['datastream'] = 'Data';
|
||||
$string['emailsubject'] = '{$a} :: Antivirus notification';
|
||||
$string['virusfound'] = '{$a->item} has been scanned by a virus checker and found to be infected!';
|
||||
|
||||
|
@ -80,6 +80,23 @@ class manager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan data steam using all enabled antiviruses, throws exception in case of infected data.
|
||||
*
|
||||
* @param string $data The varaible containing the data to scan.
|
||||
* @throws \core\antivirus\scanner_exception If data is infected.
|
||||
* @return void
|
||||
*/
|
||||
public static function scan_data($data) {
|
||||
$antiviruses = self::get_enabled();
|
||||
foreach ($antiviruses as $antivirus) {
|
||||
$result = $antivirus->scan_data($data);
|
||||
if ($result === $antivirus::SCAN_RESULT_FOUND) {
|
||||
throw new \core\antivirus\scanner_exception('virusfounduser', '', array('item' => get_string('datastream', 'antivirus')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns instance of antivirus.
|
||||
*
|
||||
|
@ -109,6 +109,26 @@ abstract class scanner {
|
||||
*/
|
||||
public abstract function scan_file($file, $filename);
|
||||
|
||||
/**
|
||||
* Scan data.
|
||||
*
|
||||
* By default it saves data variable content to file and then scans it using
|
||||
* scan_file method, however if antivirus plugin permits scanning data directly,
|
||||
* the method can be overridden.
|
||||
*
|
||||
* @param string $data The variable containing the data to scan.
|
||||
* @return int Scanning result constants.
|
||||
*/
|
||||
public function scan_data($data) {
|
||||
// Prepare temp file.
|
||||
$tempdir = make_request_directory();
|
||||
$tempfile = $tempdir . DIRECTORY_SEPARATOR . rand();
|
||||
file_put_contents($tempfile, $data);
|
||||
|
||||
// Perform a virus scan now.
|
||||
return $this->scan_file($tempfile, get_string('datastream', 'antivirus'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Email admins about antivirus scan outcomes.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user