[TASK] Hide new db settings in Configuration module
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / Classes / View / ConfigurationView.php
1 <?php
2 namespace TYPO3\CMS\Lowlevel\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\BaseScriptClass;
20 use TYPO3\CMS\Backend\Routing\Router;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Utility\ArrayUtility;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
26 use TYPO3\CMS\Fluid\View\StandaloneView;
27 use TYPO3\CMS\Lowlevel\Utility\ArrayBrowser;
28
29 /**
30 * Script class for the Config module
31 */
32 class ConfigurationView extends BaseScriptClass
33 {
34 /**
35 * @var StandaloneView
36 */
37 protected $view;
38
39 /**
40 * The name of the module
41 *
42 * @var string
43 */
44 protected $moduleName = 'system_config';
45
46 /**
47 * ModuleTemplate Container
48 *
49 * @var ModuleTemplate
50 */
51 protected $moduleTemplate;
52
53 /**
54 * Blind configurations which should not be visible
55 *
56 * @var array
57 */
58 protected $blindedConfigurationOptions = [
59 'TYPO3_CONF_VARS' => [
60 'DB' => [
61 'database' => '******',
62 'host' => '******',
63 'password' => '******',
64 'port' => '******',
65 'socket' => '******',
66 'username' => '******',
67 'Connections' => [
68 'Default' => [
69 'dbname' => '******',
70 'host' => '******',
71 'password' => '******',
72 'port' => '******',
73 'user' => '******',
74 'unix_socket' => '******',
75 ],
76 ],
77 ],
78 'SYS' => [
79 'encryptionKey' => '******'
80 ]
81 ]
82 ];
83
84 /**
85 * Constructor
86 */
87 public function __construct()
88 {
89 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
90 $this->view->getRequest()->setControllerExtensionName('lowlevel');
91 // Prepare blinding for all database connection types
92 foreach (array_keys($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']) as $connectionName) {
93 if ($connectionName !== 'Default') {
94 $this->blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections'][$connectionName] =
95 $this->blindedConfigurationOptions['TYPO3_CONF_VARS']['DB']['Connections']['Default'];
96 }
97 }
98 }
99
100 /**
101 * Initialization
102 *
103 * @return void
104 */
105 public function init()
106 {
107 $this->menuConfig();
108 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
109 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Lowlevel/ConfigurationView');
110 }
111
112 /**
113 * Menu Configuration
114 *
115 * @return void
116 */
117 public function menuConfig()
118 {
119 // MENU-ITEMS:
120 // If array, then it's a selector box menu
121 // If empty string it's just a variable, that'll be saved.
122 // Values NOT in this array will not be saved in the settings-array for the module.
123 $this->MOD_MENU = array(
124 'function' => array(
125 0 => LocalizationUtility::translate('typo3ConfVars', 'lowlevel'),
126 1 => LocalizationUtility::translate('tca', 'lowlevel'),
127 2 => LocalizationUtility::translate('tcaDescr', 'lowlevel'),
128 3 => LocalizationUtility::translate('loadedExt', 'lowlevel'),
129 4 => LocalizationUtility::translate('t3services', 'lowlevel'),
130 5 => LocalizationUtility::translate('tbemodules', 'lowlevel'),
131 6 => LocalizationUtility::translate('tbemodulesext', 'lowlevel'),
132 7 => LocalizationUtility::translate('tbeStyles', 'lowlevel'),
133 8 => LocalizationUtility::translate('beUser', 'lowlevel'),
134 9 => LocalizationUtility::translate('usersettings', 'lowlevel'),
135 10 => LocalizationUtility::translate('routes', 'lowlevel')
136 ),
137 'regexsearch' => '',
138 'fixedLgd' => ''
139 );
140 // CLEANSE SETTINGS
141 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
142 }
143
144 /**
145 * Main function
146 *
147 * @return void
148 */
149 public function main()
150 {
151 /** @var ArrayBrowser $arrayBrowser */
152 $arrayBrowser = GeneralUtility::makeInstance(ArrayBrowser::class);
153 $label = $this->MOD_MENU['function'][$this->MOD_SETTINGS['function']];
154 $search_field = GeneralUtility::_GP('search_field');
155
156 $templatePathAndFilename = GeneralUtility::getFileAbsFileName('EXT:lowlevel/Resources/Private/Templates/Backend/Configuration.html');
157 $this->view->setTemplatePathAndFilename($templatePathAndFilename);
158 $this->view->assign('label', $label);
159 $this->view->assign('search_field', $search_field);
160 $this->view->assign('checkbox_checkRegexsearch', BackendUtility::getFuncCheck(0, 'SET[regexsearch]', $this->MOD_SETTINGS['regexsearch'], '', '', 'id="checkRegexsearch"'));
161
162 switch ($this->MOD_SETTINGS['function']) {
163 case 0:
164 $theVar = $GLOBALS['TYPO3_CONF_VARS'];
165 ArrayUtility::naturalKeySortRecursive($theVar);
166 $arrayBrowser->varName = '$TYPO3_CONF_VARS';
167 break;
168 case 1:
169 $theVar = $GLOBALS['TCA'];
170 ArrayUtility::naturalKeySortRecursive($theVar);
171 $arrayBrowser->varName = '$TCA';
172 break;
173 case 2:
174 $theVar = $GLOBALS['TCA_DESCR'];
175 ArrayUtility::naturalKeySortRecursive($theVar);
176 $arrayBrowser->varName = '$TCA_DESCR';
177 break;
178 case 3:
179 $theVar = $GLOBALS['TYPO3_LOADED_EXT'];
180 ArrayUtility::naturalKeySortRecursive($theVar);
181 $arrayBrowser->varName = '$TYPO3_LOADED_EXT';
182 break;
183 case 4:
184 $theVar = $GLOBALS['T3_SERVICES'];
185 ArrayUtility::naturalKeySortRecursive($theVar);
186 $arrayBrowser->varName = '$T3_SERVICES';
187 break;
188 case 5:
189 $theVar = $GLOBALS['TBE_MODULES'];
190 ArrayUtility::naturalKeySortRecursive($theVar);
191 $arrayBrowser->varName = '$TBE_MODULES';
192 break;
193 case 6:
194 $theVar = $GLOBALS['TBE_MODULES_EXT'];
195 ArrayUtility::naturalKeySortRecursive($theVar);
196 $arrayBrowser->varName = '$TBE_MODULES_EXT';
197 break;
198 case 7:
199 $theVar = $GLOBALS['TBE_STYLES'];
200 ArrayUtility::naturalKeySortRecursive($theVar);
201 $arrayBrowser->varName = '$TBE_STYLES';
202 break;
203 case 8:
204 $theVar = $GLOBALS['BE_USER']->uc;
205 ArrayUtility::naturalKeySortRecursive($theVar);
206 $arrayBrowser->varName = '$BE_USER->uc';
207 break;
208 case 9:
209 $theVar = $GLOBALS['TYPO3_USER_SETTINGS'];
210 ArrayUtility::naturalKeySortRecursive($theVar);
211 $arrayBrowser->varName = '$TYPO3_USER_SETTINGS';
212 break;
213 case 10:
214 $router = GeneralUtility::makeInstance(Router::class);
215 $routes = $router->getRoutes();
216 $theVar = [];
217 foreach ($routes as $identifier => $route) {
218 $theVar[$identifier] = [
219 'path' => $route->getPath(),
220 'options' => $route->getOptions()
221 ];
222 }
223 ArrayUtility::naturalKeySortRecursive($theVar);
224 $arrayBrowser->varName = 'BackendRoutes';
225 break;
226 default:
227 $theVar = array();
228 }
229 // Update node:
230 $update = 0;
231 $node = GeneralUtility::_GET('node');
232 // If any plus-signs were clicked, it's registered.
233 if (is_array($node)) {
234 $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']] = $arrayBrowser->depthKeys($node, $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']]);
235 $update = 1;
236 }
237 if ($update) {
238 $this->getBackendUser()->pushModuleData($this->moduleName, $this->MOD_SETTINGS);
239 }
240 $arrayBrowser->dontLinkVar = true;
241 $arrayBrowser->depthKeys = $this->MOD_SETTINGS['node_' . $this->MOD_SETTINGS['function']];
242 $arrayBrowser->regexMode = $this->MOD_SETTINGS['regexsearch'];
243 $arrayBrowser->fixedLgd = $this->MOD_SETTINGS['fixedLgd'];
244 $arrayBrowser->searchKeysToo = true;
245
246 // If any POST-vars are send, update the condition array
247 if (GeneralUtility::_POST('search') && trim($search_field)) {
248 $arrayBrowser->depthKeys = $arrayBrowser->getSearchKeys($theVar, '', $search_field, array());
249 }
250
251 // mask sensitive information
252 $varName = trim($arrayBrowser->varName, '$');
253 if (isset($this->blindedConfigurationOptions[$varName])) {
254 ArrayUtility::mergeRecursiveWithOverrule($theVar, ArrayUtility::intersectRecursive($this->blindedConfigurationOptions[$varName], $theVar));
255 }
256 $tree = $arrayBrowser->tree($theVar, '', '');
257 $this->view->assign('tree', $tree);
258
259 // Setting up the shortcut button for docheader
260 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
261 // Shortcut
262 $shortcutButton = $buttonBar->makeShortcutButton()
263 ->setModuleName($this->moduleName)
264 ->setDisplayName($this->MOD_MENU['function'][$this->MOD_SETTINGS['function']])
265 ->setSetVariables(['function']);
266 $buttonBar->addButton($shortcutButton);
267
268 $this->getModuleMenu();
269
270 $this->content = '<form action="" id="ConfigurationView" method="post">';
271 $this->content .= $this->view->render();
272 $this->content .= '</form>';
273 }
274
275 /**
276 * Injects the request object for the current request or subrequest
277 * Simply calls main() and init() and outputs the content
278 *
279 * @param ServerRequestInterface $request the current request
280 * @param ResponseInterface $response
281 * @return ResponseInterface the response with the content
282 */
283 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
284 {
285 $GLOBALS['SOBE'] = $this;
286 $this->init();
287 $this->main();
288
289 $this->moduleTemplate->setContent($this->content);
290 $response->getBody()->write($this->moduleTemplate->renderContent());
291 return $response;
292 }
293
294 /**
295 * Generates the action menu
296 */
297 protected function getModuleMenu()
298 {
299 $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
300 $menu->setIdentifier('ConfigurationJumpMenu');
301
302 foreach ($this->MOD_MENU['function'] as $controller => $title) {
303 $item = $menu
304 ->makeMenuItem()
305 ->setHref(
306 BackendUtility::getModuleUrl(
307 $this->moduleName,
308 [
309 'id' => $this->id,
310 'SET' => [
311 'function' => $controller
312 ]
313 ]
314 )
315 )
316 ->setTitle($title);
317 if ($controller === (int)$this->MOD_SETTINGS['function']) {
318 $item->setActive(true);
319 }
320 $menu->addMenuItem($item);
321 }
322 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
323 }
324 }