diff options
-rw-r--r-- | appinfo/routes.php | 1 | ||||
-rw-r--r-- | js/viewer/viewer.js | 2 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 20 | ||||
-rw-r--r-- | lib/WOPI/DiscoveryManager.php | 34 |
4 files changed, 45 insertions, 12 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php index b4fb1e68..428ac1ec 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -46,6 +46,7 @@ return [ ['name' => 'settings#setPersonalSettings', 'url' => 'ajax/personal.php', 'verb' => 'POST'], ['name' => 'settings#setSettings', 'url' => 'ajax/admin.php', 'verb' => 'POST'], ['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'], + ['name' => 'settings#checkSettings', 'url' => 'settings/check', 'verb' => 'GET'], //Mobile access ['name' => 'directView#show', 'url' => '/direct/{token}', 'verb' => 'GET'], diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index ef0f35cf..9cc0afed 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -130,7 +130,7 @@ var odfViewer = { OC.addStyle('richdocuments', 'mobile'); var $iframe = $('<iframe id="richdocumentsframe" scrolling="no" allowfullscreen src="'+viewer+'" />'); - $.get(viewer, function() { + $.get(OC.generateUrl('/apps/richdocuments/settings/check'), function() { $iframe.src = viewer; }) .fail(function() { odfViewer.onClose(); diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 7a8ee804..432b0f12 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -14,6 +14,8 @@ namespace OCA\Richdocuments\Controller; use OCA\Richdocuments\Service\CapabilitiesService; use OCA\Richdocuments\WOPI\DiscoveryManager; use \OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; use \OCP\IRequest; use \OCP\IL10N; @@ -62,6 +64,24 @@ class SettingsController extends Controller{ } /** + * @PublicPage + * @NoCSRFRequired + * @throws \Exception + */ + public function checkSettings() { + try { + $response = $this->discoveryManager->fetchFromRemote(); + } catch (\Exception $e) { + return new DataResponse([ + 'status' => $e->getCode(), + 'message' => $e->getMessage() + ], $e->getCode()); + } + + return new DataResponse(); + } + + /** * @NoAdminRequired * * @return JSONResponse diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index b4ca94cf..5505e806 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -75,17 +75,7 @@ class DiscoveryManager { $file = $this->appData->newFile('discovery.xml'); } - $remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url'); - $wopiDiscovery = $remoteHost . '/hosting/discovery'; - - $client = $this->clientService->newClient(); - $options = []; - - if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') { - $options['verify'] = false; - } - - $response = $client->get($wopiDiscovery, $options); + $response = $this->fetchFromRemote(); $responseBody = $response->getBody(); $file->putContent( @@ -97,6 +87,28 @@ class DiscoveryManager { return $responseBody; } + /** + * @return \OCP\Http\Client\IResponse + * @throws \Exception + */ + public function fetchFromRemote() { + $remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url'); + $wopiDiscovery = $remoteHost . '/hosting/discovery'; + + $client = $this->clientService->newClient(); + $options = ['timeout' => 5]; + + if ($this->config->getAppValue('richdocuments', 'disable_certificate_verification') === 'yes') { + $options['verify'] = false; + } + + try { + return $client->get($wopiDiscovery, $options); + } catch (\Exception $e) { + throw $e; + } + } + public function refretch() { try { $this->appData->getFile('discovery.xml')->delete(); |