Browse Source

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

multihost_notor
Skylar Ittner 1 year ago
parent
commit
d5478678a7

+ 2
- 1
.gitignore View File

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

+ 1
- 1
appinfo/app.php View File

@@ -49,7 +49,7 @@ if (class_exists('\OC\Files\Type\TemplateManager')) {
49 49
 }
50 50
 
51 51
 // Whitelist the wopi URL for iframes, required for Firefox
52
-$wopiUrl = \OC::$server->getConfig()->getAppValue('richdocuments', 'wopi_url');
52
+$wopiUrl = str_replace("hostname.host", $_SERVER["HTTP_HOST"], \OC::$server->getConfig()->getAppValue('richdocuments', 'wopi_url'));
53 53
 if ($wopiUrl !== '') {
54 54
 	$manager = \OC::$server->getContentSecurityPolicyManager();
55 55
 	$policy = new ContentSecurityPolicy();

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

@@ -129,7 +129,7 @@ class DocumentController extends Controller {
129 129
 
130 130
 			$response = new TemplateResponse('richdocuments', 'documents', $params, 'empty');
131 131
 			$policy = new ContentSecurityPolicy();
132
-			$policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url'));
132
+			$policy->addAllowedFrameDomain(str_replace("hostname.host", $_SERVER["HTTP_HOST"], $this->appConfig->getAppValue('wopi_url')));
133 133
 			$policy->allowInlineScript(true);
134 134
 			$response->setContentSecurityPolicy($policy);
135 135
 			return $response;
@@ -192,7 +192,7 @@ class DocumentController extends Controller {
192 192
 
193 193
 				$response = new TemplateResponse('richdocuments', 'documents', $params, 'empty');
194 194
 				$policy = new ContentSecurityPolicy();
195
-				$policy->addAllowedFrameDomain($this->appConfig->getAppValue('wopi_url'));
195
+				$policy->addAllowedFrameDomain(str_replace("hostname.host", $_SERVER["HTTP_HOST"], $this->appConfig->getAppValue('wopi_url')));
196 196
 				$policy->allowInlineScript(true);
197 197
 				$response->setContentSecurityPolicy($policy);
198 198
 				return $response;

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

@@ -66,7 +66,8 @@ class DiscoveryManager {
66 66
 
67 67
 	public function get() {
68 68
 		// First check if there is a local valid discovery file
69
-		try {
69
+                // Skylar Ittner (2017-09-06): Disable the cache so clients on multiple hosts can use it without breaking Content Security Policy
70
+		/*try {
70 71
 			$file = $this->appData->getFile('discovery.xml');
71 72
 			$decodedFile = json_decode($file->getContent(), true);
72 73
 			if($decodedFile['timestamp'] + 3600 > $this->timeFactory->getTime()) {
@@ -74,9 +75,9 @@ class DiscoveryManager {
74 75
 			}
75 76
 		} catch (NotFoundException $e) {
76 77
 			$file = $this->appData->newFile('discovery.xml');
77
-		}
78
+		}*/
78 79
 
79
-		$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
80
+		$remoteHost = str_replace("hostname.host", $_SERVER["HTTP_HOST"], $this->config->getAppValue('richdocuments', 'wopi_url'));
80 81
 		$wopiDiscovery = $remoteHost . '/hosting/discovery';
81 82
 
82 83
 		$client = $this->clientService->newClient();
@@ -87,12 +88,13 @@ class DiscoveryManager {
87 88
 		}
88 89
 
89 90
 		$responseBody = $response->getBody();
90
-		$file->putContent(
91
+                // Skylar: Disable saving too, we don't need it if we're not loading ever
92
+		/*$file->putContent(
91 93
 			json_encode([
92 94
 				'data' => $responseBody,
93 95
 				'timestamp' => $this->timeFactory->getTime(),
94 96
 			])
95
-		);
97
+		);*/
96 98
 		return $responseBody;
97 99
 	}
98 100
 

+ 7
- 0
nbproject/project.properties View File

@@ -0,0 +1,7 @@
1
+include.path=${php.global.include.path}
2
+php.version=PHP_56
3
+source.encoding=UTF-8
4
+src.dir=.
5
+tags.asp=false
6
+tags.short=false
7
+web.root=.

+ 9
- 0
nbproject/project.xml View File

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

+ 1
- 1
templates/admin.php View File

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

Loading…
Cancel
Save