From d5478678a799c6761324dc87f557c30c6a18164d Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 6 Sep 2017 23:03:19 -0600 Subject: [PATCH] Add dynamic hostname switching so requests always go to the host the client is currently using --- .gitignore | 3 ++- appinfo/app.php | 2 +- lib/Controller/DocumentController.php | 4 ++-- lib/WOPI/DiscoveryManager.php | 12 +++++++----- nbproject/project.properties | 7 +++++++ nbproject/project.xml | 9 +++++++++ templates/admin.php | 2 +- 7 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/.gitignore b/.gitignore index 19e89a6a..618e4f99 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ tests/clover.xml *.spec *.tar.gz richdocuments.zip -build/ \ No newline at end of file +build/ +/nbproject/private/ \ No newline at end of file diff --git a/appinfo/app.php b/appinfo/app.php index bafc3467..d747b5fc 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -49,7 +49,7 @@ if (class_exists('\OC\Files\Type\TemplateManager')) { } // Whitelist the wopi URL for iframes, required for Firefox -$wopiUrl = \OC::$server->getConfig()->getAppValue('richdocuments', 'wopi_url'); +$wopiUrl = str_replace("hostname.host", $_SERVER["HTTP_HOST"], \OC::$server->getConfig()->getAppValue('richdocuments', 'wopi_url')); if ($wopiUrl !== '') { $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new ContentSecurityPolicy(); diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index ccbc46ee..83b997d0 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -129,7 +129,7 @@ class DocumentController extends Controller { $response = new TemplateResponse('richdocuments', 'documents', $params, 'empty'); $policy = new ContentSecurityPolicy(); - $policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url')); + $policy->addAllowedFrameDomain(str_replace("hostname.host", $_SERVER["HTTP_HOST"], $this->appConfig->getAppValue('wopi_url'))); $policy->allowInlineScript(true); $response->setContentSecurityPolicy($policy); return $response; @@ -192,7 +192,7 @@ class DocumentController extends Controller { $response = new TemplateResponse('richdocuments', 'documents', $params, 'empty'); $policy = new ContentSecurityPolicy(); - $policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url')); + $policy->addAllowedFrameDomain(str_replace("hostname.host", $_SERVER["HTTP_HOST"], $this->appConfig->getAppValue('wopi_url'))); $policy->allowInlineScript(true); $response->setContentSecurityPolicy($policy); return $response; diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index fd9da51c..6f7e184c 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -66,7 +66,8 @@ class DiscoveryManager { public function get() { // First check if there is a local valid discovery file - try { + // Skylar Ittner (2017-09-06): Disable the cache so clients on multiple hosts can use it without breaking Content Security Policy + /*try { $file = $this->appData->getFile('discovery.xml'); $decodedFile = json_decode($file->getContent(), true); if($decodedFile['timestamp'] + 3600 > $this->timeFactory->getTime()) { @@ -74,9 +75,9 @@ class DiscoveryManager { } } catch (NotFoundException $e) { $file = $this->appData->newFile('discovery.xml'); - } + }*/ - $remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url'); + $remoteHost = str_replace("hostname.host", $_SERVER["HTTP_HOST"], $this->config->getAppValue('richdocuments', 'wopi_url')); $wopiDiscovery = $remoteHost . '/hosting/discovery'; $client = $this->clientService->newClient(); @@ -87,12 +88,13 @@ class DiscoveryManager { } $responseBody = $response->getBody(); - $file->putContent( + // Skylar: Disable saving too, we don't need it if we're not loading ever + /*$file->putContent( json_encode([ 'data' => $responseBody, 'timestamp' => $this->timeFactory->getTime(), ]) - ); + );*/ return $responseBody; } diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 00000000..76f6f918 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_56 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 00000000..962786fb --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + richdocuments + + + diff --git a/templates/admin.php b/templates/admin.php index bbcdcb9f..244fbe8d 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -5,7 +5,7 @@ script('richdocuments', 'admin');

t('Collabora Online')) ?>

-
t('URL (and port) of the Collabora Online server that provides the editing functionality as a WOPI client.')) ?> +
t('URL (and port) of the Collabora Online server that provides the editing functionality as a WOPI client. If you use "hostname.host" as the host, it will be replaced with the current server name.')) ?>