From 090ef6dbc5ae6a918ed52a1f89def2a3fd88750a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Peters?= Date: Sat, 17 Feb 2018 10:34:18 +0100 Subject: [PATCH] [Web] Further work on attributes --- data/web/inc/functions.mailbox.inc.php | 4 ++-- data/web/inc/init_db.inc.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 89e021665..00d0f99c1 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -1152,7 +1152,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { return false; } try { - $stmt = $pdo->prepare("UPDATE `mailbox` SET `tls_enforce_out` = :tls_out, `tls_enforce_in` = :tls_in WHERE `username` = :username"); + $stmt = $pdo->prepare("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.tls_enforce_out', :tls_out), `attributes` = JSON_SET(`attributes`, '$.tls_enforce_in', :tls_in) WHERE `username` = :username"); $stmt->execute(array( ':tls_out' => $tls_enforce_out, ':tls_in' => $tls_enforce_in, @@ -2402,7 +2402,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { $_data = $_SESSION['mailcow_cc_username']; } try { - $stmt = $pdo->prepare("SELECT `tls_enforce_out`, `tls_enforce_in` FROM `mailbox` WHERE `username` = :username"); + $stmt = $pdo->prepare("SELECT JSON_EXTRACT(`attributes`, '$.tls_enforce_out') AS `tls_enforce_out`, JSON_EXTRACT(`attributes`, '$.tls_enforce_in') AS `tls_enforce_in` FROM `mailbox` WHERE `username` = :username"); $stmt->execute(array(':username' => $_data)); $policydata = $stmt->fetch(PDO::FETCH_ASSOC); } diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php index c9fa534a3..23a3d0a0c 100644 --- a/data/web/inc/init_db.inc.php +++ b/data/web/inc/init_db.inc.php @@ -189,8 +189,6 @@ function init_db_schema() { "quota" => "BIGINT(20) NOT NULL DEFAULT '102400'", "local_part" => "VARCHAR(255) NOT NULL", "domain" => "VARCHAR(255) NOT NULL", - "tls_enforce_in" => "TINYINT(1) NOT NULL DEFAULT '0'", - "tls_enforce_out" => "TINYINT(1) NOT NULL DEFAULT '0'", "attributes" => "JSON", "kind" => "VARCHAR(100) NOT NULL DEFAULT ''", "multiple_bookings" => "TINYINT(1) NOT NULL DEFAULT '0'", @@ -801,6 +799,7 @@ function init_db_schema() { // Reset table attributes $pdo->query("ALTER TABLE `" . $table . "` " . $properties['attr'] . ";"); // Migrate tls_enforce_* options + $stmt = $pdo->query("UPDATE `mailbox` SET `attributes` = '{}' WHERE `attributes` IS NULL;"); foreach($tls_options as $tls_user => $tls_options) { $stmt = $pdo->prepare("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.tls_enforce_in', :tls_enforce_in), `attributes` = JSON_SET(`attributes`, '$.tls_enforce_out', :tls_enforce_out)