SetupController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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(isset($post['install']) AND $post['install']=='true') {
  59. // We have to launch the installation process :
  60. $e = $this->setupHelper->install($post);
  61. $errors = array('errors' => $e);
  62. if(count($e) > 0) {
  63. $options = array_merge($opts, $post, $errors);
  64. $this->display($options);
  65. } else {
  66. $this->finishSetup();
  67. }
  68. } else {
  69. $options = array_merge($opts, $post);
  70. $this->display($options);
  71. }
  72. }
  73. public function display($post) {
  74. $defaults = array(
  75. 'adminlogin' => '',
  76. 'adminpass' => '',
  77. 'dbuser' => '',
  78. 'dbpass' => '',
  79. 'dbname' => '',
  80. 'dbtablespace' => '',
  81. 'dbhost' => 'localhost',
  82. 'dbtype' => '',
  83. );
  84. $parameters = array_merge($defaults, $post);
  85. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  86. \OC_Util::addVendorStyle('strengthify/strengthify');
  87. \OC_Util::addScript('setup');
  88. \OC_Template::printGuestPage('', 'installation', $parameters);
  89. }
  90. public function finishSetup() {
  91. if( file_exists( $this->autoConfigFile )) {
  92. unlink($this->autoConfigFile);
  93. }
  94. \OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
  95. \OC_Util::redirectToDefaultPage();
  96. }
  97. public function loadAutoConfig($post) {
  98. if( file_exists($this->autoConfigFile)) {
  99. \OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', ILogger::INFO);
  100. $AUTOCONFIG = array();
  101. include $this->autoConfigFile;
  102. $post = array_merge ($post, $AUTOCONFIG);
  103. }
  104. $dbIsSet = isset($post['dbtype']);
  105. $directoryIsSet = isset($post['directory']);
  106. $adminAccountIsSet = isset($post['adminlogin']);
  107. if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
  108. $post['install'] = 'true';
  109. }
  110. $post['dbIsSet'] = $dbIsSet;
  111. $post['directoryIsSet'] = $directoryIsSet;
  112. return $post;
  113. }
  114. }