SetupController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. use OCP\ILogger;
  32. class SetupController {
  33. /** @var Setup */
  34. protected $setupHelper;
  35. /** @var string */
  36. private $autoConfigFile;
  37. /**
  38. * @param Setup $setupHelper
  39. */
  40. function __construct(Setup $setupHelper) {
  41. $this->autoConfigFile = \OC::$configDir.'autoconfig.php';
  42. $this->setupHelper = $setupHelper;
  43. }
  44. /**
  45. * @param $post
  46. */
  47. public function run($post) {
  48. // Check for autosetup:
  49. $post = $this->loadAutoConfig($post);
  50. $opts = $this->setupHelper->getSystemInfo();
  51. // convert 'abcpassword' to 'abcpass'
  52. if (isset($post['adminpassword'])) {
  53. $post['adminpass'] = $post['adminpassword'];
  54. }
  55. if (isset($post['dbpassword'])) {
  56. $post['dbpass'] = $post['dbpassword'];
  57. }
  58. if (!is_file(\OC::$configDir.'/CAN_INSTALL')) {
  59. $this->displaySetupForbidden();
  60. return;
  61. }
  62. if(isset($post['install']) AND $post['install']=='true') {
  63. // We have to launch the installation process :
  64. $e = $this->setupHelper->install($post);
  65. $errors = array('errors' => $e);
  66. if(count($e) > 0) {
  67. $options = array_merge($opts, $post, $errors);
  68. $this->display($options);
  69. } else {
  70. $this->finishSetup();
  71. }
  72. } else {
  73. $options = array_merge($opts, $post);
  74. $this->display($options);
  75. }
  76. }
  77. private function displaySetupForbidden() {
  78. \OC_Template::printGuestPage('', 'installation_forbidden');
  79. }
  80. public function display($post) {
  81. $defaults = array(
  82. 'adminlogin' => '',
  83. 'adminpass' => '',
  84. 'dbuser' => '',
  85. 'dbpass' => '',
  86. 'dbname' => '',
  87. 'dbtablespace' => '',
  88. 'dbhost' => 'localhost',
  89. 'dbtype' => '',
  90. );
  91. $parameters = array_merge($defaults, $post);
  92. \OC_Util::addScript('setup');
  93. \OC_Template::printGuestPage('', 'installation', $parameters);
  94. }
  95. public function finishSetup() {
  96. if( file_exists( $this->autoConfigFile )) {
  97. unlink($this->autoConfigFile);
  98. }
  99. \OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
  100. if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) {
  101. if (!unlink(\OC::$configDir.'/CAN_INSTALL')) {
  102. \OC_Template::printGuestPage('', 'installation_incomplete');
  103. }
  104. }
  105. \OC_Util::redirectToDefaultPage();
  106. }
  107. public function loadAutoConfig($post) {
  108. if( file_exists($this->autoConfigFile)) {
  109. \OCP\Util::writeLog('core', 'Autoconfig file found, setting up Nextcloud…', ILogger::INFO);
  110. $AUTOCONFIG = array();
  111. include $this->autoConfigFile;
  112. $post = array_merge ($post, $AUTOCONFIG);
  113. }
  114. $dbIsSet = isset($post['dbtype']);
  115. $directoryIsSet = isset($post['directory']);
  116. $adminAccountIsSet = isset($post['adminlogin']);
  117. if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
  118. $post['install'] = 'true';
  119. }
  120. $post['dbIsSet'] = $dbIsSet;
  121. $post['directoryIsSet'] = $directoryIsSet;
  122. return $post;
  123. }
  124. }