1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2017 Matthias Held <[email protected]> |
5
|
|
|
* @author Matthias Held <[email protected]> |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\RansomwareDetection\Notification; |
23
|
|
|
|
24
|
|
|
use OCA\RansomwareDetection\AppInfo\Application; |
25
|
|
|
use OCP\IURLGenerator; |
|
|
|
|
26
|
|
|
use OCP\IUserManager; |
|
|
|
|
27
|
|
|
use OCP\L10N\IFactory; |
|
|
|
|
28
|
|
|
use OCP\Notification\IManager; |
|
|
|
|
29
|
|
|
use OCP\Notification\INotification; |
|
|
|
|
30
|
|
|
use OCP\Notification\INotifier; |
|
|
|
|
31
|
|
|
use OCP\IConfig; |
|
|
|
|
32
|
|
|
|
33
|
|
|
class Notifier implements INotifier |
34
|
|
|
{ |
35
|
|
|
/** @var IConfig */ |
36
|
|
|
private $config; |
37
|
|
|
|
38
|
|
|
/** @var IFactory */ |
39
|
|
|
protected $l10nFactory; |
40
|
|
|
|
41
|
|
|
/** @var IUserManager */ |
42
|
|
|
protected $userManager; |
43
|
|
|
|
44
|
|
|
/** @var IManager */ |
45
|
|
|
protected $notificationManager; |
46
|
|
|
|
47
|
|
|
/** @var IURLGenerator */ |
48
|
|
|
protected $urlGenerator; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param IConfig $config |
52
|
|
|
* @param IFactory $l10nFactory |
53
|
|
|
* @param IUserManager $userManager |
54
|
|
|
* @param IManager $notificationManager |
55
|
|
|
* @param IURLGenerator $urlGenerator |
56
|
|
|
*/ |
57
|
|
|
public function __construct( |
58
|
|
|
IConfig $config, |
59
|
|
|
IFactory $l10nFactory, |
60
|
|
|
IUserManager $userManager, |
61
|
|
|
IManager $notificationManager, |
62
|
|
|
IURLGenerator $urlGenerator |
63
|
|
|
) { |
64
|
|
|
$this->config = $config; |
65
|
|
|
$this->l10nFactory = $l10nFactory; |
66
|
|
|
$this->userManager = $userManager; |
67
|
|
|
$this->notificationManager = $notificationManager; |
68
|
|
|
$this->urlGenerator = $urlGenerator; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param INotification $notification |
73
|
|
|
* @param string $languageCode |
74
|
|
|
* |
75
|
|
|
* @return INotification |
76
|
|
|
*/ |
77
|
|
|
public function prepare(INotification $notification, string $languageCode): INotification |
78
|
|
|
{ |
79
|
|
|
if ($notification->getApp() !== Application::APP_ID) { |
80
|
|
|
// Not my app => throw |
81
|
|
|
throw new \InvalidArgumentException('Unknown app'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
//Read the language from the notification |
85
|
|
|
$l = $this->l10nFactory->get(Application::APP_ID, $languageCode); |
86
|
|
|
|
87
|
|
|
switch ($notification->getSubject()) { |
88
|
|
|
case 'ransomware_attack_detected': |
89
|
|
|
$message = 'Detected a sequence of suspicious file operations.'; |
90
|
|
|
$notification->setParsedSubject($l->t('Detected suspicious file operations.', $notification->getSubjectParameters())); |
91
|
|
|
$notification->setParsedMessage($l->t($message, $notification->getMessageParameters())); |
92
|
|
|
$notification->setIcon($this->urlGenerator->imagePath('ransomware_detection', 'app-dark.svg')); |
93
|
|
|
|
94
|
|
|
return $notification; |
95
|
|
|
default: |
96
|
|
|
throw new \InvalidArgumentException('Unknown subject'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Identifier of the notifier, only use [a-z0-9_] |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
* @since 17.0.0 |
105
|
|
|
*/ |
106
|
|
|
public function getID(): string { |
107
|
|
|
return Application::APP_ID; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Human readable name describing the notifier |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
* @since 17.0.0 |
115
|
|
|
*/ |
116
|
|
|
public function getName(): string { |
117
|
|
|
return $this->l10nFactory->get(Application::APP_ID)->t('Ransomware recovery'); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths