9 function handleAction(ev
) {
10 if (ev
.target
&& ev
.target
.getAttribute('name') === 'blacklist') {
11 L
.ui
.showModal(_('Add Blacklist Domain'), [
12 E('p', _('Add this (sub-)domain to your local blacklist.')),
13 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
14 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
15 E('input', { 'class': 'cbi-input-text', 'style': 'width:300px', 'id': 'blacklist', 'value': ev
.target
.getAttribute('value') }, [])
18 E('div', { 'class': 'right' }, [
25 'class': 'btn cbi-button-action',
26 'click': ui
.createHandlerFn(this, function(ev
) {
27 L
.resolveDefault(fs
.read_direct('/etc/adblock/adblock.blacklist'), '')
29 var domain
= document
.getElementById('blacklist').value
.trim().toLowerCase().replace(/[^a-z0-9\.\-]/g,'');
30 var pattern
= new RegExp('^' + domain
.replace(/[\.]/g,'\\.') + '$', 'm');
31 if (res
.search(pattern
) === -1) {
32 var blacklist
= res
+ domain
+ '\n';
33 fs
.write('/etc/adblock/adblock.blacklist', blacklist
);
34 ui
.addNotification(null, E('p', _('Blacklist changes have been saved. Refresh your adblock lists that changes take effect.')), 'info');
42 document
.getElementById('blacklist').focus();
45 if (ev
.target
&& ev
.target
.getAttribute('name') === 'whitelist') {
46 L
.ui
.showModal(_('Add Whitelist Domain'), [
47 E('p', _('Add this (sub-)domain to your local whitelist.')),
48 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
49 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
50 E('input', { 'class': 'cbi-input-text', 'style': 'width:300px', 'id': 'whitelist', 'value': ev
.target
.getAttribute('value') }, [])
53 E('div', { 'class': 'right' }, [
60 'class': 'btn cbi-button-action',
61 'click': ui
.createHandlerFn(this, function(ev
) {
62 L
.resolveDefault(fs
.read_direct('/etc/adblock/adblock.whitelist'), '')
64 var domain
= document
.getElementById('whitelist').value
.trim().toLowerCase().replace(/[^a-z0-9\.\-]/g,'');
65 var pattern
= new RegExp('^' + domain
.replace(/[\.]/g,'\\.') + '$', 'm');
66 if (res
.search(pattern
) === -1) {
67 var whitelist
= res
+ domain
+ '\n';
68 fs
.write('/etc/adblock/adblock.whitelist', whitelist
);
69 ui
.addNotification(null, E('p', _('Whitelist changes have been saved. Refresh your adblock lists that changes take effect.')), 'info');
77 document
.getElementById('whitelist').focus();
81 L
.ui
.showModal(_('Blocklist Query'), [
82 E('p', _('Query active blocklists and backups for a specific domain.')),
83 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
84 E('label', { 'style': 'padding-top:.5em', 'id': 'run' }, [
86 'class': 'cbi-input-text',
87 'placeholder': 'google.com',
88 'style': 'width:300px',
93 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
98 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
99 'readonly': 'readonly',
104 E('div', { 'class': 'right' }, [
111 'class': 'btn cbi-button-action',
112 'click': ui
.createHandlerFn(this, function(ev
) {
113 var domain
= document
.getElementById('search').value
.trim().toLowerCase().replace(/[^a-z0-9\.\-]/g,'');
115 document
.getElementById('run').classList
.add("spinning");
116 document
.getElementById('search').value
= domain
;
117 document
.getElementById('result').textContent
= 'The query is running, please wait...';
118 L
.resolveDefault(fs
.exec_direct('/etc/init.d/adblock', ['query', domain
])).then(function(res
) {
119 var result
= document
.getElementById('result');
121 result
.textContent
= res
.trim();
123 result
.textContent
= _('No Query results!');
125 document
.getElementById('run').classList
.remove("spinning");
126 document
.getElementById('search').value
= '';
129 document
.getElementById('search').focus();
134 document
.getElementById('search').focus();
137 if (ev
=== 'refresh') {
138 L
.ui
.showModal(_('Refresh DNS Report'), [
139 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
140 E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em' }, [
141 E('select', { 'class': 'cbi-input-select', 'id': 'count' }, [
142 E('option', { 'value': '50' }, '50'),
143 E('option', { 'value': '100' }, '100'),
144 E('option', { 'value': '150' }, '150'),
145 E('option', { 'value': '250' }, '250'),
146 E('option', { 'value': '500' }, '500')
149 _('max. result set size')
152 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
153 E('input', { 'class': 'cbi-input-text', 'spellcheck': 'false', 'id': 'search' }, [
156 _('Filter criteria like date, domain or client (optional)')
158 E('div', { 'class': 'right' }, [
165 'class': 'btn cbi-button-action',
167 'click': ui
.createHandlerFn(this, async
function(ev
) {
168 var count
= document
.getElementById('count').value
;
169 var search
= document
.getElementById('search').value
.trim().replace(/[^\w\.\-\:]/g,'') || '+';
170 L
.resolveDefault(fs
.exec_direct('/etc/init.d/adblock', ['report', search
, count
, 'true', 'json']),'');
172 while (running
=== 1) {
173 await
new Promise(r
=> setTimeout(r
, 1000));
174 L
.resolveDefault(fs
.read_direct('/var/run/adblock.pid')).then(function(res
) {
186 document
.getElementById('refresh').focus();
192 return L
.resolveDefault(fs
.exec_direct('/etc/init.d/adblock', ['report', '+', '50', 'false', 'json']),'');
195 render: function(dnsreport
) {
197 dnsreport
= '{ "data": "" }';
200 content
= JSON
.parse(dnsreport
);
203 var tbl_top
= E('table', { 'class': 'table', 'id': 'top_10' }, [
204 E('tr', { 'class': 'tr table-titles' }, [
205 E('th', { 'class': 'th right' }, _('Count')),
206 E('th', { 'class': 'th' }, _('Name / IP Address')),
207 E('th', { 'class': 'th right' }, _('Count')),
208 E('th', { 'class': 'th' }, _('Domain')),
209 E('th', { 'class': 'th right' }, _('Count')),
210 E('th', { 'class': 'th' }, _('Blocked Domain'))
215 if (content
.data
.top_clients
&& content
.data
.top_domains
&& content
.data
.top_blocked
) {
216 max
= Math
.max(content
.data
.top_clients
.length
, content
.data
.top_domains
.length
, content
.data
.top_blocked
.length
);
218 for (var i
= 0; i
< max
; i
++) {
219 var a_cnt
= '\xa0', a_addr
= '\xa0', b_cnt
= '\xa0', b_addr
= '\xa0', c_cnt
= '\xa0', c_addr
= '\xa0';
220 if (content
.data
.top_clients
[i
]) {
221 a_cnt
= content
.data
.top_clients
[i
].count
;
223 if (content
.data
.top_clients
[i
]) {
224 a_addr
= content
.data
.top_clients
[i
].address
;
226 if (content
.data
.top_domains
[i
]) {
227 b_cnt
= content
.data
.top_domains
[i
].count
;
229 if (content
.data
.top_domains
[i
]) {
230 b_addr
= content
.data
.top_domains
[i
].address
;
232 if (content
.data
.top_blocked
[i
]) {
233 c_cnt
= content
.data
.top_blocked
[i
].count
;
235 if (content
.data
.top_blocked
[i
]) {
236 c_addr
= content
.data
.top_blocked
[i
].address
;
247 cbi_update_table(tbl_top
, rows_top
);
249 var rows_requests
= [];
250 var tbl_requests
= E('table', { 'class': 'table', 'id': 'requests' }, [
251 E('tr', { 'class': 'tr table-titles' }, [
252 E('th', { 'class': 'th' }, _('Date')),
253 E('th', { 'class': 'th' }, _('Time')),
254 E('th', { 'class': 'th' }, _('Client')),
255 E('th', { 'class': 'th' }, _('Domain')),
256 E('th', { 'class': 'th' }, _('Answer')),
257 E('th', { 'class': 'th' }, _('Action'))
262 if (content
.data
.requests
) {
264 max
= content
.data
.requests
.length
;
265 for (var i
= 0; i
< max
; i
++) {
266 if (content
.data
.requests
[i
].rc
=== 'NX') {
267 button
= E('button', {
268 'class': 'cbi-button cbi-button-apply',
269 'style': 'word-break: inherit',
271 'value': content
.data
.requests
[i
].domain
,
272 'click': handleAction
273 }, [ _('Whitelist...') ]);
275 button
= E('button', {
276 'class': 'cbi-button cbi-button-apply',
277 'style': 'word-break: inherit',
279 'value': content
.data
.requests
[i
].domain
,
280 'click': handleAction
281 }, [ _('Blacklist...') ]);
284 content
.data
.requests
[i
].date
,
285 content
.data
.requests
[i
].time
,
286 content
.data
.requests
[i
].client
,
287 content
.data
.requests
[i
].domain
,
288 content
.data
.requests
[i
].rc
,
293 cbi_update_table(tbl_requests
, rows_requests
);
295 return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
296 E('div', { 'class': 'cbi-section' }, [
297 E('p', _('This shows the last generated DNS Report, press the refresh button to get a current one.')),
299 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
300 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Start Date')),
301 E('div', { 'class': 'cbi-value-field', 'id': 'start', 'style': 'margin-bottom:5px;margin-left:200px;color:#37c' }, (content
.data
.start_date
|| '-') + ', ' + (content
.data
.start_time
|| '-'))]),
302 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
303 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('End Date')),
304 E('div', { 'class': 'cbi-value-field', 'id': 'end', 'style': 'margin-bottom:5px;margin-left:200px;color:#37c' }, (content
.data
.end_date
|| '-') + ', ' + (content
.data
.end_time
|| '-'))]),
305 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
306 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('DNS Requests (total)')),
307 E('div', { 'class': 'cbi-value-field', 'id': 'total', 'style': 'margin-bottom:5px;margin-left:200px;color:#37c' }, content
.data
.total
|| '-')]),
308 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
309 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('DNS Requests (blocked)')),
310 E('div', { 'class': 'cbi-value-field', 'id': 'blocked', 'style': 'margin-bottom:5px;margin-left:200px;color:#37c' }, (content
.data
.blocked
|| '-') + ' (' + (content
.data
.percent
|| '-') + ')')]),
311 E('div', { 'class': 'right' }, [
313 'class': 'cbi-button cbi-button-apply',
314 'click': ui
.createHandlerFn(this, function() {
315 return handleAction('query');
317 }, [ _('Blocklist Query...') ]),
320 'class': 'cbi-button cbi-button-apply',
321 'click': ui
.createHandlerFn(this, function() {
322 return handleAction('refresh');
324 }, [ _('Refresh...') ])
327 E('div', { 'class': 'cbi-section' }, [
328 E('div', { 'class': 'left' }, [
329 E('h3', _('Top 10 Statistics')),
334 E('div', { 'class': 'cbi-section' }, [
335 E('div', { 'class': 'left' }, [
336 E('h3', _('Latest DNS Requests')),
342 handleSaveApply
: null,