1 | <?php |
||
22 | class Item { |
||
23 | /** |
||
24 | * file handle, user to read from the file |
||
25 | * @var resource |
||
26 | */ |
||
27 | protected $fileHandle; |
||
28 | |||
29 | /** @var AppConfig */ |
||
30 | private $config; |
||
31 | |||
32 | /** @var ActivityManager */ |
||
33 | private $activityManager; |
||
34 | |||
35 | /** @var ItemMapper */ |
||
36 | private $itemMapper; |
||
37 | |||
38 | /** @var ILogger */ |
||
39 | private $logger; |
||
40 | |||
41 | /** @var IRootFolder */ |
||
42 | private $rootFolder; |
||
43 | |||
44 | /** @var File */ |
||
45 | private $file; |
||
46 | private $isCron; |
||
47 | |||
48 | /** |
||
49 | * Item constructor. |
||
50 | * |
||
51 | * @param AppConfig $appConfig |
||
52 | * @param ActivityManager $activityManager |
||
53 | * @param ItemMapper $itemMapper |
||
54 | * @param ILogger $logger |
||
55 | * @param IRootFolder $rootFolder |
||
56 | * @param File $file |
||
57 | * @param bool $isCron |
||
58 | */ |
||
59 | public function __construct(AppConfig $appConfig, |
||
74 | |||
75 | /** |
||
76 | * Reads a file portion by portion until the very end |
||
77 | * @return string|boolean |
||
78 | */ |
||
79 | public function fread() { |
||
93 | |||
94 | /** |
||
95 | * Action to take if this item is infected |
||
96 | */ |
||
97 | public function processInfected(Status $status) { |
||
98 | $infectedAction = $this->config->getAvInfectedAction(); |
||
99 | |||
100 | $shouldDelete = $infectedAction === 'delete'; |
||
101 | |||
102 | $message = $shouldDelete ? Provider::MESSAGE_FILE_DELETED : ''; |
||
103 | |||
104 | $userFolder = $this->rootFolder->getUserFolder($this->file->getOwner()->getUID()); |
||
105 | $path = $userFolder->getRelativePath($this->file->getPath()); |
||
106 | |||
107 | $activity = $this->activityManager->generateEvent(); |
||
108 | $activity->setApp(Application::APP_NAME) |
||
109 | ->setSubject(Provider::SUBJECT_VIRUS_DETECTED_SCAN, [$status->getDetails()]) |
||
110 | ->setMessage($message) |
||
111 | ->setObject('file', $this->file->getId(), $path) |
||
112 | ->setAffectedUser($this->file->getOwner()->getUID()) |
||
113 | ->setType(Provider::TYPE_VIRUS_DETECTED); |
||
114 | $this->activityManager->publish($activity); |
||
115 | |||
116 | if ($shouldDelete) { |
||
117 | if ($this->isCron) { |
||
118 | $msg = 'Infected file deleted (during background scan)'; |
||
119 | } else { |
||
120 | $msg = 'Infected file deleted.'; |
||
121 | } |
||
122 | $this->logError($msg . ' ' . $status->getDetails()); |
||
123 | $this->deleteFile(); |
||
124 | } else { |
||
125 | if ($this->isCron) { |
||
126 | $msg = 'Infected file found (during background scan)'; |
||
127 | } else { |
||
128 | $msg = 'Infected file found.'; |
||
129 | } |
||
130 | $this->logError($msg . ' ' . $status->getDetails()); |
||
131 | $this->updateCheckTime(); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Action to take if this item status is unclear |
||
137 | * @param Status $status |
||
138 | */ |
||
139 | public function processUnchecked(Status $status) { |
||
140 | //TODO: Show warning to the user: The file can not be checked |
||
141 | $this->logError('Not Checked. ' . $status->getDetails()); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Action to take if this item status is not infected |
||
146 | */ |
||
147 | public function processClean() { |
||
150 | |||
151 | /** |
||
152 | * Update the check-time of this item to current time |
||
153 | */ |
||
154 | private function updateCheckTime() { |
||
155 | try { |
||
156 | try { |
||
157 | $item = $this->itemMapper->findByFileId($this->file->getId()); |
||
158 | $this->itemMapper->delete($item); |
||
159 | } catch (DoesNotExistException $e) { |
||
|
|||
160 | //Just ignore |
||
161 | } |
||
162 | |||
163 | $item = new \OCA\Files_Antivirus\Db\Item(); |
||
164 | $item->setFileid($this->file->getId()); |
||
165 | $item->setCheckTime(time()); |
||
166 | $this->itemMapper->insert($item); |
||
167 | } catch(\Exception $e) { |
||
168 | $this->logger->error(__METHOD__.', exception: '.$e->getMessage(), ['app' => 'files_antivirus']); |
||
169 | } |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * Check if the end of file is reached |
||
174 | * @return boolean |
||
175 | */ |
||
176 | private function feof() { |
||
177 | $isDone = feof($this->fileHandle); |
||
178 | if ($isDone) { |
||
179 | $this->logDebug('Scan is done'); |
||
180 | fclose($this->fileHandle); |
||
181 | $this->fileHandle = null; |
||
182 | } |
||
183 | return $isDone; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Opens a file for reading |
||
188 | * @throws \RuntimeException |
||
189 | */ |
||
190 | private function getFileHandle() { |
||
191 | $fileHandle = $this->file->fopen('r'); |
||
192 | if ($fileHandle === false) { |
||
193 | $this->logError('Can not open for reading.'); |
||
194 | throw new \RuntimeException(); |
||
195 | } |
||
196 | |||
197 | $this->logDebug('Scan started'); |
||
198 | $this->fileHandle = $fileHandle; |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * Delete infected file |
||
203 | */ |
||
204 | private function deleteFile() { |
||
218 | |||
219 | private function generateExtraInfo() { |
||
220 | $owner = $this->file->getOwner(); |
||
221 | |||
222 | if ($owner === null) { |
||
223 | $ownerInfo = ' Account: NO OWNER FOUND'; |
||
234 | |||
235 | /** |
||
236 | * @param string $message |
||
237 | */ |
||
238 | public function logDebug($message) { |
||
241 | |||
242 | /** |
||
243 | * @param string $message |
||
244 | */ |
||
245 | public function logError($message) { |
||
248 | } |
||
249 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.