1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2014 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
|
|
|
|
10
|
|
|
namespace OCA\Files_Antivirus\Scanner; |
11
|
|
|
|
12
|
|
|
use OCA\Files_Antivirus\AppConfig; |
13
|
|
|
|
14
|
|
|
class Local extends \OCA\Files_Antivirus\Scanner{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $avPath; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* STDIN and STDOUT descriptors |
23
|
|
|
* @var array of resources |
24
|
|
|
*/ |
25
|
|
|
private $pipes = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Process handle |
29
|
|
|
* @var resource |
30
|
|
|
*/ |
31
|
|
|
private $process; |
32
|
|
|
|
33
|
2 |
|
public function __construct(AppConfig $config){ |
34
|
2 |
|
$this->appConfig = $config; |
35
|
|
|
// get the path to the executable |
36
|
2 |
|
$this->avPath = escapeshellcmd($this->appConfig->getAvPath()); |
37
|
|
|
|
38
|
|
|
// check that the executable is available |
39
|
2 |
|
if (!file_exists($this->avPath)) { |
40
|
|
|
throw new \RuntimeException('The antivirus executable could not be found at ' . $this->avPath); |
41
|
|
|
} |
42
|
2 |
|
} |
43
|
|
|
|
44
|
2 |
|
public function initScanner(){ |
45
|
2 |
|
parent::initScanner(); |
46
|
|
|
|
47
|
|
|
// using 2>&1 to grab the full command-line output. |
48
|
2 |
|
$cmd = $this->avPath . " " . $this->appConfig->getCmdline() ." - 2>&1"; |
49
|
|
|
$descriptorSpec = array( |
50
|
2 |
|
0 => ["pipe","r"], // STDIN |
51
|
|
|
1 => ["pipe","w"] // STDOUT |
52
|
|
|
); |
53
|
|
|
|
54
|
2 |
|
$this->process = proc_open($cmd, $descriptorSpec, $this->pipes); |
55
|
2 |
|
if (!is_resource($this->process)) { |
56
|
|
|
throw new \RuntimeException('Error starting process'); |
57
|
|
|
} |
58
|
2 |
|
$this->writeHandle = $this->pipes[0]; |
59
|
2 |
|
} |
60
|
|
|
|
61
|
2 |
|
protected function shutdownScanner(){ |
62
|
2 |
|
@fclose($this->pipes[0]); |
|
|
|
|
63
|
2 |
|
$output = stream_get_contents($this->pipes[1]); |
64
|
2 |
|
@fclose($this->pipes[1]); |
|
|
|
|
65
|
|
|
|
66
|
2 |
|
$result = proc_close($this->process); |
67
|
2 |
|
\OC::$server->getLogger()->debug( |
68
|
2 |
|
'Exit code :: ' . $result . ' Response :: ' . $output, |
69
|
2 |
|
['app' => 'files_antivirus'] |
70
|
|
|
); |
71
|
2 |
|
$this->status->parseResponse($output, $result); |
72
|
2 |
|
} |
73
|
|
|
} |
74
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: