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