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.

128 lines
3.5 KiB

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