From 0d5142be7080fba001d74609676e7e1ddd5b547f Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 17 Apr 2018 17:47:11 +0200 Subject: Show a link to the docs instead of a button on the untrusted domain page Before there was a button to "quickly" add the untrusted domain to the config. This button often didn't worked, because the generated URL was often untrusted as well. Thus removing it and providing proper docs seems to be the better approach to handle this rare case. Also the log should not be spammed by messages for the untrusted domain accesses, because they are user related and not necessarily an administrative issue. Signed-off-by: Morris Jobke --- core/templates/untrustedDomain.php | 8 +-- lib/base.php | 4 +- lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - settings/Controller/SecuritySettingsController.php | 72 ---------------------- settings/js/admin.js | 25 -------- settings/routes.php | 1 - tests/Settings/ApplicationTest.php | 2 - .../Controller/SecuritySettingsControllerTest.php | 72 ---------------------- 9 files changed, 4 insertions(+), 182 deletions(-) delete mode 100644 settings/Controller/SecuritySettingsController.php delete mode 100644 tests/Settings/Controller/SecuritySettingsControllerTest.php diff --git a/core/templates/untrustedDomain.php b/core/templates/untrustedDomain.php index 297220c92bb..1443c412821 100644 --- a/core/templates/untrustedDomain.php +++ b/core/templates/untrustedDomain.php @@ -6,12 +6,8 @@

t('Please contact your administrator. If you are an administrator, edit the "trusted_domains" setting in config/config.php like the example in config.sample.php.')); ?>

+

- t('Depending on your configuration, this button could also work to trust the domain:')); ?> -

-

- - t('Add "%s" as trusted domain', array($_['domain']))); ?> - + t('Further information how to configure this can be found in the %sdocumentation%s.', ['', ''])); ?>

diff --git a/lib/base.php b/lib/base.php index fa2f5011f16..f3e2e734d0d 100644 --- a/lib/base.php +++ b/lib/base.php @@ -778,7 +778,7 @@ class OC { OC_Response::setStatus(\OC_Response::STATUS_BAD_REQUEST); header('Status: 400 Bad Request'); - \OC::$server->getLogger()->warning( + \OC::$server->getLogger()->info( 'Trusted domain error. "{remoteAddress}" tried to access using "{host}" as host.', [ 'app' => 'core', @@ -788,7 +788,7 @@ class OC { ); $tmpl = new OCP\Template('core', 'untrustedDomain', 'guest'); - $tmpl->assign('domain', $host); + $tmpl->assign('docUrl', \OC::$server->getURLGenerator()->linkToDocs('admin-trusted-domains')); $tmpl->printPage(); exit(); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 58f4a15dbd6..d6475f4a04a 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -897,7 +897,6 @@ return array( 'OC\\Settings\\Controller\\LogSettingsController' => $baseDir . '/settings/Controller/LogSettingsController.php', 'OC\\Settings\\Controller\\MailSettingsController' => $baseDir . '/settings/Controller/MailSettingsController.php', 'OC\\Settings\\Controller\\PersonalSettingsController' => $baseDir . '/settings/Controller/PersonalSettingsController.php', - 'OC\\Settings\\Controller\\SecuritySettingsController' => $baseDir . '/settings/Controller/SecuritySettingsController.php', 'OC\\Settings\\Controller\\UsersController' => $baseDir . '/settings/Controller/UsersController.php', 'OC\\Settings\\Hooks' => $baseDir . '/settings/Hooks.php', 'OC\\Settings\\Mailer\\NewUserMailHelper' => $baseDir . '/settings/Mailer/NewUserMailHelper.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index b0c04eea220..2b80a4703c7 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -927,7 +927,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Settings\\Controller\\LogSettingsController' => __DIR__ . '/../../..' . '/settings/Controller/LogSettingsController.php', 'OC\\Settings\\Controller\\MailSettingsController' => __DIR__ . '/../../..' . '/settings/Controller/MailSettingsController.php', 'OC\\Settings\\Controller\\PersonalSettingsController' => __DIR__ . '/../../..' . '/settings/Controller/PersonalSettingsController.php', - 'OC\\Settings\\Controller\\SecuritySettingsController' => __DIR__ . '/../../..' . '/settings/Controller/SecuritySettingsController.php', 'OC\\Settings\\Controller\\UsersController' => __DIR__ . '/../../..' . '/settings/Controller/UsersController.php', 'OC\\Settings\\Hooks' => __DIR__ . '/../../..' . '/settings/Hooks.php', 'OC\\Settings\\Mailer\\NewUserMailHelper' => __DIR__ . '/../../..' . '/settings/Mailer/NewUserMailHelper.php', diff --git a/settings/Controller/SecuritySettingsController.php b/settings/Controller/SecuritySettingsController.php deleted file mode 100644 index bda86dff841..00000000000 --- a/settings/Controller/SecuritySettingsController.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @author Morris Jobke - * @author Roeland Jago Douma - * - * @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 OC\Settings\Controller; - -use \OCP\AppFramework\Controller; -use OCP\IRequest; -use OCP\IConfig; - -/** - * @package OC\Settings\Controller - */ -class SecuritySettingsController extends Controller { - /** @var \OCP\IConfig */ - private $config; - - /** - * @param string $appName - * @param IRequest $request - * @param IConfig $config - */ - public function __construct($appName, - IRequest $request, - IConfig $config) { - parent::__construct($appName, $request); - $this->config = $config; - } - - /** - * @return array - */ - protected function returnSuccess() { - return array( - 'status' => 'success' - ); - } - - /** - * Add a new trusted domain - * @param string $newTrustedDomain The newly to add trusted domain - * @return array - */ - public function trustedDomains($newTrustedDomain) { - $trustedDomains = $this->config->getSystemValue('trusted_domains', []); - $trustedDomains[] = $newTrustedDomain; - $this->config->setSystemValue('trusted_domains', $trustedDomains); - - return $this->returnSuccess(); - } - -} diff --git a/settings/js/admin.js b/settings/js/admin.js index f637cb64592..650bc84930c 100644 --- a/settings/js/admin.js +++ b/settings/js/admin.js @@ -1,29 +1,4 @@ $(document).ready(function(){ - var params = OC.Util.History.parseUrlQuery(); - - // Hack to add a trusted domain - if (params.trustDomain) { - var potentialDomain = params.trustDomain; - potentialDomain = encodeURI(escapeHTML(potentialDomain)); - potentialDomain = '' + potentialDomain + ''; - - OC.dialogs.confirmHtml(t('settings', 'Are you really sure you want add {domain} as trusted domain?', { - domain: potentialDomain - }, undefined, {escape: false}), - t('settings', 'Add trusted domain'), function(answer) { - if(answer) { - $.ajax({ - type: 'POST', - url: OC.generateUrl('settings/admin/security/trustedDomains'), - data: { newTrustedDomain: params.trustDomain } - }).done(function() { - window.location.replace(OC.generateUrl('settings/admin')); - }); - } - }); - } - - $('#excludedGroups').each(function (index, element) { OC.Settings.setupGroupsSelect($(element)); $(element).change(function(ev) { diff --git a/settings/routes.php b/settings/routes.php index df49f0af859..9a89d7353ef 100644 --- a/settings/routes.php +++ b/settings/routes.php @@ -50,7 +50,6 @@ $application->registerRoutes($this, [ ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], - ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], diff --git a/tests/Settings/ApplicationTest.php b/tests/Settings/ApplicationTest.php index 8346f668d9d..31391a8fac6 100644 --- a/tests/Settings/ApplicationTest.php +++ b/tests/Settings/ApplicationTest.php @@ -33,7 +33,6 @@ use OC\Settings\Controller\CheckSetupController; use OC\Settings\Controller\GroupsController; use OC\Settings\Controller\LogSettingsController; use OC\Settings\Controller\MailSettingsController; -use OC\Settings\Controller\SecuritySettingsController; use OC\Settings\Controller\UsersController; use OC\Settings\Middleware\SubadminMiddleware; use OCP\AppFramework\Controller; @@ -76,7 +75,6 @@ class ApplicationTest extends TestCase { [GroupsController::class, Controller::class], [LogSettingsController::class, Controller::class], [MailSettingsController::class, Controller::class], - [SecuritySettingsController::class, Controller::class], [UsersController::class, Controller::class], [SubadminMiddleware::class, Middleware::class], diff --git a/tests/Settings/Controller/SecuritySettingsControllerTest.php b/tests/Settings/Controller/SecuritySettingsControllerTest.php deleted file mode 100644 index 75d580d9f85..00000000000 --- a/tests/Settings/Controller/SecuritySettingsControllerTest.php +++ /dev/null @@ -1,72 +0,0 @@ -config = $this->createMock(IConfig::class); - $this->securitySettingsController = new SecuritySettingsController( - 'settings', - $this->createMock(IRequest::class), - $this->config - ); - } - - public function testTrustedDomainsWithExistingValues() { - $this->config - ->expects($this->once()) - ->method('setSystemValue') - ->with('trusted_domains', array('owncloud.org', 'owncloud.com', 'newdomain.com')); - $this->config - ->expects($this->once()) - ->method('getSystemValue') - ->with('trusted_domains') - ->will($this->returnValue(array('owncloud.org', 'owncloud.com'))); - - $response = $this->securitySettingsController->trustedDomains('newdomain.com'); - $expectedResponse = array('status' => 'success'); - - $this->assertSame($expectedResponse, $response); - } - - public function testTrustedDomainsEmpty() { - $this->config - ->expects($this->once()) - ->method('setSystemValue') - ->with('trusted_domains', array('newdomain.com')); - $this->config - ->expects($this->once()) - ->method('getSystemValue') - ->with($this->equalTo('trusted_domains'), $this->equalTo([])) - ->willReturn([]); - - $response = $this->securitySettingsController->trustedDomains('newdomain.com'); - $expectedResponse = array('status' => 'success'); - - $this->assertSame($expectedResponse, $response); - } -} -- cgit v1.2.3