Exemple #1
0
 public function testScanFile()
 {
     $fileView = new \OC\Files\View('');
     $cleanStatus = \OCA\Files_Antivirus\Scanner::scanFile($fileView, self::TEST_CLEAN_FILENAME);
     $this->assertInstanceOf('\\OCA\\Files_Antivirus\\Status', $cleanStatus);
     $this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_CLEAN, $cleanStatus->getNumericStatus());
     $infectedStatus = \OCA\Files_Antivirus\Scanner::scanFile($fileView, 'non-existing.file');
     $this->assertInstanceOf('\\OCA\\Files_Antivirus\\Status', $infectedStatus);
     $this->assertEquals(\OCA\Files_Antivirus\Status::SCANRESULT_UNCHECKED, $infectedStatus->getNumericStatus());
 }
Exemple #2
0
 public function __construct()
 {
     parent::__construct();
     // get the path to the executable
     $avPath = \OCP\Config::getAppValue('files_antivirus', 'av_path', '/usr/bin/clamscan');
     // check that the executable is available
     if (!file_exists($avPath)) {
         throw new \RuntimeException('The antivirus executable could not be found at ' . $avPath);
     }
     $this->avPath = $avPath;
 }
Exemple #3
0
 public function initScanner()
 {
     parent::initScanner();
     // using 2>&1 to grab the full command-line output.
     $cmd = $this->avPath . " " . $this->appConfig->getCmdline() . " - 2>&1";
     $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
     $this->process = proc_open($cmd, $descriptorSpec, $this->pipes);
     if (!is_resource($this->process)) {
         throw new \RuntimeException('Error starting process');
     }
 }
 protected function initScanner()
 {
     parent::initScanner();
     if ($this->useSocket) {
         $avSocket = $this->appConfig->getAvSocket();
         $this->writeHandle = stream_socket_client('unix://' . $avSocket, $errno, $errstr, 5);
         if (!$this->writeHandle) {
             throw new \RuntimeException('Cannot connect to "' . $avSocket . '": ' . $errstr . ' (code ' . $errno . ')');
         }
     } else {
         $avHost = $this->appConfig->getAvHost();
         $avPort = $this->appConfig->getAvPort();
         $this->writeHandle = $avHost && $avPort ? @fsockopen($avHost, $avPort) : false;
         if (!$this->writeHandle) {
             throw new \RuntimeException('The clamav module is not configured for daemon mode.');
         }
     }
     // request scan from the daemon
     fwrite($this->writeHandle, "nINSTREAM\n");
 }
 public static function scan($id, $path, $storage)
 {
     $fileStatus = \OCA\Files_Antivirus\Scanner::scanFile($storage, $path);
     $result = $fileStatus->getNumericStatus();
     //TODO: Fix undefined $user here
     switch ($result) {
         case \OCA\Files_Antivirus\Status::SCANRESULT_UNCHECKED:
             \OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" with id "' . $id . '": is not checked', \OCP\Util::ERROR);
             break;
         case \OCA\Files_Antivirus\Status::SCANRESULT_INFECTED:
             $infected_action = \OCP\Config::getAppValue('files_antivirus', 'infected_action', 'only_log');
             if ($infected_action == 'delete') {
                 \OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" with id "' . $id . '": is infected, file deleted', \OCP\Util::ERROR);
                 $storage->unlink($path);
             } else {
                 \OCP\Util::writeLog('files_antivirus', 'File "' . $path . '" with id "' . $id . '": is infected', \OCP\Util::ERROR);
             }
             break;
         case \OCA\Files_Antivirus\Status::SCANRESULT_CLEAN:
             try {
                 $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*files_antivirus` WHERE `fileid` = ?');
                 $result = $stmt->execute(array($id));
                 if (\OCP\DB::isError($result)) {
                     \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
                     return;
                 }
                 $stmt = \OCP\DB::prepare('INSERT INTO `*PREFIX*files_antivirus` (`fileid`, `check_time`) VALUES (?, ?)');
                 $result = $stmt->execute(array($id, time()));
                 if (\OCP\DB::isError($result)) {
                     \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
                     return;
                 }
             } catch (\Exception $e) {
                 \OCP\Util::writeLog('files_antivirus', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
             }
             break;
     }
 }
Exemple #6
0
 public function __construct($useSocket)
 {
     parent::__construct($useSocket);
     $this->useSocket = $useSocket;
 }