-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP try with explicit scan in CacheEntryInsertedEvent
- Loading branch information
1 parent
cd80b83
commit baeb280
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace OCA\GDataVaas\Listener; | ||
|
||
use Exception; | ||
use OCA\GDataVaas\Service\VerdictService; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Cache\CacheEntryInsertedEvent; | ||
use OCP\Files\EntityTooLargeException; | ||
use OCP\Files\NotFoundException; | ||
use OCP\Files\NotPermittedException; | ||
use Psr\Log\LoggerInterface; | ||
use VaasSdk\Exceptions\FileDoesNotExistException; | ||
use VaasSdk\Exceptions\InvalidSha256Exception; | ||
use VaasSdk\Exceptions\TimeoutException; | ||
use VaasSdk\Exceptions\UploadFailedException; | ||
use VaasSdk\Exceptions\VaasAuthenticationException; | ||
|
||
class CacheEntryInsertedListener implements IEventListener | ||
{ | ||
private readonly LoggerInterface $logger; | ||
private VerdictService $verdictService; | ||
|
||
public function __construct(LoggerInterface $logger, VerdictService $verdictService) | ||
{ | ||
$this->logger = $logger; | ||
$this->verdictService = $verdictService; | ||
} | ||
|
||
public function handle(Event $event): void | ||
{ | ||
if (!($event instanceof CacheEntryInsertedEvent)) { | ||
return; | ||
} | ||
|
||
$this->logger->info('Cache entry inserted: ' . $event->getPath()); | ||
|
||
$fileId = $event->getFileId(); | ||
try { | ||
$verdict = $this->verdictService->scanFileById($fileId); | ||
// Delete file if malicious | ||
} catch (EntityTooLargeException|NotFoundException|NotPermittedException|FileDoesNotExistException|InvalidSha256Exception|TimeoutException|UploadFailedException|VaasAuthenticationException $e) { | ||
$this->logger->error($e->getMessage()); | ||
} catch (Exception $e) { | ||
$this->logger->error('An unexpected error occurred while scanning file ' . $fileId . ' with GData VaaS. Please check the logs for more information and contact your administrator: ' . $e->getMessage()); | ||
} | ||
} | ||
} |