diff options
Diffstat (limited to 'lib/private/setup.php')
-rw-r--r-- | lib/private/setup.php | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/lib/private/setup.php b/lib/private/setup.php index 8f1ae389e45..b9f8828227e 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -10,13 +10,15 @@ * @author Joas Schilling <nickvergessen@owncloud.com> * @author Lukas Reschke <lukas@owncloud.com> * @author Martin Mattel <martin.mattel@diemattels.at> + * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <icewind@owncloud.com> + * @author Roeland Jago Douma <rullzer@owncloud.com> * @author Sean Comeau <sean@ftlnetworks.ca> * @author Serge Martin <edb@sigluy.net> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Vincent Petry <pvince81@owncloud.com> * - * @copyright Copyright (c) 2015, ownCloud, Inc. + * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify @@ -192,7 +194,9 @@ class Setup { // Create data directory to test whether the .htaccess works // Notice that this is not necessarily the same data directory as the one // that will effectively be used. - @mkdir($dataDir); + if(!file_exists($dataDir)) { + @mkdir($dataDir); + } $htAccessWorking = true; if (is_dir($dataDir) && is_writable($dataDir)) { // Protect data directory here, so we can test if the protection is working @@ -310,9 +314,9 @@ class Setup { } //generate a random salt that is used to salt the local user passwords - $salt = $this->random->getLowStrengthGenerator()->generate(30); + $salt = $this->random->generate(30); // generate a secret - $secret = $this->random->getMediumStrengthGenerator()->generate(48); + $secret = $this->random->generate(48); //write the config file $this->config->setSystemValues([ @@ -322,7 +326,7 @@ class Setup { 'datadirectory' => $dataDir, 'overwrite.cli.url' => $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT, 'dbtype' => $dbType, - 'version' => implode('.', \OC_Util::getVersion()), + 'version' => implode('.', \OCP\Util::getVersion()), ]); try { @@ -369,11 +373,9 @@ class Setup { // out that this is indeed an ownCloud data directory file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); - // Update htaccess files for apache hosts - if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { - self::updateHtaccess(); - self::protectDataDirectory(); - } + // Update .htaccess files + Setup::updateHtaccess(); + Setup::protectDataDirectory(); //try to write logtimezone if (date_default_timezone_get()) { @@ -395,35 +397,20 @@ class Setup { } /** - * Checks if the .htaccess contains the current version parameter - * - * @return bool - */ - private function isCurrentHtaccess() { - $version = \OC_Util::getVersion(); - unset($version[3]); - - return !strpos( - file_get_contents($this->pathToHtaccess()), - 'Version: '.implode('.', $version) - ) === false; - } - - /** * Append the correct ErrorDocument path for Apache hosts - * - * @throws \OC\HintException If .htaccess does not include the current version */ public static function updateHtaccess() { + // From CLI we don't know the defined web root. Thus we can't write any + // directives into the .htaccess file. + if(\OC::$CLI) { + return; + } $setupHelper = new \OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getSecureRandom()); - if(!$setupHelper->isCurrentHtaccess()) { - throw new \OC\HintException('.htaccess file has the wrong version. Please upload the correct version. Maybe you forgot to replace it after updating?'); - } $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); - $content = ''; + $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; if (strpos($htaccessContent, 'ErrorDocument 403') === false) { //custom 403 error page $content.= "\nErrorDocument 403 ".\OC::$WEBROOT."/core/templates/403.php"; @@ -432,6 +419,19 @@ class Setup { //custom 404 error page $content.= "\nErrorDocument 404 ".\OC::$WEBROOT."/core/templates/404.php"; } + + // Add rewrite base + $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; + $content.="\n<IfModule mod_rewrite.c>"; + $content.="\n RewriteBase ".$webRoot; + $content .= "\n <IfModule mod_env.c>"; + $content .= "\n SetEnv front_controller_active true"; + $content .= "\n <IfModule mod_dir.c>"; + $content .= "\n DirectorySlash off"; + $content .= "\n </IfModule>"; + $content.="\n </IfModule>"; + $content.="\n</IfModule>"; + if ($content !== '') { //suppress errors in case we don't have permissions for it @file_put_contents($setupHelper->pathToHtaccess(), $content . "\n", FILE_APPEND); @@ -453,7 +453,9 @@ class Setup { $content.= "</ifModule>\n\n"; $content.= "# section for Apache 2.2 and 2.4\n"; $content.= "IndexIgnore *\n"; - file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data').'/.htaccess', $content); - file_put_contents(\OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data').'/index.html', ''); + + $baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); + file_put_contents($baseDir . '/.htaccess', $content); + file_put_contents($baseDir . '/index.html', ''); } } |