luci-app-banip: sync with banIP-0.8.4-1
[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 ip addresses/subnets via sets in nftables. \
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, infSubnets, 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_subnets\s+\:\s+(.*)$/)) {
73 rtRes.activeSubnets = rtRes[i].match(/^\s+\+\sactive_subnets\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 infSubnets = document.getElementById('subnets');
109 if (infSubnets) {
110 infSubnets.textContent = rtRes.activeSubnets || '-';
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 Subnets')),
176 E('div', { 'class': 'cbi-value-field', 'id': 'subnets', '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', _('Blocklist Feeds'));
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.unspecified = true;
268 o.multiple = true;
269 o.nocreate = true;
270 o.optional = true;
271 o.retain = true;
272
273 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv4', _('Network Interfaces'), _('Select the logical WAN IPv4 network interface(s).'));
274 o.depends('ban_autodetect', '0');
275 o.unspecified = true;
276 o.multiple = true;
277 o.nocreate = true;
278 o.optional = true;
279 o.retain = true;
280
281 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifv6', _('Network Interfaces'), _('Select the logical WAN IPv6 network interface(s).'));
282 o.depends('ban_autodetect', '0');
283 o.unspecified = true;
284 o.multiple = true;
285 o.nocreate = true;
286 o.optional = true;
287 o.retain = true;
288
289 o = s.taboption('general', form.ListValue, 'ban_fetchcmd', _('Download Utility'), _('Select one of the pre-configured download utilities.'));
290 o.depends('ban_autodetect', '0');
291 o.value('uclient-fetch');
292 o.value('wget');
293 o.value('curl');
294 o.value('aria2c');
295 o.optional = true;
296 o.retain = true;
297
298 o = s.taboption('general', form.Value, 'ban_fetchparm', _('Download Parameters'), _('Override the pre-configured download options for the selected download utility.'))
299 o.depends('ban_autodetect', '0');
300 o.optional = true;
301 o.retain = true;
302
303 o = s.taboption('general', widgets.NetworkSelect, 'ban_trigger', _('Startup Trigger Interface'), _('List of available network interfaces to trigger the banIP start.'));
304 o.unspecified = true;
305 o.multiple = true;
306 o.nocreate = true;
307 o.rmempty = true;
308
309 o = s.taboption('general', form.Value, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds before banIP processing actually starts.'));
310 o.placeholder = '10';
311 o.datatype = 'range(1,300)';
312 o.rmempty = true;
313
314 o = s.taboption('general', form.ListValue, 'ban_triggeraction', _('Trigger Action'), _('Trigger action on ifup interface events.'));
315 o.value('start', _('start (default)'));
316 o.value('reload', _('reload'));
317 o.value('restart', _('restart'));
318 o.optional = true;
319 o.rmempty = true;
320
321 o = s.taboption('general', form.Flag, 'ban_deduplicate', _('Deduplicate IPs'), _('Deduplicate IP addresses across all active sets and and tidy up the local blocklist.'));
322 o.default = 1
323 o.rmempty = false;
324
325 o = s.taboption('general', form.Flag, 'ban_loginput', _('Log WAN-Input'), _('Log suspicious incoming WAN packets (dropped).'));
326 o.default = 1
327 o.rmempty = false;
328
329 o = s.taboption('general', form.Flag, 'ban_logforwardwan', _('Log WAN-Forward'), _('Log suspicious forwarded WAN packets (dropped).'));
330 o.default = 1
331 o.rmempty = false;
332
333 o = s.taboption('general', form.Flag, 'ban_logforwardlan', _('Log LAN-Forward'), _('Log suspicious forwarded LAN packets (rejected).'));
334 o.rmempty = false;
335
336 /*
337 additional settings tab
338 */
339 o = s.taboption('advanced', form.DummyValue, '_sub');
340 o.rawhtml = true;
341 o.default = '<em><b>' + _('Changes on this tab needs a banIP service restart to take effect.') + '</b></em>';
342
343 o = s.taboption('advanced', form.ListValue, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.'));
344 o.value('-20', _('Highest Priority'));
345 o.value('-10', _('High Priority'));
346 o.value('0', _('Normal Priority (default)'));
347 o.value('10', _('Less Priority'));
348 o.value('19', _('Least Priority'));
349 o.optional = true;
350 o.rmempty = true;
351
352 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.'));
353 o.value('512', _('512'));
354 o.value('1024', _('1024 (default)'));
355 o.value('2048', _('2048'));
356 o.value('4096', _('4096'));
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('256');
371 o.value('512');
372 o.value('1024');
373 o.value('2048');
374 o.value('4096');
375 o.optional = true;
376 o.rmempty = true;
377
378 o = s.taboption('advanced', form.Value, 'ban_basedir', _('Base Directory'), _('Base working directory while banIP processing.'));
379 o.placeholder = '/tmp';
380 o.rmempty = true;
381
382 o = s.taboption('advanced', form.Value, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed feed backups.'));
383 o.placeholder = '/tmp/banIP-backup';
384 o.rmempty = true;
385
386 o = s.taboption('advanced', form.Value, 'ban_reportdir', _('Report Directory'), _('Target directory for banIP-related report files.'));
387 o.placeholder = '/tmp/banIP-report';
388 o.rmempty = true;
389
390 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.'));
391 o.default = 1
392 o.optional = true;
393
394 o = s.taboption('advanced', form.Flag, 'ban_fetchinsecure', _('Download Insecure'), _('Don\'t check SSL server certificates during download.'));
395 o.rmempty = true;
396
397 /*
398 advanced chain/set settings tab
399 */
400 o = s.taboption('adv_chain', form.DummyValue, '_sub');
401 o.rawhtml = true;
402 o.default = '<em><b>' + _('Changes on this tab needs a banIP service restart to take effect.') + '</b></em>';
403
404 o = s.taboption('adv_chain', form.ListValue, 'ban_nftpolicy', _('NFT Set Policy'), _('Set the nft policy for banIP-related Sets.'));
405 o.value('memory', _('memory (default)'));
406 o.value('performance', _('performance'));
407 o.optional = true;
408 o.rmempty = true;
409
410 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.'));
411 o.value('0', _('0'));
412 o.value('-100', _('-100'));
413 o.value('-200', _('-200 (default)'));
414 o.value('-300', _('-300'));
415 o.value('-400', _('-400'));
416 o.optional = true;
417 o.rmempty = true;
418
419 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.'));
420 o.value('input', _('WAN-Input Chain'));
421 o.value('forwardwan', _('WAN-Forward Chain'));
422 o.value('forwardlan', _('LAN-Forward Chain'));
423 o.optional = true;
424 o.rmempty = true;
425
426 let feed, feeds, descr;
427 if (result[0]) {
428 feeds = JSON.parse(result[0]);
429 } else if (result[1]) {
430 feeds = JSON.parse(result[1]);
431 }
432 if (feeds) {
433 o = s.taboption('adv_chain', form.MultiValue, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.'));
434 o.value('allowlist', _('local allowlist'));
435 o.value('blocklist', _('local blocklist'));
436 for (let i = 0; i < Object.keys(feeds).length; i++) {
437 feed = Object.keys(feeds)[i].trim();
438 o.value(feed);
439 }
440 o.optional = true;
441 o.rmempty = true;
442
443 o = s.taboption('adv_chain', form.MultiValue, 'ban_blockforwardwan', _('WAN-Forward Chain'), _('Limit certain feeds to the WAN-Forward chain.'));
444 o.value('allowlist', _('local allowlist'));
445 o.value('blocklist', _('local blocklist'));
446 for (let i = 0; i < Object.keys(feeds).length; i++) {
447 feed = Object.keys(feeds)[i].trim();
448 o.value(feed);
449 }
450 o.optional = true;
451 o.rmempty = true;
452
453 o = s.taboption('adv_chain', form.MultiValue, 'ban_blockforwardlan', _('LAN-Forward Chain'), _('Limit certain feeds to the LAN-Forward chain.'));
454 o.value('allowlist', _('local allowlist'));
455 o.value('blocklist', _('local blocklist'));
456 for (let i = 0; i < Object.keys(feeds).length; i++) {
457 feed = Object.keys(feeds)[i].trim();
458 o.value(feed);
459 }
460 o.optional = true;
461 o.rmempty = true;
462 }
463
464 o = s.taboption('adv_chain', form.ListValue, 'ban_nftexpiry', _('Blocklist Expiry'), _('Expiry time for auto added blocklist set members.'));
465 o.value('10s');
466 o.value('1m');
467 o.value('5m');
468 o.value('1h');
469 o.value('2h');
470 o.optional = true;
471 o.rmempty = true;
472
473 /*
474 advanced log settings tab
475 */
476 o = s.taboption('adv_log', form.DummyValue, '_sub');
477 o.rawhtml = true;
478 o.default = '<em><b>' + _('Changes on this tab needs a banIP service restart to take effect.') + '</b></em>';
479
480 o = s.taboption('adv_log', form.ListValue, 'ban_nftloglevel', _('Log Level'), _('Set the syslog level for NFT logging.'));
481 o.value('emerg', _('emerg'));
482 o.value('alert', _('alert'));
483 o.value('crit', _('crit'));
484 o.value('err', _('err'));
485 o.value('warn', _('warn (default)'));
486 o.value('notice', _('notice'));
487 o.value('info', _('info'));
488 o.value('debug', _('debug'));
489 o.optional = true;
490 o.rmempty = true;
491
492 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\'.'));
493 o.value('0', _('0 (disable)'));
494 o.value('50', _('50'));
495 o.value('100', _('100 (default)'));
496 o.value('250', _('250'));
497 o.value('500', _('500'));
498 o.value('1000', _('1000'));
499 o.optional = true;
500 o.rmempty = true;
501
502 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.'));
503 o.placeholder = '1';
504 o.datatype = 'range(1,10)';
505 o.rmempty = true;
506
507 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.'));
508 o.optional = true;
509 o.rmempty = true;
510
511 /*
512 advanced email settings tab
513 */
514 o = s.taboption('adv_email', form.DummyValue, '_sub');
515 o.rawhtml = true;
516 o.default = '<em><b>' + _('To enable email notifications, set up the \'msmtp\' package and specify a vaild E-Mail receiver address.') + '</b></em>';
517
518 o = s.taboption('adv_email', form.Flag, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.'));
519 o.rmempty = true;
520
521 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.'));
522 o.placeholder = 'name@example.com';
523 o.rmempty = true;
524
525 o = s.taboption('adv_email', form.Value, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
526 o.placeholder = 'no-reply@banIP';
527 o.rmempty = true;
528
529 o = s.taboption('adv_email', form.Value, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
530 o.placeholder = 'banIP notification';
531 o.rmempty = true;
532
533 o = s.taboption('adv_email', form.Value, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
534 o.placeholder = 'ban_notify';
535 o.datatype = 'uciname';
536 o.rmempty = true;
537
538 /*
539 blocklist feeds tab
540 */
541 o = s.taboption('feeds', form.DummyValue, '_sub');
542 o.rawhtml = true;
543 o.default = '<em><b>' + _('List of supported and fully pre-configured banIP feeds.') + '</b></em>';
544
545 if (feeds) {
546 o = s.taboption('feeds', form.MultiValue, 'ban_feed', _('Feed Selection'));
547 for (let i = 0; i < Object.keys(feeds).length; i++) {
548 feed = Object.keys(feeds)[i].trim();
549 descr = feeds[feed].descr.trim() || '-';
550 o.value(feed, feed + ' (' + descr + ')');
551 }
552 o.optional = true;
553 o.rmempty = true;
554 }
555
556 /*
557 prepare country data
558 */
559 let code, country, countries = [];
560 if (result[2]) {
561 countries = result[2].trim().split('\n');
562
563 o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries'));
564 for (let i = 0; i < countries.length; i++) {
565 code = countries[i].match(/^(\w+);/)[1].trim();
566 country = countries[i].match(/^\w+;(.*$)/)[1].trim();
567 o.value(code, country);
568 }
569 o.optional = true;
570 o.rmempty = true;
571 }
572
573 o = s.taboption('feeds', form.DynamicList, 'ban_asn', _('ASNs'));
574 o.datatype = 'uinteger';
575 o.optional = true;
576 o.rmempty = true;
577
578 o = s.taboption('feeds', form.Flag, 'ban_autoallowlist', _('Auto Allowlist'), _('Automatically transfers uplink IPs to the banIP allowlist.'));
579 o.default = 1
580 o.rmempty = false;
581
582 o = s.taboption('feeds', form.Flag, 'ban_autoblocklist', _('Auto Blocklist'), _('Automatically transfers suspicious IPs to the banIP blocklist.'));
583 o.default = 1
584 o.rmempty = false;
585
586 o = s.taboption('feeds', form.Flag, 'ban_allowlistonly', _('Allowlist Only'), _('Restrict the internet access from/to a small number of secure IPs.'));
587 o.rmempty = false;
588
589 return m.render();
590 },
591 handleReset: null
592 });