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