diff --git a/data/web/css/build/0081-custom-mailcow.css b/data/web/css/build/0081-custom-mailcow.css new file mode 100644 index 00000000..02bcadeb --- /dev/null +++ b/data/web/css/build/0081-custom-mailcow.css @@ -0,0 +1 @@ +/* Autogenerated by mailcow */ diff --git a/data/web/inc/functions.presets.inc.php b/data/web/inc/functions.presets.inc.php index c0e472a7..b85c3e03 100644 --- a/data/web/inc/functions.presets.inc.php +++ b/data/web/inc/functions.presets.inc.php @@ -1,56 +1,38 @@ 'danger', - 'log' => [__FUNCTION__, $_action, $_data_log], - 'msg' => 'access_denied', - ]; - - return false; - } - +function presets($_action, $_kind) { global $lang; - if ($_action === 'get') { - $kind = strtolower(trim($_kind)); - $langSection = 'admin'; - $presetsPath = __DIR__ . '/presets/' . $kind; - - if (!in_array($kind, ['admin-rspamd', 'mailbox-sieve'], true)) { - return []; - } - - if ($kind === 'mailbox-sieve') { - $langSection = 'mailbox'; - } - - if ($_object !== 'all') { - return getPresetFromFilePath($presetsPath . '/' . $_object . '.yml', $langSection); - } - - $presets = []; - foreach (glob($presetsPath . '/*.yml') as $filename) { - $presets[] = getPresetFromFilePath($filename, $langSection); - } - - return $presets; + switch ($_action) { + case 'get': + if ($_SESSION['mailcow_cc_role'] != "admin") { + return false; + } + $presets = array(); + $kind = strtolower(trim($_kind)); + $lang_base = 'admin'; + $presets_path = __DIR__ . '/presets/' . $kind; + if (!in_array($kind, ['rspamd', 'sieve'], true)) { + return array(); + } + if ($kind === 'sieve') { + $lang_base = 'mailbox'; + } + foreach (glob($presets_path . '/*.yml') as $filename) { + $presets[] = getPresetFromFilePath($filename, $lang_base); + } + return $presets; + break; } - - return []; + return array(); } - -function getPresetFromFilePath($filePath, $langSection) -{ +function getPresetFromFilePath($filePath, $lang_base) { 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]; + if (isset($lang[$lang_base][$langTextName])) { + $preset['headline'] = $lang[$lang_base][$langTextName]; } } return $preset; diff --git a/data/web/inc/presets/admin-rspamd/preset_1.yml b/data/web/inc/presets/admin-rspamd/preset_1.yml deleted file mode 100644 index f36b0547..00000000 --- a/data/web/inc/presets/admin-rspamd/preset_1.yml +++ /dev/null @@ -1,7 +0,0 @@ -headline: lang.rsettings_preset_1 -content: | - priority = 10; - authenticated = yes; - apply "default" { - symbols_enabled = ["DKIM_SIGNED", "RATELIMITED", "RATELIMIT_UPDATE", "RATELIMIT_CHECK", "DYN_RL_CHECK", "HISTORY_SAVE", "MILTER_HEADERS", "ARC_SIGNED"]; - } diff --git a/data/web/inc/presets/rspamd/preset_1.yml b/data/web/inc/presets/rspamd/preset_1.yml new file mode 100644 index 00000000..acbe352a --- /dev/null +++ b/data/web/inc/presets/rspamd/preset_1.yml @@ -0,0 +1,7 @@ +headline: lang.rsettings_preset_1 +content: | + priority = 10; + authenticated = yes; + apply "default" { + symbols_enabled = ["DKIM_SIGNED", "RATELIMITED", "RATELIMIT_UPDATE", "RATELIMIT_CHECK", "DYN_RL_CHECK", "HISTORY_SAVE", "MILTER_HEADERS", "ARC_SIGNED"]; + } diff --git a/data/web/inc/presets/admin-rspamd/preset_2.yml b/data/web/inc/presets/rspamd/preset_2.yml similarity index 100% rename from data/web/inc/presets/admin-rspamd/preset_2.yml rename to data/web/inc/presets/rspamd/preset_2.yml diff --git a/data/web/inc/presets/mailbox-sieve/sieve_1.yml b/data/web/inc/presets/sieve/sieve_1.yml similarity index 100% rename from data/web/inc/presets/mailbox-sieve/sieve_1.yml rename to data/web/inc/presets/sieve/sieve_1.yml diff --git a/data/web/inc/presets/mailbox-sieve/sieve_2.yml b/data/web/inc/presets/sieve/sieve_2.yml similarity index 100% rename from data/web/inc/presets/mailbox-sieve/sieve_2.yml rename to data/web/inc/presets/sieve/sieve_2.yml diff --git a/data/web/js/presets/rspamd.js b/data/web/js/presets/rspamd.js index 6981418c..f6d7ad3c 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/all', + url: '/api/v1/get/presets/rspamd', 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 5ba9fb32..5b15de06 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/all', + url: '/api/v1/get/presets/sieve', jsonp: false, complete: function (data) { if (data.responseText !== '{}') { diff --git a/data/web/json_api.php b/data/web/json_api.php index dcaf7f0d..82409d81 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -1071,21 +1071,25 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u break; } break; - 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; + case "presets": + switch ($object) { + case "rspamd": + process_get_return(presets('get', 'rspamd')); + case "sieve": + break; + process_get_return(presets('get', 'sieve')); + break; + } break; - // return no route found if no case is matched - default: - http_response_code(404); - echo json_encode(array( - 'type' => 'error', - 'msg' => 'route not found' - )); - exit(); + break; + // return no route found if no case is matched + default: + http_response_code(404); + echo json_encode(array( + 'type' => 'error', + 'msg' => 'route not found' + )); + exit(); } break; case "delete":