PageRenderTime 34ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/setup/index.php

http://github.com/modxcms/revolution
PHP | 105 lines | 83 code | 5 blank | 17 comment | 31 complexity | 0c4f0bf2ef866cc47efa46a2bd935fb3 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Instantiates the setup program.
  12. *
  13. * @package modx
  14. * @subpackage setup
  15. */
  16. /* do a little bit of environment cleanup if possible */
  17. @ ini_set('magic_quotes_runtime', 0);
  18. @ ini_set('magic_quotes_sybase', 0);
  19. @ ini_set('opcache.revalidate_freq', 0);
  20. /* start session */
  21. session_start();
  22. $isCommandLine = php_sapi_name() == 'cli';
  23. if ($isCommandLine) {
  24. foreach ($argv as $idx => $argv) {
  25. $p = explode('=',ltrim($argv,'--'));
  26. if (isset($p[1])) {
  27. $_REQUEST[$p[0]] = $p[1];
  28. }
  29. }
  30. if (!empty($_REQUEST['core_path']) && is_dir($_REQUEST['core_path'])) {
  31. define('MODX_CORE_PATH',$_REQUEST['core_path']);
  32. }
  33. if (!empty($_REQUEST['config_key'])) {
  34. $_REQUEST['config_key'] = str_replace(array('{','}',"'",'"','\$'), '', $_REQUEST['config_key']);
  35. define('MODX_CONFIG_KEY',$_REQUEST['config_key']);
  36. }
  37. }
  38. /* check for compatible PHP version */
  39. define('MODX_SETUP_PHP_VERSION', phpversion());
  40. $php_ver_comp = version_compare(MODX_SETUP_PHP_VERSION, '5.1.1');
  41. if ($php_ver_comp < 0) {
  42. die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Wrong PHP version! You\'re using PHP version '.MODX_SETUP_PHP_VERSION.', and MODX requires version 5.1.1 or higher.</p></body></html>');
  43. }
  44. /* make sure json extension is available */
  45. if (!function_exists('json_encode')) {
  46. die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>MODX requires the PHP JSON extension! You\'re PHP configuration at version '.MODX_SETUP_PHP_VERSION.' does not appear to have this extension enabled. This should be a standard extension on PHP 5.2+; it is available as a PECL extension in 5.1.</p></body></html>');
  47. }
  48. /* make sure date.timezone is set for PHP 5.3.0+ users */
  49. if (version_compare(MODX_SETUP_PHP_VERSION,'5.3.0') >= 0) {
  50. $phptz = @ini_get('date.timezone');
  51. if (empty($phptz)) {
  52. date_default_timezone_set('UTC');
  53. }
  54. if (!date_default_timezone_get()) {
  55. die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>To use PHP 5.3.0+, you must set the date.timezone setting in your php.ini (or have at least UTC in the list of supported timezones). Please do set it to a proper timezone before proceeding. A list can be found <a href="http://us.php.net/manual/en/timezones.php">here</a>.</p></body></html>');
  56. }
  57. }
  58. if (!$isCommandLine) {
  59. $https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : false;
  60. $installBaseUrl= (!$https || strtolower($https) != 'on') ? 'http://' : 'https://';
  61. $installBaseUrl .= $_SERVER['HTTP_HOST'];
  62. if (isset($_SERVER['SERVER_PORT']) && (string)$_SERVER['SERVER_PORT'] != '' && $_SERVER['SERVER_PORT'] != 80) $installBaseUrl= str_replace(':' . $_SERVER['SERVER_PORT'], '', $installBaseUrl);
  63. $installBaseUrl .= ($_SERVER['SERVER_PORT'] == 80 || ($https !== false || strtolower($https) == 'on')) ? '' : ':' . $_SERVER['SERVER_PORT'];
  64. $installBaseUrl .= $_SERVER['SCRIPT_NAME'];
  65. $installBaseUrl = htmlspecialchars($installBaseUrl, ENT_QUOTES, 'utf-8');
  66. define('MODX_SETUP_URL', $installBaseUrl);
  67. } else {
  68. define('MODX_SETUP_URL','/');
  69. }
  70. /* session loop-back tester */
  71. if (!$isCommandLine && (!isset($_GET['s']) || $_GET['s'] != 'set') && !isset($_SESSION['session_test'])) {
  72. $_SESSION['session_test']= 1;
  73. echo "<html><head><title>Loading...</title><script>window.location.href='" . MODX_SETUP_URL . "?s=set';</script></head><body></body></html>";
  74. exit ();
  75. } elseif (!$isCommandLine && isset($_GET['s']) && $_GET['s'] == 'set' && !isset($_SESSION['session_test'])) {
  76. die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure your PHP session configuration is valid and working.</p></body></html>');
  77. }
  78. $setupPath= strtr(realpath(dirname(__FILE__)), '\\', '/') . '/';
  79. define('MODX_SETUP_PATH', $setupPath);
  80. $installPath= strtr(realpath(dirname(__DIR__)), '\\', '/') . '/';
  81. define('MODX_INSTALL_PATH', $installPath);
  82. if (!include(MODX_SETUP_PATH . 'includes/config.core.php')) {
  83. die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure you have uploaded all of the setup/ files; your setup/includes/config.core.php file is missing.</p></body></html>');
  84. }
  85. if (!include(MODX_SETUP_PATH . 'includes/modinstall.class.php')) {
  86. die('<html><head><title></title></head><body><h1>FATAL ERROR: MODX Setup cannot continue.</h1><p>Make sure you have uploaded all of the setup/ files; your setup/includes/modinstall.class.php file is missing.</p></body></html>');
  87. }
  88. $modInstall = new modInstall();
  89. if ($modInstall->getService('lexicon','modInstallLexicon')) {
  90. $modInstall->lexicon->load('default');
  91. }
  92. $modInstall->findCore();
  93. $modInstall->doPreloadChecks();
  94. $requestClass = $isCommandLine ? 'request.modInstallCLIRequest' : 'request.modInstallRequest';
  95. $modInstall->getService('request',$requestClass);
  96. echo $modInstall->request->handle();
  97. exit();