[Web] Use redis master where necessary, hide UI if not master, create replicate quota2 table
parent
13213fa30b
commit
6686152ce0
|
@ -1,8 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
$redis = new Redis();
|
$redis = new Redis();
|
||||||
try {
|
try {
|
||||||
|
if (!empty(getenv('REDIS_SLAVEOF_IP'))) {
|
||||||
|
$redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
$redis->connect('redis-mailcow', 6379);
|
$redis->connect('redis-mailcow', 6379);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,17 @@ $autodiscover_config = array_merge($default_autodiscover_config, $autodiscover_c
|
||||||
|
|
||||||
// Redis
|
// Redis
|
||||||
$redis = new Redis();
|
$redis = new Redis();
|
||||||
|
try {
|
||||||
|
if (!empty(getenv('REDIS_SLAVEOF_IP'))) {
|
||||||
|
$redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
$redis->connect('redis-mailcow', 6379);
|
$redis->connect('redis-mailcow', 6379);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
|
|
||||||
|
|
|
@ -960,6 +960,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||||
$stmt = $pdo->prepare("INSERT INTO `quota2` (`username`, `bytes`, `messages`)
|
$stmt = $pdo->prepare("INSERT INTO `quota2` (`username`, `bytes`, `messages`)
|
||||||
VALUES (:username, '0', '0') ON DUPLICATE KEY UPDATE `bytes` = '0', `messages` = '0';");
|
VALUES (:username, '0', '0') ON DUPLICATE KEY UPDATE `bytes` = '0', `messages` = '0';");
|
||||||
$stmt->execute(array(':username' => $username));
|
$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`)
|
$stmt = $pdo->prepare("INSERT INTO `alias` (`address`, `goto`, `domain`, `active`)
|
||||||
VALUES (:username1, :username2, :domain, :active)");
|
VALUES (:username1, :username2, :domain, :active)");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
|
@ -3558,6 +3561,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
':domain' => '%@'.$domain,
|
':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 = $pdo->prepare("DELETE FROM `spamalias` WHERE `address` LIKE :domain");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
':domain' => '%@'.$domain,
|
':domain' => '%@'.$domain,
|
||||||
|
@ -3760,6 +3767,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
':username' => $username
|
':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 = $pdo->prepare("DELETE FROM `mailbox` WHERE `username` = :username");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
':username' => $username
|
':username' => $username
|
||||||
|
|
|
@ -54,8 +54,13 @@ $tfa = new RobThree\Auth\TwoFactorAuth($OTP_LABEL, 6, 30, 'sha1', $qrprovider);
|
||||||
// Redis
|
// Redis
|
||||||
$redis = new Redis();
|
$redis = new Redis();
|
||||||
try {
|
try {
|
||||||
|
if (!empty(getenv('REDIS_SLAVEOF_IP'))) {
|
||||||
|
$redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
$redis->connect('redis-mailcow', 6379);
|
$redis->connect('redis-mailcow', 6379);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
?>
|
?>
|
||||||
<center style='font-family:sans-serif;'>Connection to Redis failed.<br /><br />The following error was reported:<br/><?=$e->getMessage();?></center>
|
<center style='font-family:sans-serif;'>Connection to Redis failed.<br /><br />The following error was reported:<br/><?=$e->getMessage();?></center>
|
||||||
|
|
Loading…
Reference in New Issue