public
nobgit
read
NobMail
Based on mailcow: dockerized
Languages
Repository composition by tracked source files.
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
add ability to get specific preset, defaulting to all
9f754c95
data/web/inc/functions.presets.inc.php | 39 ++++++++++++++++++++++------------
data/web/js/presets/rspamd.js | 2 +-
data/web/js/presets/sieveMailbox.js | 2 +-
data/web/json_api.php | 8 +++++--
4 files changed, 33 insertions(+), 18 deletions(-)
Diff
diff --git a/data/web/inc/functions.presets.inc.php b/data/web/inc/functions.presets.inc.php
index 115f3d76..c0e472a7 100644
--- a/data/web/inc/functions.presets.inc.php
+++ b/data/web/inc/functions.presets.inc.php
@@ -1,5 +1,5 @@
<?php
-function presets($_action, $_data = null)
+function presets($_action, $_kind, $_object)
{
if ($_SESSION['mailcow_cc_role'] !== 'admin') {
$_SESSION['return'][] = [
@@ -13,8 +13,9 @@ function presets($_action, $_data = null)
global $lang;
if ($_action === 'get') {
- $kind = strtolower(trim($_data));
+ $kind = strtolower(trim($_kind));
$langSection = 'admin';
+ $presetsPath = __DIR__ . '/presets/' . $kind;
if (!in_array($kind, ['admin-rspamd', 'mailbox-sieve'], true)) {
return [];
@@ -24,19 +25,13 @@ function presets($_action, $_data = null)
$langSection = 'mailbox';
}
+ if ($_object !== 'all') {
+ return getPresetFromFilePath($presetsPath . '/' . $_object . '.yml', $langSection);
+ }
+
$presets = [];
- foreach (glob(__DIR__ . '/presets/' . $kind . '/*.yml') as $filename) {
- $preset = Spyc::YAMLLoad($filename);
-
- /* get translated headlines */
- if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
- $langTextName = trim(substr($preset['headline'], 5));
- if (isset($lang[$langSection][$langTextName])) {
- $preset['headline'] = $lang[$langSection][$langTextName];
- }
- }
-
- $presets[] = $preset;
+ foreach (glob($presetsPath . '/*.yml') as $filename) {
+ $presets[] = getPresetFromFilePath($filename, $langSection);
}
return $presets;
@@ -44,3 +39,19 @@ function presets($_action, $_data = null)
return [];
}
+
+function getPresetFromFilePath($filePath, $langSection)
+{
+ global $lang;
+ $preset = Spyc::YAMLLoad($filePath);
+ $preset = ['name' => basename($filePath, '.yml')] + $preset;
+
+ /* get translated headlines */
+ if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
+ $langTextName = trim(substr($preset['headline'], 5));
+ if (isset($lang[$langSection][$langTextName])) {
+ $preset['headline'] = $lang[$langSection][$langTextName];
+ }
+ }
+ return $preset;
+}
diff --git a/data/web/js/presets/rspamd.js b/data/web/js/presets/rspamd.js
index c16114d0..6981418c 100644
--- a/data/web/js/presets/rspamd.js
+++ b/data/web/js/presets/rspamd.js
@@ -3,7 +3,7 @@ var rspamd_presetsElem = document.getElementById("rspamd_presets");
if (rspamd_presetsElem) {
$.ajax({
dataType: 'json',
- url: '/api/v1/get/presets/admin-rspamd',
+ url: '/api/v1/get/presets-admin-rspamd/all',
jsonp: false,
complete: function (data) {
if (data.responseText !== '{}') {
diff --git a/data/web/js/presets/sieveMailbox.js b/data/web/js/presets/sieveMailbox.js
index 05eaa2c5..5ba9fb32 100644
--- a/data/web/js/presets/sieveMailbox.js
+++ b/data/web/js/presets/sieveMailbox.js
@@ -3,7 +3,7 @@ var sieve_presetsElem = document.getElementById("sieve_presets");
if (sieve_presetsElem) {
$.ajax({
dataType: 'json',
- url: '/api/v1/get/presets/mailbox-sieve',
+ url: '/api/v1/get/presets-mailbox-sieve/all',
jsonp: false,
complete: function (data) {
if (data.responseText !== '{}') {
diff --git a/data/web/json_api.php b/data/web/json_api.php
index bb534b79..dcaf7f0d 100644
--- a/data/web/json_api.php
+++ b/data/web/json_api.php
@@ -1071,8 +1071,12 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
break;
}
break;
- case "presets":
- process_get_return(presets('get', $object));
+ case "presets-admin-rspamd":
+ process_get_return(presets('get', 'admin-rspamd', $object));
+ break;
+ case "presets-mailbox-sieve":
+ process_get_return(presets('get', 'mailbox-sieve', $object));
+ break;
break;
// return no route found if no case is matched
default: