E('button', {
'class': 'btn cbi-button-action',
'click': ui.createHandlerFn(this, function (ev) {
+ const domain = document.getElementById('blocklist').value.trim().toLowerCase();
+ if (!domain
+ || domain.length > 253
+ || /[^a-z0-9.-]|^-|-$|\.\.|\.$/.test(domain)) {
+ ui.addNotification(null, E('p', _('Invalid input, please submit a single valid (sub-)domain.')), 'warning');
+ ui.hideModal();
+ return;
+ }
L.resolveDefault(fs.read_direct('/etc/adblock/adblock.blocklist'), '')
.then(function (res) {
- const domain = document.getElementById('blocklist').value.trim().toLowerCase().replace(/[^a-z0-9.-]/g, '');
const pattern = new RegExp('^' + domain.replace(/[.]/g, '\\.') + '$', 'm');
if (res.search(pattern) === -1) {
const blocklist = res + domain + '\n';
E('button', {
'class': 'btn cbi-button-action',
'click': ui.createHandlerFn(this, function (ev) {
+ const domain = document.getElementById('allowlist').value.trim().toLowerCase();
+ if (!domain
+ || domain.length > 253
+ || /[^a-z0-9.-]|^-|-$|\.\.|\.$/.test(domain)) {
+ ui.addNotification(null, E('p', _('Invalid input, please submit a single valid (sub-)domain.')), 'warning');
+ ui.hideModal();
+ return;
+ }
L.resolveDefault(fs.read_direct('/etc/adblock/adblock.allowlist'), '')
.then(function (res) {
- const domain = document.getElementById('allowlist').value.trim().toLowerCase().replace(/[^a-z0-9.-]/g, '');
const pattern = new RegExp('^' + domain.replace(/[.]/g, '\\.') + '$', 'm');
if (res.search(pattern) === -1) {
const allowlist = res + domain + '\n';
E('div', { 'class': 'right' }, [
E('button', {
'class': 'btn cbi-button',
- 'click': ui.hideModal
+ 'click': function () {
+ if (window._adbSearchPoller) {
+ clearInterval(window._adbSearchPoller);
+ window._adbSearchPoller = null;
+ }
+ ui.hideModal();
+ }
}, _('Cancel')),
' ',
E('button', {
'class': 'btn cbi-button-action',
'click': ui.createHandlerFn(this, function (ev) {
const domain = document.getElementById('search').value.trim().toLowerCase().replace(/[^a-z0-9.-]/g, '');
- if (domain) {
- document.getElementById('run').classList.add("spinning");
- document.getElementById('search').value = domain;
- document.getElementById('result').textContent = _('The search is running, please wait...');
-
- if (window._adbSearchPoller) {
- clearInterval(window._adbSearchPoller);
- window._adbSearchPoller = null;
- }
- L.resolveDefault(fs.write('/var/run/adblock/adblock.search', ''), '').then(function () {
- L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['search', domain]), '');
- let attempts = 0;
- window._adbSearchPoller = setInterval(function () {
- attempts++;
- L.resolveDefault(fs.read('/var/run/adblock/adblock.search'), '').then(function (res) {
- if (res && res.trim()) {
- clearInterval(window._adbSearchPoller);
- window._adbSearchPoller = null;
- document.getElementById('result').textContent = res.trim();
- document.getElementById('run').classList.remove("spinning");
- document.getElementById('search').value = '';
- } else if (attempts >= 40) {
- clearInterval(window._adbSearchPoller);
- window._adbSearchPoller = null;
- document.getElementById('result').textContent = _('No Search results!');
- document.getElementById('run').classList.remove("spinning");
- }
- });
- }, 3000);
- });
+ document.getElementById('run').classList.add("spinning");
+ document.getElementById('search').value = domain;
+ document.getElementById('result').textContent = _('The search is running, please wait...');
+
+ const modal = ev.target.closest('.modal');
+ const buttons = modal ? modal.querySelectorAll('button') : [];
+ buttons.forEach(function (btn) { btn.disabled = true; });
+
+ if (window._adbSearchPoller) {
+ clearInterval(window._adbSearchPoller);
+ window._adbSearchPoller = null;
}
+ L.resolveDefault(fs.write('/var/run/adblock/adblock.search', ''), '').then(function () {
+ L.resolveDefault(fs.exec_direct('/etc/init.d/adblock', ['search', domain]), '');
+ let attempts = 0;
+ window._adbSearchPoller = setInterval(function () {
+ attempts++;
+ L.resolveDefault(fs.read('/var/run/adblock/adblock.search'), '').then(function (res) {
+ if (res && res.trim()) {
+ clearInterval(window._adbSearchPoller);
+ window._adbSearchPoller = null;
+ document.getElementById('result').textContent = res.trim();
+ document.getElementById('run').classList.remove("spinning");
+ document.getElementById('search').value = '';
+ buttons.forEach(function (btn) { btn.disabled = false; });
+ } else if (attempts >= 60) {
+ clearInterval(window._adbSearchPoller);
+ window._adbSearchPoller = null;
+ document.getElementById('result').textContent = _('No Search results!');
+ document.getElementById('run').classList.remove("spinning");
+ buttons.forEach(function (btn) { btn.disabled = false; });
+ }
+ });
+ }, 3000);
+ });
document.getElementById('search').focus();
})
}, _('Search'))
'id': 'refresh',
'class': 'btn cbi-button-action',
'click': function () {
- document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
- btn.disabled = true;
- });
+ document.querySelectorAll('.cbi-page-actions button').forEach(b => b.disabled = true);
+ document.querySelectorAll('.modal .right button').forEach(b => b.disabled = true);
this.blur();
this.classList.add('spinning');
const top_count = document.getElementById('top_count').value;
attempts++;
if (attempts >= 10) {
clearInterval(poller);
- document.querySelectorAll('.cbi-page-actions button').forEach(function (btn) {
- btn.disabled = false;
- });
- document.getElementById('refresh').classList.remove('spinning');
+ ui.hideModal();
+ document.querySelectorAll('.cbi-page-actions button').forEach(b => b.disabled = false);
ui.addNotification(null, E('p', _('Failed to generate adblock report!')), 'error');
}
}
'class': 'btn cbi-button',
'click': ui.createHandlerFn(this, function (ev) {
ui.hideModal();
- sessionStorage.clear();
+ sessionStorage.removeItem('mapData');
location.reload();
})
}, _('Cancel')),
}
/* Draw Pie Chart with Tooltip */
- const tooltipEl = E('div', {
+ let tooltipEl = document.getElementById('dnsPieTooltip');
+ if (tooltipEl) tooltipEl.remove();
+ tooltipEl = E('div', {
id: 'dnsPieTooltip',
style: 'position:absolute; padding:6px 10px; background:#333; color:#fff; border-radius:4px; font-size:12px; pointer-events:none; opacity:0; transition:opacity .15s; z-index:9999'
});
} catch (e) {
info = null;
parseErrCount++;
+ if (parseErrCount >= 5) {
+ ui.addNotification(null, E('p', _('Unable to parse the adblock runtime information!')), 'error');
+ poll.stop();
+ }
if (status) {
status.textContent = '-';
- buttons.forEach(function (btn) {
- btn.disabled = false;
- });
+ buttons.forEach(btn => btn.disabled = false);
status.classList.remove('spinning');
- if (parseErrCount >= 5) {
- ui.addNotification(null, E('p', _('Unable to parse the adblock runtime information!')), 'error');
- poll.stop();
- }
}
return;
}
}
} else {
status.classList.remove("spinning");
- if (document.getElementById('btn_suspend')) {
- if (info.adblock_status === 'paused') {
- document.querySelector('#btn_suspend').textContent = 'Resume';
- }
- if (info.adblock_status === 'enabled') {
- document.querySelector('#btn_suspend').textContent = 'Suspend';
- }
+ const btnSuspend = document.getElementById('btn_suspend');
+ if (btnSuspend) {
+ if (info.adblock_status === 'paused') btnSuspend.textContent = _('Resume');
+ if (info.adblock_status === 'enabled') btnSuspend.textContent = _('Suspend');
}
buttons.forEach(function (btn) {
btn.disabled = false;
runtime information and buttons
*/
s = m.section(form.NamedSection, 'global');
- s.render = L.bind(function (view, section_id) {
+ s.render = function (view, section_id) {
return E('div', { 'class': 'cbi-section' }, [
E('h3', _('Information')),
E('div', { 'class': 'cbi-value' }, [
E('div', { 'class': 'cbi-value-field', 'id': 'sys', 'style': 'margin-bottom:-5px;color:#37c;' }, '-')
])
]);
- }, o, this);
+ };
/*
tabbed config section
/*
feed selection tab
*/
- let chain, descr;
+ let size, descr;
let feeds = null;
if (result[0] && result[0].trim() !== "") {
o = s.taboption('feeds', form.MultiValue, 'adb_feed', _('Blocklist Feed'));
const feedKeys = Object.keys(feeds);
for (const feed of feedKeys) {
- chain = feeds[feed].size?.trim() || 'in';
- descr = feeds[feed].descr?.trim() || '-';
- o.value(feed.trim(), feed.trim() + ' (' + chain + ', ' + descr + ')');
+ size = String(feeds[feed].size ?? '').trim() || '-';
+ descr = String(feeds[feed].descr ?? '').trim() || '-';
+ o.value(feed.trim(), feed.trim() + ' (' + size + ', ' + descr + ')');
}
o.optional = true;
o.rmempty = true;
action buttons
*/
s = m.section(form.NamedSection, 'global');
- s.render = L.bind(function () {
+ s.render = function () {
return E('div', { 'class': 'cbi-page-actions' }, [
E('button', {
'class': 'btn cbi-button cbi-button-negative important',
}
}, [_('Save & Restart')])
]);
- });
+ };
return m.render();
},
handleSaveApply: null,