Enable/disable rbl,sbl,uribl setting according to db property

This commit is contained in:
Brian Read 2025-04-10 09:02:57 +01:00
parent b513dfc9be
commit 89475c0aa3
2 changed files with 137 additions and 45 deletions

View File

@ -5,53 +5,71 @@ $(document).ready(function() {
}); });
// Initialize multiselect with existing text values // Initialize multiselect with existing text values
function initMultiselect() { // Initialize multiselect based on text input values
const multiselect = document.getElementById('CountrySelect_select'); function initMultiselect(multiselectId, textInputId) {
const textInput = document.getElementById('AccumCountryCodes_text'); const multiselect = document.getElementById(multiselectId);
const textInput = document.getElementById(textInputId);
// Split text input values and select corresponding options if (!multiselect || !textInput) {
console.error('Could not find elements with provided IDs');
return;
}
textInput.value.split(',').forEach(value => { textInput.value.split(',').forEach(value => {
const option = Array.from(multiselect.options).find(opt => opt.value === value.trim()); const option = Array.from(multiselect.options)
.find(opt => opt.value === value.trim());
if (option) option.selected = true; if (option) option.selected = true;
}); });
} }
// Update text input when multiselect changes // Update text input when multiselect changes
function updateTextInput() { function updateTextInput(multiselectId, textInputId) {
const multiselect = document.getElementById('CountrySelect_select'); const multiselect = document.getElementById(multiselectId);
const textInput = document.getElementById('AccumCountryCodes_text'); const textInput = document.getElementById(textInputId);
// Get selected values from the multiselect as an array if (!multiselect || !textInput) {
const selectedValues = Array.from(multiselect.selectedOptions).map(option => option.value); console.error('Could not find elements with provided IDs');
return;
}
const selectedValues = Array.from(multiselect.selectedOptions)
.map(option => option.value);
// Split the current value of the text input into an array of codes const currentValues = textInput.value.split(',')
const currentValues = textInput.value.split(',').map(code => code.trim()).filter(code => code !== ''); .map(code => code.trim())
.filter(code => code !== '');
// Create a new set to manage the codes
const updatedValuesSet = new Set(currentValues); const updatedValuesSet = new Set(currentValues);
// Add selected values to the set
selectedValues.forEach(value => updatedValuesSet.add(value)); selectedValues.forEach(value => updatedValuesSet.add(value));
// Remove values from the set that are no longer selected but were added via the multiselect
currentValues.forEach(code => { currentValues.forEach(code => {
if (!selectedValues.includes(code) && multiselect.querySelector(`option[value="${code}"]`)) { if (!selectedValues.includes(code) &&
multiselect.querySelector(`option[value="${code}"]`)) {
updatedValuesSet.delete(code); updatedValuesSet.delete(code);
} }
}); });
// Update the text input with the updated values, preserving manually added codes
textInput.value = Array.from(updatedValuesSet).join(','); textInput.value = Array.from(updatedValuesSet).join(',');
} }
// Initialize on page load // Initialize on page load
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
initMultiselect(); initMultiselect('CountrySelect_select','AccumCountryCodes_text');
initMultiselect('RBLList_select','RBLList_text');
initMultiselect('SBLList_select','SBLList_text');
initMultiselect('URIBLList_select','URIBLList_text');
// Add change listener to multiselect // Add change listener to multiselect
document.getElementById('CountrySelect_select') document.getElementById('CountrySelect_select')
.addEventListener('click', updateTextInput); .addEventListener('click', () => updateTextInput('CountrySelect_select','AccumCountryCodes_text'));
document.getElementById('RBLList_select')
.addEventListener('click', () => updateTextInput('RBLList_select','RBLList_text'));
document.getElementById('SBLList_select')
.addEventListener('click', () => updateTextInput('SBLList_select','SBLList_text'));
document.getElementById('URIBLList_select')
.addEventListener('click', () => updateTextInput('URIBLList_select','URIBLList_text'));
}); });
/** /**
@ -159,4 +177,48 @@ function getYesterdayDate() {
const day = String(yesterday.getDate()).padStart(2, '0'); const day = String(yesterday.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`; return `${year}-${month}-${day}`;
}
//
// disable enable RBL/SBL/URIBL list selection
//
// Example html formatting to use it.
//<div data-mailstats-group>
//<select id="EnableRHSBL_select" data-mailstats-control data-mailstats-target="RBL_group">
//<option value="disabled">Disabled</option>
//<option value="enabled">Enabled</option>
//</select>
//<div id="RBL_group">
//<!-- Content -->
//</div>
//</div>
// or , 'data-mailstats-control' => undef, 'data-mailstats-target' => "RBL_group" for mojo html helper
//
document.addEventListener('DOMContentLoaded', () => {
// Initialize all control pairs
document.querySelectorAll('[data-mailstats-group]').forEach(group => {
const select = group.querySelector('select[data-mailstats-control]');
const target = document.getElementById(select.dataset.mailstatsTarget);
if (!select || !target) {
console.error('Control group misconfigured', group);
return;
}
// Initial state
updateState(target, select.value === 'enabled');
// Change listener
select.addEventListener('change', () =>
updateState(target, select.value === 'enabled')
);
});
});
function updateState(target, enabled) {
target.style.opacity = enabled ? '1' : '0.5';
target.style.pointerEvents = enabled ? 'auto' : 'none';
target.style.filter = enabled ? 'none' : 'grayscale(50%)';
target.setAttribute('aria-disabled', !enabled);
} }

View File

@ -2,11 +2,6 @@
%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-05 11:17:38 %# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-05 11:17:38
%# %#
<div id="Mailstats-CONFIG" class="partial Mailstats-CONFIG"> <div id="Mailstats-CONFIG" class="partial Mailstats-CONFIG">
<script>
window.onload = function() {
SelectInput();
};
</script>
% if (config->{debug} == 1) { % if (config->{debug} == 1) {
<pre> <pre>
%= dumper $mst_data %= dumper $mst_data
@ -134,51 +129,86 @@
% param 'AccumCountryCodes' => $mst_data->{AccumCountryCodes} unless param 'AccumCountryCodes'; % param 'AccumCountryCodes' => $mst_data->{AccumCountryCodes} unless param 'AccumCountryCodes';
%= text_field 'AccumCountryCodes', size => '50', class => 'textinput AccumCountryCodes' , pattern=>'.*' , placeholder=>'AccumCountryCodes', title =>'Pattern regex mismatch', id => 'AccumCountryCodes_text' %= text_field 'AccumCountryCodes', size => '50', class => 'textinput AccumCountryCodes' , pattern=>'.*' , placeholder=>'AccumCountryCodes', title =>'Pattern regex mismatch', id => 'AccumCountryCodes_text'
<br></span></p> <br></span></p>
<div data-mailstats-group>
<p><span class=label> <p><span class=label>
%=l('mst_Enable_RHSBL_checking') %=l('mst_Enable_RHSBL_checking')
</span><span class=data> </span><span class=data>
% my @EnableRHSBL_options = [['yes' => 'enabled'], ['no' => 'disabled']]; % my @EnableRHSBL_options = [['yes' => 'enabled'], ['no' => 'disabled']];
% param 'EnableRHSBL' => $mst_data->{EnableRHSBL} unless param 'EnableRHSBL'; % param 'EnableRHSBL' => $mst_data->{EnableRHSBL} unless param 'EnableRHSBL';
%= select_field 'EnableRHSBL' => @EnableRHSBL_options, class => 'input', id => 'EnableRHSBL_select' %= select_field 'EnableRHSBL' => @EnableRHSBL_options, class => 'input', id => 'EnableRHSBL_select', 'data-mailstats-control' => undef, 'data-mailstats-target' => "RBL_group"
<br></span> </p> <br></span> </p>
<div id=RBL_group>
<p><span class=label>
%=l('mst_Select_the_RBL_Lists')
</span><span class=data>
% my @RBLSelect_options = $c->get_RBL_lists();
% param 'RBLSelect' => $mst_data->{RBLSelect} unless param 'RBLSelect';
%= select_field 'RBLSelect' => @RBLSelect_options, class => 'input', id => 'RBLList_select', multiple => 'multiple'
<br></span> </p>
<p><span class=label>
%=l('mst_RBL_Servers_to_use')
</span><span class=data>
% param 'RBLList' => $mst_data->{RBLList} unless param 'RBLList';
%= text_field 'RBLList', size => '50', class => 'textinput RBLList' , pattern=>'.*' , placeholder=>'RBLList', title =>'Pattern regex mismatch', id => 'RBLList_text'
<br></span></p>
</div>
</div>
<div data-mailstats-group>
<p><span class=label> <p><span class=label>
%=l('mst_Enable_DNSBL_checking') %=l('mst_Enable_DNSBL_checking')
</span><span class=data> </span><span class=data>
% my @EnableDNSBL_options = [['yes' => 'enabled'], ['no' => 'disabled']]; % my @EnableDNSBL_options = [['yes' => 'enabled'], ['no' => 'disabled']];
% param 'EnableDNSBL' => $mst_data->{EnableDNSBL} unless param 'EnableDNSBL'; % param 'EnableDNSBL' => $mst_data->{EnableDNSBL} unless param 'EnableDNSBL';
%= select_field 'EnableDNSBL' => @EnableDNSBL_options, class => 'input', id => 'EnableDNSBL_select' %= select_field 'EnableDNSBL' => @EnableDNSBL_options, class => 'input', id => 'EnableDNSBL_select' , 'data-mailstats-control' => undef, 'data-mailstats-target' => "SBL_group"
<br></span> </p> <br></span> </p>
<div id=SBL_group>
<p><span class=label>
%=l('mst_Select_the_SBL_Lists')
</span><span class=data>
% my @SBLSelect_options = $c->get_SBL_lists();
% param 'SBLSelect' => $mst_data->{SBLSelect} unless param 'SBLSelect';
%= select_field 'SBLSelect' => @SBLSelect_options, class => 'input', id => 'SBLList_select', multiple => 'multiple'
<br></span> </p>
<p><span class=label>
%=l('mst_SBL_Servers_to_use')
</span><span class=data>
% param 'SBLList' => $mst_data->{SBLList} unless param 'SBLList';
%= text_field 'SBLList', size => '50', class => 'textinput SBLList' , pattern=>'.*' , placeholder=>'SBLList', title =>'Pattern regex mismatch', id => "SBLList_text"
<br></span></p>
</div>
</div>
<div data-mailstats-group>
<p><span class=label> <p><span class=label>
%=l('mst_Enable_URIBL_checking') %=l('mst_Enable_URIBL_checking')
</span><span class=data> </span><span class=data>
% my @EnableURIBL_options = [['yes' => 'enabled'], ['no' => 'disabled']]; % my @EnableURIBL_options = [['yes' => 'enabled'], ['no' => 'disabled']];
% param 'EnableURIBL' => $mst_data->{EnableURIBL} unless param 'EnableURIBL'; % param 'EnableURIBL' => $mst_data->{EnableURIBL} unless param 'EnableURIBL';
%= select_field 'EnableURIBL' => @EnableURIBL_options, class => 'input', id => 'EnableURIBL_select' %= select_field 'EnableURIBL' => @EnableURIBL_options, class => 'input', id => 'EnableURIBL_select' , 'data-mailstats-control' => undef, 'data-mailstats-target' => "URIBL_group"
<br></span> </p> <br></span> </p>
<div id=URIBL_group>
<p><span class=label> <p><span class=label>
%=l('mst_RBL_Servers_to_use') %=l('mst_Select_the_URIBL_Lists')
</span><span class=data> </span><span class=data>
% param 'RBLList' => $mst_data->{RBLList} unless param 'RBLList'; % my @URIBLSelect_options = $c->get_URIBL_lists();
%= text_field 'RBLList', size => '50', class => 'textinput RBLList' , pattern=>'.*' , placeholder=>'RBLList', title =>'Pattern regex mismatch' % param 'URIBLSelect' => $mst_data->{URIBLSelect} unless param 'URIBLSelect';
<br></span></p> %= select_field 'URIBLSelect' => @URIBLSelect_options, class => 'input', id => 'URIBLList_select', multiple => 'multiple'
<br></span> </p>
<p><span class=label> <p><span class=label>
%=l('mst_SBL_Servers_to_use') %=l('mst_URIBL_Servers_to_use')
</span><span class=data> </span><span class=data>
% param 'SBLList' => $mst_data->{SBLList} unless param 'SBLList'; % param 'URIBLList' => $mst_data->{URIBLList} unless param 'URIBLList';
%= text_field 'SBLList', size => '50', class => 'textinput SBLList' , pattern=>'.*' , placeholder=>'SBLList', title =>'Pattern regex mismatch' %= text_field 'URIBLList', size => '50', class => 'textinput URIBLList' , pattern=>'.*' , placeholder=>'URIBLList', title =>'Pattern regex mismatch', id => 'URIBLList_text'
<br></span></p>
<p><span class=label>
%=l('mst_UBL_Servers_to_use')
</span><span class=data>
% param 'UBLList' => $mst_data->{UBLList} unless param 'UBLList';
%= text_field 'UBLList', size => '50', class => 'textinput UBLList' , pattern=>'.*' , placeholder=>'UBLList', title =>'Pattern regex mismatch'
<br></span></p> <br></span></p>
</div>
</div>
<h2 class='subh4'><%=l('mst_Spamassassin_scores_-_tag_and')%></h2> <h2 class='subh4'><%=l('mst_Spamassassin_scores_-_tag_and')%></h2>