|
@@ -4,6 +4,8 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
global $redis;
|
|
|
global $lang;
|
|
|
global $MAILBOX_DEFAULT_ATTRIBUTES;
|
|
|
+ global $iam_settings;
|
|
|
+
|
|
|
$_data_log = $_data;
|
|
|
!isset($_data_log['password']) ?: $_data_log['password'] = '*';
|
|
|
!isset($_data_log['password2']) ?: $_data_log['password2'] = '*';
|
|
@@ -1005,6 +1007,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$local_part = strtolower(trim($_data['local_part']));
|
|
|
$domain = idn_to_ascii(strtolower(trim($_data['domain'])), 0, INTL_IDNA_VARIANT_UTS46);
|
|
|
$username = $local_part . '@' . $domain;
|
|
|
+ $authsource = 'mailcow';
|
|
|
if (!filter_var($username, FILTER_VALIDATE_EMAIL)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -1021,15 +1024,19 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
+ if ($_data['authsource'] == "mailcow" ||
|
|
|
+ in_array($_data['authsource'], array('keycloak', 'generic-oidc', 'ldap')) && $iam_settings['authsource'] == $_data['authsource']){
|
|
|
+ $authsource = $_data['authsource'];
|
|
|
+ }
|
|
|
if (empty($name)) {
|
|
|
$name = $local_part;
|
|
|
}
|
|
|
$template_attr = null;
|
|
|
if ($_data['template']){
|
|
|
- $template_attr = mailbox('get', 'mailbox_templates', $_data['template'])['attributes'];
|
|
|
+ $template_attr = mailbox('get', 'mailbox_templates', $_data['template'], $_extra)['attributes'];
|
|
|
}
|
|
|
if (empty($template_attr)) {
|
|
|
- $template_attr = mailbox('get', 'mailbox_templates')[0]['attributes'];
|
|
|
+ $template_attr = mailbox('get', 'mailbox_templates', null, $_extra)[0]['attributes'];
|
|
|
}
|
|
|
$MAILBOX_DEFAULT_ATTRIBUTES = array_merge($MAILBOX_DEFAULT_ATTRIBUTES, $template_attr);
|
|
|
|
|
@@ -1038,7 +1045,12 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$name = ltrim(rtrim($_data['name'], '>'), '<');
|
|
|
$tags = (isset($_data['tags'])) ? $_data['tags'] : $MAILBOX_DEFAULT_ATTRIBUTES['tags'];
|
|
|
$quota_m = (isset($_data['quota'])) ? intval($_data['quota']) : intval($MAILBOX_DEFAULT_ATTRIBUTES['quota']) / 1024 ** 2;
|
|
|
- if ((!isset($_SESSION['acl']['unlimited_quota']) || $_SESSION['acl']['unlimited_quota'] != "1") && $quota_m === 0) {
|
|
|
+ if ($authsource != 'mailcow'){
|
|
|
+ $password = '';
|
|
|
+ $password2 = '';
|
|
|
+ $password_hashed = '';
|
|
|
+ }
|
|
|
+ if (!hasACLAccess("unlimited_quota") && $quota_m === 0) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1067,6 +1079,10 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$quarantine_notification = (isset($_data['quarantine_notification'])) ? strval($_data['quarantine_notification']) : strval($MAILBOX_DEFAULT_ATTRIBUTES['quarantine_notification']);
|
|
|
$quarantine_category = (isset($_data['quarantine_category'])) ? strval($_data['quarantine_category']) : strval($MAILBOX_DEFAULT_ATTRIBUTES['quarantine_category']);
|
|
|
$quota_b = ($quota_m * 1048576);
|
|
|
+ $attribute_hash = (!empty($_data['attribute_hash'])) ? $_data['attribute_hash'] : '';
|
|
|
+ if (in_array($authsource, array('keycloak', 'generic-oidc', 'ldap'))){
|
|
|
+ $force_pw_update = 0;
|
|
|
+ }
|
|
|
$mailbox_attrs = json_encode(
|
|
|
array(
|
|
|
'force_pw_update' => strval($force_pw_update),
|
|
@@ -1081,7 +1097,8 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'passwd_update' => time(),
|
|
|
'mailbox_format' => strval($MAILBOX_DEFAULT_ATTRIBUTES['mailbox_format']),
|
|
|
'quarantine_notification' => strval($quarantine_notification),
|
|
|
- 'quarantine_category' => strval($quarantine_category)
|
|
|
+ 'quarantine_category' => strval($quarantine_category),
|
|
|
+ 'attribute_hash' => $attribute_hash
|
|
|
)
|
|
|
);
|
|
|
if (!is_valid_domain_name($domain)) {
|
|
@@ -1156,10 +1173,12 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- if (password_check($password, $password2) !== true) {
|
|
|
- return false;
|
|
|
+ if ($authsource == 'mailcow'){
|
|
|
+ if (password_check($password, $password2) !== true) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $password_hashed = hash_password($password);
|
|
|
}
|
|
|
- $password_hashed = hash_password($password);
|
|
|
if ($MailboxData['count'] >= $DomainData['mailboxes']) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -1185,8 +1204,8 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
return false;
|
|
|
}
|
|
|
- $stmt = $pdo->prepare("INSERT INTO `mailbox` (`username`, `password`, `name`, `quota`, `local_part`, `domain`, `attributes`, `active`)
|
|
|
- VALUES (:username, :password_hashed, :name, :quota_b, :local_part, :domain, :mailbox_attrs, :active)");
|
|
|
+ $stmt = $pdo->prepare("INSERT INTO `mailbox` (`username`, `password`, `name`, `quota`, `local_part`, `domain`, `attributes`, `authsource`, `active`)
|
|
|
+ VALUES (:username, :password_hashed, :name, :quota_b, :local_part, :domain, :mailbox_attrs, :authsource, :active)");
|
|
|
$stmt->execute(array(
|
|
|
':username' => $username,
|
|
|
':password_hashed' => $password_hashed,
|
|
@@ -1195,6 +1214,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
':local_part' => $local_part,
|
|
|
':domain' => $domain,
|
|
|
':mailbox_attrs' => $mailbox_attrs,
|
|
|
+ ':authsource' => $authsource,
|
|
|
':active' => $active
|
|
|
));
|
|
|
$stmt = $pdo->prepare("UPDATE `mailbox` SET
|
|
@@ -1214,11 +1234,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
break;
|
|
|
}
|
|
|
- $stmt = $pdo->prepare("INSERT INTO `tags_mailbox` (`username`, `tag_name`) VALUES (:username, :tag_name)");
|
|
|
- $stmt->execute(array(
|
|
|
- ':username' => $username,
|
|
|
- ':tag_name' => $tag,
|
|
|
- ));
|
|
|
+ try {
|
|
|
+ $stmt = $pdo->prepare("INSERT INTO `tags_mailbox` (`username`, `tag_name`) VALUES (:username, :tag_name)");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':username' => $username,
|
|
|
+ ':tag_name' => $tag,
|
|
|
+ ));
|
|
|
+ } catch (Exception $e) {
|
|
|
+ }
|
|
|
}
|
|
|
$stmt = $pdo->prepare("INSERT INTO `quota2` (`username`, `bytes`, `messages`)
|
|
|
VALUES (:username, '0', '0') ON DUPLICATE KEY UPDATE `bytes` = '0', `messages` = '0';");
|
|
@@ -1312,16 +1335,62 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'object' => $username,
|
|
|
'rl_frame' => $_data['rl_frame'],
|
|
|
'rl_value' => $_data['rl_value']
|
|
|
- ));
|
|
|
+ ), $_extra);
|
|
|
}
|
|
|
|
|
|
- update_sogo_static_view($username);
|
|
|
+ try {
|
|
|
+ update_sogo_static_view($username);
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => $e->getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'success',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
'msg' => array('mailbox_added', htmlspecialchars($username))
|
|
|
);
|
|
|
- return true;
|
|
|
+ break;
|
|
|
+ case 'mailbox_from_template':
|
|
|
+ $stmt = $pdo->prepare("SELECT * FROM `templates`
|
|
|
+ WHERE `template` = :template AND type = 'mailbox'");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ":template" => $_data['template']
|
|
|
+ ));
|
|
|
+ $mbox_template_data = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
+ if (empty($mbox_template_data)){
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'template_missing'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $attribute_hash = sha1(json_encode($mbox_template_data["attributes"]));
|
|
|
+ $mbox_template_data = json_decode($mbox_template_data["attributes"], true);
|
|
|
+ $mbox_template_data['domain'] = $_data['domain'];
|
|
|
+ $mbox_template_data['name'] = $_data['name'];
|
|
|
+ $mbox_template_data['local_part'] = $_data['local_part'];
|
|
|
+ $mbox_template_data['authsource'] = $_data['authsource'];
|
|
|
+ $mbox_template_data['attribute_hash'] = $attribute_hash;
|
|
|
+ $mbox_template_data['quota'] = intval($mbox_template_data['quota'] / 1048576);
|
|
|
+
|
|
|
+ $mailbox_attributes = array('acl' => array());
|
|
|
+ foreach ($mbox_template_data as $key => $value){
|
|
|
+ switch (true) {
|
|
|
+ case (strpos($key, 'acl_') === 0 && $value != 0):
|
|
|
+ array_push($mailbox_attributes['acl'], str_replace('acl_' , '', $key));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $mailbox_attributes[$key] = $value;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return mailbox('add', 'mailbox', $mailbox_attributes);
|
|
|
break;
|
|
|
case 'resource':
|
|
|
$domain = idn_to_ascii(strtolower(trim($_data['domain'])), 0, INTL_IDNA_VARIANT_UTS46);
|
|
@@ -1689,7 +1758,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
else {
|
|
|
$usernames = $_data['username'];
|
|
|
}
|
|
|
- if (!isset($_SESSION['acl']['tls_policy']) || $_SESSION['acl']['tls_policy'] != "1" ) {
|
|
|
+ if (!hasACLAccess("tls_policy")) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1698,7 +1767,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
return false;
|
|
|
}
|
|
|
foreach ($usernames as $username) {
|
|
|
- if (!filter_var($username, FILTER_VALIDATE_EMAIL) || !hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) {
|
|
|
+ if (!hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1706,7 +1775,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- $is_now = mailbox('get', 'tls_policy', $username);
|
|
|
+ $is_now = mailbox('get', 'tls_policy', $username, $_extra);
|
|
|
if (!empty($is_now)) {
|
|
|
$tls_enforce_in = (isset($_data['tls_enforce_in'])) ? intval($_data['tls_enforce_in']) : $is_now['tls_enforce_in'];
|
|
|
$tls_enforce_out = (isset($_data['tls_enforce_out'])) ? intval($_data['tls_enforce_out']) : $is_now['tls_enforce_out'];
|
|
@@ -1743,7 +1812,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
else {
|
|
|
$usernames = $_data['username'];
|
|
|
}
|
|
|
- if (!isset($_SESSION['acl']['quarantine_notification']) || $_SESSION['acl']['quarantine_notification'] != "1" ) {
|
|
|
+ if (!hasACLAccess("quarantine_notification")) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1752,7 +1821,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
return false;
|
|
|
}
|
|
|
foreach ($usernames as $username) {
|
|
|
- if (!filter_var($username, FILTER_VALIDATE_EMAIL) || !hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) {
|
|
|
+ if (!hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1760,7 +1829,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- $is_now = mailbox('get', 'quarantine_notification', $username);
|
|
|
+ $is_now = mailbox('get', 'quarantine_notification', $username, $_extra);
|
|
|
if (!empty($is_now)) {
|
|
|
$quarantine_notification = (isset($_data['quarantine_notification'])) ? $_data['quarantine_notification'] : $is_now['quarantine_notification'];
|
|
|
}
|
|
@@ -1802,7 +1871,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
else {
|
|
|
$usernames = $_data['username'];
|
|
|
}
|
|
|
- if (!isset($_SESSION['acl']['quarantine_category']) || $_SESSION['acl']['quarantine_category'] != "1" ) {
|
|
|
+ if (!hasACLAccess("quarantine_category")) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1811,7 +1880,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
return false;
|
|
|
}
|
|
|
foreach ($usernames as $username) {
|
|
|
- if (!filter_var($username, FILTER_VALIDATE_EMAIL) || !hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) {
|
|
|
+ if (!hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -1819,7 +1888,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- $is_now = mailbox('get', 'quarantine_category', $username);
|
|
|
+ $is_now = mailbox('get', 'quarantine_category', $username, $_extra);
|
|
|
if (!empty($is_now)) {
|
|
|
$quarantine_category = (isset($_data['quarantine_category'])) ? $_data['quarantine_category'] : $is_now['quarantine_category'];
|
|
|
}
|
|
@@ -2863,7 +2932,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- $is_now = mailbox('get', 'mailbox_details', $username);
|
|
|
+ $is_now = mailbox('get', 'mailbox_details', $username, $_extra);
|
|
|
if (isset($_data['protocol_access'])) {
|
|
|
$_data['protocol_access'] = (array)$_data['protocol_access'];
|
|
|
$_data['imap_access'] = (in_array('imap', $_data['protocol_access'])) ? 1 : 0;
|
|
@@ -2874,20 +2943,29 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
if (!empty($is_now)) {
|
|
|
$active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active'];
|
|
|
(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']) && isset($_SESSION['acl']['sogo_access']) && $_SESSION['acl']['sogo_access'] == "1") ? intval($_data['sogo_access']) : intval($is_now['attributes']['sogo_access']);
|
|
|
- (int)$imap_access = (isset($_data['imap_access']) && isset($_SESSION['acl']['protocol_access']) && $_SESSION['acl']['protocol_access'] == "1") ? intval($_data['imap_access']) : intval($is_now['attributes']['imap_access']);
|
|
|
- (int)$pop3_access = (isset($_data['pop3_access']) && isset($_SESSION['acl']['protocol_access']) && $_SESSION['acl']['protocol_access'] == "1") ? intval($_data['pop3_access']) : intval($is_now['attributes']['pop3_access']);
|
|
|
- (int)$smtp_access = (isset($_data['smtp_access']) && isset($_SESSION['acl']['protocol_access']) && $_SESSION['acl']['protocol_access'] == "1") ? intval($_data['smtp_access']) : intval($is_now['attributes']['smtp_access']);
|
|
|
- (int)$sieve_access = (isset($_data['sieve_access']) && isset($_SESSION['acl']['protocol_access']) && $_SESSION['acl']['protocol_access'] == "1") ? intval($_data['sieve_access']) : intval($is_now['attributes']['sieve_access']);
|
|
|
- (int)$relayhost = (isset($_data['relayhost']) && isset($_SESSION['acl']['mailbox_relayhost']) && $_SESSION['acl']['mailbox_relayhost'] == "1") ? intval($_data['relayhost']) : intval($is_now['attributes']['relayhost']);
|
|
|
+ (int)$sogo_access = (isset($_data['sogo_access']) && hasACLAccess("sogo_access")) ? intval($_data['sogo_access']) : intval($is_now['attributes']['sogo_access']);
|
|
|
+ (int)$imap_access = (isset($_data['imap_access']) && hasACLAccess("protocol_access")) ? intval($_data['imap_access']) : intval($is_now['attributes']['imap_access']);
|
|
|
+ (int)$pop3_access = (isset($_data['pop3_access']) && hasACLAccess("protocol_access")) ? intval($_data['pop3_access']) : intval($is_now['attributes']['pop3_access']);
|
|
|
+ (int)$smtp_access = (isset($_data['smtp_access']) && hasACLAccess("protocol_access")) ? intval($_data['smtp_access']) : intval($is_now['attributes']['smtp_access']);
|
|
|
+ (int)$sieve_access = (isset($_data['sieve_access']) && hasACLAccess("protocol_access")) ? intval($_data['sieve_access']) : intval($is_now['attributes']['sieve_access']);
|
|
|
+ (int)$relayhost = (isset($_data['relayhost']) && hasACLAccess("mailbox_relayhost")) ? intval($_data['relayhost']) : intval($is_now['attributes']['relayhost']);
|
|
|
(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_b = $quota_m * 1048576;
|
|
|
$password = (!empty($_data['password'])) ? $_data['password'] : null;
|
|
|
$password2 = (!empty($_data['password2'])) ? $_data['password2'] : null;
|
|
|
- $pw_recovery_email = (isset($_data['pw_recovery_email'])) ? $_data['pw_recovery_email'] : $is_now['attributes']['recovery_email'];
|
|
|
$tags = (is_array($_data['tags']) ? $_data['tags'] : array());
|
|
|
+ $attribute_hash = (!empty($_data['attribute_hash'])) ? $_data['attribute_hash'] : '';
|
|
|
+ $authsource = $is_now['authsource'];
|
|
|
+ if ($_data['authsource'] == "mailcow" ||
|
|
|
+ in_array($_data['authsource'], array('keycloak', 'generic-oidc', 'ldap')) && $iam_settings['authsource'] == $_data['authsource']){
|
|
|
+ $authsource = $_data['authsource'];
|
|
|
+ }
|
|
|
+ if (in_array($authsource, array('keycloak', 'generic-oidc', 'ldap'))){
|
|
|
+ $force_pw_update = 0;
|
|
|
+ }
|
|
|
+ $pw_recovery_email = (isset($_data['pw_recovery_email']) && $authsource == 'mailcow') ? $_data['pw_recovery_email'] : $is_now['attributes']['recovery_email'];
|
|
|
}
|
|
|
else {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -2898,7 +2976,7 @@ 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)) {
|
|
|
+ if (!hasACLAccess("unlimited_quota") && ($quota_m == 0 && $is_now['quota'] != 0)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -2914,7 +2992,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
continue;
|
|
|
}
|
|
|
- $DomainData = mailbox('get', 'domain_details', $domain);
|
|
|
+ $DomainData = mailbox('get', 'domain_details', $domain, $_extra);
|
|
|
if ($quota_m > ($is_now['max_new_quota'] / 1048576)) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
@@ -2933,7 +3011,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
}
|
|
|
$extra_acls = array();
|
|
|
if (isset($_data['extended_sender_acl'])) {
|
|
|
- if (!isset($_SESSION['acl']['extend_sender_acl']) || $_SESSION['acl']['extend_sender_acl'] != "1" ) {
|
|
|
+ if (!hasACLAccess("extend_sender_acl")) {
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'danger',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -3126,7 +3204,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$stmt = $pdo->prepare("UPDATE `mailbox` SET
|
|
|
`password` = :password_hashed,
|
|
|
`attributes` = JSON_SET(`attributes`, '$.passwd_update', NOW())
|
|
|
- WHERE `username` = :username");
|
|
|
+ WHERE `username` = :username AND authsource = 'mailcow'");
|
|
|
$stmt->execute(array(
|
|
|
':password_hashed' => $password_hashed,
|
|
|
':username' => $username
|
|
@@ -3145,6 +3223,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
`active` = :active,
|
|
|
`name`= :name,
|
|
|
`quota` = :quota_b,
|
|
|
+ `authsource` = :authsource,
|
|
|
`attributes` = JSON_SET(`attributes`, '$.force_pw_update', :force_pw_update),
|
|
|
`attributes` = JSON_SET(`attributes`, '$.sogo_access', :sogo_access),
|
|
|
`attributes` = JSON_SET(`attributes`, '$.imap_access', :imap_access),
|
|
@@ -3152,22 +3231,25 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
`attributes` = JSON_SET(`attributes`, '$.pop3_access', :pop3_access),
|
|
|
`attributes` = JSON_SET(`attributes`, '$.relayhost', :relayhost),
|
|
|
`attributes` = JSON_SET(`attributes`, '$.smtp_access', :smtp_access),
|
|
|
- `attributes` = JSON_SET(`attributes`, '$.recovery_email', :recovery_email)
|
|
|
+ `attributes` = JSON_SET(`attributes`, '$.recovery_email', :recovery_email),
|
|
|
+ `attributes` = JSON_SET(`attributes`, '$.attribute_hash', :attribute_hash)
|
|
|
WHERE `username` = :username");
|
|
|
- $stmt->execute(array(
|
|
|
- ':active' => $active,
|
|
|
- ':name' => $name,
|
|
|
- ':quota_b' => $quota_b,
|
|
|
- ':force_pw_update' => $force_pw_update,
|
|
|
- ':sogo_access' => $sogo_access,
|
|
|
- ':imap_access' => $imap_access,
|
|
|
- ':pop3_access' => $pop3_access,
|
|
|
- ':sieve_access' => $sieve_access,
|
|
|
- ':smtp_access' => $smtp_access,
|
|
|
- ':recovery_email' => $pw_recovery_email,
|
|
|
- ':relayhost' => $relayhost,
|
|
|
- ':username' => $username
|
|
|
- ));
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':active' => $active,
|
|
|
+ ':name' => $name,
|
|
|
+ ':quota_b' => $quota_b,
|
|
|
+ ':attribute_hash' => $attribute_hash,
|
|
|
+ ':force_pw_update' => $force_pw_update,
|
|
|
+ ':sogo_access' => $sogo_access,
|
|
|
+ ':imap_access' => $imap_access,
|
|
|
+ ':pop3_access' => $pop3_access,
|
|
|
+ ':sieve_access' => $sieve_access,
|
|
|
+ ':smtp_access' => $smtp_access,
|
|
|
+ ':recovery_email' => $pw_recovery_email,
|
|
|
+ ':relayhost' => $relayhost,
|
|
|
+ ':username' => $username,
|
|
|
+ ':authsource' => $authsource
|
|
|
+ ));
|
|
|
}
|
|
|
catch (PDOException $e) {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -3188,11 +3270,14 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
);
|
|
|
break;
|
|
|
}
|
|
|
- $stmt = $pdo->prepare("INSERT INTO `tags_mailbox` (`username`, `tag_name`) VALUES (:username, :tag_name)");
|
|
|
- $stmt->execute(array(
|
|
|
- ':username' => $username,
|
|
|
- ':tag_name' => $tag,
|
|
|
- ));
|
|
|
+ try {
|
|
|
+ $stmt = $pdo->prepare("INSERT INTO `tags_mailbox` (`username`, `tag_name`) VALUES (:username, :tag_name)");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ':username' => $username,
|
|
|
+ ':tag_name' => $tag,
|
|
|
+ ));
|
|
|
+ } catch (Exception $e) {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -3201,7 +3286,15 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'msg' => array('mailbox_modified', $username)
|
|
|
);
|
|
|
|
|
|
- update_sogo_static_view($username);
|
|
|
+ try {
|
|
|
+ update_sogo_static_view($username);
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => $e->getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
return true;
|
|
|
break;
|
|
@@ -3401,6 +3494,75 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
'msg' => array('mailbox_renamed', $old_username, $new_username)
|
|
|
);
|
|
|
break;
|
|
|
+ case 'mailbox_from_template':
|
|
|
+ $stmt = $pdo->prepare("SELECT * FROM `templates`
|
|
|
+ WHERE `template` = :template AND type = 'mailbox'");
|
|
|
+ $stmt->execute(array(
|
|
|
+ ":template" => $_data['template']
|
|
|
+ ));
|
|
|
+ $mbox_template_data = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
+ if (empty($mbox_template_data)){
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'danger',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => 'template_missing'
|
|
|
+ );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $attribute_hash = sha1(json_encode($mbox_template_data["attributes"]));
|
|
|
+ $is_now = mailbox('get', 'mailbox_details', $_data['username']);
|
|
|
+ $name = ltrim(rtrim($_data['name'], '>'), '<');
|
|
|
+ if ($is_now['attributes']['attribute_hash'] == $attribute_hash && $is_now['name'] == $name)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ $mbox_template_data = json_decode($mbox_template_data["attributes"], true);
|
|
|
+ $mbox_template_data['attribute_hash'] = $attribute_hash;
|
|
|
+ $mbox_template_data['name'] = $name;
|
|
|
+ $quarantine_attributes = array('username' => $_data['username']);
|
|
|
+ $tls_attributes = array('username' => $_data['username']);
|
|
|
+ $ratelimit_attributes = array('object' => $_data['username']);
|
|
|
+ $acl_attributes = array('username' => $_data['username'], 'user_acl' => array());
|
|
|
+ $mailbox_attributes = array('username' => $_data['username']);
|
|
|
+ foreach ($mbox_template_data as $key => $value){
|
|
|
+ switch (true) {
|
|
|
+ case (strpos($key, 'quarantine_') === 0):
|
|
|
+ $quarantine_attributes[$key] = $value;
|
|
|
+ break;
|
|
|
+ case (strpos($key, 'tls_') === 0):
|
|
|
+ if ($value == null)
|
|
|
+ $value = 0;
|
|
|
+ $tls_attributes[$key] = $value;
|
|
|
+ break;
|
|
|
+ case (strpos($key, 'rl_') === 0):
|
|
|
+ $ratelimit_attributes[$key] = $value;
|
|
|
+ break;
|
|
|
+ case (strpos($key, 'acl_') === 0 && $value != 0):
|
|
|
+ array_push($acl_attributes['user_acl'], str_replace('acl_' , '', $key));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $mailbox_attributes[$key] = $value;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $mailbox_attributes['quota'] = intval($mailbox_attributes['quota'] / 1048576);
|
|
|
+ $result = mailbox('edit', 'mailbox', $mailbox_attributes);
|
|
|
+ if ($result === false) return $result;
|
|
|
+ $result = mailbox('edit', 'tls_policy', $tls_attributes);
|
|
|
+ if ($result === false) return $result;
|
|
|
+ $result = mailbox('edit', 'quarantine_notification', $quarantine_attributes);
|
|
|
+ if ($result === false) return $result;
|
|
|
+ $result = mailbox('edit', 'quarantine_category', $quarantine_attributes);
|
|
|
+ if ($result === false) return $result;
|
|
|
+ $result = ratelimit('edit', 'mailbox', $ratelimit_attributes);
|
|
|
+ if ($result === false) return $result;
|
|
|
+ $result = acl('edit', 'user', $acl_attributes);
|
|
|
+ if ($result === false) return $result;
|
|
|
+
|
|
|
+ $_SESSION['return'] = array();
|
|
|
+ return true;
|
|
|
+ break;
|
|
|
case 'mailbox_templates':
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
|
|
$_SESSION['return'][] = array(
|
|
@@ -4666,6 +4828,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
`mailbox`.`quota`,
|
|
|
`mailbox`.`created`,
|
|
|
`mailbox`.`modified`,
|
|
|
+ `mailbox`.`authsource`,
|
|
|
`quota2`.`bytes`,
|
|
|
`attributes`,
|
|
|
`custom_attributes`,
|
|
@@ -4687,6 +4850,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
`mailbox`.`quota`,
|
|
|
`mailbox`.`created`,
|
|
|
`mailbox`.`modified`,
|
|
|
+ `mailbox`.`authsource`,
|
|
|
`quota2replica`.`bytes`,
|
|
|
`attributes`,
|
|
|
`custom_attributes`,
|
|
@@ -4716,6 +4880,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
$mailboxdata['percent_in_use'] = ($row['quota'] == 0) ? '- ' : round((intval($row['bytes']) / intval($row['quota'])) * 100);
|
|
|
$mailboxdata['created'] = $row['created'];
|
|
|
$mailboxdata['modified'] = $row['modified'];
|
|
|
+ $mailboxdata['authsource'] = ($row['authsource']) ? $row['authsource'] : 'mailcow';
|
|
|
|
|
|
if ($mailboxdata['percent_in_use'] === '- ') {
|
|
|
$mailboxdata['percent_class'] = "info";
|
|
@@ -4746,7 +4911,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
else if ($SaslLogs['service'] == 'pop3') {
|
|
|
$last_pop3_login = strtotime($SaslLogs['datetime']);
|
|
|
}
|
|
|
- else if ($SaslLogs['service'] == 'SSO') {
|
|
|
+ else if ($SaslLogs['service'] == 'SSO') {
|
|
|
$last_sso_login = strtotime($SaslLogs['datetime']);
|
|
|
}
|
|
|
}
|
|
@@ -4759,7 +4924,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
if (!isset($last_pop3_login) || $GLOBALS['SHOW_LAST_LOGIN'] === false) {
|
|
|
$last_pop3_login = 0;
|
|
|
}
|
|
|
- if (!isset($last_sso_login) || $GLOBALS['SHOW_LAST_LOGIN'] === false) {
|
|
|
+ if (!isset($last_sso_login) || $GLOBALS['SHOW_LAST_LOGIN'] === false) {
|
|
|
$last_sso_login = 0;
|
|
|
}
|
|
|
$mailboxdata['last_imap_login'] = $last_imap_login;
|
|
@@ -4811,7 +4976,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
return $mailboxdata;
|
|
|
break;
|
|
|
case 'mailbox_templates':
|
|
|
- if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") {
|
|
|
+ if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin" && $_SESSION['access_all_exception'] != "1") {
|
|
|
return false;
|
|
|
}
|
|
|
$_data = (isset($_data)) ? intval($_data) : null;
|
|
@@ -5565,7 +5730,15 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- update_sogo_static_view($username);
|
|
|
+ try {
|
|
|
+ update_sogo_static_view($username);
|
|
|
+ }catch (PDOException $e) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'success',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => $e->getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
$_SESSION['return'][] = array(
|
|
|
'type' => 'success',
|
|
|
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
@@ -5779,6 +5952,16 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
|
|
|
break;
|
|
|
}
|
|
|
if ($_action != 'get' && in_array($_type, array('domain', 'alias', 'alias_domain', 'resource')) && getenv('SKIP_SOGO') != "y") {
|
|
|
- update_sogo_static_view();
|
|
|
+ try {
|
|
|
+ update_sogo_static_view();
|
|
|
+ }catch (PDOException $e) {
|
|
|
+ $_SESSION['return'][] = array(
|
|
|
+ 'type' => 'success',
|
|
|
+ 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
|
|
+ 'msg' => $e->getMessage()
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|