From 81775765d8c6ea6b4946f03d4ac9666697d854c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Sat, 21 Oct 2017 10:07:06 +0200 Subject: [PATCH] [Web] Customize app menu and logo; Fix #671 --- data/web/admin.php | 81 +++++++++- data/web/css/admin.css | 4 + data/web/css/mailcow.css | 9 ++ data/web/inc/footer.inc.php | 7 + data/web/inc/functions.customize.inc.php | 180 +++++++++++++++++++++++ data/web/inc/functions.mailbox.inc.php | 4 +- data/web/inc/header.inc.php | 10 +- data/web/inc/prerequisites.inc.php | 1 + data/web/inc/sessions.inc.php | 1 + data/web/inc/triggers.inc.php | 10 ++ data/web/index.php | 10 +- data/web/js/admin.js | 20 ++- data/web/js/api.js | 5 +- data/web/js/bootstrap-filestyle.min.js | 10 ++ data/web/json_api.php | 42 ++++++ data/web/lang/lang.de.php | 11 ++ data/web/lang/lang.en.php | 12 ++ 17 files changed, 407 insertions(+), 10 deletions(-) create mode 100644 data/web/inc/functions.customize.inc.php create mode 100644 data/web/js/bootstrap-filestyle.min.js diff --git a/data/web/admin.php b/data/web/admin.php index 6347cd7e..a2ec3d94 100644 --- a/data/web/admin.php +++ b/data/web/admin.php @@ -129,6 +129,7 @@ $tfa_data = get_tfa(); Relayhosts + @@ -260,9 +261,7 @@ $tfa_data = get_tfa();
- +
@@ -376,6 +375,82 @@ XYZ + + +
+
+
+ +

+
+

+ + +

+
+ +
+
+
+ mailcow logo +
+ x px + + +
+
+
+
+

+
+
+
+ + +

+
+ + + + + + + $val): + ?> + + + + + + + + + + + + + +
+ + +
+
+
+
diff --git a/data/web/css/admin.css b/data/web/css/admin.css index aa07d7a3..eb6b64f8 100644 --- a/data/web/css/admin.css +++ b/data/web/css/admin.css @@ -53,3 +53,7 @@ body.modal-open { top: 65px; z-index: 1; } +.thumbnail img { + min-height:100px; + height:100px; +} \ No newline at end of file diff --git a/data/web/css/mailcow.css b/data/web/css/mailcow.css index e3356ee7..955b05fb 100644 --- a/data/web/css/mailcow.css +++ b/data/web/css/mailcow.css @@ -101,4 +101,13 @@ legend { -ms-user-select: none -o-user-select: none; user-select: none; +} +.navbar .navbar-brand { + padding-top: 5px; +} +.navbar .navbar-brand img { + height: 40px; +} +.mailcow-logo img { + max-width: 250px; } \ No newline at end of file diff --git a/data/web/inc/footer.inc.php b/data/web/inc/footer.inc.php index 55a8f88d..8740612c 100644 --- a/data/web/inc/footer.inc.php +++ b/data/web/inc/footer.inc.php @@ -6,10 +6,14 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php'; + diff --git a/data/web/inc/functions.customize.inc.php b/data/web/inc/functions.customize.inc.php new file mode 100644 index 00000000..231bc898 --- /dev/null +++ b/data/web/inc/functions.customize.inc.php @@ -0,0 +1,180 @@ + 'danger', + 'msg' => sprintf($lang['danger']['access_denied']) + ); + return false; + } + switch ($_item) { + case 'main_logo': + if (in_array($_data['main_logo']['type'], array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/svg+xml'))) { + try { + if (file_exists($_data['main_logo']['tmp_name']) !== true) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Cannot validate image file: Temporary file not found' + ); + return false; + } + $image = new Imagick($_data['main_logo']['tmp_name']); + if ($image->valid() !== true) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Cannot validate image file' + ); + return false; + } + $image->destroy(); + } + catch (ImagickException $e) { + $image->destroy(); + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Cannot validate image file' + ); + return false; + } + } + else { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Invalid mime type' + ); + return false; + } + try { + $redis->Set('MAIN_LOGO', 'data:' . $_data['main_logo']['type'] . ';base64,' . base64_encode(file_get_contents($_data['main_logo']['tmp_name']))); + } + catch (RedisException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Redis: '.$e + ); + return false; + } + $_SESSION['return'] = array( + 'type' => 'success', + 'msg' => 'File uploaded successfully' + ); + break; + } + break; + case 'edit': + if ($_SESSION['mailcow_cc_role'] != "admin") { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => sprintf($lang['danger']['access_denied']) + ); + return false; + } + switch ($_item) { + case 'app_links': + $apps = (array)$_data['app']; + $links = (array)$_data['href']; + $out = array(); + if (count($apps) == count($links)) {; + for ($i = 0; $i < count($apps); $i++) { + $out[] = array($apps[$i] => $links[$i]); + } + try { + $redis->set('APP_LINKS', json_encode($out)); + } + catch (RedisException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Redis: '.$e + ); + return false; + } + } + $_SESSION['return'] = array( + 'type' => 'success', + 'msg' => 'Saved changes to app links' + ); + break; + } + break; + case 'delete': + if ($_SESSION['mailcow_cc_role'] != "admin") { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => sprintf($lang['danger']['access_denied']) + ); + return false; + } + switch ($_item) { + case 'main_logo': + try { + if ($redis->del('MAIN_LOGO')) { + $_SESSION['return'] = array( + 'type' => 'success', + 'msg' => 'Reset default logo' + ); + return true; + } + } + catch (RedisException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Redis: '.$e + ); + return false; + } + break; + } + break; + case 'get': + switch ($_item) { + case 'app_links': + try { + $app_links = json_decode($redis->get('APP_LINKS'), true); + } + catch (RedisException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Redis: '.$e + ); + return false; + } + return ($app_links) ? $app_links : false; + break; + case 'main_logo': + try { + return $redis->get('MAIN_LOGO'); + } + catch (RedisException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Redis: '.$e + ); + return false; + } + break; + case 'main_logo_specs': + try { + $image = new Imagick(); + $img_data = explode('base64,', customize('get', 'main_logo')); + if ($img_data[1]) { + $image->readImageBlob(base64_decode($img_data[1])); + } + return $image->identifyImage(); + } + catch (ImagickException $e) { + $_SESSION['return'] = array( + 'type' => 'danger', + 'msg' => 'Error: Imagick exception while reading image' + ); + return false; + } + break; + } + break; + } +} \ No newline at end of file diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 9deb6ef0..209b4acc 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -1291,11 +1291,11 @@ function mailbox($_action, $_type, $_data = null) { $port1 = (!empty($_data['port1'])) ? $_data['port1'] : $is_now['port1']; $password1 = (!empty($_data['password1'])) ? $_data['password1'] : $is_now['password1']; $host1 = (!empty($_data['host1'])) ? $_data['host1'] : $is_now['host1']; - $subfolder2 = (!empty($_data['subfolder2'])) ? $_data['subfolder2'] : ''; + $subfolder2 = (isset($_data['subfolder2'])) ? $_data['subfolder2'] : $is_now['subfolder2']; $enc1 = (!empty($_data['enc1'])) ? $_data['enc1'] : $is_now['enc1']; $mins_interval = (!empty($_data['mins_interval'])) ? $_data['mins_interval'] : $is_now['mins_interval']; $exclude = (!empty($_data['exclude'])) ? $_data['exclude'] : ''; - $maxage = (!empty($_data['maxage'])) ? $_data['maxage'] : $is_now['maxage']; + $maxage = (isset($_data['maxage']) && $_data['maxage'] != "") ? intval($_data['maxage']) : $is_now['maxage']; } else { $_SESSION['return'] = array( diff --git a/data/web/inc/header.inc.php b/data/web/inc/header.inc.php index ccccc616..b64bd5a8 100644 --- a/data/web/inc/header.inc.php +++ b/data/web/inc/header.inc.php @@ -39,7 +39,7 @@ - mailcow-logo + mailcow-logo