mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2024-12-04 10:24:42 +02:00
+ add api for presets
+ add yml-files for preset-definition
This commit is contained in:
parent
3453207301
commit
943b7c6bb2
46
data/web/inc/functions.presets.inc.php
Normal file
46
data/web/inc/functions.presets.inc.php
Normal 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 [];
|
||||
}
|
1186
data/web/inc/lib/Spyc.php
Normal file
1186
data/web/inc/lib/Spyc.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
|
7
data/web/inc/presets/rspamd/preset_1.yml
Normal file
7
data/web/inc/presets/rspamd/preset_1.yml
Normal 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"];
|
||||
}
|
5
data/web/inc/presets/rspamd/preset_2.yml
Normal file
5
data/web/inc/presets/rspamd/preset_2.yml
Normal file
@ -0,0 +1,5 @@
|
||||
headline: lang.rsettings_preset_2
|
||||
content: |
|
||||
priority = 10;
|
||||
rcpt = "/postmaster@.*/";
|
||||
want_spam = yes;
|
7
data/web/inc/presets/sieve/sieve_1.yml
Normal file
7
data/web/inc/presets/sieve/sieve_1.yml
Normal 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;
|
||||
}
|
7
data/web/inc/presets/sieve/sieve_2.yml
Normal file
7
data/web/inc/presets/sieve/sieve_2.yml
Normal file
@ -0,0 +1,7 @@
|
||||
headline: lang.sieve_preset_2
|
||||
content: |
|
||||
require ["envelope", "imap4flags"];
|
||||
if envelope "from" "mark@me-read.com"
|
||||
{
|
||||
setflag "\\seen";
|
||||
}
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user