Browse Source

[Web] add app hide option

FreddleSpl0it 2 years ago
parent
commit
6e35574c72

+ 4 - 2
data/web/inc/functions.customize.inc.php

@@ -123,12 +123,14 @@ function customize($_action, $_item, $_data = null) {
           $apps = (array)$_data['app'];
           $apps = (array)$_data['app'];
           $links = (array)$_data['href'];
           $links = (array)$_data['href'];
           $user_links = (array)$_data['user_href'];
           $user_links = (array)$_data['user_href'];
+          $hide = (array)$_data['hide'];
           $out = array();
           $out = array();
-          if (count($apps) == count($links) && count($apps) == count($user_links)) {
+          if (count($apps) == count($links) && count($apps) == count($user_links) && count($apps) == count($hide)) {
             for ($i = 0; $i < count($apps); $i++) {
             for ($i = 0; $i < count($apps); $i++) {
               $out[] = array($apps[$i] => array(
               $out[] = array($apps[$i] => array(
                 'link' => $links[$i],
                 'link' => $links[$i],
-                'user_link' => $user_links[$i]
+                'user_link' => $user_links[$i],
+                'hide' => ($hide[$i] === '0' || $hide[$i] === 0) ? false : true
               ));
               ));
             }
             }
             try {
             try {

+ 22 - 2
data/web/inc/header.inc.php

@@ -31,11 +31,29 @@ if(!file_exists($CSSPath)) {
 }
 }
 
 
 $mailcow_apps_processed = $MAILCOW_APPS;
 $mailcow_apps_processed = $MAILCOW_APPS;
+$app_links = customize('get', 'app_links');
+$app_links_processed = $app_links;
+$hide_mailcow_apps = true;
 for ($i = 0; $i < count($mailcow_apps_processed); $i++) {
 for ($i = 0; $i < count($mailcow_apps_processed); $i++) {
+  if ($hide_mailcow_apps && !$mailcow_apps_processed[$i]['hide']){
+    $hide_mailcow_apps = false;
+  }
   if (!empty($_SESSION['mailcow_cc_username'])){
   if (!empty($_SESSION['mailcow_cc_username'])){
     $mailcow_apps_processed[$i]['user_link'] = str_replace('%u', $_SESSION['mailcow_cc_username'], $mailcow_apps_processed[$i]['user_link']);
     $mailcow_apps_processed[$i]['user_link'] = str_replace('%u', $_SESSION['mailcow_cc_username'], $mailcow_apps_processed[$i]['user_link']);
   }
   }
 }
 }
+if ($app_links_processed){
+  for ($i = 0; $i < count($app_links_processed); $i++) {
+    $key = array_key_first($app_links_processed[$i]);
+    if ($hide_mailcow_apps && !$app_links_processed[$i][$key]['hide']){
+      $hide_mailcow_apps = false;
+    }
+    if (!empty($_SESSION['mailcow_cc_username'])){
+      $app_links_processed[$i][$key]['user_link'] = str_replace('%u', $_SESSION['mailcow_cc_username'], $app_links_processed[$i][$key]['user_link']);
+    }
+  }
+}
+
 
 
 
 
 $globalVariables = [
 $globalVariables = [
@@ -53,9 +71,11 @@ $globalVariables = [
   'lang' => $lang,
   'lang' => $lang,
   'skip_sogo' => (getenv('SKIP_SOGO') == 'y'),
   'skip_sogo' => (getenv('SKIP_SOGO') == 'y'),
   'allow_admin_email_login' => (getenv('ALLOW_ADMIN_EMAIL_LOGIN') == 'n'),
   'allow_admin_email_login' => (getenv('ALLOW_ADMIN_EMAIL_LOGIN') == 'n'),
-  'mailcow_apps_processed' => $mailcow_apps_processed,
+  'hide_mailcow_apps' => $hide_mailcow_apps,
   'mailcow_apps' => $MAILCOW_APPS,
   'mailcow_apps' => $MAILCOW_APPS,
-  'app_links' => customize('get', 'app_links'),
+  'mailcow_apps_processed' => $mailcow_apps_processed,
+  'app_links' => $app_links,
+  'app_links_processed' => $app_links_processed,
   'is_root_uri' => (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/'),
   'is_root_uri' => (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/'),
   'uri' => $_SERVER['REQUEST_URI'],
   'uri' => $_SERVER['REQUEST_URI'],
   'last_login' => last_login('get', $_SESSION['mailcow_cc_username'], 7, 0)['ui']['time']
   'last_login' => last_login('get', $_SESSION['mailcow_cc_username'], 7, 0)['ui']['time']

+ 3 - 1
data/web/inc/vars.inc.php

@@ -122,7 +122,9 @@ $SHOW_DKIM_PRIV_KEYS = false;
 $MAILCOW_APPS = array(
 $MAILCOW_APPS = array(
   array(
   array(
     'name' => 'Webmail',
     'name' => 'Webmail',
-    'link' => '/SOGo/',
+    'link' => '/SOGo/so/',
+    'user_link' => '/sogo-auth.php?login=%u',
+    'hide' => true
   )
   )
 );
 );
 
 

+ 14 - 0
data/web/js/site/admin.js

@@ -706,20 +706,34 @@ jQuery(function($){
     }
     }
   })
   })
   // App links
   // App links
+  // setup eventlistener
+  setAppHideEvent();
+  function setAppHideEvent(){ 
+    $('.app_hide').off('change');
+    $('.app_hide').on('change', function (e) {
+      var value = $(this).is(':checked') ? '1' : '0';
+      console.log(value)
+      $(this).parent().children(':first-child').val(value);
+    })
+  }
   function add_table_row(table_id, type) {
   function add_table_row(table_id, type) {
     var row = $('<tr />');
     var row = $('<tr />');
     if (type == "app_link") {
     if (type == "app_link") {
       cols = '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="app" required></td>';
       cols = '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="app" required></td>';
       cols += '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="href" required></td>';
       cols += '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="href" required></td>';
       cols += '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="user_href" required></td>';
       cols += '<td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="user_href" required></td>';
+      cols += '<td><div class="d-flex align-items-center justify-content-center" style="height: 33.5px"><input data-id="app_links" type="hidden" name="hide" value="0"><input class="form-check-input app_hide" type="checkbox" value="1"></div></td>';
       cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang.remove_row + '</a></td>';
       cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang.remove_row + '</a></td>';
     } else if (type == "f2b_regex") {
     } else if (type == "f2b_regex") {
       cols = '<td><input style="text-align:center" class="input-sm input-xs-lg form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
       cols = '<td><input style="text-align:center" class="input-sm input-xs-lg form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
       cols += '<td><input class="input-sm input-xs-lg form-control regex-input" data-id="f2b_regex" type="text" name="regex" required></td>';
       cols += '<td><input class="input-sm input-xs-lg form-control regex-input" data-id="f2b_regex" type="text" name="regex" required></td>';
       cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang.remove_row + '</a></td>';
       cols += '<td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">' + lang.remove_row + '</a></td>';
     }
     }
+
     row.append(cols);
     row.append(cols);
     table_id.append(row);
     table_id.append(row);
+    if (type == "app_link")
+      setAppHideEvent();
   }
   }
   $('#app_link_table').on('click', 'tr a', function (e) {
   $('#app_link_table').on('click', 'tr a', function (e) {
     e.preventDefault();
     e.preventDefault();

+ 12 - 0
data/web/templates/admin/tab-config-customize.twig

@@ -59,6 +59,7 @@
             <th>{{ lang.admin.app_name }}</th>
             <th>{{ lang.admin.app_name }}</th>
             <th>{{ lang.admin.link }}</th>
             <th>{{ lang.admin.link }}</th>
             <th>{{ lang.admin.user_link }}</th>
             <th>{{ lang.admin.user_link }}</th>
+            <th>{{ lang.admin.app_hide }}</th>
             <th style="width:100px;">&nbsp;</th>
             <th style="width:100px;">&nbsp;</th>
           </tr>
           </tr>
           {% for row in app_links %}
           {% for row in app_links %}
@@ -67,6 +68,12 @@
                 <td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="app" required value="{{ key }}"></td>
                 <td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="app" required value="{{ key }}"></td>
                 <td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="href" required value="{{ val.link }}"></td>
                 <td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="href" required value="{{ val.link }}"></td>
                 <td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="user_href" required value="{{ val.user_link }}"></td>
                 <td><input class="input-sm input-xs-lg form-control" data-id="app_links" type="text" name="user_href" required value="{{ val.user_link }}"></td>
+                <td>
+                  <div class="d-flex align-items-center justify-content-center" style="height: 33.5px">
+                    <input data-id="app_links" type="hidden" name="hide" {% if val.hide %}value="1"{% else %}value="0"{% endif %}>
+                    <input class="form-check-input app_hide" type="checkbox" value="1" {% if val.hide %}checked{% endif %}>
+                  </div>
+                </td>
                 <td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">{{ lang.admin.remove_row }}</a></td>
                 <td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100" type="button">{{ lang.admin.remove_row }}</a></td>
               </tr>
               </tr>
             {% endfor %}
             {% endfor %}
@@ -76,6 +83,11 @@
               <td><input class="input-sm input-xs-lg form-control" value="{{ app.name }}" disabled></td>
               <td><input class="input-sm input-xs-lg form-control" value="{{ app.name }}" disabled></td>
               <td><input class="input-sm input-xs-lg form-control" value="{{ app.link }}" disabled></td>
               <td><input class="input-sm input-xs-lg form-control" value="{{ app.link }}" disabled></td>
               <td><input class="input-sm input-xs-lg form-control" value="{{ app.user_link }}" disabled></td>
               <td><input class="input-sm input-xs-lg form-control" value="{{ app.user_link }}" disabled></td>
+              <td>
+                <div class="d-flex align-items-center justify-content-center" style="height: 33.5px">
+                  <input class="form-check-input" data-id="app_links" type="checkbox" name="hide" value="1" disabled {% if app.hide %}checked{% endif %}>
+                </div>
+              </td>
               <td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100 disabled" type="button">{{ lang.admin.remove_row }}</a></td>
               <td><a href="#" role="button" class="btn btn-sm btn-xs-lg btn-secondary h-100 w-100 disabled" type="button">{{ lang.admin.remove_row }}</a></td>
             </tr>
             </tr>
           {% endfor %}
           {% endfor %}

+ 9 - 3
data/web/templates/index.twig

@@ -67,19 +67,25 @@
         <p><div class="my-4 alert alert-info">{{ lang.login.delayed|format(login_delay) }}</b></div></p>
         <p><div class="my-4 alert alert-info">{{ lang.login.delayed|format(login_delay) }}</b></div></p>
         {% endif %}
         {% endif %}
         <div class="my-4" id="fido2-alerts"></div>
         <div class="my-4" id="fido2-alerts"></div>
-        {% if not oauth2_request and (mailcow_apps or app_links) %}
+        {% if not oauth2_request and (mailcow_apps or app_links) and not hide_mailcow_apps %}
         <legend><i class="bi bi-link-45deg"></i> {{ ui_texts.apps_name|raw }}</legend><hr />
         <legend><i class="bi bi-link-45deg"></i> {{ ui_texts.apps_name|raw }}</legend><hr />
         <div class="my-2 d-grid gap-2 d-sm-block apps">
         <div class="my-2 d-grid gap-2 d-sm-block apps">
           {% for app in mailcow_apps %}
           {% for app in mailcow_apps %}
-            {% if not skip_sogo or not is_uri('SOGo', app.link) %}
-              <a href="{{ app.link }}" role="button" {% if app.description %}title="{{ app.description }}"{% endif %} class="btn btn-primary">{{ app.name }}</a>
+            {% if not app.hide %}
+              {% if not skip_sogo or not is_uri('SOGo', app.link) %}
+              <div class="m-2">
+                <a href="{{ app.link }}" role="button" {% if app.description %}title="{{ app.description }}"{% endif %} class="btn btn-primary btn-block">{{ app.name }}</a>
+              </div>
             {% endif %}
             {% endif %}
+          {% endif %}
           {% endfor %}
           {% endfor %}
           {% for row in app_links %}
           {% for row in app_links %}
             {% for key, val in row %}
             {% for key, val in row %}
+            {% if not val.hide %}
               <div class="m-2">
               <div class="m-2">
                 <a href="{{ val.link }}" role="button" class="btn btn-primary btn-block">{{ key }}</a>
                 <a href="{{ val.link }}" role="button" class="btn btn-primary btn-block">{{ key }}</a>
               </div>
               </div>
+            {% endif %}
             {% endfor %}
             {% endfor %}
           {% endfor %}
           {% endfor %}
         </div>
         </div>