1 | <?php |
||
14 | class Local extends ScannerBase{ |
||
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(){ |
|
73 | } |
||
74 |
If you suppress an error, we recommend checking for the error condition explicitly: