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