Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
+43
-14
@@ -51,6 +51,11 @@ class _Redis
|
||||
* @brief Unpack the config once
|
||||
*/
|
||||
protected static $config = NULL;
|
||||
|
||||
/**
|
||||
* @brief Can we encrypt?
|
||||
*/
|
||||
protected $canEncrypt = FALSE;
|
||||
|
||||
/**
|
||||
* Get instance
|
||||
@@ -77,6 +82,16 @@ class _Redis
|
||||
/* Return */
|
||||
return static::$multitons[ $identifier ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->canEncrypt = \IPS\REDIS_ENCRYPT === TRUE and function_exists( 'openssl_encrypt' ) and in_array( 'aes-256-ctr', openssl_get_cipher_methods() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to Redis
|
||||
@@ -84,7 +99,7 @@ class _Redis
|
||||
* @param string $identifier
|
||||
* @return \Redis
|
||||
*/
|
||||
protected function connection( $identifier=NULL )
|
||||
public function connection( $identifier=NULL )
|
||||
{
|
||||
if ( ! class_exists('Redis') )
|
||||
{
|
||||
@@ -173,6 +188,9 @@ class _Redis
|
||||
{
|
||||
$connection->close();
|
||||
}
|
||||
|
||||
/* Reset stored connections so they can be re-connected correctly if tasks run after this shutdown proceses */
|
||||
static::$connections = array();
|
||||
}
|
||||
catch( \RedisException $e ){}
|
||||
}, $this );
|
||||
@@ -294,7 +312,7 @@ class _Redis
|
||||
*/
|
||||
public function sort( $key, $options=array() )
|
||||
{
|
||||
$return = static::connection('write')->sort( $this->key( $key ), $options );
|
||||
$return = $this->connection('write')->sort( $this->key( $key ), $options );
|
||||
|
||||
if ( isset( $options['store'] ) )
|
||||
{
|
||||
@@ -319,7 +337,7 @@ class _Redis
|
||||
public function hGetAll( $key )
|
||||
{
|
||||
/* Make sure we read */
|
||||
$return = static::connection('read')->hGetAll( $this->key( $key ) );
|
||||
$return = $this->connection('read')->hGetAll( $this->key( $key ) );
|
||||
|
||||
if ( \IPS\REDIS_LOG )
|
||||
{
|
||||
@@ -370,6 +388,11 @@ class _Redis
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cached encryption key
|
||||
*/
|
||||
protected $encryptionKey = NULL;
|
||||
|
||||
/**
|
||||
* Encryption key
|
||||
@@ -378,12 +401,18 @@ class _Redis
|
||||
*/
|
||||
protected function _encryptionKey()
|
||||
{
|
||||
$password = \IPS\Settings::i()->sql_pass;
|
||||
if( $this->encryptionKey !== NULL )
|
||||
{
|
||||
return $this->encryptionKey;
|
||||
}
|
||||
|
||||
$this->encryptionKey = \IPS\Settings::i()->sql_pass;
|
||||
if ( function_exists( 'openssl_digest' ) and in_array( 'sha256', openssl_get_md_methods() ) )
|
||||
{
|
||||
$password = openssl_digest( $password, 'sha256', TRUE );
|
||||
$this->encryptionKey = openssl_digest( $this->encryptionKey, 'sha256', TRUE );
|
||||
}
|
||||
return $password;
|
||||
|
||||
return $this->encryptionKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,7 +425,7 @@ class _Redis
|
||||
{
|
||||
$value = json_encode( $value );
|
||||
|
||||
if ( function_exists( 'openssl_encrypt' ) and in_array( 'aes-256-ctr', openssl_get_cipher_methods() ) )
|
||||
if ( $this->canEncrypt )
|
||||
{
|
||||
$iv = \IPS\Login::generateRandomString( 16 );
|
||||
$value = $iv . openssl_encrypt( $value, 'aes-256-ctr', $this->_encryptionKey(), OPENSSL_RAW_DATA, $iv );
|
||||
@@ -413,7 +442,7 @@ class _Redis
|
||||
*/
|
||||
public function decode( $value )
|
||||
{
|
||||
if ( function_exists( 'openssl_encrypt' ) and in_array( 'aes-256-ctr', openssl_get_cipher_methods() ) )
|
||||
if ( $this->canEncrypt )
|
||||
{
|
||||
$value = @openssl_decrypt( \substr( $value, 16 ), 'aes-256-ctr', $this->_encryptionKey(), OPENSSL_RAW_DATA, \substr( $value, 0, 16 ) );
|
||||
}
|
||||
@@ -497,20 +526,20 @@ class _Redis
|
||||
switch( $type )
|
||||
{
|
||||
case \Redis::REDIS_STRING:
|
||||
$return[ $key . '(' . $ttl . ')' ] = \IPS\Redis::i()->decode( $this->connection('write')->get( $key ) );
|
||||
$return[ $key . ' (TTL: ' . $ttl . ')' ] = \IPS\Redis::i()->decode( $this->connection('write')->get( $key ) );
|
||||
break;
|
||||
case \Redis::REDIS_ZSET:
|
||||
$return[ $key . '(' . $ttl . ')' ] = $this->connection('write')->zRange( $key, 0, -1, TRUE );
|
||||
$return[ $key . ' (TTL: ' . $ttl . ')' ] = $this->connection('write')->zRange( $key, 0, -1, TRUE );
|
||||
break;
|
||||
case \Redis::REDIS_HASH:
|
||||
$return[ $key . '(' . $ttl . ')' ] = $this->connection('write')->hGetAll( $key );
|
||||
if ( isset( $return[ $key . '(' . $ttl . ')' ]['data'] ) )
|
||||
$return[ $key . ' (TTL: ' . $ttl . ')' ] = $this->connection('write')->hGetAll( $key );
|
||||
if ( isset( $return[ $key . ' (TTL: ' . $ttl . ')' ]['data'] ) )
|
||||
{
|
||||
$return[ $key . '(' . $ttl . ')' ]['data'] = \IPS\Redis::i()->decode( $return[ $key . '(' . $ttl . ')' ]['data'] );
|
||||
$return[ $key . ' (TTL: ' . $ttl . ')' ]['data'] = \IPS\Redis::i()->decode( $return[ $key . ' (TTL: ' . $ttl . ')' ]['data'] );
|
||||
}
|
||||
break;
|
||||
case \Redis::REDIS_LIST:
|
||||
$return[ $key . '(' . $ttl . ')' ] = $this->connection('write')->lRange( $key, 0, -1 );
|
||||
$return[ $key . ' (TTL: ' . $ttl . ')' ] = $this->connection('write')->lRange( $key, 0, -1 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user