diff --git a/controller/documentcontroller.php b/controller/documentcontroller.php index e82d77a8..38e38f28 100644 --- a/controller/documentcontroller.php +++ b/controller/documentcontroller.php @@ -103,38 +103,47 @@ class DocumentController extends Controller{ \OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' ); $maxUploadFilesize = \OCP\Util::maxUploadFilesize("/"); $wopiRemote = $this->settings->getAppValue('richdocuments', 'wopi_url'); + if (($parts = parse_url($wopiRemote))) { + // Provides access to information about the capabilities of a WOPI client + // and the mechanisms for invoking those abilities through URIs. + // HTTP://server/hosting/discovery + $wopiDiscovery = sprintf( + "%s%s%s%s", + isset($parts['scheme']) ? $parts['scheme'] . "://" : '', + isset($parts['host']) ? $parts['host'] : "", + isset($parts['port']) ? ":" . $parts['port'] : "", + "/hosting/discovery" ); + $webSocket = sprintf( + "%s%s%s", + "ws://", + isset($parts['host']) ? $parts['host'] : "", + isset($parts['port']) ? ":" . $parts['port'] : ""); + } + else { + $wopiRemote = null; + } + $response = new TemplateResponse('richdocuments', 'documents', [ 'enable_previews' => $this->settings->getSystemValue('enable_previews', true), 'savePath' => $this->settings->getUserValue($this->uid, 'richdocuments', 'save_path', '/'), 'uploadMaxFilesize' => $maxUploadFilesize, 'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize), 'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'), - 'wopi_url' => $wopiRemote, + 'wopi_url' => $webSocket, ]); $policy = new ContentSecurityPolicy(); $policy->addAllowedScriptDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $wopiRemote); $policy->addAllowedFrameDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $wopiRemote); - $policy->addAllowedConnectDomain('ws://' . $_SERVER['SERVER_NAME'] . ':9980'); + $policy->addAllowedConnectDomain($webSocket); $policy->addAllowedImageDomain('*'); $policy->allowInlineScript(true); $policy->addAllowedFontDomain('data:'); $response->setContentSecurityPolicy($policy); - $discovery = $this->cache->get('discovery.xml'); - if(is_null($discovery)) { - if (($parts = parse_url($wopiRemote))) { - // Provides access to information about the capabilities of a WOPI client - // and the mechanisms for invoking those abilities through URIs. - // HTTP://server/hosting/discovery - $wopiDiscovery = sprintf( - "%s%s%s%s", - isset($parts['scheme']) ? $parts['scheme'] . "://" : '', - isset($parts['host']) ? $parts['host'] : '', - isset($parts['port']) ? ":" . $parts['port'] : '', - "/hosting/discovery" ); - $this->requestDiscovery($wopiDiscovery); - } + $discovery = $this->cache->get('discovery.xml'); + if(is_null($discovery) && isset($wopiDiscovery)) { + $this->requestDiscovery($wopiDiscovery); } return $response; diff --git a/js/documents.js b/js/documents.js index 11ddbe3e..cc983069 100644 --- a/js/documents.js +++ b/js/documents.js @@ -197,8 +197,8 @@ var documentsMain = { documentsMain.url = window.location.protocol + '//' + window.location.host + url; var viewer = urlsrc + - 'file_path=' + encodeURIComponent(documentsMain.url) + - '&host=' + 'ws://' + window.location.hostname + ':9980' + + 'WOPISrc=' + encodeURIComponent(documentsMain.url) + + '&host=' + $('#wopi-url').val() + '&permission=' + 'view' + '×tamp=' + ''; diff --git a/lib/appconfig.php b/lib/appconfig.php index bc255d22..d418a0ff 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -16,7 +16,7 @@ use \OCP\IConfig; class AppConfig{ private $appName = 'richdocuments'; private $defaults = [ - 'wopi_url' => 'http://localhost' + 'wopi_url' => 'http://localhost:9980' ]; private $config;