From 6f656c39b4344f5ecda914de446221a4f9d706fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 27 Jul 2018 22:19:59 +0200 Subject: [PATCH] [Web] Do not use hard-coded params in imapsync jobs [Web] Allow custom parameters in imapsync --- data/web/css/mailbox.css | 4 +++ data/web/edit.php | 40 +++++++++++++++++++---- data/web/inc/functions.mailbox.inc.php | 44 ++++++++++++++++++++++---- data/web/inc/header.inc.php | 4 +-- data/web/inc/init_db.inc.php | 6 +++- data/web/js/api.js | 6 ++-- data/web/js/mailbox.js | 24 +++++++------- data/web/lang/lang.de.php | 5 +++ data/web/lang/lang.en.php | 8 ++++- data/web/modals/mailbox.php | 39 +++++++++++++++++++---- 10 files changed, 143 insertions(+), 37 deletions(-) diff --git a/data/web/css/mailbox.css b/data/web/css/mailbox.css index 02ba90a03..8a9c46d57 100644 --- a/data/web/css/mailbox.css +++ b/data/web/css/mailbox.css @@ -41,3 +41,7 @@ table.footable>tbody>tr.footable-empty>td { .table-lines { vertical-align: inherit; } +#logText { + font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace; + font-size:smaller; +} \ No newline at end of file diff --git a/data/web/edit.php b/data/web/edit.php index 9cd1994cc..cfe3d5226 100644 --- a/data/web/edit.php +++ b/data/web/edit.php @@ -733,6 +733,7 @@ if (isset($_SESSION['mailcow_cc_role'])) { +
@@ -771,7 +772,7 @@ if (isset($_SESSION['mailcow_cc_role'])) {
- 10-3600 + 1-3600
@@ -794,44 +795,71 @@ if (isset($_SESSION['mailcow_cc_role'])) { 0-125000000
+
+ +
+ + 1-32000 +
+
+
+ +
+ + 1-32000 +
+
+
+ +
+ +
+
- +
- +
- +
- +
- + +
+
+
+
+
+
+
diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 1397a11d4..8565489d3 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -211,10 +211,13 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { ); return false; } - $active = intval($_data['active']); + $active = intval($_data['active']); + $subscribeall = intval($_data['subscribeall']); $delete2duplicates = intval($_data['delete2duplicates']); $delete1 = intval($_data['delete1']); $delete2 = intval($_data['delete2']); + $timeout1 = intval($_data['timeout1']); + $timeout2 = intval($_data['timeout2']); $skipcrossduplicates = intval($_data['skipcrossduplicates']); $automap = intval($_data['automap']); $port1 = $_data['port1']; @@ -226,13 +229,20 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { $subfolder2 = $_data['subfolder2']; $user1 = $_data['user1']; $mins_interval = $_data['mins_interval']; - $enc1 = $_data['enc1']; + $enc1 = $_data['enc1']; + $custom_params = (empty(trim($_data['custom_params']))) ? '' : trim($_data['custom_params']); if (empty($subfolder2)) { $subfolder2 = ""; } - if (!isset($maxage) || !filter_var($maxage, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32767)))) { + if (!isset($maxage) || !filter_var($maxage, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32000)))) { $maxage = "0"; } + if (!isset($timeout1) || !filter_var($timeout1, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32000)))) { + $timeout1 = "600"; + } + if (!isset($timeout2) || !filter_var($timeout2, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32000)))) { + $timeout2 = "600"; + } if (!isset($maxbytespersecond) || !filter_var($maxbytespersecond, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 125000000)))) { $maxbytespersecond = "0"; } @@ -292,17 +302,21 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { return false; } try { - $stmt = $pdo->prepare("INSERT INTO `imapsync` (`user2`, `exclude`, `delete1`, `delete2`, `automap`, `skipcrossduplicates`, `maxbytespersecond`, `maxage`, `subfolder2`, `host1`, `authmech1`, `user1`, `password1`, `mins_interval`, `port1`, `enc1`, `delete2duplicates`, `active`) - VALUES (:user2, :exclude, :delete1, :delete2, :automap, :skipcrossduplicates, :maxbytespersecond, :maxage, :subfolder2, :host1, :authmech1, :user1, :password1, :mins_interval, :port1, :enc1, :delete2duplicates, :active)"); + $stmt = $pdo->prepare("INSERT INTO `imapsync` (`user2`, `exclude`, `delete1`, `delete2`, `timeout1`, `timeout2`, `automap`, `skipcrossduplicates`, `maxbytespersecond`, `subscribeall`, `maxage`, `subfolder2`, `host1`, `authmech1`, `user1`, `password1`, `mins_interval`, `port1`, `enc1`, `delete2duplicates`, `custom_params`, `active`) + VALUES (:user2, :exclude, :delete1, :delete2, :timeout1, :timeout2, :automap, :skipcrossduplicates, :maxbytespersecond, :subscribeall, :maxage, :subfolder2, :host1, :authmech1, :user1, :password1, :mins_interval, :port1, :enc1, :delete2duplicates, :custom_params, :active)"); $stmt->execute(array( ':user2' => $username, + ':custom_params' => $custom_params, ':exclude' => $exclude, ':maxage' => $maxage, ':delete1' => $delete1, ':delete2' => $delete2, + ':timeout1' => $timeout1, + ':timeout2' => $timeout2, ':automap' => $automap, ':skipcrossduplicates' => $skipcrossduplicates, ':maxbytespersecond' => $maxbytespersecond, + ':subscribeall' => $subscribeall, ':subfolder2' => $subfolder2, ':host1' => $host1, ':authmech1' => 'PLAIN', @@ -1458,6 +1472,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active_int']; $last_run = (isset($_data['last_run'])) ? NULL : $is_now['last_run']; $delete2duplicates = (isset($_data['delete2duplicates'])) ? intval($_data['delete2duplicates']) : $is_now['delete2duplicates']; + $subscribeall = (isset($_data['subscribeall'])) ? intval($_data['subscribeall']) : $is_now['subscribeall']; $delete1 = (isset($_data['delete1'])) ? intval($_data['delete1']) : $is_now['delete1']; $delete2 = (isset($_data['delete2'])) ? intval($_data['delete2']) : $is_now['delete2']; $automap = (isset($_data['automap'])) ? intval($_data['automap']) : $is_now['automap']; @@ -1469,8 +1484,11 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { $enc1 = (!empty($_data['enc1'])) ? $_data['enc1'] : $is_now['enc1']; $mins_interval = (!empty($_data['mins_interval'])) ? $_data['mins_interval'] : $is_now['mins_interval']; $exclude = (isset($_data['exclude'])) ? $_data['exclude'] : $is_now['exclude']; + $custom_params = (isset($_data['custom_params'])) ? $_data['custom_params'] : $is_now['custom_params']; $maxage = (isset($_data['maxage']) && $_data['maxage'] != "") ? intval($_data['maxage']) : $is_now['maxage']; $maxbytespersecond = (isset($_data['maxbytespersecond']) && $_data['maxbytespersecond'] != "") ? intval($_data['maxbytespersecond']) : $is_now['maxbytespersecond']; + $timeout1 = (isset($_data['timeout1']) && $_data['timeout1'] != "") ? intval($_data['timeout1']) : $is_now['timeout1']; + $timeout2 = (isset($_data['timeout2']) && $_data['timeout2'] != "") ? intval($_data['timeout2']) : $is_now['timeout2']; } else { $_SESSION['return'] = array( @@ -1482,9 +1500,15 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { if (empty($subfolder2)) { $subfolder2 = ""; } - if (!isset($maxage) || !filter_var($maxage, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32767)))) { + if (!isset($maxage) || !filter_var($maxage, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32000)))) { $maxage = "0"; } + if (!isset($timeout1) || !filter_var($timeout1, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32000)))) { + $timeout1 = "600"; + } + if (!isset($timeout2) || !filter_var($timeout2, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32000)))) { + $timeout2 = "600"; + } if (!isset($maxbytespersecond) || !filter_var($maxbytespersecond, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 125000000)))) { $maxbytespersecond = "0"; } @@ -1540,6 +1564,10 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { `port1` = :port1, `enc1` = :enc1, `delete2duplicates` = :delete2duplicates, + `custom_params` = :custom_params, + `timeout1` = :timeout1, + `timeout2` = :timeout2, + `subscribeall` = :subscribeall, `active` = :active WHERE `id` = :id"); $stmt->execute(array( @@ -1560,6 +1588,10 @@ function mailbox($_action, $_type, $_data = null, $attr = null) { ':port1' => $port1, ':enc1' => $enc1, ':delete2duplicates' => $delete2duplicates, + ':custom_params' => $custom_params, + ':timeout1' => $timeout1, + ':timeout2' => $timeout2, + ':subscribeall' => $subscribeall, ':active' => $active, )); } diff --git a/data/web/inc/header.inc.php b/data/web/inc/header.inc.php index 9108b2c38..396f0a979 100644 --- a/data/web/inc/header.inc.php +++ b/data/web/inc/header.inc.php @@ -130,11 +130,11 @@ } if (!isset($_SESSION['dual-login']) && isset($_SESSION['mailcow_cc_username'])): ?> -
  • +
  • -
  • ()
  • +
  • ()
  • diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php index c307d8aa9..9be8b57ec 100644 --- a/data/web/inc/init_db.inc.php +++ b/data/web/inc/init_db.inc.php @@ -3,7 +3,7 @@ function init_db_schema() { try { global $pdo; - $db_version = "04072018_2119"; + $db_version = "25072018_1129"; $stmt = $pdo->query("SHOW TABLES LIKE 'versions'"); $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); @@ -417,6 +417,10 @@ function init_db_schema() { "delete2" => "TINYINT(1) NOT NULL DEFAULT '0'", "automap" => "TINYINT(1) NOT NULL DEFAULT '0'", "skipcrossduplicates" => "TINYINT(1) NOT NULL DEFAULT '0'", + "custom_params" => "VARCHAR(512) NOT NULL DEFAULT ''", + "timeout1" => "SMALLINT NOT NULL DEFAULT '600'", + "timeout2" => "SMALLINT NOT NULL DEFAULT '600'", + "subscribeall" => "TINYINT(1) NOT NULL DEFAULT '1'", "is_running" => "TINYINT(1) NOT NULL DEFAULT '0'", "returned_text" => "MEDIUMTEXT", "last_run" => "TIMESTAMP NULL DEFAULT NULL", diff --git a/data/web/js/api.js b/data/web/js/api.js index 549419491..3f9bc4b7b 100644 --- a/data/web/js/api.js +++ b/data/web/js/api.js @@ -80,11 +80,11 @@ $(document).ready(function() { // If clicked element #edit_selected is in a form with the same data-id as the button, // we merge all input fields by {"name":"value"} into api-attr if ($(this).closest("form").data('id') == id) { - var req_empty = false; + var invalid = false; $(this).closest("form").find('select, textarea, input').each(function() { if ($(this).prop('required')) { if (!$(this).val() && $(this).prop('disabled') === false) { - req_empty = true; + invalid = true; $(this).addClass('inputMissingAttr'); } else { $(this).removeClass('inputMissingAttr'); @@ -106,7 +106,7 @@ $(document).ready(function() { } } }); - if (!req_empty) { + if (!invalid) { var attr_to_merge = $(this).closest("form").serializeObject(); var api_attr = $.extend(api_attr, attr_to_merge) } else { diff --git a/data/web/js/mailbox.js b/data/web/js/mailbox.js index 1432e3b0d..73e3baa67 100644 --- a/data/web/js/mailbox.js +++ b/data/web/js/mailbox.js @@ -233,7 +233,7 @@ jQuery(function($){ ft_paging.goto(parseInt(current_page[name])) } } - function table_mailbox_paging(ft, name) { + function paging_mailbox_after(ft, name) { var ft_paging = ft.use(FooTable.Paging) current_page[name] = ft_paging.current; localStorage.setItem('current_page', JSON.stringify(current_page)); @@ -306,7 +306,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'domain_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'domain_table'); + paging_mailbox_after(ft, 'domain_table'); } } }); @@ -392,7 +392,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'mailbox_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'mailbox_table'); + paging_mailbox_after(ft, 'mailbox_table'); } } }); @@ -457,7 +457,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'resource_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'resource_table'); + paging_mailbox_after(ft, 'resource_table'); } } }); @@ -519,7 +519,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'bcc_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'bcc_table'); + paging_mailbox_after(ft, 'bcc_table'); } } }); @@ -576,7 +576,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'recipient_map_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'recipient_map_table'); + paging_mailbox_after(ft, 'recipient_map_table'); } } }); @@ -645,7 +645,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'alias_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'alias_table'); + paging_mailbox_after(ft, 'alias_table'); } } }); @@ -699,7 +699,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'aliasdomain_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'aliasdomain_table'); + paging_mailbox_after(ft, 'aliasdomain_table'); } } }); @@ -711,10 +711,10 @@ jQuery(function($){ {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"}, {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}}, {"name":"user2","title":lang.owner}, - {"name":"server_w_port","title":"Server","breakpoints":"xs"}, + {"name":"server_w_port","title":"Server","breakpoints":"xs","style":{"word-break":"break-all"}}, {"name":"exclude","title":lang.excludes,"breakpoints":"all"}, {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"}, - {"name":"last_run","title":lang.last_run,"breakpoints":"all"}, + {"name":"last_run","title":lang.last_run,"breakpoints":"sm"}, {"name":"log","title":"Log"}, {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active}, {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status}, @@ -774,7 +774,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'sync_job_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'sync_job_table'); + paging_mailbox_after(ft, 'sync_job_table'); } } }); @@ -837,7 +837,7 @@ jQuery(function($){ table_mailbox_ready(ft, 'filter_table'); }, "after.ft.paging": function(e, ft){ - table_mailbox_paging(ft, 'filter_table'); + paging_mailbox_after(ft, 'filter_table'); } } }); diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php index 3de887b13..d93f77ba7 100644 --- a/data/web/lang/lang.de.php +++ b/data/web/lang/lang.de.php @@ -300,6 +300,11 @@ $lang['add']['exclude'] = 'Elemente ausschließen (Regex)'; $lang['add']['delete2duplicates'] = 'Lösche Duplikate im Ziel'; $lang['add']['delete1'] = 'Lösche Nachricht nach Übertragung vom Quell-Server'; $lang['add']['delete2'] = 'Lösche Nachrichten von Ziel-Server, die nicht auf Quell-Server vorhanden sind'; +$lang['add']['custom_params'] = 'Eigene Parameter'; +$lang['add']['subscribeall'] = 'Alle synchronisierten Ordner abonnieren'; +$lang['add']['timeout1'] = 'Timeout für Verbindung zum Remote-Host'; +$lang['add']['timeout2'] = 'Timeout für Verbindung zum lokalen Host'; + $lang['edit']['delete2duplicates'] = 'Lösche Duplikate im Ziel'; $lang['edit']['delete1'] = 'Lösche Nachricht nach Übertragung vom Quell-Server'; $lang['edit']['delete2'] = 'Lösche Nachrichten von Ziel-Server, die nicht auf Quell-Server vorhanden sind'; diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php index 2f9eda73d..0e18bbfcb 100644 --- a/data/web/lang/lang.en.php +++ b/data/web/lang/lang.en.php @@ -251,7 +251,7 @@ $lang['edit']['redirect_uri'] = 'Redirect/Callback URL'; $lang['edit']['hostname'] = 'Hostname'; $lang['edit']['encryption'] = 'Encryption'; $lang['edit']['maxage'] = 'Maximum age of messages in days that will be polled from remote
    (0 = ignore age)'; -$lang['edit']['maxbytespersecond'] = 'Max. bytes per second (0 equals to unlimited)'; +$lang['edit']['maxbytespersecond'] = 'Max. bytes per second
    (0 = unlimited)'; $lang['edit']['automap'] = 'Try to automap folders ("Sent items", "Sent" => "Sent" etc.)'; $lang['edit']['skipcrossduplicates'] = 'Skip duplicate messages across folders (first come, first serve)'; $lang['add']['automap'] = 'Try to automap folders ("Sent items", "Sent" => "Sent" etc.)'; @@ -260,6 +260,7 @@ $lang['edit']['subfolder2'] = 'Sync into subfolder on destination
    (emp $lang['edit']['mins_interval'] = 'Interval (min)'; $lang['edit']['exclude'] = 'Exclude objects (regex)'; $lang['edit']['save'] = 'Save changes'; +$lang['edit']['username'] = 'Username'; $lang['edit']['max_mailboxes'] = 'Max. possible mailboxes'; $lang['edit']['title'] = 'Edit object'; $lang['edit']['target_address'] = 'Goto address/es (comma-separated)'; @@ -304,6 +305,11 @@ $lang['add']['exclude'] = 'Exclude objects (regex)'; $lang['add']['delete2duplicates'] = 'Delete duplicates on destination'; $lang['add']['delete1'] = 'Delete from source when completed'; $lang['add']['delete2'] = 'Delete messages on destination that are not on source'; +$lang['add']['custom_params'] = 'Custom parameters'; +$lang['add']['subscribeall'] = 'Subscribe all folders'; +$lang['add']['timeout1'] = 'Timeout for connection to remote host'; +$lang['add']['timeout2'] = 'Timeout for connection to local host'; + $lang['edit']['delete2duplicates'] = 'Delete duplicates on destination'; $lang['edit']['delete1'] = 'Delete from source when completed'; $lang['edit']['delete2'] = 'Delete messages on destination that are not on source'; diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php index 1e0a7aaee..12b20bc30 100644 --- a/data/web/modals/mailbox.php +++ b/data/web/modals/mailbox.php @@ -383,7 +383,7 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
    - 10-3600 + 1-3600
    @@ -406,44 +406,71 @@ if (!isset($_SESSION['mailcow_cc_role'])) { 0-125000000
    +
    + +
    + + 1-32000 +
    +
    +
    + +
    + + 1-32000 +
    +
    +
    + +
    + +
    +
    - +
    - +
    - +
    - +
    - + +
    +
    +
    +
    +
    +
    +