|
@@ -326,9 +326,18 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$description = $_data['description'];
|
|
|
$aliases = $_data['aliases'];
|
|
|
$mailboxes = $_data['mailboxes'];
|
|
|
+ $defquota = $_data['defquota'];
|
|
|
$maxquota = $_data['maxquota'];
|
|
|
$restart_sogo = $_data['restart_sogo'];
|
|
|
$quota = $_data['quota'];
|
|
|
+ if ($defquota > $maxquota) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'mailbox_defquota_exceeds_mailbox_maxquota'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if ($maxquota > $quota) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -337,6 +346,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
+ if ($defquota == "0" || empty($defquota)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'defquota_empty'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if ($maxquota == "0" || empty($maxquota)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -392,13 +409,18 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- $stmt = $pdo->prepare("INSERT INTO `domain` (`domain`, `description`, `aliases`, `mailboxes`, `maxquota`, `quota`, `backupmx`, `gal`, `active`, `relay_all_recipients`)
|
|
|
- VALUES (:domain, :description, :aliases, :mailboxes, :maxquota, :quota, :backupmx, :gal, :active, :relay_all_recipients)");
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `external` = 1 AND `send_as` LIKE :domain");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':domain' => '%@' . $domain
|
|
|
+ ));
|
|
|
+ $stmt = $pdo->prepare("INSERT INTO `domain` (`domain`, `description`, `aliases`, `mailboxes`, `defquota`, `maxquota`, `quota`, `backupmx`, `gal`, `active`, `relay_all_recipients`)
|
|
|
+ VALUES (:domain, :description, :aliases, :mailboxes, :defquota, :maxquota, :quota, :backupmx, :gal, :active, :relay_all_recipients)");
|
|
|
$stmt->execute(array(
|
|
|
':domain' => $domain,
|
|
|
':description' => $description,
|
|
|
':aliases' => $aliases,
|
|
|
':mailboxes' => $mailboxes,
|
|
|
+ ':defquota' => $defquota,
|
|
|
':maxquota' => $maxquota,
|
|
|
':quota' => $quota,
|
|
|
':backupmx' => $backupmx,
|
|
@@ -561,7 +583,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
'msg' => array('is_alias_or_mailbox', htmlspecialchars($address))
|
|
|
);
|
|
|
- return false;
|
|
|
+ continue;
|
|
|
}
|
|
|
$stmt = $pdo->prepare("SELECT `domain` FROM `domain`
|
|
|
WHERE `domain`= :domain1 OR `domain` = (SELECT `target_domain` FROM `alias_domain` WHERE `alias_domain` = :domain2)");
|
|
@@ -573,7 +595,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
'msg' => array('domain_not_found', htmlspecialchars($domain))
|
|
|
);
|
|
|
- return false;
|
|
|
+ continue;
|
|
|
}
|
|
|
$stmt = $pdo->prepare("SELECT `address` FROM `spamalias`
|
|
|
WHERE `address`= :address");
|
|
@@ -585,7 +607,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
'msg' => array('is_spam_alias', htmlspecialchars($address))
|
|
|
);
|
|
|
- return false;
|
|
|
+ continue;
|
|
|
}
|
|
|
if ((!filter_var($address, FILTER_VALIDATE_EMAIL) === true) && !empty($local_part)) {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -593,7 +615,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
'msg' => 'alias_invalid'
|
|
|
);
|
|
|
- return false;
|
|
|
+ continue;
|
|
|
}
|
|
|
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -601,7 +623,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
'msg' => 'access_denied'
|
|
|
);
|
|
|
- return false;
|
|
|
+ continue;
|
|
|
}
|
|
|
$stmt = $pdo->prepare("INSERT INTO `alias` (`address`, `public_comment`, `private_comment`, `goto`, `domain`, `active`)
|
|
|
VALUES (:address, :public_comment, :private_comment, :goto, :domain, :active)");
|
|
@@ -692,6 +714,18 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
+ $stmt = $pdo->prepare("SELECT `domain` FROM `domain`
|
|
|
+ WHERE `domain`= :target_domain AND `backupmx` = '1'");
|
|
|
+ $stmt->execute(array(':target_domain' => $target_domain));
|
|
|
+ $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
+ if ($num_results == 1) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => array('targetd_relay_domain', htmlspecialchars($target_domain))
|
|
|
+ );
|
|
|
+ continue;
|
|
|
+ }
|
|
|
$stmt = $pdo->prepare("SELECT `alias_domain` FROM `alias_domain` WHERE `alias_domain`= :alias_domain
|
|
|
UNION
|
|
|
SELECT `domain` FROM `domain` WHERE `domain`= :alias_domain_in_domain");
|
|
@@ -705,6 +739,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `external` = 1 AND `send_as` LIKE :domain");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':domain' => '%@' . $domain
|
|
|
+ ));
|
|
|
$stmt = $pdo->prepare("INSERT INTO `alias_domain` (`alias_domain`, `target_domain`, `active`)
|
|
|
VALUES (:alias_domain, :target_domain, :active)");
|
|
|
$stmt->execute(array(
|
|
@@ -756,7 +794,15 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$password = $_data['password'];
|
|
|
$password2 = $_data['password2'];
|
|
|
$name = ltrim(rtrim($_data['name'], '>'), '<');
|
|
|
- $quota_m = filter_var($_data['quota'], FILTER_SANITIZE_NUMBER_FLOAT);
|
|
|
+ $quota_m = intval($_data['quota']);
|
|
|
+ if ((!isset($_SESSION['acl']['unlimited_quota']) || $_SESSION['acl']['unlimited_quota'] != "1") && $quota_m === 0) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'unlimited_quota_acl'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (empty($name)) {
|
|
|
$name = $local_part;
|
|
|
}
|
|
@@ -844,14 +890,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- if (!is_numeric($quota_m) || $quota_m == "0") {
|
|
|
- $_SESSION['return'][] = array(
|
|
|
- 'type' => 'danger',
|
|
|
- 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
- 'msg' => 'quota_not_0_not_numeric'
|
|
|
- );
|
|
|
- return false;
|
|
|
- }
|
|
|
if (!empty($password) && !empty($password2)) {
|
|
|
if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password)) {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -1695,25 +1733,27 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- $stmt = $pdo->prepare("SELECT `address` FROM `alias`
|
|
|
- WHERE `address`= :address OR `address` IN (
|
|
|
- SELECT `username` FROM `mailbox`, `alias_domain`
|
|
|
- WHERE (
|
|
|
- `alias_domain`.`alias_domain` = :address_d
|
|
|
- AND `mailbox`.`username` = CONCAT(:address_l, '@', alias_domain.target_domain)))");
|
|
|
- $stmt->execute(array(
|
|
|
- ':address' => $address,
|
|
|
- ':address_l' => $local_part,
|
|
|
- ':address_d' => $domain
|
|
|
- ));
|
|
|
- $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
- if ($num_results != 0) {
|
|
|
- $_SESSION['return'][] = array(
|
|
|
- 'type' => 'danger',
|
|
|
- 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
- 'msg' => array('is_alias_or_mailbox', htmlspecialchars($address))
|
|
|
- );
|
|
|
- continue;
|
|
|
+ if (strtolower($is_now['address']) != strtolower($address)) {
|
|
|
+ $stmt = $pdo->prepare("SELECT `address` FROM `alias`
|
|
|
+ WHERE `address`= :address OR `address` IN (
|
|
|
+ SELECT `username` FROM `mailbox`, `alias_domain`
|
|
|
+ WHERE (
|
|
|
+ `alias_domain`.`alias_domain` = :address_d
|
|
|
+ AND `mailbox`.`username` = CONCAT(:address_l, '@', alias_domain.target_domain)))");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':address' => $address,
|
|
|
+ ':address_l' => $local_part,
|
|
|
+ ':address_d' => $domain
|
|
|
+ ));
|
|
|
+ $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
+ if ($num_results != 0) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => array('is_alias_or_mailbox', htmlspecialchars($address))
|
|
|
+ );
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
$stmt = $pdo->prepare("SELECT `domain` FROM `domain`
|
|
|
WHERE `domain`= :domain1 OR `domain` = (SELECT `target_domain` FROM `alias_domain` WHERE `alias_domain` = :domain2)");
|
|
@@ -1773,6 +1813,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
unset($gotos[$i]);
|
|
|
continue;
|
|
|
}
|
|
|
+ // Delete from sender_acl to prevent duplicates
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE
|
|
|
+ `logged_in_as` = :goto AND
|
|
|
+ `send_as` = :address");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':goto' => $goto,
|
|
|
+ ':address' => $address
|
|
|
+ ));
|
|
|
}
|
|
|
$gotos = array_filter($gotos);
|
|
|
$goto = implode(",", $gotos);
|
|
@@ -1859,6 +1907,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$relayhost = (isset($_data['relayhost'])) ? intval($_data['relayhost']) : $is_now['relayhost'];
|
|
|
$aliases = (!empty($_data['aliases'])) ? $_data['aliases'] : $is_now['max_num_aliases_for_domain'];
|
|
|
$mailboxes = (isset($_data['mailboxes']) && $_data['mailboxes'] != '') ? intval($_data['mailboxes']) : $is_now['max_num_mboxes_for_domain'];
|
|
|
+ $defquota = (isset($_data['defquota']) && $_data['defquota'] != '') ? intval($_data['defquota']) : ($is_now['def_quota_for_mbox'] / 1048576);
|
|
|
$maxquota = (!empty($_data['maxquota'])) ? $_data['maxquota'] : ($is_now['max_quota_for_mbox'] / 1048576);
|
|
|
$quota = (!empty($_data['quota'])) ? $_data['quota'] : ($is_now['max_quota_for_domain'] / 1048576);
|
|
|
$description = (!empty($_data['description'])) ? $_data['description'] : $is_now['description'];
|
|
@@ -1890,6 +1939,22 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
)");
|
|
|
$stmt->execute(array(':domain' => $domain));
|
|
|
$AliasData = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
+ if ($defquota > $maxquota) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'mailbox_defquota_exceeds_mailbox_maxquota'
|
|
|
+ );
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($defquota == "0" || empty($defquota)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'defquota_empty'
|
|
|
+ );
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if ($maxquota > $quota) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -1944,6 +2009,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
`gal` = :gal,
|
|
|
`active` = :active,
|
|
|
`quota` = :quota,
|
|
|
+ `defquota` = :defquota,
|
|
|
`maxquota` = :maxquota,
|
|
|
`relayhost` = :relayhost,
|
|
|
`mailboxes` = :mailboxes,
|
|
@@ -1956,6 +2022,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
':gal' => $gal,
|
|
|
':active' => $active,
|
|
|
':quota' => $quota,
|
|
|
+ ':defquota' => $defquota,
|
|
|
':maxquota' => $maxquota,
|
|
|
':relayhost' => $relayhost,
|
|
|
':mailboxes' => $mailboxes,
|
|
@@ -1993,9 +2060,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int'];
|
|
|
(int)$force_pw_update = (isset($_data['force_pw_update'])) ? intval($_data['force_pw_update']) : intval($is_now['attributes']['force_pw_update']);
|
|
|
(int)$sogo_access = (isset($_data['sogo_access'])) ? intval($_data['sogo_access']) : intval($is_now['attributes']['sogo_access']);
|
|
|
+ (int)$quota_m = (isset_has_content($_data['quota'])) ? intval($_data['quota']) : ($is_now['quota'] / 1048576);
|
|
|
$name = (!empty($_data['name'])) ? ltrim(rtrim($_data['name'], '>'), '<') : $is_now['name'];
|
|
|
$domain = $is_now['domain'];
|
|
|
- $quota_m = (!empty($_data['quota'])) ? $_data['quota'] : ($is_now['quota'] / 1048576);
|
|
|
$quota_b = $quota_m * 1048576;
|
|
|
$password = (!empty($_data['password'])) ? $_data['password'] : null;
|
|
|
$password2 = (!empty($_data['password2'])) ? $_data['password2'] : null;
|
|
@@ -2008,6 +2075,15 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
+ // if already 0 == ok
|
|
|
+ if ((!isset($_SESSION['acl']['unlimited_quota']) || $_SESSION['acl']['unlimited_quota'] != "1") && ($quota_m == 0 && $is_now['quota'] != 0)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'unlimited_quota_acl'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
$stmt = $pdo->prepare("SELECT `quota`, `maxquota`
|
|
|
FROM `domain`
|
|
|
WHERE `domain` = :domain");
|
|
@@ -2021,14 +2097,6 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- if (!is_numeric($quota_m) || $quota_m == "0") {
|
|
|
- $_SESSION['return'][] = array(
|
|
|
- 'type' => 'danger',
|
|
|
- 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
- 'msg' => array('quota_not_0_not_numeric', htmlspecialchars($quota_m))
|
|
|
- );
|
|
|
- continue;
|
|
|
- }
|
|
|
if ($quota_m > $DomainData['maxquota']) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -2045,6 +2113,75 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
+ $extra_acls = array();
|
|
|
+ if (isset($_data['extended_sender_acl'])) {
|
|
|
+ if (!isset($_SESSION['acl']['extend_sender_acl']) || $_SESSION['acl']['extend_sender_acl'] != "1" ) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'access_denied'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $extra_acls = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['extended_sender_acl']));
|
|
|
+ foreach ($extra_acls as $i => &$extra_acl) {
|
|
|
+ if (empty($extra_acl)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (substr($extra_acl, 0, 1) === "@") {
|
|
|
+ $extra_acl = ltrim($extra_acl, '@');
|
|
|
+ }
|
|
|
+ if (!filter_var($extra_acl, FILTER_VALIDATE_EMAIL) && !is_valid_domain_name($extra_acl)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => array('extra_acl_invalid', htmlspecialchars($extra_acl))
|
|
|
+ );
|
|
|
+ unset($extra_acls[$i]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $domains = array_merge(mailbox('get', 'domains'), mailbox('get', 'alias_domains'));
|
|
|
+ if (filter_var($extra_acl, FILTER_VALIDATE_EMAIL)) {
|
|
|
+ $extra_acl_domain = idn_to_ascii(substr(strstr($extra_acl, '@'), 1), 0, INTL_IDNA_VARIANT_UTS46);
|
|
|
+ if (in_array($extra_acl_domain, $domains)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => array('extra_acl_invalid_domain', $extra_acl_domain)
|
|
|
+ );
|
|
|
+ unset($extra_acls[$i]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (in_array($extra_acl, $domains)) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => array('extra_acl_invalid_domain', $extra_acl_domain)
|
|
|
+ );
|
|
|
+ unset($extra_acls[$i]);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $extra_acl = '@' . $extra_acl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $extra_acls = array_filter($extra_acls);
|
|
|
+ $extra_acls = array_values($extra_acls);
|
|
|
+ $extra_acls = array_unique($extra_acls);
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `external` = 1 AND `logged_in_as` = :username");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':username' => $username
|
|
|
+ ));
|
|
|
+ foreach ($extra_acls as $sender_acl_external) {
|
|
|
+ $stmt = $pdo->prepare("INSERT INTO `sender_acl` (`send_as`, `logged_in_as`, `external`)
|
|
|
+ VALUES (:sender_acl, :username, 1)");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':sender_acl' => $sender_acl_external,
|
|
|
+ ':username' => $username
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ }
|
|
|
if (isset($_data['sender_acl'])) {
|
|
|
// Get sender_acl items set by admin
|
|
|
$sender_acl_admin = array_merge(
|
|
@@ -2116,9 +2253,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
unset($sender_acl_domain_admin[$key]);
|
|
|
continue;
|
|
|
}
|
|
|
- // Check if user has mailbox access (if object is email)
|
|
|
+ // Check if user has alias access (if object is email)
|
|
|
if (filter_var($val, FILTER_VALIDATE_EMAIL)) {
|
|
|
- if (!hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $val)) {
|
|
|
+ if (!hasAliasObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $val)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -2133,15 +2270,20 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$sender_acl_merged = array_merge($sender_acl_domain_admin, $sender_acl_admin);
|
|
|
// If merged array still contains "*", set it as only value
|
|
|
!in_array('*', $sender_acl_merged) ?: $sender_acl_merged = array('*');
|
|
|
- $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `logged_in_as` = :username");
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `external` = 0 AND `logged_in_as` = :username");
|
|
|
$stmt->execute(array(
|
|
|
':username' => $username
|
|
|
));
|
|
|
+ $fixed_sender_aliases = mailbox('get', 'sender_acl_handles', $username)['fixed_sender_aliases'];
|
|
|
foreach ($sender_acl_merged as $sender_acl) {
|
|
|
$domain = ltrim($sender_acl, '@');
|
|
|
if (is_valid_domain_name($domain)) {
|
|
|
$sender_acl = '@' . $domain;
|
|
|
}
|
|
|
+ // Don't add if allowed by alias
|
|
|
+ if (in_array($sender_acl, $fixed_sender_aliases)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
$stmt = $pdo->prepare("INSERT INTO `sender_acl` (`send_as`, `logged_in_as`)
|
|
|
VALUES (:sender_acl, :username)");
|
|
|
$stmt->execute(array(
|
|
@@ -2151,7 +2293,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `logged_in_as` = :username");
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `external` = 0 AND `logged_in_as` = :username");
|
|
|
$stmt->execute(array(
|
|
|
':username' => $username
|
|
|
));
|
|
@@ -2306,6 +2448,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$data['sender_acl_addresses']['rw'] = array();
|
|
|
$data['sender_acl_addresses']['selectable'] = array();
|
|
|
$data['fixed_sender_aliases'] = array();
|
|
|
+ $data['external_sender_aliases'] = array();
|
|
|
// Fixed addresses
|
|
|
$stmt = $pdo->prepare("SELECT `address` FROM `alias` WHERE `goto` REGEXP :goto AND `address` NOT LIKE '@%'");
|
|
|
$stmt->execute(array(':goto' => '(^|,)'.$_data.'($|,)'));
|
|
@@ -2323,9 +2466,18 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$data['fixed_sender_aliases'][] = $row['alias_domain_alias'];
|
|
|
}
|
|
|
}
|
|
|
+ // External addresses
|
|
|
+ $stmt = $pdo->prepare("SELECT `send_as` as `send_as_external` FROM `sender_acl` WHERE `logged_in_as` = :logged_in_as AND `external` = '1'");
|
|
|
+ $stmt->execute(array(':logged_in_as' => $_data));
|
|
|
+ $exernal_rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
+ while ($row = array_shift($exernal_rows)) {
|
|
|
+ if (!empty($row['send_as_external'])) {
|
|
|
+ $data['external_sender_aliases'][] = $row['send_as_external'];
|
|
|
+ }
|
|
|
+ }
|
|
|
// Return array $data['sender_acl_domains/addresses']['ro'] with read-only objects
|
|
|
// Return array $data['sender_acl_domains/addresses']['rw'] with read-write objects (can be deleted)
|
|
|
- $stmt = $pdo->prepare("SELECT REPLACE(`send_as`, '@', '') AS `send_as` FROM `sender_acl` WHERE `logged_in_as` = :logged_in_as AND (`send_as` LIKE '@%' OR `send_as` = '*')");
|
|
|
+ $stmt = $pdo->prepare("SELECT REPLACE(`send_as`, '@', '') AS `send_as` FROM `sender_acl` WHERE `logged_in_as` = :logged_in_as AND `external` = '0' AND (`send_as` LIKE '@%' OR `send_as` = '*')");
|
|
|
$stmt->execute(array(':logged_in_as' => $_data));
|
|
|
$domain_rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
while ($domain_row = array_shift($domain_rows)) {
|
|
@@ -2344,15 +2496,15 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$data['sender_acl_domains']['rw'][] = $domain_row['send_as'];
|
|
|
}
|
|
|
}
|
|
|
- $stmt = $pdo->prepare("SELECT `send_as` FROM `sender_acl` WHERE `logged_in_as` = :logged_in_as AND (`send_as` NOT LIKE '@%' AND `send_as` != '*')");
|
|
|
+ $stmt = $pdo->prepare("SELECT `send_as` FROM `sender_acl` WHERE `logged_in_as` = :logged_in_as AND `external` = '0' AND (`send_as` NOT LIKE '@%' AND `send_as` != '*')");
|
|
|
$stmt->execute(array(':logged_in_as' => $_data));
|
|
|
$address_rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
while ($address_row = array_shift($address_rows)) {
|
|
|
- if (filter_var($address_row['send_as'], FILTER_VALIDATE_EMAIL) && !hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $address_row['send_as'])) {
|
|
|
+ if (filter_var($address_row['send_as'], FILTER_VALIDATE_EMAIL) && !hasAliasObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $address_row['send_as'])) {
|
|
|
$data['sender_acl_addresses']['ro'][] = $address_row['send_as'];
|
|
|
continue;
|
|
|
}
|
|
|
- if (filter_var($address_row['send_as'], FILTER_VALIDATE_EMAIL) && hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $address_row['send_as'])) {
|
|
|
+ if (filter_var($address_row['send_as'], FILTER_VALIDATE_EMAIL) && hasAliasObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $address_row['send_as'])) {
|
|
|
$data['sender_acl_addresses']['rw'][] = $address_row['send_as'];
|
|
|
continue;
|
|
|
}
|
|
@@ -2361,12 +2513,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
WHERE `domain` NOT IN (
|
|
|
SELECT REPLACE(`send_as`, '@', '') FROM `sender_acl`
|
|
|
WHERE `logged_in_as` = :logged_in_as1
|
|
|
+ AND `external` = '0'
|
|
|
AND `send_as` LIKE '@%')
|
|
|
UNION
|
|
|
SELECT '*' FROM `domain`
|
|
|
WHERE '*' NOT IN (
|
|
|
SELECT `send_as` FROM `sender_acl`
|
|
|
WHERE `logged_in_as` = :logged_in_as2
|
|
|
+ AND `external` = '0'
|
|
|
)");
|
|
|
$stmt->execute(array(
|
|
|
':logged_in_as1' => $_data,
|
|
@@ -2388,6 +2542,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
AND `address` NOT IN (
|
|
|
SELECT `send_as` FROM `sender_acl`
|
|
|
WHERE `logged_in_as` = :logged_in_as
|
|
|
+ AND `external` = '0'
|
|
|
AND `send_as` NOT LIKE '@%')");
|
|
|
$stmt->execute(array(
|
|
|
':logged_in_as' => $_data,
|
|
@@ -2395,7 +2550,11 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
));
|
|
|
$rows_mbox = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
while ($row = array_shift($rows_mbox)) {
|
|
|
- if (filter_var($row['address'], FILTER_VALIDATE_EMAIL) && hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $row['address'])) {
|
|
|
+ // Aliases are not selectable
|
|
|
+ if (in_array($row['address'], $data['fixed_sender_aliases'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (filter_var($row['address'], FILTER_VALIDATE_EMAIL) && hasAliasObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $row['address'])) {
|
|
|
$data['sender_acl_addresses']['selectable'][] = $row['address'];
|
|
|
}
|
|
|
}
|
|
@@ -2852,7 +3011,13 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
':aliasdomain' => $_data,
|
|
|
));
|
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
+ $stmt = $pdo->prepare("SELECT `backupmx` FROM `domain` WHERE `domain` = :target_domain");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':target_domain' => $row['target_domain']
|
|
|
+ ));
|
|
|
+ $row_parent = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
$aliasdomaindata['alias_domain'] = $row['alias_domain'];
|
|
|
+ $aliasdomaindata['parent_is_backupmx'] = $row_parent['backupmx'];
|
|
|
$aliasdomaindata['target_domain'] = $row['target_domain'];
|
|
|
$aliasdomaindata['active'] = $row['active'];
|
|
|
$aliasdomaindata['rl'] = $rl;
|
|
@@ -2904,6 +3069,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
`description`,
|
|
|
`aliases`,
|
|
|
`mailboxes`,
|
|
|
+ `defquota`,
|
|
|
`maxquota`,
|
|
|
`quota`,
|
|
|
`relayhost`,
|
|
@@ -2935,6 +3101,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
if ($domaindata['max_new_mailbox_quota'] > ($row['maxquota'] * 1048576)) {
|
|
|
$domaindata['max_new_mailbox_quota'] = ($row['maxquota'] * 1048576);
|
|
|
}
|
|
|
+ $domaindata['def_new_mailbox_quota'] = $domaindata['max_new_mailbox_quota'];
|
|
|
+ if ($domaindata['def_new_mailbox_quota'] > ($row['defquota'] * 1048576)) {
|
|
|
+ $domaindata['def_new_mailbox_quota'] = ($row['defquota'] * 1048576);
|
|
|
+ }
|
|
|
$domaindata['quota_used_in_domain'] = $MailboxDataDomain['in_use'];
|
|
|
$domaindata['mboxes_in_domain'] = $MailboxDataDomain['count'];
|
|
|
$domaindata['mboxes_left'] = $row['mailboxes'] - $MailboxDataDomain['count'];
|
|
@@ -2942,6 +3112,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$domaindata['description'] = $row['description'];
|
|
|
$domaindata['max_num_aliases_for_domain'] = $row['aliases'];
|
|
|
$domaindata['max_num_mboxes_for_domain'] = $row['mailboxes'];
|
|
|
+ $domaindata['def_quota_for_mbox'] = $row['defquota'] * 1048576;
|
|
|
$domaindata['max_quota_for_mbox'] = $row['maxquota'] * 1048576;
|
|
|
$domaindata['max_quota_for_domain'] = $row['quota'] * 1048576;
|
|
|
$domaindata['relayhost'] = $row['relayhost'];
|
|
@@ -3006,7 +3177,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$mailboxdata['max_new_quota'] = ($DomainQuota['maxquota'] * 1048576);
|
|
|
}
|
|
|
$mailboxdata['username'] = $row['username'];
|
|
|
- $mailboxdata['rl'] = $rl;
|
|
|
+ if (!empty($rl)) {
|
|
|
+ $mailboxdata['rl'] = $rl;
|
|
|
+ $mailboxdata['rl_scope'] = 'mailbox';
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $mailboxdata['rl'] = ratelimit('get', 'domain', $row['domain']);
|
|
|
+ $mailboxdata['rl_scope'] = 'domain';
|
|
|
+ }
|
|
|
$mailboxdata['is_relayed'] = $row['backupmx'];
|
|
|
$mailboxdata['name'] = $row['name'];
|
|
|
$mailboxdata['active'] = $row['active'];
|
|
@@ -3016,10 +3194,13 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$mailboxdata['quota'] = $row['quota'];
|
|
|
$mailboxdata['attributes'] = json_decode($row['attributes'], true);
|
|
|
$mailboxdata['quota_used'] = intval($row['bytes']);
|
|
|
- $mailboxdata['percent_in_use'] = round((intval($row['bytes']) / intval($row['quota'])) * 100);
|
|
|
+ $mailboxdata['percent_in_use'] = ($row['quota'] == 0) ? '- ' : round((intval($row['bytes']) / intval($row['quota'])) * 100);
|
|
|
$mailboxdata['messages'] = $row['messages'];
|
|
|
$mailboxdata['spam_aliases'] = $SpamaliasUsage['sa_count'];
|
|
|
- if ($mailboxdata['percent_in_use'] >= 90) {
|
|
|
+ if ($mailboxdata['percent_in_use'] === '- ') {
|
|
|
+ $mailboxdata['percent_class'] = "info";
|
|
|
+ }
|
|
|
+ elseif ($mailboxdata['percent_in_use'] >= 90) {
|
|
|
$mailboxdata['percent_class'] = "danger";
|
|
|
}
|
|
|
elseif ($mailboxdata['percent_in_use'] >= 75) {
|
|
@@ -3317,7 +3498,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
- 'msg' => 'domain_not_empty'
|
|
|
+ 'msg' => array('domain_not_empty', $domain)
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
@@ -3411,6 +3592,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$stmt->execute(array(
|
|
|
':id' => $id
|
|
|
));
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sender_acl` WHERE `send_as` = :alias_address");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':alias_address' => $alias_data['address']
|
|
|
+ ));
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'success',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -3525,7 +3710,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
}
|
|
|
if (strtolower(getenv('SKIP_SOLR')) == 'n') {
|
|
|
$curl = curl_init();
|
|
|
- curl_setopt($curl, CURLOPT_URL, 'http://solr:8983/solr/dovecot/update?commit=true');
|
|
|
+ curl_setopt($curl, CURLOPT_URL, 'http://solr:8983/solr/dovecot-fts/update?commit=true');
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: text/xml'));
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
@@ -3587,7 +3772,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$stmt->execute(array(
|
|
|
':username' => $username
|
|
|
));
|
|
|
- $stmt = $pdo->prepare("DELETE FROM `sogo_acl` WHERE `c_object` LIKE '%/" . $username . "/%' OR `c_uid` = :username");
|
|
|
+ $stmt = $pdo->prepare("DELETE FROM `sogo_acl` WHERE `c_object` LIKE '%/" . str_replace('%', '\%', $username) . "/%' OR `c_uid` = :username");
|
|
|
$stmt->execute(array(
|
|
|
':username' => $username
|
|
|
));
|
|
@@ -3714,7 +3899,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
- if ($_action != 'get' && in_array($_type, array('domain', 'alias', 'alias_domain', 'mailbox'))) {
|
|
|
+ if ($_action != 'get' && in_array($_type, array('domain', 'alias', 'alias_domain', 'mailbox', 'resource'))) {
|
|
|
update_sogo_static_view();
|
|
|
}
|
|
|
}
|