SetupController.php 3.5 KB

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