[Web, Postfix] Move TLS policy to mailbox attributes

This commit is contained in:
André Peters 2018-02-17 11:12:16 +01:00
parent f29451f03c
commit ab720bf164
2 changed files with 12 additions and 8 deletions

View File

@ -39,7 +39,7 @@ query = SELECT IF(EXISTS(
SELECT CONCAT('%u', '@', target_domain) FROM alias_domain SELECT CONCAT('%u', '@', target_domain) FROM alias_domain
WHERE alias_domain='%d' WHERE alias_domain='%d'
) )
) AND json_extract(`attributes`, '$.tls_enforce_in') = '1' AND mailbox.active = '1' ) AND json_extract(attributes, '$.tls_enforce_in') = '1' AND mailbox.active = '1'
), 'reject_plaintext_session', NULL) AS 'tls_enforce_in'; ), 'reject_plaintext_session', NULL) AS 'tls_enforce_in';
EOF EOF
@ -58,7 +58,7 @@ query = SELECT GROUP_CONCAT(transport SEPARATOR '') AS transport_maps
WHERE alias_domain = '%d' WHERE alias_domain = '%d'
) )
) )
AND json_extract(`attributes`, '$.tls_enforce_out') = '1' AND json_extract(attributes, '$.tls_enforce_out') = '1'
AND mailbox.active = '1' AND mailbox.active = '1'
), 'smtp_enforced_tls:', 'smtp:') AS 'transport' ), 'smtp_enforced_tls:', 'smtp:') AS 'transport'
UNION ALL UNION ALL

View File

@ -1154,8 +1154,8 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
try { try {
$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 = $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( $stmt->execute(array(
':tls_out' => $tls_enforce_out, ':tls_out' => intval($tls_enforce_out),
':tls_in' => $tls_enforce_in, ':tls_in' => intval($tls_enforce_in),
':username' => $username ':username' => $username
)); ));
} }
@ -2392,7 +2392,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
return $mailboxes; return $mailboxes;
break; break;
case 'tls_policy': case 'tls_policy':
$policydata = array(); $attrs = array();
if (isset($_data) && filter_var($_data, FILTER_VALIDATE_EMAIL)) { if (isset($_data) && filter_var($_data, FILTER_VALIDATE_EMAIL)) {
if (!hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $_data)) { if (!hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $_data)) {
return false; return false;
@ -2402,9 +2402,9 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
$_data = $_SESSION['mailcow_cc_username']; $_data = $_SESSION['mailcow_cc_username'];
} }
try { try {
$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 = $pdo->prepare("SELECT `attributes` FROM `mailbox` WHERE `username` = :username");
$stmt->execute(array(':username' => $_data)); $stmt->execute(array(':username' => $_data));
$policydata = $stmt->fetch(PDO::FETCH_ASSOC); $attrs = $stmt->fetch(PDO::FETCH_ASSOC);
} }
catch(PDOException $e) { catch(PDOException $e) {
$_SESSION['return'] = array( $_SESSION['return'] = array(
@ -2413,7 +2413,11 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
); );
return false; return false;
} }
return $policydata; $attrs = json_decode($attrs['attributes'], true);
return array(
'tls_enforce_in' => $attrs['tls_enforce_in'],
'tls_enforce_out' => $attrs['tls_enforce_out']
);
break; break;
case 'filters': case 'filters':
$filters = array(); $filters = array();