From 8ae612f6930235aa1768d3a5beeff65a3565d90a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 10 Sep 2013 20:19:42 +0200 Subject: [PATCH 1/9] Move core setup code to controller class --- core/setup.php | 59 ----------------------------- core/setup/controller.php | 79 +++++++++++++++++++++++++++++++++++++++ lib/base.php | 3 +- 3 files changed, 81 insertions(+), 60 deletions(-) delete mode 100644 core/setup.php create mode 100644 core/setup/controller.php diff --git a/core/setup.php b/core/setup.php deleted file mode 100644 index 4758c23b04..0000000000 --- a/core/setup.php +++ /dev/null @@ -1,59 +0,0 @@ - $hasSQLite, - 'hasMySQL' => $hasMySQL, - 'hasPostgreSQL' => $hasPostgreSQL, - 'hasOracle' => $hasOracle, - 'hasMSSQL' => $hasMSSQL, - 'directory' => $datadir, - 'secureRNG' => OC_Util::secureRNGAvailable(), - 'htaccessWorking' => OC_Util::isHtAccessWorking(), - 'vulnerableToNullByte' => $vulnerableToNullByte, - 'errors' => array(), -); - -if(isset($_POST['install']) AND $_POST['install']=='true') { - // We have to launch the installation process : - $e = OC_Setup::install($_POST); - $errors = array('errors' => $e); - - if(count($e) > 0) { - //OC_Template::printGuestPage("", "error", array("errors" => $errors)); - $options = array_merge($_POST, $opts, $errors); - OC_Template::printGuestPage("", "installation", $options); - } - else { - header( 'Location: '.OC_Helper::linkToRoute( 'post_setup_check' )); - exit(); - } -} -else { - OC_Template::printGuestPage("", "installation", $opts); -} diff --git a/core/setup/controller.php b/core/setup/controller.php new file mode 100644 index 0000000000..54bfe14612 --- /dev/null +++ b/core/setup/controller.php @@ -0,0 +1,79 @@ +loadAutoConfig($post); + $opts = $this->getSystemInfo(); + + if(isset($post['install']) AND $post['install']=='true') { + // We have to launch the installation process : + $e = \OC_Setup::install($post); + $errors = array('errors' => $e); + + if(count($e) > 0) { + $options = array_merge($post, $opts, $errors); + $this->display($options); + } + else { + $this->finishSetup(); + } + } + else { + $this->display($opts); + } + } + + public function display($post) { + \OC_Util::addScript('setup'); + \OC_Template::printGuestPage('', 'installation', $post); + } + + public function finishSetup() { + header( 'Location: '.\OC_Helper::linkToRoute( 'post_setup_check' )); + exit(); + } + + public function loadAutoConfig($post) { + $autosetup_file = \OC::$SERVERROOT.'/config/autoconfig.php'; + if( file_exists( $autosetup_file )) { + \OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', \OC_Log::INFO); + include $autosetup_file; + $post['install'] = 'true'; + $post = array_merge ($post, $AUTOCONFIG); + unlink($autosetup_file); + } + return $post; + } + + 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'); + $datadir = \OC_Config::getValue('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; + } + + // Protect data directory here, so we can test if the protection is working + \OC_Setup::protectDataDirectory(); + + return array( + 'hasSQLite' => $hasSQLite, + 'hasMySQL' => $hasMySQL, + 'hasPostgreSQL' => $hasPostgreSQL, + 'hasOracle' => $hasOracle, + 'hasMSSQL' => $hasMSSQL, + 'directory' => $datadir, + 'secureRNG' => \OC_Util::secureRNGAvailable(), + 'htaccessWorking' => \OC_Util::isHtAccessWorking(), + 'vulnerableToNullByte' => $vulnerableToNullByte, + 'errors' => array(), + ); + } +} diff --git a/lib/base.php b/lib/base.php index ea5adbadc9..aa91176d21 100644 --- a/lib/base.php +++ b/lib/base.php @@ -610,7 +610,8 @@ class OC { // Check if ownCloud is installed or in maintenance (update) mode if (!OC_Config::getValue('installed', false)) { - require_once 'core/setup.php'; + $controller = new OC\Core\Setup\Controller(); + $controller->run($_POST); exit(); } From 65aab3dc8c88f012e063ccea7cacc17f528b7d4d Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 10 Sep 2013 22:05:20 +0200 Subject: [PATCH 2/9] Check for failure in creating htaccessWorking testfile --- core/setup/controller.php | 14 ++++++++++++-- lib/util.php | 12 ++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index 54bfe14612..8ddcf19bb6 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -60,8 +60,18 @@ class Controller { $vulnerableToNullByte = true; } + $errors = array(); + // Protect data directory here, so we can test if the protection is working \OC_Setup::protectDataDirectory(); + try { + $htaccessworking = \OC_Util::isHtAccessWorking(); + } catch (\OC\HintException $e) { + $errors[] = array( + 'error' => $e->getMessage(), + 'hint' => $e->getHint() + ); + } return array( 'hasSQLite' => $hasSQLite, @@ -71,9 +81,9 @@ class Controller { 'hasMSSQL' => $hasMSSQL, 'directory' => $datadir, 'secureRNG' => \OC_Util::secureRNGAvailable(), - 'htaccessWorking' => \OC_Util::isHtAccessWorking(), + 'htaccessWorking' => $htaccessWorking, 'vulnerableToNullByte' => $vulnerableToNullByte, - 'errors' => array(), + 'errors' => $errors, ); } } diff --git a/lib/util.php b/lib/util.php index 0777643a95..e8e3bc37e5 100755 --- a/lib/util.php +++ b/lib/util.php @@ -689,9 +689,13 @@ class OC_Util { return false; } - $fp = @fopen($testfile, 'w'); - @fwrite($fp, $testcontent); - @fclose($fp); + $fp = @fopen($testFile, 'w'); + if (!$fp) { + throw new OC\HintException('Can\'t create test file to check for working .htaccess file.', + 'Make sure it is possible for the webserver to write to '.$testFile); + } + fwrite($fp, $testContent); + fclose($fp); // accessing the file via http $url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$fileName); @@ -700,7 +704,7 @@ class OC_Util { @fclose($fp); // cleanup - @unlink($testfile); + @unlink($testFile); // does it work ? if($content==$testContent) { From 071b8033cb59a3ed51925374e78790ecfa7a2fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 24 Sep 2013 00:44:55 +0200 Subject: [PATCH 3/9] fixing typo on $htaccessWorking - testing own code before pushing is appreciated --- core/setup/controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index 8ddcf19bb6..e1ad9d60e8 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -64,8 +64,9 @@ class Controller { // Protect data directory here, so we can test if the protection is working \OC_Setup::protectDataDirectory(); + $htaccessWorking = false; try { - $htaccessworking = \OC_Util::isHtAccessWorking(); + $htaccessWorking = \OC_Util::isHtAccessWorking(); } catch (\OC\HintException $e) { $errors[] = array( 'error' => $e->getMessage(), From 5db98aadd30b9f1218dda8f836acca0062ce1d9f Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Wed, 2 Oct 2013 18:23:47 +0200 Subject: [PATCH 4/9] Copyright and small fix --- core/setup/controller.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index e1ad9d60e8..9b35432f11 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -1,4 +1,10 @@ + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ namespace OC\Core\Setup; @@ -43,7 +49,7 @@ class Controller { include $autosetup_file; $post['install'] = 'true'; $post = array_merge ($post, $AUTOCONFIG); - unlink($autosetup_file); + @unlink($autosetup_file); } return $post; } From 09d2ba017e603fe6ac237da7830d86d74b2da61c Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 7 Oct 2013 00:36:42 +0200 Subject: [PATCH 5/9] fix undefined $htaccessWorking --- core/setup/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index 9b35432f11..679efee81b 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -70,7 +70,6 @@ class Controller { // Protect data directory here, so we can test if the protection is working \OC_Setup::protectDataDirectory(); - $htaccessWorking = false; try { $htaccessWorking = \OC_Util::isHtAccessWorking(); } catch (\OC\HintException $e) { @@ -78,6 +77,7 @@ class Controller { 'error' => $e->getMessage(), 'hint' => $e->getHint() ); + $htaccessWorking = false; } return array( From 12a900de2539a31b0bbfbba9ffa861fb0f36e8cd Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 31 Jan 2014 16:57:49 +0100 Subject: [PATCH 6/9] Do setup default value handling in the controller not the template --- core/setup/controller.php | 12 +++++++++++- core/templates/installation.php | 16 ++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index 0c87103138..5189aba2f3 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -33,11 +33,21 @@ class Controller { } public function display($post) { + $defaults = array( + 'adminlogin' => '', + 'adminpass' => '', + 'dbuser' => '', + 'dbpass' => '', + 'dbname' => '', + 'dbtablespace' => '', + 'dbhost' => '', + ); + $parameters = array_merge($defaults, $post); \OC_Util::addScript( '3rdparty', 'strengthify/jquery.strengthify' ); \OC_Util::addStyle( '3rdparty', 'strengthify/strengthify' ); \OC_Util::addScript('setup'); - \OC_Template::printGuestPage('', 'installation', $post); + \OC_Template::printGuestPage('', 'installation', $parameters); } public function finishSetup() { diff --git a/core/templates/installation.php b/core/templates/installation.php index 182fc83a4d..7e216d0ee9 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -48,13 +48,13 @@ t( 'Create an admin account' )); ?>

+ value="" autocomplete="off" autofocus required />

+ value="" required /> @@ -75,7 +75,7 @@ " - value="" /> + value="" /> @@ -149,11 +149,11 @@

+ value="" autocomplete="off" />

+ value="" /> @@ -161,7 +161,7 @@

@@ -169,14 +169,14 @@

+ value="" autocomplete="off" />

+ value="" />

From d8ec7e270167594ed407b22cb9ae78b1501ca946 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 31 Jan 2014 17:31:19 +0100 Subject: [PATCH 7/9] DRY for database type radiolist --- core/setup/controller.php | 17 +++++++++ core/templates/installation.php | 62 +++++---------------------------- 2 files changed, 25 insertions(+), 54 deletions(-) diff --git a/core/setup/controller.php b/core/setup/controller.php index 5189aba2f3..c628bda609 100644 --- a/core/setup/controller.php +++ b/core/setup/controller.php @@ -85,6 +85,22 @@ class Controller { $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'; + } + if ($hasPostgreSQL) { + $databases['pgsql'] = 'PostgreSQL'; + } + if ($hasOracle) { + $databases['oci'] = 'Oracle'; + } + if ($hasMSSQL) { + $databases['mssql'] = 'MS SQL'; + } $datadir = \OC_Config::getValue('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) @@ -111,6 +127,7 @@ class Controller { 'hasPostgreSQL' => $hasPostgreSQL, 'hasOracle' => $hasOracle, 'hasMSSQL' => $hasMSSQL, + 'databases' => $databases, 'directory' => $datadir, 'secureRNG' => \OC_Util::secureRNGAvailable(), 'htaccessWorking' => $htaccessWorking, diff --git a/core/templates/installation.php b/core/templates/installation.php index 7e216d0ee9..9356e62aa6 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -86,62 +86,16 @@ $hasOtherDB = true; else $hasOtherDB =false; //other than SQLite ?> t( 'Configure the database' )); ?>
- - - -

SQLite t( 'will be used' )); ?>.

- + $label): ?> + +

t( 'will be used' )); ?>.

+ - /> - - - - - - - -

MySQL t( 'will be used' )); ?>.

- - - /> - - - - - - -

PostgreSQL t( 'will be used' )); ?>.

- - - - /> - - - - - -

Oracle t( 'will be used' )); ?>.

- - - - /> - - - - - - -

MS SQL t( 'will be used' )); ?>.

- - - - /> - + /> + +
From f1c60c7f8b12180917828775fcf4ba82ba68d573 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 31 Jan 2014 17:33:15 +0100 Subject: [PATCH 8/9] Remove unused functions from OC_Helper init_var and init_radio where only used in the installation template --- lib/private/helper.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/lib/private/helper.php b/lib/private/helper.php index 58bee9c630..ce5708e2bb 100644 --- a/lib/private/helper.php +++ b/lib/private/helper.php @@ -448,29 +448,6 @@ class OC_Helper { * */ - //FIXME: should also check for value validation (i.e. the email is an email). - public static function init_var($s, $d = "") { - $r = $d; - if (isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) { - $r = OC_Util::sanitizeHTML($_REQUEST[$s]); - } - - return $r; - } - - /** - * returns "checked"-attribute if request contains selected radio element - * OR if radio element is the default one -- maybe? - * - * @param string $s Name of radio-button element name - * @param string $v Value of current radio-button element - * @param string $d Value of default radio-button element - */ - public static function init_radio($s, $v, $d) { - if ((isset($_REQUEST[$s]) && $_REQUEST[$s] == $v) || (!isset($_REQUEST[$s]) && $v == $d)) - print "checked=\"checked\" "; - } - /** * detect if a given program is found in the search PATH * From 5844d682a74533be8577160860758709bef706ba Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Sat, 1 Feb 2014 15:02:36 +0100 Subject: [PATCH 9/9] Use === instead of ==, add missing whitespace and CSS class --- core/templates/installation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/templates/installation.php b/core/templates/installation.php index 9356e62aa6..9670a5e9ee 100644 --- a/core/templates/installation.php +++ b/core/templates/installation.php @@ -87,8 +87,8 @@ t( 'Configure the database' )); ?>
$label): ?> - -

t( 'will be used' )); ?>.

+ +

t( 'will be used' )); ?>.