luci-app-banip: Fix Treshold to Threshold
[project/luci.git] / applications / luci-app-banip / htdocs / luci-static / resources / view / banip / overview.js
1 'use strict';
2 'require dom';
3 'require view';
4 'require poll';
5 'require fs';
6 'require ui';
7 'require uci';
8 'require form';
9 'require tools.widgets as widgets';
10
11 /*
12 button handling
13 */
14 function handleAction(ev) {
15 if (ev === 'restart') {
16 let map = document.querySelector('.cbi-map');
17 return dom.callClassMethod(map, 'save')
18 .then(L.bind(ui.changes.apply, ui.changes))
19 .then(function() {
20 return fs.exec_direct('/etc/init.d/banip', [ev]);
21 });
22 } else {
23 return fs.exec_direct('/etc/init.d/banip', [ev]);
24 }
25 }
26
27 return view.extend({
28 load: function () {
29 return Promise.all([
30 L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds'), ''),
31 L.resolveDefault(fs.read_direct('/etc/banip/banip.feeds'), ''),
32 L.resolveDefault(fs.read_direct('/etc/banip/banip.countries'), ''),
33 uci.load('banip')
34 ]);
35 },
36
37 render: function (result) {
38 let m, s, o;
39
40 m = new form.Map('banip', 'banIP', _('Configuration of the banIP package to ban incoming and outgoing IPs via named nftables Sets. \
41 For further information please check the <a style="color:#37c;font-weight:bold;" href="https://github.com/openwrt/packages/blob/master/net/banip/files/README.md" target="_blank" rel="noreferrer noopener" >online documentation</a>'));
42
43 /*
44 poll runtime information
45 */
46 let buttons, rtRes, infStat, infVer, infElements, infFeeds, infDevices, infUplink, infSystem, nftInfos, runInfos, infFlags, last_run
47
48 pollData: poll.add(function () {
49 return L.resolveDefault(fs.stat('/var/run/banip.lock')).then(function (stat) {
50 buttons = document.querySelectorAll('.cbi-button');
51 infStat = document.getElementById('status');
52 if (stat) {
53 for (let i = 0; i < buttons.length; i++) {
54 buttons[i].setAttribute('disabled', 'true');
55 }
56 if (infStat && !infStat.classList.contains('spinning')) {
57 infStat.classList.add('spinning');
58 }
59 } else {
60 for (let i = 0; i < buttons.length; i++) {
61 buttons[i].removeAttribute('disabled');
62 }
63 if (infStat && infStat.classList.contains('spinning')) {
64 infStat.classList.remove('spinning');
65 }
66 }
67 L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['status'])).then(function (result) {
68 if (result) {
69 rtRes = result.trim().split('\n');
70 if (rtRes) {
71 for (let i = 0; i < rtRes.length; i++) {
72 if (rtRes[i].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)) {
73 rtRes.status = rtRes[i].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)[1];
74 } else if (rtRes[i].match(/^\s+\+\sversion\s+\:\s+(.*)$/)) {
75 rtRes.version = rtRes[i].match(/^\s+\+\sversion\s+\:\s+(.*)$/)[1];
76 } else if (rtRes[i].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)) {
77 rtRes.elementCount = rtRes[i].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)[1];
78 } else if (rtRes[i].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)) {
79 rtRes.activeFeeds = rtRes[i].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)[1];
80 } else if (rtRes[i].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)) {
81 rtRes.activeDevices = rtRes[i].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)[1];
82 } else if (rtRes[i].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)) {
83 rtRes.activeUplink = rtRes[i].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)[1];
84 } else if (rtRes[i].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)) {
85 rtRes.nftInfo = rtRes[i].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)[1];
86 } else if (rtRes[i].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)) {
87 rtRes.runInfo = rtRes[i].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)[1];
88 } else if (rtRes[i].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)) {
89 rtRes.runFlags = rtRes[i].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)[1];
90 } else if (rtRes[i].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)) {
91 rtRes.lastRun = rtRes[i].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)[1];
92 } else if (rtRes[i].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)) {
93 rtRes.systemInfo = rtRes[i].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)[1];
94 }
95 }
96 }
97 if (rtRes) {
98 infStat = document.getElementById('status');
99 if (infStat) {
100 infStat.textContent = rtRes.status || '-';
101 }
102 infVer = document.getElementById('version');
103 if (infVer) {
104 infVer.textContent = rtRes.version || '-';
105 }
106 infElements = document.getElementById('elements');
107 if (infElements) {
108 infElements.textContent = rtRes.elementCount || '-';
109 }
110 infFeeds = document.getElementById('feeds');
111 if (infFeeds) {
112 infFeeds.textContent = rtRes.activeFeeds || '-';
113 }
114 infDevices = document.getElementById('devices');
115 if (infDevices) {
116 infDevices.textContent = rtRes.activeDevices || '-';
117 }
118 infUplink = document.getElementById('uplink');
119 if (infUplink) {
120 infUplink.textContent = rtRes.activeUplink || '-';
121 }
122 nftInfos = document.getElementById('nft');
123 if (nftInfos) {
124 nftInfos.textContent = rtRes.nftInfo || '-';
125 }
126 runInfos = document.getElementById('run');
127 if (runInfos) {
128 runInfos.textContent = rtRes.runInfo || '-';
129 }
130 infFlags = document.getElementById('flags');
131 if (infFlags) {
132 infFlags.textContent = rtRes.runFlags || '-';
133 }
134 last_run = document.getElementById('last');
135 if (last_run) {
136 last_run.textContent = rtRes.lastRun || '-';
137 }
138 infSystem = document.getElementById('system');
139 if (infSystem) {
140 infSystem.textContent = rtRes.systemInfo || '-';
141 }
142 }
143 } else {
144 infStat = document.getElementById('status');
145 if (infStat) {
146 infStat.textContent = '-';
147 poll.stop();
148 if (infStat.classList.contains('spinning')) {
149 infStat.classList.remove('spinning');
150 }
151 }
152 }
153 });
154 });
155 }, 2);
156
157 /*
158 runtime information and buttons
159 */
160 s = m.section(form.NamedSection, 'global');
161 s.render = L.bind(function (view, section_id) {
162 return E('div', { 'class': 'cbi-section' }, [
163 E('h3', _('Information')),
164 E('div', { 'class': 'cbi-value' }, [
165 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Status')),
166 E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '\xa0')
167 ]),
168 E('div', { 'class': 'cbi-value' }, [
169 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Version')),
170 E('div', { 'class': 'cbi-value-field', 'id': 'version', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
171 ]),
172 E('div', { 'class': 'cbi-value' }, [
173 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Element Count')),
174 E('div', { 'class': 'cbi-value-field', 'id': 'elements', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
175 ]),
176 E('div', { 'class': 'cbi-value' }, [
177 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Active Feeds')),
178 E('div', { 'class': 'cbi-value-field', 'id': 'feeds', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
179 ]),
180 E('div', { 'class': 'cbi-value' }, [
181 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Active Devices')),
182 E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
183 ]),
184 E('div', { 'class': 'cbi-value' }, [
185 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Active Uplink')),
186 E('div', { 'class': 'cbi-value-field', 'id': 'uplink', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
187 ]),
188 E('div', { 'class': 'cbi-value' }, [
189 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('NFT Information')),
190 E('div', { 'class': 'cbi-value-field', 'id': 'nft', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
191 ]),
192 E('div', { 'class': 'cbi-value' }, [
193 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Run Information')),
194 E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
195 ]),
196 E('div', { 'class': 'cbi-value' }, [
197 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Run Flags')),
198 E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
199 ]),
200 E('div', { 'class': 'cbi-value' }, [
201 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Last Run')),
202 E('div', { 'class': 'cbi-value-field', 'id': 'last', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
203 ]),
204 E('div', { 'class': 'cbi-value' }, [
205 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('System Information')),
206 E('div', { 'class': 'cbi-value-field', 'id': 'system', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
207 ]),
208 E('div', { class: 'right' }, [
209 E('button', {
210 'class': 'btn cbi-button cbi-button-action',
211 'click': ui.createHandlerFn(this, function () {
212 return handleAction('lookup');
213 })
214 }, [_('Domain Lookup')]),
215 '\xa0\xa0\xa0',
216 E('button', {
217 'class': 'btn cbi-button cbi-button-negative',
218 'click': ui.createHandlerFn(this, function () {
219 return handleAction('stop');
220 })
221 }, [_('Stop')]),
222 '\xa0\xa0\xa0',
223 E('button', {
224 'class': 'btn cbi-button cbi-button-positive',
225 'click': ui.createHandlerFn(this, function () {
226 return handleAction('reload');
227 })
228 }, [_('Reload')]),
229 '\xa0\xa0\xa0',
230 E('button', {
231 'class': 'btn cbi-button cbi-button-positive',
232 'click': ui.createHandlerFn(this, function () {
233 return handleAction('restart');
234 })
235 }, [_('Apply & Restart')])
236 ])
237 ]);
238 }, o, this);
239 this.pollData;
240
241 /*
242 tabbed config section
243 */
244 s = m.section(form.NamedSection, 'global', 'banip', _('Settings'));
245 s.addremove = false;
246 s.tab('general', _('General Settings'));
247 s.tab('advanced', _('Advanced Settings'));
248 s.tab('adv_chain', _('Table/Chain Settings'));
249 s.tab('adv_set', _('Feed/Set Settings'));
250 s.tab('adv_log', _('Log Settings'));
251 s.tab('adv_email', _('E-Mail Settings'));
252 s.tab('feeds', _('Feed Selection'));
253
254 /*
255 general settings tab
256 */
257 o = s.taboption('general', form.Flag, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
258 o.rmempty = false;
259
260 o = s.taboption('general', form.Flag, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of processing errors.'));
261 o.rmempty = false;
262
263 o = s.taboption('general', form.Flag, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network devices, interfaces, subnets, protocols and utilities automatically.'));
264 o.rmempty = false;
265
266 o = s.taboption('general', form.Flag, 'ban_protov4', _('IPv4 Support'), _('Enables IPv4 support.'));
267 o.depends('ban_autodetect', '0');
268 o.optional = true;
269 o.retain = true;
270
271 o = s.taboption('general', form.Flag, 'ban_protov6', _('IPv6 Support'), _('Enables IPv6 support.'));
272 o.depends('ban_autodetect', '0');
273 o.optional = true;
274 o.retain = true;
275
276 o = s.taboption('general', widgets.DeviceSelect, 'ban_dev', _('Network Devices'), _('Select the WAN network device(s).'));
277 o.depends('ban_autodetect', '0');
278 o.multiple = true;
279 o.nocreate = true;
280 o.optional = true;
281 o.retain = true;
282
283 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv4', _('IPv4 Network Interfaces'), _('Select the logical WAN IPv4 network interface(s).'));
284 o.depends('ban_autodetect', '0');
285 o.multiple = true;
286 o.nocreate = true;
287 o.optional = true;
288 o.retain = true;
289
290 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv6', _('IPv6 Network Interfaces'), _('Select the logical WAN IPv6 network interface(s).'));
291 o.depends('ban_autodetect', '0');
292 o.multiple = true;
293 o.nocreate = true;
294 o.optional = true;
295 o.retain = true;
296
297 o = s.taboption('general', form.ListValue, 'ban_fetchcmd', _('Download Utility'), _('Select one of the pre-configured download utilities.'));
298 o.depends('ban_autodetect', '0');
299 o.value('uclient-fetch');
300 o.value('wget');
301 o.value('curl');
302 o.value('aria2c');
303 o.optional = true;
304 o.retain = true;
305
306 o = s.taboption('general', form.Value, 'ban_fetchparm', _('Download Parameters'), _('Override the pre-configured download options for the selected download utility.'))
307 o.depends('ban_autodetect', '0');
308 o.optional = true;
309 o.retain = true;
310
311 o = s.taboption('general', widgets.NetworkSelect, 'ban_trigger', _('Reload Trigger Interface'), _('List of available reload trigger interface(s).'));
312 o.multiple = true;
313 o.nocreate = true;
314 o.rmempty = true;
315
316 o = s.taboption('general', form.Value, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds during interface reload and boot.'));
317 o.placeholder = '10';
318 o.datatype = 'range(1,300)';
319 o.rmempty = true;
320
321 o = s.taboption('general', form.ListValue, 'ban_fetchretry', _('Download Retries'), _('Number of download attempts in case of an error (not supported by uclient-fetch).'));
322 o.value('1', '1');
323 o.value('3', '3');
324 o.value('5', '5');
325 o.value('10', '10');
326 o.value('20', '20');
327 o.default = '5';
328 o.optional = true;
329 o.rmempty = true;
330
331 o = s.taboption('general', form.Flag, 'ban_fetchinsecure', _('Download Insecure'), _('Don\'t check SSL server certificates during download.'));
332 o.rmempty = true;
333
334 /*
335 additional settings tab
336 */
337 o = s.taboption('advanced', form.DummyValue, '_sub');
338 o.rawhtml = true;
339 o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
340
341 o = s.taboption('advanced', form.ListValue, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.'));
342 o.value('-20', _('Highest Priority'));
343 o.value('-10', _('High Priority'));
344 o.value('0', _('Normal Priority'));
345 o.value('10', _('Less Priority'));
346 o.value('19', _('Least Priority'));
347 o.default = '0';
348 o.optional = true;
349 o.rmempty = true;
350
351 o = s.taboption('advanced', form.ListValue, 'ban_filelimit', _('Max Open Files'), _('Increase the maximal number of open files, e.g. to handle the amount of temporary split files while loading the Sets.'));
352 o.value('512', '512');
353 o.value('1024', '1024');
354 o.value('2048', '2048');
355 o.value('4096', '4096');
356 o.default = '1024';
357 o.optional = true;
358 o.rmempty = true;
359
360 o = s.taboption('advanced', form.ListValue, 'ban_cores', _('CPU Cores'), _('Limit the cpu cores used by banIP to save RAM.'));
361 o.value('1');
362 o.value('2');
363 o.value('4');
364 o.value('8');
365 o.value('16');
366 o.optional = true;
367 o.rmempty = true;
368
369 o = s.taboption('advanced', form.ListValue, 'ban_splitsize', _('Set Split Size'), _('Split external Set loading after every n members to save RAM.'));
370 o.value('512');
371 o.value('1024');
372 o.value('2048');
373 o.value('4096');
374 o.value('8192');
375 o.value('16384');
376 o.optional = true;
377 o.rmempty = true;
378
379 o = s.taboption('advanced', form.Value, 'ban_basedir', _('Base Directory'), _('Base working directory while banIP processing.'));
380 o.placeholder = '/tmp';
381 o.rmempty = true;
382
383 o = s.taboption('advanced', form.Value, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed feed backups.'));
384 o.placeholder = '/tmp/banIP-backup';
385 o.rmempty = true;
386
387 o = s.taboption('advanced', form.Value, 'ban_reportdir', _('Report Directory'), _('Target directory for banIP-related report files.'));
388 o.placeholder = '/tmp/banIP-report';
389 o.rmempty = true;
390
391 o = s.taboption('advanced', form.Flag, 'ban_deduplicate', _('Deduplicate IPs'), _('Deduplicate IP addresses across all active Sets and tidy up the local blocklist.'));
392 o.default = 1
393 o.rmempty = false;
394
395 o = s.taboption('advanced', form.Flag, 'ban_reportelements', _('Report Elements'), _('List Set elements in the status and report, disable this to reduce the CPU load.'));
396 o.default = 1
397 o.optional = true;
398
399 /*
400 advanced chain settings tab
401 */
402 o = s.taboption('adv_chain', form.DummyValue, '_sub');
403 o.rawhtml = true;
404 o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
405
406 o = s.taboption('adv_chain', form.ListValue, 'ban_nftpriority', _('Chain Priority'), _('Set the nft chain priority within the banIP table, lower values means higher priority.'));
407 o.value('0', '0');
408 o.value('-100', '-100');
409 o.value('-150', '-150');
410 o.value('-200', '-200');
411 o.default = '100';
412 o.optional = true;
413 o.rmempty = true;
414
415 o = s.taboption('adv_chain', form.Value, 'ban_allowflag', _('Allow Protocol/Ports'), _('Always allow a protocol \(tcp/udp\) with certain ports or port ranges in WAN-Input and WAN-Forward chain.'));
416 o.placeholder = 'tcp 80 443-445';
417 o.rmempty = true;
418
419 o = s.taboption('adv_chain', widgets.DeviceSelect, 'ban_vlanallow', _('Allow VLAN Forwards'), _('Always allow certain VLAN forwards.'));
420 o.multiple = true;
421 o.nocreate = true;
422 o.optional = true;
423 o.rmempty = true;
424
425 o = s.taboption('adv_chain', widgets.DeviceSelect, 'ban_vlanblock', _('Block VLAN Forwards'), _('Always block certain VLAN forwards.'));
426 o.multiple = true;
427 o.nocreate = true;
428 o.optional = true;
429 o.rmempty = true;
430
431 o = s.taboption('adv_chain', form.ListValue, 'ban_icmplimit', _('ICMP-Threshold'), _('ICMP-Threshold in packets per second to prevent WAN-DDoS attacks.'));
432 o.value('1', '1');
433 o.value('10', '10');
434 o.value('50', '50');
435 o.value('100', '100');
436 o.value('250', '250');
437 o.value('500', '500');
438 o.default = '10';
439 o.optional = true;
440 o.rmempty = true;
441
442 o = s.taboption('adv_chain', form.ListValue, 'ban_synlimit', _('SYN-Threshold'), _('SYN-Threshold in packets per second to prevent WAN-DDoS attacks.'));
443 o.value('1', '1');
444 o.value('10', '10');
445 o.value('50', '50');
446 o.value('100', '100');
447 o.value('250', '250');
448 o.value('500', '500');
449 o.default = '10';
450 o.optional = true;
451 o.rmempty = true;
452
453 o = s.taboption('adv_chain', form.ListValue, 'ban_udplimit', _('UDP-Threshold'), _('UDP-Threshold in packets per second to prevent WAN-DDoS attacks.'));
454 o.value('1', '1');
455 o.value('10', '10');
456 o.value('50', '50');
457 o.value('100', '100');
458 o.value('250', '250');
459 o.value('500', '500');
460 o.default = '100';
461 o.optional = true;
462 o.rmempty = true;
463
464 /*
465 advanced Set settings tab
466 */
467 o = s.taboption('adv_set', form.DummyValue, '_sub');
468 o.rawhtml = true;
469 o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
470
471 o = s.taboption('adv_set', form.ListValue, 'ban_nftpolicy', _('Set Policy'), _('Set the nft policy for banIP-related Sets.'));
472 o.value('memory', _('memory'));
473 o.value('performance', _('performance'));
474 o.default = 'memory';
475 o.optional = true;
476 o.rmempty = true;
477
478 o = s.taboption('adv_set', form.ListValue, 'ban_blocktype', _('Block Type'), _('Drop packets silently or actively reject the traffic on WAN-Input and WAN-Forward chains.'));
479 o.value('drop', _('drop'));
480 o.value('reject', _('reject'));
481 o.default = 'drop';
482 o.optional = true;
483 o.rmempty = true;
484
485 o = s.taboption('adv_set', form.ListValue, 'ban_blockpolicy', _('Default Block Policy'), _('By default each feed is active in all supported chains. Limit the default block policy to a certain chain.'));
486 o.value('input', _('WAN-Input Chain'));
487 o.value('forwardwan', _('WAN-Forward Chain'));
488 o.value('forwardlan', _('LAN-Forward Chain'));
489 o.optional = true;
490 o.rmempty = true;
491
492 let feed, feeds, descr;
493 if (result[0]) {
494 try {
495 feeds = JSON.parse(result[0]);
496 } catch (e) {
497 feeds = "";
498 ui.addNotification(null, E('p', _('Unable to parse the custom feed file: %s').format(e.message)), 'error');
499 }
500 } else if (result[1]) {
501 try {
502 feeds = JSON.parse(result[1]);
503 } catch (e) {
504 feeds = "";
505 ui.addNotification(null, E('p', _('Unable to parse the default feed file: %s').format(e.message)), 'error');
506 }
507 }
508 if (feeds) {
509 o = s.taboption('adv_set', form.MultiValue, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.'));
510 o.value('allowlist', _('local allowlist'));
511 o.value('blocklist', _('local blocklist'));
512 for (let i = 0; i < Object.keys(feeds).length; i++) {
513 feed = Object.keys(feeds)[i].trim();
514 o.value(feed);
515 }
516 o.optional = true;
517 o.rmempty = true;
518
519 o = s.taboption('adv_set', form.MultiValue, 'ban_blockforwardwan', _('WAN-Forward Chain'), _('Limit certain feeds to the WAN-Forward chain.'));
520 o.value('allowlist', _('local allowlist'));
521 o.value('blocklist', _('local blocklist'));
522 for (let i = 0; i < Object.keys(feeds).length; i++) {
523 feed = Object.keys(feeds)[i].trim();
524 o.value(feed);
525 }
526 o.optional = true;
527 o.rmempty = true;
528
529 o = s.taboption('adv_set', form.MultiValue, 'ban_blockforwardlan', _('LAN-Forward Chain'), _('Limit certain feeds to the LAN-Forward chain.'));
530 o.value('allowlist', _('local allowlist'));
531 o.value('blocklist', _('local blocklist'));
532 for (let i = 0; i < Object.keys(feeds).length; i++) {
533 feed = Object.keys(feeds)[i].trim();
534 o.value(feed);
535 }
536 o.optional = true;
537 o.rmempty = true;
538 }
539
540 /*
541 advanced log settings tab
542 */
543 o = s.taboption('adv_log', form.DummyValue, '_sub');
544 o.rawhtml = true;
545 o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
546
547 o = s.taboption('adv_log', form.ListValue, 'ban_nftloglevel', _('NFT Log Level'), _('Set the syslog level for NFT logging.'));
548 o.value('emerg', _('emerg'));
549 o.value('alert', _('alert'));
550 o.value('crit', _('crit'));
551 o.value('err', _('err'));
552 o.value('warn', _('warn'));
553 o.value('notice', _('notice'));
554 o.value('info', _('info'));
555 o.value('debug', _('debug'));
556 o.default = 'warn';
557 o.optional = true;
558 o.rmempty = true;
559
560 o = s.taboption('adv_log', form.Flag, 'ban_logprerouting', _('Log Prerouting'), _('Log suspicious Prerouting packets.'));
561 o.rmempty = false;
562
563 o = s.taboption('adv_log', form.Flag, 'ban_loginput', _('Log WAN-Input'), _('Log suspicious incoming WAN packets.'));
564 o.rmempty = false;
565
566 o = s.taboption('adv_log', form.Flag, 'ban_logforwardwan', _('Log WAN-Forward'), _('Log suspicious forwarded WAN packets.'));
567 o.rmempty = false;
568
569 o = s.taboption('adv_log', form.Flag, 'ban_logforwardlan', _('Log LAN-Forward'), _('Log suspicious forwarded LAN packets.'));
570 o.rmempty = false;
571
572 o = s.taboption('adv_log', form.Value, 'ban_logreadfile', _('Logfile Location'), _('Location for parsing the log file, e.g. via syslog-ng, to deactivate the standard parsing via logread.'));
573 o.placeholder = '/var/log/messages';
574 o.rmempty = true;
575
576 o = s.taboption('adv_log', form.ListValue, 'ban_loglimit', _('Log Limit'), _('Parse only the last stated number of log entries for suspicious events. To disable the log monitor at all set it to \'0\'.'));
577 o.value('0', _('Disable'));
578 o.value('50', '50');
579 o.value('100', '100');
580 o.value('250', '250');
581 o.value('500', '500');
582 o.value('1000', '1000');
583 o.default = '100';
584 o.optional = true;
585 o.rmempty = true;
586
587 o = s.taboption('adv_log', form.Value, 'ban_logcount', _('Log Count'), _('Number of failed login attempts of the same IP in the log before blocking.'));
588 o.placeholder = '1';
589 o.datatype = 'range(1,10)';
590 o.rmempty = true;
591
592 o = s.taboption('adv_log', form.DynamicList, 'ban_logterm', _('Log Terms'), _('The default regular expressions are filtering suspicious ssh, LuCI, nginx and asterisk traffic.'));
593 o.optional = true;
594 o.rmempty = true;
595
596 o = s.taboption('adv_log', form.Flag, 'ban_remotelog', _('Enable Remote Logging'), _('Enable the cgi interface to receive remote logging events.'));
597 o.default = 0
598 o.optional = true;
599 o.rmempty = true;
600
601 o = s.taboption('adv_log', form.Value, 'ban_remotetoken', _('Remote Token'), _('Token to communicate with the cgi interface.'));
602 o.depends('ban_remotelog', '1');
603 o.datatype = 'and(minlength(3),maxlength(20))';
604 o.validate = function (section_id, value) {
605 if (!value) {
606 return _('Empty field not allowed');
607 }
608 if (!value.match(/^[A-Za-z0-9\.\:]+$/)) {
609 return _('Invalid characters');
610 }
611 return true;
612 }
613 o.optional = true;
614 o.rmempty = true;
615
616 /*
617 advanced email settings tab
618 */
619 o = s.taboption('adv_email', form.DummyValue, '_sub');
620 o.rawhtml = true;
621 o.default = '<em style="color:#37c;font-weight:bold;">' + _('To enable email notifications, set up the \'msmtp\' package and specify a vaild E-Mail receiver address.') + '</em>';
622
623 o = s.taboption('adv_email', form.Flag, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.'));
624 o.rmempty = true;
625
626 o = s.taboption('adv_email', form.Value, 'ban_mailreceiver', _('E-Mail Receiver Address'), _('Receiver address for banIP notification E-Mails, this information is required to enable E-Mail functionality.'));
627 o.placeholder = 'name@example.com';
628 o.rmempty = true;
629
630 o = s.taboption('adv_email', form.Value, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
631 o.placeholder = 'no-reply@banIP';
632 o.rmempty = true;
633
634 o = s.taboption('adv_email', form.Value, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
635 o.placeholder = 'banIP notification';
636 o.rmempty = true;
637
638 o = s.taboption('adv_email', form.Value, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
639 o.placeholder = 'ban_notify';
640 o.datatype = 'uciname';
641 o.rmempty = true;
642
643 /*
644 feeds tab
645 */
646 o = s.taboption('feeds', form.DummyValue, '_sub');
647 o.rawhtml = true;
648 o.default = '<em style="color:#37c;font-weight:bold;">' + _('External Blocklist Feeds') + '</em>';
649
650 if (feeds) {
651 o = s.taboption('feeds', form.MultiValue, 'ban_feed', _('Blocklist Feed'));
652 for (let i = 0; i < Object.keys(feeds).length; i++) {
653 feed = Object.keys(feeds)[i].trim();
654 descr = feeds[feed].descr.trim() || '-';
655 o.value(feed, feed + ' (' + descr + ')');
656 }
657 o.optional = true;
658 o.rmempty = true;
659 }
660
661 let ccode, rir, country, countries = [];
662 if (result[2]) {
663 countries = result[2].trim().split('\n');
664
665 o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries') + ' (<abbr title="Regional Internet Registries">RIR</abbr>)');
666 for (let i = 0; i < countries.length; i++) {
667 try {
668 ccode = countries[i].match(/^(\w+)\t/)[1].trim();
669 rir = countries[i].match(/^\w+\t(\w+)\t/)[1].trim();
670 country = countries[i].match(/^\w+\t\w+\t(.*$)/)[1].trim();
671 o.value(ccode, country + ' (' + rir + ')');
672 } catch (e) {
673 countries[i] = "";
674 ui.addNotification(null, E('p', _('Unable to parse the countries file: %s').format(e.message)), 'error');
675 }
676 }
677 o.optional = true;
678 o.rmempty = true;
679 }
680
681 o = s.taboption('feeds', form.MultiValue, 'ban_region', _('Regional Internet Registry'));
682 o.value('AFRINIC', _('AFRINIC - serving Africa and the Indian Ocean region'));
683 o.value('APNIC', _('APNIC - serving the Asia Pacific region'));
684 o.value('ARIN', _('ARIN - serving Canada and the United States'));
685 o.value('LACNIC', _('LACNIC - serving the Latin American and Caribbean region'));
686 o.value('RIPE', _('RIPE - serving Europe, Middle East and Central Asia'));
687 o.optional = true;
688 o.rmempty = true;
689
690 o = s.taboption('feeds', form.DynamicList, 'ban_asn', _('ASNs'));
691 o.datatype = 'uinteger';
692 o.optional = true;
693 o.rmempty = true;
694
695 o = s.taboption('feeds', form.DummyValue, '_feeds');
696 o.rawhtml = true;
697 o.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('External Allowlist Feeds') + '</em>';
698
699 o = s.taboption('feeds', form.DynamicList, 'ban_allowurl', _('Allowlist Feed URLs'));
700 if (countries) {
701 for (let i = 0; i < countries.length; i++) {
702 try {
703 ccode = countries[i].match(/^(\w+)\t/)[1].trim();
704 rir = countries[i].match(/^\w+\t(\w+)\t/)[1].trim();
705 country = countries[i].match(/^\w+\t\w+\t(.*$)/)[1].trim();
706 o.value('https://www.ipdeny.com/ipblocks/data/aggregated/' + ccode + '-aggregated.zone', country + ' IPv4 (' + rir + ')');
707 o.value('https://www.ipdeny.com/ipv6/ipaddresses/aggregated/' + ccode + '-aggregated.zone', country + ' IPv6 (' + rir + ')');
708 } catch (e) {
709 countries[i] = "";
710 }
711 }
712 }
713 o.optional = true;
714 o.rmempty = true;
715 o.validate = function (section_id, value) {
716 if (!value) {
717 return true;
718 }
719 if (!value.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) {
720 return _('Protocol/URL format not supported');
721 }
722 return true;
723 }
724
725 o = s.taboption('feeds', form.DummyValue, '_feeds');
726 o.rawhtml = true;
727 o.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('Local Feed Settings') + '</em>';
728
729 o = s.taboption('feeds', form.Flag, 'ban_autoallowlist', _('Auto Allowlist'), _('Automatically add resolved domains and uplink IPs to the local banIP allowlist.'));
730 o.default = 1
731 o.rmempty = false;
732
733 o = s.taboption('feeds', form.ListValue, 'ban_autoallowuplink', _('Auto Allow Uplink'), _('Limit the uplink autoallow function.'));
734 o.depends('ban_autoallowlist', '1');
735 o.value('disable', _('Disable'));
736 o.value('subnet', _('Subnet'));
737 o.value('ip', _('IP'));
738 o.default = 'subnet';
739 o.optional = true;
740 o.rmempty = true;
741
742 o = s.taboption('feeds', form.Flag, 'ban_autoblocklist', _('Auto Blocklist'), _('Automatically add resolved domains and suspicious IPs to the local banIP blocklist.'));
743 o.default = 1
744 o.rmempty = false;
745
746 o = s.taboption('feeds', form.Flag, 'ban_autoblocksubnet', _('Auto Block Subnet'), _('Automatically add entire subnets to the blocklist Set based on an additional RDAP request with the suspicious IP.'));
747 o.default = 0
748 o.optional = true;
749 o.rmempty = true;
750
751 o = s.taboption('feeds', form.ListValue, 'ban_nftexpiry', _('Blocklist Set Expiry'), _('Expiry time for auto added blocklist Set members.'));
752 o.value('10s');
753 o.value('1m');
754 o.value('5m');
755 o.value('1h');
756 o.value('2h');
757 o.value('1d');
758 o.optional = true;
759 o.rmempty = true;
760
761 o = s.taboption('feeds', form.Flag, 'ban_allowlistonly', _('Allowlist Only'), _('Restrict the internet access from/to a small number of secure IPs.'));
762 o.rmempty = false;
763
764 return m.render();
765 },
766 handleReset: null
767 });