summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2018-12-03 11:04:25 +0100
committerJulius Härtl <jus@bitgrid.net>2018-12-03 11:08:15 +0100
commitbb100ea8790389d3d1d7383083dd05c0cf2ccfdb (patch)
tree752a11a890736265553a40cd1a98ed1ac6c3d1d4
parenta89dc2819eeb6fb326934552954ca47e1cc61c6f (diff)
Add setup check for .well-known urls
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--lib/Controller/NavigationController.php72
-rw-r--r--lib/Service/CheckService.php92
-rw-r--r--src/App.vue19
3 files changed, 140 insertions, 43 deletions
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index 223f633f..f4c569fb 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -40,9 +40,11 @@ use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Service\ActivityPub\DocumentService;
use OCA\Social\Service\ActivityPub\PersonService;
use OCA\Social\Service\ActorService;
+use OCA\Social\Service\CheckService;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
@@ -70,9 +72,6 @@ class NavigationController extends Controller {
/** @var IURLGenerator */
private $urlGenerator;
- /** @var IClientService */
- private $clientService;
-
/** @var ActorService */
private $actorService;
@@ -90,6 +89,9 @@ class NavigationController extends Controller {
/** @var PersonService */
private $personService;
+ /** @var CheckService */
+ private $checkService;
+
/**
* NavigationController constructor.
*
@@ -97,18 +99,18 @@ class NavigationController extends Controller {
* @param string $userId
* @param IConfig $config
* @param IURLGenerator $urlGenerator
- * @param IClientService $clientService
* @param ActorService $actorService
* @param DocumentService $documentService
* @param ConfigService $configService
* @param PersonService $personService
+ * @param CheckService $checkService
* @param MiscService $miscService
* @param IL10N $l10n
*/
public function __construct(
- IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator, IClientService $clientService,
+ IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator,
ActorService $actorService, DocumentService $documentService, ConfigService $configService,
- PersonService $personService,
+ PersonService $personService, CheckService $checkService,
MiscService $miscService, IL10N $l10n
) {
parent::__construct(Application::APP_NAME, $request);
@@ -116,7 +118,7 @@ class NavigationController extends Controller {
$this->userId = $userId;
$this->config = $config;
$this->urlGenerator = $urlGenerator;
- $this->clientService = $clientService;
+ $this->checkService = $checkService;
$this->actorService = $actorService;
$this->documentService = $documentService;
@@ -144,50 +146,40 @@ class NavigationController extends Controller {
'public' => false,
'firstrun' => false,
'setup' => false,
+ 'isAdmin' => \OC::$server->getGroupManager()->isAdmin($this->userId),
+ 'cliUrl' => $this->config->getSystemValue(
+ 'overwrite.cli.url', \OC::$server->getURLGenerator()
+ ->getBaseUrl()
+ )
]
];
+ $checks = $this->checkService->checkDefault();
+ $data['serverData']['checks'] = $checks;
+
try {
$data['serverData']['cloudAddress'] = $this->configService->getCloudAddress();
} catch (SocialAppConfigException $e) {
- $cloudAddress = rtrim(
- $this->config->getSystemValue('overwrite.cli.url', ''), '/'
- );
- $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
+ $cloudAddress = $this->setupCloudAddress();
if ($cloudAddress !== ''){
- if (!$frontControllerActive){
- $cloudAddress .= '/index.php';
- }
- $this->configService->setCloudAddress($cloudAddress);
$data['serverData']['cloudAddress'] = $cloudAddress;
} else {
$data['serverData']['setup'] = true;
- $data['serverData']['isAdmin'] = \OC::$server->getGroupManager()
- ->isAdmin($this->userId);
+
if ($data['serverData']['isAdmin']) {
$cloudAddress = $this->request->getParam('cloudAddress');
if ($cloudAddress !== null) {
$this->configService->setCloudAddress($cloudAddress);
} else {
- $data['serverData']['cliUrl'] = $this->config->getSystemValue(
- 'overwrite.cli.url', \OC::$server->getURLGenerator()
- ->getBaseUrl()
- );
-
return new TemplateResponse(Application::APP_NAME, 'main', $data);
}
}
}
}
- try {
- $url = $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . '/.well-known/webfinger';
- $response = $this->clientService->newClient()->get($url);
- } catch (\GuzzleHttp\Exception\ClientException $e) {
- $data['serverData']['error'] = $this->l10n->t('.well-known/webfinger isn\'t properly set up');
- $data['serverData']['setup'] = true;
- }
-
+ /*
+ * Create social user account if it doesn't exist yet
+ */
try {
$this->actorService->createActor($this->userId, $this->userId);
$data['serverData']['firstrun'] = true;
@@ -199,13 +191,23 @@ class NavigationController extends Controller {
// neither.
}
- $csp = new ContentSecurityPolicy();
- $csp->addAllowedImageDomain('*');
- $response = new TemplateResponse(Application::APP_NAME, 'main', $data);
- $response->setContentSecurityPolicy($csp);
- return $response;
+ return new TemplateResponse(Application::APP_NAME, 'main', $data);
}
+ private function setupCloudAddress(): string {
+ return '';
+ $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
+
+ $cloudAddress = rtrim($this->config->getSystemValue('overwrite.cli.url', ''), '/');
+ if ($cloudAddress !== '') {
+ if (!$frontControllerActive) {
+ $cloudAddress .= '/index.php';
+ }
+ $this->configService->setCloudAddress($cloudAddress);
+ return $cloudAddress;
+ }
+ return '';
+ }
/**
* Display the navigation page of the Social app.
diff --git a/lib/Service/CheckService.php b/lib/Service/CheckService.php
new file mode 100644
index 00000000..9c5ba7c3
--- /dev/null
+++ b/lib/Service/CheckService.php
@@ -0,0 +1,92 @@
+<?php
+/**
+ * @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Social\Service;
+
+
+use OCP\AppFramework\Http;
+use OCP\Http\Client\IClientService;
+use OCP\ICache;
+use OCP\IConfig;
+use OCP\IRequest;
+
+class CheckService {
+
+ private $cache;
+ private $config;
+
+ const CACHE_PREFIX = 'social_check_';
+
+
+ public function __construct(ICache $cache, IConfig $config, IClientService $clientService, IRequest $request) {
+ $this->cache = $cache;
+ $this->config = $config;
+ $this->clientService = $clientService;
+ $this->request = $request;
+ }
+
+ public function checkDefault(): array {
+ $checks = [];
+ $checks['wellknown'] = $this->checkWellKnown();
+
+ $success = true;
+ foreach ($checks as $check) {
+ if (!$check) {
+ $success = false;
+ }
+ }
+ return [
+ 'success' => $success,
+ 'checks' => $checks
+ ];
+ }
+ public function checkWellKnown(): bool {
+ $state = (bool) ($this->cache->get(self::CACHE_PREFIX . 'wellknown') === 'true');
+ if ($state === true) {
+ return true;
+ }
+ try {
+ $url = $this->request->getServerProtocol() . '://' . $this->request->getServerHost() . '/.well-known/webfinger';
+ $response = $this->clientService->newClient()->get($url);
+ if ($response->getStatusCode() === Http::STATUS_OK) {
+ $this->cache->set(self::CACHE_PREFIX . 'wellknown', 'true', 3600);
+ return true;
+ }
+ } catch (\GuzzleHttp\Exception\ClientException $e) {
+ } catch (\Exception $e) {
+ }
+
+ try {
+ $url = \OC::$server->getURLGenerator()->getBaseUrl() . '/.well-known/webfinger';
+ $response = $this->clientService->newClient()->get($url);
+ if ($response->getStatusCode() === Http::STATUS_OK) {
+ $this->cache->set(self::CACHE_PREFIX . 'wellknown', 'true', 3600);
+ return true;
+ }
+ } catch (\GuzzleHttp\Exception\ClientException $e) {
+ } catch (\Exception $e) {
+ }
+ return false;
+ }
+
+}
diff --git a/src/App.vue b/src/App.vue
index 299d4c2e..56a362fc 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -4,10 +4,13 @@
<app-navigation :menu="menu" />
</div>
<div id="app-content">
- <div class="social__wrapper">
- <Search v-if="searchTerm != ''" :term="searchTerm" />
- <router-view v-if="searchTerm === ''" :key="$route.fullPath" />
+ <div v-if="serverData.isAdmin && !serverData.checks.success" class="setup">
+ <h3 v-if="!serverData.checks.checks.wellknown">{{ t('social', '.well-known/webfinger isn\'t properly set up!') }}</h3>
+ <p v-if="!serverData.checks.checks.wellknown">{{ t('social', 'Social needs the .well-known auto discovery to be properly set up. If Nextcloud is not installed in the root of the domain it is often the case, that Nextcloud can\'t configure this automatically. To use Social the admin of this Nextcloud instance needs to manually configure the .well-known redirects: ') }}<a class="external_link" href="https://docs.nextcloud.com/server/15/go.php?to=admin-setup-well-known-URL" target="_blank"
+ rel="noreferrer noopener">{{ t('social', 'Open Documentation') }} ↗</a></p>
</div>
+ <Search v-if="searchTerm != ''" :term="searchTerm" />
+ <router-view v-if="searchTerm === ''" :key="$route.fullPath" />
</div>
</div>
<div v-else class="setup">
@@ -21,13 +24,13 @@
required>
<input :value="t('social', 'Finish setup')" type="submit" class="primary">
</p>
+ <template v-if="!serverData.checks.success">
+ <h3 v-if="!serverData.checks.checks.wellknown">{{ t('social', '.well-known/webfinger isn\'t properly set up!') }}</h3>
+ <p v-if="!serverData.checks.checks.wellknown">{{ t('social', 'Social needs the .well-known auto discovery to be properly set up. If Nextcloud is not installed in the root of the domain it is often the case, that Nextcloud can\'t configure this automatically. To use Social the admin of this Nextcloud instance needs to manually configure the .well-known redirects: ') }}<a class="external_link" href="https://docs.nextcloud.com/server/15/go.php?to=admin-setup-well-known-URL" target="_blank"
+ rel="noreferrer noopener">{{ t('social', 'Open Documentation') }} ↗</a></p>
+ </template>
</form>
</template>
- <template v-else-if="serverData.error">
- <h2>{{ t('social', 'Social app setup') }}</h2>
- <p>{{ t('social', '.well-known/webfinger isn\'t properly set up!') }}</p>
- <p>{{ t('social', 'Social needs the .well-known auto discovery to be properly set up. If Nextcloud is not installed in the root of the domain it is often the case, that Nextcloud can\'t configure this automatically. To use Social the admin of this Nextcloud instance needs to manually configure the .well-known redirects: ') }}<a class="external_link" href="https://docs.nextcloud.com/server/15/go.php?to=admin-setup-well-known-URL" target="_blank" rel="noreferrer noopener">{{ t('social', 'Open Documentation') }} ↗</a></p>
- </template>
<template v-else>
<p>{{ t('social', 'The social app requires to be setup by the server administrator.') }}</p>
</template>