1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Mvc\Controller; |
13
|
|
|
|
14
|
|
|
use Xenolope\Quahog\Client; |
15
|
|
|
use Zemit\Mvc\View; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @property View $view |
19
|
|
|
* @property Client $clamav |
20
|
|
|
*/ |
21
|
|
|
trait Clamav |
22
|
|
|
{ |
23
|
|
|
public function indexAction(): void |
24
|
|
|
{ |
25
|
|
|
$this->clamav->startSession(); |
26
|
|
|
$this->pingAction(); |
27
|
|
|
$this->versionAction(); |
28
|
|
|
$this->statsAction(); |
29
|
|
|
$this->clamav->endSession(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function scanAction(?string $filePath = null): bool |
33
|
|
|
{ |
34
|
|
|
$this->clamav->startSession(); |
35
|
|
|
$result = $this->clamav->scanFile($filePath); |
36
|
|
|
$this->clamav->endSession(); |
37
|
|
|
|
38
|
|
|
$ret = []; |
39
|
|
|
$ret['ok'] = $result->isOk(); |
40
|
|
|
$ret['error'] = $result->isError(); |
41
|
|
|
$ret['found'] = $result->isFound(); |
42
|
|
|
$ret['reason'] = $result->getReason(); |
43
|
|
|
$ret['id'] = $result->getId(); |
44
|
|
|
$ret['filename'] = $result->getFilename(); |
45
|
|
|
|
46
|
|
|
$this->view->setVars($ret); |
47
|
|
|
|
48
|
|
|
return $ret['ok']; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function pingAction(): bool |
52
|
|
|
{ |
53
|
|
|
$ret = $this->clamav->ping(); |
54
|
|
|
$this->view->setVar('ping', $ret); |
55
|
|
|
return $ret; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function versionAction(): bool |
59
|
|
|
{ |
60
|
|
|
$ret = $this->clamav->version(); |
61
|
|
|
$this->view->setVar('version', $ret); |
62
|
|
|
return !empty($ret); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function statsAction(): bool |
66
|
|
|
{ |
67
|
|
|
$ret = $this->clamav->stats(); |
68
|
|
|
$this->view->setVar('stats', $ret); |
69
|
|
|
return !empty($ret); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function reloadAction(): bool |
73
|
|
|
{ |
74
|
|
|
$ret = $this->clamav->reload(); |
75
|
|
|
$this->view->setVar('reload', $ret); |
76
|
|
|
return $ret === 'RELOADING'; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|