1 | <?php |
||
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 = []; |
||
24 | |||
25 | /** |
||
26 | * Process handle |
||
27 | * @var resource |
||
28 | */ |
||
29 | private $process; |
||
30 | |||
31 | 4 | public function __construct($config){ |
|
32 | 4 | $this->appConfig = $config; |
|
33 | // get the path to the executable |
||
34 | 4 | $this->avPath = escapeshellcmd($this->appConfig->getAvPath()); |
|
35 | |||
36 | // check that the executable is available |
||
37 | 4 | if (!file_exists($this->avPath)) { |
|
38 | 2 | throw new \RuntimeException('The antivirus executable could not be found at ' . $this->avPath); |
|
39 | } |
||
40 | 2 | } |
|
41 | |||
42 | 2 | public function initScanner(){ |
|
43 | 2 | parent::initScanner(); |
|
44 | |||
45 | // using 2>&1 to grab the full command-line output. |
||
46 | 2 | $cmd = $this->avPath . " " . $this->appConfig->getCmdline() ." - 2>&1"; |
|
47 | $descriptorSpec = array( |
||
48 | 2 | 0 => ["pipe","r"], // STDIN |
|
49 | 1 => ["pipe","w"] // STDOUT |
||
50 | ); |
||
51 | |||
52 | 2 | $this->process = proc_open($cmd, $descriptorSpec, $this->pipes); |
|
53 | 2 | if (!is_resource($this->process)) { |
|
54 | throw new \RuntimeException('Error starting process'); |
||
55 | } |
||
56 | 2 | $this->writeHandle = $this->pipes[0]; |
|
57 | 2 | } |
|
58 | |||
59 | 2 | protected function shutdownScanner(){ |
|
71 | } |
||
72 |
If you suppress an error, we recommend checking for the error condition explicitly: