Completed
Pull Request — master (#195)
by Victor
03:10
created

SettingsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
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
	public function __construct(IRequest $request, AppConfig $appConfig, ScannerFactory $scannerFactory, IL10N $l10n) {
32
		$this->settings = $appConfig;
33
		$this->scannerFactory = $scannerFactory;
34
		$this->l10n = $l10n;
35
	}
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
	public function save($avMode, $avSocket, $avHost, $avPort, $avCmdOptions, $avPath, $avInfectedAction, $avStreamMaxLength, $avMaxFileSize) {
61
		$this->settings->setAvMode($avMode);
62
		$this->settings->setAvSocket($avSocket);
63
		$this->settings->setAvHost($avHost);
64
		$this->settings->setAvPort($avPort);
65
		$this->settings->setAvCmdOptions($avCmdOptions);
66
		$this->settings->setAvPath($avPath);
67
		$this->settings->setAvInfectedAction($avInfectedAction);
68
		$this->settings->setAvStreamMaxLength($avStreamMaxLength);
69
		$this->settings->setAvMaxFileSize($avMaxFileSize);
70
71
		$connectionStatus = intval($this->scannerFactory->testConnection($this->settings));
72
73
		return new JSONResponse(
74
			['data' =>
75
				['message' =>
76
					(string) $this->l10n->t('Saved')
77
				],
78
				'connection' => $connectionStatus,
79
				'status' => 'success',
80
				'settings' => $this->settings->getAllValues()
81
			]
82
		);
83
	}
84
}
85