/** * Checks if service is available. In case of this service we check that * following prerequesties are fulfilled: * - loginSecurityLevel of according TYPO3_MODE is set to normal * * @return bool TRUE if service is available */ public function init() { $available = FALSE; $mode = TYPO3_MODE; if ($this->info['requestedServiceSubType'] === 'authUserBE') { $mode = 'BE'; } elseif ($this->info['requestedServiceSubType'] === 'authUserFE') { $mode = 'FE'; } if (\TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled($mode)) { $available = TRUE; $this->extConf = \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::returnExtConf(); } return $available ? parent::init() : FALSE; }
/** * @test */ public function doesReturnExtConfReturnMergedSettingsIfExtensionConfigurationIsFound() { $setting = array('setting' => 1); $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords'] = serialize(array('TEST_MODE.' => $setting)); $this->assertEquals(array_merge(\TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::returnExtConfDefaults(), $setting), \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::returnExtConf('TEST_MODE')); }
/** * Parses mapping settings and builds an array holding the query fields information. * * @return array The query fields */ protected function parseFields() { $queryFields = []; //parse mapping foreach ($this->settings['fields.'] as $fieldname => $options) { $fieldname = str_replace('.', '', $fieldname); if (isset($options) && is_array($options)) { if (!isset($options['special'])) { $mapping = $options['mapping']; //if no mapping default to the name of the form field if (!$mapping) { $mapping = $fieldname; } $fieldValue = $this->utilityFuncs->getGlobal($mapping, $this->gp); //pre process the field value. e.g. to format a date if (isset($options['preProcessing.']) && is_array($options['preProcessing.'])) { if (!isset($options['preProcessing.']['value'])) { $options['preProcessing.']['value'] = $fieldValue; } $fieldValue = $this->utilityFuncs->getSingle($options, 'preProcessing'); } if (isset($options['mapping.']) && is_array($options['mapping.'])) { if (!isset($options['mapping.']['value'])) { $options['mapping.']['value'] = $fieldValue; } $fieldValue = $this->utilityFuncs->getSingle($options, 'mapping'); } //process empty value handling if (isset($options['ifIsEmpty']) && strlen($fieldValue) === 0) { $fieldValue = $this->utilityFuncs->getSingle($options, 'ifIsEmpty'); } if (intval($this->utilityFuncs->getSingle($options, 'zeroIfEmpty')) === 1 && strlen($fieldValue) === 0) { $fieldValue = 0; } //process array handling if (is_array($fieldValue)) { $separator = ','; if ($options['separator']) { $separator = $this->utilityFuncs->getSingle($options, 'separator'); } $fieldValue = implode($separator, $fieldValue); } //process uploaded files $files = $this->globals->getSession()->get('files'); if (isset($files[$fieldname]) && is_array($files[$fieldname])) { $fieldValue = $this->getFileList($files, $fieldname); } } else { switch ($options['special']) { case 'saltedpassword': $field = $this->utilityFuncs->getSingle($options['special.'], 'field'); $saltedpasswords = SaltedPasswordsUtility::returnExtConf(); $tx_saltedpasswords = GeneralUtility::makeInstance($saltedpasswords['saltedPWHashingMethod']); $encryptedPassword = $tx_saltedpasswords->getHashedPassword($this->gp[$field]); $fieldValue = $encryptedPassword; break; case 'files': $field = $this->utilityFuncs->getSingle($options['special.'], 'field'); if (isset($options['special.']['separator'])) { $separator = $this->utilityFuncs->getSingle($options['special.'], 'separator'); } else { $separator = ','; } $filesArray = []; if (isset($options['special.']['info'])) { $info = $this->utilityFuncs->getSingle($options['special.'], 'info'); } else { $info = '[uploaded_name]'; } $files = $this->globals->getSession()->get('files'); if (isset($files[$field]) && is_array($files[$field])) { foreach ($files[$field] as $idx => $file) { $infoString = $info; foreach ($file as $infoKey => $infoValue) { $infoString = str_replace('[' . $infoKey . ']', $infoValue, $infoString); } array_push($filesArray, $infoString); } } if (isset($options['special.']['index'])) { $index = $this->utilityFuncs->getSingle($options['special.'], 'index'); if (isset($filesArray[$index])) { $fieldValue = $filesArray[$index]; } } else { $fieldValue = implode($separator, $filesArray); } break; case 'date': $field = $this->utilityFuncs->getSingle($options['special.'], 'field'); $date = $this->gp[$field]; $dateFormat = 'Y-m-d'; if ($options['special.']['dateFormat']) { $dateFormat = $this->utilityFuncs->getSingle($options['special.'], 'dateFormat'); } elseif ($options['special.']['format']) { $dateFormat = $this->utilityFuncs->getSingle($options['special.'], 'format'); } $fieldValue = $this->utilityFuncs->dateToTimestamp($date, $dateFormat); break; case 'datetime': if (version_compare(PHP_VERSION, '5.3.0') < 0) { $this->utilityFuncs->throwException('error_datetime'); } $field = $this->utilityFuncs->getSingle($options['special.'], 'field'); $date = $this->gp[$field]; $dateFormat = 'Y-m-d H:i:s'; if ($options['special.']['dateFormat']) { $dateFormat = $this->utilityFuncs->getSingle($options['special.'], 'dateFormat'); } elseif ($options['special.']['format']) { $dateFormat = $this->utilityFuncs->getSingle($options['special.'], 'format'); } $fieldValue = $this->utilityFuncs->dateToTimestamp($date, $dateFormat); break; case 'sub_datetime': $dateFormat = 'Y-m-d H:i:s'; if ($options['special.']['dateFormat']) { $dateFormat = $this->utilityFuncs->getSingle($options['special.'], 'dateFormat'); } elseif ($options['special.']['format']) { $dateFormat = $this->utilityFuncs->getSingle($options['special.'], 'format'); } $fieldValue = date($dateFormat, time()); break; case 'sub_tstamp': $fieldValue = time(); break; case 'ip': $fieldValue = GeneralUtility::getIndpEnv('REMOTE_ADDR'); break; case 'inserted_uid': $table = $this->utilityFuncs->getSingle($options['special.'], 'table'); if (is_array($this->gp['saveDB'])) { foreach ($this->gp['saveDB'] as $idx => $info) { if ($info['table'] === $table) { $fieldValue = $info['uid']; } } } break; } } } else { $fieldValue = $options; } //post process the field value after formhandler did it's magic. if (isset($options['postProcessing.']) && is_array($options['postProcessing.'])) { if (!isset($options['postProcessing.']['value'])) { $options['postProcessing.']['value'] = $fieldValue; } $fieldValue = $this->utilityFuncs->getSingle($options, 'postProcessing'); } $queryFields[$fieldname] = $fieldValue; if (intval($this->utilityFuncs->getSingle($options, 'nullIfEmpty')) === 1 && strlen($queryFields[$fieldname]) == 0) { unset($queryFields[$fieldname]); } } return $queryFields; }
/** * Check and validate field of type "input" * * @param string $field * @param string|array $val * @return string */ public function checkFieldFromTcaInput($field, $val) { $config = $this->getFieldConfig($field); if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($config['eval'], 'password')) { if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('saltedpasswords') && $GLOBALS['TYPO3_CONF_VARS']['FE']['loginSecurityLevel']) { $saltedpasswords = \TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::returnExtConf(); if ($saltedpasswords['enabled']) { $txSaltedpasswords = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($saltedpasswords['saltedPWHashingMethod']); $val = $txSaltedpasswords->getHashedPassword($val); } } } return $val; }