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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Controller;
  8. use OC\Setup;
  9. use OCP\Util;
  10. use Psr\Log\LoggerInterface;
  11. class SetupController {
  12. private string $autoConfigFile;
  13. public function __construct(
  14. protected Setup $setupHelper,
  15. protected LoggerInterface $logger,
  16. ) {
  17. $this->autoConfigFile = \OC::$configDir.'autoconfig.php';
  18. }
  19. public function run(array $post): void {
  20. // Check for autosetup:
  21. $post = $this->loadAutoConfig($post);
  22. $opts = $this->setupHelper->getSystemInfo();
  23. // convert 'abcpassword' to 'abcpass'
  24. if (isset($post['adminpassword'])) {
  25. $post['adminpass'] = $post['adminpassword'];
  26. }
  27. if (isset($post['dbpassword'])) {
  28. $post['dbpass'] = $post['dbpassword'];
  29. }
  30. if (!$this->setupHelper->canInstallFileExists()) {
  31. $this->displaySetupForbidden();
  32. return;
  33. }
  34. if (isset($post['install']) and $post['install'] == 'true') {
  35. // We have to launch the installation process :
  36. $e = $this->setupHelper->install($post);
  37. $errors = ['errors' => $e];
  38. if (count($e) > 0) {
  39. $options = array_merge($opts, $post, $errors);
  40. $this->display($options);
  41. } else {
  42. $this->finishSetup();
  43. }
  44. } else {
  45. $options = array_merge($opts, $post);
  46. $this->display($options);
  47. }
  48. }
  49. private function displaySetupForbidden(): void {
  50. \OC_Template::printGuestPage('', 'installation_forbidden');
  51. }
  52. public function display($post): void {
  53. $defaults = [
  54. 'adminlogin' => '',
  55. 'adminpass' => '',
  56. 'dbuser' => '',
  57. 'dbpass' => '',
  58. 'dbname' => '',
  59. 'dbtablespace' => '',
  60. 'dbhost' => 'localhost',
  61. 'dbtype' => '',
  62. ];
  63. $parameters = array_merge($defaults, $post);
  64. Util::addStyle('server', null);
  65. // include common nextcloud webpack bundle
  66. Util::addScript('core', 'common');
  67. Util::addScript('core', 'main');
  68. Util::addTranslations('core');
  69. \OC_Template::printGuestPage('', 'installation', $parameters);
  70. }
  71. private function finishSetup(): void {
  72. if (file_exists($this->autoConfigFile)) {
  73. unlink($this->autoConfigFile);
  74. }
  75. \OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
  76. if ($this->setupHelper->shouldRemoveCanInstallFile()) {
  77. \OC_Template::printGuestPage('', 'installation_incomplete');
  78. }
  79. header('Location: ' . \OC::$server->getURLGenerator()->getAbsoluteURL('index.php/core/apps/recommended'));
  80. exit();
  81. }
  82. public function loadAutoConfig(array $post): array {
  83. if (file_exists($this->autoConfigFile)) {
  84. $this->logger->info('Autoconfig file found, setting up Nextcloud…');
  85. $AUTOCONFIG = [];
  86. include $this->autoConfigFile;
  87. $post = array_merge($post, $AUTOCONFIG);
  88. }
  89. $dbIsSet = isset($post['dbtype']);
  90. $directoryIsSet = isset($post['directory']);
  91. $adminAccountIsSet = isset($post['adminlogin']);
  92. if ($dbIsSet and $directoryIsSet and $adminAccountIsSet) {
  93. $post['install'] = 'true';
  94. }
  95. $post['dbIsSet'] = $dbIsSet;
  96. $post['directoryIsSet'] = $directoryIsSet;
  97. return $post;
  98. }
  99. }