1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2020 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\Events; |
23
|
|
|
|
24
|
|
|
use OCA\RansomwareDetection\Monitor; |
25
|
|
|
use OCA\RansomwareDetection\AppInfo\Application; |
26
|
|
|
use OCP\ILogger; |
|
|
|
|
27
|
|
|
|
28
|
|
|
class FilesEvents { |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
private $userId; |
32
|
|
|
|
33
|
|
|
/** @var ILogger */ |
34
|
|
|
private $logger; |
35
|
|
|
|
36
|
|
|
/** @var Monitor */ |
37
|
|
|
private $monitor; |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ILogger $logger |
42
|
|
|
* @param Monitor $monitor |
43
|
|
|
* @param string $userId |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
ILogger $logger, |
47
|
|
|
Monitor $monitor, |
48
|
|
|
$userId |
49
|
|
|
|
50
|
|
|
) { |
51
|
|
|
$this->logger = $logger; |
52
|
|
|
$this->monitor = $monitor; |
53
|
|
|
$this->userId = $userId; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $params |
58
|
|
|
*/ |
59
|
|
|
public function onFileUpdate(array $params) { |
60
|
|
|
$this->logger->debug("Updating ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
61
|
|
|
$this->analyze([$params['path']], Monitor::WRITE); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $params |
67
|
|
|
*/ |
68
|
|
|
public function onFileRename(array $params) { |
69
|
|
|
$this->logger->debug("Renaming ".$params['oldpath']." to ".$params['newpath'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
70
|
|
|
$this->analyze([$params['oldpath'], $params['newpath']], Monitor::RENAME); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param array $params |
75
|
|
|
*/ |
76
|
|
|
public function onFileCreate(array $params) { |
77
|
|
|
$this->logger->debug("Creating ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
78
|
|
|
$this->analyze([$params['path']], Monitor::CREATE); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param array $params |
83
|
|
|
*/ |
84
|
|
|
public function onFileWrite(array $params) { |
85
|
|
|
$this->logger->debug("Writing ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
86
|
|
|
$this->analyze([$params['path']], Monitor::WRITE); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param array $params |
91
|
|
|
*/ |
92
|
|
|
public function onFileDelete(array $params) { |
93
|
|
|
$this->logger->debug("Deleting ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
94
|
|
|
$this->analyze([$params['path']], Monitor::DELETE); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param array $params |
99
|
|
|
*/ |
100
|
|
|
public function onFileCopy(array $params) { |
101
|
|
|
$this->logger->debug("Copying ".$params['oldpath']." to ".$params['newpath'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
102
|
|
|
$this->analyze([$params['oldpath'], $params['newpath']], Monitor::RENAME); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param array $params |
107
|
|
|
*/ |
108
|
|
|
public function onFileTouch(array $params) { |
109
|
|
|
$this->logger->debug("Touching ".$params['path'].": Params: ".print_r($params, true), ['app' => Application::APP_ID]); |
110
|
|
|
$this->analyze([$params['path']], Monitor::WRITE); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Makes it easier to test. |
115
|
|
|
* |
116
|
|
|
* @param IStorage $storage |
|
|
|
|
117
|
|
|
* @param string $path |
118
|
|
|
* @param int $mode |
119
|
|
|
*/ |
120
|
|
|
protected function analyze($path, $mode) |
121
|
|
|
{ |
122
|
|
|
return $this->monitor->analyze($path, $mode); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
} |
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