2019-11-15 03:23:58 +08:00
|
|
|
<?php
|
2019-11-15 05:07:49 +08:00
|
|
|
function presets($_action, $_kind, $_object)
|
2019-11-15 03:23:58 +08:00
|
|
|
{
|
|
|
|
if ($_SESSION['mailcow_cc_role'] !== 'admin') {
|
|
|
|
$_SESSION['return'][] = [
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => [__FUNCTION__, $_action, $_data_log],
|
|
|
|
'msg' => 'access_denied',
|
|
|
|
];
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
global $lang;
|
|
|
|
if ($_action === 'get') {
|
2019-11-15 05:07:49 +08:00
|
|
|
$kind = strtolower(trim($_kind));
|
2019-11-15 03:32:42 +08:00
|
|
|
$langSection = 'admin';
|
2019-11-15 05:07:49 +08:00
|
|
|
$presetsPath = __DIR__ . '/presets/' . $kind;
|
2019-11-15 03:32:42 +08:00
|
|
|
|
|
|
|
if (!in_array($kind, ['admin-rspamd', 'mailbox-sieve'], true)) {
|
2019-11-15 03:23:58 +08:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2019-11-15 03:32:42 +08:00
|
|
|
if ($kind === 'mailbox-sieve') {
|
|
|
|
$langSection = 'mailbox';
|
|
|
|
}
|
|
|
|
|
2019-11-15 05:07:49 +08:00
|
|
|
if ($_object !== 'all') {
|
|
|
|
return getPresetFromFilePath($presetsPath . '/' . $_object . '.yml', $langSection);
|
|
|
|
}
|
|
|
|
|
2019-11-15 03:23:58 +08:00
|
|
|
$presets = [];
|
2019-11-15 05:07:49 +08:00
|
|
|
foreach (glob($presetsPath . '/*.yml') as $filename) {
|
|
|
|
$presets[] = getPresetFromFilePath($filename, $langSection);
|
2019-11-15 03:23:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $presets;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2019-11-15 05:07:49 +08:00
|
|
|
|
|
|
|
function getPresetFromFilePath($filePath, $langSection)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $preset;
|
|
|
|
}
|