From a89dc2819eeb6fb326934552954ca47e1cc61c6f Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Fri, 30 Nov 2018 09:51:48 +0100 Subject: [PATCH 1/5] add check for .well-known/webfinger Signed-off-by: Jonas Sulzer --- lib/Controller/NavigationController.php | 17 +++++++++++++++-- src/App.vue | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 0911b12f..223f633f 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -52,6 +52,7 @@ use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use OCP\IURLGenerator; +use OCP\Http\Client\IClientService; class NavigationController extends Controller { @@ -69,6 +70,9 @@ class NavigationController extends Controller { /** @var IURLGenerator */ private $urlGenerator; + /** @var IClientService */ + private $clientService; + /** @var ActorService */ private $actorService; @@ -93,6 +97,7 @@ 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 @@ -101,7 +106,7 @@ class NavigationController extends Controller { * @param IL10N $l10n */ public function __construct( - IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator, + IRequest $request, $userId, IConfig $config, IURLGenerator $urlGenerator, IClientService $clientService, ActorService $actorService, DocumentService $documentService, ConfigService $configService, PersonService $personService, MiscService $miscService, IL10N $l10n @@ -111,6 +116,7 @@ class NavigationController extends Controller { $this->userId = $userId; $this->config = $config; $this->urlGenerator = $urlGenerator; + $this->clientService = $clientService; $this->actorService = $actorService; $this->documentService = $documentService; @@ -174,6 +180,14 @@ class NavigationController extends Controller { } } + 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; + } + try { $this->actorService->createActor($this->userId, $this->userId); $data['serverData']['firstrun'] = true; @@ -301,4 +315,3 @@ class NavigationController extends Controller { } } - diff --git a/src/App.vue b/src/App.vue index c7c9355b..299d4c2e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -23,6 +23,11 @@

+ @@ -57,6 +62,9 @@ #social-spacer a:focus { border: none !important; } + a.external_link { + text-decoration: underline; + } From bb100ea8790389d3d1d7383083dd05c0cf2ccfdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 3 Dec 2018 11:04:25 +0100 Subject: [PATCH 2/5] Add setup check for .well-known urls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/NavigationController.php | 72 +++++++++---------- lib/Service/CheckService.php | 92 +++++++++++++++++++++++++ src/App.vue | 19 ++--- 3 files changed, 140 insertions(+), 43 deletions(-) create mode 100644 lib/Service/CheckService.php 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 @@ + + * + * @author Julius Härtl + * + * @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 . + * + */ + +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 @@
-
@@ -21,13 +24,13 @@ required>

+ - From 03d02594603b0b42a405a9ca586641c22225feeb Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Mon, 3 Dec 2018 12:27:55 +0100 Subject: [PATCH 3/5] Small wording fixes on the initial setup page Signed-off-by: Jan-Christoph Borchardt --- src/App.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index 56a362fc..029bbae2 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,8 +6,8 @@

{{ t('social', '.well-known/webfinger isn\'t properly set up!') }}

-

{{ 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: ') }}{{ t('social', 'Open Documentation') }} ↗

+

{{ t('social', 'Social needs the .well-known automatic 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: ') }}{{ t('social', 'Open documentation') }} ↗

@@ -16,7 +16,7 @@
From 0f69a61a098acd09acc6468e3ca52f6c6a0b5c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 3 Dec 2018 12:10:03 +0100 Subject: [PATCH 4/5] Check for configured base URL as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/NavigationController.php | 15 +++++++---- lib/Service/CheckService.php | 35 +++++++++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index f4c569fb..d6396122 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -147,10 +147,7 @@ class NavigationController extends Controller { 'firstrun' => false, 'setup' => false, 'isAdmin' => \OC::$server->getGroupManager()->isAdmin($this->userId), - 'cliUrl' => $this->config->getSystemValue( - 'overwrite.cli.url', \OC::$server->getURLGenerator() - ->getBaseUrl() - ) + 'cliUrl' => $this->getCliUrl() ] ]; @@ -195,7 +192,6 @@ class NavigationController extends Controller { } 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', ''), '/'); @@ -209,6 +205,15 @@ class NavigationController extends Controller { return ''; } + private function getCliUrl() { + $url = rtrim($this->urlGenerator->getBaseUrl(), '/'); + $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); + if (!$frontControllerActive) { + $url .= '/index.php'; + } + return $url; + } + /** * Display the navigation page of the Social app. * diff --git a/lib/Service/CheckService.php b/lib/Service/CheckService.php index 9c5ba7c3..dea98418 100644 --- a/lib/Service/CheckService.php +++ b/lib/Service/CheckService.php @@ -29,20 +29,25 @@ use OCP\Http\Client\IClientService; use OCP\ICache; use OCP\IConfig; use OCP\IRequest; +use OCP\IURLGenerator; class CheckService { private $cache; private $config; + private $clientService; + private $request; + private $urlGenerator; const CACHE_PREFIX = 'social_check_'; - public function __construct(ICache $cache, IConfig $config, IClientService $clientService, IRequest $request) { + public function __construct(ICache $cache, IConfig $config, IClientService $clientService, IRequest $request, IURLGenerator $urlGenerator) { $this->cache = $cache; $this->config = $config; $this->clientService = $clientService; $this->request = $request; + $this->urlGenerator = $urlGenerator; } public function checkDefault(): array { @@ -65,19 +70,27 @@ class CheckService { 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) { + + $address = $this->config->getAppValue('social', 'address', ''); + + if ($address !== '' && $this->requestWellKnown($address)) { + return true; } + if ($this->requestWellKnown($this->request->getServerProtocol() . '://' . $this->request->getServerHost())) { + return true; + } + + if ($this->requestWellKnown($this->urlGenerator->getBaseUrl())) { + return true; + } + + return false; + } + + private function requestWellKnown($base) { try { - $url = \OC::$server->getURLGenerator()->getBaseUrl() . '/.well-known/webfinger'; + $url = $base . '/.well-known/webfinger'; $response = $this->clientService->newClient()->get($url); if ($response->getStatusCode() === Http::STATUS_OK) { $this->cache->set(self::CACHE_PREFIX . 'wellknown', 'true', 3600); From 339ee9cffc4ce734860cd2e840a12821cc79990d Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Mon, 3 Dec 2018 13:28:19 +0100 Subject: [PATCH 5/5] Fix wording on setup screen Signed-off-by: Jan-Christoph Borchardt --- src/App.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 029bbae2..5108225b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -16,7 +16,7 @@