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