controller.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author cmeh <cmeh@users.noreply.github.com>
  5. * @author ideaship <ideaship@users.noreply.github.com>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <icewind@owncloud.com>
  9. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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\Setup;
  29. use OC\Setup;
  30. class Controller {
  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_Util::redirectToDefaultPage();
  93. }
  94. public function loadAutoConfig($post) {
  95. if( file_exists($this->autoConfigFile)) {
  96. \OC_Log::write('core', 'Autoconfig file found, setting up ownCloud…', \OC_Log::INFO);
  97. $AUTOCONFIG = array();
  98. include $this->autoConfigFile;
  99. $post = array_merge ($post, $AUTOCONFIG);
  100. }
  101. $dbIsSet = isset($post['dbtype']);
  102. $directoryIsSet = isset($post['directory']);
  103. $adminAccountIsSet = isset($post['adminlogin']);
  104. if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
  105. $post['install'] = 'true';
  106. }
  107. $post['dbIsSet'] = $dbIsSet;
  108. $post['directoryIsSet'] = $directoryIsSet;
  109. return $post;
  110. }
  111. }