Browse Source

Add dynamic hostname switching so requests always go to the host the client is currently using

multihost_notor
Skylar Ittner 2 years ago
parent
commit
d5478678a7

+ 2
- 1
.gitignore View File

@@ -2,4 +2,5 @@ tests/clover.xml
*.spec
*.tar.gz
richdocuments.zip
build/
build/
/nbproject/private/

+ 1
- 1
appinfo/app.php View File

@@ -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();

+ 2
- 2
lib/Controller/DocumentController.php View File

@@ -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;

+ 7
- 5
lib/WOPI/DiscoveryManager.php View File

@@ -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;
}


+ 7
- 0
nbproject/project.properties View File

@@ -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=.

+ 9
- 0
nbproject/project.xml View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.php.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/php-project/1">
<name>richdocuments</name>
</data>
</configuration>
</project>

+ 1
- 1
templates/admin.php View File

@@ -5,7 +5,7 @@ script('richdocuments', 'admin');
<h2><?php p($l->t('Collabora Online')) ?></h2>
<label for="wopi_url"><?php p($l->t('Collabora Online server')) ?></label>
<input type="text" name="wopi_url" id="wopi_url" value="<?php p($_['wopi_url'])?>" style="width:300px;">
<br/><em><?php p($l->t('URL (and port) of the Collabora Online server that provides the editing functionality as a WOPI client.')) ?></em>
<br/><em><?php p($l->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.')) ?></em>
<br/><button type="button" id="wopi_apply"><?php p($l->t('Apply')) ?></button>
<span id="documents-admin-msg" class="msg"></span>
<br/>

Loading…
Cancel
Save