1 | <?php |
||
14 | class External extends \OCA\Files_Antivirus\Scanner { |
||
15 | |||
16 | // Daemon/socket mode |
||
17 | private $useSocket; |
||
18 | |||
19 | 2 | public function __construct(AppConfig $config){ |
|
23 | |||
24 | 2 | public function initScanner(){ |
|
25 | 2 | parent::initScanner(); |
|
26 | |||
27 | 2 | if ($this->useSocket){ |
|
28 | $avSocket = $this->appConfig->getAvSocket(); |
||
29 | $this->writeHandle = stream_socket_client('unix://' . $avSocket, $errno, $errstr, 5); |
||
30 | if (!$this->getWriteHandle()) { |
||
31 | throw new \RuntimeException('Cannot connect to "' . $avSocket . '": ' . $errstr . ' (code ' . $errno . ')'); |
||
32 | } |
||
33 | } else { |
||
34 | 2 | $avHost = $this->appConfig->getAvHost(); |
|
35 | 2 | $avPort = $this->appConfig->getAvPort(); |
|
36 | 2 | if (!($avHost && $avPort)) { |
|
37 | throw new \RuntimeException('The clamav port and host are not configured.'); |
||
38 | } |
||
39 | 2 | $this->writeHandle = ($avHost && $avPort) ? @fsockopen($avHost, $avPort) : false; |
|
40 | 2 | if (!$this->getWriteHandle()) { |
|
41 | throw new \RuntimeException('The clamav module is not configured for daemon mode.'); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | // request scan from the daemon |
||
46 | 2 | @fwrite($this->getWriteHandle(), "nINSTREAM\n"); |
|
|
|||
47 | 2 | } |
|
48 | |||
49 | 2 | protected function shutdownScanner(){ |
|
50 | 2 | @fwrite($this->getWriteHandle(), pack('N', 0)); |
|
51 | 2 | $response = fgets($this->getWriteHandle()); |
|
52 | 2 | \OC::$server->getLogger()->debug( |
|
53 | 2 | 'Response :: ' . $response, |
|
54 | 2 | ['app' => 'files_antivirus'] |
|
55 | ); |
||
56 | 2 | @fclose($this->getWriteHandle()); |
|
57 | |||
58 | 2 | $this->status->parseResponse($response); |
|
59 | 2 | } |
|
60 | |||
61 | 2 | protected function prepareChunk($data){ |
|
65 | } |
||
66 |
If you suppress an error, we recommend checking for the error condition explicitly: