Skip to content

Commit da063e7

Browse files
committed
Add more helpful setup checks
Signed-off-by: Julius Härtl <[email protected]>
1 parent 16d6c4a commit da063e7

File tree

17 files changed

+369
-414
lines changed

17 files changed

+369
-414
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You can also edit your documents off-line with the Collabora Office app from the
2828
<nextcloud min-version="28" max-version="28"/>
2929
</dependencies>
3030
<background-jobs>
31-
<job>OCA\Richdocuments\Backgroundjobs\ObtainCapabilities</job>
31+
<job>OCA\Richdocuments\Backgroundjobs\CheckConnectivity</job>
3232
<job>OCA\Richdocuments\Backgroundjobs\Cleanup</job>
3333
</background-jobs>
3434
<commands>

composer/composer/autoload_classmap.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
1010
'OCA\\Richdocuments\\AppConfig' => $baseDir . '/../lib/AppConfig.php',
1111
'OCA\\Richdocuments\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
12+
'OCA\\Richdocuments\\Backgroundjobs\\CheckConnectivity' => $baseDir . '/../lib/Backgroundjobs/CheckConnectivity.php',
1213
'OCA\\Richdocuments\\Backgroundjobs\\Cleanup' => $baseDir . '/../lib/Backgroundjobs/Cleanup.php',
13-
'OCA\\Richdocuments\\Backgroundjobs\\ObtainCapabilities' => $baseDir . '/../lib/Backgroundjobs/ObtainCapabilities.php',
1414
'OCA\\Richdocuments\\Capabilities' => $baseDir . '/../lib/Capabilities.php',
1515
'OCA\\Richdocuments\\Command\\ActivateConfig' => $baseDir . '/../lib/Command/ActivateConfig.php',
1616
'OCA\\Richdocuments\\Command\\ConvertToBigInt' => $baseDir . '/../lib/Command/ConvertToBigInt.php',
@@ -55,8 +55,11 @@
5555
'OCA\\Richdocuments\\Preview\\Office' => $baseDir . '/../lib/Preview/Office.php',
5656
'OCA\\Richdocuments\\Preview\\OpenDocument' => $baseDir . '/../lib/Preview/OpenDocument.php',
5757
'OCA\\Richdocuments\\Preview\\Pdf' => $baseDir . '/../lib/Preview/Pdf.php',
58+
'OCA\\Richdocuments\\Service\\BaseRemoteService' => $baseDir . '/../lib/Service/BaseRemoteService.php',
5859
'OCA\\Richdocuments\\Service\\CapabilitiesService' => $baseDir . '/../lib/Service/CapabilitiesService.php',
60+
'OCA\\Richdocuments\\Service\\ConnectivityService' => $baseDir . '/../lib/Service/ConnectivityService.php',
5961
'OCA\\Richdocuments\\Service\\DemoService' => $baseDir . '/../lib/Service/DemoService.php',
62+
'OCA\\Richdocuments\\Service\\DiscoveryService' => $baseDir . '/../lib/Service/DiscoveryService.php',
6063
'OCA\\Richdocuments\\Service\\FederationService' => $baseDir . '/../lib/Service/FederationService.php',
6164
'OCA\\Richdocuments\\Service\\FontService' => $baseDir . '/../lib/Service/FontService.php',
6265
'OCA\\Richdocuments\\Service\\InitialStateService' => $baseDir . '/../lib/Service/InitialStateService.php',
@@ -68,6 +71,5 @@
6871
'OCA\\Richdocuments\\Template\\CollaboraTemplateProvider' => $baseDir . '/../lib/Template/CollaboraTemplateProvider.php',
6972
'OCA\\Richdocuments\\TokenManager' => $baseDir . '/../lib/TokenManager.php',
7073
'OCA\\Richdocuments\\UploadException' => $baseDir . '/../lib/UploadException.php',
71-
'OCA\\Richdocuments\\WOPI\\DiscoveryManager' => $baseDir . '/../lib/WOPI/DiscoveryManager.php',
7274
'OCA\\Richdocuments\\WOPI\\Parser' => $baseDir . '/../lib/WOPI/Parser.php',
7375
);

composer/composer/autoload_static.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class ComposerStaticInitRichdocuments
2424
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
2525
'OCA\\Richdocuments\\AppConfig' => __DIR__ . '/..' . '/../lib/AppConfig.php',
2626
'OCA\\Richdocuments\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
27+
'OCA\\Richdocuments\\Backgroundjobs\\CheckConnectivity' => __DIR__ . '/..' . '/../lib/Backgroundjobs/CheckConnectivity.php',
2728
'OCA\\Richdocuments\\Backgroundjobs\\Cleanup' => __DIR__ . '/..' . '/../lib/Backgroundjobs/Cleanup.php',
28-
'OCA\\Richdocuments\\Backgroundjobs\\ObtainCapabilities' => __DIR__ . '/..' . '/../lib/Backgroundjobs/ObtainCapabilities.php',
2929
'OCA\\Richdocuments\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php',
3030
'OCA\\Richdocuments\\Command\\ActivateConfig' => __DIR__ . '/..' . '/../lib/Command/ActivateConfig.php',
3131
'OCA\\Richdocuments\\Command\\ConvertToBigInt' => __DIR__ . '/..' . '/../lib/Command/ConvertToBigInt.php',
@@ -70,8 +70,11 @@ class ComposerStaticInitRichdocuments
7070
'OCA\\Richdocuments\\Preview\\Office' => __DIR__ . '/..' . '/../lib/Preview/Office.php',
7171
'OCA\\Richdocuments\\Preview\\OpenDocument' => __DIR__ . '/..' . '/../lib/Preview/OpenDocument.php',
7272
'OCA\\Richdocuments\\Preview\\Pdf' => __DIR__ . '/..' . '/../lib/Preview/Pdf.php',
73+
'OCA\\Richdocuments\\Service\\BaseRemoteService' => __DIR__ . '/..' . '/../lib/Service/BaseRemoteService.php',
7374
'OCA\\Richdocuments\\Service\\CapabilitiesService' => __DIR__ . '/..' . '/../lib/Service/CapabilitiesService.php',
75+
'OCA\\Richdocuments\\Service\\ConnectivityService' => __DIR__ . '/..' . '/../lib/Service/ConnectivityService.php',
7476
'OCA\\Richdocuments\\Service\\DemoService' => __DIR__ . '/..' . '/../lib/Service/DemoService.php',
77+
'OCA\\Richdocuments\\Service\\DiscoveryService' => __DIR__ . '/..' . '/../lib/Service/DiscoveryService.php',
7578
'OCA\\Richdocuments\\Service\\FederationService' => __DIR__ . '/..' . '/../lib/Service/FederationService.php',
7679
'OCA\\Richdocuments\\Service\\FontService' => __DIR__ . '/..' . '/../lib/Service/FontService.php',
7780
'OCA\\Richdocuments\\Service\\InitialStateService' => __DIR__ . '/..' . '/../lib/Service/InitialStateService.php',
@@ -83,7 +86,6 @@ class ComposerStaticInitRichdocuments
8386
'OCA\\Richdocuments\\Template\\CollaboraTemplateProvider' => __DIR__ . '/..' . '/../lib/Template/CollaboraTemplateProvider.php',
8487
'OCA\\Richdocuments\\TokenManager' => __DIR__ . '/..' . '/../lib/TokenManager.php',
8588
'OCA\\Richdocuments\\UploadException' => __DIR__ . '/..' . '/../lib/UploadException.php',
86-
'OCA\\Richdocuments\\WOPI\\DiscoveryManager' => __DIR__ . '/..' . '/../lib/WOPI/DiscoveryManager.php',
8789
'OCA\\Richdocuments\\WOPI\\Parser' => __DIR__ . '/..' . '/../lib/WOPI/Parser.php',
8890
);
8991

lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
use OCA\Richdocuments\Preview\OpenDocument;
4141
use OCA\Richdocuments\Preview\Pdf;
4242
use OCA\Richdocuments\Service\CapabilitiesService;
43+
use OCA\Richdocuments\Service\DiscoveryService;
4344
use OCA\Richdocuments\Template\CollaboraTemplateProvider;
44-
use OCA\Richdocuments\WOPI\DiscoveryManager;
4545
use OCA\Viewer\Event\LoadViewer;
4646
use OCP\AppFramework\App;
4747
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -198,7 +198,7 @@ public function checkAndEnableCODEServer() {
198198
$appConfig->setAppValue('wopi_url', $new_wopi_url);
199199
$appConfig->setAppValue('disable_certificate_verification', 'yes');
200200

201-
$discoveryManager = $this->getContainer()->query(DiscoveryManager::class);
201+
$discoveryManager = $this->getContainer()->query(DiscoveryService::class);
202202
$capabilitiesService = $this->getContainer()->query(CapabilitiesService::class);
203203

204204
$discoveryManager->refetch();
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323

2424
namespace OCA\Richdocuments\Backgroundjobs;
2525

26-
use OC\BackgroundJob\TimedJob;
27-
use OCA\Richdocuments\Service\CapabilitiesService;
28-
29-
class ObtainCapabilities extends TimedJob {
30-
/** @var CapabilitiesService */
31-
private $capabilitiesService;
32-
33-
public function __construct(CapabilitiesService $capabilitiesService) {
34-
$this->capabilitiesService = $capabilitiesService;
26+
use OCA\Richdocuments\Service\ConnectivityService;
27+
use OCP\AppFramework\Utility\ITimeFactory;
28+
use OCP\BackgroundJob\TimedJob;
3529

30+
class CheckConnectivity extends TimedJob {
31+
public function __construct(
32+
protected ITimeFactory $timeFactory,
33+
protected ConnectivityService $connectivityService
34+
) {
35+
parent::__construct($timeFactory);
3636
$this->setInterval(60 * 60);
3737
}
3838

3939
protected function run($argument) {
40-
$this->capabilitiesService->refetch();
40+
$this->connectivityService->verifyConnection();
4141
}
4242
}

lib/Capabilities.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public function getCapabilities() {
138138
'use_groups' => $this->config->getAppValue('use_groups'),
139139
'doc_format' => $this->config->getAppValue('doc_format'),
140140
'timeout' => $this->config->getAppValue('timeout'),
141-
142141
]
143142
],
144143
];

lib/Command/ActivateConfig.php

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,19 @@
2525
namespace OCA\Richdocuments\Command;
2626

2727
use OCA\Richdocuments\AppConfig;
28-
use OCA\Richdocuments\Service\CapabilitiesService;
29-
use OCA\Richdocuments\WOPI\DiscoveryManager;
28+
use OCA\Richdocuments\Service\ConnectivityService;
3029
use OCA\Richdocuments\WOPI\Parser;
3130
use Symfony\Component\Console\Command\Command;
3231
use Symfony\Component\Console\Input\InputInterface;
3332
use Symfony\Component\Console\Output\OutputInterface;
3433

3534
class ActivateConfig extends Command {
36-
/** @var AppConfig */
37-
private $appConfig;
38-
39-
/** @var CapabilitiesService */
40-
private $capabilitiesService;
41-
42-
/** @var DiscoveryManager */
43-
private $discoveryManager;
44-
45-
/** @var Parser */
46-
private $wopiParser;
47-
48-
public function __construct(AppConfig $appConfig, CapabilitiesService $capabilitiesService, DiscoveryManager $discoveryManager, Parser $wopiParser) {
35+
public function __construct(
36+
private AppConfig $appConfig,
37+
private ConnectivityService $connectivityService,
38+
private Parser $wopiParser
39+
) {
4940
parent::__construct();
50-
51-
$this->appConfig = $appConfig;
52-
$this->capabilitiesService = $capabilitiesService;
53-
$this->discoveryManager = $discoveryManager;
54-
$this->wopiParser = $wopiParser;
5541
}
5642

5743
protected function configure() {
@@ -62,17 +48,13 @@ protected function configure() {
6248

6349
protected function execute(InputInterface $input, OutputInterface $output) {
6450
try {
65-
$this->discoveryManager->refetch();
66-
$this->capabilitiesService->clear();
67-
$capaUrlSrc = $this->wopiParser->getUrlSrc('Capabilities');
68-
if (is_array($capaUrlSrc) && $capaUrlSrc['action'] === 'getinfo') {
69-
$public_wopi_url = str_replace('/hosting/capabilities', '', $capaUrlSrc['urlsrc']);
70-
if ($public_wopi_url !== null) {
71-
$this->appConfig->setAppValue('public_wopi_url', $public_wopi_url);
72-
}
51+
$this->connectivityService->verifyConnection(true);
52+
$publicUrl = $this->wopiParser->getDetectedPublicUrl();
53+
if ($publicUrl) {
54+
$this->appConfig->setAppValue('public_wopi_url', $publicUrl);
55+
$this->connectivityService->verifyConnection(true);
56+
7357
}
74-
$this->capabilitiesService->clear();
75-
$this->capabilitiesService->refetch();
7658
$output->writeln('<info>Activated any config changes</info>');
7759
return 0;
7860
} catch (\Exception $e) {

lib/Controller/SettingsController.php

Lines changed: 35 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@
1515
use \OCP\IL10N;
1616
use \OCP\IRequest;
1717
use OCA\Richdocuments\AppConfig;
18-
use OCA\Richdocuments\Service\CapabilitiesService;
18+
use OCA\Richdocuments\Service\ConnectivityService;
1919
use OCA\Richdocuments\Service\DemoService;
2020
use OCA\Richdocuments\Service\FontService;
2121
use OCA\Richdocuments\UploadException;
22-
use OCA\Richdocuments\WOPI\DiscoveryManager;
2322
use OCA\Richdocuments\WOPI\Parser;
2423
use OCP\AppFramework\Http;
2524
use OCP\AppFramework\Http\DataDisplayResponse;
2625
use OCP\AppFramework\Http\DataResponse;
2726
use OCP\AppFramework\Http\JSONResponse;
28-
use OCP\AppFramework\Http\NotFoundResponse;
2927
use OCP\Files\NotFoundException;
3028
use OCP\Files\NotPermittedException;
3129
use OCP\Files\SimpleFS\ISimpleFile;
3230
use OCP\IConfig;
33-
use OCP\ILogger;
3431
use OCP\PreConditionNotMetException;
3532
use OCP\Util;
33+
use Psr\Log\LoggerInterface;
3634

3735
class SettingsController extends Controller {
3836
// TODO adapt overview generation if we add more font mimetypes
@@ -44,81 +42,37 @@ class SettingsController extends Controller {
4442
'application/vnd.oasis.opendocument.formula-template',
4543
];
4644

47-
/** @var IL10N */
48-
private $l10n;
49-
/** @var AppConfig */
50-
private $appConfig;
51-
/** @var IConfig */
52-
private $config;
53-
/** @var DiscoveryManager */
54-
private $discoveryManager;
55-
/** @var Parser */
56-
private $wopiParser;
57-
/** @var string */
58-
private $userId;
59-
/** @var CapabilitiesService */
60-
private $capabilitiesService;
61-
/** @var DemoService */
62-
private $demoService;
63-
/** @var ILogger */
64-
private $logger;
65-
/**
66-
* @var FontService
67-
*/
68-
private $fontService;
69-
70-
public function __construct($appName,
45+
public function __construct(
46+
string $appName,
7147
IRequest $request,
72-
IL10N $l10n,
73-
AppConfig $appConfig,
74-
IConfig $config,
75-
DiscoveryManager $discoveryManager,
76-
Parser $wopiParser,
77-
CapabilitiesService $capabilitiesService,
78-
DemoService $demoService,
79-
FontService $fontService,
80-
ILogger $logger,
81-
$userId
48+
private IL10N $l10n,
49+
private AppConfig $appConfig,
50+
private IConfig $config,
51+
private ConnectivityService $connectivityService,
52+
private Parser $wopiParser,
53+
private DemoService $demoService,
54+
private FontService $fontService,
55+
private LoggerInterface $logger,
56+
private ?string $userId
8257
) {
8358
parent::__construct($appName, $request);
84-
$this->l10n = $l10n;
85-
$this->appConfig = $appConfig;
86-
$this->config = $config;
87-
$this->discoveryManager = $discoveryManager;
88-
$this->wopiParser = $wopiParser;
89-
$this->capabilitiesService = $capabilitiesService;
90-
$this->demoService = $demoService;
91-
$this->logger = $logger;
92-
$this->userId = $userId;
93-
$this->fontService = $fontService;
94-
$this->request = $request;
9559
}
9660

9761
/**
9862
* @PublicPage
9963
* @NoCSRFRequired
100-
* @throws \Exception
10164
*/
102-
public function checkSettings() {
103-
try {
104-
$response = $this->discoveryManager->fetchFromRemote();
105-
} catch (\Exception $e) {
106-
$this->logger->logException($e, ['app' => 'richdocuments']);
107-
return new DataResponse([
108-
'status' => $e->getCode(),
109-
'message' => 'Could not fetch discovery details'
110-
], Http::STATUS_INTERNAL_SERVER_ERROR);
111-
}
112-
113-
return new DataResponse();
65+
public function checkSettings(): DataResponse {
66+
$this->connectivityService->verifyConnection();
67+
return new DataResponse($this->connectivityService->getStatus());
11468
}
11569

116-
public function demoServers() {
70+
public function demoServers(): DataResponse {
11771
$demoServers = $this->demoService->fetchDemoServers(true);
11872
if (count($demoServers) > 0) {
11973
return new DataResponse($demoServers);
12074
}
121-
return new NotFoundResponse([]);
75+
return new DataResponse([], Http::STATUS_NOT_FOUND);
12276
}
12377

12478
/**
@@ -193,44 +147,31 @@ public function setSettings($wopi_url,
193147
$this->appConfig->setAppValue('canonical_webroot', $canonical_webroot);
194148
}
195149

196-
$this->discoveryManager->refetch();
197-
$this->capabilitiesService->clear();
198-
try {
199-
$capaUrlSrc = $this->wopiParser->getUrlSrc('Capabilities');
200-
if (is_array($capaUrlSrc) && $capaUrlSrc['action'] === 'getinfo') {
201-
$public_wopi_url = str_replace('/hosting/capabilities', '', $capaUrlSrc['urlsrc']);
202-
if ($public_wopi_url !== null) {
203-
$this->appConfig->setAppValue('public_wopi_url', $public_wopi_url);
204-
$colon = strpos($public_wopi_url, ':', 0);
205-
if ($this->request->getServerProtocol() !== substr($public_wopi_url, 0, $colon)) {
206-
$message = $this->l10n->t('Saved with error: Collabora Online should expose the same protocol as the server installation. Please check the ssl.enable and ssl.termination settings of your Collabora Online server.');
207-
}
208-
}
209-
}
210-
} catch (\Exception $e) {
211-
if ($wopi_url !== null) {
212-
return new JSONResponse([
213-
'status' => 'error',
214-
'data' => ['message' => 'Failed to connect to the remote server']
215-
], 500);
216-
}
150+
$this->connectivityService->verifyConnection(true);
151+
152+
$publicUrl = $this->wopiParser->getDetectedPublicUrl();
153+
if ($publicUrl) {
154+
$this->appConfig->setAppValue('public_wopi_url', $publicUrl);
155+
$this->connectivityService->verifyConnection(true);
217156
}
218157

219-
$this->capabilitiesService->clear();
220-
$this->capabilitiesService->refetch();
221-
if ($this->capabilitiesService->getCapabilities() === []) {
158+
if (!$this->connectivityService->isDiscoveryReachable()) {
222159
return new JSONResponse([
223160
'status' => 'error',
224-
'data' => ['message' => 'Failed to connect to the remote server', 'hint' => 'missing_capabilities']
161+
'data' => [
162+
'message' => 'Failed to connect to the remote server',
163+
'status' => $this->connectivityService->getStatus(),]
225164
], 500);
226165
}
227166

228-
$response = [
167+
return new JSONResponse([
229168
'status' => 'success',
230-
'data' => ['message' => $message]
231-
];
232-
233-
return new JSONResponse($response);
169+
'data' => [
170+
'discovery' => $this->wopiParser->getUrlSrc('application/vnd.oasis.opendocument.text')['urlsrc'],
171+
'message' => $message,
172+
'status' => $this->connectivityService->getStatus(),
173+
]
174+
]);
234175
}
235176

236177
public function updateWatermarkSettings($settings = []) {

lib/Listener/CSPListener.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public function handle(Event $event): void {
7171
$policy->addAllowedFrameDomain("'self'");
7272
$policy->addAllowedFrameDomain("nc:");
7373

74+
if ($this->isSettingsPage()) {
75+
// Allow the admin page settings to request the entered endpoint for checking connectivity
76+
$policy->addAllowedConnectDomain("*");
77+
}
78+
7479
foreach ($urls as $url) {
7580
$policy->addAllowedFrameDomain($url);
7681
$policy->addAllowedFormActionDomain($url);
@@ -86,6 +91,10 @@ private function isPageLoad(): bool {
8691
return end($scriptNameParts) === 'index.php';
8792
}
8893

94+
private function isSettingsPage(): bool {
95+
return str_starts_with($this->request->getPathInfo(), '/settings/admin/richdocuments');
96+
}
97+
8998
private function getFederationDomains(): array {
9099
if (!$this->appManager->isEnabledForUser('federation')) {
91100
return [];

0 commit comments

Comments
 (0)