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.

SetupController.php 4.2KB

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