NobGit
public nobgit read

NobMail

Based on mailcow: dockerized

Languages

Repository composition by tracked source files.

PHP
PHP 49% JavaScript 35% HTML 9% CSS 4% Shell 2% Python 1% Lua 0% Perl 0% Ruby 0% SCSS 0%
Create file Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git

Commit

[Dovecot: Imapsync] Parse, save and show last run status (#4253)

* [imapsync] - check for errors in returned_text Signed-off-by: Kristian Feldsam <[email protected]> * [imapsync] parse and save exit status Signed-off-by: Kristian Feldsam <[email protected]> * [dovecot] updated image version Signed-off-by: Kristian Feldsam <[email protected]>

54c4d7e4
Kristian Feldsam <[email protected]> 4 years, 11 months ago
data/Dockerfiles/dovecot/imapsync_runner.pl | 22 ++++++++++++++++------
 data/web/inc/functions.mailbox.inc.php      |  3 +++
 data/web/inc/init_db.inc.php                |  4 +++-
 data/web/js/site/mailbox.js                 | 13 +++++++++++++
 data/web/js/site/user.js                    | 17 +++++++++++++++--
 data/web/lang/lang.cs.json                  | 18 ++++++++++++++++++
 data/web/lang/lang.en.json                  | 18 ++++++++++++++++++
 data/web/lang/lang.sk.json                  | 18 ++++++++++++++++++
 data/web/mailbox.php                        |  2 +-
 docker-compose.yml                          |  2 +-
 10 files changed, 106 insertions(+), 11 deletions(-)

Diff

diff --git a/data/Dockerfiles/dovecot/imapsync_runner.pl b/data/Dockerfiles/dovecot/imapsync_runner.pl
index 0f01a971..5b297abd 100644
--- a/data/Dockerfiles/dovecot/imapsync_runner.pl
+++ b/data/Dockerfiles/dovecot/imapsync_runner.pl
@@ -152,18 +152,28 @@ while ($row = $sth->fetchrow_arrayref()) {
   '--noreleasecheck'];
 
   try {
-    $is_running = $dbh->prepare("UPDATE imapsync SET is_running = 1 WHERE id = ?");
+    $is_running = $dbh->prepare("UPDATE imapsync SET is_running = 1, success = NULL, exit_status = NULL WHERE id = ?");
     $is_running->bind_param( 1, ${id} );
     $is_running->execute();
-    
+
     run [@$generated_cmds, @$custom_params_ref], '&>', \my $stdout;
-    
-    $update = $dbh->prepare("UPDATE imapsync SET returned_text = ? WHERE id = ?");
+
+    # check exit code and status
+    ($exit_code, $exit_status) = ($stdout =~ m/Exiting\swith\sreturn\svalue\s(\d+)\s\(([^:)]+)/);
+
+    $success = 0;
+    if (defined $exit_code && $exit_code == 0) {
+      $success = 1;
+    }
+
+    $update = $dbh->prepare("UPDATE imapsync SET returned_text = ?, success = ?, exit_status = ? WHERE id = ?");
     $update->bind_param( 1, ${stdout} );
-    $update->bind_param( 2, ${id} );
+    $update->bind_param( 2, ${success} );
+    $update->bind_param( 3, ${exit_status} );
+    $update->bind_param( 4, ${id} );
     $update->execute();
   } catch {
-    $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync' WHERE id = ?");
+    $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync', success = 0 WHERE id = ?");
     $update->bind_param( 1, ${id} );
     $update->execute();
   } finally {
diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php
index 24e5dabf..5010df9e 100644
--- a/data/web/inc/functions.mailbox.inc.php
+++ b/data/web/inc/functions.mailbox.inc.php
@@ -1673,6 +1673,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
               $user1 = (!empty($_data['user1'])) ? $_data['user1'] : $is_now['user1'];
               $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active'];
               $last_run = (isset($_data['last_run'])) ? NULL : $is_now['last_run'];
+              $success = (isset($_data['success'])) ? NULL : $is_now['success'];
               $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'];
@@ -1768,6 +1769,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
               `exclude` = :exclude,
               `host1` = :host1,
               `last_run` = :last_run,
+              `success` = :success,
               `user1` = :user1,
               `password1` = :password1,
               `mins_interval` = :mins_interval,
@@ -1794,6 +1796,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) {
               ':user1' => $user1,
               ':password1' => $password1,
               ':last_run' => $last_run,
+              ':success' => $success,
               ':mins_interval' => $mins_interval,
               ':port1' => $port1,
               ':enc1' => $enc1,
diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php
index c43afbf9..c0c984b8 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 = "01072021_0630";
+    $db_version = "23082021_2224";
 
     $stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
     $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
@@ -632,6 +632,8 @@ function init_db_schema() {
           "is_running" => "TINYINT(1) NOT NULL DEFAULT '0'",
           "returned_text" => "LONGTEXT",
           "last_run" => "TIMESTAMP NULL DEFAULT NULL",
+          "success" => "TINYINT(1) UNSIGNED DEFAULT NULL",
+          "exit_status" => "VARCHAR(50) DEFAULT NULL",
           "created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
           "modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP",
           "active" => "TINYINT(1) NOT NULL DEFAULT '0'"
diff --git a/data/web/js/site/mailbox.js b/data/web/js/site/mailbox.js
index fec23821..745c4f21 100644
--- a/data/web/js/site/mailbox.js
+++ b/data/web/js/site/mailbox.js
@@ -988,6 +988,7 @@ jQuery(function($){
         {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
         {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
         {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
+        {"name":"exit_status","filterable": false,"title":lang.syncjob_last_run_result},
         {"name":"log","title":"Log"},
         {"name":"active","filterable": false,"style":{"min-width":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
         {"name":"is_running","filterable": false,"style":{"min-width":"120px","width":"100px"},"title":lang.status},
@@ -1024,6 +1025,18 @@ jQuery(function($){
             if (!item.last_run > 0) {
               item.last_run = lang.waiting;
             }
+            if (item.success == null) {
+              item.success = '-';
+              item.exit_status = '';
+            } else {
+              item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
+            }
+            if (lang['syncjob_'+item.exit_status]) {
+	            item.exit_status = lang['syncjob_'+item.exit_status];
+            } else if (item.success != '-') {
+	            item.exit_status = lang.syncjob_check_log;
+            }
+            item.exit_status = item.success + ' ' + item.exit_status;
           });
         }
       }),
diff --git a/data/web/js/site/user.js b/data/web/js/site/user.js
index 83aedba4..a07ec5fc 100644
--- a/data/web/js/site/user.js
+++ b/data/web/js/site/user.js
@@ -176,12 +176,13 @@ jQuery(function($){
       "columns": [
         {"name":"chkbox","title":"","style":{"min-width":"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":"server_w_port","title":"Server"},
+        {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
         {"name":"enc1","title":lang.encryption,"breakpoints":"all"},
         {"name":"user1","title":lang.username},
         {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
         {"name":"mins_interval","title":lang.interval + " (min)","breakpoints":"all"},
-        {"name":"last_run","title":lang.last_run,"breakpoints":"all"},
+        {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
+        {"name":"exit_status","filterable": false,"title":lang.syncjob_last_run_result},
         {"name":"log","title":"Log"},
         {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
         {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status},
@@ -224,6 +225,18 @@ jQuery(function($){
             if (!item.last_run > 0) {
               item.last_run = lang.waiting;
             }
+            if (item.success == null) {
+              item.success = '-';
+              item.exit_status = '';
+            } else {
+              item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
+            }
+            if (lang['syncjob_'+item.exit_status]) {
+	            item.exit_status = lang['syncjob_'+item.exit_status];
+            } else if (item.success != '-') {
+	            item.exit_status = lang.syncjob_check_log;
+            }
+            item.exit_status = item.success + ' ' + item.exit_status;
           });
         }
       }),
diff --git a/data/web/lang/lang.cs.json b/data/web/lang/lang.cs.json
index 1d658c3b..78e5205a 100644
--- a/data/web/lang/lang.cs.json
+++ b/data/web/lang/lang.cs.json
@@ -794,6 +794,15 @@
         "stats": "Statistika",
         "status": "Stav",
         "sync_jobs": "Synchronizační úlohy",
+        "syncjob_check_log": "Zkontrolujte záznam",
+        "syncjob_last_run_result": "Výsledek posledního spuštění",
+        "syncjob_EX_OK": "Úspěch",
+        "syncjob_EXIT_CONNECTION_FAILURE": "Problém se spojením",
+        "syncjob_EXIT_TLS_FAILURE": "Problém se šifrovaným spojením",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE": "Problém s autentifikací",
+        "syncjob_EXIT_OVERQUOTA": "Cílová schránka je plná",
+        "syncjob_EXIT_CONNECTION_FAILURE_HOST1": "Nelze se připojit ke vzdálenému serveru",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE_USER1": "Chybné uživatelské jméno nebo heslo",
         "table_size": "Velikost tabulky",
         "table_size_show_n": "Zobrazit %s položek",
         "target_address": "Cílová adresa",
@@ -1119,6 +1128,15 @@
         "spamfilter_yellow": "Žlutá: tato zpráva může být spam, bude označena jako spam a přesunuta do složky nevyžádané pošty",
         "status": "Stav",
         "sync_jobs": "Synchronizační úlohy",
+        "syncjob_check_log": "Zkontrolujte záznam",
+        "syncjob_last_run_result": "Výsledek posledního spuštění",
+        "syncjob_EX_OK": "Úspěch",
+        "syncjob_EXIT_CONNECTION_FAILURE": "Problém se spojením",
+        "syncjob_EXIT_TLS_FAILURE": "Problém se šifrovaným spojením",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE": "Problém s autentifikací",
+        "syncjob_EXIT_OVERQUOTA": "Cílová schránka je plná",
+        "syncjob_EXIT_CONNECTION_FAILURE_HOST1": "Nelze se připojit ke vzdálenému serveru",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE_USER1": "Chybné uživatelské jméno nebo heslo",
         "tag_handling": "Zacházení s označkovanou poštou",
         "tag_help_example": "Příklad e-mailové adresy se značkou: me<b>+Facebook</b>@example.org",
         "tag_help_explain": "V podsložce: v doručené poště bude vytvořena nová podsložka pojmenovaná po značce zprávy (\"INBOX / Facebook\").<br>\r\nV předmětu: název značky bude přidáván k předmětu mailu, například: \"[Facebook] Moje zprávy\".",
diff --git a/data/web/lang/lang.en.json b/data/web/lang/lang.en.json
index 4850b142..62a26908 100644
--- a/data/web/lang/lang.en.json
+++ b/data/web/lang/lang.en.json
@@ -820,6 +820,15 @@
         "stats": "Statistics",
         "status": "Status",
         "sync_jobs": "Sync jobs",
+        "syncjob_check_log": "Check log",
+        "syncjob_last_run_result": "Last run result",
+        "syncjob_EX_OK": "Success",
+        "syncjob_EXIT_CONNECTION_FAILURE": "Connection problem",
+        "syncjob_EXIT_TLS_FAILURE": "Problem with encrypted connection",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE": "Authentication problem",
+        "syncjob_EXIT_OVERQUOTA": "Target mailbox is over quota",
+        "syncjob_EXIT_CONNECTION_FAILURE_HOST1": "Can't connect to remote server",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE_USER1": "Wrong username or password",
         "table_size": "Table size",
         "table_size_show_n": "Show %s items",
         "target_address": "Goto address",
@@ -1147,6 +1156,15 @@
         "spamfilter_yellow": "Yellow: this message may be spam, will be tagged as spam and moved to your junk folder",
         "status": "Status",
         "sync_jobs": "Sync jobs",
+        "syncjob_check_log": "Check log",
+        "syncjob_last_run_result": "Last run result",
+        "syncjob_EX_OK": "Success",
+        "syncjob_EXIT_CONNECTION_FAILURE": "Connection problem",
+        "syncjob_EXIT_TLS_FAILURE": "Problem with encrypted connection",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE": "Authentication problem",
+        "syncjob_EXIT_OVERQUOTA": "Target mailbox is over quota",
+        "syncjob_EXIT_CONNECTION_FAILURE_HOST1": "Can't connect to remote server",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE_USER1": "Wrong username or password",
         "tag_handling": "Set handling for tagged mail",
         "tag_help_example": "Example for a tagged email address: me<b>+Facebook</b>@example.org",
         "tag_help_explain": "In subfolder: a new subfolder named after the tag will be created below INBOX (\"INBOX/Facebook\").<br>\r\nIn subject: the tags name will be prepended to the mails subject, example: \"[Facebook] My News\".",
diff --git a/data/web/lang/lang.sk.json b/data/web/lang/lang.sk.json
index ee5a7a72..306402e2 100644
--- a/data/web/lang/lang.sk.json
+++ b/data/web/lang/lang.sk.json
@@ -818,6 +818,15 @@
         "stats": "Štatistika",
         "status": "Status",
         "sync_jobs": "Synchronizačné úlohy",
+        "syncjob_check_log": "Skontrolujte záznam",
+        "syncjob_last_run_result": "Výsledok posledného spustenia",
+        "syncjob_EX_OK": "Úspech",
+        "syncjob_EXIT_CONNECTION_FAILURE": "Problém so spojením",
+        "syncjob_EXIT_TLS_FAILURE": "Problém so šifrovaným spojením",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE": "Problém s autentifikáciou",
+        "syncjob_EXIT_OVERQUOTA": "Cieľová schránka je plná",
+        "syncjob_EXIT_CONNECTION_FAILURE_HOST1": "Nedá sa pripojiť k vzdialenému serveru",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE_USER1": "Chybné uživateľské meno alebo heslo",
         "table_size": "Veľkosť tabuľky",
         "table_size_show_n": "Zobraziť %s položiek",
         "target_address": "Cieľová adresa",
@@ -1145,6 +1154,15 @@
         "spamfilter_yellow": "Žltá: Táto správa môže byť spam, bude označená ako spam a presunutá do priečinku nevyžiadanej pošty",
         "status": "Status",
         "sync_jobs": "Synchronizačné úlohy",
+        "syncjob_check_log": "Skontrolujte záznam",
+        "syncjob_last_run_result": "Výsledok posledného spustenia",
+        "syncjob_EX_OK": "Úspech",
+        "syncjob_EXIT_CONNECTION_FAILURE": "Problém so spojením",
+        "syncjob_EXIT_TLS_FAILURE": "Problém so šifrovaným spojením",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE": "Problém s autentifikáciou",
+        "syncjob_EXIT_OVERQUOTA": "Cieľová schránka je plná",
+        "syncjob_EXIT_CONNECTION_FAILURE_HOST1": "Nedá sa pripojiť k vzdialenému serveru",
+        "syncjob_EXIT_AUTHENTICATION_FAILURE_USER1": "Chybné uživateľské meno alebo heslo",
         "tag_handling": "Zaobchádzanie s označenou poštou",
         "tag_help_example": "Príklad tagu e-mailovej adresy: me<b>+Facebook</b>@example.org",
         "tag_help_explain": "V podadresári: nový podadresár s menom tag-u bude vytvorený nižšie INBOX (\"INBOX/Facebook\").<br>\r\nIn subject: meno štítka bude pridané pred predmet pošty, napríklad: \"[Facebook] My News\".",
diff --git a/data/web/mailbox.php b/data/web/mailbox.php
index 6dfe3af5..4d481fee 100644
--- a/data/web/mailbox.php
+++ b/data/web/mailbox.php
@@ -385,7 +385,7 @@ $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
                 <a class="btn btn-sm btn-xs-half visible-xs-block visible-sm-inline visible-md-inline visible-lg-inline btn-default" id="toggle_multi_select_all" data-id="syncjob" href="#"><i class="bi bi-check-all"></i> <?=$lang['mailbox']['toggle_all'];?></a>
                 <a class="btn btn-sm btn-xs-half visible-xs-block visible-sm-inline visible-md-inline visible-lg-inline btn-default dropdown-toggle" data-toggle="dropdown" href="#"><?=$lang['mailbox']['quick_actions'];?> <span class="caret"></span></a>
                 <ul class="dropdown-menu">
-                  <li><a data-action="edit_selected" data-id="syncjob" data-api-url='edit/syncjob' data-api-attr='{"last_run":""}' href="#"><?=$lang['mailbox']['last_run_reset'];?></a></li>
+                  <li><a data-action="edit_selected" data-id="syncjob" data-api-url='edit/syncjob' data-api-attr='{"last_run":"","success":""}' href="#"><?=$lang['mailbox']['last_run_reset'];?></a></li>
                   <li role="separator" class="divider"></li>
                   <li><a data-action="edit_selected" data-id="syncjob" data-api-url='edit/syncjob' data-api-attr='{"active":"1"}' href="#"><?=$lang['mailbox']['activate'];?></a></li>
                   <li><a data-action="edit_selected" data-id="syncjob" data-api-url='edit/syncjob' data-api-attr='{"active":"0"}' href="#"><?=$lang['mailbox']['deactivate'];?></a></li>
diff --git a/docker-compose.yml b/docker-compose.yml
index 2bd3b44f..80d7ee57 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -210,7 +210,7 @@ services:
             - sogo
 
     dovecot-mailcow:
-      image: mailcow/dovecot:1.155
+      image: mailcow/dovecot:1.156
       depends_on:
         - mysql-mailcow
       dns: