Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan files on update or change #156

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .devcontainer/postCreateCommands.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

bash -i -c 'nvm install 20'
bash -i -c 'nvm use 20'

echo "setup php-scoper"
composer global require humbug/php-scoper
$(composer config home)/vendor/bin/php-scoper completion bash >> $HOME.bash_completion
Expand All @@ -22,10 +25,9 @@ echo ". /usr/share/bash-completion/bash_completion" >> /home/vscode/.bashrc
NEXTCLOUD_VERSION=$(grep -oP -m 1 "[0-9]+\.[0-9]+\.[0-9]+" install.sh)

mkdir -p ~/.ssh/
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

rm -rf nextcloud-server/
git clone --depth 1 --recurse-submodules --single-branch --branch v$NEXTCLOUD_VERSION git@github.com:nextcloud/server.git ./nextcloud-server
git clone --depth 1 --recurse-submodules --single-branch --branch v$NEXTCLOUD_VERSION https://github.com/nextcloud/server.git ./nextcloud-server
cd nextcloud-server
git submodule update --init
cd -
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"port": 9080,
"pathMappings": {
"/var/www/html/": "${workspaceFolder}/nextcloud-server",
"/var/www/html/apps/gdatavaas": "${workspaceFolder}/",
"/var/www/html/apps/gdatavaas": "${workspaceFolder}/build/artifacts/gdatavaas",
},
"runtimeArgs": [
"-dxdebug.mode=debug",
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile.Nextcloud
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ RUN echo "error_log = /var/www/html/data/php.log" >> "$PHP_INI_DIR/php.ini"
RUN sed -i 's/#LogLevel info ssl:warn/LogLevel debug/g' /etc/apache2/sites-available/000-default.conf

COPY xdebug.ini /tmp/xdebug.ini
RUN if [[ "$INSTALL_XDEBUG" == "1" ]]; then \
install-php-extensions gd xdebug; \
mv /tmp/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
fi
RUN install-php-extensions gd xdebug
RUN mv /tmp/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

5 changes: 4 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use OCA\GDataVaas\AvirWrapper;
use OCA\GDataVaas\CacheEntryListener;
use OCA\GDataVaas\Db\DbFileMapper;
use OCA\GDataVaas\Listener\CacheEntryInsertedListener;
use OCA\GDataVaas\Service\MailService;
use OCA\GDataVaas\Service\TagService;
use OCA\GDataVaas\Service\VerdictService;
Expand All @@ -20,6 +21,7 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheEntryInsertedEvent;
use OCP\Files\IHomeStorage;
use OCP\Files\Storage\IStorage;
use OCP\IAppConfig;
Expand All @@ -46,7 +48,8 @@ public function __construct() {
$eventDispatcher->addListener(LoadAdditionalScriptsEvent::class, function () {
Util::addScript(self::APP_ID, 'gdatavaas-files-action');
});
}
//$eventDispatcher->addServiceListener(CacheEntryInsertedEvent::class, CacheEntryInsertedListener::class);
}

/**
* Load the composer autoloader if it exists
Expand Down
49 changes: 49 additions & 0 deletions lib/Listener/CacheEntryInsertedListener.php
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());
}
}
}
Loading