Skip to content

Commit

Permalink
feat: Add browser connectivity check
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Nov 23, 2023
1 parent f21a198 commit 3085507
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 0 additions & 3 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public function __construct($appName,
parent::__construct($appName, $request);
}

#[PublicPage]
#[NoCSRFRequired]
public function checkSettings(): DataResponse {
try {
$output = new NullOutput();
Expand All @@ -76,7 +74,6 @@ public function checkSettings(): DataResponse {
return new DataResponse([
'status' => $e->getCode(),
'data' => [
// FIXME ONLY AS ADMIN
'message' => 'Failed to connect to the remote server: ' . $e->getMessage(),
'settings' => $this->getSettingsData(),
],
Expand Down
8 changes: 8 additions & 0 deletions lib/Listener/AddContentSecurityPolicyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,19 @@ public function handle(Event $event): void {
$policy->addAllowedImageDomain($url);
}

if ($this->isSettingsPage()) {
$policy->addAllowedConnectDomain("*");
}

$event->addPolicy($policy);
}

private function isPageLoad(): bool {
$scriptNameParts = explode('/', $this->request->getScriptName());
return end($scriptNameParts) === 'index.php';
}

private function isSettingsPage(): bool {
return str_starts_with($this->request->getPathInfo(), '/settings/admin/richdocuments');
}
}
21 changes: 21 additions & 0 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
<NcNoteCard v-else-if="serverError == 3" type="error">
<p>{{ t('richdocuments', 'Collabora Online should use the same protocol as the server installation.') }}</p>
</NcNoteCard>
<NcNoteCard v-else-if="serverError == 4" type="error">
<p>
{{ t('richdocuments', 'Your browser has been unable to connect to the Collabora server:') }}
{{ settings.public_wopi_url }}
</p>
<p>{{ t('richdocuments', 'This URL is determined on the Collabora server either from the configured URL or the server_name parameter in coolwsd.xml.') }}</p>
</NcNoteCard>
<NcNoteCard v-else type="success">
<p>{{ t('richdocuments', 'Collabora Online server is reachable.') }}</p>
<p>{{ settings.product_name }} {{ settings.product_version }} {{ settings.product_hash }}</p>
Expand Down Expand Up @@ -422,6 +429,8 @@ const SERVER_STATE_OK = 0
const SERVER_STATE_LOADING = 1
const SERVER_STATE_CONNECTION_ERROR = 2
const PROTOCOL_MISMATCH = 3
const SERVER_STATE_BROWSER_CONNECTION_ERROR = 4

const fontMimes = [
'font/ttf',
'application/font-sfnt',
Expand Down Expand Up @@ -609,6 +618,16 @@ export default {
for (const settingKey in settings) {
this.settings[settingKey] = settings[settingKey]
}
this.checkFrontend()
},
async checkFrontend() {
try {
await fetch(this.settings.public_wopi_url + '/hosting/discovery', { mode: 'no-cors' })
await fetch(this.settings.public_wopi_url + '/hosting/capabilities', { mode: 'no-cors' })
} catch (e) {
console.error(e)
this.serverError = SERVER_STATE_BROWSER_CONNECTION_ERROR
}
},
async fetchDemoServers() {
try {
Expand Down Expand Up @@ -712,6 +731,8 @@ export default {
this.settings[settingKey] = settings[settingKey]
}

this.checkFrontend()

return result
} catch (e) {
this.updating = false
Expand Down
2 changes: 1 addition & 1 deletion src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default {
},
computed: {
showIframe() {
return this.loading >= LOADING_STATE.FRAME_READY
return this.loading >= LOADING_STATE.FRAME_READY || this.debug
},
showLoadingIndicator() {
return this.loading < LOADING_STATE.FRAME_READY
Expand Down

0 comments on commit 3085507

Please sign in to comment.