Skip to content

Commit

Permalink
[Web] add seperate link for logged in users
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddleSpl0it authored and DerLinkman committed Feb 8, 2024
1 parent cfce708 commit 415c1d0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 21 deletions.
25 changes: 22 additions & 3 deletions data/web/inc/functions.customize.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ function customize($_action, $_item, $_data = null) {
case 'app_links':
$apps = (array)$_data['app'];
$links = (array)$_data['href'];
$user_links = (array)$_data['user_href'];
$out = array();
if (count($apps) == count($links)) {
if (count($apps) == count($links) && count($apps) == count($user_links)) {
for ($i = 0; $i < count($apps); $i++) {
$out[] = array($apps[$i] => $links[$i]);
$out[] = array($apps[$i] => array(
'link' => $links[$i],
'user_link' => $user_links[$i]
));
}
try {
$redis->set('APP_LINKS', json_encode($out));
Expand Down Expand Up @@ -256,7 +260,22 @@ function customize($_action, $_item, $_data = null) {
);
return false;
}
return ($app_links) ? $app_links : false;

if (empty($app_links)){
return false;
}

foreach($app_links as $key => $value){
foreach($value as $app => $details){
if (empty($details['user_link']) || empty($_SESSION['mailcow_cc_username'])){
$app_links[$key][$app]['user_link'] = $app_links[$key][$app]['link'];
} else {
$app_links[$key][$app]['user_link'] = str_replace('%u', $_SESSION['mailcow_cc_username'], $app_links[$key][$app]['user_link']);
}
}
}

return $app_links;
break;
case 'main_logo':
case 'main_logo_dark':
Expand Down
9 changes: 9 additions & 0 deletions data/web/inc/header.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
cleanupCSS($hash);
}

$mailcow_apps_processed = $MAILCOW_APPS;
for ($i = 0; $i < count($mailcow_apps_processed); $i++) {
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']);
}
}


$globalVariables = [
'mailcow_hostname' => getenv('MAILCOW_HOSTNAME'),
'mailcow_locale' => @$_SESSION['mailcow_locale'],
Expand All @@ -45,6 +53,7 @@
'lang' => $lang,
'skip_sogo' => (getenv('SKIP_SOGO') == 'y'),
'allow_admin_email_login' => (getenv('ALLOW_ADMIN_EMAIL_LOGIN') == 'n'),
'mailcow_apps_processed' => $mailcow_apps_processed,
'mailcow_apps' => $MAILCOW_APPS,
'app_links' => customize('get', 'app_links'),
'is_root_uri' => (parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/'),
Expand Down
1 change: 1 addition & 0 deletions data/web/js/site/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ jQuery(function($){
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="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><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") {
cols = '<td><input style="text-align:center" class="input-sm input-xs-lg form-control" data-id="f2b_regex" type="text" value="+" disabled></td>';
Expand Down
5 changes: 4 additions & 1 deletion data/web/templates/admin/tab-config-customize.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@
<tr>
<th>{{ lang.admin.app_name }}</th>
<th>{{ lang.admin.link }}</th>
<th>{{ lang.admin.user_link }}</th>
<th style="width:100px;">&nbsp;</th>
</tr>
{% for row in app_links %}
{% for key, val in row %}
<tr>
<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 }}"></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><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>
{% endfor %}
Expand All @@ -73,6 +75,7 @@
<tr>
<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.user_link }}" disabled></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>
{% endfor %}
Expand Down
41 changes: 25 additions & 16 deletions data/web/templates/base.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<body>
<div class="overlay"></div>
{% block navbar %}
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-fixed-top p-0">
<nav class="navbar navbar-expand-lg navbar-light bg-light sticky-top p-0">
<div class="container-fluid">
<a class="navbar-brand" href="/">
<img class="main-logo" alt="mailcow-logo" src="{{ logo|default('/img/cow_mailcow.svg') }}">
Expand Down Expand Up @@ -60,49 +60,58 @@
</ul>
</li>
{% endif %}

{% if mailcow_cc_role %}
{% if mailcow_cc_role == 'admin' %}
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">{{ lang.header.mailcow_system }}</a>
<ul class="dropdown-menu">
{% if mailcow_cc_role == 'admin' %}
<li><a href="/debug" class="dropdown-item {% if is_uri('debug') %}active{% endif %}">{{ lang.header.debug }}</a></li>
<li><a href="/admin" class="dropdown-item {% if is_uri('admin') %}active{% endif %}">{{ lang.header.mailcow_config }}</a></li>
{% endif %}
{% if mailcow_cc_role != 'admin' %}
<li><a href="/user" class="dropdown-item {% if is_uri('user') %}active{% endif %}">{{ lang.header.user_settings }}</a></li>
{% endif %}
</ul>
</li>
{% endif %}
{% if mailcow_cc_role != 'admin' %}
<li class="nav-item dropdown">
<a href="/user" class="nav-link" role="button" aria-expanded="false">{{ lang.header.user_settings }}</a>
</li>
{% endif %}

{% if mailcow_cc_role == 'admin' or mailcow_cc_role == 'domainadmin' %}
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false">{{ lang.header.email }}</a>
<ul class="dropdown-menu">
{% if mailcow_cc_role == 'admin' or mailcow_cc_role == 'domainadmin' %}
<li><a href="/mailbox" class="dropdown-item {% if is_uri('mailbox') %}active{% endif %}">{{ lang.header.mailcow_config }}</a></li>
{% endif %}
<li><a href="/quarantine" class="dropdown-item {% if is_uri('quarantine') %}active{% endif %}">{{ lang.header.quarantine }}</a></li>
{% if mailcow_cc_role == 'admin' %}
<li><a href="/queue" class="dropdown-item {% if is_uri('queue') %}active{% endif %}">{{ lang.queue.queue_manager }}</a></li>
{% endif %}
{% if mailcow_cc_role == 'admin' %}
<li><a href="#" class="dropdown-item" data-bs-toggle="modal" data-container="sogo-mailcow" data-bs-target="#RestartContainer">{{ lang.header.restart_sogo }}</a></li>
{% endif %}
</ul>
</li>
{% endif %}
{% if mailcow_apps or app_links %}

{% if mailcow_cc_role == 'user' %}
<li class="nav-item dropdown">
<a href="/quarantine" class="nav-link">{{ lang.header.quarantine }}</a>
</li>
{% endif %}
{% endif %}

{% if mailcow_apps_processed or app_links %}
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false"><i class="bi bi-link-45deg me-2"></i> {{ ui_texts.apps_name|raw }}</a>
<ul class="dropdown-menu">
{% for app in mailcow_apps %}
{% if not skip_sogo or not is_uri('SOGo', app.link) %}
{% for app in mailcow_apps_processed %}
{% if not skip_sogo or not is_uri('SOGo', app.user_link) %}
<li {% if app.description %}title="{{ app.description }}"{% endif %}>
<a href="{{ app.link }}" class="dropdown-item">{{ app.name }}</a>
<a href="{{ app.user_link }}" class="dropdown-item">{{ app.name }}</a>
</li>
{% endif %}
{% endfor %}
{% for row in app_links %}
{% for key, val in row %}
<li><a href="{{ val }}" class="dropdown-item">{{ key }}</a></li>
<li><a href="{{ val.user_link }}" class="dropdown-item">{{ key }}</a></li>
{% endfor %}
{% endfor %}
</ul>
Expand Down Expand Up @@ -132,7 +141,7 @@
</div>
{% endif %}

<div class="container my-4">
<div class="container flex-grow-1 my-4">
{% block content %}{% endblock %}
</div>

Expand Down
4 changes: 3 additions & 1 deletion data/web/templates/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
{% endfor %}
{% for row in app_links %}
{% for key, val in row %}
<a href="{{ val }}" role="button" class="btn btn-primary">{{ key }}</a>
<div class="m-2">
<a href="{{ val.link }}" role="button" class="btn btn-primary btn-block">{{ key }}</a>
</div>
{% endfor %}
{% endfor %}
</div>
Expand Down

0 comments on commit 415c1d0

Please sign in to comment.