[TASK] Reduce CGL violations DoubleQuoteUsageNotRequired in install/
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / mod / class.tx_install_ajax.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 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 * This is the eID handler for install tool AJAX calls.
30 *
31 * @author Marcus Krause <security@typo3.org>
32 */
33 class tx_install_ajax {
34
35
36 /**
37 * Keeps content to be printed.
38 *
39 * @var string
40 */
41 var $content;
42
43 /**
44 * Keeps command to process.
45 *
46 * @var string
47 */
48 var $cmd = '';
49
50
51 /**
52 * Init function, setting the input vars in the class scope.
53 *
54 * @return void
55 */
56 function init() {
57 $this->cmd = t3lib_div::_GP('cmd');
58 }
59
60 /**
61 * Main function which creates the AJAX call return string.
62 * It is stored in $this->content.
63 *
64 * @return void
65 */
66 function main() {
67 // Create output:
68 switch ($this->cmd) {
69 case 'encryptionKey':
70 default:
71 $this->content = $this->createEncryptionKey();
72 $this->addTempContentHttpHeaders();
73 break;
74 }
75 }
76
77 /**
78 * Outputs the content from $this->content
79 *
80 * @return void
81 */
82 function printContent() {
83 if (!headers_sent()) {
84 header('Content-Length: ' . strlen($this->content));
85 }
86 echo $this->content;
87 }
88
89 /**
90 * Returns a newly created TYPO3 encryption key with a given length.
91 *
92 * @param integer $keyLength desired key length
93 * @return string
94 */
95 function createEncryptionKey($keyLength = 96) {
96 if (!headers_sent()) {
97 header('Content-type: text/plain');
98 }
99
100 return t3lib_div::getRandomHexString($keyLength);
101 }
102
103 /**
104 * Sends cache control headers that prevent caching in user agents.
105 *
106 */
107 function addTempContentHttpHeaders() {
108 if (!headers_sent()) {
109 // see RFC 2616
110 // see Microsoft Knowledge Base #234067
111 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
112 header('Cache-Control: no-cache, must-revalidate');
113 header('Pragma: no-cache');
114 header('Expires: -1');
115 }
116 }
117 }
118
119 // Make instance:
120 $SOBE = t3lib_div::makeInstance('tx_install_ajax');
121 $SOBE->init();
122 $SOBE->main();
123 $SOBE->printContent();
124 ?>