|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ownCloud - Files_antivirus |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Viktar Dubiniuk <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @copyright Viktar Dubiniuk 2015-2018 |
|
11
|
|
|
* @license AGPL-3.0 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace OCA\Files_Antivirus\Db; |
|
15
|
|
|
|
|
16
|
|
|
use OCA\Files_Antivirus\Status; |
|
17
|
|
|
use OCP\IDb; |
|
18
|
|
|
use OCP\AppFramework\Db\Mapper; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class RuleMapper |
|
22
|
|
|
* |
|
23
|
|
|
* @package OCA\Files_Antivirus\Db |
|
24
|
|
|
*/ |
|
25
|
|
|
class RuleMapper extends Mapper { |
|
26
|
|
|
/** |
|
27
|
|
|
* RuleMapper constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param IDb $db |
|
30
|
|
|
*/ |
|
31
|
12 |
|
public function __construct(IDb $db) { |
|
32
|
12 |
|
parent::__construct( |
|
33
|
12 |
|
$db, |
|
34
|
12 |
|
'files_avir_status', |
|
35
|
12 |
|
'\OCA\Files_Antivirus\Db\Rule' |
|
36
|
|
|
); |
|
37
|
12 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Empty the table |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
5 |
|
public function deleteAll() { |
|
45
|
5 |
|
$sql = 'DELETE FROM `*PREFIX*files_avir_status`'; |
|
46
|
5 |
|
return $this->execute($sql); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Find rule by id |
|
51
|
|
|
* |
|
52
|
|
|
* @param int $id |
|
53
|
|
|
* |
|
54
|
|
|
* @return Rule |
|
55
|
|
|
*/ |
|
56
|
|
|
public function find($id) { |
|
57
|
|
|
$sql = 'SELECT * FROM `*PREFIX*files_avir_status` WHERE `id` = ?'; |
|
58
|
|
|
return $this->findEntity($sql, [$id]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get all rules |
|
63
|
|
|
*/ |
|
64
|
|
|
public function findAll() { |
|
65
|
|
|
$sql = 'SELECT * FROM `*PREFIX*files_avir_status`'; |
|
66
|
|
|
return $this->findEntities($sql); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get collection of rules by given exit code |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $result |
|
73
|
|
|
* |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
4 |
|
public function findByResult($result) { |
|
77
|
4 |
|
$sql = 'SELECT * FROM `*PREFIX*files_avir_status` WHERE `status_type`=? and `result`=?'; |
|
78
|
4 |
|
return $this->findEntities($sql, [Rule::RULE_TYPE_CODE, $result]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get collection of rules of type Match |
|
83
|
|
|
* |
|
84
|
|
|
* @param int $status |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
5 |
|
public function findAllMatchedByStatus($status) { |
|
89
|
5 |
|
$sql = 'SELECT * FROM `*PREFIX*files_avir_status` WHERE `status_type`=? and `status`=?'; |
|
90
|
5 |
|
return $this->findEntities($sql, [Rule::RULE_TYPE_MATCH, $status]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Fill the table with rules used with clamav |
|
95
|
|
|
*/ |
|
96
|
5 |
|
public function populate() { |
|
97
|
|
|
$descriptions = [ |
|
98
|
|
|
[ |
|
99
|
5 |
|
'groupId' => 0, |
|
100
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
101
|
5 |
|
'result' => 0, |
|
102
|
5 |
|
'match' => '', |
|
103
|
5 |
|
'description' => "", |
|
104
|
|
|
'status' => Status::SCANRESULT_CLEAN |
|
105
|
|
|
], |
|
106
|
|
|
|
|
107
|
|
|
[ |
|
108
|
5 |
|
'groupId' => 0, |
|
109
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
110
|
5 |
|
'result' => 1, |
|
111
|
5 |
|
'match' => '', |
|
112
|
5 |
|
'description' => "", |
|
113
|
|
|
'status' => Status::SCANRESULT_INFECTED |
|
114
|
|
|
], |
|
115
|
|
|
|
|
116
|
|
|
[ |
|
117
|
5 |
|
'groupId' => 0, |
|
118
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
119
|
5 |
|
'result' => 40, |
|
120
|
5 |
|
'match' => '', |
|
121
|
5 |
|
'description' => "Unknown option passed.", |
|
122
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
123
|
|
|
], |
|
124
|
|
|
|
|
125
|
|
|
[ |
|
126
|
5 |
|
'groupId' => 0, |
|
127
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
128
|
5 |
|
'result' => 50, |
|
129
|
5 |
|
'match' => '', |
|
130
|
5 |
|
'description' => "Database initialization error.", |
|
131
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
132
|
|
|
], |
|
133
|
|
|
|
|
134
|
|
|
[ |
|
135
|
5 |
|
'groupId' => 0, |
|
136
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
137
|
5 |
|
'result' => 52, |
|
138
|
5 |
|
'match' => '', |
|
139
|
5 |
|
'description' => "Not supported file type.", |
|
140
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
141
|
|
|
], |
|
142
|
|
|
|
|
143
|
|
|
[ |
|
144
|
5 |
|
'groupId' => 0, |
|
145
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
146
|
5 |
|
'result' => 53, |
|
147
|
5 |
|
'match' => '', |
|
148
|
5 |
|
'description' => "Can't open directory.", |
|
149
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
150
|
|
|
], |
|
151
|
|
|
|
|
152
|
|
|
[ |
|
153
|
5 |
|
'groupId' => 0, |
|
154
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
155
|
5 |
|
'result' => 54, |
|
156
|
5 |
|
'match' => '', |
|
157
|
5 |
|
'description' => "Can't open file. (ofm)", |
|
158
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
159
|
|
|
], |
|
160
|
|
|
|
|
161
|
|
|
[ |
|
162
|
5 |
|
'groupId' => 0, |
|
163
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
164
|
5 |
|
'result' => 55, |
|
165
|
5 |
|
'match' => '', |
|
166
|
5 |
|
'description' => "Error reading file. (ofm)", |
|
167
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
168
|
|
|
], |
|
169
|
|
|
|
|
170
|
|
|
[ |
|
171
|
5 |
|
'groupId' => 0, |
|
172
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
173
|
5 |
|
'result' => 56, |
|
174
|
5 |
|
'match' => '', |
|
175
|
5 |
|
'description' => "Can't stat input file / directory.", |
|
176
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
177
|
|
|
], |
|
178
|
|
|
|
|
179
|
|
|
[ |
|
180
|
5 |
|
'groupId' => 0, |
|
181
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
182
|
5 |
|
'result' => 57, |
|
183
|
5 |
|
'match' => '', |
|
184
|
5 |
|
'description' => "Can't get absolute path name of current working directory.", |
|
185
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
186
|
|
|
], |
|
187
|
|
|
|
|
188
|
|
|
[ |
|
189
|
5 |
|
'groupId' => 0, |
|
190
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
191
|
5 |
|
'result' => 58, |
|
192
|
5 |
|
'match' => '', |
|
193
|
5 |
|
'description' => "I/O error, please check your file system.", |
|
194
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
195
|
|
|
], |
|
196
|
|
|
|
|
197
|
|
|
[ |
|
198
|
5 |
|
'groupId' => 0, |
|
199
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
200
|
5 |
|
'result' => 62, |
|
201
|
5 |
|
'match' => '', |
|
202
|
5 |
|
'description' => "Can't initialize logger.", |
|
203
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
204
|
|
|
], |
|
205
|
|
|
|
|
206
|
|
|
[ |
|
207
|
5 |
|
'groupId' => 0, |
|
208
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
209
|
5 |
|
'result' => 63, |
|
210
|
5 |
|
'match' => '', |
|
211
|
5 |
|
'description' => "Can't create temporary files/directories (check permissions).", |
|
212
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
213
|
|
|
], |
|
214
|
|
|
|
|
215
|
|
|
[ |
|
216
|
5 |
|
'groupId' => 0, |
|
217
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
218
|
5 |
|
'result' => 64, |
|
219
|
5 |
|
'match' => '', |
|
220
|
5 |
|
'description' => "Can't write to temporary directory (please specify another one).", |
|
221
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
222
|
|
|
], |
|
223
|
|
|
|
|
224
|
|
|
[ |
|
225
|
5 |
|
'groupId' => 0, |
|
226
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
227
|
5 |
|
'result' => 70, |
|
228
|
5 |
|
'match' => '', |
|
229
|
5 |
|
'description' => "Can't allocate memory (calloc).", |
|
230
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
231
|
|
|
], |
|
232
|
|
|
|
|
233
|
|
|
[ |
|
234
|
5 |
|
'groupId' => 0, |
|
235
|
5 |
|
'statusType' => Rule::RULE_TYPE_CODE, |
|
236
|
5 |
|
'result' => 71, |
|
237
|
5 |
|
'match' => '', |
|
238
|
5 |
|
'description' => "Can't allocate memory (malloc).", |
|
239
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
240
|
|
|
], |
|
241
|
|
|
|
|
242
|
|
|
[ |
|
243
|
5 |
|
'groupId' => 0, |
|
244
|
5 |
|
'statusType' => Rule::RULE_TYPE_MATCH, |
|
245
|
5 |
|
'result' => 0, |
|
246
|
5 |
|
'match' => '/.*: OK$/', |
|
247
|
5 |
|
'description' => '', |
|
248
|
|
|
'status' => Status::SCANRESULT_CLEAN |
|
249
|
|
|
], |
|
250
|
|
|
|
|
251
|
|
|
[ |
|
252
|
5 |
|
'groupId' => 0, |
|
253
|
5 |
|
'statusType' => Rule::RULE_TYPE_MATCH, |
|
254
|
5 |
|
'result' => 0, |
|
255
|
5 |
|
'match' => '/.*: (.*) FOUND$/', |
|
256
|
5 |
|
'description' => '', |
|
257
|
|
|
'status' => Status::SCANRESULT_INFECTED |
|
258
|
|
|
], |
|
259
|
|
|
|
|
260
|
|
|
[ |
|
261
|
5 |
|
'groupId' => 0, |
|
262
|
5 |
|
'statusType' => Rule::RULE_TYPE_MATCH, |
|
263
|
5 |
|
'result' => 0, |
|
264
|
5 |
|
'match' => '/.*: (.*) ERROR$/', |
|
265
|
5 |
|
'description' => '', |
|
266
|
|
|
'status' => Status::SCANRESULT_UNCHECKED |
|
267
|
|
|
], |
|
268
|
|
|
]; |
|
269
|
|
|
|
|
270
|
5 |
|
foreach ($descriptions as $description) { |
|
271
|
5 |
|
$rule = Rule::fromParams($description); |
|
272
|
5 |
|
$this->insert($rule); |
|
273
|
|
|
} |
|
274
|
5 |
|
} |
|
275
|
|
|
} |
|
276
|
|
|
|