luci-app-banip: Remove unused unspecified option
[project/luci.git] / applications / luci-app-banip / htdocs / luci-static / resources / view / banip / overview.js
1 'use strict';
2 'require view';
3 'require poll';
4 'require fs';
5 'require ui';
6 'require uci';
7 'require form';
8 'require tools.widgets as widgets';
9
10 /*
11 button handling
12 */
13 function handleAction(ev) {
14 fs.exec_direct('/etc/init.d/banip', [ev])
15 }
16
17 return view.extend({
18 load: function () {
19 return Promise.all([
20 L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds'), ''),
21 L.resolveDefault(fs.read_direct('/etc/banip/banip.feeds'), ''),
22 L.resolveDefault(fs.read_direct('/etc/banip/banip.countries'), ''),
23 uci.load('banip')
24 ]);
25 },
26
27 render: function (result) {
28 let m, s, o;
29
30 m = new form.Map('banip', 'banIP', _('Configuration of the banIP package to ban incoming and outgoing IPs via named nftables Sets. \
31 For further information <a href="https://github.com/openwrt/packages/blob/master/net/banip/files/README.md" target="_blank" rel="noreferrer noopener" >check the online documentation</a>'));
32
33 /*
34 poll runtime information
35 */
36 let buttons, rtRes, infStat, infVer, infElements, infFeeds, infDevices, infUplink, infSystem, nftInfos, runInfos, infFlags, last_run
37
38 pollData: poll.add(function () {
39 return L.resolveDefault(fs.stat('/var/run/banip.lock')).then(function (stat) {
40 buttons = document.querySelectorAll('.cbi-button');
41 infStat = document.getElementById('status');
42 if (stat) {
43 for (let i = 0; i < buttons.length; i++) {
44 buttons[i].setAttribute('disabled', 'true');
45 }
46 if (infStat && !infStat.classList.contains('spinning')) {
47 infStat.classList.add('spinning');
48 }
49 } else {
50 for (let i = 0; i < buttons.length; i++) {
51 buttons[i].removeAttribute('disabled');
52 }
53 if (infStat && infStat.classList.contains('spinning')) {
54 infStat.classList.remove('spinning');
55 }
56 }
57 L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['status'])).then(function (result) {
58 if (result) {
59 rtRes = result.trim().split('\n');
60 if (rtRes) {
61 for (let i = 0; i < rtRes.length; i++) {
62 if (rtRes[i].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)) {
63 rtRes.status = rtRes[i].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)[1];
64 } else if (rtRes[i].match(/^\s+\+\sversion\s+\:\s+(.*)$/)) {
65 rtRes.version = rtRes[i].match(/^\s+\+\sversion\s+\:\s+(.*)$/)[1];
66 } else if (rtRes[i].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)) {
67 rtRes.elementCount = rtRes[i].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)[1];
68 } else if (rtRes[i].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)) {
69 rtRes.activeFeeds = rtRes[i].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)[1];
70 } else if (rtRes[i].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)) {
71 rtRes.activeDevices = rtRes[i].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)[1];
72 } else if (rtRes[i].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)) {
73 rtRes.activeUplink = rtRes[i].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)[1];
74 } else if (rtRes[i].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)) {
75 rtRes.nftInfo = rtRes[i].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)[1];
76 } else if (rtRes[i].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)) {
77 rtRes.runInfo = rtRes[i].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)[1];
78 } else if (rtRes[i].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)) {
79 rtRes.runFlags = rtRes[i].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)[1];
80 } else if (rtRes[i].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)) {
81 rtRes.lastRun = rtRes[i].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)[1];
82 } else if (rtRes[i].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)) {
83 rtRes.systemInfo = rtRes[i].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)[1];
84 }
85 }
86 }
87 if (rtRes) {
88 infStat = document.getElementById('status');
89 if (infStat) {
90 infStat.textContent = rtRes.status || '-';
91 }
92 infVer = document.getElementById('version');
93 if (infVer) {
94 infVer.textContent = rtRes.version || '-';
95 }
96 infElements = document.getElementById('elements');
97 if (infElements) {
98 infElements.textContent = rtRes.elementCount || '-';
99 }
100 infFeeds = document.getElementById('feeds');
101 if (infFeeds) {
102 infFeeds.textContent = rtRes.activeFeeds || '-';
103 }
104 infDevices = document.getElementById('devices');
105 if (infDevices) {
106 infDevices.textContent = rtRes.activeDevices || '-';
107 }
108 infUplink = document.getElementById('uplink');
109 if (infUplink) {
110 infUplink.textContent = rtRes.activeUplink || '-';
111 }
112 nftInfos = document.getElementById('nft');
113 if (nftInfos) {
114 nftInfos.textContent = rtRes.nftInfo || '-';
115 }
116 runInfos = document.getElementById('run');
117 if (runInfos) {
118 runInfos.textContent = rtRes.runInfo || '-';
119 }
120 infFlags = document.getElementById('flags');
121 if (infFlags) {
122 infFlags.textContent = rtRes.runFlags || '-';
123 }
124 last_run = document.getElementById('last');
125 if (last_run) {
126 last_run.textContent = rtRes.lastRun || '-';
127 }
128 infSystem = document.getElementById('system');
129 if (infSystem) {
130 infSystem.textContent = rtRes.systemInfo || '-';
131 }
132 }
133 } else {
134 infStat = document.getElementById('status');
135 if (infStat) {
136 infStat.textContent = '-';
137 poll.stop();
138 if (infStat.classList.contains('spinning')) {
139 infStat.classList.remove('spinning');
140 }
141 }
142 }
143 });
144 });
145 }, 2);
146
147 /*
148 runtime information and buttons
149 */
150 s = m.section(form.NamedSection, 'global');
151 s.render = L.bind(function (view, section_id) {
152 return E('div', { 'class': 'cbi-section' }, [
153 E('h3', _('Information')),
154 E('div', { 'class': 'cbi-value' }, [
155 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Status')),
156 E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'color:#37c' }, '\xa0')
157 ]),
158 E('div', { 'class': 'cbi-value' }, [
159 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Version')),
160 E('div', { 'class': 'cbi-value-field', 'id': 'version', 'style': 'color:#37c' }, '-')
161 ]),
162 E('div', { 'class': 'cbi-value' }, [
163 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Element Count')),
164 E('div', { 'class': 'cbi-value-field', 'id': 'elements', 'style': 'color:#37c' }, '-')
165 ]),
166 E('div', { 'class': 'cbi-value' }, [
167 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Feeds')),
168 E('div', { 'class': 'cbi-value-field', 'id': 'feeds', 'style': 'color:#37c' }, '-')
169 ]),
170 E('div', { 'class': 'cbi-value' }, [
171 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Devices')),
172 E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'color:#37c' }, '-')
173 ]),
174 E('div', { 'class': 'cbi-value' }, [
175 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Uplink')),
176 E('div', { 'class': 'cbi-value-field', 'id': 'uplink', 'style': 'color:#37c' }, '-')
177 ]),
178 E('div', { 'class': 'cbi-value' }, [
179 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('NFT Information')),
180 E('div', { 'class': 'cbi-value-field', 'id': 'nft', 'style': 'color:#37c' }, '-')
181 ]),
182 E('div', { 'class': 'cbi-value' }, [
183 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Run Information')),
184 E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'color:#37c' }, '-')
185 ]),
186 E('div', { 'class': 'cbi-value' }, [
187 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Run Flags')),
188 E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'color:#37c' }, '-')
189 ]),
190 E('div', { 'class': 'cbi-value' }, [
191 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Last Run')),
192 E('div', { 'class': 'cbi-value-field', 'id': 'last', 'style': 'color:#37c' }, '-')
193 ]),
194 E('div', { 'class': 'cbi-value' }, [
195 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('System Information')),
196 E('div', { 'class': 'cbi-value-field', 'id': 'system', 'style': 'color:#37c' }, '-')
197 ]),
198 E('div', { class: 'right' }, [
199 E('button', {
200 'class': 'btn cbi-button cbi-button-action',
201 'click': ui.createHandlerFn(this, function () {
202 return handleAction('lookup');
203 })
204 }, [_('Domain Lookup')]),
205 '\xa0\xa0\xa0',
206 E('button', {
207 'class': 'btn cbi-button cbi-button-negative',
208 'click': ui.createHandlerFn(this, function () {
209 return handleAction('stop');
210 })
211 }, [_('Stop')]),
212 '\xa0\xa0\xa0',
213 E('button', {
214 'class': 'btn cbi-button cbi-button-positive',
215 'click': ui.createHandlerFn(this, function () {
216 return handleAction('reload');
217 })
218 }, [_('Reload')]),
219 '\xa0\xa0\xa0',
220 E('button', {
221 'class': 'btn cbi-button cbi-button-positive',
222 'click': ui.createHandlerFn(this, function () {
223 return handleAction('restart');
224 })
225 }, [_('Restart')])
226 ])
227 ]);
228 }, o, this);
229 this.pollData;
230
231 /*
232 tabbed config section
233 */
234 s = m.section(form.NamedSection, 'global', 'banip', _('Settings'));
235 s.addremove = false;
236 s.tab('general', _('General Settings'));
237 s.tab('advanced', _('Advanced Settings'));
238 s.tab('adv_chain', _('Chain/Set Settings'));
239 s.tab('adv_log', _('Log Settings'));
240 s.tab('adv_email', _('E-Mail Settings'));
241 s.tab('feeds', _('Feed Selection'));
242
243 /*
244 general settings tab
245 */
246 o = s.taboption('general', form.Flag, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
247 o.rmempty = false;
248
249 o = s.taboption('general', form.Flag, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of processing errors.'));
250 o.rmempty = false;
251
252 o = s.taboption('general', form.Flag, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network devices, interfaces, subnets, protocols and utilities automatically.'));
253 o.rmempty = false;
254
255 o = s.taboption('general', form.Flag, 'ban_protov4', _('IPv4 Support'), _('Enables IPv4 support.'));
256 o.depends('ban_autodetect', '0');
257 o.optional = true;
258 o.retain = true;
259
260 o = s.taboption('general', form.Flag, 'ban_protov6', _('IPv6 Support'), _('Enables IPv6 support.'));
261 o.depends('ban_autodetect', '0');
262 o.optional = true;
263 o.retain = true;
264
265 o = s.taboption('general', widgets.DeviceSelect, 'ban_dev', _('Network Devices'), _('Select the WAN network device(s).'));
266 o.depends('ban_autodetect', '0');
267 o.multiple = true;
268 o.nocreate = true;
269 o.optional = true;
270 o.retain = true;
271
272 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv4', _('Network Interfaces'), _('Select the logical WAN IPv4 network interface(s).'));
273 o.depends('ban_autodetect', '0');
274 o.multiple = true;
275 o.nocreate = true;
276 o.optional = true;
277 o.retain = true;
278
279 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv6', _('Network Interfaces'), _('Select the logical WAN IPv6 network interface(s).'));
280 o.depends('ban_autodetect', '0');
281 o.multiple = true;
282 o.nocreate = true;
283 o.optional = true;
284 o.retain = true;
285
286 o = s.taboption('general', form.ListValue, 'ban_fetchcmd', _('Download Utility'), _('Select one of the pre-configured download utilities.'));
287 o.depends('ban_autodetect', '0');
288 o.value('uclient-fetch');
289 o.value('wget');
290 o.value('curl');
291 o.value('aria2c');
292 o.optional = true;
293 o.retain = true;
294
295 o = s.taboption('general', form.Value, 'ban_fetchparm', _('Download Parameters'), _('Override the pre-configured download options for the selected download utility.'))
296 o.depends('ban_autodetect', '0');
297 o.optional = true;
298 o.retain = true;
299
300 o = s.taboption('general', widgets.NetworkSelect, 'ban_trigger', _('Startup Trigger Interface'), _('List of available network interfaces to trigger the banIP start.'));
301 o.multiple = true;
302 o.nocreate = true;
303 o.rmempty = true;
304
305 o = s.taboption('general', form.Value, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds before banIP processing actually starts.'));
306 o.placeholder = '10';
307 o.datatype = 'range(1,300)';
308 o.rmempty = true;
309
310 o = s.taboption('general', form.ListValue, 'ban_triggeraction', _('Trigger Action'), _('Trigger action on ifup interface events.'));
311 o.value('start', _('start (default)'));
312 o.value('reload', _('reload'));
313 o.value('restart', _('restart'));
314 o.optional = true;
315 o.rmempty = true;
316
317 o = s.taboption('general', form.ListValue, 'ban_fetchretry', _('Download Retries'), _('Number of download attempts in case of an error (not supported by uclient-fetch).'));
318 o.value('1', _('1'));
319 o.value('3', _('3'));
320 o.value('5', _('5 (default)'));
321 o.value('10', _('10'));
322 o.value('20', _('20'));
323 o.optional = true;
324 o.rmempty = true;
325
326 o = s.taboption('general', form.Flag, 'ban_fetchinsecure', _('Download Insecure'), _('Don\'t check SSL server certificates during download.'));
327 o.rmempty = true;
328
329 /*
330 additional settings tab
331 */
332 o = s.taboption('advanced', form.DummyValue, '_sub');
333 o.rawhtml = true;
334 o.default = '<em><b>' + _('Changes on this tab needs a banIP service restart to take effect.') + '</b></em>';
335
336 o = s.taboption('advanced', form.ListValue, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.'));
337 o.value('-20', _('Highest Priority'));
338 o.value('-10', _('High Priority'));
339 o.value('0', _('Normal Priority (default)'));
340 o.value('10', _('Less Priority'));
341 o.value('19', _('Least Priority'));
342 o.optional = true;
343 o.rmempty = true;
344
345 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.'));
346 o.value('512', _('512'));
347 o.value('1024', _('1024 (default)'));
348 o.value('2048', _('2048'));
349 o.value('4096', _('4096'));
350 o.optional = true;
351 o.rmempty = true;
352
353 o = s.taboption('advanced', form.ListValue, 'ban_cores', _('CPU Cores'), _('Limit the cpu cores used by banIP to save RAM.'));
354 o.value('1');
355 o.value('2');
356 o.value('4');
357 o.value('8');
358 o.value('16');
359 o.optional = true;
360 o.rmempty = true;
361
362 o = s.taboption('advanced', form.ListValue, 'ban_splitsize', _('Set Split Size'), _('Split external Set loading after every n members to save RAM.'));
363 o.value('256');
364 o.value('512');
365 o.value('1024');
366 o.value('2048');
367 o.value('4096');
368 o.optional = true;
369 o.rmempty = true;
370
371 o = s.taboption('advanced', form.Value, 'ban_basedir', _('Base Directory'), _('Base working directory while banIP processing.'));
372 o.placeholder = '/tmp';
373 o.rmempty = true;
374
375 o = s.taboption('advanced', form.Value, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed feed backups.'));
376 o.placeholder = '/tmp/banIP-backup';
377 o.rmempty = true;
378
379 o = s.taboption('advanced', form.Value, 'ban_reportdir', _('Report Directory'), _('Target directory for banIP-related report files.'));
380 o.placeholder = '/tmp/banIP-report';
381 o.rmempty = true;
382
383 o = s.taboption('advanced', form.Flag, 'ban_deduplicate', _('Deduplicate IPs'), _('Deduplicate IP addresses across all active Sets and tidy up the local blocklist.'));
384 o.default = 1
385 o.rmempty = false;
386
387 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.'));
388 o.default = 1
389 o.optional = true;
390
391 /*
392 advanced chain/set settings tab
393 */
394 o = s.taboption('adv_chain', form.DummyValue, '_sub');
395 o.rawhtml = true;
396 o.default = '<em><b>' + _('Changes on this tab needs a banIP service restart to take effect.') + '</b></em>';
397
398 o = s.taboption('adv_chain', form.ListValue, 'ban_nftpolicy', _('NFT Set Policy'), _('Set the nft policy for banIP-related Sets.'));
399 o.value('memory', _('memory (default)'));
400 o.value('performance', _('performance'));
401 o.optional = true;
402 o.rmempty = true;
403
404 o = s.taboption('adv_chain', form.ListValue, 'ban_nftpriority', _('NFT Chain Priority'), _('Set the nft chain priority within the banIP table. Please note: lower values means higher priority.'));
405 o.value('0', _('0'));
406 o.value('-100', _('-100'));
407 o.value('-200', _('-200 (default)'));
408 o.value('-300', _('-300'));
409 o.value('-400', _('-400'));
410 o.optional = true;
411 o.rmempty = true;
412
413 o = s.taboption('adv_chain', widgets.DeviceSelect, 'ban_vlanallow', _('Allow VLAN Forwads'), _('Always allow certain VLAN forwards.'));
414 o.multiple = true;
415 o.nocreate = true;
416 o.optional = true;
417 o.rmempty = true;
418
419 o = s.taboption('adv_chain', widgets.DeviceSelect, 'ban_vlanblock', _('Block VLAN Forwads'), _('Always block 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', 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.'));
426 o.value('input', _('WAN-Input Chain'));
427 o.value('forwardwan', _('WAN-Forward Chain'));
428 o.value('forwardlan', _('LAN-Forward Chain'));
429 o.optional = true;
430 o.rmempty = true;
431
432 let feed, feeds, descr;
433 if (result[0]) {
434 feeds = JSON.parse(result[0]);
435 } else if (result[1]) {
436 feeds = JSON.parse(result[1]);
437 }
438 if (feeds) {
439 o = s.taboption('adv_chain', form.MultiValue, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.'));
440 o.value('allowlist', _('local allowlist'));
441 o.value('blocklist', _('local blocklist'));
442 for (let i = 0; i < Object.keys(feeds).length; i++) {
443 feed = Object.keys(feeds)[i].trim();
444 o.value(feed);
445 }
446 o.optional = true;
447 o.rmempty = true;
448
449 o = s.taboption('adv_chain', form.MultiValue, 'ban_blockforwardwan', _('WAN-Forward Chain'), _('Limit certain feeds to the WAN-Forward chain.'));
450 o.value('allowlist', _('local allowlist'));
451 o.value('blocklist', _('local blocklist'));
452 for (let i = 0; i < Object.keys(feeds).length; i++) {
453 feed = Object.keys(feeds)[i].trim();
454 o.value(feed);
455 }
456 o.optional = true;
457 o.rmempty = true;
458
459 o = s.taboption('adv_chain', form.MultiValue, 'ban_blockforwardlan', _('LAN-Forward Chain'), _('Limit certain feeds to the LAN-Forward chain.'));
460 o.value('allowlist', _('local allowlist'));
461 o.value('blocklist', _('local blocklist'));
462 for (let i = 0; i < Object.keys(feeds).length; i++) {
463 feed = Object.keys(feeds)[i].trim();
464 o.value(feed);
465 }
466 o.optional = true;
467 o.rmempty = true;
468 }
469
470 /*
471 advanced log settings tab
472 */
473 o = s.taboption('adv_log', form.DummyValue, '_sub');
474 o.rawhtml = true;
475 o.default = '<em><b>' + _('Changes on this tab needs a banIP service restart to take effect.') + '</b></em>';
476
477 o = s.taboption('adv_log', form.ListValue, 'ban_nftloglevel', _('Log Level'), _('Set the syslog level for NFT logging.'));
478 o.value('emerg', _('emerg'));
479 o.value('alert', _('alert'));
480 o.value('crit', _('crit'));
481 o.value('err', _('err'));
482 o.value('warn', _('warn (default)'));
483 o.value('notice', _('notice'));
484 o.value('info', _('info'));
485 o.value('debug', _('debug'));
486 o.optional = true;
487 o.rmempty = true;
488
489 o = s.taboption('adv_log', form.Flag, 'ban_loginput', _('Log WAN-Input'), _('Log suspicious incoming WAN packets (dropped).'));
490 o.default = 1
491 o.rmempty = false;
492
493 o = s.taboption('adv_log', form.Flag, 'ban_logforwardwan', _('Log WAN-Forward'), _('Log suspicious forwarded WAN packets (dropped).'));
494 o.default = 1
495 o.rmempty = false;
496
497 o = s.taboption('adv_log', form.Flag, 'ban_logforwardlan', _('Log LAN-Forward'), _('Log suspicious forwarded LAN packets (rejected).'));
498 o.rmempty = false;
499
500 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\'.'));
501 o.value('0', _('0 (disable)'));
502 o.value('50', _('50'));
503 o.value('100', _('100 (default)'));
504 o.value('250', _('250'));
505 o.value('500', _('500'));
506 o.value('1000', _('1000'));
507 o.optional = true;
508 o.rmempty = true;
509
510 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.'));
511 o.placeholder = '1';
512 o.datatype = 'range(1,10)';
513 o.rmempty = true;
514
515 o = s.taboption('adv_log', form.DynamicList, 'ban_logterm', _('Log Terms'), _('The default log terms / regular expressions are filtering suspicious ssh, LuCI, nginx and asterisk traffic.'));
516 o.optional = true;
517 o.rmempty = true;
518
519 /*
520 advanced email settings tab
521 */
522 o = s.taboption('adv_email', form.DummyValue, '_sub');
523 o.rawhtml = true;
524 o.default = '<em><b>' + _('To enable email notifications, set up the \'msmtp\' package and specify a vaild E-Mail receiver address.') + '</b></em>';
525
526 o = s.taboption('adv_email', form.Flag, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.'));
527 o.rmempty = true;
528
529 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.'));
530 o.placeholder = 'name@example.com';
531 o.rmempty = true;
532
533 o = s.taboption('adv_email', form.Value, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
534 o.placeholder = 'no-reply@banIP';
535 o.rmempty = true;
536
537 o = s.taboption('adv_email', form.Value, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
538 o.placeholder = 'banIP notification';
539 o.rmempty = true;
540
541 o = s.taboption('adv_email', form.Value, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
542 o.placeholder = 'ban_notify';
543 o.datatype = 'uciname';
544 o.rmempty = true;
545
546 /*
547 feeds tab
548 */
549 o = s.taboption('feeds', form.DummyValue, '_sub');
550 o.rawhtml = true;
551 o.default = '<em><b>' + _('External blocklist feeds') + '</b></em>';
552
553 if (feeds) {
554 o = s.taboption('feeds', form.MultiValue, 'ban_feed', _('Blocklist Feed Selection'));
555 for (let i = 0; i < Object.keys(feeds).length; i++) {
556 feed = Object.keys(feeds)[i].trim();
557 descr = feeds[feed].descr.trim() || '-';
558 o.value(feed, feed + ' (' + descr + ')');
559 }
560 o.optional = true;
561 o.rmempty = true;
562 }
563
564 let code, country, countries = [];
565 if (result[2]) {
566 countries = result[2].trim().split('\n');
567
568 o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries'));
569 for (let i = 0; i < countries.length; i++) {
570 code = countries[i].match(/^(\w+);/)[1].trim();
571 country = countries[i].match(/^\w+;(.*$)/)[1].trim();
572 o.value(code, country);
573 }
574 o.optional = true;
575 o.rmempty = true;
576 }
577
578 o = s.taboption('feeds', form.DynamicList, 'ban_asn', _('ASNs'));
579 o.datatype = 'uinteger';
580 o.optional = true;
581 o.rmempty = true;
582
583 o = s.taboption('feeds', form.DummyValue, '_feeds');
584 o.rawhtml = true;
585 o.default = '<hr style="width: 200px; height: 1px;" /><em><b>' + _('External allowlist feeds') + '</b></em>';
586
587 o = s.taboption('feeds', form.DynamicList, 'ban_allowurl', _('Allowlist Feed Selection'));
588 o.optional = true;
589 o.rmempty = true;
590 o.validate = function (section_id, value) {
591 if (!value) {
592 return true;
593 }
594 if (!value.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) {
595 return _('Protocol/URL format not supported');
596 }
597 return true;
598 }
599
600 o = s.taboption('feeds', form.DummyValue, '_feeds');
601 o.rawhtml = true;
602 o.default = '<hr style="width: 200px; height: 1px;" /><em><b>' + _('Local feed settings') + '</b></em>';
603
604 o = s.taboption('feeds', form.Flag, 'ban_autoallowlist', _('Auto Allowlist'), _('Automatically add resolved domains and uplink IPs to the local banIP allowlist.'));
605 o.default = 1
606 o.rmempty = false;
607
608 o = s.taboption('feeds', form.ListValue, 'ban_autoallowuplink', _('Auto Allow Uplink'), _('Limit the uplink autoallow function.'));
609 o.depends('ban_autoallowlist', '1');
610 o.value('disable', _('Disable'));
611 o.value('subnet', _('Subnet (default)'));
612 o.value('ip', _('IP'));
613 o.optional = true;
614 o.rmempty = true;
615
616 o = s.taboption('feeds', form.Flag, 'ban_autoblocklist', _('Auto Blocklist'), _('Automatically add resolved domains and suspicious IPs to the local banIP blocklist.'));
617 o.default = 1
618 o.rmempty = false;
619
620 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.'));
621 o.default = 0
622 o.optional = true;
623 o.rmempty = true;
624
625 o = s.taboption('feeds', form.ListValue, 'ban_nftexpiry', _('Blocklist Set Expiry'), _('Expiry time for auto added blocklist Set members.'));
626 o.value('10s');
627 o.value('1m');
628 o.value('5m');
629 o.value('1h');
630 o.value('2h');
631 o.value('1d');
632 o.optional = true;
633 o.rmempty = true;
634
635 o = s.taboption('feeds', form.Flag, 'ban_allowlistonly', _('Allowlist Only'), _('Restrict the internet access from/to a small number of secure IPs.'));
636 o.rmempty = false;
637
638 return m.render();
639 },
640 handleReset: null
641 });