2019-11-14 21:23:58 +02:00
|
|
|
<?php
|
2019-12-15 23:04:22 +02:00
|
|
|
function presets($_action, $_kind) {
|
2019-11-14 21:23:58 +02:00
|
|
|
global $lang;
|
2019-12-15 23:04:22 +02:00
|
|
|
switch ($_action) {
|
|
|
|
case 'get':
|
2020-03-19 13:46:39 +02:00
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin" && $_SESSION['mailcow_cc_role'] != "domainadmin") {
|
2019-12-15 23:04:22 +02:00
|
|
|
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;
|
2019-11-14 21:23:58 +02:00
|
|
|
}
|
2019-12-15 23:04:22 +02:00
|
|
|
return array();
|
2019-11-14 21:23:58 +02:00
|
|
|
}
|
2019-12-15 23:04:22 +02:00
|
|
|
function getPresetFromFilePath($filePath, $lang_base) {
|
2019-11-14 23:07:49 +02:00
|
|
|
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));
|
2019-12-15 23:04:22 +02:00
|
|
|
if (isset($lang[$lang_base][$langTextName])) {
|
|
|
|
$preset['headline'] = $lang[$lang_base][$langTextName];
|
2019-11-14 23:07:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $preset;
|
|
|
|
}
|