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