From 21e4fa495aefc98031026fd5dda7e733cdbe83a4 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 7 Jun 2021 13:46:04 +0200 Subject: [PATCH 1/4] Add index route for the OC10 integration --- changelog/unreleased/bugfix-oc10-index-route | 8 ++ .../lib/Controller/IndexController.php | 92 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 changelog/unreleased/bugfix-oc10-index-route create mode 100644 packages/web-integration-oc10/lib/Controller/IndexController.php diff --git a/changelog/unreleased/bugfix-oc10-index-route b/changelog/unreleased/bugfix-oc10-index-route new file mode 100644 index 00000000000..0f223e8fb87 --- /dev/null +++ b/changelog/unreleased/bugfix-oc10-index-route @@ -0,0 +1,8 @@ +Bugfix: Add index route for the OC10 integration + +Added an index route for the OC10 integration which gets called when opening http://your-server/index.php/apps/web. +The route basically redirects to the same URL while appending /index.html, as this is the correct URL for +accessing the Web UI. Setting Web as default layout would result in an endless redirect loop otherwise. + +https://github.com/owncloud/web/pull/5112 +https://github.com/owncloud/core/issues/38799 diff --git a/packages/web-integration-oc10/lib/Controller/IndexController.php b/packages/web-integration-oc10/lib/Controller/IndexController.php new file mode 100644 index 00000000000..b6a46087161 --- /dev/null +++ b/packages/web-integration-oc10/lib/Controller/IndexController.php @@ -0,0 +1,92 @@ + + * @author Jan Ackermann + * + * @copyright Copyright (c) 2021, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ + +namespace OCA\Web\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\Response; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IL10N; +use OCP\IRequest; + +/** + * Class IndexController + * + * @package OCA\Web\Controller + */ +class IndexController extends Controller { + + /** + * @var IConfig + */ + private $config; + /** + * @var IL10N + */ + private $l10n; + + /** + * IndexController constructor. + * + * @param string $appName + * @param IRequest $request + * @param IConfig $config + * @param IL10N $l10n + */ + public function __construct(string $appName, IRequest $request, IConfig $config, IL10N $l10n) { + parent::__construct($appName, $request); + $this->config = $config; + $this->l10n = $l10n; + } + + /** + * Loads the WebUI index page according to the web.baseUrl config. + * Then appends "/index.html" to the URL as this is needed to load the page properly. + * + * @PublicPage + * @NoCSRFRequired + * + * @return RedirectResponse | TemplateResponse + */ + public function index(): Response { + $webBaseUrl = $this->config->getSystemValue('web.baseUrl', null); + if (!$webBaseUrl) { + // Check the old phoenix.baseUrl system key to provide compatibility across + // the name change from phoenix to web. + $webBaseUrl = \OC::$server->getConfig()->getSystemValue('phoenix.baseUrl', null); + } + + if ($webBaseUrl) { + $webBaseUrl = \rtrim($webBaseUrl, '/') . '/index.html'; + return new RedirectResponse($webBaseUrl); + } + + return new TemplateResponse( + 'core', 'error', + [ + "errors" => [["error" => $this->l10n->t('Unable to reach the WebURL. Please contact your administrator.')]] + ], 'guest' + ); + } +} From 1827bae49f80a5a0d341f8e15e16b64c68fd0abc Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Mon, 7 Jun 2021 13:48:01 +0200 Subject: [PATCH 2/4] Fix PR link in changelog --- changelog/unreleased/bugfix-oc10-index-route | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/unreleased/bugfix-oc10-index-route b/changelog/unreleased/bugfix-oc10-index-route index 0f223e8fb87..42a53961e06 100644 --- a/changelog/unreleased/bugfix-oc10-index-route +++ b/changelog/unreleased/bugfix-oc10-index-route @@ -4,5 +4,5 @@ Added an index route for the OC10 integration which gets called when opening htt The route basically redirects to the same URL while appending /index.html, as this is the correct URL for accessing the Web UI. Setting Web as default layout would result in an endless redirect loop otherwise. -https://github.com/owncloud/web/pull/5112 +https://github.com/owncloud/web/pull/5201 https://github.com/owncloud/core/issues/38799 From fddc56666bd12c1875819190c1d3e63e71cc0b30 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Tue, 8 Jun 2021 08:25:01 +0200 Subject: [PATCH 3/4] Add route --- packages/web-integration-oc10/appinfo/routes.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web-integration-oc10/appinfo/routes.php b/packages/web-integration-oc10/appinfo/routes.php index 7e45ea9aeef..4fd3ff3eae3 100644 --- a/packages/web-integration-oc10/appinfo/routes.php +++ b/packages/web-integration-oc10/appinfo/routes.php @@ -26,6 +26,7 @@ $this, [ 'routes' => [ + ['name' => 'Index#index', 'url' => '/', 'verb' => 'GET'], ['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'], [ 'name' => 'Files#getFile', From 86d5137b073bfca010e4c0ed6ff0c7a4feb664b6 Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Tue, 8 Jun 2021 08:28:28 +0200 Subject: [PATCH 4/4] Fix line indent --- packages/web-integration-oc10/appinfo/routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web-integration-oc10/appinfo/routes.php b/packages/web-integration-oc10/appinfo/routes.php index 4fd3ff3eae3..b64b62ae9f0 100644 --- a/packages/web-integration-oc10/appinfo/routes.php +++ b/packages/web-integration-oc10/appinfo/routes.php @@ -27,7 +27,7 @@ [ 'routes' => [ ['name' => 'Index#index', 'url' => '/', 'verb' => 'GET'], - ['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'], + ['name' => 'Config#getConfig', 'url' => '/config.json', 'verb' => 'GET'], [ 'name' => 'Files#getFile', 'url' => '/{path}',