From 6686152ce05802a9cb70ce7200d36efda9b15cae Mon Sep 17 00:00:00 2001 From: andryyy Date: Wed, 5 Feb 2020 11:04:14 +0100 Subject: [PATCH] [Web] Use redis master where necessary, hide UI if not master, create replicate quota2 table --- data/web/_rspamderror.php | 7 ++++++- data/web/autodiscover.php | 12 +++++++++++- data/web/inc/functions.mailbox.inc.php | 11 +++++++++++ data/web/inc/prerequisites.inc.php | 7 ++++++- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/data/web/_rspamderror.php b/data/web/_rspamderror.php index 7cde1601..6bdfb349 100644 --- a/data/web/_rspamderror.php +++ b/data/web/_rspamderror.php @@ -1,7 +1,12 @@ connect('redis-mailcow', 6379); + if (!empty(getenv('REDIS_SLAVEOF_IP'))) { + $redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT')); + } + else { + $redis->connect('redis-mailcow', 6379); + } } catch (Exception $e) { exit; diff --git a/data/web/autodiscover.php b/data/web/autodiscover.php index 8f17b70b..3f258e86 100644 --- a/data/web/autodiscover.php +++ b/data/web/autodiscover.php @@ -9,7 +9,17 @@ $autodiscover_config = array_merge($default_autodiscover_config, $autodiscover_c // Redis $redis = new Redis(); -$redis->connect('redis-mailcow', 6379); +try { + if (!empty(getenv('REDIS_SLAVEOF_IP'))) { + $redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT')); + } + else { + $redis->connect('redis-mailcow', 6379); + } +} +catch (Exception $e) { + exit; +} error_reporting(0); diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 4fe6fb4a..bfa32cb0 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -960,6 +960,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { $stmt = $pdo->prepare("INSERT INTO `quota2` (`username`, `bytes`, `messages`) VALUES (:username, '0', '0') ON DUPLICATE KEY UPDATE `bytes` = '0', `messages` = '0';"); $stmt->execute(array(':username' => $username)); + $stmt = $pdo->prepare("INSERT INTO `quota2replica` (`username`, `bytes`, `messages`) + VALUES (:username, '0', '0') ON DUPLICATE KEY UPDATE `bytes` = '0', `messages` = '0';"); + $stmt->execute(array(':username' => $username)); $stmt = $pdo->prepare("INSERT INTO `alias` (`address`, `goto`, `domain`, `active`) VALUES (:username1, :username2, :domain, :active)"); $stmt->execute(array( @@ -3558,6 +3561,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { $stmt->execute(array( ':domain' => '%@'.$domain, )); + $stmt = $pdo->prepare("DELETE FROM `quota2replica` WHERE `username` LIKE :domain"); + $stmt->execute(array( + ':domain' => '%@'.$domain, + )); $stmt = $pdo->prepare("DELETE FROM `spamalias` WHERE `address` LIKE :domain"); $stmt->execute(array( ':domain' => '%@'.$domain, @@ -3760,6 +3767,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { $stmt->execute(array( ':username' => $username )); + $stmt = $pdo->prepare("DELETE FROM `quota2replica` WHERE `username` = :username"); + $stmt->execute(array( + ':username' => $username + )); $stmt = $pdo->prepare("DELETE FROM `mailbox` WHERE `username` = :username"); $stmt->execute(array( ':username' => $username diff --git a/data/web/inc/prerequisites.inc.php b/data/web/inc/prerequisites.inc.php index 46f902e6..ff58cce9 100644 --- a/data/web/inc/prerequisites.inc.php +++ b/data/web/inc/prerequisites.inc.php @@ -54,7 +54,12 @@ $tfa = new RobThree\Auth\TwoFactorAuth($OTP_LABEL, 6, 30, 'sha1', $qrprovider); // Redis $redis = new Redis(); try { - $redis->connect('redis-mailcow', 6379); + if (!empty(getenv('REDIS_SLAVEOF_IP'))) { + $redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT')); + } + else { + $redis->connect('redis-mailcow', 6379); + } } catch (Exception $e) { ?>