[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 <?php
function presets($_action, $_kind, $_object) function presets($_action, $_kind) {
{
if ($_SESSION['mailcow_cc_role'] !== 'admin') {
$_SESSION['return'][] = [
'type' => 'danger',
'log' => [__FUNCTION__, $_action, $_data_log],
'msg' => 'access_denied',
];
return false;
}
global $lang; global $lang;
if ($_action === 'get') { switch ($_action) {
$kind = strtolower(trim($_kind)); case 'get':
$langSection = 'admin'; if ($_SESSION['mailcow_cc_role'] != "admin") {
$presetsPath = __DIR__ . '/presets/' . $kind; return false;
}
if (!in_array($kind, ['admin-rspamd', 'mailbox-sieve'], true)) { $presets = array();
return []; $kind = strtolower(trim($_kind));
} $lang_base = 'admin';
$presets_path = __DIR__ . '/presets/' . $kind;
if ($kind === 'mailbox-sieve') { if (!in_array($kind, ['rspamd', 'sieve'], true)) {
$langSection = 'mailbox'; return array();
} }
if ($kind === 'sieve') {
if ($_object !== 'all') { $lang_base = 'mailbox';
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) { return $presets;
$presets[] = getPresetFromFilePath($filename, $langSection); break;
}
return $presets;
} }
return array();
return [];
} }
function getPresetFromFilePath($filePath, $lang_base) {
function getPresetFromFilePath($filePath, $langSection)
{
global $lang; global $lang;
$preset = Spyc::YAMLLoad($filePath); $preset = Spyc::YAMLLoad($filePath);
$preset = ['name' => basename($filePath, '.yml')] + $preset; $preset = ['name' => basename($filePath, '.yml')] + $preset;
/* get translated headlines */ /* get translated headlines */
if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) { if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
$langTextName = trim(substr($preset['headline'], 5)); $langTextName = trim(substr($preset['headline'], 5));
if (isset($lang[$langSection][$langTextName])) { if (isset($lang[$lang_base][$langTextName])) {
$preset['headline'] = $lang[$langSection][$langTextName]; $preset['headline'] = $lang[$lang_base][$langTextName];
} }
} }
return $preset; 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) { if (rspamd_presetsElem) {
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/get/presets-admin-rspamd/all', url: '/api/v1/get/presets/rspamd',
jsonp: false, jsonp: false,
complete: function (data) { complete: function (data) {
if (data.responseText !== '{}') { if (data.responseText !== '{}') {

View File

@ -3,7 +3,7 @@ var sieve_presetsElem = document.getElementById("sieve_presets");
if (sieve_presetsElem) { if (sieve_presetsElem) {
$.ajax({ $.ajax({
dataType: 'json', dataType: 'json',
url: '/api/v1/get/presets-mailbox-sieve/all', url: '/api/v1/get/presets/sieve',
jsonp: false, jsonp: false,
complete: function (data) { complete: function (data) {
if (data.responseText !== '{}') { if (data.responseText !== '{}') {

View File

@ -1071,21 +1071,25 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
break; break;
} }
break; break;
case "presets-admin-rspamd": case "presets":
process_get_return(presets('get', 'admin-rspamd', $object)); switch ($object) {
break; case "rspamd":
case "presets-mailbox-sieve": process_get_return(presets('get', 'rspamd'));
process_get_return(presets('get', 'mailbox-sieve', $object)); case "sieve":
break; break;
process_get_return(presets('get', 'sieve'));
break;
}
break; break;
// return no route found if no case is matched break;
default: // return no route found if no case is matched
http_response_code(404); default:
echo json_encode(array( http_response_code(404);
'type' => 'error', echo json_encode(array(
'msg' => 'route not found' 'type' => 'error',
)); 'msg' => 'route not found'
exit(); ));
exit();
} }
break; break;
case "delete": case "delete":