You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.5 KiB

10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author ideaship <ideaship@users.noreply.github.com>
  5. * @author Lukas Reschke <lukas@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Robin McCorkell <robin@mccorkell.me.uk>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @copyright Copyright (c) 2016, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\Core\Controller;
  28. use OC\Setup;
  29. class SetupController {
  30. /** @var Setup */
  31. protected $setupHelper;
  32. /** @var string */
  33. private $autoConfigFile;
  34. /**
  35. * @param Setup $setupHelper
  36. */
  37. function __construct(Setup $setupHelper) {
  38. $this->autoConfigFile = \OC::$SERVERROOT.'/config/autoconfig.php';
  39. $this->setupHelper = $setupHelper;
  40. }
  41. /**
  42. * @param $post
  43. */
  44. public function run($post) {
  45. // Check for autosetup:
  46. $post = $this->loadAutoConfig($post);
  47. $opts = $this->setupHelper->getSystemInfo();
  48. // convert 'abcpassword' to 'abcpass'
  49. if (isset($post['adminpassword'])) {
  50. $post['adminpass'] = $post['adminpassword'];
  51. }
  52. if (isset($post['dbpassword'])) {
  53. $post['dbpass'] = $post['dbpassword'];
  54. }
  55. if(isset($post['install']) AND $post['install']=='true') {
  56. // We have to launch the installation process :
  57. $e = $this->setupHelper->install($post);
  58. $errors = array('errors' => $e);
  59. if(count($e) > 0) {
  60. $options = array_merge($opts, $post, $errors);
  61. $this->display($options);
  62. } else {
  63. $this->finishSetup();
  64. }
  65. } else {
  66. $options = array_merge($opts, $post);
  67. $this->display($options);
  68. }
  69. }
  70. public function display($post) {
  71. $defaults = array(
  72. 'adminlogin' => '',
  73. 'adminpass' => '',
  74. 'dbuser' => '',
  75. 'dbpass' => '',
  76. 'dbname' => '',
  77. 'dbtablespace' => '',
  78. 'dbhost' => 'localhost',
  79. 'dbtype' => '',
  80. );
  81. $parameters = array_merge($defaults, $post);
  82. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  83. \OC_Util::addVendorStyle('strengthify/strengthify');
  84. \OC_Util::addScript('setup');
  85. \OC_Template::printGuestPage('', 'installation', $parameters);
  86. }
  87. public function finishSetup() {
  88. if( file_exists( $this->autoConfigFile )) {
  89. unlink($this->autoConfigFile);
  90. }
  91. \OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
  92. \OC_Util::redirectToDefaultPage();
  93. }
  94. public function loadAutoConfig($post) {
  95. if( file_exists($this->autoConfigFile)) {
  96. \OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', \OCP\Util::INFO);
  97. $AUTOCONFIG = array();
  98. include $this->autoConfigFile;
  99. $post = array_merge ($post, $AUTOCONFIG);
  100. }
  101. $dbIsSet = isset($post['dbtype']);
  102. $directoryIsSet = isset($post['directory']);
  103. $adminAccountIsSet = isset($post['adminlogin']);
  104. if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
  105. $post['install'] = 'true';
  106. }
  107. $post['dbIsSet'] = $dbIsSet;
  108. $post['directoryIsSet'] = $directoryIsSet;
  109. return $post;
  110. }
  111. }