1 | <?php |
||
12 | class External extends \OCA\Files_Antivirus\Scanner { |
||
13 | |||
14 | // Daemon/socket mode |
||
15 | private $useSocket; |
||
16 | |||
17 | /** |
||
18 | * Handle to write data into |
||
19 | * @var resource |
||
20 | */ |
||
21 | private $writeHandle; |
||
22 | |||
23 | public function __construct($config){ |
||
27 | |||
28 | protected function initScanner(){ |
||
29 | parent::initScanner(); |
||
30 | |||
31 | if ($this->useSocket){ |
||
32 | $avSocket = $this->appConfig->getAvSocket(); |
||
33 | $this->writeHandle = stream_socket_client('unix://' . $avSocket, $errno, $errstr, 5); |
||
34 | if (!$this->writeHandle) { |
||
35 | throw new \RuntimeException('Cannot connect to "' . $avSocket . '": ' . $errstr . ' (code ' . $errno . ')'); |
||
36 | } |
||
37 | } else { |
||
38 | $avHost = $this->appConfig->getAvHost(); |
||
39 | $avPort = $this->appConfig->getAvPort(); |
||
40 | $this->writeHandle = ($avHost && $avPort) ? @fsockopen($avHost, $avPort) : false; |
||
41 | if (!$this->writeHandle) { |
||
42 | throw new \RuntimeException('The clamav module is not configured for daemon mode.'); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | // request scan from the daemon |
||
47 | fwrite($this->writeHandle, "nINSTREAM\n"); |
||
48 | } |
||
49 | |||
50 | protected function shutdownScanner(){ |
||
51 | fwrite($this->writeHandle, pack('N', 0)); |
||
52 | $response = fgets($this->writeHandle); |
||
53 | \OCP\Util::writeLog('files_antivirus', 'Response :: '.$response, \OCP\Util::DEBUG); |
||
54 | fclose($this->writeHandle); |
||
55 | |||
56 | $this->status->parseResponse($response); |
||
57 | } |
||
58 | |||
59 | protected function getWriteHandle(){ |
||
62 | |||
63 | protected function prepareChunk($data){ |
||
67 | } |
||
68 |