Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
+82
-3
@@ -68,6 +68,16 @@ abstract class _Cache extends AbstractData
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Needs cache key check with this storage engine to maintain integrity
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkKeys()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store value using cache method if available or falling back to the database
|
||||
*
|
||||
@@ -75,7 +85,7 @@ abstract class _Cache extends AbstractData
|
||||
* @param mixed $value Value
|
||||
* @param \IPS\DateTime $expire Expiration if using database
|
||||
* @param bool $fallback Use database if no caching method is available?
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function storeWithExpire( $key, $value, \IPS\DateTime $expire, $fallback=FALSE )
|
||||
{
|
||||
@@ -83,14 +93,18 @@ abstract class _Cache extends AbstractData
|
||||
|
||||
if ( \IPS\CACHING_LOG )
|
||||
{
|
||||
$this->log[] = array( 'set', $key, version_compare( PHP_VERSION, '5.4.0' ) >= 0 ? json_encode( $value, JSON_PRETTY_PRINT ) : json_encode( $value ), var_export( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), TRUE ) );
|
||||
$this->log[ microtime(true) ] = array( 'set', $key, version_compare( PHP_VERSION, '5.4.0' ) >= 0 ? json_encode( $value, JSON_PRETTY_PRINT ) : json_encode( $value ), var_export( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), TRUE ) );
|
||||
}
|
||||
|
||||
if ( $this->set( $key, json_encode( $value ), $expire ) )
|
||||
if ( $this->set( $key, $this->encode( $value ), $expire ) )
|
||||
{
|
||||
$this->_data[ $key ] = $value;
|
||||
$this->_exists[ $key ] = $key;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,4 +156,69 @@ abstract class _Cache extends AbstractData
|
||||
does not allow us to actually clear them */
|
||||
\IPS\Data\Store::i()->cacheKeys = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encryption key
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _encryptionKey()
|
||||
{
|
||||
$password = \IPS\Settings::i()->sql_pass;
|
||||
if ( function_exists( 'openssl_digest' ) and in_array( 'sha256', openssl_get_md_methods() ) )
|
||||
{
|
||||
$password = openssl_digest( $password, 'sha256', TRUE );
|
||||
}
|
||||
return $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode
|
||||
*
|
||||
* @param mixed $value Value
|
||||
* @return string
|
||||
*/
|
||||
protected function encode( $value )
|
||||
{
|
||||
$value = json_encode( $value );
|
||||
|
||||
if ( function_exists( 'openssl_encrypt' ) and in_array( 'aes-256-ctr', openssl_get_cipher_methods() ) )
|
||||
{
|
||||
$iv = \IPS\Login::generateRandomString( 16 );
|
||||
$value = $iv . openssl_encrypt( $value, 'aes-256-ctr', $this->_encryptionKey(), OPENSSL_RAW_DATA, $iv );
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode
|
||||
*
|
||||
* @param mixed $value Value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function decode( $value )
|
||||
{
|
||||
if ( function_exists( 'openssl_encrypt' ) and in_array( 'aes-256-ctr', openssl_get_cipher_methods() ) )
|
||||
{
|
||||
$value = @openssl_decrypt( \substr( $value, 16 ), 'aes-256-ctr', $this->_encryptionKey(), OPENSSL_RAW_DATA, \substr( $value, 0, 16 ) );
|
||||
}
|
||||
|
||||
return json_decode( $value, TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic Method: Isset
|
||||
*
|
||||
* @param string $key Key
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset( $key )
|
||||
{
|
||||
if ( parent::__isset( $key ) )
|
||||
{
|
||||
return ( is_array( $this->$key ) or $this->$key === 0 ) ? true : (bool) $this->$key;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user