Skip to content

Commit

Permalink
MDL-50887 antivirus_clamav: Implement file scanning functionality.
Browse files Browse the repository at this point in the history
This also removes runclamonupload config setting. It is implied that files
will be scanned if plugin is enabled, no need to have a separate setting.

In addition to that, some language strings are updated. It is 'ClamAV', not
'clam AV' (see http://www.clamav.net/index.html).
  • Loading branch information
kabalin committed Feb 25, 2016
1 parent 7d19e0e commit 1a1d249
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
10 changes: 4 additions & 6 deletions lib/antivirus/clamav/lang/en/antivirus_clamav.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
$string['configclamactlikevirus'] = 'Treat files like viruses';
$string['configclamdonothing'] = 'Treat files as OK';
$string['configclamfailureonupload'] = 'If you have configured clam to scan uploaded files, but it is configured incorrectly or fails to run for some unknown reason, how should it behave? If you choose \'Treat files like viruses\', they\'ll be moved into the quarantine area, or deleted. If you choose \'Treat files as OK\', the files will be moved to the destination directory like normal. Either way, admins will be alerted that clam has failed. If you choose \'Treat files like viruses\' and for some reason clam fails to run (usually because you have entered an invalid pathtoclam), ALL files that are uploaded will be moved to the given quarantine area, or deleted. Be careful with this setting.';
$string['configpathtoclam'] = 'Path to clam AV. Probably something like /usr/bin/clamscan or /usr/bin/clamdscan. You need this in order for clam AV to run.';
$string['configquarantinedir'] = 'If you want clam AV to move infected files to a quarantine directory, enter it here. It must be writable by the webserver. If you leave this blank, or if you enter a directory that doesn\'t exist or isn\'t writable, infected files will be deleted. Do not include a trailing slash.';
$string['configrunclamavonupload'] = 'When enabled, clam AV will be used to scan all uploaded files.';
$string['clamfailureonupload'] = 'On clam AV failure';
$string['pathtoclam'] = 'clam AV path';
$string['configpathtoclam'] = 'Path to ClamAV. Probably something like /usr/bin/clamscan or /usr/bin/clamdscan. You need this in order for ClamAV to run.';
$string['configquarantinedir'] = 'If you want ClamAV to move infected files to a quarantine directory, enter it here. It must be writable by the webserver. If you leave this blank, or if you enter a directory that doesn\'t exist or isn\'t writable, infected files will be deleted. Do not include a trailing slash.';
$string['clamfailureonupload'] = 'On ClamAV failure';
$string['pathtoclam'] = 'ClamAV path';
$string['pluginname'] = 'ClamAV antivirus';
$string['quarantinedir'] = 'Quarantine directory';
$string['runclamavonupload'] = 'Use clam AV on uploaded files';
22 changes: 22 additions & 0 deletions lib/antivirus/clamav/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,26 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class antivirus_clamav extends antivirus {
/**
* Are the necessary antivirus settings configured?
*
* @return bool True if all necessary config settings been entered
*/
public function is_configured() {
return !empty($this->config->pathtoclam);
}
/**
* Scan file, throws exception in case of infected file.
*
* Please note that the scanning engine must be able to access the file,
* permissions of the file are not modified here!
*
* @param string $file Full path to the file.
* @param bool $deleteinfected whether infected file needs to be deleted.
* @throws moodle_exception If file is infected.
* @return void
*/
public function scan_file($file, $deleteinfected) {
// Here goes the scanning code.
}
}
2 changes: 0 additions & 2 deletions lib/antivirus/clamav/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
defined('MOODLE_INTERNAL') || die();

if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('antivirus_clamav/runclamonupload',
new lang_string('runclamavonupload', 'antivirus_clamav'), new lang_string('configrunclamavonupload', 'antivirus_clamav'), 0));
$settings->add(new admin_setting_configexecutable('antivirus_clamav/pathtoclam',
new lang_string('pathtoclam', 'antivirus_clamav'), new lang_string('configpathtoclam', 'antivirus_clamav'), ''));
$settings->add(new admin_setting_configdirectory('antivirus_clamav/quarantinedir',
Expand Down

0 comments on commit 1a1d249

Please sign in to comment.