1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2015 Viktar Dubiniuk <[email protected]> |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. |
6
|
|
|
* See the COPYING-README file. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OCA\Files_Antivirus\Controller; |
10
|
|
|
|
11
|
|
|
use OCA\Files_Antivirus\ScannerFactory; |
12
|
|
|
use \OCP\AppFramework\Controller; |
13
|
|
|
use \OCP\IRequest; |
14
|
|
|
use \OCP\IL10N; |
15
|
|
|
use \OCA\Files_Antivirus\AppConfig; |
16
|
|
|
|
17
|
|
|
use \OCP\AppFramework\Http\TemplateResponse; |
18
|
|
|
use \OCP\AppFramework\Http\JSONResponse; |
19
|
|
|
|
20
|
|
|
class SettingsController extends Controller { |
21
|
|
|
|
22
|
|
|
/** @var AppConfig */ |
23
|
|
|
private $settings; |
24
|
|
|
|
25
|
|
|
/** @var ScannerFactory */ |
26
|
|
|
private $scannerFactory; |
27
|
|
|
|
28
|
|
|
/** @var IL10N */ |
29
|
|
|
private $l10n; |
30
|
|
|
|
31
|
3 |
|
public function __construct(IRequest $request, AppConfig $appConfig, ScannerFactory $scannerFactory, IL10N $l10n) { |
32
|
3 |
|
$this->settings = $appConfig; |
33
|
3 |
|
$this->scannerFactory = $scannerFactory; |
34
|
3 |
|
$this->l10n = $l10n; |
35
|
3 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Print config section |
39
|
|
|
* @return TemplateResponse |
40
|
|
|
*/ |
41
|
|
|
public function index() { |
42
|
|
|
$data = $this->settings->getAllValues(); |
43
|
|
|
return new TemplateResponse('files_antivirus', 'settings', $data, 'blank'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Save Parameters |
48
|
|
|
* |
49
|
|
|
* @param string $avMode - antivirus mode |
50
|
|
|
* @param string $avSocket - path to socket (Socket mode) |
51
|
|
|
* @param string $avHost - antivirus url |
52
|
|
|
* @param int $avPort - port |
53
|
|
|
* @param string $avCmdOptions - extra command line options |
54
|
|
|
* @param string $avPath - path to antivirus executable (Executable mode) |
55
|
|
|
* @param string $avInfectedAction - action performed on infected files |
56
|
|
|
* @param $avStreamMaxLength - reopen socket after bytes |
57
|
|
|
* @param int $avMaxFileSize - file size limit |
58
|
|
|
* @return JSONResponse |
59
|
|
|
*/ |
60
|
3 |
|
public function save($avMode, $avSocket, $avHost, $avPort, $avCmdOptions, $avPath, $avInfectedAction, $avStreamMaxLength, $avMaxFileSize) { |
61
|
3 |
|
$this->settings->setAvMode($avMode); |
62
|
3 |
|
if ($avMode === 'executable') { |
63
|
1 |
|
$this->settings->setAvCmdOptions($avCmdOptions); |
64
|
1 |
|
$this->settings->setAvPath($avPath); |
65
|
3 |
|
} else if ($avMode === 'daemon') { |
66
|
1 |
|
$this->settings->setAvPort($avPort); |
67
|
1 |
|
$this->settings->setAvHost($avHost); |
68
|
2 |
|
} else if ($avMode === 'socket') { |
69
|
1 |
|
$this->settings->setAvSocket($avSocket); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
3 |
|
$this->settings->setAvInfectedAction($avInfectedAction); |
73
|
3 |
|
$this->settings->setAvStreamMaxLength($avStreamMaxLength); |
74
|
3 |
|
$this->settings->setAvMaxFileSize($avMaxFileSize); |
75
|
|
|
|
76
|
3 |
|
$connectionStatus = intval($this->scannerFactory->testConnection($this->settings)); |
77
|
|
|
|
78
|
3 |
|
return new JSONResponse( |
79
|
|
|
['data' => |
80
|
|
|
['message' => |
81
|
3 |
|
(string) $this->l10n->t('Saved') |
82
|
3 |
|
], |
83
|
3 |
|
'connection' => $connectionStatus, |
84
|
3 |
|
'status' => 'success', |
85
|
3 |
|
'settings' => $this->settings->getAllValues() |
86
|
3 |
|
] |
87
|
3 |
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|