From 0de90cfc672ebb8bb7c8ffa01d40380715c42f94 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 26 Jul 2017 16:30:09 +0200 Subject: [PATCH] Fix 403 and 404 redirect * Nextcloud is not properly loaded in the standalone version (especially the theming) * it is already not listed anymore in the Nginx config (see nextcloud/documentation#392) * the index.php-free version doesn't support this Signed-off-by: Morris Jobke --- core/templates/403.php | 8 ++++---- core/templates/404.php | 8 ++++---- lib/private/Setup.php | 4 ++-- tests/Core/Templates/TemplatesTest.php | 20 -------------------- 4 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 tests/Core/Templates/TemplatesTest.php diff --git a/core/templates/403.php b/core/templates/403.php index 7d07c72c87..e053fad764 100644 --- a/core/templates/403.php +++ b/core/templates/403.php @@ -1,10 +1,10 @@ printPage(); + + $urlGenerator = \OC::$server->getURLGenerator(); + header('Location: ' . $urlGenerator->getAbsoluteURL('/')); exit; } // @codeCoverageIgnoreEnd diff --git a/core/templates/404.php b/core/templates/404.php index cc45cbeaf5..0f7318e937 100644 --- a/core/templates/404.php +++ b/core/templates/404.php @@ -3,11 +3,11 @@ /** @var $l \OCP\IL10N */ /** @var $theme OCP\Defaults */ // @codeCoverageIgnoreStart -if(!isset($_)) {//also provide standalone error page +if(!isset($_)) {//standalone page is not supported anymore - redirect to / require_once '../../lib/base.php'; - - $tmpl = new OC_Template( '', '404', 'guest' ); - $tmpl->printPage(); + + $urlGenerator = \OC::$server->getURLGenerator(); + header('Location: ' . $urlGenerator->getAbsoluteURL('/')); exit; } // @codeCoverageIgnoreEnd diff --git a/lib/private/Setup.php b/lib/private/Setup.php index f5bfca604a..1e98ed5456 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -449,10 +449,10 @@ class Setup { $htaccessContent = explode($content, $htaccessContent, 2)[0]; //custom 403 error page - $content.= "\nErrorDocument 403 ".$webRoot."/core/templates/403.php"; + $content.= "\nErrorDocument 403 ".$webRoot."/"; //custom 404 error page - $content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php"; + $content.= "\nErrorDocument 404 ".$webRoot."/"; // Add rewrite rules if the RewriteBase is configured $rewriteBase = $config->getValue('htaccess.RewriteBase', ''); diff --git a/tests/Core/Templates/TemplatesTest.php b/tests/Core/Templates/TemplatesTest.php deleted file mode 100644 index cd1502fd22..0000000000 --- a/tests/Core/Templates/TemplatesTest.php +++ /dev/null @@ -1,20 +0,0 @@ -
  • \n\t\tAccess forbidden

  • "; - $this->assertTemplate($expectedHtml, $template); - } - - public function test404() { - $template = \OC::$SERVERROOT . '/core/templates/404.php'; - $href = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); - $expectedHtml = ""; - $this->assertTemplate($expectedHtml, $template); - } - -}