From 8934a3a68b4f9d8bf2ecff8e25a3324fbb54944c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Sun, 29 Jul 2018 00:38:22 +0200 Subject: [PATCH] [Web] Allow spam/ham "traps" [Web] Changes to docker functions [Web] List all containers of compose project name --- data/web/debug.php | 77 +++++-------- data/web/edit.php | 10 +- data/web/inc/ajax/container_ctrl.php | 12 +- data/web/inc/functions.docker.inc.php | 79 +++++++++---- data/web/inc/functions.inc.php | 2 +- data/web/inc/functions.mailbox.inc.php | 26 ++++- data/web/inc/vars.inc.php | 3 +- data/web/js/edit.js | 11 +- data/web/js/mailbox.js | 19 +++- data/web/json_api.php | 152 +------------------------ data/web/lang/lang.de.php | 2 + data/web/lang/lang.en.php | 2 + data/web/modals/mailbox.php | 12 +- 13 files changed, 162 insertions(+), 245 deletions(-) diff --git a/data/web/debug.php b/data/web/debug.php index 1347bbde..cd7a9756 100644 --- a/data/web/debug.php +++ b/data/web/debug.php @@ -32,7 +32,7 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI']; 'df', 'dir' => '/var/vmail'); - $vmail_df = explode(',', json_decode(docker('dovecot-mailcow', 'post', 'exec', $exec_fields), true)); + $vmail_df = explode(',', json_decode(docker('post', 'dovecot-mailcow', 'exec', $exec_fields), true)); ?>
@@ -60,52 +60,35 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
    -
  • - - setTimestamp(mktime( - $StartedAt['hour'], - $StartedAt['minute'], - $StartedAt['second'], - $StartedAt['month'], - $StartedAt['day'], - $StartedAt['year'])); - $user_tz = new DateTimeZone(getenv('TZ')); - $date->setTimezone($user_tz); - $started = $date->format('r'); - } - else { - $started = '?'; - } - ?> - (Started on ), - Restart -     -
  • + $containers = (docker('info')); + foreach ($containers as $container => $container_info) { + ?> +
  • + + setTimestamp(mktime( + $StartedAt['hour'], + $StartedAt['minute'], + $StartedAt['second'], + $StartedAt['month'], + $StartedAt['day'], + $StartedAt['year'])); + $user_tz = new DateTimeZone(getenv('TZ')); + $date->setTimezone($user_tz); + $started = $date->format('r'); + } + else { + $started = '?'; + } + ?> + (Started on ), + Restart +     +
  • diff --git a/data/web/edit.php b/data/web/edit.php index cfe3d522..d32e6ea4 100644 --- a/data/web/edit.php +++ b/data/web/edit.php @@ -31,9 +31,15 @@ if (isset($_SESSION['mailcow_cc_role'])) {
    - +
    - + +
    +
    + +
    +
    +
    diff --git a/data/web/inc/ajax/container_ctrl.php b/data/web/inc/ajax/container_ctrl.php index d12f5767..792e2fe4 100644 --- a/data/web/inc/ajax/container_ctrl.php +++ b/data/web/inc/ajax/container_ctrl.php @@ -9,8 +9,8 @@ if (preg_match('/^[a-z\-]{0,}-mailcow/', $_GET['service'])) { if ($_GET['action'] == "start") { header('Content-Type: text/html; charset=utf-8'); $retry = 0; - while (docker($_GET['service'], 'info')['State']['Running'] != 1 && $retry <= 3) { - $response = docker($_GET['service'], 'post', 'start'); + while (docker('info', $_GET['service'])['State']['Running'] != 1 && $retry <= 3) { + $response = docker('post', $_GET['service'], 'start'); $response = json_decode($response, true); $last_response = ($response['type'] == "success") ? 'OK' : 'Error: ' . $response['msg'] . ''; if ($response['type'] == "success") { @@ -24,8 +24,8 @@ if (preg_match('/^[a-z\-]{0,}-mailcow/', $_GET['service'])) { if ($_GET['action'] == "stop") { header('Content-Type: text/html; charset=utf-8'); $retry = 0; - while (docker($_GET['service'], 'info')['State']['Running'] == 1 && $retry <= 3) { - $response = docker($_GET['service'], 'post', 'stop'); + while (docker('info', $_GET['service'])['State']['Running'] == 1 && $retry <= 3) { + $response = docker('post', $_GET['service'], 'stop'); $response = json_decode($response, true); $last_response = ($response['type'] == "success") ? 'OK' : 'Error: ' . $response['msg'] . ''; if ($response['type'] == "success") { @@ -38,7 +38,7 @@ if (preg_match('/^[a-z\-]{0,}-mailcow/', $_GET['service'])) { } if ($_GET['action'] == "restart") { header('Content-Type: text/html; charset=utf-8'); - $response = docker($_GET['service'], 'post', 'restart'); + $response = docker('post', $_GET['service'], 'restart'); $response = json_decode($response, true); $last_response = ($response['type'] == "success") ? 'OK' : 'Error: ' . $response['msg'] . ''; echo (!isset($last_response)) ? 'Cannot restart container' : $last_response; @@ -46,7 +46,7 @@ if (preg_match('/^[a-z\-]{0,}-mailcow/', $_GET['service'])) { if ($_GET['action'] == "logs") { $lines = (empty($_GET['lines']) || !is_numeric($_GET['lines'])) ? 1000 : $_GET['lines']; header('Content-Type: text/plain; charset=utf-8'); - print_r(preg_split('/\n/', docker($_GET['service'], 'logs', $lines))); + print_r(preg_split('/\n/', docker('logs', $_GET['service'], $lines))); } } diff --git a/data/web/inc/functions.docker.inc.php b/data/web/inc/functions.docker.inc.php index 183bbc58..e7a0a4f4 100644 --- a/data/web/inc/functions.docker.inc.php +++ b/data/web/inc/functions.docker.inc.php @@ -1,5 +1,5 @@ 'worker_password', 'raw' => $rspamd_ui_pass), array('Content-Type: application/json')); + $docker_return = docker('post', 'rspamd-mailcow', 'exec', array('cmd' => 'worker_password', 'raw' => $rspamd_ui_pass), array('Content-Type: application/json')); if ($docker_return_array = json_decode($docker_return, true)) { if ($docker_return_array['type'] == 'success') { $_SESSION['return'] = array( diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 8565489d..52a7faa7 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -414,10 +414,10 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { ); return false; } - if ($domain == $MAILCOW_HOSTNAME) { + if ($domain == getenv('MAILCOW_HOSTNAME')) { $_SESSION['return'] = array( 'type' => 'danger', - 'msg' => sprintf($lang['danger']['domain_matches_hostname'], htmlspecialchars($domain)) + 'msg' => 'Domain cannot match hostname' ); return false; } @@ -446,7 +446,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { return false; } if (!empty($restart_sogo)) { - $restart_reponse = json_decode(docker('sogo-mailcow', 'post', 'restart'), true); + $restart_reponse = json_decode(docker('post', 'sogo-mailcow', 'restart'), true); if ($restart_reponse['type'] == "success") { $_SESSION['return'] = array( 'type' => 'success', @@ -475,6 +475,8 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { $gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['goto'])); $active = intval($_data['active']); $goto_null = intval($_data['goto_null']); + $goto_spam = intval($_data['goto_spam']); + $goto_ham = intval($_data['goto_ham']); if (empty($addresses[0])) { $_SESSION['return'] = array( 'type' => 'danger', @@ -492,6 +494,12 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { if ($goto_null == "1") { $goto = "null@localhost"; } + elseif ($goto_spam == "1") { + $goto = "spam@localhost"; + } + elseif ($goto_ham == "1") { + $goto = "ham@localhost"; + } else { foreach ($gotos as &$goto) { if (empty($goto)) { @@ -1714,6 +1722,8 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { if (!empty($is_now)) { $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int']; $goto_null = (isset($_data['goto_null'])) ? intval($_data['goto_null']) : $is_now['goto_null']; + $goto_spam = (isset($_data['goto_spam'])) ? intval($_data['goto_spam']) : $is_now['goto_spam']; + $goto_ham = (isset($_data['goto_ham'])) ? intval($_data['goto_ham']) : $is_now['goto_ham']; $goto = (!empty($_data['goto'])) ? $_data['goto'] : $is_now['goto']; } else { @@ -1726,6 +1736,12 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { if ($goto_null == "1") { $goto = "null@localhost"; } + elseif ($goto_spam == "1") { + $goto = "spam@localhost"; + } + elseif ($goto_ham == "1") { + $goto = "ham@localhost"; + } else { $gotos = array_map('trim', preg_split( "/( |,|;|\n)/", $_data['goto'])); foreach ($gotos as &$goto) { @@ -2529,7 +2545,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { 'cmd' => 'sieve_list', 'username' => $_data ); - $filters = json_decode(docker('dovecot-mailcow', 'post', 'exec', $exec_fields), true); + $filters = json_decode(docker('post', 'dovecot-mailcow', 'exec', $exec_fields), true); $filters = array_filter(explode(PHP_EOL, $filters)); foreach ($filters as $filter) { if (preg_match('/.+ ACTIVE/i', $filter)) { @@ -2538,7 +2554,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { 'script_name' => substr($filter, 0, -7), 'username' => $_data ); - $filters = json_decode(docker('dovecot-mailcow', 'post', 'exec', $exec_fields), true); + $filters = json_decode(docker('post', 'dovecot-mailcow', 'exec', $exec_fields), true); return preg_replace('/^.+\n/', '', $filters); } } diff --git a/data/web/inc/vars.inc.php b/data/web/inc/vars.inc.php index fdd22f14..5e3ca0d3 100644 --- a/data/web/inc/vars.inc.php +++ b/data/web/inc/vars.inc.php @@ -118,4 +118,5 @@ $OTP_LABEL = "mailcow UI"; $RELAY_TO = "null@hosted.mailcow.de"; // How long to wait (in s) for cURL Docker requests -$DOCKER_TIMEOUT = 60; \ No newline at end of file +$DOCKER_TIMEOUT = 60; + diff --git a/data/web/js/edit.js b/data/web/js/edit.js index 8cf0889c..6f82c545 100644 --- a/data/web/js/edit.js +++ b/data/web/js/edit.js @@ -1,15 +1,16 @@ $(document).ready(function() { - if ($("#goto_null").is(":checked")) { - $('#textarea_alias_goto').prop('disabled', true); - } - $("#goto_null").click(function( event ) { - if ($("#goto_null").is(":checked")) { + $(".goto_checkbox").click(function( event ) { + $("form[data-id='editalias'] .goto_checkbox").not(this).prop('checked', false); + if ($("form[data-id='editalias'] .goto_checkbox:checked").length > 0) { $('#textarea_alias_goto').prop('disabled', true); } else { $("#textarea_alias_goto").removeAttr('disabled'); } }); + if ($("form[data-id='editalias'] .goto_checkbox:checked").length > 0) { + $('#textarea_alias_goto').prop('disabled', true); + } $("#script_data").numberedtextarea({allowTabChar: true}); }); if ($("#multiple_bookings_select").val() == "custom") { diff --git a/data/web/js/mailbox.js b/data/web/js/mailbox.js index 73e3baa6..11b8a182 100644 --- a/data/web/js/mailbox.js +++ b/data/web/js/mailbox.js @@ -89,8 +89,17 @@ $(document).ready(function() { $('#password2').val(random_passwd); }); - $("#goto_null").click(function( event ) { - if ($("#goto_null").is(":checked")) { + $(".goto_checkbox").click(function( event ) { + $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false); + if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) { + $('#textarea_alias_goto').prop('disabled', true); + } + else { + $("#textarea_alias_goto").removeAttr('disabled'); + } + }); + $('#addAliasModal').on('show.bs.modal', function(e) { + if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) { $('#textarea_alias_goto').prop('disabled', true); } else { @@ -616,6 +625,12 @@ jQuery(function($){ if (item.goto == "null@localhost") { item.goto = '⤷ '; } + else if (item.goto == "spam@localhost") { + item.goto = 'Learn as spam'; + } + else if (item.goto == "ham@localhost") { + item.goto = 'Learn as ham'; + } if (item.in_primary_domain !== "") { item.domain = "↳ " + item.domain + " (" + item.in_primary_domain + ")"; } diff --git a/data/web/json_api.php b/data/web/json_api.php index e0263b3a..4df8433f 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -167,7 +167,9 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u if ($data) { $return = array(); $stats_array = json_decode($data, true)['actions']; - $stats_array['soft reject'] = $stats_array['soft reject'] + $stats_array['greylist']; + if (!empty($stats_array['soft reject']) || !empty($stats_array['greylist'])) { + $stats_array['soft reject'] = $stats_array['soft reject'] + $stats_array['greylist']; + } unset($stats_array['greylist']); foreach ($stats_array as $action => $count) { $return[] = array($action, $count); @@ -178,154 +180,6 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u echo '{}'; } break; - case "stat": - $data = file_get_contents('http://rspamd-mailcow:11334/stat'); - process_get_return($data); - break; - case "graph": - switch ($extra) { - case "hourly": - $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=hourly'); - if (!empty($data)) { - $data_array = json_decode($data, true); - $rejected['label'] = "reject"; - foreach ($data_array[0] as $dataset) { - $rejected['data'][] = $dataset; - } - $temp_reject['label'] = "temp_reject"; - foreach ($data_array[1] as $dataset) { - $temp_reject['data'][] = $dataset; - } - $add_header['label'] = "add_header"; - foreach ($data_array[2] as $dataset) { - $add_header['data'][] = $dataset; - } - $prob_spam['label'] = "prob_spam"; - foreach ($data_array[3] as $dataset) { - $prob_spam['data'][] = $dataset; - } - $greylist['label'] = "greylist"; - foreach ($data_array[4] as $dataset) { - $greylist['data'][] = $dataset; - } - $clean['label'] = "clean"; - $clean['pointStyle'] = "cross"; - foreach ($data_array[5] as $dataset) { - $clean['data'][] = $dataset; - } - echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); - } - elseif (!isset($data) || empty($data)) { - echo '{}'; - } - break; - case "daily": - $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=daily'); - if (!empty($data)) { - $data_array = json_decode($data, true); - $rejected['label'] = "reject"; - foreach ($data_array[0] as $dataset) { - $rejected['data'][] = $dataset; - } - $temp_reject['label'] = "temp_reject"; - foreach ($data_array[1] as $dataset) { - $temp_reject['data'][] = $dataset; - } - $add_header['label'] = "add_header"; - foreach ($data_array[2] as $dataset) { - $add_header['data'][] = $dataset; - } - $prob_spam['label'] = "prob_spam"; - foreach ($data_array[3] as $dataset) { - $prob_spam['data'][] = $dataset; - } - $greylist['label'] = "greylist"; - foreach ($data_array[4] as $dataset) { - $greylist['data'][] = $dataset; - } - $clean['label'] = "clean"; - $clean['pointStyle'] = "cross"; - foreach ($data_array[5] as $dataset) { - $clean['data'][] = $dataset; - } - echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); - } - elseif (!isset($data) || empty($data)) { - echo '{}'; - } - break; - case "weekly": - $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=weekly'); - if (!empty($data)) { - $data_array = json_decode($data, true); - $rejected['label'] = "reject"; - foreach ($data_array[0] as $dataset) { - $rejected['data'][] = $dataset; - } - $temp_reject['label'] = "temp_reject"; - foreach ($data_array[1] as $dataset) { - $temp_reject['data'][] = $dataset; - } - $add_header['label'] = "add_header"; - foreach ($data_array[2] as $dataset) { - $add_header['data'][] = $dataset; - } - $prob_spam['label'] = "prob_spam"; - foreach ($data_array[3] as $dataset) { - $prob_spam['data'][] = $dataset; - } - $greylist['label'] = "greylist"; - foreach ($data_array[4] as $dataset) { - $greylist['data'][] = $dataset; - } - $clean['label'] = "clean"; - $clean['pointStyle'] = "cross"; - foreach ($data_array[5] as $dataset) { - $clean['data'][] = $dataset; - } - echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); - } - elseif (!isset($data) || empty($data)) { - echo '{}'; - } - break; - case "monthly": - $data = file_get_contents('http://rspamd-mailcow:11334/graph?type=monthly'); - if (!empty($data)) { - $data_array = json_decode($data, true); - $rejected['label'] = "reject"; - foreach ($data_array[0] as $dataset) { - $rejected['data'][] = $dataset; - } - $temp_reject['label'] = "temp_reject"; - foreach ($data_array[1] as $dataset) { - $temp_reject['data'][] = $dataset; - } - $add_header['label'] = "add_header"; - foreach ($data_array[2] as $dataset) { - $add_header['data'][] = $dataset; - } - $prob_spam['label'] = "prob_spam"; - foreach ($data_array[3] as $dataset) { - $prob_spam['data'][] = $dataset; - } - $greylist['label'] = "greylist"; - foreach ($data_array[4] as $dataset) { - $greylist['data'][] = $dataset; - } - $clean['label'] = "clean"; - $clean['pointStyle'] = "cross"; - foreach ($data_array[5] as $dataset) { - $clean['data'][] = $dataset; - } - echo json_encode(array($rejected, $temp_reject, $add_header, $prob_spam, $greylist, $clean), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); - } - elseif (!isset($data) || empty($data)) { - echo '{}'; - } - break; - } - break; } break; case "domain": diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php index d93f77ba..f015bd26 100644 --- a/data/web/lang/lang.de.php +++ b/data/web/lang/lang.de.php @@ -339,6 +339,8 @@ $lang['add']['password'] = 'Passwort'; $lang['add']['password_repeat'] = 'Passwort (Wiederholung)'; $lang['add']['restart_sogo_hint'] = 'Der SOGo Container muss nach dem Hinzufügen einer neuen Domain neugestartet werden!'; $lang['add']['goto_null'] = 'Nachrichten sofort verwerfen'; +$lang['add']['goto_ham'] = 'Nachrichten als Ham lernen'; +$lang['add']['goto_spam'] = 'Nachrichten als Spam lernen'; $lang['add']['validation_success'] = 'Erfolgreich validiert'; $lang['add']['activate_filter_warn'] = 'Alle anderen Filter diesen Typs werden deaktiviert, falls dieses Script aktiv markiert wird.'; $lang['add']['validate'] = 'Validieren'; diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php index 0e18bbfc..dd0da489 100644 --- a/data/web/lang/lang.en.php +++ b/data/web/lang/lang.en.php @@ -344,6 +344,8 @@ $lang['add']['password'] = 'Password'; $lang['add']['password_repeat'] = 'Confirmation password (repeat)'; $lang['add']['restart_sogo_hint'] = 'You will need to restart the SOGo service container after adding a new domain!'; $lang['add']['goto_null'] = 'Silently discard mail'; +$lang['add']['goto_ham'] = 'Learn as ham'; +$lang['add']['goto_spam'] = 'Learn as spam'; $lang['add']['validation_success'] = 'Validated successfully'; $lang['add']['activate_filter_warn'] = 'All other filters will be deactivated, when active is checked.'; $lang['add']['validate'] = 'Validate'; diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php index 12b20bc3..149f579c 100644 --- a/data/web/modals/mailbox.php +++ b/data/web/modals/mailbox.php @@ -245,10 +245,16 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
    -
    - -

    +
    + +
    +
    + +
    +
    + +