First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
151
sites/all/modules/civicrm/packages/IDS/Caching/Apc.php
Normal file
151
sites/all/modules/civicrm/packages/IDS/Caching/Apc.php
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
require_once 'IDS/Caching/Interface.php';
|
||||
|
||||
/**
|
||||
* APC caching wrapper
|
||||
*
|
||||
* This class inhabits functionality to get and set cache via memcached.
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Yves Berkholz <godzilla80@gmx.net>
|
||||
* @copyright 2007-2009 The PHPIDS Groupoup
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @version Release: $Id$
|
||||
* @link http://php-ids.org/
|
||||
* @since Version 0.6.5
|
||||
*/
|
||||
class IDS_Caching_Apc implements IDS_Caching_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Caching type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = null;
|
||||
|
||||
/**
|
||||
* Cache configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* Flag if the filter storage has been found in memcached
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $isCached = false;
|
||||
|
||||
/**
|
||||
* Holds an instance of this class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $cachingInstance = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param array $init the IDS_Init object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $init)
|
||||
{
|
||||
|
||||
$this->type = $type;
|
||||
$this->config = $init->config['Caching'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of this class
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public static function getInstance($type, $init)
|
||||
{
|
||||
|
||||
if (!self::$cachingInstance) {
|
||||
self::$cachingInstance = new IDS_Caching_Apc($type, $init);
|
||||
}
|
||||
|
||||
return self::$cachingInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes cache data
|
||||
*
|
||||
* @param array $data the caching data
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public function setCache(array $data)
|
||||
{
|
||||
if(!$this->isCached)
|
||||
apc_store($this->config['key_prefix'] . '.storage',
|
||||
$data, $this->config['expiration_time']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached data
|
||||
*
|
||||
* Note that this method returns false if either type or file cache is
|
||||
* not set
|
||||
*
|
||||
* @return mixed cache data or false
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
$data = apc_fetch($this->config['key_prefix'] . '.storage');
|
||||
$this->isCached = !empty($data);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
291
sites/all/modules/civicrm/packages/IDS/Caching/Database.php
Normal file
291
sites/all/modules/civicrm/packages/IDS/Caching/Database.php
Normal file
|
@ -0,0 +1,291 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
require_once 'IDS/Caching/Interface.php';
|
||||
|
||||
/**
|
||||
* Needed SQL:
|
||||
*
|
||||
|
||||
#create the database
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS `phpids` DEFAULT CHARACTER
|
||||
SET utf8 COLLATE utf8_general_ci;
|
||||
DROP TABLE IF EXISTS `cache`;
|
||||
|
||||
#now select the created datbase and create the table
|
||||
|
||||
CREATE TABLE `cache` (
|
||||
`type` VARCHAR( 32 ) NOT null ,
|
||||
`data` TEXT NOT null ,
|
||||
`created` DATETIME NOT null ,
|
||||
`modified` DATETIME NOT null
|
||||
) ENGINE = MYISAM ;
|
||||
*/
|
||||
|
||||
/**
|
||||
* Database caching wrapper
|
||||
*
|
||||
* This class inhabits functionality to get and set cache via a database.
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @copyright 2007-2009 The PHPIDS Groupup
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @version Release: $Id:Database.php 517 2007-09-15 15:04:13Z mario $
|
||||
* @link http://php-ids.org/
|
||||
* @since Version 0.4
|
||||
*/
|
||||
class IDS_Caching_Database implements IDS_Caching_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Caching type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = null;
|
||||
|
||||
/**
|
||||
* Cache configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* DBH
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $handle = null;
|
||||
|
||||
/**
|
||||
* Holds an instance of this class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $cachingInstance = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Connects to database.
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $init)
|
||||
{
|
||||
|
||||
$this->type = $type;
|
||||
$this->config = $init->config['Caching'];
|
||||
$this->handle = $this->_connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of this class
|
||||
*
|
||||
* @static
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public static function getInstance($type, $init)
|
||||
{
|
||||
|
||||
if (!self::$cachingInstance) {
|
||||
self::$cachingInstance = new IDS_Caching_Database($type, $init);
|
||||
}
|
||||
return self::$cachingInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes cache data into the database
|
||||
*
|
||||
* @param array $data the caching data
|
||||
*
|
||||
* @throws PDOException if a db error occurred
|
||||
* @return object $this
|
||||
*/
|
||||
public function setCache(array $data)
|
||||
{
|
||||
|
||||
$handle = $this->handle;
|
||||
|
||||
$rows = $handle->query('SELECT created FROM `' .
|
||||
$this->config['table'].'`');
|
||||
|
||||
if (!$rows || $rows->rowCount() === 0) {
|
||||
|
||||
$this->_write($handle, $data);
|
||||
} else {
|
||||
|
||||
foreach ($rows as $row) {
|
||||
|
||||
if ((time()-strtotime($row['created'])) >
|
||||
$this->config['expiration_time']) {
|
||||
|
||||
$this->_write($handle, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached data
|
||||
*
|
||||
* Note that this method returns false if either type or file cache is
|
||||
* not set
|
||||
*
|
||||
* @throws PDOException if a db error occurred
|
||||
* @return mixed cache data or false
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
|
||||
try{
|
||||
$handle = $this->handle;
|
||||
$result = $handle->prepare('SELECT * FROM `' .
|
||||
$this->config['table'] .
|
||||
'` where type=?');
|
||||
$result->execute(array($this->type));
|
||||
|
||||
foreach ($result as $row) {
|
||||
return unserialize($row['data']);
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
throw new PDOException('PDOException: ' . $e->getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database and return a handle
|
||||
*
|
||||
* @return object PDO
|
||||
* @throws Exception if connection parameters are faulty
|
||||
* @throws PDOException if a db error occurred
|
||||
*/
|
||||
private function _connect()
|
||||
{
|
||||
|
||||
// validate connection parameters
|
||||
if (!$this->config['wrapper']
|
||||
|| !$this->config['user']
|
||||
|| !$this->config['password']
|
||||
|| !$this->config['table']) {
|
||||
|
||||
throw new Exception('
|
||||
Insufficient connection parameters'
|
||||
);
|
||||
}
|
||||
|
||||
// try to connect
|
||||
try {
|
||||
$handle = new PDO(
|
||||
$this->config['wrapper'],
|
||||
$this->config['user'],
|
||||
$this->config['password']
|
||||
);
|
||||
$handle->setAttribute(
|
||||
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true
|
||||
);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
throw new PDOException('PDOException: ' . $e->getMessage());
|
||||
}
|
||||
return $handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the cache data to the table
|
||||
*
|
||||
* @param object $handle the database handle
|
||||
* @param array $data the caching data
|
||||
*
|
||||
* @return object PDO
|
||||
* @throws PDOException if a db error occurred
|
||||
*/
|
||||
private function _write($handle, $data)
|
||||
{
|
||||
|
||||
try {
|
||||
$handle->query('TRUNCATE ' .
|
||||
$this->config['table'].'');
|
||||
$statement = $handle->prepare('
|
||||
INSERT INTO `' .
|
||||
$this->config['table'].'` (
|
||||
type,
|
||||
data,
|
||||
created,
|
||||
modified
|
||||
)
|
||||
VALUES (
|
||||
:type,
|
||||
:data,
|
||||
now(),
|
||||
now()
|
||||
)
|
||||
');
|
||||
|
||||
$statement->bindParam('type',
|
||||
$handle->quote($this->type));
|
||||
$statement->bindParam('data', serialize($data));
|
||||
|
||||
if (!$statement->execute()) {
|
||||
throw new PDOException($statement->errorCode());
|
||||
}
|
||||
|
||||
} catch (PDOException $e) {
|
||||
throw new PDOException('PDOException: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
94
sites/all/modules/civicrm/packages/IDS/Caching/Factory.php
Normal file
94
sites/all/modules/civicrm/packages/IDS/Caching/Factory.php
Normal file
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caching factory
|
||||
*
|
||||
* This class is used as a factory to load the correct concrete caching
|
||||
* implementation.
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @copyright 2007-2009 The PHPIDS Group
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @version Release: $Id:Factory.php 517 2007-09-15 15:04:13Z mario $
|
||||
* @link http://php-ids.org/
|
||||
* @since Version 0.4
|
||||
*/
|
||||
class IDS_Caching
|
||||
{
|
||||
|
||||
/**
|
||||
* Factory method
|
||||
*
|
||||
* @param object $init the IDS_Init object
|
||||
* @param string $type the caching type
|
||||
*
|
||||
* @return object the caching facility
|
||||
*/
|
||||
public static function factory($init, $type)
|
||||
{
|
||||
|
||||
$object = false;
|
||||
$wrapper = preg_replace(
|
||||
'/\W+/m',
|
||||
null,
|
||||
ucfirst($init->config['Caching']['caching'])
|
||||
);
|
||||
$class = 'IDS_Caching_' . $wrapper;
|
||||
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR .
|
||||
$wrapper . '.php';
|
||||
|
||||
if (file_exists($path)) {
|
||||
include_once $path;
|
||||
|
||||
if (class_exists($class)) {
|
||||
$object = call_user_func(array($class, 'getInstance'),
|
||||
$type, $init);
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
187
sites/all/modules/civicrm/packages/IDS/Caching/File.php
Normal file
187
sites/all/modules/civicrm/packages/IDS/Caching/File.php
Normal file
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
require_once 'IDS/Caching/Interface.php';
|
||||
|
||||
/**
|
||||
* File caching wrapper
|
||||
*
|
||||
* This class inhabits functionality to get and set cache via a static flatfile.
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @copyright 2007-2009 The PHPIDS Group
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @version Release: $Id:File.php 517 2007-09-15 15:04:13Z mario $
|
||||
* @link http://php-ids.org/
|
||||
* @since Version 0.4
|
||||
*/
|
||||
class IDS_Caching_File implements IDS_Caching_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Caching type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = null;
|
||||
|
||||
/**
|
||||
* Cache configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* Path to cache file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $path = null;
|
||||
|
||||
/**
|
||||
* Holds an instance of this class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $cachingInstance = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $init)
|
||||
{
|
||||
|
||||
$this->type = $type;
|
||||
$this->config = $init->config['Caching'];
|
||||
$this->path = $init->getBasePath() . $this->config['path'];
|
||||
|
||||
if (file_exists($this->path) && !is_writable($this->path)) {
|
||||
throw new Exception('Make sure all files in ' .
|
||||
htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') .
|
||||
'are writeable!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of this class
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public static function getInstance($type, $init)
|
||||
{
|
||||
if (!self::$cachingInstance) {
|
||||
self::$cachingInstance = new IDS_Caching_File($type, $init);
|
||||
}
|
||||
|
||||
return self::$cachingInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes cache data into the file
|
||||
*
|
||||
* @param array $data the cache data
|
||||
*
|
||||
* @throws Exception if cache file couldn't be created
|
||||
* @return object $this
|
||||
*/
|
||||
public function setCache(array $data)
|
||||
{
|
||||
|
||||
if (!is_writable(preg_replace('/[\/][^\/]+\.[^\/]++$/', null,
|
||||
$this->path))) {
|
||||
throw new Exception('Temp directory ' .
|
||||
htmlspecialchars($this->path, ENT_QUOTES, 'UTF-8') .
|
||||
' seems not writable');
|
||||
}
|
||||
|
||||
if ((!file_exists($this->path) || (time()-filectime($this->path)) >
|
||||
$this->config['expiration_time'])) {
|
||||
$handle = @fopen($this->path, 'w+');
|
||||
$serialized = @serialize($data);
|
||||
|
||||
if (!$handle) {
|
||||
throw new Exception("Cache file couldn't be created");
|
||||
}
|
||||
if (!$serialized) {
|
||||
throw new Exception("Cache data couldn't be serialized");
|
||||
}
|
||||
|
||||
fwrite($handle, $serialized);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached data
|
||||
*
|
||||
* Note that this method returns false if either type or file cache is
|
||||
* not set
|
||||
*
|
||||
* @return mixed cache data or false
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
|
||||
// make sure filters are parsed again if cache expired
|
||||
if (file_exists($this->path) && (time()-filectime($this->path)) <
|
||||
$this->config['expiration_time']) {
|
||||
$data = unserialize(file_get_contents($this->path));
|
||||
return $data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
73
sites/all/modules/civicrm/packages/IDS/Caching/Interface.php
Normal file
73
sites/all/modules/civicrm/packages/IDS/Caching/Interface.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Caching wrapper interface
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @copyright 2007-2009 The PHPIDS Group
|
||||
* @version SVN: $Id:Interface.php 517 2007-09-15 15:04:13Z mario $
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @since Version 0.4
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
interface IDS_Caching_Interface
|
||||
{
|
||||
/**
|
||||
* Interface method
|
||||
*
|
||||
* @param array $data the cache data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCache(array $data);
|
||||
|
||||
/**
|
||||
* Interface method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
195
sites/all/modules/civicrm/packages/IDS/Caching/Memcached.php
Normal file
195
sites/all/modules/civicrm/packages/IDS/Caching/Memcached.php
Normal file
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
require_once 'IDS/Caching/Interface.php';
|
||||
|
||||
/**
|
||||
* File caching wrapper
|
||||
*
|
||||
* This class inhabits functionality to get and set cache via memcached.
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @copyright 2007-2009 The PHPIDS Groupoup
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @version Release: $Id:Memcached.php 517 2007-09-15 15:04:13Z mario $
|
||||
* @link http://php-ids.org/
|
||||
* @since Version 0.4
|
||||
*/
|
||||
class IDS_Caching_Memcached implements IDS_Caching_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Caching type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = null;
|
||||
|
||||
/**
|
||||
* Cache configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* Flag if the filter storage has been found in memcached
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $isCached = false;
|
||||
|
||||
/**
|
||||
* Memcache object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $memcache = null;
|
||||
|
||||
/**
|
||||
* Holds an instance of this class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $cachingInstance = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param array $init the IDS_Init object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $init)
|
||||
{
|
||||
|
||||
$this->type = $type;
|
||||
$this->config = $init->config['Caching'];
|
||||
|
||||
$this->_connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of this class
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public static function getInstance($type, $init)
|
||||
{
|
||||
|
||||
if (!self::$cachingInstance) {
|
||||
self::$cachingInstance = new IDS_Caching_Memcached($type, $init);
|
||||
}
|
||||
|
||||
return self::$cachingInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes cache data
|
||||
*
|
||||
* @param array $data the caching data
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public function setCache(array $data)
|
||||
{
|
||||
|
||||
if(!$this->isCached) {
|
||||
$this->memcache->set(
|
||||
$this->config['key_prefix'] . '.storage',
|
||||
$data, false, $this->config['expiration_time']
|
||||
);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached data
|
||||
*
|
||||
* Note that this method returns false if either type or file cache is
|
||||
* not set
|
||||
*
|
||||
* @return mixed cache data or false
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
|
||||
$data = $this->memcache->get(
|
||||
$this->config['key_prefix'] .
|
||||
'.storage'
|
||||
);
|
||||
$this->isCached = !empty($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the memcached server
|
||||
*
|
||||
* @throws Exception if connection parameters are insufficient
|
||||
* @return void
|
||||
*/
|
||||
private function _connect()
|
||||
{
|
||||
|
||||
if ($this->config['host'] && $this->config['port']) {
|
||||
// establish the memcache connection
|
||||
$this->memcache = new Memcache;
|
||||
$this->memcache->pconnect(
|
||||
$this->config['host'],
|
||||
$this->config['port']
|
||||
);
|
||||
|
||||
} else {
|
||||
throw new Exception('Insufficient connection parameters');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
146
sites/all/modules/civicrm/packages/IDS/Caching/Session.php
Normal file
146
sites/all/modules/civicrm/packages/IDS/Caching/Session.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
*
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2008 PHPIDS group (https://phpids.org)
|
||||
*
|
||||
* PHPIDS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PHPIDS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with PHPIDS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* PHP version 5.1.6+
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @link http://php-ids.org/
|
||||
*/
|
||||
|
||||
require_once 'IDS/Caching/Interface.php';
|
||||
|
||||
/**
|
||||
* File caching wrapper
|
||||
*
|
||||
* This class inhabits functionality to get and set cache via session.
|
||||
*
|
||||
* @category Security
|
||||
* @package PHPIDS
|
||||
* @author Christian Matthies <ch0012@gmail.com>
|
||||
* @author Mario Heiderich <mario.heiderich@gmail.com>
|
||||
* @author Lars Strojny <lars@strojny.net>
|
||||
* @copyright 2007-2009 The PHPIDS Group
|
||||
* @license http://www.gnu.org/licenses/lgpl.html LGPL
|
||||
* @version Release: $Id:Session.php 517 2007-09-15 15:04:13Z mario $
|
||||
* @link http://php-ids.org/
|
||||
* @since Version 0.4
|
||||
*/
|
||||
class IDS_Caching_Session implements IDS_Caching_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Caching type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $type = null;
|
||||
|
||||
/**
|
||||
* Cache configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* Holds an instance of this class
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $cachingInstance = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $init)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->config = $init->config['Caching'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of this class
|
||||
*
|
||||
* @param string $type caching type
|
||||
* @param object $init the IDS_Init object
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public static function getInstance($type, $init)
|
||||
{
|
||||
|
||||
if (!self::$cachingInstance) {
|
||||
self::$cachingInstance = new IDS_Caching_Session($type, $init);
|
||||
}
|
||||
|
||||
return self::$cachingInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes cache data into the session
|
||||
*
|
||||
* @param array $data the caching data
|
||||
*
|
||||
* @return object $this
|
||||
*/
|
||||
public function setCache(array $data)
|
||||
{
|
||||
|
||||
$_SESSION['PHPIDS'][$this->type] = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached data
|
||||
*
|
||||
* Note that this method returns false if either type or file cache is not set
|
||||
*
|
||||
* @return mixed cache data or false
|
||||
*/
|
||||
public function getCache()
|
||||
{
|
||||
|
||||
if ($this->type && $_SESSION['PHPIDS'][$this->type]) {
|
||||
return $_SESSION['PHPIDS'][$this->type];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue