Executable.php in ClamAV 2.x
File
src/Scanner/Executable.php
View source
<?php
namespace Drupal\clamav\Scanner;
use Drupal\file\FileInterface;
use Drupal\clamav\ScannerInterface;
use Drupal\clamav\Scanner;
use Drupal\clamav\Config;
class Executable implements ScannerInterface {
private $_executable_path = '';
private $_executable_parameters = '';
private $_file = '';
protected $_virus_name = '';
public function __construct(Config $config) {
$this->_executable_path = $config
->get('mode_executable.executable_path');
$this->_executable_parameters = $config
->get('mode_executable.executable_parameters');
}
public function scan(FileInterface $file) {
if (!file_exists($this->_executable_path)) {
\Drupal::logger('Clam AV')
->warning('Unable to find ClamAV executable at @executable_path', array(
'@executable_path' => $this->_executable_path,
));
return Scanner::FILE_IS_UNCHECKED;
}
$script = "{$this->_executable_path} {$this->_executable_parameters}";
$filename = \Drupal::service('file_system')
->realpath($file
->getFileUri());
$cmd = escapeshellcmd($script) . ' ' . escapeshellarg($filename) . ' 2>&1';
exec($cmd, $output, $return_code);
$output = implode("\n", $output);
switch ($return_code) {
case 0:
return Scanner::FILE_IS_CLEAN;
case 1:
return Scanner::FILE_IS_INFECTED;
default:
return Scanner::FILE_IS_UNCHECKED;
}
}
public function virus_name() {
return $this->_virus_name;
}
public function version() {
if (file_exists($this->_executable_path)) {
return exec(escapeshellcmd($this->_executable_path) . ' -V');
}
else {
return NULL;
}
}
}