'Using $OLD_BE_USER of class SetupModuleController from the outside is discouraged, the variable will be removed.', 'MOD_MENU' => 'Using $MOD_MENU of class SetupModuleController from the outside is discouraged, the variable will be removed.', 'MOD_SETTINGS' => 'Using $MOD_SETTINGS of class SetupModuleController from the outside is discouraged, the variable will be removed.', 'content' => 'Using $content of class SetupModuleController from the outside is discouraged, as this variable is only used for internal storage.', 'overrideConf' => 'Using $overrideConf of class SetupModuleController from the outside is discouraged, as this variable is only used for internal storage.', 'languageUpdate' => 'Using $languageUpdate of class SetupModuleController from the outside is discouraged, as this variable is only used for internal storage.', ]; /** * @var array */ private $deprecatedPublicMethods = [ 'storeIncomingData' => 'Using SetupModuleController::storeIncomingData() is deprecated and will not be possible anymore in TYPO3 v10.0.', 'main' => 'Using SetupModuleController::main() is deprecated and will not be possible anymore in TYPO3 v10.0.', 'init' => 'Using SetupModuleController::init() is deprecated and will not be possible anymore in TYPO3 v10.0.', ]; /** * @var array */ protected $MOD_MENU = []; /** * @var array */ protected $MOD_SETTINGS = []; /** * @var string */ protected $content; /** * @var array */ protected $overrideConf; /** * @deprecated will be removed in TYPO3 v10.0 */ protected $OLD_BE_USER; /** * @var bool */ protected $languageUpdate; /** * @var bool */ protected $pagetreeNeedsRefresh = false; /** * @var bool */ protected $isAdmin; /** * @var array */ protected $tsFieldConf; /** * @var bool */ protected $saveData = false; /** * @var int */ protected $passwordIsUpdated = self::PASSWORD_NOT_UPDATED; /** * @var bool */ protected $passwordIsSubmitted = false; /** * @var bool */ protected $setupIsUpdated = false; /** * @var bool */ protected $settingsAreResetToDefault = false; /** * Form protection instance * * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection */ protected $formProtection; /** * @var string */ protected $simulateSelector = ''; /** * @var int */ protected $simUser; /** * The name of the module * * @var string */ protected $moduleName = 'user_setup'; /** * ModuleTemplate object * * @var ModuleTemplate */ protected $moduleTemplate; /** * Instantiate the form protection before a simulated user is initialized. */ public function __construct() { $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); $this->formProtection = FormProtectionFactory::get(); $pageRenderer = $this->moduleTemplate->getPageRenderer(); $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal'); $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/FormEngine'); $pageRenderer->addInlineSetting('FormEngine', 'formName', 'editform'); $pageRenderer->addInlineLanguageLabelArray([ 'FormEngine.remainingCharacters' => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.remainingCharacters'), ]); } /** * Getter for the form protection instance. * * @return \TYPO3\CMS\Core\FormProtection\BackendFormProtection * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. */ public function getFormProtection() { trigger_error('SetupModuleController->getFormProtection() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED); return $this->formProtection; } /** * If settings are submitted to _POST[DATA], store them * NOTICE: This method is called before the \TYPO3\CMS\Backend\Template\ModuleTemplate * is included. See bottom of document. */ protected function storeIncomingData() { // First check if something is submitted in the data-array from POST vars $d = GeneralUtility::_POST('data'); $columns = $GLOBALS['TYPO3_USER_SETTINGS']['columns']; $backendUser = $this->getBackendUser(); $beUserId = $backendUser->user['uid']; $storeRec = []; $fieldList = $this->getFieldsFromShowItem(); if (is_array($d) && $this->formProtection->validateToken((string)GeneralUtility::_POST('formToken'), 'BE user setup', 'edit')) { // UC hashed before applying changes $save_before = md5(serialize($backendUser->uc)); // PUT SETTINGS into the ->uc array: // Reload left frame when switching BE language if (isset($d['lang']) && $d['lang'] != $backendUser->uc['lang']) { $this->languageUpdate = true; } // Reload pagetree if the title length is changed if (isset($d['titleLen']) && $d['titleLen'] !== $backendUser->uc['titleLen']) { $this->pagetreeNeedsRefresh = true; } if ($d['setValuesToDefault']) { // If every value should be default $backendUser->resetUC(); $this->settingsAreResetToDefault = true; } elseif ($d['save']) { // Save all submitted values if they are no array (arrays are with table=be_users) and exists in $GLOBALS['TYPO3_USER_SETTINGS'][columns] foreach ($columns as $field => $config) { if (!in_array($field, $fieldList)) { continue; } if ($config['table']) { if ($config['table'] === 'be_users' && !in_array($field, ['password', 'password2', 'passwordCurrent', 'email', 'realName', 'admin', 'avatar'])) { if (!isset($config['access']) || $this->checkAccess($config) && $backendUser->user[$field] !== $d['be_users'][$field]) { if ($config['type'] === 'check') { $fieldValue = isset($d['be_users'][$field]) ? 1 : 0; } else { $fieldValue = $d['be_users'][$field]; } $storeRec['be_users'][$beUserId][$field] = $fieldValue; $backendUser->user[$field] = $fieldValue; } } } if ($config['type'] === 'check') { $backendUser->uc[$field] = isset($d[$field]) ? 1 : 0; } else { $backendUser->uc[$field] = htmlspecialchars($d[$field]); } } // Personal data for the users be_user-record (email, name, password...) // If email and name is changed, set it in the users record: $be_user_data = $d['be_users']; // Possibility to modify the transmitted values. Useful to do transformations, like RSA password decryption foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['modifyUserDataBeforeSave'] ?? [] as $function) { $params = ['be_user_data' => &$be_user_data]; GeneralUtility::callUserFunction($function, $params, $this); } $this->passwordIsSubmitted = (string)$be_user_data['password'] !== ''; $passwordIsConfirmed = $this->passwordIsSubmitted && $be_user_data['password'] === $be_user_data['password2']; // Update the real name: if ($be_user_data['realName'] !== $backendUser->user['realName']) { $backendUser->user['realName'] = ($storeRec['be_users'][$beUserId]['realName'] = substr($be_user_data['realName'], 0, 80)); } // Update the email address: if ($be_user_data['email'] !== $backendUser->user['email']) { $backendUser->user['email'] = ($storeRec['be_users'][$beUserId]['email'] = substr($be_user_data['email'], 0, 80)); } // Update the password: if ($passwordIsConfirmed) { if ($this->isAdmin) { $passwordOk = true; } else { $currentPasswordHashed = $GLOBALS['BE_USER']->user['password']; $passwordOk = false; $saltFactory = GeneralUtility::makeInstance(PasswordHashFactory::class); try { $hashInstance = $saltFactory->get($currentPasswordHashed, 'BE'); $passwordOk = $hashInstance->checkPassword($be_user_data['passwordCurrent'], $currentPasswordHashed); } catch (InvalidPasswordHashException $e) { // Could not find hash class responsible for existing password. This is a // misconfiguration and user can not change its password. } } if ($passwordOk) { $this->passwordIsUpdated = self::PASSWORD_UPDATED; $storeRec['be_users'][$beUserId]['password'] = $be_user_data['password']; } else { $this->passwordIsUpdated = self::PASSWORD_OLD_WRONG; } } else { $this->passwordIsUpdated = self::PASSWORD_NOT_THE_SAME; } $this->setAvatarFileUid($beUserId, $be_user_data['avatar'], $storeRec); $this->saveData = true; } // Inserts the overriding values. $backendUser->overrideUC(); $save_after = md5(serialize($backendUser->uc)); // If something in the uc-array of the user has changed, we save the array... if ($save_before != $save_after) { $backendUser->writeUC($backendUser->uc); $backendUser->writelog(254, 1, 0, 1, 'Personal settings changed', []); $this->setupIsUpdated = true; } // Persist data if something has changed: if (!empty($storeRec) && $this->saveData) { // Make instance of TCE for storing the changes. $dataHandler = GeneralUtility::makeInstance(DataHandler::class); $dataHandler->start($storeRec, []); $dataHandler->admin = true; // This is to make sure that the users record can be updated even if in another workspace. This is tolerated. $dataHandler->bypassWorkspaceRestrictions = true; $dataHandler->process_datamap(); if ($this->passwordIsUpdated === self::PASSWORD_NOT_UPDATED || count($storeRec['be_users'][$beUserId]) > 1) { $this->setupIsUpdated = true; } BackendUtility::setUpdateSignal('updateTopbar'); } } } /** * Initializes the module for display of the settings form. */ protected function init() { $this->getLanguageService()->includeLLFile('EXT:setup/Resources/Private/Language/locallang.xlf'); $backendUser = $this->getBackendUser(); $this->isAdmin = $backendUser->isAdmin(); // Getting the 'override' values as set might be set in User TSconfig $this->overrideConf = $backendUser->getTSConfig()['setup.']['override.'] ?? null; // Getting the disabled fields might be set in User TSconfig (eg setup.fields.password.disabled=1) $this->tsFieldConf = $backendUser->getTSConfig()['setup.']['fields.'] ?? null; // id password is disabled, disable repeat of password too (password2) if (isset($this->tsFieldConf['password.']) && $this->tsFieldConf['password.']['disabled']) { $this->tsFieldConf['password2.']['disabled'] = 1; $this->tsFieldConf['passwordCurrent.']['disabled'] = 1; } } /** * Generate necessary JavaScript * * @return string */ protected function getJavaScript() { $javaScript = ''; foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/setup/mod/index.php']['setupScriptHook'] ?? [] as $function) { $params = []; $javaScript .= GeneralUtility::callUserFunction($function, $params, $this); } return $javaScript; } /** * Generate the main settings form: */ protected function main() { $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $this->content .= '
'; if ($this->languageUpdate) { $this->moduleTemplate->addJavaScriptCode('languageUpdate', ' if (top && top.TYPO3.ModuleMenu.App) { top.TYPO3.ModuleMenu.App.refreshMenu(); } if (top && top.TYPO3.Backend.Topbar) { top.TYPO3.Backend.Topbar.refresh(); } '); } if ($this->pagetreeNeedsRefresh) { BackendUtility::setUpdateSignal('updatePageTree'); } // Start page: $this->moduleTemplate->getPageRenderer()->addJsFile('EXT:backend/Resources/Public/JavaScript/md5.js'); // Use a wrapper div $this->content .= '
'; $this->content .= $this->moduleTemplate->header($this->getLanguageService()->getLL('UserSettings')); $this->addFlashMessages(); // Render the menu items $menuItems = $this->renderUserSetup(); $this->content .= $this->moduleTemplate->getDynamicTabMenu($menuItems, 'user-setup', 1, false, false); $formToken = $this->formProtection->generateToken('BE user setup', 'edit'); $this->content .= '
'; $this->content .= ' '; $this->content .= '
'; // End of wrapper div $this->content .= '
'; // Setting up the buttons and markers for docheader $this->getButtons(); // Build the for the module // Renders the module page $this->moduleTemplate->setContent($this->content); $this->content .= '
'; } /** * Injects the request object for the current request or subrequest * Simply calls main() and init() and writes the content to the response * * @param ServerRequestInterface $request the current request * @return ResponseInterface the response with the content */ public function mainAction(ServerRequestInterface $request): ResponseInterface { $this->init(); $this->storeIncomingData(); $this->main(); return new HtmlResponse($this->moduleTemplate->renderContent()); } /** * Create the panel of buttons for submitting the form or otherwise perform operations. */ protected function getButtons() { $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); $cshButton = $buttonBar->makeHelpButton() ->setModuleName('_MOD_user_setup') ->setFieldName(''); $buttonBar->addButton($cshButton); $saveButton = $buttonBar->makeInputButton() ->setName('data[save]') ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:rm.saveDoc')) ->setValue('1') ->setForm('SetupModuleController') ->setShowLabelText(true) ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL)); $buttonBar->addButton($saveButton); $shortcutButton = $buttonBar->makeShortcutButton() ->setModuleName($this->moduleName); $buttonBar->addButton($shortcutButton); } /****************************** * * Render module * ******************************/ /** * renders the data for all tabs in the user setup and returns * everything that is needed with tabs and dyntab menu * * @return array Ready to use for the dyntabmenu itemarray */ protected function renderUserSetup() { $backendUser = $this->getBackendUser(); $html = ''; $result = []; $firstTabLabel = ''; $code = []; $fieldArray = $this->getFieldsFromShowItem(); $tabLabel = ''; foreach ($fieldArray as $fieldName) { $config = $GLOBALS['TYPO3_USER_SETTINGS']['columns'][$fieldName]; if (isset($config['access']) && !$this->checkAccess($config)) { continue; } if (strpos($fieldName, '--div--;') === 0) { if ($firstTabLabel === '') { // First tab $tabLabel = $this->getLabel(substr($fieldName, 8), '', false); $firstTabLabel = $tabLabel; } else { $result[] = [ 'label' => $tabLabel, 'content' => count($code) ? implode(LF, $code) : '' ]; $tabLabel = $this->getLabel(substr($fieldName, 8), '', false); $code = []; } continue; } $label = $this->getLabel($config['label'], $fieldName); $label = $this->getCSH($config['csh'] ?: $fieldName, $label); $type = $config['type']; $class = $config['class']; if ($type !== 'check') { $class .= ' form-control'; } $more = ''; if ($class) { $more .= ' class="' . htmlspecialchars($class) . '"'; } $style = $config['style']; if ($style) { $more .= ' style="' . htmlspecialchars($style) . '"'; } if (isset($this->overrideConf[$fieldName])) { $more .= ' disabled="disabled"'; } $value = $config['table'] === 'be_users' ? $backendUser->user[$fieldName] : $backendUser->uc[$fieldName]; if (!$value && isset($config['default'])) { $value = $config['default']; } $dataAdd = ''; if ($config['table'] === 'be_users') { $dataAdd = '[be_users]'; } switch ($type) { case 'text': case 'number': case 'email': case 'password': $noAutocomplete = ''; $maxLength = $config['max'] ?? 0; if ((int)$maxLength > 0) { $more .= ' maxlength="' . (int)$maxLength . '"'; } if ($type === 'password') { $value = ''; $noAutocomplete = 'autocomplete="new-password" '; $more .= ' data-rsa-encryption=""'; } $html = ''; break; case 'check': $html = $label . '
'; $label = ''; break; case 'select': if ($config['itemsProcFunc']) { $html = GeneralUtility::callUserFunction($config['itemsProcFunc'], $config, $this); } else { $html = ''; } break; case 'user': $html = GeneralUtility::callUserFunction($config['userFunc'], $config, $this); break; case 'button': if ($config['onClick']) { $onClick = $config['onClick']; if ($config['onClickLabels']) { foreach ($config['onClickLabels'] as $key => $labelclick) { $config['onClickLabels'][$key] = $this->getLabel($labelclick, '', false); } $onClick = vsprintf($onClick, $config['onClickLabels']); } $html = '
'; } if (!empty($config['confirm'])) { $confirmData = $config['confirmData']; $html = '
'; } break; case 'avatar': // Get current avatar image $html = '
'; $avatarFileUid = $this->getAvatarFileUid($backendUser->user['uid']); if ($avatarFileUid) { $defaultAvatarProvider = GeneralUtility::makeInstance(DefaultAvatarProvider::class); $avatarImage = $defaultAvatarProvider->getImage($backendUser->user, 32); if ($avatarImage) { $icon = '' . '' . ''; $html .= '' . $icon . ' '; } } $html .= ''; $html .= '
'; $iconFactory = GeneralUtility::makeInstance(IconFactory::class); if ($avatarFileUid) { $html .= ''; } $html .= '
'; $this->addAvatarButtonJs($fieldName); break; default: $html = ''; } $code[] = '
' . $label . $html . '
'; } $result[] = [ 'label' => $tabLabel, 'content' => count($code) ? implode(LF, $code) : '' ]; return $result; } /** * Return a select with available languages. * This method is called from the setup module fake TCA userFunc. * * @return string Complete select as HTML string or warning box if something went wrong. */ public function renderLanguageSelect() { $backendUser = $this->getBackendUser(); $language = $this->getLanguageService(); $languageOptions = []; // Compile the languages dropdown $langDefault = htmlspecialchars($language->getLL('lang_default')); $languageOptions[$langDefault] = ''; if (isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lang']['availableLanguages'])) { // Traverse the number of languages $locales = GeneralUtility::makeInstance(Locales::class); $languages = $locales->getLanguages(); foreach ($languages as $locale => $name) { if ($locale !== 'default') { $defaultName = isset($GLOBALS['LOCAL_LANG']['default']['lang_' . $locale]) ? $GLOBALS['LOCAL_LANG']['default']['lang_' . $locale][0]['source'] : $name; $localizedName = htmlspecialchars($language->getLL('lang_' . $locale)); if ($localizedName === '') { $localizedName = htmlspecialchars($name); } $localLabel = ' - [' . htmlspecialchars($defaultName) . ']'; $available = in_array($locale, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lang']['availableLanguages'], true) || is_dir(Environment::getLabelsPath() . '/' . $locale); if ($available) { $languageOptions[$defaultName] = ''; } } } } ksort($languageOptions); $languageCode = ' '; if ($backendUser->uc['lang'] && !@is_dir(Environment::getLabelsPath() . '/' . $backendUser->uc['lang'])) { // TODO: The text constants have to be moved into language files $languageUnavailableWarning = 'The selected language "' . htmlspecialchars($language->getLL('lang_' . $backendUser->uc['lang'])) . '" is not available before the language files are installed.  
  ' . ($backendUser->isAdmin() ? 'You can use the Language module to easily download new language files.' : 'Please ask your system administrator to do this.'); $languageCode = '
' . $languageUnavailableWarning . '

' . $languageCode; } return $languageCode; } /** * Returns a select with all modules for startup. * This method is called from the setup module fake TCA userFunc. * * @return string Complete select as HTML string */ public function renderStartModuleSelect() { // Load available backend modules $backendUser = $this->getBackendUser(); $language = $this->getLanguageService(); $loadModules = GeneralUtility::makeInstance(ModuleLoader::class); $loadModules->observeWorkspaces = true; $loadModules->load($GLOBALS['TBE_MODULES']); $startModuleSelect = ''; foreach ($loadModules->modules as $mainMod => $modData) { if (!empty($modData['sub']) && is_array($modData['sub'])) { $modules = ''; foreach ($modData['sub'] as $subData) { $modName = $subData['name']; $modules .= ''; } $groupLabel = htmlspecialchars($language->sL($loadModules->getLabelsForModule($mainMod)['title'])); $startModuleSelect .= '' . $modules . ''; } } return ''; } /** * Will make the simulate-user selector if the logged in user is administrator. * It will also set the GLOBAL(!) BE_USER to the simulated user selected if any (and set $this->OLD_BE_USER to logged in user) * * @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. */ public function simulateUser() { trigger_error('SetupModuleController->simulateUser() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED); // If admin, allow simulation of another user $this->simUser = 0; $this->simulateSelector = ''; unset($this->OLD_BE_USER); $currentBeUser = $this->getBackendUser(); if ($currentBeUser->isAdmin()) { $this->simUser = (int)GeneralUtility::_GP('simUser'); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users'); $users = $queryBuilder ->select('*') ->from('be_users') ->where( $queryBuilder->expr()->neq( 'uid', $queryBuilder->createNamedParameter($currentBeUser->user['uid'], \PDO::PARAM_INT) ), $queryBuilder->expr()->notLike( 'username', $queryBuilder->createNamedParameter( $queryBuilder->escapeLikeWildcards('_cli_') . '%', \PDO::PARAM_STR ) ) ) ->orderBy('username') ->execute() ->fetchAll(); $opt = []; foreach ($users as $rr) { $label = $rr['username'] . ($rr['realName'] ? ' (' . $rr['realName'] . ')' : ''); $opt[] = ''; } if (!empty($opt)) { $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); $this->simulateSelector = ''; } } // This can only be set if the previous code was executed. if ($this->simUser > 0) { // Save old user... $this->OLD_BE_USER = $currentBeUser; // Unset current // New backend user object $currentBeUser = GeneralUtility::makeInstance(BackendUserAuthentication::class); $currentBeUser->setBeUserByUid($this->simUser); $currentBeUser->fetchGroupData(); $currentBeUser->backendSetUC(); } } /** * Returns access check (currently only "admin" is supported) * * @param array $config Configuration of the field, access mode is defined in key 'access' * @return bool Whether it is allowed to modify the given field */ protected function checkAccess(array $config) { $access = $config['access']; if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['setup']['accessLevelCheck'][$access])) { if (class_exists($access)) { $accessObject = GeneralUtility::makeInstance($access); if (method_exists($accessObject, 'accessLevelCheck')) { // Initialize vars. If method fails, $set will be set to FALSE return $accessObject->accessLevelCheck($config); } } } elseif ($access === 'admin') { return $this->isAdmin; } return false; } /** * Returns the label $str from getLL() and grays out the value if the $str/$key is found in $this->overrideConf array * * @param string $str Locallang key * @param string $key Alternative override-config key * @param bool $addLabelTag Defines whether the string should be wrapped in a