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