[Web] Small adjustments to presets

master
andryyy 2019-12-15 22:04:22 +01:00
parent 9f754c95b9
commit 8003f3b4b3
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
10 changed files with 53 additions and 66 deletions

View File

@ -0,0 +1 @@
/* Autogenerated by mailcow */

View File

@ -1,56 +1,38 @@
<?php
function presets($_action, $_kind, $_object)
{
if ($_SESSION['mailcow_cc_role'] !== 'admin') {
$_SESSION['return'][] = [
'type' => 'danger',
'log' => [__FUNCTION__, $_action, $_data_log],
'msg' => 'access_denied',
];
function presets($_action, $_kind) {
global $lang;
switch ($_action) {
case 'get':
if ($_SESSION['mailcow_cc_role'] != "admin") {
return false;
}
global $lang;
if ($_action === 'get') {
$presets = array();
$kind = strtolower(trim($_kind));
$langSection = 'admin';
$presetsPath = __DIR__ . '/presets/' . $kind;
if (!in_array($kind, ['admin-rspamd', 'mailbox-sieve'], true)) {
return [];
$lang_base = 'admin';
$presets_path = __DIR__ . '/presets/' . $kind;
if (!in_array($kind, ['rspamd', 'sieve'], true)) {
return array();
}
if ($kind === 'mailbox-sieve') {
$langSection = 'mailbox';
if ($kind === 'sieve') {
$lang_base = 'mailbox';
}
if ($_object !== 'all') {
return getPresetFromFilePath($presetsPath . '/' . $_object . '.yml', $langSection);
foreach (glob($presets_path . '/*.yml') as $filename) {
$presets[] = getPresetFromFilePath($filename, $lang_base);
}
$presets = [];
foreach (glob($presetsPath . '/*.yml') as $filename) {
$presets[] = getPresetFromFilePath($filename, $langSection);
}
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;

View File

@ -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"];
}

View File

@ -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"];
}

View File

@ -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 !== '{}') {

View File

@ -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 !== '{}') {

View File

@ -1071,11 +1071,15 @@ 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));
case "presets":
switch ($object) {
case "rspamd":
process_get_return(presets('get', 'rspamd'));
case "sieve":
break;
case "presets-mailbox-sieve":
process_get_return(presets('get', 'mailbox-sieve', $object));
process_get_return(presets('get', 'sieve'));
break;
}
break;
break;
// return no route found if no case is matched