SetupController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author ideaship <ideaship@users.noreply.github.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Robin McCorkell <robin@mccorkell.me.uk>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OC\Core\Controller;
  29. use OC\Setup;
  30. class SetupController {
  31. /** @var Setup */
  32. protected $setupHelper;
  33. /** @var string */
  34. private $autoConfigFile;
  35. /**
  36. * @param Setup $setupHelper
  37. */
  38. function __construct(Setup $setupHelper) {
  39. $this->autoConfigFile = \OC::$SERVERROOT.'/config/autoconfig.php';
  40. $this->setupHelper = $setupHelper;
  41. }
  42. /**
  43. * @param $post
  44. */
  45. public function run($post) {
  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(isset($post['install']) AND $post['install']=='true') {
  57. // We have to launch the installation process :
  58. $e = $this->setupHelper->install($post);
  59. $errors = array('errors' => $e);
  60. if(count($e) > 0) {
  61. $options = array_merge($opts, $post, $errors);
  62. $this->display($options);
  63. } else {
  64. $this->finishSetup();
  65. }
  66. } else {
  67. $options = array_merge($opts, $post);
  68. $this->display($options);
  69. }
  70. }
  71. public function display($post) {
  72. $defaults = array(
  73. 'adminlogin' => '',
  74. 'adminpass' => '',
  75. 'dbuser' => '',
  76. 'dbpass' => '',
  77. 'dbname' => '',
  78. 'dbtablespace' => '',
  79. 'dbhost' => 'localhost',
  80. 'dbtype' => '',
  81. );
  82. $parameters = array_merge($defaults, $post);
  83. \OC_Util::addVendorScript('strengthify/jquery.strengthify');
  84. \OC_Util::addVendorStyle('strengthify/strengthify');
  85. \OC_Util::addScript('setup');
  86. \OC_Template::printGuestPage('', 'installation', $parameters);
  87. }
  88. public function finishSetup() {
  89. if( file_exists( $this->autoConfigFile )) {
  90. unlink($this->autoConfigFile);
  91. }
  92. \OC::$server->getIntegrityCodeChecker()->runInstanceVerification();
  93. \OC_Util::redirectToDefaultPage();
  94. }
  95. public function loadAutoConfig($post) {
  96. if( file_exists($this->autoConfigFile)) {
  97. \OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', \OCP\Util::INFO);
  98. $AUTOCONFIG = array();
  99. include $this->autoConfigFile;
  100. $post = array_merge ($post, $AUTOCONFIG);
  101. }
  102. $dbIsSet = isset($post['dbtype']);
  103. $directoryIsSet = isset($post['directory']);
  104. $adminAccountIsSet = isset($post['adminlogin']);
  105. if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
  106. $post['install'] = 'true';
  107. }
  108. $post['dbIsSet'] = $dbIsSet;
  109. $post['directoryIsSet'] = $directoryIsSet;
  110. return $post;
  111. }
  112. }