+ add api for presets

+ add yml-files for preset-definition
master
tinect 2019-11-14 20:23:58 +01:00
parent 3453207301
commit 943b7c6bb2
10 changed files with 1271 additions and 1 deletions

View File

@ -0,0 +1,46 @@
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/lib/Spyc.php';
function presets($_action, $_data = null)
{
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') {
$kind = strtolower(trim($_data));
if (!in_array($kind, ['rspamd', 'sieve'], true)) {
return [];
}
$presets = [];
foreach (glob(__DIR__ . '/presets/' . $kind . '/*.yml') as $filename) {
$preset = Spyc::YAMLLoad($filename);
/* get translated headlines */
if (isset($preset['headline']) && strpos($preset['headline'], 'lang.') === 0) {
$textName = trim(substr($preset['headline'], 5));
if ($kind === 'rspamd') {
$preset['headline'] = $lang['admin'][$textName];
} elseif ($kind === 'sieve') {
$preset['headline'] = $lang['mailbox'][$textName];
}
}
$presets[] = $preset;
}
return $presets;
}
return [];
}

File diff suppressed because it is too large Load Diff

View File

@ -223,6 +223,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.rspamd.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.tls_policy_maps.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.fail2ban.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.docker.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.presets.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/init_db.inc.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/triggers.inc.php';
init_db_schema();

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

@ -0,0 +1,5 @@
headline: lang.rsettings_preset_2
content: |
priority = 10;
rcpt = "/postmaster@.*/";
want_spam = yes;

View File

@ -0,0 +1,7 @@
headline: lang.sieve_preset_1
content: |
if header :contains "x-attached"
[".exe",".bat",".js",".com",".cmd",".ini",".dll",".bas",".cpl",".drv",".inf",".sys",".pif",".doc",".docx"] {
discard;
stop;
}

View File

@ -0,0 +1,7 @@
headline: lang.sieve_preset_2
content: |
require ["envelope", "imap4flags"];
if envelope "from" "mark@me-read.com"
{
setflag "\\seen";
}

View File

@ -8,6 +8,10 @@ var rspamdPresets = [
codeValue: 'priority = 10;\nrcpt = "/postmaster@.*/";\nwant_spam = yes;'
}
];
/*
TODO: aus API holen:
/api/v1/get/rspamd/sieve/
*/
var rspamd_presetsElem = document.getElementById("rspamd_presets");
if (rspamd_presetsElem && rspamdPresets) {

View File

@ -8,6 +8,10 @@ var sieveMailboxPresets = [
codeValue: 'require ["envelope", "imap4flags"];\nif envelope "from" "mark@me-read.com"\n{\n setflag "\\\\seen";\n}'
}
];
/*
TODO: aus API holen:
/api/v1/get/rspamd/sieve/
*/
var sieve_presetsElem = document.getElementById("sieve_presets");
if (sieve_presetsElem && sieveMailboxPresets) {

View File

@ -1071,6 +1071,9 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
break;
}
break;
case "presets":
process_get_return(presets('get', $object));
break;
// return no route found if no case is matched
default:
http_response_code(404);
@ -1302,7 +1305,7 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
break;
case "filter":
process_edit_return(mailbox('edit', 'filter', array_merge(array('id' => $items), $attr)));
break;
break;
case "resource":
process_edit_return(mailbox('edit', 'resource', array_merge(array('name' => $items), $attr)));
break;