These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\Service\DemoService; |
||
16 | use OCA\Richdocuments\WOPI\DiscoveryManager; |
||
17 | use OCA\Richdocuments\WOPI\Parser; |
||
18 | use \OCP\AppFramework\Controller; |
||
19 | use OCP\AppFramework\Http; |
||
20 | use OCP\AppFramework\Http\DataResponse; |
||
21 | use OCP\AppFramework\Http\JSONResponse; |
||
22 | use OCP\AppFramework\Http\NotFoundResponse; |
||
23 | use OCP\Http\Client\IClientService; |
||
24 | use OCP\ICache; |
||
25 | use \OCP\IRequest; |
||
26 | use \OCP\IL10N; |
||
27 | use OCA\Richdocuments\AppConfig; |
||
28 | use OCP\IConfig; |
||
29 | use OCP\PreConditionNotMetException; |
||
30 | |||
31 | class SettingsController extends Controller{ |
||
32 | /** @var IL10N */ |
||
33 | private $l10n; |
||
34 | /** @var AppConfig */ |
||
35 | private $appConfig; |
||
36 | /** @var IConfig */ |
||
37 | private $config; |
||
38 | /** @var DiscoveryManager */ |
||
39 | private $discoveryManager; |
||
40 | /** @var Parser */ |
||
41 | private $wopiParser; |
||
42 | /** @var string */ |
||
43 | private $userId; |
||
44 | /** @var CapabilitiesService */ |
||
45 | private $capabilitiesService; |
||
46 | /** @var DemoService */ |
||
47 | private $demoService; |
||
48 | |||
49 | /** |
||
50 | * @param string $appName |
||
51 | * @param IRequest $request |
||
52 | * @param IL10N $l10n |
||
53 | * @param AppConfig $appConfig |
||
54 | * @param IConfig $config |
||
55 | * @param DiscoveryManager $discoveryManager |
||
56 | * @param Parser $wopiParser |
||
57 | * @param string $userId |
||
58 | * @param CapabilitiesService $capabilitiesService |
||
59 | */ |
||
60 | public function __construct($appName, |
||
61 | IRequest $request, |
||
62 | IL10N $l10n, |
||
63 | AppConfig $appConfig, |
||
64 | IConfig $config, |
||
65 | DiscoveryManager $discoveryManager, |
||
66 | Parser $wopiParser, |
||
67 | $userId, |
||
68 | CapabilitiesService $capabilitiesService, |
||
69 | DemoService $demoService |
||
70 | ) { |
||
71 | parent::__construct($appName, $request); |
||
72 | $this->l10n = $l10n; |
||
73 | $this->appConfig = $appConfig; |
||
74 | $this->config = $config; |
||
75 | $this->discoveryManager = $discoveryManager; |
||
76 | $this->wopiParser = $wopiParser; |
||
77 | $this->userId = $userId; |
||
78 | $this->capabilitiesService = $capabilitiesService; |
||
79 | $this->demoService = $demoService; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @PublicPage |
||
84 | * @NoCSRFRequired |
||
85 | * @throws \Exception |
||
86 | */ |
||
87 | public function checkSettings() { |
||
88 | try { |
||
89 | $response = $this->discoveryManager->fetchFromRemote(); |
||
0 ignored issues
–
show
|
|||
90 | } catch (\Exception $e) { |
||
91 | return new DataResponse([ |
||
92 | 'status' => $e->getCode(), |
||
93 | 'message' => $e->getMessage() |
||
94 | ], Http::STATUS_INTERNAL_SERVER_ERROR); |
||
95 | } |
||
96 | |||
97 | return new DataResponse(); |
||
98 | } |
||
99 | |||
100 | public function demoServers() { |
||
101 | $demoServers = $this->demoService->fetchDemoServers(true); |
||
102 | if (count($demoServers) > 0) { |
||
103 | return new DataResponse($demoServers); |
||
104 | } |
||
105 | return new NotFoundResponse([]); |
||
0 ignored issues
–
show
The call to
NotFoundResponse::__construct() has too many arguments starting with array() .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @NoAdminRequired |
||
110 | * |
||
111 | * @return JSONResponse |
||
112 | */ |
||
113 | public function getSettings() { |
||
114 | return new JSONResponse([ |
||
115 | 'wopi_url' => $this->appConfig->getAppValue('wopi_url'), |
||
116 | 'public_wopi_url' => $this->appConfig->getAppValue('public_wopi_url'), |
||
117 | 'disable_certificate_verification' => $this->appConfig->getAppValue('disable_certificate_verification', '') !== '', |
||
0 ignored issues
–
show
The call to
AppConfig::getAppValue() has too many arguments starting with '' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
118 | 'edit_groups' => $this->appConfig->getAppValue('edit_groups'), |
||
119 | 'use_groups' => $this->appConfig->getAppValue('use_groups'), |
||
120 | 'doc_format' => $this->appConfig->getAppValue('doc_format'), |
||
121 | ]); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @param string $wopi_url |
||
126 | * @param string $disable_certificate_verification |
||
127 | * @param string $edit_groups |
||
128 | * @param string $use_groups |
||
129 | * @param string $doc_format |
||
130 | * @param string $external_apps |
||
131 | * @param string $canonical_webroot |
||
132 | * @return JSONResponse |
||
133 | */ |
||
134 | public function setSettings($wopi_url, |
||
135 | $disable_certificate_verification, |
||
136 | $edit_groups, |
||
137 | $use_groups, |
||
138 | $doc_format, |
||
139 | $external_apps, |
||
140 | $canonical_webroot) { |
||
141 | $message = $this->l10n->t('Saved'); |
||
142 | |||
143 | if ($wopi_url !== null){ |
||
144 | $this->appConfig->setAppValue('wopi_url', $wopi_url); |
||
145 | } |
||
146 | |||
147 | if ($disable_certificate_verification !== null) { |
||
148 | $this->appConfig->setAppValue( |
||
149 | 'disable_certificate_verification', |
||
150 | $disable_certificate_verification === 'true' ? 'yes' : '' |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | if ($edit_groups !== null){ |
||
155 | $this->appConfig->setAppValue('edit_groups', $edit_groups); |
||
156 | } |
||
157 | |||
158 | if ($use_groups !== null){ |
||
159 | $this->appConfig->setAppValue('use_groups', $use_groups); |
||
160 | } |
||
161 | |||
162 | if ($doc_format !== null) { |
||
163 | $this->appConfig->setAppValue('doc_format', $doc_format); |
||
164 | } |
||
165 | |||
166 | if ($external_apps !== null) { |
||
167 | $this->appConfig->setAppValue('external_apps', $external_apps); |
||
168 | } |
||
169 | |||
170 | if ($canonical_webroot !== null) { |
||
171 | $this->appConfig->setAppValue('canonical_webroot', $canonical_webroot); |
||
172 | } |
||
173 | |||
174 | $this->discoveryManager->refretch(); |
||
175 | $this->capabilitiesService->clear(); |
||
176 | try { |
||
177 | $capaUrlSrc = $this->wopiParser->getUrlSrc('Capabilities'); |
||
178 | if (is_array($capaUrlSrc) && $capaUrlSrc['action'] === 'getinfo') { |
||
179 | $public_wopi_url = str_replace('/hosting/capabilities', '', $capaUrlSrc['urlsrc']); |
||
180 | if ($public_wopi_url !== null) { |
||
181 | $this->appConfig->setAppValue('public_wopi_url', $public_wopi_url); |
||
182 | $colon = strpos($public_wopi_url, ':', 0); |
||
183 | if ($this->request->getServerProtocol() !== substr($public_wopi_url, 0, $colon)){ |
||
184 | $message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.'); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | } catch (\Exception $e){ |
||
189 | if ($wopi_url !== null) { |
||
190 | return new JSONResponse([ |
||
191 | 'status' => 'error', |
||
192 | 'data' => ['message' => 'Failed to connect to the remote server'] |
||
193 | ], 500); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | $this->capabilitiesService->clear(); |
||
198 | $this->capabilitiesService->refretch(); |
||
199 | |||
200 | $response = [ |
||
201 | 'status' => 'success', |
||
202 | 'data' => ['message' => $message] |
||
203 | ]; |
||
204 | |||
205 | return new JSONResponse($response); |
||
206 | } |
||
207 | |||
208 | public function updateWatermarkSettings($settings = []) { |
||
209 | $supportedOptions = [ |
||
210 | 'watermark_text', |
||
211 | 'watermark_enabled', |
||
212 | 'watermark_shareAll', |
||
213 | 'watermark_shareRead', |
||
214 | 'watermark_linkSecure', |
||
215 | 'watermark_linkRead', |
||
216 | 'watermark_linkAll', |
||
217 | 'watermark_linkTags', |
||
218 | 'watermark_linkTagsList', |
||
219 | 'watermark_allGroups', |
||
220 | 'watermark_allGroupsList', |
||
221 | 'watermark_allTags', |
||
222 | 'watermark_allTagsList', |
||
223 | ]; |
||
224 | $message = $this->l10n->t('Saved'); |
||
225 | |||
226 | $watermarkSettings = $settings['watermark']; |
||
227 | foreach ($watermarkSettings as $key => $value) { |
||
228 | $fullKey = 'watermark_' . $key; |
||
229 | if (in_array($fullKey, $supportedOptions) !== true) { |
||
230 | return new JSONResponse([ |
||
231 | 'status' => 'error', |
||
232 | 'data' => ['message' => $this->l10n->t('Invalid config key') . ' ' . $fullKey] |
||
233 | ], Http::STATUS_BAD_REQUEST); |
||
234 | } |
||
235 | $value = $value === true ? 'yes' : $value; |
||
236 | $value = $value === false ? 'no' : $value; |
||
237 | if (AppConfig::APP_SETTING_TYPES[$fullKey] === 'array') { |
||
238 | $value = implode(',', $value); |
||
239 | } |
||
240 | $this->appConfig->setAppValue($fullKey, $value); |
||
241 | } |
||
242 | |||
243 | $response = [ |
||
244 | 'status' => 'success', |
||
245 | 'data' => ['message' => $message] |
||
246 | ]; |
||
247 | |||
248 | return new JSONResponse($response); |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @NoAdminRequired |
||
253 | * |
||
254 | * @param $key |
||
255 | * @param $value |
||
256 | * @return JSONResponse |
||
257 | */ |
||
258 | public function setPersonalSettings($templateFolder) { |
||
259 | $message = $this->l10n->t('Saved'); |
||
260 | $status = 'success'; |
||
261 | |||
262 | if ($templateFolder !== null){ |
||
263 | try { |
||
264 | $this->config->setUserValue($this->userId, 'richdocuments', 'templateFolder', $templateFolder); |
||
265 | } catch (PreConditionNotMetException $e) { |
||
266 | $message = $this->l10n->t('Error when saving'); |
||
267 | $status = 'error'; |
||
268 | } |
||
269 | } |
||
270 | |||
271 | $response = [ |
||
272 | 'status' => $status, |
||
273 | 'data' => ['message' => $message] |
||
274 | ]; |
||
275 | |||
276 | return new JSONResponse($response); |
||
277 | |||
278 | } |
||
279 | } |
||
280 |
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.