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 3.9KB

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