PageRenderTime 102ms CodeModel.GetById 16ms RepoModel.GetById 2ms app.codeStats 0ms

/typo3/sysext/install/mod/class.tx_install_ajax.php

https://bitbucket.org/linxpinx/mercurial
PHP | 158 lines | 122 code | 5 blank | 31 comment | 3 complexity | 4bf98d4b95c2301c71017910ab3e08ff MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, Unlicense, LGPL-2.1, Apache-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 2009-2010 Marcus Krause, Helmut Hummel (security@typo3.org)
  6. * All rights reserved
  7. *
  8. * This script is part of the TYPO3 project. The TYPO3 project is
  9. * free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * The GNU General Public License can be found at
  15. * http://www.gnu.org/copyleft/gpl.html.
  16. * A copy is found in the textfile GPL.txt and important notices to the license
  17. * from the author is found in LICENSE.txt distributed with these scripts.
  18. *
  19. *
  20. * This script 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 General Public License for more details.
  24. *
  25. * This copyright notice MUST APPEAR in all copies of the script!
  26. ***************************************************************/
  27. // *******************************
  28. // Set error reporting
  29. // *******************************
  30. if (defined('E_DEPRECATED')) {
  31. error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
  32. } else {
  33. error_reporting(E_ALL ^ E_NOTICE);
  34. }
  35. // ***********************
  36. // Paths are setup
  37. // ***********************
  38. define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
  39. define('TYPO3_MODE','FE');
  40. if (!defined('PATH_thisScript')) define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', (PHP_SAPI=='cgi'||PHP_SAPI=='isapi' ||PHP_SAPI=='cgi-fcgi')&&($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED'])? ($_SERVER['ORIG_PATH_TRANSLATED']?$_SERVER['ORIG_PATH_TRANSLATED']:$_SERVER['PATH_TRANSLATED']):($_SERVER['ORIG_SCRIPT_FILENAME']?$_SERVER['ORIG_SCRIPT_FILENAME']:$_SERVER['SCRIPT_FILENAME']))));
  41. if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
  42. if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
  43. define('PATH_tslib', PATH_site.'tslib/');
  44. define('PATH_typo3conf', PATH_site.'typo3conf/');
  45. define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
  46. if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
  47. require_once(PATH_t3lib.'class.t3lib_div.php');
  48. /**
  49. * This is the eID handler for install tool AJAX calls.
  50. *
  51. * @author Marcus Krause <security@typo3.org>
  52. */
  53. class tx_install_ajax {
  54. /**
  55. * Keeps content to be printed.
  56. *
  57. * @var string
  58. */
  59. var $content;
  60. /**
  61. * Keeps command to process.
  62. *
  63. * @var string
  64. */
  65. var $cmd = '';
  66. /**
  67. * Init function, setting the input vars in the class scope.
  68. *
  69. * @return void
  70. */
  71. function init() {
  72. $this->cmd = t3lib_div::_GP('cmd');
  73. }
  74. /**
  75. * Main function which creates the AJAX call return string.
  76. * It is stored in $this->content.
  77. *
  78. * @return void
  79. */
  80. function main() {
  81. // Create output:
  82. switch ($this->cmd) {
  83. case 'encryptionKey':
  84. default:
  85. $this->content = $this->createEncryptionKey();
  86. $this->addTempContentHttpHeaders();
  87. break;
  88. }
  89. }
  90. /**
  91. * Outputs the content from $this->content
  92. *
  93. * @return void
  94. */
  95. function printContent() {
  96. if (!headers_sent()) {
  97. header('Content-Length: ' . strlen($this->content));
  98. }
  99. echo $this->content;
  100. }
  101. /**
  102. * Returns a newly created TYPO3 encryption key with a given length.
  103. *
  104. * @param integer $keyLength desired key length
  105. * @return string
  106. */
  107. function createEncryptionKey($keyLength = 96) {
  108. if (!headers_sent()) {
  109. header("Content-type: text/plain");
  110. }
  111. return t3lib_div::getRandomHexString($keyLength);
  112. }
  113. /**
  114. * Sends cache control headers that prevent caching in user agents.
  115. *
  116. */
  117. function addTempContentHttpHeaders() {
  118. if (!headers_sent()) {
  119. // see RFC 2616
  120. // see Microsoft Knowledge Base #234067
  121. header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
  122. header('Cache-Control: no-cache, must-revalidate');
  123. header('Pragma: no-cache');
  124. header('Expires: -1');
  125. }
  126. }
  127. }
  128. // Make instance:
  129. $SOBE = t3lib_div::makeInstance('tx_install_ajax');
  130. $SOBE->init();
  131. $SOBE->main();
  132. $SOBE->printContent();
  133. if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/install/mod/class.tx_install_ajax.php']) {
  134. include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/install/mod/class.tx_install_ajax.php']);
  135. }
  136. ?>