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', 'spellcheck': 'false', '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', 'spellcheck': 'false', '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',
89 'spellcheck': 'false',
94 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
99 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
100 'readonly': 'readonly',
105 E('div', { 'class': 'right' }, [
112 'class': 'btn cbi-button-action',
113 'click': ui
.createHandlerFn(this, function(ev
) {
114 var domain
= document
.getElementById('search').value
.trim().toLowerCase().replace(/[^a-z0-9\.\-]/g,'');
116 document
.getElementById('run').classList
.add("spinning");
117 document
.getElementById('search').value
= domain
;
118 document
.getElementById('result').textContent
= 'The query is running, please wait...';
119 L
.resolveDefault(fs
.exec_direct('/etc/init.d/adblock', ['query', domain
])).then(function(res
) {
120 var result
= document
.getElementById('result');
122 result
.textContent
= res
.trim();
124 result
.textContent
= _('No Query results!');
126 document
.getElementById('run').classList
.remove("spinning");
127 document
.getElementById('search').value
= '';
130 document
.getElementById('search').focus();
135 document
.getElementById('search').focus();
138 if (ev
=== 'refresh') {
139 L
.ui
.showModal(_('Refresh DNS Report'), [
140 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
141 E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em' }, [
142 E('select', { 'class': 'cbi-input-select', 'id': 'count' }, [
143 E('option', { 'value': '50' }, '50'),
144 E('option', { 'value': '100' }, '100'),
145 E('option', { 'value': '150' }, '150'),
146 E('option', { 'value': '250' }, '250'),
147 E('option', { 'value': '500' }, '500')
150 _('max. result set size')
153 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
154 E('input', { 'class': 'cbi-input-text', 'spellcheck': 'false', 'id': 'search' }, [
157 _('Filter criteria like date, domain or client (optional)')
159 E('div', { 'class': 'right' }, [
166 'class': 'btn cbi-button-action',
168 'click': ui
.createHandlerFn(this, async
function(ev
) {
169 var count
= document
.getElementById('count').value
;
170 var search
= document
.getElementById('search').value
.trim().replace(/[^\w\.\-\:]/g,'') || '+';
171 L
.resolveDefault(fs
.exec_direct('/etc/init.d/adblock', ['report', search
, count
, 'true', 'json']),'');
173 while (running
=== 1) {
174 await
new Promise(r
=> setTimeout(r
, 1000));
175 L
.resolveDefault(fs
.read_direct('/var/run/adblock.pid')).then(function(res
) {
187 document
.getElementById('refresh').focus();
193 return L
.resolveDefault(fs
.exec_direct('/etc/init.d/adblock', ['report', '+', '50', 'false', 'json']),'');
196 render: function(dnsreport
) {
198 dnsreport
= '{ "data": "" }';
201 content
= JSON
.parse(dnsreport
);
204 var tbl_top
= E('table', { 'class': 'table', 'id': 'top_10' }, [
205 E('tr', { 'class': 'tr table-titles' }, [
206 E('th', { 'class': 'th right' }, _('Count')),
207 E('th', { 'class': 'th' }, _('Name / IP Address')),
208 E('th', { 'class': 'th right' }, _('Count')),
209 E('th', { 'class': 'th' }, _('Domain')),
210 E('th', { 'class': 'th right' }, _('Count')),
211 E('th', { 'class': 'th' }, _('Blocked Domain'))
216 if (content
.data
.top_clients
&& content
.data
.top_domains
&& content
.data
.top_blocked
) {
217 max
= Math
.max(content
.data
.top_clients
.length
, content
.data
.top_domains
.length
, content
.data
.top_blocked
.length
);
219 for (var i
= 0; i
< max
; i
++) {
220 var a_cnt
= '\xa0', a_addr
= '\xa0', b_cnt
= '\xa0', b_addr
= '\xa0', c_cnt
= '\xa0', c_addr
= '\xa0';
221 if (content
.data
.top_clients
[i
]) {
222 a_cnt
= content
.data
.top_clients
[i
].count
;
224 if (content
.data
.top_clients
[i
]) {
225 a_addr
= content
.data
.top_clients
[i
].address
;
227 if (content
.data
.top_domains
[i
]) {
228 b_cnt
= content
.data
.top_domains
[i
].count
;
230 if (content
.data
.top_domains
[i
]) {
231 b_addr
= '<a href="https://duckduckgo.com/?q=' + encodeURIComponent(content
.data
.top_domains
[i
].address
) + '&k1=-1&km=l&kh=1" target="_blank" title="Search this domain">' + content
.data
.top_domains
[i
].address
+ '</a>';
233 if (content
.data
.top_blocked
[i
]) {
234 c_cnt
= content
.data
.top_blocked
[i
].count
;
236 if (content
.data
.top_blocked
[i
]) {
237 c_addr
= '<a href="https://duckduckgo.com/?q=' + encodeURIComponent(content
.data
.top_blocked
[i
].address
) + '&k1=-1&km=l&kh=1" target="_blank" title="Search this domain">' + content
.data
.top_blocked
[i
].address
+ '</a>';
248 cbi_update_table(tbl_top
, rows_top
);
250 var rows_requests
= [];
251 var tbl_requests
= E('table', { 'class': 'table', 'id': 'requests' }, [
252 E('tr', { 'class': 'tr table-titles' }, [
253 E('th', { 'class': 'th' }, _('Date')),
254 E('th', { 'class': 'th' }, _('Time')),
255 E('th', { 'class': 'th' }, _('Client')),
256 E('th', { 'class': 'th' }, _('Domain')),
257 E('th', { 'class': 'th' }, _('Answer')),
258 E('th', { 'class': 'th' }, _('Action'))
263 if (content
.data
.requests
) {
265 max
= content
.data
.requests
.length
;
266 for (var i
= 0; i
< max
; i
++) {
267 if (content
.data
.requests
[i
].rc
=== 'NX') {
268 button
= E('button', {
269 'class': 'cbi-button cbi-button-apply',
270 'style': 'word-break: inherit',
272 'value': content
.data
.requests
[i
].domain
,
273 'click': handleAction
274 }, [ _('Whitelist...') ]);
276 button
= E('button', {
277 'class': 'cbi-button cbi-button-apply',
278 'style': 'word-break: inherit',
280 'value': content
.data
.requests
[i
].domain
,
281 'click': handleAction
282 }, [ _('Blacklist...') ]);
285 content
.data
.requests
[i
].date
,
286 content
.data
.requests
[i
].time
,
287 content
.data
.requests
[i
].client
,
288 '<a href="https://duckduckgo.com/?q=' + encodeURIComponent(content
.data
.requests
[i
].domain
) + '&k1=-1&km=l&kh=1" target="_blank" title="Search this domain">' + content
.data
.requests
[i
].domain
+ '</a>',
289 content
.data
.requests
[i
].rc
,
294 cbi_update_table(tbl_requests
, rows_requests
);
296 return E('div', { 'class': 'cbi-map', 'id': 'map' }, [
297 E('div', { 'class': 'cbi-section' }, [
298 E('p', _('This shows the last generated DNS Report, press the refresh button to get a current one.')),
300 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
301 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Start Timestamp')),
302 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
|| '-'))]),
303 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
304 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('End Timestamp')),
305 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
|| '-'))]),
306 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
307 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Total DNS Requests')),
308 E('div', { 'class': 'cbi-value-field', 'id': 'total', 'style': 'margin-bottom:5px;margin-left:200px;color:#37c' }, content
.data
.total
|| '-')]),
309 E('div', { 'class': 'cbi-value', 'style': 'margin-bottom:5px' }, [
310 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Blocked DNS Requests')),
311 E('div', { 'class': 'cbi-value-field', 'id': 'blocked', 'style': 'margin-bottom:5px;margin-left:200px;color:#37c' }, (content
.data
.blocked
|| '-') + ' (' + (content
.data
.percent
|| '-') + ')')]),
312 E('div', { 'class': 'right' }, [
314 'class': 'cbi-button cbi-button-apply',
315 'click': ui
.createHandlerFn(this, function() {
316 return handleAction('query');
318 }, [ _('Blocklist Query...') ]),
321 'class': 'cbi-button cbi-button-apply',
322 'click': ui
.createHandlerFn(this, function() {
323 return handleAction('refresh');
325 }, [ _('Refresh...') ])
328 E('div', { 'class': 'cbi-section' }, [
329 E('div', { 'class': 'left' }, [
330 E('h3', _('Top 10 Statistics')),
335 E('div', { 'class': 'cbi-section' }, [
336 E('div', { 'class': 'left' }, [
337 E('h3', _('Latest DNS Requests')),
343 handleSaveApply
: null,