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

[Web] Restart SOGo after adding a new domain, fixes #864

278f1c2a
andre.peters <[email protected]> 9 years ago
data/web/inc/footer.inc.php            |  3 ++-
 data/web/inc/functions.mailbox.inc.php | 20 ++++++++++++++++----
 data/web/js/api.js                     | 13 +++++++++++++
 data/web/lang/lang.de.php              |  2 ++
 data/web/lang/lang.en.php              |  2 ++
 data/web/modals/mailbox.php            |  3 ++-
 6 files changed, 37 insertions(+), 6 deletions(-)

Diff

diff --git a/data/web/inc/footer.inc.php b/data/web/inc/footer.inc.php
index eb419308..d7bb4353 100644
--- a/data/web/inc/footer.inc.php
+++ b/data/web/inc/footer.inc.php
@@ -13,6 +13,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php';
 <script src="/js/u2f-api.js"></script>
 <script src="/js/api.js"></script>
 <script>
+var loading_text = '<?= $lang['footer']['loading']; ?>'
 $(window).scroll(function() {
   sessionStorage.scrollTop = $(this).scrollTop();
 });
@@ -157,7 +158,7 @@ $(document).ready(function() {
     }
   })();
 
-  // Disable submit after submitting form
+  // Disable submit after submitting form (not API driven buttons)
   $('form').submit(function() {
     if ($('form button[type="submit"]').data('submitted') == '1') {
       return false;
diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php
index 77512fa0..56fe167c 100644
--- a/data/web/inc/functions.mailbox.inc.php
+++ b/data/web/inc/functions.mailbox.inc.php
@@ -333,6 +333,7 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
           $aliases			= $_data['aliases'];
           $mailboxes    = $_data['mailboxes'];
           $maxquota			= $_data['maxquota'];
+          $restart_sogo = $_data['restart_sogo'];
           $quota				= $_data['quota'];
           if ($maxquota > $quota) {
             $_SESSION['return'] = array(
@@ -416,10 +417,21 @@ function mailbox($_action, $_type, $_data = null, $attr = null) {
               );
               return false;
             }
-            $_SESSION['return'] = array(
-              'type' => 'success',
-              'msg' => sprintf($lang['success']['domain_added'], htmlspecialchars($domain))
-            );
+            if (!empty($restart_sogo)) {
+              $restart_reponse = json_decode(docker('sogo-mailcow', 'post', 'restart'), true);
+              if ($restart_reponse['type'] == "success") {
+                $_SESSION['return'] = array(
+                  'type' => 'success',
+                  'msg' => sprintf($lang['success']['domain_added'], htmlspecialchars($domain))
+                );
+              }
+              else {
+                $_SESSION['return'] = array(
+                  'type' => 'warning',
+                  'msg' => 'Added domain but failed to restart SOGo, please check your server logs.'
+                );
+              }
+            }
           }
           catch (PDOException $e) {
             mailbox('delete', 'domain', array('domain' => $domain));
diff --git a/data/web/js/api.js b/data/web/js/api.js
index cc036d2f..f0a0e0b6 100644
--- a/data/web/js/api.js
+++ b/data/web/js/api.js
@@ -1,4 +1,15 @@
 $(document).ready(function() {
+  function is_active(elem) {
+    if ($(elem).data('submitted') == '1') {
+      return true;
+    } else {
+      $(elem).text(loading_text);
+      $(elem).attr('data-submitted', '1');
+      function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
+      $(document).on("keydown", disableF5);
+      return false;
+    }
+  }
   $.fn.serializeObject = function() {
     var o = {};
     var a = this.serializeArray();
@@ -115,6 +126,7 @@ $(document).ready(function() {
     api_items = multi_data[id];
     // alert(JSON.stringify(api_attr));
     if (Object.keys(api_items).length !== 0) {
+      if (is_active($(this))) { return false; }
       $.ajax({
         type: "POST",
         dataType: "json",
@@ -185,6 +197,7 @@ $(document).ready(function() {
         return false;
       }
     }
+    if (is_active($(this))) { return false; }
     // alert(JSON.stringify(api_attr));
     $.ajax({
       type: "POST",
diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php
index 6d80d231..e605a47e 100644
--- a/data/web/lang/lang.de.php
+++ b/data/web/lang/lang.de.php
@@ -493,6 +493,8 @@ $lang['admin']['dkim_key_unused'] = 'Key ohne Zuweisung';
 $lang['admin']['dkim_key_missing'] = 'Key fehlt';
 $lang['admin']['dkim_key_hint'] = 'Der Selector für DKIM-Keys lautet immer <code>dkim</code>.';
 $lang['admin']['add'] = 'Hinzufügen';
+$lang['add']['add_domain_restart'] = 'Domain hinzufügen und SOGo neustarten';
+$lang['add']['add_domain_only'] = 'Nur Domain hinzufügen';
 $lang['admin']['configuration'] = 'Konfiguration';
 $lang['admin']['password'] = 'Passwort';
 $lang['admin']['password_repeat'] = 'Passwort (Wiederholung)';
diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php
index ac108a5e..74df7c53 100644
--- a/data/web/lang/lang.en.php
+++ b/data/web/lang/lang.en.php
@@ -499,6 +499,8 @@ $lang['admin']['sys_info'] = 'System information';
 $lang['admin']['dkim_add_key'] = 'Add ARC/DKIM key';
 $lang['admin']['dkim_keys'] = 'ARC/DKIM keys';
 $lang['admin']['add'] = 'Add';
+$lang['add']['add_domain_restart'] = 'Add domain and restart SOGo';
+$lang['add']['add_domain_only'] = 'Add domain only';
 $lang['admin']['configuration'] = 'Configuration';
 $lang['admin']['password'] = 'Password';
 $lang['admin']['password_repeat'] = 'Confirmation password (repeat)';
diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php
index aa1c00f5..b70cbe13 100644
--- a/data/web/modals/mailbox.php
+++ b/data/web/modals/mailbox.php
@@ -143,7 +143,8 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
 					</div>
 					<div class="form-group">
 						<div class="col-sm-offset-2 col-sm-10">
-              <button class="btn btn-default" id="add_item" data-id="add_domain" data-api-url='add/domain' data-api-attr='{}' href="#"><?=$lang['admin']['add'];?></button>
+              <button class="btn btn-default" id="add_item" data-id="add_domain" data-api-url='add/domain' data-api-attr='{}' href="#"><?=$lang['add']['add_domain_only'];?></button>
+              <button class="btn btn-default" id="add_item" data-id="add_domain" data-api-url='add/domain' data-api-attr='{"restart_sogo":"1"}' href="#"><?=$lang['add']['add_domain_restart'];?></button>
 						</div>
 					</div>
 					<p><span class="glyphicon glyphicon-exclamation-sign text-danger"></span> <?=$lang['add']['restart_sogo_hint'];?></p>