Skip to content

Commit

Permalink
Merge pull request #29 from GDATASoftwareAG/tmp/uoload-scanning
Browse files Browse the repository at this point in the history
Tmp/uoload scanning
  • Loading branch information
pstadermann authored Jun 4, 2024
2 parents 0886569 + 3c4dbb1 commit fdfd795
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 158 deletions.
41 changes: 0 additions & 41 deletions .devcontainer/dev/devcontainer.json

This file was deleted.

40 changes: 0 additions & 40 deletions .devcontainer/nextcloud/devcontainer.json

This file was deleted.

8 changes: 8 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@
<database>pgsql</database>
<database>mysql</database>
<database>sqlite</database>
<activity>
<settings>
<setting>OCA\GDataVaas\Activity\Setting</setting>
</settings>
<providers>
<provider>OCA\GDataVaas\Activity\Provider</provider>
</providers>
</activity>
</info>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
}
],
"require": {
"gdata/vaas": "^8.0.0"
"gdata/vaas": "^8.0.2"
},
"require-dev": {
"nextcloud/ocp": "dev-stable28",
"psalm/phar": "^5.17.0",
"nextcloud/coding-standard": "^v1.1.1"
},
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"lint": "find lib -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff .",
"cs:fix": "php-cs-fixer fix .",
"psalm": "vendor/psalm/phar/psalm.phar --threads=1",
Expand Down
16 changes: 16 additions & 0 deletions img/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 9 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

docker stop nextcloud-container
sleep 1
docker run -d --name nextcloud-container --rm --publish 80:80 --publish 8080:8080 --publish 8443:8443 nextcloud:stable
docker run -d --name nextcloud-container --rm --publish 80:80 nextcloud:28
echo "Waiting for sunrise..."
sleep 5
docker exec --user www-data -it nextcloud-container php occ maintenance:install --admin-user=admin --admin-pass=admin

until docker exec --user www-data -it nextcloud-container php occ maintenance:install --admin-user=admin --admin-pass=admin >/dev/null
do
echo "Try again waiting 2 seconds"
sleep 2
done

make build
make appstore
tar -xf ./build/artifacts/gdatavaas.tar.gz -C ./build/artifacts
docker cp ./build/artifacts/gdatavaas nextcloud-container:/var/www/html/apps/
Expand Down
139 changes: 139 additions & 0 deletions lib/Activity/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php
/**
* @copyright Copyright (c) 2018 Roeland Jago Douma <[email protected]>
*
* @author Roeland Jago Douma <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\GDataVaas\Activity;

use OCA\GDataVaas\AppInfo\Application;
use OCP\Activity\IEvent;
use OCP\Activity\IProvider;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;

class Provider implements IProvider {
public const TYPE_VIRUS_DETECTED = 'virus_detected';

public const SUBJECT_VIRUS_DETECTED = 'virus_detected';
public const SUBJECT_VIRUS_DETECTED_UPLOAD = 'virus_detected_upload';
public const SUBJECT_VIRUS_DETECTED_SCAN = 'virus_detected_scan';

public const MESSAGE_FILE_DELETED = 'file_deleted';

/** @var IFactory */
private $languageFactory;

/** @var IURLGenerator */
private $urlGenerator;
private LoggerInterface $logger;

public function __construct(IFactory $languageFactory, IURLGenerator $urlGenerator, LoggerInterface $logger) {
$this->languageFactory = $languageFactory;
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
}

public function parse($language, IEvent $event, IEvent $previousEvent = null) {
if ($event->getApp() !== Application::APP_ID || $event->getType() !== self::TYPE_VIRUS_DETECTED) {
throw new \InvalidArgumentException();
}

$parameters = [];
$subject = '';

if ($event->getSubject() === self::SUBJECT_VIRUS_DETECTED) {
$subject = 'File {file} is infected with {virus}';

$params = $event->getSubjectParameters();
$parameters['virus'] = [
'type' => 'highlight',
'id' => $params[1],
'name' => $params[1],
];

$parameters['file'] = [
'type' => 'highlight',
'id' => $event->getObjectName(),
'name' => basename($event->getObjectName()),
];
$event->setIcon($this->urlGenerator->imagePath('gdatavaas', 'favicon.svg'));

if ($event->getMessage() === self::MESSAGE_FILE_DELETED) {
$event->setParsedMessage('The file has been removed');
}
} elseif ($event->getSubject() === self::SUBJECT_VIRUS_DETECTED_UPLOAD) {
$subject = 'File containing {virus} detected';

$params = $event->getSubjectParameters();
$parameters['virus'] = [
'type' => 'highlight',
'id' => $params[0],
'name' => $params[0],
];

$event->setParsedSubject($subject);
$event->setRichSubject($subject);
$event->setIcon($this->urlGenerator->imagePath('gdatavaas', 'favicon.svg'));

if ($event->getMessage() === self::MESSAGE_FILE_DELETED) {
$event->setParsedMessage('The file has been removed');
}
} elseif ($event->getSubject() === self::SUBJECT_VIRUS_DETECTED_SCAN) {
$subject = 'File {file} is infected with {virus}';

$params = $event->getSubjectParameters();
$parameters['virus'] = [
'type' => 'highlight',
'id' => $params[0],
'name' => $params[0],
];
$parameters['file'] = [
'type' => 'highlight',
'id' => $event->getObjectName(),
'name' => $event->getObjectName(),
];
$event->setIcon($this->urlGenerator->imagePath('gdatavaas', 'favicon.svg'));

if ($event->getMessage() === self::MESSAGE_FILE_DELETED) {
$event->setParsedMessage('The file has been removed');
}
}

$this->setSubjects($event, $subject, $parameters);

return $event;
}

private function setSubjects(IEvent $event, string $subject, array $parameters): void {
$placeholders = $replacements = [];
foreach ($parameters as $placeholder => $parameter) {
$placeholders[] = '{' . $placeholder . '}';
if ($parameter['type'] === 'file') {
$replacements[] = $parameter['path'];
} else {
$replacements[] = $parameter['name'];
}
}

$event->setParsedSubject(str_replace($placeholders, $replacements, $subject))
->setRichSubject($subject, $parameters);
}
}
59 changes: 59 additions & 0 deletions lib/Activity/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @copyright Copyright (c) 2018 Roeland Jago Douma <[email protected]>
*
* @author Roeland Jago Douma <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\GDataVaas\Activity;

use OCP\Activity\ISetting;

class Setting implements ISetting {

public function __construct() {
}

public function getIdentifier() {
return Provider::TYPE_VIRUS_DETECTED;
}

public function getName() {
return 'Antivirus detected a virus';
}

public function getPriority() {
return 70;
}

public function canChangeStream() {
return false;
}

public function isDefaultEnabledStream() {
return true;
}

public function canChangeMail() {
return false;
}

public function isDefaultEnabledMail() {
return false;
}
}
5 changes: 3 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use OC\Files\Filesystem;
use OCA\GDataVaas\AvirWrapper;
use OCA\GDataVaas\Service\VerdictService;
use OCP\Activity\IManager;
use OCP\App\IAppManager;
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
Expand Down Expand Up @@ -71,15 +72,15 @@ function (string $mountPoint, IStorage $storage) {
*/

$container = $this->getContainer();
// $scannerFactory = $container->query(ScannerFactory::class);
$verdictService = $container->get(VerdictService::class);
// $l10n = $container->get(IL10N::class);
$logger = $container->get(LoggerInterface::class);
$activityManager = $container->get(IManager::class);
$eventDispatcher = $container->get(IEventDispatcher::class);
$appManager = $container->get(IAppManager::class);
return new AvirWrapper([
'storage' => $storage,
//'scannerFactory' => $scannerFactory,
'verdictService' => $verdictService,
//'l10n' => $l10n,
'logger' => $logger,
'activityManager' => $activityManager,
Expand Down
Loading

0 comments on commit fdfd795

Please sign in to comment.