Add better preset management (#3119)

* add rspamd-presets

* add sieveMailbox-presets

* adding new translations
master
tinect 2019-11-11 10:38:56 +01:00 committed by André Peters
parent 3243bf42cd
commit 79053742ca
9 changed files with 85 additions and 21 deletions

View File

@ -201,7 +201,7 @@ if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CAC
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Rspamd UI</h3>
@ -655,7 +655,7 @@ if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CAC
if (!empty($f2b_data['active_bans'])):
foreach ($f2b_data['active_bans'] as $active_bans):
?>
<p><span class="label label-info" style="padding:4px;font-size:85%;"><span class="glyphicon glyphicon-filter"></span> <?=$active_bans['network'];?> (<?=$active_bans['banned_until'];?>) -
<p><span class="label label-info" style="padding:4px;font-size:85%;"><span class="glyphicon glyphicon-filter"></span> <?=$active_bans['network'];?> (<?=$active_bans['banned_until'];?>) -
<?php
if ($active_bans['queued_for_unban'] == 0):
?>
@ -1136,7 +1136,7 @@ if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CAC
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane" id="tab-rspamdmaps">
<div class="panel panel-default">
<div class="panel-heading">
@ -1199,6 +1199,7 @@ echo "var log_pagination_size = '". $LOG_PAGINATION_SIZE . "';\n";
</script>
<?php
$js_minifier->add('/web/js/site/admin.js');
$js_minifier->add('/web/js/presets/rspamd.js');
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';
} else {
header('Location: /');

View File

@ -0,0 +1,32 @@
var rspamdPresets = [
{
description: lang.rsettings_preset_1,
codeValue: 'priority = 10;\nauthenticated = yes;\napply "default" {\n symbols_enabled = ["DKIM_SIGNED", "RATELIMITED", "RATELIMIT_UPDATE", "RATELIMIT_CHECK", "DYN_RL_CHECK", "HISTORY_SAVE", "MILTER_HEADERS", "ARC_SIGNED"];\n}'
},
{
description: lang.rsettings_preset_2,
codeValue: 'priority = 10;\nrcpt = "/postmaster@.*/";\nwant_spam = yes;'
}
];
var rspamd_presetsElem = document.getElementById("rspamd_presets");
if (rspamd_presetsElem && rspamdPresets) {
rspamd_presetsElem.innerHTML = '';
rspamdPresets.forEach(function (item, index) {
var elemID = 'rspamd_preset_' + index;
rspamd_presetsElem.innerHTML += '<li><a href="#" class="small" id="' + elemID + '">' + lang.rsettings_insert_preset.replace('%s', item.description) + '</a></li>';
/*
we need to define 0-timeout here, to prevent dom not be ready.
*/
setTimeout(function () {
document.getElementById(elemID).addEventListener('click', function (e) {
e.preventDefault();
document.querySelector('form[data-id=rsetting] #adminRspamdSettingsDesc').value = item.description;
document.querySelector('form[data-id=rsetting] #adminRspamdSettingsContent').value = item.codeValue;
return true;
});
}, 0)
});
}

View File

@ -0,0 +1,31 @@
var sieveMailboxPresets = [
{
description: lang.sieve_preset_1,
codeValue: 'if header :contains "x-attached"\n [".exe",".bat",".js",".com",".cmd",".ini",".dll",".bas",".cpl",".drv",".inf",".sys",".pif",".doc",".docx"] {\n discard;\n stop;\n}'
},
{
description: lang.sieve_preset_2,
codeValue: 'require ["envelope", "imap4flags"];\nif envelope "from" "mark@me-read.com"\n{\n setflag "\\\\seen";\n}'
}
];
var sieve_presetsElem = document.getElementById("sieve_presets");
if (sieve_presetsElem && sieveMailboxPresets) {
sieve_presetsElem.innerHTML = '';
sieveMailboxPresets.forEach(function (item, index) {
var elemID = 'sieve_preset_' + index;
sieve_presetsElem.innerHTML += '<li><a href="#" class="small" id="' + elemID + '">' + lang.insert_preset.replace('%s', item.description) + '</a></li>';
/*
we need to define 0-timeout here, to prevent dom not be ready.
*/
setTimeout(function () {
document.getElementById(elemID).addEventListener('click', function (e) {
e.preventDefault();
document.querySelector('form[data-id=add_filter] #script_desc').value = item.description;
document.querySelector('form[data-id=add_filter] #script_data').value = item.codeValue;
return true;
});
}, 0)
});
}

View File

@ -9,16 +9,6 @@ jQuery(function($){
function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
function hashCode(t){for(var n=0,r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return n}
function intToRGB(t){var n=(16777215&t).toString(16).toUpperCase();return"00000".substring(0,6-n.length)+n}
$("#rspamd_preset_1").on('click', function(e) {
e.preventDefault();
$("form[data-id=rsetting]").find("#adminRspamdSettingsDesc").val(lang.rsettings_preset_1);
$("form[data-id=rsetting]").find("#adminRspamdSettingsContent").val('priority = 10;\nauthenticated = yes;\napply "default" {\n symbols_enabled = ["DKIM_SIGNED", "RATELIMITED", "RATELIMIT_UPDATE", "RATELIMIT_CHECK", "DYN_RL_CHECK", "HISTORY_SAVE", "MILTER_HEADERS", "ARC_SIGNED"];\n}');
});
$("#rspamd_preset_2").on('click', function(e) {
e.preventDefault();
$("form[data-id=rsetting]").find("#adminRspamdSettingsDesc").val(lang.rsettings_preset_2);
$("form[data-id=rsetting]").find("#adminRspamdSettingsContent").val('priority = 10;\nrcpt = "/postmaster@.*/";\nwant_spam = yes;');
});
$("#dkim_missing_keys").on('click', function(e) {
e.preventDefault();
var domains = [];

View File

@ -310,7 +310,7 @@
"admin": {
"spamfilter": "Spamfilter",
"domain_s": "Domain(s)",
"rspamd-com_settings": "<a href=\"https://rspamd.com/doc/configuration/settings.html#settings-structure\" target=\"_blank\">Rspamd docs</a>\r\n - Ein Name wird automatisch generiert. Beispielinhalte zur Einsicht stehen nachstehend bereit.",
"rspamd-com_settings": "Ein Name wird automatisch generiert. Beispielinhalte zur Einsicht stehen nachstehend bereit. Siehe auch <a href=\"https://rspamd.com/doc/configuration/settings.html#settings-structure\" target=\"_blank\">Rspamd docs</a>",
"no_new_rows": "Keine weiteren Zeilen vorhanden",
"additional_rows": " zusätzliche Zeilen geladen",
"private_key": "Private Key",
@ -647,7 +647,11 @@
"alias_domain_backupmx": "Alias-Domain für Relay-Domain inaktiv",
"add_domain_record_first": "Bitte zuerst eine Domain hinzufügen",
"no": "&#10005;",
"yes": "&#10003;"
"yes": "&#10003;",
"insert_preset": "Beispiel \"%s\" laden",
"sieve_preset_header": "Beispielinhalte zur Einsicht stehen nachstehend bereit. Siehe auch <a href=\"https://de.wikipedia.org/wiki/Sieve\" target=\"_blank\">Wikipedia</a>.",
"sieve_preset_1": "E-Mails mit potenziell gefährlichen Dateitypen abweisen",
"sieve_preset_2": "E-Mail eines bestimmten Absenders immer als gelesen markieren"
},
"edit": {
"sogo_visible": "Alias in SOGo sichtbar",

View File

@ -311,7 +311,7 @@
"spamfilter": "Spam filter",
"domain": "Domain",
"domain_s": "Domain/s",
"rspamd-com_settings": "<a href=\"https://rspamd.com/doc/configuration/settings.html#settings-structure\" target=\"_blank\">Rspamd docs</a>\r\n - A setting name will be auto-generated, please see the example presets below.",
"rspamd-com_settings": "A setting name will be auto-generated, please see the example presets below. For more details see <a href=\"https://rspamd.com/doc/configuration/settings.html#settings-structure\" target=\"_blank\">Rspamd docs</a>",
"no_new_rows": "No further rows available",
"queue_manager": "Queue manager",
"additional_rows": " additional rows were added",
@ -646,7 +646,11 @@
"recipient_map_new": "New recipient",
"add_recipient_map_entry": "Add recipient map",
"mailbox_defquota": "Default mailbox size",
"alias_domain_backupmx": "Alias domain inactive for relay domain"
"alias_domain_backupmx": "Alias domain inactive for relay domain",
"insert_preset": "Insert example preset \"%s\"",
"sieve_preset_header": "Please see the example presets below. For more details see <a href=\"https://en.wikipedia.org/wiki/Sieve_(mail_filtering_language)\" target=\"_blank\">Wikipedia</a>.",
"sieve_preset_1": "Discard mail with probable dangerous file types",
"sieve_preset_2": "Always mark the e-mail of a specific sender as seen"
},
"edit": {
"sogo_visible": "Alias is visible in SOGo",

View File

@ -360,6 +360,7 @@ echo "var ALLOW_ADMIN_EMAIL_LOGIN = " . $ALLOW_ADMIN_EMAIL_LOGIN . ";\n";
</script>
<?php
$js_minifier->add('/web/js/site/mailbox.js');
$js_minifier->add('/web/js/presets/sieveMailbox.js');
$js_minifier->add('/web/js/site/pwgen.js');
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';
}

View File

@ -41,8 +41,7 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
</form>
<hr>
<p><?=$lang['admin']['rspamd-com_settings'];?></p>
<a href="#" class="small" id="rspamd_preset_1"><?=sprintf($lang['admin']['rsettings_insert_preset'], $lang['admin']['rsettings_preset_1']);?></a><br />
<a href="#" class="small" id="rspamd_preset_2"><?=sprintf($lang['admin']['rsettings_insert_preset'], $lang['admin']['rsettings_preset_2']);?></a>
<ul id="rspamd_presets"></ul>
</div>
</div>
</div>

View File

@ -397,7 +397,7 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
?>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="host1"><?=$lang['add']['hostname'];?></label>
<div class="col-sm-10">
@ -586,7 +586,7 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
<div class="form-group">
<label class="control-label col-sm-2" for="script_desc"><?=$lang['add']['sieve_desc'];?></label>
<div class="col-sm-10">
<input type="text" class="form-control" name="script_desc" required maxlength="255">
<input type="text" class="form-control" id="script_desc" name="script_desc" required maxlength="255">
</div>
</div>
<div class="form-group">
@ -610,6 +610,8 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
</div>
</div>
</form>
<?=$lang['mailbox']['sieve_preset_header']?>
<ul id="sieve_presets"></ul>
</div>
</div>
</div>