controller.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Core\Setup;
  9. class Controller {
  10. public function run($post) {
  11. // Check for autosetup:
  12. $post = $this->loadAutoConfig($post);
  13. $opts = $this->getSystemInfo();
  14. if(isset($post['install']) AND $post['install']=='true') {
  15. // We have to launch the installation process :
  16. $e = \OC_Setup::install($post);
  17. $errors = array('errors' => $e);
  18. if(count($e) > 0) {
  19. $options = array_merge($opts, $post, $errors);
  20. $this->display($options);
  21. }
  22. else {
  23. $this->finishSetup();
  24. }
  25. }
  26. else {
  27. $options = array_merge($opts, $post);
  28. $this->display($options);
  29. }
  30. }
  31. public function display($post) {
  32. $defaults = array(
  33. 'adminlogin' => '',
  34. 'adminpass' => '',
  35. 'dbuser' => '',
  36. 'dbpass' => '',
  37. 'dbname' => '',
  38. 'dbtablespace' => '',
  39. 'dbhost' => 'localhost',
  40. 'dbtype' => '',
  41. );
  42. $parameters = array_merge($defaults, $post);
  43. \OC_Util::addScript( '3rdparty', 'strengthify/jquery.strengthify' );
  44. \OC_Util::addStyle( '3rdparty', 'strengthify/strengthify' );
  45. \OC_Util::addScript('setup');
  46. \OC_Template::printGuestPage('', 'installation', $parameters);
  47. }
  48. public function finishSetup() {
  49. header( 'Location: '.\OC_Helper::linkToRoute( 'post_setup_check' ));
  50. exit();
  51. }
  52. public function loadAutoConfig($post) {
  53. $autosetup_file = \OC::$SERVERROOT.'/config/autoconfig.php';
  54. if( file_exists( $autosetup_file )) {
  55. \OC_Log::write('core', 'Autoconfig file found, setting up owncloud...', \OC_Log::INFO);
  56. $AUTOCONFIG = array();
  57. include $autosetup_file;
  58. $post = array_merge ($post, $AUTOCONFIG);
  59. }
  60. $dbIsSet = isset($post['dbtype']);
  61. $directoryIsSet = isset($post['directory']);
  62. $adminAccountIsSet = isset($post['adminlogin']);
  63. if ($dbIsSet AND $directoryIsSet AND $adminAccountIsSet) {
  64. $post['install'] = 'true';
  65. if( file_exists( $autosetup_file )) {
  66. unlink($autosetup_file);
  67. }
  68. }
  69. $post['dbIsSet'] = $dbIsSet;
  70. $post['directoryIsSet'] = $directoryIsSet;
  71. return $post;
  72. }
  73. /**
  74. * Gathers system information like database type and does
  75. * a few system checks.
  76. *
  77. * @return array of system info, including an "errors" value
  78. * in case of errors/warnings
  79. */
  80. public function getSystemInfo() {
  81. $hasSQLite = class_exists('SQLite3');
  82. $hasMySQL = is_callable('mysql_connect');
  83. $hasPostgreSQL = is_callable('pg_connect');
  84. $hasOracle = is_callable('oci_connect');
  85. $hasMSSQL = is_callable('sqlsrv_connect');
  86. $databases = array();
  87. if ($hasSQLite) {
  88. $databases['sqlite'] = 'SQLite';
  89. }
  90. if ($hasMySQL) {
  91. $databases['mysql'] = 'MySQL/MariaDB';
  92. }
  93. if ($hasPostgreSQL) {
  94. $databases['pgsql'] = 'PostgreSQL';
  95. }
  96. if ($hasOracle) {
  97. $databases['oci'] = 'Oracle';
  98. }
  99. if ($hasMSSQL) {
  100. $databases['mssql'] = 'MS SQL';
  101. }
  102. $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT.'/data');
  103. $vulnerableToNullByte = false;
  104. if(@file_exists(__FILE__."\0Nullbyte")) { // Check if the used PHP version is vulnerable to the NULL Byte attack (CVE-2006-7243)
  105. $vulnerableToNullByte = true;
  106. }
  107. $errors = array();
  108. // Protect data directory here, so we can test if the protection is working
  109. \OC_Setup::protectDataDirectory();
  110. try {
  111. $htaccessWorking = \OC_Util::isHtaccessWorking();
  112. } catch (\OC\HintException $e) {
  113. $errors[] = array(
  114. 'error' => $e->getMessage(),
  115. 'hint' => $e->getHint()
  116. );
  117. $htaccessWorking = false;
  118. }
  119. if (\OC_Util::runningOnMac()) {
  120. $l10n = \OC_L10N::get('core');
  121. $themeName = \OC_Util::getTheme();
  122. $theme = new \OC_Defaults();
  123. $errors[] = array(
  124. 'error' => $l10n->t(
  125. 'Mac OS X is not supported and %s will not work properly on this platform. ' .
  126. 'Use it at your own risk! ',
  127. $theme->getName()
  128. ),
  129. 'hint' => $l10n->t('For the best results, please consider using a GNU/Linux server instead.')
  130. );
  131. }
  132. return array(
  133. 'hasSQLite' => $hasSQLite,
  134. 'hasMySQL' => $hasMySQL,
  135. 'hasPostgreSQL' => $hasPostgreSQL,
  136. 'hasOracle' => $hasOracle,
  137. 'hasMSSQL' => $hasMSSQL,
  138. 'databases' => $databases,
  139. 'directory' => $datadir,
  140. 'secureRNG' => \OC_Util::secureRNGAvailable(),
  141. 'htaccessWorking' => $htaccessWorking,
  142. 'vulnerableToNullByte' => $vulnerableToNullByte,
  143. 'errors' => $errors,
  144. );
  145. }
  146. }