1 | <?php |
||
14 | class ScannerFactory{ |
||
15 | // We split it in two parts in order to prevent reports from av scanners |
||
16 | const EICAR_PART_1 = 'X5O!P%@AP[4\PZX54(P^)7CC)7}$'; |
||
17 | const EICAR_PART_2 = 'EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'; |
||
18 | |||
19 | /** |
||
20 | * @var \OCA\Files_Antivirus\AppConfig |
||
21 | */ |
||
22 | protected $appConfig; |
||
23 | |||
24 | /** |
||
25 | * @var ILogger; |
||
26 | */ |
||
27 | protected $logger; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $scannerClass; |
||
33 | |||
34 | 15 | public function __construct(AppConfig $appConfig, ILogger $logger) { |
|
35 | 15 | $this->appConfig = $appConfig; |
|
36 | 15 | $this->logger = $logger; |
|
37 | try { |
||
38 | 15 | $this->getScannerClass(); |
|
39 | } catch (InitException $e) { |
||
40 | // rethrow misconfiguration exception |
||
41 | throw $e; |
||
42 | } catch (\Exception $e) { |
||
43 | $message = implode(' ', [ __CLASS__, __METHOD__, $e->getMessage()]); |
||
44 | $this->logger->warning($message, ['app' => 'files_antivirus']); |
||
45 | } |
||
46 | 15 | } |
|
47 | |||
48 | /** |
||
49 | * @throws InitException |
||
50 | */ |
||
51 | 15 | protected function getScannerClass() { |
|
52 | 15 | switch ($this->appConfig->getAvMode()) { |
|
53 | 15 | case 'daemon': |
|
54 | 9 | $this->scannerClass = 'OCA\Files_Antivirus\Scanner\Daemon'; |
|
55 | 9 | break; |
|
56 | 7 | case 'socket': |
|
57 | 1 | $this->scannerClass = 'OCA\Files_Antivirus\Scanner\Socket'; |
|
58 | 1 | break; |
|
59 | 6 | case 'executable': |
|
60 | 6 | $this->scannerClass = 'OCA\Files_Antivirus\Scanner\Local'; |
|
61 | 6 | break; |
|
62 | default: |
||
63 | throw new InitException( |
||
64 | sprintf( |
||
65 | 'Please check the settings at the admin page. Invalid mode: "%s"', |
||
66 | $this->appConfig->getAvMode() |
||
67 | ) |
||
68 | ); |
||
69 | } |
||
70 | 15 | } |
|
71 | |||
72 | /** |
||
73 | * Produce a scanner instance |
||
74 | * @return \OCA\Files_Antivirus\Scanner\AbstractScanner |
||
75 | */ |
||
76 | 8 | public function getScanner() { |
|
79 | |||
80 | /** |
||
81 | * @param AppConfig $appConfig |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function testConnection(AppConfig $appConfig) { |
||
96 | } |
||
97 |