Initial push or quick actions in alias table

This commit is contained in:
andryyy 2017-04-26 23:38:18 +02:00
parent a03b36e0c3
commit 5586bd2bb5
7 changed files with 504 additions and 327 deletions

View File

@ -16,4 +16,17 @@ table.footable>tbody>tr.footable-empty>td {
font-style: italic; font-style: italic;
display:block; display:block;
padding: 10px; padding: 10px;
} }
.mass-each-action {
font-style: italic;
padding: 0 3px 0 3px;
user-select: none;
}
.mass-actions {
user-select: none;
padding:10px;
}
.mass-select-all {
cursor:pointer;
color:grey;
}

View File

@ -50,3 +50,8 @@ pre{white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-s
-ms-user-select: none; -ms-user-select: none;
user-select: none; user-select: none;
} }
/* Fix modal moving content left */
body.modal-open {
overflow: inherit;
padding-right: inherit !important;
}

View File

@ -3308,82 +3308,95 @@ function mailbox_edit_alias_domain($postarray) {
); );
} }
function mailbox_edit_alias($postarray) { function mailbox_edit_alias($postarray) {
// Array elements // We can edit multiple addresses at once, but only set one "goto" and/or "active" attribute for all
// address string // address string or array containing strings | email | required
// goto string (separated by " ", "," ";" "\n") - email address or domain // goto string | separated by " ", "," ";" "\n", email or domain | optional
// active int // active set (active) or unset (inactive)
global $lang; global $lang;
global $pdo; global $pdo;
$address = $postarray['address']; if (!is_array($postarray['address'])) {
$domain = idn_to_ascii(substr(strstr($address, '@'), 1)); $address_array = array();
$local_part = strstr($address, '@', true); $address_array[] = $postarray['address'];
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) { }
$_SESSION['return'] = array( else {
'type' => 'danger', $address_array = $postarray['address'];
'msg' => sprintf($lang['danger']['access_denied']) }
); if (isset($postarray['goto']) || !empty($postarray['goto'])) {
return false; $gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $postarray['goto']));
} foreach ($gotos as &$goto) {
if (empty($postarray['goto'])) { if (empty($goto)) {
$_SESSION['return'] = array( continue;
'type' => 'danger', }
'msg' => sprintf($lang['danger']['goto_empty']) if (!filter_var($goto, FILTER_VALIDATE_EMAIL)) {
); $_SESSION['return'] = array(
return false; 'type' => 'danger',
} 'msg' =>sprintf($lang['danger']['goto_invalid'])
$gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $postarray['goto'])); );
foreach ($gotos as &$goto) { return false;
if (empty($goto)) { }
continue; if ($goto == $address) {
} $_SESSION['return'] = array(
if (!filter_var($goto, FILTER_VALIDATE_EMAIL)) { 'type' => 'danger',
$_SESSION['return'] = array( 'msg' => sprintf($lang['danger']['alias_goto_identical'])
'type' => 'danger', );
'msg' =>sprintf($lang['danger']['goto_invalid']) return false;
); }
return false; }
} $gotos = array_filter($gotos);
if ($goto == $address) { $goto = implode(",", $gotos);
$_SESSION['return'] = array( }
'type' => 'danger',
'msg' => sprintf($lang['danger']['alias_goto_identical'])
);
return false;
}
}
$gotos = array_filter($gotos);
$goto = implode(",", $gotos);
isset($postarray['active']) ? $active = '1' : $active = '0'; isset($postarray['active']) ? $active = '1' : $active = '0';
if ((!filter_var($address, FILTER_VALIDATE_EMAIL) === true) && !empty($local_part)) { foreach ($address_array as $address) {
$_SESSION['return'] = array( $domain = idn_to_ascii(substr(strstr($address, '@'), 1));
'type' => 'danger', $local_part = strstr($address, '@', true);
'msg' => sprintf($lang['danger']['alias_invalid']) if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
); $_SESSION['return'] = array(
return false; 'type' => 'danger',
} 'msg' => sprintf($lang['danger']['access_denied'])
);
try { return false;
$stmt = $pdo->prepare("UPDATE `alias` SET }
`goto` = :goto, if ((!filter_var($address, FILTER_VALIDATE_EMAIL) === true) && !empty($local_part)) {
`active`= :active $_SESSION['return'] = array(
WHERE `address` = :address"); 'type' => 'danger',
$stmt->execute(array( 'msg' => sprintf($lang['danger']['alias_invalid'])
':goto' => $goto, );
':active' => $active, return false;
':address' => $address }
)); try {
$_SESSION['return'] = array( if (isset($goto) && !empty($goto)) {
'type' => 'success', $stmt = $pdo->prepare("UPDATE `alias` SET
'msg' => sprintf($lang['success']['alias_modified'], htmlspecialchars($address)) `goto` = :goto,
); `active`= :active
} WHERE `address` = :address");
catch (PDOException $e) { $stmt->execute(array(
$_SESSION['return'] = array( ':goto' => $goto,
'type' => 'danger', ':active' => $active,
'msg' => 'MySQL: '.$e ':address' => $address
); ));
return false; }
else {
$stmt = $pdo->prepare("UPDATE `alias` SET
`active`= :active
WHERE `address` = :address");
$stmt->execute(array(
':active' => $active,
':address' => $address
));
}
}
catch (PDOException $e) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => 'MySQL: '.$e
);
return false;
}
} }
$_SESSION['return'] = array(
'type' => 'success',
'msg' => sprintf($lang['success']['alias_modified'], htmlspecialchars(implode(', ', $address_array)))
);
} }
function mailbox_edit_domain($postarray) { function mailbox_edit_domain($postarray) {
// Array elements // Array elements
@ -4527,48 +4540,57 @@ function mailbox_delete_domain($postarray) {
return true; return true;
} }
function mailbox_delete_alias($postarray) { function mailbox_delete_alias($postarray) {
// $postarray['address'] can be a single element or an array
global $lang; global $lang;
global $pdo; global $pdo;
$address = $postarray['address']; if (!is_array($postarray['address'])) {
$local_part = strstr($address, '@', true); $address_array = array();
$domain = mailbox_get_alias_details($address)['domain']; $address_array[] = $postarray['address'];
try { }
$stmt = $pdo->prepare("SELECT `goto` FROM `alias` WHERE `address` = :address"); else {
$stmt->execute(array(':address' => $address)); $address_array = $postarray['address'];
$gotos = $stmt->fetch(PDO::FETCH_ASSOC); }
} foreach ($address_array as $address) {
catch(PDOException $e) { $local_part = strstr($address, '@', true);
$_SESSION['return'] = array( $domain = mailbox_get_alias_details($address)['domain'];
'type' => 'danger', try {
'msg' => 'MySQL: '.$e $stmt = $pdo->prepare("SELECT `goto` FROM `alias` WHERE `address` = :address");
); $stmt->execute(array(':address' => $address));
return false; $gotos = $stmt->fetch(PDO::FETCH_ASSOC);
} }
$goto_array = explode(',', $gotos['goto']); catch(PDOException $e) {
$_SESSION['return'] = array(
'type' => 'danger',
'msg' => 'MySQL: '.$e
);
return false;
}
$goto_array = explode(',', $gotos['goto']);
if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) { if (!hasDomainAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $domain)) {
$_SESSION['return'] = array( $_SESSION['return'] = array(
'type' => 'danger', 'type' => 'danger',
'msg' => sprintf($lang['danger']['access_denied']) 'msg' => sprintf($lang['danger']['access_denied'])
); );
return false; return false;
} }
try { try {
$stmt = $pdo->prepare("DELETE FROM `alias` WHERE `address` = :address AND `address` NOT IN (SELECT `username` FROM `mailbox`)"); $stmt = $pdo->prepare("DELETE FROM `alias` WHERE `address` = :address AND `address` NOT IN (SELECT `username` FROM `mailbox`)");
$stmt->execute(array( $stmt->execute(array(
':address' => $address ':address' => $address
)); ));
} }
catch (PDOException $e) { catch (PDOException $e) {
$_SESSION['return'] = array( $_SESSION['return'] = array(
'type' => 'danger', 'type' => 'danger',
'msg' => 'MySQL: '.$e 'msg' => 'MySQL: '.$e
); );
return false; return false;
} }
}
$_SESSION['return'] = array( $_SESSION['return'] = array(
'type' => 'success', 'type' => 'success',
'msg' => sprintf($lang['success']['alias_removed'], htmlspecialchars($address)) 'msg' => sprintf($lang['success']['alias_removed'], htmlspecialchars(implode(', ', $address_array)))
); );
} }

View File

@ -12,10 +12,10 @@ $(document).ready(function() {
} while(Math.abs(bytes) >= 1024 && u < units.length - 1); } while(Math.abs(bytes) >= 1024 && u < units.length - 1);
return bytes.toFixed(1)+' '+units[u]; return bytes.toFixed(1)+' '+units[u];
} }
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/domain/all', url: '/api/v1/get/domain/all',
jsonp: false, jsonp: false,
error: function () { error: function () {
alert('Cannot draw domain table'); alert('Cannot draw domain table');
@ -78,7 +78,7 @@ $(document).ready(function() {
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/mailbox/all', url: '/api/v1/get/mailbox/all',
jsonp: false, jsonp: false,
error: function () { error: function () {
alert('Cannot draw mailbox table'); alert('Cannot draw mailbox table');
@ -146,7 +146,7 @@ $(document).ready(function() {
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/resource/all', url: '/api/v1/get/resource/all',
jsonp: false, jsonp: false,
error: function () { error: function () {
alert('Cannot draw resource table'); alert('Cannot draw resource table');
@ -188,7 +188,7 @@ $(document).ready(function() {
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/alias-domain/all', url: '/api/v1/get/alias-domain/all',
jsonp: false, jsonp: false,
error: function () { error: function () {
alert('Cannot draw alias domain table'); alert('Cannot draw alias domain table');
@ -228,7 +228,7 @@ $(document).ready(function() {
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/alias/all', url: '/api/v1/get/alias/all',
jsonp: false, jsonp: false,
error: function () { error: function () {
alert('Cannot draw alias table'); alert('Cannot draw alias table');
@ -239,6 +239,7 @@ $(document).ready(function() {
'<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' + '<a href="/edit.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
'<a href="/delete.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' + '<a href="/delete.php?alias=' + encodeURI(item.address) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
'</div>'; '</div>';
item.chkbox = '<input type="checkbox" class="alias_item" name="sel_aliases" value="' + item.address + '" />';
if (item.is_catch_all == 1) { if (item.is_catch_all == 1) {
item.address = '<div class="label label-default">Catch-All</div> ' + item.address; item.address = '<div class="label label-default">Catch-All</div> ' + item.address;
} }
@ -246,8 +247,9 @@ $(document).ready(function() {
item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")"; item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")";
} }
}); });
$('#alias_table').footable({ ft_aliases = FooTable.init("#alias_table", {
"columns": [ "columns": [
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
{"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}}, {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
{"name":"goto","title":lang.target_address}, {"name":"goto","title":lang.target_address},
{"name":"domain","title":lang.domain,"breakpoints":"xs sm"}, {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
@ -269,6 +271,68 @@ $(document).ready(function() {
"sorting": { "sorting": {
"enabled": true "enabled": true
} }
}, function aliases_table_hook() {
var selected_aliases = {};
$('input[name=sel_aliases]').change(function() {
selected_aliases = {};
$('input[name=sel_aliases]:checked').each(function(i) {
selected_aliases[i] = ($(this).val());
});
});
$("#select_all_aliases").click(function(e) {
e.preventDefault();
var alias_chkbxs = $("input[name=sel_aliases]");
alias_chkbxs.prop("checked", !alias_chkbxs.prop("checked")).change();
});
$("#activate_selected_alias").click(function(e) {
e.preventDefault();
if (Object.keys(selected_aliases).length !== 0) {
$.ajax({
type: "POST",
dataType: "json",
data: { "address": JSON.stringify(selected_aliases), "active": "1" },
url: '/api/v1/edit/alias/post',
jsonp: false,
complete: function (data) {
location.reload();
}
});
}
});
$("#deactivate_selected_alias").click(function(e) {
e.preventDefault();
if (Object.keys(selected_aliases).length !== 0) {
$.ajax({
type: "POST",
dataType: "json",
data: { "address": JSON.stringify(selected_aliases), "active": "0" },
url: '/api/v1/edit/alias/post',
jsonp: false,
complete: function (data) {
location.reload();
}
});
}
});
$("#delete_selected_alias").click(function(e) {
e.preventDefault();
if (Object.keys(selected_aliases).length !== 0) {
$.ajax({
type: "POST",
dataType: "json",
data: { "address": JSON.stringify(selected_aliases) },
url: '/api/v1/delete/alias/post',
jsonp: false,
complete: function (data) {
location.reload();
}
});
}
});
$("tr").on('click',function(event) {
var checkbox = $(this).find(':checkbox');
checkbox.trigger('click');
});
}); });
} }
}); });

View File

@ -2,242 +2,307 @@
require_once 'inc/prerequisites.inc.php'; require_once 'inc/prerequisites.inc.php';
error_reporting(E_ALL); error_reporting(E_ALL);
if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) { if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_username'])) {
if (isset($_GET['action']) && isset($_GET['object'])) { if (isset($_GET['action']) && isset($_GET['cat'])) {
$category = filter_input(INPUT_GET, 'cat', FILTER_SANITIZE_STRING);
$action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING); $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
$object = filter_input(INPUT_GET, 'object', FILTER_SANITIZE_STRING);
if (isset($_GET['object'])) {
$object = filter_input(INPUT_GET, 'object', FILTER_SANITIZE_STRING);
}
switch ($action) { switch ($action) {
case "domain": case "get":
switch ($object) { switch ($category) {
case "all": case "domain":
$domains = mailbox_get_domains(); switch ($object) {
if (!empty($domains)) { case "all":
foreach ($domains as $domain) { $domains = mailbox_get_domains();
$data[] = mailbox_get_domain_details($domain); if (!empty($domains)) {
} foreach ($domains as $domain) {
if (!isset($data) || empty($data)) { $data[] = mailbox_get_domain_details($domain);
echo '{}'; }
} if (!isset($data) || empty($data)) {
else { echo '{}';
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); }
} else {
} echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
else {
echo '{}';
}
break;
default:
$data = mailbox_get_domain_details($object);
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode(mailbox_get_domain_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
break;
}
break;
case "mailbox":
switch ($object) {
case "all":
$domains = mailbox_get_domains();
if (!empty($domains)) {
foreach ($domains as $domain) {
$mailboxes = mailbox_get_mailboxes($domain);
if (!empty($mailboxes)) {
foreach ($mailboxes as $mailbox) {
$data[] = mailbox_get_mailbox_details($mailbox);
} }
} }
} else {
if (!isset($data) || empty($data)) { echo '{}';
echo '{}'; }
} break;
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); default:
} $data = mailbox_get_domain_details($object);
} if (!isset($data) || empty($data)) {
else { echo '{}';
echo '{}'; }
else {
echo json_encode(mailbox_get_domain_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
break;
} }
break; break;
case "mailbox":
default: switch ($object) {
$data = mailbox_get_mailbox_details($object); case "all":
if (!isset($data) || empty($data)) { $domains = mailbox_get_domains();
echo '{}'; if (!empty($domains)) {
} foreach ($domains as $domain) {
else { $mailboxes = mailbox_get_mailboxes($domain);
echo json_encode(mailbox_get_mailbox_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); if (!empty($mailboxes)) {
} foreach ($mailboxes as $mailbox) {
break; $data[] = mailbox_get_mailbox_details($mailbox);
}
} }
break; }
case "resource": if (!isset($data) || empty($data)) {
switch ($object) { echo '{}';
case "all": }
$domains = mailbox_get_domains(); else {
if (!empty($domains)) { echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
foreach ($domains as $domain) {
$resources = mailbox_get_resources($domain);
if (!empty($resources)) {
foreach ($resources as $resource) {
$data[] = mailbox_get_resource_details($resource);
} }
} }
} else {
if (!isset($data) || empty($data)) { echo '{}';
echo '{}'; }
} break;
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); default:
} $data = mailbox_get_mailbox_details($object);
} if (!isset($data) || empty($data)) {
else { echo '{}';
echo '{}'; }
else {
echo json_encode(mailbox_get_mailbox_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
break;
} }
break; break;
case "resource":
default: switch ($object) {
$data = mailbox_get_resource_details($object); case "all":
if (!isset($data) || empty($data)) { $domains = mailbox_get_domains();
echo '{}'; if (!empty($domains)) {
} foreach ($domains as $domain) {
else { $resources = mailbox_get_resources($domain);
echo json_encode(mailbox_get_resource_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); if (!empty($resources)) {
} foreach ($resources as $resource) {
break; $data[] = mailbox_get_resource_details($resource);
}
} }
break; }
case "alias-domain": if (!isset($data) || empty($data)) {
switch ($object) { echo '{}';
case "all": }
$domains = mailbox_get_domains(); else {
if (!empty($domains)) { echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
foreach ($domains as $domain) {
$alias_domains = mailbox_get_alias_domains($domain);
if (!empty($alias_domains)) {
foreach ($alias_domains as $alias_domain) {
$data[] = mailbox_get_alias_domain_details($alias_domain);
} }
} }
} else {
if (!isset($data) || empty($data)) { echo '{}';
echo '{}'; }
} break;
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); default:
} $data = mailbox_get_resource_details($object);
} if (!isset($data) || empty($data)) {
else { echo '{}';
echo '{}'; }
} else {
break; echo json_encode(mailbox_get_resource_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
break;
default:
$data = mailbox_get_alias_domains($object);
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode(mailbox_get_alias_domains($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} }
break; break;
} case "alias-domain":
break; switch ($object) {
case "alias": case "all":
switch ($object) { $domains = mailbox_get_domains();
case "all": if (!empty($domains)) {
$domains = array_merge(mailbox_get_domains(), mailbox_get_alias_domains()); foreach ($domains as $domain) {
if (!empty($domains)) { $alias_domains = mailbox_get_alias_domains($domain);
foreach ($domains as $domain) { if (!empty($alias_domains)) {
$aliases = mailbox_get_aliases($domain); foreach ($alias_domains as $alias_domain) {
if (!empty($aliases)) { $data[] = mailbox_get_alias_domain_details($alias_domain);
foreach ($aliases as $alias) { }
$data[] = mailbox_get_alias_details($alias); }
}
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} }
} }
} else {
if (!isset($data) || empty($data)) { echo '{}';
echo '{}'; }
} break;
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
}
else {
echo '{}';
}
break;
default: default:
$data = mailbox_get_alias_details($object); $data = mailbox_get_alias_domains($object);
if (!isset($data) || empty($data)) { if (!isset($data) || empty($data)) {
echo '{}'; echo '{}';
} }
else { else {
echo json_encode(mailbox_get_alias_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); echo json_encode(mailbox_get_alias_domains($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} }
break; break;
}
break;
case "domain-admin":
switch ($object) {
case "all":
$domain_admins = get_domain_admins();
if (!empty($domain_admins)) {
foreach ($domain_admins as $domain_admin) {
$data[] = get_domain_admin_details($domain_admin);
}
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
}
else {
echo '{}';
} }
break; break;
case "alias":
switch ($object) {
case "all":
$domains = array_merge(mailbox_get_domains(), mailbox_get_alias_domains());
if (!empty($domains)) {
foreach ($domains as $domain) {
$aliases = mailbox_get_aliases($domain);
if (!empty($aliases)) {
foreach ($aliases as $alias) {
$data[] = mailbox_get_alias_details($alias);
}
}
}
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
}
else {
echo '{}';
}
break;
default: default:
$data = get_domain_admin_details($object); $data = mailbox_get_alias_details($object);
if (!isset($data) || empty($data)) { if (!isset($data) || empty($data)) {
echo '{}'; echo '{}';
}
else {
echo json_encode(mailbox_get_alias_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
break;
}
break;
case "domain-admin":
switch ($object) {
case "all":
$domain_admins = get_domain_admins();
if (!empty($domain_admins)) {
foreach ($domain_admins as $domain_admin) {
$data[] = get_domain_admin_details($domain_admin);
}
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
}
else {
echo '{}';
}
break;
default:
$data = get_domain_admin_details($object);
if (!isset($data) || empty($data)) {
echo '{}';
}
else {
echo json_encode(get_domain_admin_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
break;
}
break;
case "u2f-registration":
if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) {
$data = $u2f->getRegisterData(get_u2f_registrations($object));
list($req, $sigs) = $data;
$_SESSION['regReq'] = json_encode($req);
echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';';
} }
else { else {
echo json_encode(get_domain_admin_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); return;
}
break;
case "u2f-authentication":
if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
$reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
$_SESSION['authReq'] = $reqs;
echo 'var req = ' . $reqs . ';';
}
else {
return;
}
break;
default:
echo '{}';
break;
}
break;
case "delete":
switch ($category) {
case "alias":
if (isset($_POST['address'])) {
$address = json_decode($_POST['address'], true);
if (is_array($address)) {
if (mailbox_delete_alias(array('address' => $address)) === false) {
echo json_encode(array(
'type' => 'error',
'message' => 'Deletion of item failed'
));
exit();
}
echo json_encode(array(
'type' => 'success',
'message' => 'Task completed'
));
}
}
else {
echo json_encode(array(
'type' => 'error',
'message' => 'Cannot find address array in post data'
));
} }
break; break;
} }
break; break;
case "u2f-registration": case "edit":
if (($_SESSION["mailcow_cc_role"] == "admin" || $_SESSION["mailcow_cc_role"] == "domainadmin") && $_SESSION["mailcow_cc_username"] == $object) { switch ($category) {
$data = $u2f->getRegisterData(get_u2f_registrations($object)); case "alias":
list($req, $sigs) = $data; if (isset($_POST['address']) && isset($_POST['active'])) {
$_SESSION['regReq'] = json_encode($req); $address = json_decode($_POST['address'], true);
echo 'var req = ' . json_encode($req) . '; var sigs = ' . json_encode($sigs) . ';'; if (is_array($address)) {
if (mailbox_edit_alias(array('address' => $address, 'active' => ($_POST['active'] == "1") ? $active = 1 : null)) === false) {
echo json_encode(array(
'type' => 'error',
'message' => 'Edit item failed'
));
exit();
}
echo json_encode(array(
'type' => 'success',
'message' => 'Task completed'
));
}
}
else {
echo json_encode(array(
'type' => 'error',
'message' => 'Cannot find address array in post data'
));
}
break;
} }
else {
return;
}
break;
case "u2f-authentication":
if (isset($_SESSION['pending_mailcow_cc_username']) && $_SESSION['pending_mailcow_cc_username'] == $object) {
$reqs = json_encode($u2f->getAuthenticateData(get_u2f_registrations($object)));
$_SESSION['authReq'] = $reqs;
echo 'var req = ' . $reqs . ';';
}
else {
return;
}
break;
default:
echo '{}';
break; break;
} }
} }
} }

View File

@ -40,7 +40,7 @@ $lang['danger']['alias_goto_identical'] = "Alias and goto address must not be id
$lang['danger']['aliasd_targetd_identical'] = "Alias domain must not be equal to target domain"; $lang['danger']['aliasd_targetd_identical'] = "Alias domain must not be equal to target domain";
$lang['danger']['maxquota_empty'] = 'Max. quota per mailbox must not be 0.'; $lang['danger']['maxquota_empty'] = 'Max. quota per mailbox must not be 0.';
$lang['success']['alias_added'] = "Alias address/es has/have been added"; $lang['success']['alias_added'] = "Alias address/es has/have been added";
$lang['success']['alias_modified'] = "Changes to alias have been saved"; $lang['success']['alias_modified'] = "Changes to alias/es %s have been saved";
$lang['success']['aliasd_modified'] = "Changes to alias domain have been saved"; $lang['success']['aliasd_modified'] = "Changes to alias domain have been saved";
$lang['success']['mailbox_modified'] = "Changes to mailbox %s have been saved"; $lang['success']['mailbox_modified'] = "Changes to mailbox %s have been saved";
$lang['success']['resource_modified'] = "Changes to mailbox %s have been saved"; $lang['success']['resource_modified'] = "Changes to mailbox %s have been saved";
@ -79,7 +79,7 @@ $lang['danger']['mailbox_quota_left_exceeded'] = "Not enough space left (space l
$lang['success']['mailbox_added'] = "Mailbox %s has been added"; $lang['success']['mailbox_added'] = "Mailbox %s has been added";
$lang['success']['resource_added'] = "Resource %s has been added"; $lang['success']['resource_added'] = "Resource %s has been added";
$lang['success']['domain_removed'] = "Domain %s has been removed"; $lang['success']['domain_removed'] = "Domain %s has been removed";
$lang['success']['alias_removed'] = "Alias-Adresse %s has been removed"; $lang['success']['alias_removed'] = "Alias %s has been removed";
$lang['success']['alias_domain_removed'] = "Alias domain %s has been removed"; $lang['success']['alias_domain_removed'] = "Alias domain %s has been removed";
$lang['success']['domain_admin_removed'] = "Domain administrator %s has been removed"; $lang['success']['domain_admin_removed'] = "Domain administrator %s has been removed";
$lang['success']['mailbox_removed'] = "Mailbox %s has been removed"; $lang['success']['mailbox_removed'] = "Mailbox %s has been removed";

View File

@ -89,6 +89,14 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
</div> </div>
<div class="table-responsive"> <div class="table-responsive">
<table id="alias_table" class="table table-striped"></table> <table id="alias_table" class="table table-striped"></table>
<div class="mass-actions">
<span id="select_all_aliases" class="mass-select-all">Toggle all</span>
<br /><span>(
<a id="delete_selected_alias" href="#" class="mass-each-action">delete</a> |
<a id="activate_selected_alias" href="#" class="mass-each-action">activate</a> |
<a id="deactivate_selected_alias" href="#" class="mass-each-action">deactivate</a>)
</span>
</div>
</div> </div>
<span class="footer-add-item"><a href="/add.php?alias"><?=$lang['mailbox']['add_alias'];?></a></span> </div> <span class="footer-add-item"><a href="/add.php?alias"><?=$lang['mailbox']['add_alias'];?></a></span> </div>
</div> </div>