1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Richdocuments App |
4
|
|
|
* |
5
|
|
|
* @author Victor Dubiniuk |
6
|
|
|
* @copyright 2014 Victor Dubiniuk [email protected] |
7
|
|
|
* |
8
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
9
|
|
|
* later. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Richdocuments\Controller; |
13
|
|
|
|
14
|
|
|
use OCA\Richdocuments\Service\CapabilitiesService; |
15
|
|
|
use OCA\Richdocuments\WOPI\DiscoveryManager; |
16
|
|
|
use \OCP\AppFramework\Controller; |
17
|
|
|
use OCP\AppFramework\Http; |
18
|
|
|
use OCP\AppFramework\Http\DataResponse; |
19
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
20
|
|
|
use \OCP\IRequest; |
21
|
|
|
use \OCP\IL10N; |
22
|
|
|
use OCA\Richdocuments\AppConfig; |
23
|
|
|
use OCP\IConfig; |
24
|
|
|
use OCP\PreConditionNotMetException; |
25
|
|
|
|
26
|
|
|
class SettingsController extends Controller{ |
27
|
|
|
/** @var IL10N */ |
28
|
|
|
private $l10n; |
29
|
|
|
/** @var AppConfig */ |
30
|
|
|
private $appConfig; |
31
|
|
|
/** @var IConfig */ |
32
|
|
|
private $config; |
33
|
|
|
/** @var DiscoveryManager */ |
34
|
|
|
private $discoveryManager; |
35
|
|
|
/** @var string */ |
36
|
|
|
private $userId; |
37
|
|
|
/** @var CapabilitiesService */ |
38
|
|
|
private $capabilitiesService; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $appName |
42
|
|
|
* @param IRequest $request |
43
|
|
|
* @param IL10N $l10n |
44
|
|
|
* @param AppConfig $appConfig |
45
|
|
|
* @param IConfig $config |
46
|
|
|
* @param DiscoveryManager $discoveryManager |
47
|
|
|
* @param string $userId |
48
|
|
|
*/ |
49
|
|
|
public function __construct($appName, |
50
|
|
|
IRequest $request, |
51
|
|
|
IL10N $l10n, |
52
|
|
|
AppConfig $appConfig, |
53
|
|
|
IConfig $config, |
54
|
|
|
DiscoveryManager $discoveryManager, |
55
|
|
|
$userId, |
56
|
|
|
CapabilitiesService $capabilitiesService) { |
57
|
|
|
parent::__construct($appName, $request); |
58
|
|
|
$this->l10n = $l10n; |
59
|
|
|
$this->appConfig = $appConfig; |
60
|
|
|
$this->config = $config; |
61
|
|
|
$this->discoveryManager = $discoveryManager; |
62
|
|
|
$this->userId = $userId; |
63
|
|
|
$this->capabilitiesService = $capabilitiesService; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @PublicPage |
68
|
|
|
* @NoCSRFRequired |
69
|
|
|
* @throws \Exception |
70
|
|
|
*/ |
71
|
|
|
public function checkSettings() { |
72
|
|
|
try { |
73
|
|
|
$response = $this->discoveryManager->fetchFromRemote(); |
|
|
|
|
74
|
|
|
} catch (\Exception $e) { |
75
|
|
|
return new DataResponse([ |
76
|
|
|
'status' => $e->getCode(), |
77
|
|
|
'message' => $e->getMessage() |
78
|
|
|
], $e->getCode()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return new DataResponse(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @NoAdminRequired |
86
|
|
|
* |
87
|
|
|
* @return JSONResponse |
88
|
|
|
*/ |
89
|
|
|
public function getSettings() { |
90
|
|
|
return new JSONResponse([ |
91
|
|
|
'wopi_url' => $this->appConfig->getAppValue('wopi_url'), |
92
|
|
|
'disable_certificate_verification' => $this->appConfig->getAppValue('disable_certificate_verification'), |
93
|
|
|
'edit_groups' => $this->appConfig->getAppValue('edit_groups'), |
94
|
|
|
'use_groups' => $this->appConfig->getAppValue('use_groups'), |
95
|
|
|
'doc_format' => $this->appConfig->getAppValue('doc_format'), |
96
|
|
|
]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $wopi_url |
101
|
|
|
* @param string $disable_certificate_verification |
102
|
|
|
* @param string $edit_groups |
103
|
|
|
* @param string $use_groups |
104
|
|
|
* @param string $doc_format |
105
|
|
|
* @param string $external_apps |
106
|
|
|
* @param string $canonical_webroot |
107
|
|
|
* @return JSONResponse |
108
|
|
|
*/ |
109
|
|
|
public function setSettings($wopi_url, |
110
|
|
|
$disable_certificate_verification, |
111
|
|
|
$edit_groups, |
112
|
|
|
$use_groups, |
113
|
|
|
$doc_format, |
114
|
|
|
$external_apps, |
115
|
|
|
$canonical_webroot) { |
116
|
|
|
$message = $this->l10n->t('Saved'); |
117
|
|
|
|
118
|
|
|
if ($wopi_url !== null){ |
119
|
|
|
$this->appConfig->setAppValue('wopi_url', $wopi_url); |
120
|
|
|
|
121
|
|
|
$colon = strpos($wopi_url, ':', 0); |
122
|
|
|
if ($this->request->getServerProtocol() !== substr($wopi_url, 0, $colon)){ |
123
|
|
|
$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.'); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if ($disable_certificate_verification !== null) { |
128
|
|
|
$this->appConfig->setAppValue( |
129
|
|
|
'disable_certificate_verification', |
130
|
|
|
$disable_certificate_verification === 'true' ? 'yes' : '' |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if ($edit_groups !== null){ |
135
|
|
|
$this->appConfig->setAppValue('edit_groups', $edit_groups); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if ($use_groups !== null){ |
139
|
|
|
$this->appConfig->setAppValue('use_groups', $use_groups); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if ($doc_format !== null) { |
143
|
|
|
$this->appConfig->setAppValue('doc_format', $doc_format); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
if ($external_apps !== null) { |
147
|
|
|
$this->appConfig->setAppValue('external_apps', $external_apps); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if ($canonical_webroot !== null) { |
151
|
|
|
$this->appConfig->setAppValue('canonical_webroot', $canonical_webroot); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$this->discoveryManager->refretch(); |
155
|
|
|
$this->capabilitiesService->refretch(); |
156
|
|
|
|
157
|
|
|
$response = [ |
158
|
|
|
'status' => 'success', |
159
|
|
|
'data' => ['message' => $message] |
160
|
|
|
]; |
161
|
|
|
|
162
|
|
|
return new JSONResponse($response); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @NoAdminRequired |
167
|
|
|
* |
168
|
|
|
* @param $key |
169
|
|
|
* @param $value |
170
|
|
|
* @return JSONResponse |
171
|
|
|
*/ |
172
|
|
|
public function setPersonalSettings($templateFolder) { |
173
|
|
|
$message = $this->l10n->t('Saved'); |
174
|
|
|
$status = 'success'; |
175
|
|
|
|
176
|
|
|
if ($templateFolder !== null){ |
177
|
|
|
try { |
178
|
|
|
$this->config->setUserValue($this->userId, 'richdocuments', 'templateFolder', $templateFolder); |
179
|
|
|
} catch (PreConditionNotMetException $e) { |
|
|
|
|
180
|
|
|
$message = $this->l10n->t('Error when saving'); |
181
|
|
|
$status = 'error'; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$response = [ |
186
|
|
|
'status' => $status, |
187
|
|
|
'data' => ['message' => $message] |
188
|
|
|
]; |
189
|
|
|
|
190
|
|
|
return new JSONResponse($response); |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.