46281c4526212cc4c378b428fbb0b0af4aab9d1b
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / mod / class.tx_install_ajax.php
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
29
30 // *******************************
31 // Set error reporting
32 // *******************************
33 if (defined('E_DEPRECATED')) {
34 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
35 } else {
36 error_reporting(E_ALL ^ E_NOTICE);
37 }
38
39
40 // ***********************
41 // Paths are setup
42 // ***********************
43 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
44 define('TYPO3_MODE','FE');
45 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']))));
46
47 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
48 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
49 define('PATH_tslib', PATH_site.'tslib/');
50 define('PATH_typo3conf', PATH_site.'typo3conf/');
51 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
52
53 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
54
55
56 require_once(PATH_t3lib.'class.t3lib_div.php');
57
58 /**
59 * This is the eID handler for install tool AJAX calls.
60 *
61 * @author Marcus Krause <security@typo3.org>
62 */
63 class tx_install_ajax {
64
65
66 /**
67 * Keeps content to be printed.
68 *
69 * @var string
70 */
71 var $content;
72
73 /**
74 * Keeps command to process.
75 *
76 * @var string
77 */
78 var $cmd = '';
79
80
81 /**
82 * Init function, setting the input vars in the class scope.
83 *
84 * @return void
85 */
86 function init() {
87 $this->cmd = t3lib_div::_GP('cmd');
88 }
89
90 /**
91 * Main function which creates the AJAX call return string.
92 * It is stored in $this->content.
93 *
94 * @return void
95 */
96 function main() {
97 // Create output:
98 switch ($this->cmd) {
99 case 'encryptionKey':
100 default:
101 $this->content = $this->createEncryptionKey();
102 $this->addTempContentHttpHeaders();
103 break;
104 }
105 }
106
107 /**
108 * Outputs the content from $this->content
109 *
110 * @return void
111 */
112 function printContent() {
113 if (!headers_sent()) {
114 header('Content-Length: ' . strlen($this->content));
115 }
116 echo $this->content;
117 }
118
119 /**
120 * Returns a newly created TYPO3 encryption key with a given length.
121 *
122 * @param integer $keyLength desired key length
123 * @return string
124 */
125 function createEncryptionKey($keyLength = 96) {
126 if (!headers_sent()) {
127 header("Content-type: text/plain");
128 }
129
130 return t3lib_div::getRandomHexString($keyLength);
131 }
132
133 /**
134 * Sends cache control headers that prevent caching in user agents.
135 *
136 */
137 function addTempContentHttpHeaders() {
138 if (!headers_sent()) {
139 // see RFC 2616
140 // see Microsoft Knowledge Base #234067
141 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
142 header('Cache-Control: no-cache, must-revalidate');
143 header('Pragma: no-cache');
144 header('Expires: -1');
145 }
146 }
147 }
148
149 // Make instance:
150 $SOBE = t3lib_div::makeInstance('tx_install_ajax');
151 $SOBE->init();
152 $SOBE->main();
153 $SOBE->printContent();
154
155 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/install/mod/class.tx_install_ajax.php']) {
156 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/install/mod/class.tx_install_ajax.php']);
157 }
158 ?>