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()); }
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; } }