Page MenuHomePhorge

No OneTemporary

Size
17 KB
Referenced Files
None
Subscribers
None
diff --git a/plugins/database_attachments/config.inc.php.dist b/plugins/database_attachments/config.inc.php.dist
index b47615b79..b4464343c 100644
--- a/plugins/database_attachments/config.inc.php.dist
+++ b/plugins/database_attachments/config.inc.php.dist
@@ -1,16 +1,16 @@
<?php
// By default this plugin stores attachments in filesystem
// and copies them into sql database.
-// You can change it to use 'memcache' or 'apc'.
+// You can change it to use 'memcache', 'redis' or 'apc'.
// -----------------------------------------------------------
// WARNING: Remember to set max_allowed_packet in database or
// config to match with expected max attachment size.
// -----------------------------------------------------------
$config['database_attachments_cache'] = 'db';
// Attachment data expires after specied TTL time in seconds (max.2592000).
// Default is 12 hours.
$config['database_attachments_cache_ttl'] = 12 * 60 * 60;
?>
diff --git a/plugins/database_attachments/database_attachments.php b/plugins/database_attachments/database_attachments.php
index 5e3268d80..b06717458 100644
--- a/plugins/database_attachments/database_attachments.php
+++ b/plugins/database_attachments/database_attachments.php
@@ -1,192 +1,194 @@
<?php
/**
* Database Attachments
*
* This plugin which provides database backed storage for temporary
* attachment file handling. The primary advantage of this plugin
* is its compatibility with round-robin dns multi-server roundcube
* installations.
*
* This plugin relies on the core filesystem_attachments plugin
*
* @author Ziba Scott <ziba@umich.edu>
* @author Aleksander Machniak <alec@alec.pl>
*
+ * Copyright (C) 2011-2018, The Roundcube Dev Team
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
if (class_exists('filesystem_attachments', false) && !defined('TESTS_DIR')) {
die("Configuration issue. There can be only one enabled plugin for attachments handling");
}
require_once INSTALL_PATH . 'plugins/filesystem_attachments/filesystem_attachments.php';
class database_attachments extends filesystem_attachments
{
// Cache object
protected $cache;
// A prefix for the cache key used in the session and in the key field of the cache table
const PREFIX = "ATTACH";
/**
* Save a newly uploaded attachment
*/
function upload($args)
{
$args['status'] = false;
$cache = $this->get_cache();
$key = $this->_key($args);
$data = file_get_contents($args['path']);
if ($data === false) {
return $args;
}
$data = base64_encode($data);
$status = $cache->write($key, $data);
if ($status) {
$args['id'] = $key;
$args['status'] = true;
$args['path'] = null;
}
return $args;
}
/**
* Save an attachment from a non-upload source (draft or forward)
*/
function save($args)
{
$args['status'] = false;
$cache = $this->get_cache();
$key = $this->_key($args);
if ($args['path']) {
$args['data'] = file_get_contents($args['path']);
if ($args['data'] === false) {
return $args;
}
$args['path'] = null;
}
$data = base64_encode($args['data']);
$status = $cache->write($key, $data);
if ($status) {
$args['id'] = $key;
$args['status'] = true;
}
return $args;
}
/**
* Remove an attachment from storage
* This is triggered by the remove attachment button on the compose screen
*/
function remove($args)
{
$cache = $this->get_cache();
$status = $cache->remove($args['id']);
$args['status'] = true;
return $args;
}
/**
* When composing an html message, image attachments may be shown
* For this plugin, $this->get() will check the file and
* return it's contents
*/
function display($args)
{
return $this->get($args);
}
/**
* When displaying or sending the attachment the file contents are fetched
* using this method. This is also called by the attachment_display hook.
*/
function get($args)
{
$cache = $this->get_cache();
$data = $cache->read($args['id']);
if ($data !== null && $data !== false) {
$args['data'] = base64_decode($data);
$args['status'] = true;
}
else {
$args['status'] = false;
}
return $args;
}
/**
* Delete all temp files associated with this user
*/
function cleanup($args)
{
// check if cache object exist, it may be empty on session_destroy (#1489726)
if ($cache = $this->get_cache()) {
$cache->remove($args['group'], true);
}
}
/**
* Helper method to generate a unique key for the given attachment file
*/
protected function _key($args)
{
$uname = $args['path'] ?: $args['name'];
return $args['group'] . md5(time() . $uname . $_SESSION['user_id']);
}
/**
* Initialize and return cache object
*/
protected function get_cache()
{
if (!$this->cache) {
$this->load_config();
$rcmail = rcube::get_instance();
$ttl = 12 * 60 * 60; // default: 12 hours
$ttl = $rcmail->config->get('database_attachments_cache_ttl', $ttl);
$type = $rcmail->config->get('database_attachments_cache', 'db');
$prefix = self::PREFIX;
// Add session identifier to the prefix to prevent from removing attachments
// in other sessions of the same user (#1490542)
if ($id = session_id()) {
$prefix .= $id;
}
// Init SQL cache (disable cache data serialization)
$this->cache = $rcmail->get_cache($prefix, $type, $ttl, false);
}
return $this->cache;
}
}
diff --git a/plugins/redundant_attachments/composer.json b/plugins/redundant_attachments/composer.json
index bdbd0ed34..78b9138f0 100644
--- a/plugins/redundant_attachments/composer.json
+++ b/plugins/redundant_attachments/composer.json
@@ -1,30 +1,30 @@
{
"name": "roundcube/redundant_attachments",
"type": "roundcube-plugin",
"description": "This plugin provides a redundant storage for temporary uploaded attachment files. They are stored in both the database backend as well as on the local file system. It provides also memcache store as a fallback.",
"license": "GPLv2",
- "version": "1.1",
+ "version": "1.2",
"authors": [
{
"name": "Aleksander Machniak",
"email": "alec@alec.pl",
"role": "Lead"
},
{
"name": "Thomas Bruederli",
"email": "roundcube@gmail.com",
"role": "Lead"
}
],
"repositories": [
{
"type": "composer",
"url": "http://plugins.roundcube.net"
}
],
"require": {
"php": ">=5.3.0",
"roundcube/plugin-installer": ">=0.1.3",
"roundcube/filesystem_attachments": ">=1.0.0"
}
}
diff --git a/plugins/redundant_attachments/config.inc.php.dist b/plugins/redundant_attachments/config.inc.php.dist
index 9cc1b0034..b66d304c4 100644
--- a/plugins/redundant_attachments/config.inc.php.dist
+++ b/plugins/redundant_attachments/config.inc.php.dist
@@ -1,17 +1,18 @@
<?php
-// By default this plugin stores attachments in filesystem
-// and copies them into sql database.
-// In environments with replicated database it is possible
-// to use memcache as a fallback when write-master is unavailable.
-// ------------------------------------------------------------
-// WARNING: Remember to also set memcache_max_allowed_packet in
-// config to match with expected max attachment size.
-// ------------------------------------------------------------
-$config['redundant_attachments_memcache'] = false;
+// By default this plugin stores attachments in filesystem and copies them into sql database.
+// In environments with replicated database it is possible to use memcache or redis
+// as a fallback when write-master is unavailable.
+// -------------------------------------------------------------------------------------
+// WARNING: Remember to also set memcache_max_allowed_packet or redis_max_allowed_packet
+// in config to match with expected maximum attachment size.
+// -------------------------------------------------------------------------------------
+// This option can be set to 'memcache' or 'redis'.
+// Don't forget to set redis_*/memcache_* options in Roundcube config file.
+$config['redundant_attachments_fallback'] = false;
// Attachment data expires after specified TTL time in seconds (max.2592000).
// Default is 12 hours.
$config['redundant_attachments_cache_ttl'] = 12 * 60 * 60;
?>
diff --git a/plugins/redundant_attachments/redundant_attachments.php b/plugins/redundant_attachments/redundant_attachments.php
index 52a7ea3be..149ac9998 100644
--- a/plugins/redundant_attachments/redundant_attachments.php
+++ b/plugins/redundant_attachments/redundant_attachments.php
@@ -1,237 +1,242 @@
<?php
/**
* Redundant attachments
*
* This plugin provides a redundant storage for temporary uploaded
* attachment files. They are stored in both the database backend
* as well as on the local file system.
*
- * It provides also memcache store as a fallback (see config file).
+ * It provides also memcache/redis store as a fallback (see config file).
*
* This plugin relies on the core filesystem_attachments plugin
* and combines it with the functionality of the database_attachments plugin.
*
* @author Thomas Bruederli <roundcube@gmail.com>
* @author Aleksander Machniak <machniak@kolabsys.com>
*
- * Copyright (C) 2011, The Roundcube Dev Team
- * Copyright (C) 2011, Kolab Systems AG
+ * Copyright (C) 2011-2018, The Roundcube Dev Team
+ * Copyright (C) 2011-2018, Kolab Systems AG
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
if (class_exists('filesystem_attachments', false) && !defined('TESTS_DIR')) {
die("Configuration issue. There can be only one enabled plugin for attachments handling");
}
require_once(RCUBE_PLUGINS_DIR . 'filesystem_attachments/filesystem_attachments.php');
class redundant_attachments extends filesystem_attachments
{
// A prefix for the cache key used in the session and in the key field of the cache table
const PREFIX = "ATTACH";
// rcube_cache instance for SQL DB
private $cache;
- // rcube_cache instance for memcache
+ // rcube_cache instance for memcache/redis
private $mem_cache;
private $loaded;
/**
* Loads plugin configuration and initializes cache object(s)
*/
private function _load_drivers()
{
if ($this->loaded) {
return;
}
$rcmail = rcube::get_instance();
// load configuration
$this->load_config();
- $ttl = 12 * 60 * 60; // 12 hours
- $ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl);
- $prefix = self::PREFIX;
+ $ttl = 12 * 60 * 60; // 12 hours
+ $ttl = $rcmail->config->get('redundant_attachments_cache_ttl', $ttl);
+ $fallback = $rcmail->config->get('redundant_attachments_fallback');
+ $prefix = self::PREFIX;
if ($id = session_id()) {
$prefix .= $id;
}
+ if ($fallback === null) {
+ $fallback = $rcmail->config->get('redundant_attachments_memcache') ? 'memcache' : null; // BC
+ }
+
// Init SQL cache (disable cache data serialization)
$this->cache = $rcmail->get_cache($prefix, 'db', $ttl, false);
- // Init memcache (fallback) cache
- if ($rcmail->config->get('redundant_attachments_memcache')) {
- $this->mem_cache = $rcmail->get_cache($prefix, 'memcache', $ttl, false);
+ // Init memcache/redis (fallback) cache
+ if ($fallback) {
+ $this->mem_cache = $rcmail->get_cache($prefix, $fallback, $ttl, false);
}
$this->loaded = true;
}
/**
* Helper method to generate a unique key for the given attachment file
*/
private function _key($args)
{
$uname = $args['path'] ?: $args['name'];
return $args['group'] . md5(time() . $uname . $_SESSION['user_id']);
}
/**
* Save a newly uploaded attachment
*/
function upload($args)
{
$args = parent::upload($args);
$this->_load_drivers();
$key = $this->_key($args);
$data = base64_encode(file_get_contents($args['path']));
$status = $this->cache->write($key, $data);
if (!$status && $this->mem_cache) {
$status = $this->mem_cache->write($key, $data);
}
if ($status) {
$args['id'] = $key;
$args['status'] = true;
}
return $args;
}
/**
* Save an attachment from a non-upload source (draft or forward)
*/
function save($args)
{
$args = parent::save($args);
$this->_load_drivers();
$data = $args['path'] ? file_get_contents($args['path']) : $args['data'];
$args['data'] = null;
$key = $this->_key($args);
$data = base64_encode($data);
$status = $this->cache->write($key, $data);
if (!$status && $this->mem_cache) {
$status = $this->mem_cache->write($key, $data);
}
if ($status) {
$args['id'] = $key;
$args['status'] = true;
}
return $args;
}
/**
* Remove an attachment from storage
* This is triggered by the remove attachment button on the compose screen
*/
function remove($args)
{
parent::remove($args);
$this->_load_drivers();
$status = $this->cache->remove($args['id']);
if (!$status && $this->mem_cache) {
$status = $this->cache->remove($args['id']);
}
// we cannot trust the result of any of the methods above
// assume true, attachments will be removed on cleanup
$args['status'] = true;
return $args;
}
/**
* When composing an html message, image attachments may be shown
* For this plugin, $this->get() will check the file and
* return it's contents
*/
function display($args)
{
return $this->get($args);
}
/**
* When displaying or sending the attachment the file contents are fetched
* using this method. This is also called by the attachment_display hook.
*/
function get($args)
{
// attempt to get file from local file system
$args = parent::get($args);
if ($args['path'] && ($args['status'] = file_exists($args['path'])))
return $args;
$this->_load_drivers();
// fetch from database if not found on FS
$data = $this->cache->read($args['id']);
// fetch from memcache if not found on FS and DB
if (($data === false || $data === null) && $this->mem_cache) {
$data = $this->mem_cache->read($args['id']);
}
if ($data) {
$args['data'] = base64_decode($data);
$args['status'] = true;
}
return $args;
}
/**
* Delete all temp files associated with this user
*/
function cleanup($args)
{
$this->_load_drivers();
if ($this->cache) {
$this->cache->remove($args['group'], true);
}
if ($this->mem_cache) {
$this->mem_cache->remove($args['group'], true);
}
parent::cleanup($args);
$args['status'] = true;
return $args;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Apr 9, 1:01 PM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
540443
Default Alt Text
(17 KB)

Event Timeline