[Web] Small adjustments to presets

This commit is contained in:
andryyy
2019-12-15 22:04:22 +01:00
parent 9f754c95b9
commit 8003f3b4b3
10 changed files with 53 additions and 66 deletions

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',
];
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;