diff --git a/data/web/admin.php b/data/web/admin.php index b2962079..39900fac 100644 --- a/data/web/admin.php +++ b/data/web/admin.php @@ -279,45 +279,14 @@ $tfa_data = get_tfa();

-
-
- - - - - - - - - - - $attr) { - ?> - - - - - - - - - - - -
-
- -
-
+ +
+ + +
+
+
+
diff --git a/data/web/css/mailcow.css b/data/web/css/mailcow.css index 20dfb69a..8ab3d1e9 100644 --- a/data/web/css/mailcow.css +++ b/data/web/css/mailcow.css @@ -55,4 +55,12 @@ body.modal-open { overflow: inherit; padding-right: inherit !important; } - +.mailcow-alert-box { + position: fixed; + bottom: 8px; + right: 25px; + min-width: 300px; + max-width: 350px; + z-index: 2000; + display: none; +} \ No newline at end of file diff --git a/data/web/inc/footer.inc.php b/data/web/inc/footer.inc.php index 97b59c0e..6fc6d321 100644 --- a/data/web/inc/footer.inc.php +++ b/data/web/inc/footer.inc.php @@ -19,6 +19,9 @@ if (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == "admi
+ -
@@ -53,6 +53,16 @@ function setLang(sel) { } $(document).ready(function() { + function mailcow_alert_box(type, message) { + $('.mailcow-alert-box').show(); + $('.mailcow-alert-box').addClass("alert-" + type); + $('#mailcow-alert-text').text(message); + } + // PHP error handler + + mailcow_alert_box("", ""); + + // Confirm TFA modal $('#ConfirmTFAModal').modal({ @@ -220,21 +230,10 @@ $(document).ready(function() { }); }); - -
-
-
class="alert alert-" role="alert"> - × - -
-
+ - diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php index a2b2fba8..26888b79 100644 --- a/data/web/inc/functions.inc.php +++ b/data/web/inc/functions.inc.php @@ -5103,11 +5103,10 @@ function get_forwarding_hosts() { global $redis; $data = array(); try { - $wl_hosts = $redis->hGetAll('WHITELISTED_FWD_HOST'); - if (!empty($wl_hosts)) { - foreach ($wl_hosts as $host => $source) { - $data[$host]['keep_spam'] = ($redis->hGet('KEEP_SPAM', $host)) ? "yes" : "no"; - $data[$host]['source'] = $source; + $fwd_hosts = $redis->hGetAll('WHITELISTED_FWD_HOST'); + if (!empty($fwd_hosts)) { + foreach ($fwd_hosts as $fwd_host => $source) { + $data[] = $fwd_host; } } } @@ -5120,6 +5119,31 @@ function get_forwarding_hosts() { } return $data; } +function get_forwarding_host_details($host) { + global $redis; + $data = array(); + if (!isset($host) || empty($host)) { + return false; + } + if (filter_var($host, FILTER_VALIDATE_IP)) { + return; + } + try { + if ($source = $redis->hGet('WHITELISTED_FWD_HOST', $host)) { + $data['host'] = $host; + $data['source'] = $source; + $data['keep_spam'] = ($redis->hGet('KEEP_SPAM', $host)) ? "yes" : "no"; + } + } + catch (RedisException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Redis: '.$e + ); + return false; + } + return $data; +} function add_forwarding_host($postarray) { require_once 'spf.inc.php'; global $redis; @@ -5132,7 +5156,7 @@ function add_forwarding_host($postarray) { return false; } $source = $postarray['hostname']; - $host = trim($postarray['hostname']); + $host = trim($postarray['hostname']); $filter_spam = $postarray['filter_spam']; if (isset($postarray['filter_spam']) && $postarray['filter_spam'] == 1) { $filter_spam = 1; @@ -5140,13 +5164,16 @@ function add_forwarding_host($postarray) { else { $filter_spam = 0; } - if (filter_var($host, FILTER_VALIDATE_IP)) { + if (preg_match('/^[0-9a-fA-F:\/]+$/', $host)) { // IPv6 address $hosts = array($host); - } + } + elseif (preg_match('/^[0-9\.\/]+$/', $host)) { // IPv4 address + $hosts = array($host); + } else { $hosts = get_outgoing_hosts_best_guess($host); } - if (!$hosts) { + if (empty($hosts)) { $_SESSION['return'] = array( 'type' => 'danger', 'msg' => 'Invalid host specified: '. htmlspecialchars($host) @@ -5195,8 +5222,8 @@ function delete_forwarding_host($postarray) { } foreach ($hosts as $host) { try { - return $redis->hDel('WHITELISTED_FWD_HOST', $host); - return $redis->hDel('KEEP_SPAM', $host); + $redis->hDel('WHITELISTED_FWD_HOST', $host); + $redis->hDel('KEEP_SPAM', $host); } catch (RedisException $e) { $_SESSION['return'] = array( @@ -5208,7 +5235,7 @@ function delete_forwarding_host($postarray) { } $_SESSION['return'] = array( 'type' => 'success', - 'msg' => sprintf($lang['success']['forwarding_host_removed'], htmlspecialchars($host)) + 'msg' => sprintf($lang['success']['forwarding_host_removed'], htmlspecialchars(implode(', ', $hosts))) ); } function get_logs($container, $lines = 100) { diff --git a/data/web/js/admin.js b/data/web/js/admin.js index 42cc6e34..be0fbd11 100644 --- a/data/web/js/admin.js +++ b/data/web/js/admin.js @@ -1,4 +1,37 @@ $(document).ready(function() { + + // Collect values of input fields with name multi_select to js array multi_data[data-id-of-checkbox] + var multi_data = []; + $(document).on('change', 'input[name=multi_select]:checkbox', function() { + if ($(this).is(':checked') && $(this).attr('data-form-id')) { + var id = $(this).data('form-id'); + if (typeof multi_data[id] == "undefined") { + multi_data[id] = []; + } + multi_data[id].push($(this).val()); + } + else { + var id = $(this).data('form-id'); + multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1); + } + }); + // Select by click on tr + $(document).on('click', 'tr', function(e) { + if (e.target.type == "checkbox") { + e.stopPropagation(); + } else { + var checkbox = $(this).find(':checkbox'); + checkbox.trigger('click'); + } + }); + // Select or deselect all checkboxes with same data-form-id + $(document).on('click', '#toggle_multi_select_all', function(e) { + e.preventDefault(); + var closests_checkboxes = $("input[data-form-id=" + $(this).attr("data-form-id") + "]"); + closests_checkboxes.prop("checked", !closests_checkboxes.prop("checked")).change(); + }); + + // Draw domain admin table $.ajax({ dataType: 'json', url: '/api/v1/get/domain-admin/all', @@ -39,6 +72,84 @@ $(document).ready(function() { }); } }); + + // Draw fwd hosts table + $.ajax({ + dataType: 'json', + url: '/api/v1/get/fwdhost/all', + jsonp: false, + error: function () { + console.log('Cannot draw forwarding hosts table'); + }, + success: function (data) { + $.each(data, function (i, item) { + item.action = '
' + + ' ' + lang.remove + '' + + '
'; + if (item.keep_spam == "yes") { + item.keep_spam = lang.no; + } + else { + item.keep_spam = lang.yes; + } + item.chkbox = ''; + }); + $('#forwardinghoststable').footable({ + "columns": [ + {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"}, + {"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}}, + {"name":"source","title":lang.source,"breakpoints":"xs sm"}, + {"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"}}, + {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"} + ], + "rows": data, + "empty": lang.empty, + "paging": { + "enabled": true, + "limit": 5, + "size": pagination_size + }, + "sorting": { + "enabled": true + } + }); + } + }); + + $(document).on('click', '#delete_fwdhosts', function(e) { + e.preventDefault(); + var id = $(this).closest("form").attr('data-id'); + if (typeof multi_data[id] == "undefined") return; + data_array = multi_data[id]; + if (Object.keys(data_array).length !== 0) { + $(document).on('show.bs.modal','#ConfirmDeleteModal', function () { + $("#ItemsToDelete").empty(); + for (var i in data_array) { + $("#ItemsToDelete").append("
  • " + data_array[i] + "
  • "); + } + }) + $('#ConfirmDeleteModal').modal({ + backdrop: 'static', + keyboard: false + }) + .one('click', '#IsConfirmed', function(e) { + $.ajax({ + type: "POST", + dataType: "json", + data: { "forwardinghost": JSON.stringify(data_array) }, + url: '/api/v1/delete/fwdhost', + jsonp: false, + complete: function (data) { + location.reload(); + } + }); + }) + .one('click', '#isCanceled', function(e) { + $('#ConfirmDeleteModal').modal('hide'); + });; + } + }); + $("#refresh_dovecot_log").on('click', function(e) { function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); diff --git a/data/web/js/mailbox.js b/data/web/js/mailbox.js index 6acb22eb..1e168f59 100644 --- a/data/web/js/mailbox.js +++ b/data/web/js/mailbox.js @@ -301,7 +301,7 @@ $(document).ready(function() { $(document).on('click', '#activate_selected_alias', function(e) { e.preventDefault(); - if (selected_aliases.length !== 0) { + if (Object.keys(selected_aliases).length !== 0) { $.ajax({ type: "POST", dataType: "json", diff --git a/data/web/json_api.php b/data/web/json_api.php index 7ac78b53..c48a1293 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -33,7 +33,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u $domains = mailbox_get_domains(); if (!empty($domains)) { foreach ($domains as $domain) { - $data[] = mailbox_get_domain_details($domain); + if ($details = mailbox_get_domain_details($domain)) { + $data[] = $details; + } + else { + continue; + } } if (!isset($data) || empty($data)) { echo '{}'; @@ -53,7 +58,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } else { - echo json_encode(mailbox_get_domain_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } break; } @@ -102,7 +107,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u $mailboxes = mailbox_get_mailboxes($domain); if (!empty($mailboxes)) { foreach ($mailboxes as $mailbox) { - $data[] = mailbox_get_mailbox_details($mailbox); + if ($details = mailbox_get_mailbox_details($mailbox)) { + $data[] = $details; + } + else { + continue; + } } } } @@ -124,7 +134,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } else { - echo json_encode(mailbox_get_mailbox_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } break; @@ -139,7 +149,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u $resources = mailbox_get_resources($domain); if (!empty($resources)) { foreach ($resources as $resource) { - $data[] = mailbox_get_resource_details($resource); + if ($details = mailbox_get_resource_details($resource)) { + $data[] = $details; + } + else { + continue; + } } } } @@ -161,7 +176,40 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } else { - echo json_encode(mailbox_get_resource_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + } + break; + + } + break; + case "fwdhost": + switch ($object) { + case "all": + $fwdhosts = get_forwarding_hosts(); + if (!empty($fwdhosts)) { + foreach ($fwdhosts as $fwdhost) { + if ($details = get_forwarding_host_details($fwdhost)) { + $data[] = $details; + } + else { + continue; + } + } + } + if (!isset($data) || empty($data)) { + echo '{}'; + } + else { + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + } + break; + default: + $data = get_forwarding_host_details($object); + if (!isset($data) || empty($data)) { + echo '{}'; + } + else { + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } break; @@ -176,7 +224,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u $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); + if ($details = mailbox_get_alias_domain_details($alias_domain)) { + $data[] = $details; + } + else { + continue; + } } } } @@ -198,7 +251,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } else { - echo json_encode(mailbox_get_alias_domains($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } break; } @@ -212,7 +265,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u $aliases = mailbox_get_aliases($domain); if (!empty($aliases)) { foreach ($aliases as $alias) { - $data[] = mailbox_get_alias_details($alias); + if ($details = mailbox_get_alias_details($alias)) { + $data[] = $details; + } + else { + continue; + } } } } @@ -234,7 +292,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } else { - echo json_encode(mailbox_get_alias_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } break; } @@ -245,7 +303,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u $domain_admins = get_domain_admins(); if (!empty($domain_admins)) { foreach ($domain_admins as $domain_admin) { - $data[] = get_domain_admin_details($domain_admin); + if ($details = get_domain_admin_details($domain_admin)) { + $data[] = $details; + } + else { + continue; + } } if (!isset($data) || empty($data)) { echo '{}'; @@ -265,7 +328,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } else { - echo json_encode(get_domain_admin_details($object), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } break; } @@ -307,7 +370,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u if (mailbox_delete_alias(array('address' => $address)) === false) { echo json_encode(array( 'type' => 'error', - 'message' => 'Deletion of item failed' + 'message' => 'Deletion of item/s failed' )); exit(); } @@ -324,6 +387,30 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u )); } break; + case "fwdhost": + if (isset($_POST['forwardinghost'])) { + $forwardinghost = json_decode($_POST['forwardinghost'], true); + if (is_array($forwardinghost)) { + if (delete_forwarding_host(array('forwardinghost' => $forwardinghost)) === false) { + echo json_encode(array( + 'type' => 'error', + 'message' => 'Deletion of item/s failed' + )); + exit(); + } + echo json_encode(array( + 'type' => 'success', + 'message' => 'Task completed' + )); + } + } + else { + echo json_encode(array( + 'type' => 'error', + 'message' => 'Cannot find forwardinghost array in post data' + )); + } + break; } break; case "edit": diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php index a6a856e6..bc254ccb 100644 --- a/data/web/lang/lang.de.php +++ b/data/web/lang/lang.de.php @@ -135,6 +135,7 @@ $lang['user']['day'] = 'Tag'; $lang['user']['week'] = 'Woche'; $lang['user']['weeks'] = 'Wochen'; $lang['user']['spamfilter'] = 'Spamfilter'; +$lang['admin']['spamfilter'] = 'Spamfilter'; $lang['user']['spamfilter_wl'] = 'Whitelist'; $lang['user']['spamfilter_wl_desc'] = 'Für E-Mail-Adressen, die vom Spamfilter nicht erfasst werden sollen. Die Verwendung von Wildcards ist gestattet.'; $lang['user']['spamfilter_bl'] = 'Blacklist'; @@ -480,8 +481,8 @@ $lang['admin']['message'] = 'Nachricht'; $lang['admin']['forwarding_hosts'] = 'Weiterleitungs-Hosts'; $lang['admin']['forwarding_hosts_hint'] = 'Eingehende Nachrichten werden von den hier gelisteten Hosts bedingungslos akzeptiert. Diese Hosts werden dann nicht mit DNSBLs abgeglichen oder Greylisting unterworfen. Von ihnen empfangener Spam wird nie abgelehnt, optional kann er aber in den Spam-Ordner einsortiert werden. Die übliche Verwendung für diese Funktion ist, um Mailserver anzugeben, auf denen eine Weiterleitung zu Ihrem Mailcow-Server eingerichtet wurde.'; $lang['admin']['forwarding_hosts_add_hint'] = 'Sie können entweder IPv4/IPv6-Adressen, Netzwerke in CIDR-Notation, Hostnamen (die zu IP-Adressen aufgelöst werden), oder Domainnamen (die zu IP-Adressen aufgelöst werden, indem ihr SPF-Record abgefragt wird oder, in dessen Abwesenheit, ihre MX-Records) angeben.'; -$lang['edit']['host'] = 'Host'; -$lang['edit']['source'] = 'Quelle'; +$lang['admin']['host'] = 'Host'; +$lang['admin']['source'] = 'Quelle'; $lang['admin']['add_forwarding_host'] = 'Weiterleitungs-Host hinzufügen'; $lang['delete']['remove_forwardinghost_warning'] = 'Warnung: Sie entfernen den Weiterleitungs-Host %s!'; $lang['success']['forwarding_host_removed'] = "Weiterleitungs-Host %s wurde entfernt"; diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php index 4b361afe..af500355 100644 --- a/data/web/lang/lang.en.php +++ b/data/web/lang/lang.en.php @@ -137,6 +137,7 @@ $lang['user']['day'] = 'Day'; $lang['user']['week'] = 'Week'; $lang['user']['weeks'] = 'Weeks'; $lang['user']['spamfilter'] = 'Spam filter'; +$lang['admin']['spamfilter'] = 'Spam filter'; $lang['user']['spamfilter_wl'] = 'Whitelist'; $lang['user']['spamfilter_wl_desc'] = 'Whitelisted email addresses to never classify as spam. Wildcards maybe used.'; $lang['user']['spamfilter_bl'] = 'Blacklist'; @@ -492,8 +493,8 @@ $lang['admin']['logs'] = 'Logs'; $lang['admin']['forwarding_hosts'] = 'Forwarding Hosts'; $lang['admin']['forwarding_hosts_hint'] = 'Incoming messages are unconditionally accepted from any hosts listed here. These hosts are then not checked against DNSBLs or subjected to greylisting. Spam received from them is never rejected, but optionally it can be filed into the Junk folder. The most common use for this is to specify mail servers on which you have set up a rule that forwards incoming emails to your Mailcow server.'; $lang['admin']['forwarding_hosts_add_hint'] = 'You can either specify IPv4/IPv6 addresses, networks in CIDR notation, host names (which will be resolved to IP addresses), or domain names (which will be resolved to IP addresses by querying SPF records or, in their absence, MX records).'; -$lang['edit']['host'] = 'Host'; -$lang['edit']['source'] = 'Source'; +$lang['admin']['host'] = 'Host'; +$lang['admin']['source'] = 'Source'; $lang['admin']['add_forwarding_host'] = 'Add Forwarding Host'; $lang['delete']['remove_forwardinghost_warning'] = 'Warning: You are about to remove the forwarding host %s!'; $lang['success']['forwarding_host_removed'] = "Forwarding host %s has been removed";