diff --git a/README.md b/README.md index fe7226ce..f9149136 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ The app offers a variety of settings to customize the behavior of the antivirus. - **Authentication Method:** If you have created your own account on https://vaas.gdata.de/login, select 'Resource Owner Password Flow' here. If you have received access data from your provider (Client ID and Secret), select 'Client Credentials Flow'. - **Scan only this:** Equivalent to an allowlist. If the values here are separated by commas, e.g. "Documents, .exe, Scan", only those containing the corresponding values in the path are scanned. In this example, *.exe files and the contents of the Documents/ and Scan/ folders would be scanned. -- **Do not scan this:** Equivalent to a blocklist. If there are values separated by commas, e.g. "Documents, .exe, Scan", these are not scanned.time until all files are scanned. Recommended are values between 10 and 100. +- **Do not scan this:** Equivalent to a blocklist. If there are values separated by commas, e.g. "Documents, .exe, Scan", these are not scanned. - **Quarantine folder:** If an existing file is found to be malicious, it is moved to this folder in the user's home directory. If the folder does not exist, it is created automatically. If you do not want to use a quarantine folder, leave this field empty. - **Notify mails:** If an email address is entered here (or multiple comma seperated), a notification is sent to this address when a user uploads a file that is found to be malicious. - **Maximum scan size:** Files larger than this size (in MB) are not scanned and tagged as "Won't Scan". Recommended values are between 10 and 300 MB. diff --git a/appinfo/routes.php b/appinfo/routes.php index ffaaf294..17b8d0d3 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -12,8 +12,6 @@ ['name' => 'settings#setadvancedconfig', 'url' => '/setadvancedconfig', 'verb' => 'POST'], ['name' => 'settings#setAutoScan', 'url' => '/setAutoScan', 'verb' => 'POST'], ['name' => 'settings#getAutoScan', 'url' => '/getAutoScan', 'verb' => 'GET'], - ['name' => 'settings#setScanOnlyNewFiles', 'url' => '/setScanOnlyNewFiles', 'verb' => 'POST'], - ['name' => 'settings#getScanOnlyNewFiles', 'url' => '/getScanOnlyNewFiles', 'verb' => 'GET'], ['name' => 'settings#setPrefixMalicious', 'url' => '/setPrefixMalicious', 'verb' => 'POST'], ['name' => 'settings#getPrefixMalicious', 'url' => '/getPrefixMalicious', 'verb' => 'GET'], ['name' => 'settings#getAuthMethod', 'url' => '/getAuthMethod', 'verb' => 'GET'], @@ -23,10 +21,6 @@ ['name' => 'settings#getCounters', 'url' => '/getCounters', 'verb' => 'GET'], ['name' => 'settings#getSendMailOnVirusUpload', 'url' => '/getSendMailOnVirusUpload', 'verb' => 'GET'], ['name' => 'settings#setSendMailOnVirusUpload', 'url' => '/setSendMailOnVirusUpload', 'verb' => 'POST'], - ['name' => 'settings#getSendMailSummaryOfMaliciousFiles', 'url' - => '/getSendMailSummaryOfMaliciousFiles', 'verb' => 'GET'], - ['name' => 'settings#setSendMailSummaryOfMaliciousFiles', 'url' - => '/setSendMailSummaryOfMaliciousFiles', 'verb' => 'POST'], ['name' => 'settings#testsettings', 'url' => '/testsettings', 'verb' => 'POST'], ['name' => 'settings#getCache', 'url' => '/getCache', 'verb' => 'GET'], ['name' => 'settings#getHashlookup', 'url' => '/getHashlookup', 'verb' => 'GET'] diff --git a/lib/BackgroundJobs/NotifyAdminJob.php b/lib/BackgroundJobs/NotifyAdminJob.php deleted file mode 100644 index 1e4f6ff4..00000000 --- a/lib/BackgroundJobs/NotifyAdminJob.php +++ /dev/null @@ -1,106 +0,0 @@ - -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -namespace OCA\GDataVaas\BackgroundJobs; - -use OC\User\NoUserException; -use OCA\GDataVaas\AppInfo\Application; -use OCA\GDataVaas\Db\DbFileMapper; -use OCA\GDataVaas\Service\FileService; -use OCA\GDataVaas\Service\MailService; -use OCA\GDataVaas\Service\TagService; -use OCP\AppFramework\Utility\ITimeFactory; -use OCP\BackgroundJob\TimedJob; -use OCP\DB\Exception; -use OCP\Files\File; -use OCP\Files\NotFoundException; -use OCP\Files\NotPermittedException; -use OCP\IAppConfig; -use OCP\SystemTag\TagNotFoundException; -use Psr\Log\LoggerInterface; - -class NotifyAdminJob extends TimedJob { - private IAppConfig $appConfig; - private TagService $tagService; - private DbFileMapper $dbFileMapper; - private MailService $mailService; - private LoggerInterface $logger; - private FileService $fileService; - - public function __construct(ITimeFactory $time, - IAppConfig $appConfig, - TagService $tagService, - DbFileMapper $dbFileMapper, - LoggerInterface $logger, - MailService $mailService, - FileService $fileService) { - parent::__construct($time); - - $this->appConfig = $appConfig; - $this->tagService = $tagService; - $this->dbFileMapper = $dbFileMapper; - $this->logger = $logger; - $this->mailService = $mailService; - $this->fileService = $fileService; - - $this->setInterval(7 * 24 * 3600); - $this->setAllowParallelRuns(false); - $this->setTimeSensitivity(self::TIME_INSENSITIVE); - } - - /** - * @param $argument - * @return void - * @throws Exception - * @throws NotFoundException - * @throws NotPermittedException - * @throws \Exception - */ - #[\Override] - protected function run($argument): void { - $notifyAdminEnabled = $this->appConfig->getValueBool(Application::APP_ID, 'notifyAdminEnabled'); - if (!$notifyAdminEnabled) { - return; - } - - try { - $maliciousTagId = $this->tagService->getTag(TagService::MALICIOUS, false)->getId(); - } catch (TagNotFoundException) { - return; - } - $allFiles = $this->dbFileMapper->getFilesCount(); - $maliciousFiles = $this->dbFileMapper->getFileIdsWithTags([$maliciousTagId], $allFiles); - - $this->logger->info( - 'Found ' . count($maliciousFiles) . ' malicious files out of ' . $allFiles . ' total files' - ); - - if (count($maliciousFiles) > 0) { - $this->logger->debug('Sending notification to admin'); - $this->mailService->notifyWeeklySummary($this->getFilesFromFileIds($maliciousFiles)); - } else { - $this->logger->info('No malicious files found, no weekly summary sent'); - } - } - - /** - * @param array $fileIds - * @return array - * @throws NotFoundException - * @throws NotPermittedException - * @throws NoUserException - */ - private function getFilesFromFileIds(array $fileIds): array { - $files = []; - foreach ($fileIds as $fileId) { - $file = $this->fileService->getNodeFromFileId($fileId); - if ($file instanceof File) { - $files[] = $file; - } - } - return $files; - } -} diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 651a40dc..80681176 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -100,15 +100,6 @@ public function getAutoScan(): JSONResponse { return new JSONResponse(['status' => $this->config->getValueBool($this->appName, 'autoScanFiles')]); } - public function setScanOnlyNewFiles(bool $scanOnlyNewFiles): JSONResponse { - $this->config->setValueBool($this->appName, 'scanOnlyNewFiles', $scanOnlyNewFiles); - return new JSONResponse(['status' => 'success']); - } - - public function getScanOnlyNewFiles(): JSONResponse { - return new JSONResponse(['status' => $this->config->getValueBool($this->appName, 'scanOnlyNewFiles')]); - } - public function setPrefixMalicious(bool $prefixMalicious): JSONResponse { $this->config->setValueBool($this->appName, 'prefixMalicious', $prefixMalicious); return new JSONResponse(['status' => 'success']); @@ -163,15 +154,6 @@ public function setSendMailOnVirusUpload(bool $sendMailOnVirusUpload): JSONRespo return new JSONResponse(['status' => 'success']); } - public function getSendMailSummaryOfMaliciousFiles(): JSONResponse { - return new JSONResponse(['status' => $this->config->getValueBool($this->appName, 'notifyAdminEnabled')]); - } - - public function setSendMailSummaryOfMaliciousFiles(bool $sendMailSummaryOfMaliciousFiles): JSONResponse { - $this->config->setValueBool($this->appName, 'notifyAdminEnabled', $sendMailSummaryOfMaliciousFiles); - return new JSONResponse(['status' => 'success']); - } - public function testSettings(string $tokenEndpoint, string $vaasUrl): JSONResponse { try { $authenticator = $this->verdictService->getAuthenticator($this->verdictService->authMethod, $tokenEndpoint); diff --git a/lib/Service/MailService.php b/lib/Service/MailService.php index 358b566e..c154d524 100644 --- a/lib/Service/MailService.php +++ b/lib/Service/MailService.php @@ -9,9 +9,6 @@ use Coduo\PHPHumanizer\NumberHumanizer; use Exception; use OCA\GDataVaas\AppInfo\Application; -use OCP\Files\File; -use OCP\Files\InvalidPathException; -use OCP\Files\NotFoundException; use OCP\IAppConfig; use OCP\Mail\IMailer; use Psr\Log\LoggerInterface; @@ -76,100 +73,4 @@ private function getNotifyMails(): array { } return explode(',', $notifyMails); } - - /** - * @param array $maliciousFiles - * @return void - * @throws Exception - */ - public function notifyWeeklySummary(array $maliciousFiles): void { - $msg = $this->mailer->createMessage(); - $msg->setSubject('Summary: Malicious files in your Nextcloud instance'); - $msg->setHtmlBody($this->createSummaryHtml($maliciousFiles)); - $msg->setPlainBody($this->createSummaryPlain($maliciousFiles)); - $receiver = $this->getNotifyMails(); - $msg->setTo($receiver); - - $this->mailer->send($msg); - $this->logger->debug('Mail sent to ' . implode(', ', $receiver)); - } - - /** - * @param array $maliciousFiles - * @return string - */ - private function createSummaryHtml(array $maliciousFiles): string { - $htmlMessage = '

This is your weekly summary of the malicious files found in your Nextcloud instance:

'; - $htmlMessage .= '

Found ' . count($maliciousFiles) . ' malicious files:

'; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - foreach ($maliciousFiles as $file) { - if ($file instanceof File) { - try { - $size = $file->getSize(); - } catch (InvalidPathException|NotFoundException) { - $size = 0; - } - $uploadTime = $file->getCreationTime() ?: $file->getUploadTime(); - if ($uploadTime === 0) { - $uploadTime = 'Unknown'; - } - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - $htmlMessage .= ''; - if ($size !== 0) { - $htmlMessage .= ''; - } else { - $htmlMessage .= ''; - } - $htmlMessage .= ''; - } - } - $htmlMessage .= '
Name Path Owner Upload time Mimetype Size
' . $file->getName() . '' . $file->getInternalPath() . '' . $file->getOwner()->getDisplayName() . '' . $uploadTime . '' . $file->getMimeType() . '' . NumberHumanizer::binarySuffix($size, 'de') . 'Unknown
'; - return $htmlMessage; - } - - /** - * @param array $maliciousFiles - * @return string - */ - private function createSummaryPlain(array $maliciousFiles): string { - $plainMessage = "This is your weekly summary of the malicious files found in your Nextcloud instance:\n"; - $plainMessage .= 'Found ' . count($maliciousFiles) . " malicious files:\n"; - foreach ($maliciousFiles as $file) { - if ($file instanceof File) { - $plainMessage .= "\n"; - try { - $size = $file->getSize(); - } catch (InvalidPathException|NotFoundException) { - $size = 0; - } - $uploadTime = $file->getCreationTime() ?: $file->getUploadTime(); - if ($uploadTime === 0) { - $uploadTime = 'Unknown'; - } - $plainMessage .= 'Name: ' . $file->getName() . "\n"; - $plainMessage .= 'Path: ' . $file->getPath() . "\n"; - $plainMessage .= 'Owner: ' . $file->getOwner()->getDisplayName() . "\n"; - $plainMessage .= 'Time: ' . $uploadTime . "\n"; - $plainMessage .= 'Mimetype: ' . $file->getMimeType() . "\n"; - if ($size !== 0) { - $plainMessage .= 'Size: ' . NumberHumanizer::binarySuffix($size, 'de') . "\n"; - } else { - $plainMessage .= "Size: Unknown\n"; - } - } - } - return $plainMessage; - } } diff --git a/lib/Settings/VaasAdmin.php b/lib/Settings/VaasAdmin.php index 4e3e050f..f3ea696a 100644 --- a/lib/Settings/VaasAdmin.php +++ b/lib/Settings/VaasAdmin.php @@ -45,8 +45,6 @@ public function getForm(): TemplateResponse { 'quarantineFolder' => $this->config->getValueString(Application::APP_ID, 'quarantineFolder', 'Quarantine'), 'autoScanFiles' => $this->config->getValueBool(Application::APP_ID, 'autoScanFiles'), - 'scanOnlyNewFiles' - => $this->config->getValueBool(Application::APP_ID, 'scanOnlyNewFiles', true), 'prefixMalicious' => $this->config->getValueBool(Application::APP_ID, 'prefixMalicious', true), 'disableUnscannedTag' => $this->config->getValueBool(Application::APP_ID, 'disableUnscannedTag'), @@ -55,7 +53,6 @@ public function getForm(): TemplateResponse { 'notifyMail' => $this->config->getValueString(Application::APP_ID, 'notifyMails'), 'sendMailOnVirusUpload' => $this->config->getValueBool(Application::APP_ID, 'sendMailOnVirusUpload'), - 'notifyAdminEnabled' => $this->config->getValueBool(Application::APP_ID, 'notifyAdminEnabled'), 'maxScanSizeInMB' => $this->config->getValueInt(Application::APP_ID, 'maxScanSizeInMB', 256), 'timeout' => $this->config->getValueInt(Application::APP_ID, 'timeout', 300), diff --git a/src/admin-settings.js b/src/admin-settings.js index 305ea4eb..8804b740 100644 --- a/src/admin-settings.js +++ b/src/admin-settings.js @@ -46,8 +46,6 @@ document.addEventListener('DOMContentLoaded', async () => { const disableUnscannedTag = document.querySelector('#disable_tag_unscanned'); const scanCounter = document.querySelector('#scan_counter'); const sendMailOnVirusUpload = document.querySelector('#send_mail_on_virus_upload'); - const sendMailSummaryOfMaliciousFiles = - document.querySelector('#send_summary_mail_for_malicious_files'); hideUnneccessaryFields(authMethod.value); @@ -171,13 +169,6 @@ document.addEventListener('DOMContentLoaded', async () => { ); }); - sendMailSummaryOfMaliciousFiles.addEventListener('click', async () => { - await postData( - OC.generateUrl('apps/gdatavaas/setSendMailSummaryOfMaliciousFiles'), - {sendMailSummaryOfMaliciousFiles: sendMailSummaryOfMaliciousFiles.checked} - ); - }); - // Activate or deactivate automatic file scanning const toggleAutoScan = async (enable) => { autoScanFiles.checked = enable; @@ -199,8 +190,6 @@ document.addEventListener('DOMContentLoaded', async () => { prefixMalicious.checked = (await getData(OC.generateUrl('apps/gdatavaas/getPrefixMalicious'))).status; disableUnscannedTag.checked = (await getData(OC.generateUrl('apps/gdatavaas/getDisableUnscannedTag'))).status; sendMailOnVirusUpload.checked = (await getData(OC.generateUrl('apps/gdatavaas/getSendMailOnVirusUpload'))).status; - sendMailSummaryOfMaliciousFiles.checked = - (await getData(OC.generateUrl('apps/gdatavaas/getSendMailSummaryOfMaliciousFiles'))).status; let filesCounter = await getData(OC.generateUrl('apps/gdatavaas/getCounters')); if (filesCounter['status'] === 'success') { diff --git a/templates/admin.php b/templates/admin.php index 3825c674..7ac9612d 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -142,13 +142,6 @@
- - - - - -
-