get sieve and rspamd-filter from new api-point

master
tinect 2019-11-14 20:47:27 +01:00
parent 6ef61cdb8a
commit fd63fba467
2 changed files with 59 additions and 62 deletions

View File

@ -1,36 +1,34 @@
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;'
}
];
/*
TODO: aus API holen:
/api/v1/get/rspamd/sieve/
*/
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)
if (rspamd_presetsElem) {
$.ajax({
dataType: 'json',
url: '/api/v1/get/presets/admin-rspamd',
jsonp: false,
complete: function (data) {
if (data.responseText !== '{}') {
var rspamdPresets = JSON.parse(data.responseText);
if (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.headline) + '</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.headline;
document.querySelector('form[data-id=rsetting] #adminRspamdSettingsContent').value = item.content;
return true;
});
}, 0);
});
}
}
}
});
}

View File

@ -1,35 +1,34 @@
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}'
}
];
/*
TODO: aus API holen:
/api/v1/get/rspamd/sieve/
*/
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)
if (sieve_presetsElem) {
$.ajax({
dataType: 'json',
url: '/api/v1/get/presets/mailbox-sieve',
jsonp: false,
complete: function (data) {
if (data.responseText !== '{}') {
var sieveMailboxPresets = JSON.parse(data.responseText);
if (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.headline) + '</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.headline;
document.querySelector('form[data-id=add_filter] #script_data').value = item.content;
return true;
});
}, 0);
});
}
}
}
});
}