From 233c49f4b9fc90f5bd023420ed899439fb413db0 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 27 Oct 2014 12:51:26 +0100 Subject: Make supported DBs configurable within config.php This commit will make the supported DBs for installation configurable within config.php. By default the following databases are tested: "sqlite", "mysql", "pgsql". The reason behind this is that there might be instances where we want to prevent SQLite to be used by mistake. To test this play around with the new configuration parameter "supportedDatabases". --- core/setup/controller.php | 49 +++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'core') diff --git a/core/setup/controller.php b/core/setup/controller.php index 53f247e9769..628a4b0349f 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -1,6 +1,7 @@ + * Copyright (c) 2014 Lukas Reschke * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -8,7 +9,19 @@ namespace OC\Core\Setup; +use OCP\IConfig; + class Controller { + /** @var \OCP\IConfig */ + protected $config; + + /** + * @param IConfig $config + */ + function __construct(IConfig $config) { + $this->config = $config; + } + public function run($post) { // Check for autosetup: $post = $this->loadAutoConfig($post); @@ -87,28 +100,10 @@ class Controller { * in case of errors/warnings */ public function getSystemInfo() { - $hasSQLite = class_exists('SQLite3'); - $hasMySQL = is_callable('mysql_connect'); - $hasPostgreSQL = is_callable('pg_connect'); - $hasOracle = is_callable('oci_connect'); - $hasMSSQL = is_callable('sqlsrv_connect'); - $databases = array(); - if ($hasSQLite) { - $databases['sqlite'] = 'SQLite'; - } - if ($hasMySQL) { - $databases['mysql'] = 'MySQL/MariaDB'; - } - if ($hasPostgreSQL) { - $databases['pgsql'] = 'PostgreSQL'; - } - if ($hasOracle) { - $databases['oci'] = 'Oracle'; - } - if ($hasMSSQL) { - $databases['mssql'] = 'MS SQL'; - } - $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data'); + $setup = new \OC_Setup($this->config); + $databases = $setup->getSupportedDatabases(); + + $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); $vulnerableToNullByte = false; if(@file_exists(__FILE__."\0Nullbyte")) { // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243) $vulnerableToNullByte = true; @@ -150,11 +145,11 @@ class Controller { } return array( - 'hasSQLite' => $hasSQLite, - 'hasMySQL' => $hasMySQL, - 'hasPostgreSQL' => $hasPostgreSQL, - 'hasOracle' => $hasOracle, - 'hasMSSQL' => $hasMSSQL, + 'hasSQLite' => isset($databases['sqlite']), + 'hasMySQL' => isset($databases['mysql']), + 'hasPostgreSQL' => isset($databases['postgre']), + 'hasOracle' => isset($databases['oci']), + 'hasMSSQL' => isset($databases['mssql']), 'databases' => $databases, 'directory' => $datadir, 'htaccessWorking' => $htaccessWorking, -- cgit v1.2.3 From 79778d6a5118f3d024d1d4c1e001fba8fba13423 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 27 Oct 2014 19:53:12 +0100 Subject: code cleanup during review :+1: --- core/setup/controller.php | 16 ++++++++-------- lib/private/setup.php | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'core') diff --git a/core/setup/controller.php b/core/setup/controller.php index 628a4b0349f..f5f05348fd1 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -103,7 +103,7 @@ class Controller { $setup = new \OC_Setup($this->config); $databases = $setup->getSupportedDatabases(); - $datadir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); $vulnerableToNullByte = false; if(@file_exists(__FILE__."\0Nullbyte")) { // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243) $vulnerableToNullByte = true; @@ -114,25 +114,25 @@ class Controller { // 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 (is_dir($datadir) && is_writable($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 \OC_Setup::protectDataDirectory(); try { - $htaccessWorking = \OC_Util::isHtaccessWorking(); + $htAccessWorking = \OC_Util::isHtaccessWorking(); } catch (\OC\HintException $e) { $errors[] = array( 'error' => $e->getMessage(), 'hint' => $e->getHint() ); - $htaccessWorking = false; + $htAccessWorking = false; } } if (\OC_Util::runningOnMac()) { $l10n = \OC::$server->getL10N('core'); - $themeName = \OC_Util::getTheme(); $theme = new \OC_Defaults(); $errors[] = array( 'error' => $l10n->t( @@ -151,8 +151,8 @@ class Controller { 'hasOracle' => isset($databases['oci']), 'hasMSSQL' => isset($databases['mssql']), 'databases' => $databases, - 'directory' => $datadir, - 'htaccessWorking' => $htaccessWorking, + 'directory' => $dataDir, + 'htaccessWorking' => $htAccessWorking, 'vulnerableToNullByte' => $vulnerableToNullByte, 'errors' => $errors, ); diff --git a/lib/private/setup.php b/lib/private/setup.php index 8945c2c03f1..b82e0be72e8 100644 --- a/lib/private/setup.php +++ b/lib/private/setup.php @@ -90,7 +90,8 @@ class OC_Setup { 'name' => 'MS SQL' ) ); - $configuredDatabases = $this->config->getSystemValue('supportedDatabases', array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql')); + $configuredDatabases = $this->config->getSystemValue('supportedDatabases', + array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql')); if(!is_array($configuredDatabases)) { throw new Exception('Supported databases are not properly configured.'); } @@ -122,7 +123,7 @@ class OC_Setup { $l = self::getTrans(); $error = array(); - $dbtype = $options['dbtype']; + $dbType = $options['dbtype']; if(empty($options['adminlogin'])) { $error[] = $l->t('Set an admin username.'); @@ -134,25 +135,25 @@ class OC_Setup { $options['directory'] = OC::$SERVERROOT."/data"; } - if (!isset(self::$dbSetupClasses[$dbtype])) { - $dbtype = 'sqlite'; + if (!isset(self::$dbSetupClasses[$dbType])) { + $dbType = 'sqlite'; } $username = htmlspecialchars_decode($options['adminlogin']); $password = htmlspecialchars_decode($options['adminpass']); - $datadir = htmlspecialchars_decode($options['directory']); + $dataDir = htmlspecialchars_decode($options['directory']); - $class = self::$dbSetupClasses[$dbtype]; + $class = self::$dbSetupClasses[$dbType]; /** @var \OC\Setup\AbstractDatabase $dbSetup */ $dbSetup = new $class(self::getTrans(), 'db_structure.xml'); $error = array_merge($error, $dbSetup->validate($options)); // validate the data directory if ( - (!is_dir($datadir) and !mkdir($datadir)) or - !is_writable($datadir) + (!is_dir($dataDir) and !mkdir($dataDir)) or + !is_writable($dataDir) ) { - $error[] = $l->t("Can't create or write into the data directory %s", array($datadir)); + $error[] = $l->t("Can't create or write into the data directory %s", array($dataDir)); } if(count($error) != 0) { @@ -168,12 +169,12 @@ class OC_Setup { } if (OC_Util::runningOnWindows()) { - $datadir = rtrim(realpath($datadir), '\\'); + $dataDir = rtrim(realpath($dataDir), '\\'); } - //use sqlite3 when available, otherise sqlite2 will be used. - if($dbtype=='sqlite' and class_exists('SQLite3')) { - $dbtype='sqlite3'; + //use sqlite3 when available, otherwise sqlite2 will be used. + if($dbType=='sqlite' and class_exists('SQLite3')) { + $dbType='sqlite3'; } //generate a random salt that is used to salt the local user passwords @@ -186,9 +187,9 @@ class OC_Setup { //write the config file \OC::$server->getConfig()->setSystemValue('trusted_domains', $trustedDomains); - \OC::$server->getConfig()->setSystemValue('datadirectory', $datadir); + \OC::$server->getConfig()->setSystemValue('datadirectory', $dataDir); \OC::$server->getConfig()->setSystemValue('overwrite.cli.url', \OC_Request::serverProtocol() . '://' . \OC_Request::serverHost() . OC::$WEBROOT); - \OC::$server->getConfig()->setSystemValue('dbtype', $dbtype); + \OC::$server->getConfig()->setSystemValue('dbtype', $dbType); \OC::$server->getConfig()->setSystemValue('version', implode('.', OC_Util::getVersion())); try { @@ -211,8 +212,7 @@ class OC_Setup { //create the user and group try { OC_User::createUser($username, $password); - } - catch(Exception $exception) { + } catch(Exception $exception) { $error[] = $exception->getMessage(); } -- cgit v1.2.3