|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Dmitry Dulepov <dmitry@typo3.org> 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 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * [CLASS/FUNCTION INDEX of SCRIPT] 00027 * 00028 * $Id: class.tx_rsaauth_split_storage.php 10120 2011-01-18 20:03:36Z ohader $ 00029 */ 00030 00031 require_once(t3lib_extMgm::extPath('rsaauth', 'sv1/storage/class.tx_rsaauth_abstract_storage.php')); 00032 00033 /** 00034 * This class contains a "split" storage for the data. It keeps part of the data 00035 * in the database, part in the database. 00036 * 00037 * @author Dmitry Dulepov <dmitry@typo3.org> 00038 * @package TYPO3 00039 * @subpackage tx_rsaauth 00040 */ 00041 class tx_rsaauth_split_storage extends tx_rsaauth_abstract_storage { 00042 00043 /** 00044 * Creates an instance of this class. It checks and initializes PHP 00045 * sessions if necessary. 00046 * 00047 * @return void 00048 */ 00049 public function __construct() { 00050 if (!isset($_SESSION) || !is_array($_SESSION)) { 00051 session_start(); 00052 } 00053 } 00054 00055 /** 00056 * Obtains a key from the database 00057 * 00058 * @return string The key or null 00059 * @see tx_rsaauth_abstract_storage::get() 00060 */ 00061 public function get() { 00062 $result = null; 00063 00064 list($keyId, $keyPart1) = $_SESSION['tx_rsaauth_key']; 00065 if (t3lib_div::testInt($keyId)) { 00066 00067 // Remove expired keys (more than 30 minutes old) 00068 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_rsaauth_keys', 00069 'crdate<' . ($GLOBALS['EXEC_TIME'] - 30 * 60)); 00070 00071 // Get our value 00072 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('key_value', 00073 'tx_rsaauth_keys', 'uid=' . $keyId); 00074 if (is_array($row)) { 00075 $result = $keyPart1 . $row['key_value']; 00076 } 00077 } 00078 return $result; 00079 } 00080 00081 /** 00082 * Adds a key to the storage or removes existing key 00083 * 00084 * @param string $key The key 00085 * @return void 00086 * @see tx_rsaauth_abstract_storage::put() 00087 */ 00088 public function put($key) { 00089 if ($key == null) { 00090 // Remove existing key 00091 list($keyId) = $_SESSION['tx_rsaauth_key']; 00092 00093 if (t3lib_div::testInt($keyId)) { 00094 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_rsaauth_keys', 00095 'uid=' . $keyId); 00096 unset($_SESSION['tx_rsaauth_key']); 00097 } 00098 } 00099 else { 00100 // Add key 00101 00102 // Get split point. First part is always smaller than the second 00103 // because it goes to the file system 00104 $keyLength = strlen($key); 00105 $splitPoint = rand(intval($keyLength/10), intval($keyLength/2)); 00106 00107 // Get key parts 00108 $keyPart1 = substr($key, 0, $splitPoint); 00109 $keyPart2 = substr($key, $splitPoint); 00110 00111 // Store part of the key in the database 00112 // 00113 // Notice: we may not use TCEmain below to insert key part into the 00114 // table because TCEmain requires a valid BE user! 00115 $time = $GLOBALS['EXEC_TIME']; 00116 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_rsaauth_keys', array( 00117 'pid' => 0, 00118 'crdate' => $time, 00119 'key_value' => $keyPart2 00120 )); 00121 $keyId = $GLOBALS['TYPO3_DB']->sql_insert_id(); 00122 00123 // Store another part in session 00124 $_SESSION['tx_rsaauth_key'] = array($keyId, $keyPart1); 00125 } 00126 00127 // Remove expired keys (more than 30 minutes old) 00128 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_rsaauth_keys', 00129 'crdate<' . ($GLOBALS['EXEC_TIME'] - 30 * 60)); 00130 } 00131 } 00132 00133 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/storage/class.tx_rsaauth_split_storage.php'])) { 00134 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rsaauth/sv1/storage/class.tx_rsaauth_split_storage.php']); 00135 } 00136 00137 ?>
1.8.0