Merge pull request #20878 from owncloud/proper-htaccess-support-in-code-signing-checker

Also run .htaccess routine when installing on another system than Apache
This commit is contained in:
Thomas Müller 2015-12-11 11:46:37 +01:00
commit f831d93f3f
3 changed files with 8 additions and 39 deletions

View File

@ -1,4 +1,3 @@
# Version: 9.0.0
<IfModule mod_headers.c> <IfModule mod_headers.c>
<IfModule mod_fcgid.c> <IfModule mod_fcgid.c>
<IfModule mod_setenvif.c> <IfModule mod_setenvif.c>

View File

@ -369,11 +369,9 @@ class Setup {
// out that this is indeed an ownCloud data directory // out that this is indeed an ownCloud data directory
file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', ''); file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/.ocdata', '');
// Update htaccess files for apache hosts // Update .htaccess files
if (isset($_SERVER['SERVER_SOFTWARE']) && strstr($_SERVER['SERVER_SOFTWARE'], 'Apache')) { Setup::updateHtaccess();
self::updateHtaccess(); Setup::protectDataDirectory();
self::protectDataDirectory();
}
//try to write logtimezone //try to write logtimezone
if (date_default_timezone_get()) { if (date_default_timezone_get()) {
@ -394,33 +392,18 @@ class Setup {
return \OC::$SERVERROOT.'/.htaccess'; return \OC::$SERVERROOT.'/.htaccess';
} }
/**
* 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 * Append the correct ErrorDocument path for Apache hosts
*
* @throws \OC\HintException If .htaccess does not include the current version
*/ */
public static function updateHtaccess() { 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(), $setupHelper = new \OC\Setup(\OC::$server->getConfig(), \OC::$server->getIniWrapper(),
\OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(), \OC::$server->getL10N('lib'), new \OC_Defaults(), \OC::$server->getLogger(),
\OC::$server->getSecureRandom()); \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()); $htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
$content = ''; $content = '';

View File

@ -130,17 +130,4 @@ class Test_OC_Setup extends \Test\TestCase {
->will($this->returnValue('NotAnArray')); ->will($this->returnValue('NotAnArray'));
$this->setupClass->getSupportedDatabases(); $this->setupClass->getSupportedDatabases();
} }
/**
* This is actual more an integration test whether the version parameter in the .htaccess
* was updated as well when the version has been incremented.
* If it hasn't this test will fail.
*/
public function testHtaccessIsCurrent() {
$result = self::invokePrivate(
$this->setupClass,
'isCurrentHtaccess'
);
$this->assertTrue($result);
}
} }