Browse Source

add demo_mode for mailcow ui

FreddleSpl0it 2 years ago
parent
commit
ef392ef6ba

+ 28 - 0
data/web/inc/functions.customize.inc.php

@@ -2,8 +2,18 @@
 function customize($_action, $_item, $_data = null) {
 function customize($_action, $_item, $_data = null) {
 	global $redis;
 	global $redis;
 	global $lang;
 	global $lang;
+  
   switch ($_action) {
   switch ($_action) {
     case 'add':
     case 'add':
+      // disable functionality when demo mode is enabled
+      if ($GLOBALS["DEMO_MODE"]) {
+        $_SESSION['return'][] = array(
+          'type' => 'danger',
+          'log' => array(__FUNCTION__, $_action, $_item, $_data),
+          'msg' => 'demo_mode_enabled'
+        );
+        return false;
+      }
       if ($_SESSION['mailcow_cc_role'] != "admin") {
       if ($_SESSION['mailcow_cc_role'] != "admin") {
         $_SESSION['return'][] = array(
         $_SESSION['return'][] = array(
           'type' => 'danger',
           'type' => 'danger',
@@ -72,6 +82,15 @@ function customize($_action, $_item, $_data = null) {
       }
       }
     break;
     break;
     case 'edit':
     case 'edit':
+      // disable functionality when demo mode is enabled
+      if ($GLOBALS["DEMO_MODE"]) {
+        $_SESSION['return'][] = array(
+          'type' => 'danger',
+          'log' => array(__FUNCTION__, $_action, $_item, $_data),
+          'msg' => 'demo_mode_enabled'
+        );
+        return false;
+      }
       if ($_SESSION['mailcow_cc_role'] != "admin") {
       if ($_SESSION['mailcow_cc_role'] != "admin") {
         $_SESSION['return'][] = array(
         $_SESSION['return'][] = array(
           'type' => 'danger',
           'type' => 'danger',
@@ -144,6 +163,15 @@ function customize($_action, $_item, $_data = null) {
       }
       }
     break;
     break;
     case 'delete':
     case 'delete':
+      // disable functionality when demo mode is enabled
+      if ($GLOBALS["DEMO_MODE"]) {
+        $_SESSION['return'][] = array(
+          'type' => 'danger',
+          'log' => array(__FUNCTION__, $_action, $_item, $_data),
+          'msg' => 'demo_mode_enabled'
+        );
+        return false;
+      }
       if ($_SESSION['mailcow_cc_role'] != "admin") {
       if ($_SESSION['mailcow_cc_role'] != "admin") {
         $_SESSION['return'][] = array(
         $_SESSION['return'][] = array(
           'type' => 'danger',
           'type' => 'danger',

+ 2 - 0
data/web/inc/prerequisites.inc.php

@@ -2,6 +2,8 @@
 
 
 // check for development mode
 // check for development mode
 $DEV_MODE = (getenv('DEV_MODE') == 'y');
 $DEV_MODE = (getenv('DEV_MODE') == 'y');
+// check for demo mode
+$DEMO_MODE = (getenv('DEMO_MODE') == 'y');
 
 
 // Slave does not serve UI
 // Slave does not serve UI
 /* if (!preg_match('/y|yes/i', getenv('MASTER'))) {
 /* if (!preg_match('/y|yes/i', getenv('MASTER'))) {

+ 1 - 0
data/web/lang/lang.de-de.json

@@ -352,6 +352,7 @@
         "bcc_must_be_email": "BCC-Ziel %s ist keine gültige E-Mail-Adresse",
         "bcc_must_be_email": "BCC-Ziel %s ist keine gültige E-Mail-Adresse",
         "comment_too_long": "Kommentarfeld darf maximal 160 Zeichen enthalten",
         "comment_too_long": "Kommentarfeld darf maximal 160 Zeichen enthalten",
         "defquota_empty": "Standard-Quota darf nicht 0 sein",
         "defquota_empty": "Standard-Quota darf nicht 0 sein",
+        "demo_mode_enabled": "Demo Mode ist aktiviert",
         "description_invalid": "Ressourcenbeschreibung für %s ist ungültig",
         "description_invalid": "Ressourcenbeschreibung für %s ist ungültig",
         "dkim_domain_or_sel_exists": "Ein DKIM-Key für die Domain \"%s\" existiert und wird nicht überschrieben",
         "dkim_domain_or_sel_exists": "Ein DKIM-Key für die Domain \"%s\" existiert und wird nicht überschrieben",
         "dkim_domain_or_sel_invalid": "DKIM-Domain oder Selector nicht korrekt: %s",
         "dkim_domain_or_sel_invalid": "DKIM-Domain oder Selector nicht korrekt: %s",

+ 1 - 0
data/web/lang/lang.en-gb.json

@@ -352,6 +352,7 @@
         "bcc_must_be_email": "BCC destination %s is not a valid email address",
         "bcc_must_be_email": "BCC destination %s is not a valid email address",
         "comment_too_long": "Comment too long, max 160 chars allowed",
         "comment_too_long": "Comment too long, max 160 chars allowed",
         "defquota_empty": "Default quota per mailbox must not be 0.",
         "defquota_empty": "Default quota per mailbox must not be 0.",
+        "demo_mode_enabled": "Demo Mode is enabled",
         "description_invalid": "Resource description for %s is invalid",
         "description_invalid": "Resource description for %s is invalid",
         "dkim_domain_or_sel_exists": "A DKIM key for \"%s\" exists and will not be overwritten",
         "dkim_domain_or_sel_exists": "A DKIM key for \"%s\" exists and will not be overwritten",
         "dkim_domain_or_sel_invalid": "DKIM domain or selector invalid: %s",
         "dkim_domain_or_sel_invalid": "DKIM domain or selector invalid: %s",

+ 1 - 0
docker-compose.yml

@@ -160,6 +160,7 @@ services:
         - ALLOW_ADMIN_EMAIL_LOGIN=${ALLOW_ADMIN_EMAIL_LOGIN:-n}
         - ALLOW_ADMIN_EMAIL_LOGIN=${ALLOW_ADMIN_EMAIL_LOGIN:-n}
         - MASTER=${MASTER:-y}
         - MASTER=${MASTER:-y}
         - DEV_MODE=${DEV_MODE:-n}
         - DEV_MODE=${DEV_MODE:-n}
+        - DEMO_MODE=${DEMO_MODE:-n}
         - WEBAUTHN_ONLY_TRUSTED_VENDORS=${WEBAUTHN_ONLY_TRUSTED_VENDORS:-n}
         - WEBAUTHN_ONLY_TRUSTED_VENDORS=${WEBAUTHN_ONLY_TRUSTED_VENDORS:-n}
       restart: always
       restart: always
       networks:
       networks: