|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) Steffen Ritter (info@rs-websystems.de) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 // Make sure that we are executed only in TYPO3 context 00028 if (!defined ('TYPO3_MODE')) die ('Access denied.'); 00029 00030 00031 /** 00032 * class providing configuration checks for saltedpasswords. 00033 * 00034 * @author Steffen Ritter <info@rs-websystems.de> 00035 * 00036 * @since 2009-09-04 00037 * @package TYPO3 00038 * @subpackage tx_saltedpasswords 00039 */ 00040 class tx_saltedpasswords_emconfhelper { 00041 /** 00042 * @var integer 00043 */ 00044 protected $errorType = t3lib_FlashMessage::OK; 00045 00046 /** 00047 * @var string 00048 */ 00049 protected $header; 00050 00051 /** 00052 * @var string 00053 */ 00054 protected $preText; 00055 00056 /* 00057 * @var array 00058 */ 00059 protected $problems = array(); 00060 00061 /** 00062 * Set the error level if no higher level 00063 * is set already 00064 * 00065 * @param string $level: one out of error, ok, warning, info 00066 * @return void 00067 */ 00068 private function setErrorLevel($level) { 00069 00070 switch ($level) { 00071 case 'error': 00072 $this->errorType = t3lib_FlashMessage::ERROR; 00073 $this->header = 'Errors found in your configuration'; 00074 $this->preText = 'SaltedPasswords will not work until these problems have been resolved:<br />'; 00075 break; 00076 case 'warning': 00077 if ($this->errorType < t3lib_FlashMessage::ERROR) { 00078 $this->errorType = t3lib_FlashMessage::WARNING; 00079 $this->header = 'Warnings about your configuration'; 00080 $this->preText = 'SaltedPasswords might behave different than expectated:<br />'; 00081 } 00082 break; 00083 case 'info': 00084 if ($this->errorType < t3lib_FlashMessage::WARNING) { 00085 $this->errorType = t3lib_FlashMessage::INFO; 00086 $this->header = 'Additional information'; 00087 $this->preText = '<br />'; 00088 } 00089 break; 00090 case 'ok': 00091 // TODO: Remove INFO condition as it has lower importance 00092 if ($this->errorType < t3lib_FlashMessage::WARNING && $this->errorType != t3lib_FlashMessage::INFO) { 00093 $this->errorType = t3lib_FlashMessage::OK; 00094 $this->header = 'No errors were found'; 00095 $this->preText = 'SaltedPasswords has been configured correctly and works as expected.<br />'; 00096 } 00097 break; 00098 } 00099 } 00100 00101 /** 00102 * Renders the flash messages if problems have been found. 00103 * 00104 * @return string The flash message as HTML. 00105 */ 00106 private function renderFlashMessage() { 00107 $message = ''; 00108 // if there are problems, render them into an unordered list 00109 if (count($this->problems) > 0) { 00110 $message = <<< EOT 00111 <ul> 00112 <li>###PROBLEMS###</li> 00113 </ul> 00114 EOT; 00115 $message = str_replace('###PROBLEMS###', implode('<br /> </li><li>', $this->problems), $message); 00116 00117 if ($this->errorType > t3lib_FlashMessage::OK) { 00118 $message .= <<< EOT 00119 <br /> 00120 Note, that a wrong configuration might have impact on the security of 00121 your TYPO3 installation and the usability of the backend. 00122 EOT; 00123 } 00124 } 00125 00126 if (empty($message)) { 00127 $this->setErrorLevel('ok'); 00128 } 00129 00130 $message = $this->preText . $message; 00131 $flashMessage = t3lib_div::makeInstance('t3lib_FlashMessage', $message, $this->header, $this->errorType); 00132 00133 return $flashMessage->render(); 00134 } 00135 00136 /** 00137 * Initializes this object. 00138 * 00139 * @return void 00140 */ 00141 private function init() { 00142 $requestSetup = $this->processPostData((array)$_REQUEST['data']); 00143 $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['saltedpasswords']); 00144 $this->extConf['BE'] = array_merge((array)$extConf['BE.'], (array)$requestSetup['BE.']); 00145 $this->extConf['FE'] = array_merge((array)$extConf['FE.'], (array)$requestSetup['FE.']); 00146 $GLOBALS['LANG']->includeLLFile('EXT:saltedpasswords/locallang.xml'); 00147 } 00148 00149 /** 00150 * Checks the backend configuration and shows a message if necessary. 00151 * 00152 * @param array $params: Field information to be rendered 00153 * @param t3lib_tsStyleConfig $pObj: The calling parent object. 00154 * @return string Messages as HTML if something needs to be reported 00155 */ 00156 public function checkConfigurationBackend(array $params, t3lib_tsStyleConfig $pObj) { 00157 $this->init(); 00158 $extConf = $this->extConf['BE']; 00159 00160 // the backend is called over SSL 00161 $SSL = (($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] > 0 ? TRUE : FALSE) && ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] != 'superchallenged')); 00162 // rsaAuth is loaded/active 00163 $RSAauth = (t3lib_extMgm::isLoaded('rsaauth') && ($GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] == 'rsa')); 00164 00165 if ($extConf['enabled']) { 00166 // SSL configured? 00167 if ($SSL) { 00168 $this->setErrorLevel('ok'); 00169 $problems[] = 'The backend is configured to use SaltedPasswords over SSL.'; 00170 } elseif ($RSAauth) { 00171 $this->setErrorLevel('ok'); 00172 $problems[] = 'The backend is configured to use SaltedPasswords with RSA authentification.'; 00173 } else { 00174 $this->setErrorLevel('error'); 00175 $problems[] = <<< EOT 00176 Backend requirements for SaltedPasswords are not met, therefore the 00177 authentication will not work even if it was explicitely enabled for backend 00178 usage:<br /> 00179 <ul> 00180 <li>Install the "rsaauth" extension and use the Install Tool to set the 00181 Login Security Level for the backend to "rsa" 00182 (\$TYPO3_CONF_VARS['BE']['loginSecurityLevel'])</li> 00183 00184 <li>If you have the option to use SSL, you can also configure your 00185 backend for SSL usage:<br /> 00186 Use the Install Tool to set the Security-Level for the backend 00187 to "normal" (\$TYPO3_CONF_VARS['BE']['loginSecurityLevel']) and 00188 the SSL-locking option to a value greater than "0" 00189 (see description - \$TYPO3_CONF_VARS['BE']['lockSSL'])</li> 00190 </ul> 00191 <br /> 00192 It is also possible to use "lockSSL" and "rsa" Login Security Level at the same 00193 time. 00194 EOT; 00195 } 00196 00197 // only saltedpasswords as authsservice 00198 if ($extConf['onlyAuthService']) { 00199 // warn user taht the combination with "forceSalted" may lock him out from Backend 00200 if ($extConf['forceSalted']) { 00201 $this->setErrorLevel('warning'); 00202 $problems[] = <<< EOT 00203 SaltedPasswords has been configured to be the only authentication service for 00204 the backend. Additionally, usage of salted passwords is enforced (forceSalted). 00205 The result is that there is no chance to login with users not having a salted 00206 password hash.<br /> 00207 <strong><i>WARNING:</i></strong> This may lock you out of the backend! 00208 EOT; 00209 } else { 00210 // inform the user that things like openid won't work anymore 00211 $this->setErrorLevel('info'); 00212 $problems[] = <<< EOT 00213 SaltedPasswords has been configured to be the only authentication service for 00214 the backend. This means that other services like "ipauth", "openid", etc. will 00215 be ignored (except "rsauth", which is implicitely used). 00216 EOT; 00217 } 00218 } 00219 // forceSalted is set 00220 if ($extConf['forceSalted'] && !$extConf['onlyAuthService']) { 00221 $this->setErrorLevel('warning'); 00222 $problems[] = <<< EOT 00223 SaltedPasswords has been configured to enforce salted passwords (forceSalted). 00224 <br /> 00225 This means that only passwords in the format of this extension will succeed for 00226 login.<br /> 00227 <strong><i>IMPORTANT:</i></strong> This has the effect that passwords that are set from 00228 the Install Tool will not work! 00229 EOT; 00230 } 00231 // updatePasswd wont work with "forceSalted" 00232 if ($extConf['updatePasswd'] && $extConf['forceSalted']) { 00233 $this->setErrorLevel('error'); 00234 $problems[] = <<< EOT 00235 SaltedPasswords is configured wrong and will not work as expected:<br /> 00236 It is not possible to set "updatePasswd" and "forceSalted" at the same time. 00237 Please disable either one of them. 00238 EOT; 00239 } 00240 // check if the configured hash-method is available on system 00241 if (!$instance = tx_saltedpasswords_salts_factory::getSaltingInstance(NULL,'BE') || !$instance->isAvailable()) { 00242 $this->setErrorLevel('error'); 00243 $problems[] = <<< EOT 00244 The selected method for hashing your salted passwords is not available on this 00245 system! Please check your configuration. 00246 EOT; 00247 } 00248 00249 } else { 00250 // not enabled warning 00251 $this->setErrorLevel('info'); 00252 $problems[] = 'SaltedPasswords has been disabled for backend users.'; 00253 } 00254 00255 $this->problems = $problems; 00256 00257 return $this->renderFlashMessage(); 00258 } 00259 00260 /** 00261 * Checks the frontend configuration and shows a message if necessary. 00262 * 00263 * @param array $params: Field information to be rendered 00264 * @param t3lib_tsStyleConfig $pObj: The calling parent object. 00265 * @return string Messages as HTML if something needs to be reported 00266 */ 00267 public function checkConfigurationFrontend(array $params, t3lib_tsStyleConfig $pObj) { 00268 $this->init(); 00269 $extConf = $this->extConf['FE']; 00270 00271 if ($extConf['enabled']) { 00272 // inform the user if securityLevel in FE is superchallenged or blank --> extension won't work 00273 if (!t3lib_div::inList('normal,rsa', $GLOBALS['TYPO3_CONF_VARS']['FE']['loginSecurityLevel'])) { 00274 $this->setErrorLevel('info'); 00275 $problems[] = <<< EOT 00276 <strong>IMPORTANT:</strong><br /> 00277 Frontend requirements for SaltedPasswords are not met, therefore the 00278 authentication will not work even if it was explicitely enabled for frontend 00279 usage:<br /> 00280 <ul> 00281 <li>Install the "rsaauth" extension and use the Install Tool to set the 00282 Login Security Level for the frontend to "rsa" 00283 (\$TYPO3_CONF_VARS['FE']['loginSecurityLevel'])</li> 00284 00285 <li>Alternatively, use the Install Tool to set the Login Security Level 00286 for the frontend to "normal" 00287 (\$TYPO3_CONF_VARS['FE']['loginSecurityLevel'])</li> 00288 </ul> 00289 <br /> 00290 Make sure that the Login Security Level is not set to "" or "superchallenged"! 00291 EOT; 00292 } 00293 // only saltedpasswords as authsservice 00294 if ($extConf['onlyAuthService']) { 00295 // warn user taht the combination with "forceSalted" may lock him out from frontend 00296 if ($extConf['forceSalted']) { 00297 $this->setErrorLevel('warning'); 00298 $problems[] = <<< EOT 00299 SaltedPasswords has been configured to enforce salted passwords (forceSalted). 00300 <br /> 00301 This means that only passwords in the format of this extension will succeed for 00302 login.<br /> 00303 <strong><i>IMPORTANT:</i></strong> Because of this, it is not possible to login with 00304 users not having a salted password hash (e.g. existing frontend users). 00305 EOT; 00306 } else { 00307 // inform the user that things like openid won't work anymore 00308 $this->setErrorLevel('info'); 00309 $problems[] = <<< EOT 00310 SaltedPasswords has been configured to be the only authentication service for 00311 frontend logins. This means that other services like "ipauth", "openid", etc. 00312 will be ignored. 00313 EOT; 00314 } 00315 } 00316 // forceSalted is set 00317 if ($extConf['forceSalted'] && !$extConf['onlyAuthService']) { 00318 $this->setErrorLevel('warning'); 00319 $problems[] = <<< EOT 00320 SaltedPasswords has been configured to enforce salted passwords (forceSalted). 00321 <br /> 00322 This means that only passwords in the format of this extension will succeed for 00323 login.<br /> 00324 <strong><i>IMPORTANT:</i></strong> This has the effect that passwords that were set 00325 before SaltedPasswords was used will not work (in fact, they need to be 00326 redefined). 00327 EOT; 00328 } 00329 // updatePasswd wont work with "forceSalted" 00330 if ($extConf['updatePasswd'] && $extConf['forceSalted']) { 00331 $this->setErrorLevel('error'); 00332 $problems[] = <<< EOT 00333 SaltedPasswords is configured wrong and will not work as expected:<br /> 00334 It is not possible to set "updatePasswd" and "forceSalted" at the same time. 00335 Please disable either one of them. 00336 EOT; 00337 } 00338 00339 } else { 00340 // not enabled warning 00341 $this->setErrorLevel('info'); 00342 $problems[] = 'SaltedPasswords has been disabled for frontend users.'; 00343 } 00344 00345 $this->problems = $problems; 00346 00347 return $this->renderFlashMessage(); 00348 } 00349 00350 /** 00351 * Renders a selector element that allows to select the hash method to be used. 00352 * 00353 * @param array $params: Field information to be rendered 00354 * @param t3lib_tsStyleConfig $pObj: The calling parent object. 00355 * @param string $disposal: The configuration disposal ('FE' or 'BE') 00356 * @return string The HTML selector 00357 */ 00358 protected function buildHashMethodSelector(array $params, t3lib_tsStyleConfig $pObj, $disposal) { 00359 $this->init(); 00360 $fieldName = substr($params['fieldName'], 5, -1); 00361 $unknownVariablePleaseRenameMe = '\'' . substr(md5($fieldName), 0, 10) . '\''; 00362 00363 $p_field = ''; 00364 00365 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/saltedpasswords']['saltMethods'] as $class => $reference) { 00366 $classInstance = t3lib_div::getUserObj($reference, 'tx_'); 00367 00368 if ($classInstance instanceof tx_saltedpasswords_salts && $classInstance->isAvailable()) { 00369 $sel = ($this->extConf[$disposal]['saltedPWHashingMethod'] == $class) ? ' selected="selected" ' : ''; 00370 $label = 'ext.saltedpasswords.title.' . $class; 00371 $p_field .= '<option value="' . htmlspecialchars($class) . '"' . $sel . '>' . $GLOBALS['LANG']->getLL($label) . '</option>'; 00372 } 00373 } 00374 00375 $p_field = '<select id="' . $fieldName . '" name="' . $params['fieldName'] . '" onChange="uFormUrl(' . $unknownVariablePleaseRenameMe . ')">' . $p_field . '</select>'; 00376 00377 return $p_field; 00378 } 00379 00380 /** 00381 * Renders a selector element that allows to select the hash method to be used (frontend disposal). 00382 * 00383 * @param array $params: Field information to be rendered 00384 * @param t3lib_tsStyleConfig $pObj: The calling parent object. 00385 * @return string The HTML selector 00386 */ 00387 public function buildHashMethodSelectorFE(array $params, t3lib_tsStyleConfig $pObj) { 00388 return $this->buildHashMethodSelector($params, $pObj, 'FE'); 00389 } 00390 00391 /** 00392 * Renders a selector element that allows to select the hash method to be used (backend disposal) 00393 * 00394 * @param array $params: Field information to be rendered 00395 * @param t3lib_tsStyleConfig $pObj: The calling parent object. 00396 * @return string The HTML selector 00397 */ 00398 public function buildHashMethodSelectorBE(array $params, t3lib_tsStyleConfig $pObj) { 00399 return $this->buildHashMethodSelector($params, $pObj, 'BE'); 00400 } 00401 00402 /** 00403 * Processes the information submitted by the user using a POST request and 00404 * transforms it to a TypoScript node notation. 00405 * 00406 * @param array $postArray: Incoming POST information 00407 * @return array Processed and transformed POST information 00408 */ 00409 private function processPostData(array $postArray = array()) { 00410 foreach ($postArray as $key => $value) { 00411 // TODO: Explain 00412 $parts = explode('.', $key, 2); 00413 00414 if (count($parts)==2) { 00415 // TODO: Explain 00416 $value = $this->processPostData(array($parts[1] => $value)); 00417 $postArray[$parts[0].'.'] = array_merge((array)$postArray[$parts[0].'.'], $value); 00418 } else { 00419 // TODO: Explain 00420 $postArray[$parts[0]] = $value; 00421 } 00422 } 00423 00424 return $postArray; 00425 } 00426 00427 } 00428 00429 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php'])) { 00430 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/saltedpasswords/classes/class.tx_saltedpasswords_emconfhelper.php']); 00431 } 00432 ?>
1.8.0