summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js
blob: 60e5025c11f6ac7f479027bcebf12d3176aec7cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
'use strict';
'require view';
'require poll';
'require fs';
'require ui';
'require uci';
'require form';
'require tools.widgets as widgets';

/*
	button handling
*/
function handleAction(ev) {
	if (ev === 'timer') {
		L.ui.showModal(_('Refresh Timer'), [
			E('p', _('To keep your banIP lists up-to-date, you should setup an automatic update job for these lists.')),
			E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
				E('h5', _('Existing job(s)')),
				E('textarea', {
					'id': 'cronView',
					'style': 'width: 100% !important; padding: 5px; font-family: monospace',
					'readonly': 'readonly',
					'wrap': 'off',
					'rows': 5
				})
			]),
			E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
				E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em' }, [
					E('h5', _('Set a new banIP job')),
					E('select', { 'class': 'cbi-input-select', 'id': 'timerA' }, [
						E('option', { 'value': 'start' }, 'Start'),
						E('option', { 'value': 'reload' }, 'Reload'),
						E('option', { 'value': 'restart' }, 'Restart'),
						E('option', { 'value': 'refresh' }, 'Refresh'),
						E('option', { 'value': 'suspend' }, 'Suspend'),
						E('option', { 'value': 'resume' }, 'Resume'),
						E('option', { 'value': 'report gen' }, 'Report'),
						E('option', { 'value': 'report mail' }, 'Report & Mail')
					]),
					'\xa0\xa0\xa0',
					_('banIP action')
				]),
				E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
					E('input', { 'class': 'cbi-input-text', 'id': 'timerH', 'maxlength': '2' }, [
					]),
					'\xa0\xa0\xa0',
					_('The hours portition (req., range: 0-23)')
				]),
				E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
					E('input', { 'class': 'cbi-input-text', 'id': 'timerM', 'maxlength': '2' }),
					'\xa0\xa0\xa0',
					_('The minutes portion (opt., range: 0-59)')
				]),
				E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
					E('input', { 'class': 'cbi-input-text', 'id': 'timerD', 'maxlength': '13' }),
					'\xa0\xa0\xa0',
					_('The day of the week (opt., values: 1-7 possibly sep. by , or -)')
				])
			]),
			E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
				E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em' }, [
					E('h5', _('Remove an existing job')),
					E('input', { 'class': 'cbi-input-text', 'id': 'lineno', 'maxlength': '2' }, [
					]),
					'\xa0\xa0\xa0',
					_('Line number to remove')
				])
			]),
			E('div', { 'class': 'right' }, [
				E('button', {
					'class': 'btn cbi-button',
					'click': L.hideModal
				}, _('Cancel')),
				' ',
				E('button', {
					'class': 'btn cbi-button-action',
					'click': ui.createHandlerFn(this, function(ev) {
						var lineno  = document.getElementById('lineno').value;
						var action  = document.getElementById('timerA').value;
						var hours   = document.getElementById('timerH').value;
						var minutes = document.getElementById('timerM').value || '0';
						var days    = document.getElementById('timerD').value || '*';
						if (hours) {
							L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['timer', 'add', action, hours, minutes, days]))
							.then(function(res) {
								if (res) {
									ui.addNotification(null, E('p', _('The Refresh Timer could not been updated.')), 'error');
								} else {
									ui.addNotification(null, E('p', _('The Refresh Timer has been updated.')), 'info');
								}
							});
						} else if (lineno) {
							L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['timer', 'remove', lineno]))
							.then(function(res) {
								if (res) {
									ui.addNotification(null, E('p', _('The Refresh Timer could not been updated.')), 'error');
								} else {
									ui.addNotification(null, E('p', _('The Refresh Timer has been updated.')), 'info');
								}
							});
						} else {
							document.getElementById('timerH').focus();
							return
						}
						L.hideModal();
					})
				}, _('Save'))
			])
		]);
		L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['timer', 'list']))
		.then(function(res) {
			document.getElementById('cronView').value = res.trim();
		});
		document.getElementById('timerH').focus();
		return
	}

	if (document.getElementById('status') && document.getElementById('status').textContent.substr(0,6) === 'paused') {
		ev = 'resume';
	}

	fs.exec_direct('/etc/init.d/banip', [ev])
}

return view.extend({
	load: function() {
		return Promise.all([
			L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['list']), {}),
			L.resolveDefault(fs.exec_direct('/usr/sbin/iptables', ['-L']), null),
			L.resolveDefault(fs.exec_direct('/usr/sbin/ip6tables', ['-L']), null),
			L.resolveDefault(fs.read_direct('/etc/banip/banip.countries'), ''),
			uci.load('banip')
		]);
	},

	render: function(result) {
		var m, s, o;

		m = new form.Map('banip', 'banIP', _('Configuration of the banIP package to block ip adresses/subnets via IPSet. \
			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>'));

		/*
			poll runtime information
		*/
		var rt_res, inf_stat, inf_ipsets, inf_sources, inf_srcarr, inf_devices, inf_devarr, inf_ifaces, inf_ifarr, inf_logterms, inf_logtarr
		var inf_subnets, inf_subnarr, inf_misc, inf_flags, inf_run

		pollData: poll.add(function() {
			return L.resolveDefault(fs.read_direct('/tmp/ban_runtime.json'), 'null').then(function(res) {
				rt_res = JSON.parse(res);
				inf_stat = document.getElementById('status');
				if (inf_stat && rt_res) {
					inf_stat.textContent = (rt_res.status || '-') + ' / ' + (rt_res.version || '-');
					if (rt_res.status === "running") {
						if (!inf_stat.classList.contains("spinning")) {
							inf_stat.classList.add("spinning");
						}
					} else {
						if (inf_stat.classList.contains("spinning")) {
							inf_stat.classList.remove("spinning");
							if (document.getElementById('btn_suspend')) {
								if (inf_stat.textContent.substr(0,6) === 'paused') {
									document.querySelector('#btn_suspend').textContent = 'Resume';
								}
								if (document.getElementById('status').textContent.substr(0,7) === 'enabled') {
									document.querySelector('#btn_suspend').textContent = 'Suspend';
								}
							}
						}
					}
				} else if (inf_stat) {
					inf_stat.textContent = '-';
					if (inf_stat.classList.contains("spinning")) {
						inf_stat.classList.remove("spinning");
					}
				}
				inf_ipsets = document.getElementById('ipsets');
				if (inf_ipsets && rt_res) {
					inf_ipsets.textContent = rt_res.ipset_info || '-';
				}
				inf_sources = document.getElementById('sources');
				inf_srcarr = [];
				if (inf_sources && rt_res) {
					for (var i = 0; i < rt_res.active_sources.length; i++) {
						if (i < rt_res.active_sources.length-1) {
							inf_srcarr += rt_res.active_sources[i].source + ', ';
						} else {
							inf_srcarr += rt_res.active_sources[i].source
						}
					}
					inf_sources.textContent = inf_srcarr || '-';
				}
				inf_devices = document.getElementById('devices');
				inf_devarr = [];
				if (inf_devices && rt_res) {
					for (var i = 0; i < rt_res.active_devs.length; i++) {
						if (i < rt_res.active_devs.length-1) {
							inf_devarr += rt_res.active_devs[i].dev + ', ';
						} else {
							inf_devarr += rt_res.active_devs[i].dev
						}
					}
					inf_devices.textContent = inf_devarr || '-';
				}
				inf_ifaces = document.getElementById('ifaces');
				inf_ifarr = [];
				if (inf_ifaces && rt_res) {
					for (var i = 0; i < rt_res.active_ifaces.length; i++) {
						if (i < rt_res.active_ifaces.length-1) {
							inf_ifarr += rt_res.active_ifaces[i].iface + ', ';
						} else {
							inf_ifarr += rt_res.active_ifaces[i].iface
						}
					}
					inf_ifaces.textContent = inf_ifarr || '-';
				}
				inf_logterms = document.getElementById('logterms');
				inf_logtarr = [];
				if (inf_logterms && rt_res) {
					for (var i = 0; i < rt_res.active_logterms.length; i++) {
						if (i < rt_res.active_logterms.length-1) {
							inf_logtarr += rt_res.active_logterms[i].term + ', ';
						} else {
							inf_logtarr += rt_res.active_logterms[i].term
						}
					}
					inf_logterms.textContent = inf_logtarr || '-';
				}
				inf_subnets = document.getElementById('subnets');
				inf_subnarr = [];
				if (inf_subnets && rt_res) {
					for (var i = 0; i < rt_res.active_subnets.length; i++) {
						if (i < rt_res.active_subnets.length-1) {
							inf_subnarr += rt_res.active_subnets[i].subnet + ', ';
						} else {
							inf_subnarr += rt_res.active_subnets[i].subnet
						}
					}
					inf_subnets.textContent = inf_subnarr || '-';
				}
				inf_misc = document.getElementById('infos');
				if (inf_misc && rt_res) {
					inf_misc.textContent = rt_res.run_infos || '-';
				}
				inf_flags = document.getElementById('flags');
				if (inf_flags && rt_res) {
					inf_flags.textContent = rt_res.run_flags || '-';
				}
				inf_run = document.getElementById('run');
				if (inf_run && rt_res) {
					inf_run.textContent = rt_res.last_run || '-';
				}
			});
		}, 1);

		/*
			runtime information and buttons
		*/
		s = m.section(form.NamedSection, 'global');
		s.render = L.bind(function(view, section_id) {
			return E('div', { 'class': 'cbi-section' }, [
				E('h3', _('Information')), 
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Status / Version')),
					E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'color:#37c' },'\xa0')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('IPSet Information')),
					E('div', { 'class': 'cbi-value-field', 'id': 'ipsets', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Sources')),
					E('div', { 'class': 'cbi-value-field', 'id': 'sources', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Devices')),
					E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Interfaces')),
					E('div', { 'class': 'cbi-value-field', 'id': 'ifaces', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Logterms')),
					E('div', { 'class': 'cbi-value-field', 'id': 'logterms', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Subnets')),
					E('div', { 'class': 'cbi-value-field', 'id': 'subnets', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Run Information')),
					E('div', { 'class': 'cbi-value-field', 'id': 'infos', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Run Flags')),
					E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'color:#37c' },'-')
				]),
				E('div', { 'class': 'cbi-value' }, [
					E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Last Run')),
					E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'color:#37c' },'-')
				]),
				E('div', { class: 'right' }, [
					E('button', {
						'class': 'btn cbi-button cbi-button-apply',
						'click': ui.createHandlerFn(this, function() {
							return handleAction('timer');
						})
					}, [ _('Refresh Timer...') ]),
					'\xa0\xa0\xa0',
					E('button', {
						'class': 'btn cbi-button cbi-button-apply',
						'id': 'btn_suspend',
						'click': ui.createHandlerFn(this, function() {
							return handleAction('suspend');
						})
					}, [ _('Suspend') ]),
					'\xa0\xa0\xa0',
					E('button', {
						'class': 'btn cbi-button cbi-button-positive',
						'click': ui.createHandlerFn(this, function() {
							return handleAction('refresh');
						})
					}, [ _('Refresh') ]),
					'\xa0\xa0\xa0',
					E('button', {
						'class': 'btn cbi-button cbi-button-negative',
						'click': ui.createHandlerFn(this, function() {
							return handleAction('restart');
						})
					}, [ _('Restart') ])
				])
			]);
		}, o, this);
		this.pollData;

		/*
			tabbed config section
		*/
		s = m.section(form.NamedSection, 'global', 'banip', _('Settings'));
		s.addremove = false;
		s.tab('general',  _('General Settings'));
		s.tab('additional', _('Additional Settings'));
		s.tab('adv_chain', _('Advanced Chain Settings'));
		s.tab('adv_log', _('Advanced Log Settings'));
		s.tab('adv_email', _('Advanced E-Mail Settings'));
		s.tab('sources', _('Blocklist Sources'));

		/*
			general settings tab
		*/
		o = s.taboption('general', form.Flag, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
		o.rmempty = false;

		o = s.taboption('general', widgets.NetworkSelect, 'ban_trigger', _('Startup Trigger Interface'), _('List of available network interfaces to trigger the banIP start.'));
		o.unspecified = true;
		o.nocreate = true;
		o.rmempty = true;

		o = s.taboption('general', form.Flag, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network interfaces, devices, subnets and protocols automatically.'));
		o.rmempty = false;

		o = s.taboption('general', widgets.NetworkSelect, 'ban_ifaces', _('Network Interfaces'), _('Select the relevant network interfaces manually.'));
		o.depends('ban_autodetect', '0');
		o.unspecified = true;
		o.multiple = true;
		o.nocreate = true;
		o.optional = true;
		o.rmempty = false;

		o = s.taboption('general', form.Flag, 'ban_proto4_enabled', _('IPv4 Support'), _('Enables IPv4 support in banIP.'));
		o.depends('ban_autodetect', '0');
		o.optional = true;
		o.rmempty = false;

		o = s.taboption('general', form.Flag, 'ban_proto6_enabled', _('IPv6 Support'), _('Enables IPv6 support in banIP.'));
		o.depends('ban_autodetect', '0');
		o.optional = true;
		o.rmempty = false;

		o = s.taboption('general', form.Flag, 'ban_monitor_enabled', _('Log Monitor'), _('Starts a small log monitor in the background to block suspicious SSH/LuCI login attempts.'));
		o.rmempty = false;

		o = s.taboption('general', form.Flag, 'ban_logsrc_enabled', _('Enable SRC logging'), _('Log suspicious incoming packets - usually dropped.'));
		o.rmempty = false;

		o = s.taboption('general', form.Flag, 'ban_logdst_enabled', _('Enable DST logging'), _('Log suspicious outgoing packets - usually rejected. \
			Logging such packets may cause an increase in latency due to it requiring additional system resources.'));
		o.rmempty = false;

		o = s.taboption('general', form.Flag, 'ban_mail_enabled', _('E-Mail Notification'), _('Send banIP related notification e-mails. \
			This needs the installation and setup of the additional \'msmtp\' package.'));
		o.rmempty = false;

		o = s.taboption('general', form.Value, 'ban_mailreceiver', _('E-Mail Receiver Address'), _('Receiver address for banIP notification e-mails.'));
		o.depends('ban_mail_enabled', '1');
		o.placeholder = 'name@example.com';
		o.rmempty = true;

		/*
			additional settings tab
		*/
		o = s.taboption('additional', form.Flag, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of any processing errors.'));
		o.rmempty = false;

		o = s.taboption('additional', form.ListValue, 'ban_nice', _('Service Priority'), _('The selected priority will be used for banIP background processing. \
			This change requires a full banIP service restart to take effect.'));
		o.value('-20', _('Highest Priority'));
		o.value('-10', _('High Priority'));
		o.value('0', _('Normal Priority (default)'));
		o.value('10', _('Less Priority'));
		o.value('19', _('Least Priority'));
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('additional', form.Value, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds before banIP processing begins.'));
		o.placeholder = '5';
		o.datatype = 'range(1,120)';
		o.rmempty = true;

		o = s.taboption('additional', form.ListValue, 'ban_maxqueue', _('Download Queue'), _('Size of the download queue for download processing in parallel.'));
		o.value('1');
		o.value('2');
		o.value('4');
		o.value('8');
		o.value('16');
		o.value('32');
		o.optional = true;
		o.rmempty = false;

		o = s.taboption('additional', form.Value, 'ban_tmpbase', _('Base Temp Directory'), _('Base Temp Directory used for all banIP related runtime operations.'));
		o.placeholder = '/tmp';
		o.rmempty = true;

		o = s.taboption('additional', form.Value, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed source list backups.'));
		o.placeholder = '/tmp/banIP-Backup';
		o.rmempty = true;

		o = s.taboption('additional', form.Value, 'ban_reportdir', _('Report Directory'), _('Target directory for IPSet related report files.'));
		o.placeholder = '/tmp/banIP-Report';
		o.rmempty = true;

		o = s.taboption('additional', form.ListValue, 'ban_fetchutil', _('Download Utility'), _('List of supported and fully pre-configured download utilities.'));
		o.value('uclient-fetch');
		o.value('wget');
		o.value('curl');
		o.value('aria2c');
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('additional', form.Value, 'ban_fetchparm', _('Download Parameters'), _('Special config options for the selected download utility.'))
		o.rmempty = true;

		/*
			advanced chain settings tab
		*/
		o = s.taboption('adv_chain', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>Changes on this tab needs a full banIP service restart to take effect.</b></em>';

		o = s.taboption('adv_chain', form.ListValue, 'ban_global_settype', _('Global IPSet Type'), _('Set the global IPset type default, to block incoming (SRC) and/or outgoing (DST) packets.'));
		o.value('src+dst');
		o.value('src');
		o.value('dst');
		o.rmempty = false;

		o = s.taboption('adv_chain', form.ListValue, 'ban_target_src', _('SRC Target'), _('Set the firewall target for all SRC related rules.'));
		o.value('DROP');
		o.value('REJECT');
		o.rmempty = false;

		o = s.taboption('adv_chain', form.ListValue, 'ban_target_dst', _('DST Target'), _('Set the firewall target for all DST related rules.'));
		o.value('REJECT');
		o.value('DROP');
		o.rmempty = false;

		o = s.taboption('adv_chain', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>Individual IPSet Settings</b></em>';

		o = s.taboption('adv_chain', form.ListValue, 'ban_maclist_timeout', _('Maclist Timeout'), _('Set the maclist IPSet timeout.'));
		o.value('1800', _('30 minutes'));
		o.value('3600', _('1 hour'));
		o.value('21600', _('6 hours'));
		o.value('43200', _('12 hours'));
		o.value('86400', _('24 hours'));
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.ListValue, 'ban_whitelist_timeout', _('Whitelist Timeout'), _('Set the whitelist IPSet timeout.'));
		o.value('1800', _('30 minutes'));
		o.value('3600', _('1 hour'));
		o.value('21600', _('6 hours'));
		o.value('43200', _('12 hours'));
		o.value('86400', _('24 hours'));
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.ListValue, 'ban_blacklist_timeout', _('Blacklist Timeout'), _('Set the blacklist IPSet timeout.'));
		o.value('1800', _('30 minutes'));
		o.value('3600', _('1 hour'));
		o.value('21600', _('6 hours'));
		o.value('43200', _('12 hours'));
		o.value('86400', _('24 hours'));
		o.optional = true;
		o.rmempty = true;

		var info, source, sources = [];
		if (result[0]) {
			sources = result[0].trim().split('\n');
		}

		o = s.taboption('adv_chain', form.MultiValue, 'ban_settype_src', _('SRC IPSet Type'), _('Set individual SRC type per IPset to block only incoming packets.'));
		o.value('whitelist');
		o.value('blacklist');
		for (var i = 0; i < sources.length; i++) {
			if (sources[i].match(/^\s+\+/)) {
				source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
				o.value(source);
			}
		}
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.MultiValue, 'ban_settype_dst', _('DST IPSet Type'), _('Set individual DST type per IPset to block only outgoing packets.'));
		o.value('whitelist');
		o.value('blacklist');
		for (var i = 0; i < sources.length; i++) {
			if (sources[i].match(/^\s+\+/)) {
				source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
				o.value(source);
			}
		}
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.MultiValue, 'ban_settype_all', _('SRC+DST IPSet Type'), _('Set individual SRC+DST type per IPset to block incoming and outgoing packets.'));
		o.value('whitelist');
		o.value('blacklist');
		for (var i = 0; i < sources.length; i++) {
			if (sources[i].match(/^\s+\+/)) {
				source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
				o.value(source);
			}
		}
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>IPv4 Chains</b></em>';

		/*
			prepare iptables data
		*/
		var chain, result_v4=[], result_v6=[];
		if (result[1]) {
			result_v4 = result[1].trim().split('\n');
		} else if (result[2]) {
			result_v4 = result[2].trim().split('\n');
		}

		if (result[2]) {
			result_v6 = result[2].trim().split('\n');
		} else if (result[1]) {
			result_v6 = result[1].trim().split('\n');
		}

		o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_inputchains_4', _('LAN Input'), _('Default chain used by banIP is \'input_lan_rule\''));
		for (var i = 0; i < result_v4.length; i++) {
			if (result_v4[i].match(/^Chain input[\w_]+\s+/)) {
				chain = result_v4[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_forwardchains_4', _('LAN Forward'), _('Default chain used by banIP is \'forwarding_lan_rule\''));
		for (var i = 0; i < result_v4.length; i++) {
			if (result_v4[i].match(/^Chain forwarding[\w_]+\s+/)) {
				chain = result_v4[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_inputchains_4', _('WAN Input'), _('Default chain used by banIP is \'input_wan_rule\''));
		for (var i = 0; i < result_v4.length; i++) {
			if (result_v4[i].match(/^Chain input[\w_]+\s+/)) {
				chain = result_v4[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_forwardchains_4', _('WAN Forward'), _('Default chain used by banIP is \'forwarding_wan_rule\''));
		for (var i = 0; i < result_v4.length; i++) {
			if (result_v4[i].match(/^Chain forwarding[\w_]+\s+/)) {
				chain = result_v4[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>IPv6 Chains</b></em>';

		o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_inputchains_6', _('LAN Input'), _('Default chain used by banIP is \'input_lan_rule\''));
		for (var i = 0; i < result_v6.length; i++) {
			if (result_v6[i].match(/^Chain input[\w_]+\s+/)) {
				chain = result_v6[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_forwardchains_6', _('LAN Forward'), _('Default chain used by banIP is \'forwarding_lan_rule\''));
		for (var i = 0; i < result_v6.length; i++) {
			if (result_v6[i].match(/^Chain forwarding[\w_]+\s+/)) {
				chain = result_v6[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_inputchains_6', _('WAN Input'), _('Default chain used by banIP is \'input_wan_rule\''));
		for (var i = 0; i < result_v6.length; i++) {
			if (result_v6[i].match(/^Chain input[\w_]+\s+/)) {
				chain = result_v6[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_forwardchains_6', _('WAN Forward'), _('Default chain used by banIP is \'forwarding_wan_rule\''));
		for (var i = 0; i < result_v6.length; i++) {
			if (result_v6[i].match(/^Chain forwarding[\w_]+\s+/)) {
				chain = result_v6[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
				o.value(chain);
			}
		}
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		/*
			advanced log settings tab
		*/
		o = s.taboption('adv_log', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>Changes on this tab needs a full banIP service restart to take effect.</b></em>';

		o = s.taboption('adv_log', form.ListValue, 'ban_loglimit', _('Log Limit'), _('Parse only the last stated number of log entries for suspicious events.'));
		o.value('50');
		o.value('100');
		o.value('250');
		o.value('500');
		o.rmempty = false;

		o = s.taboption('adv_log', form.MultiValue, 'ban_logterms', _('Log Terms'), _('Limit the log monitor to certain log terms.'));
		o.value('dropbear');
		o.value('sshd');
		o.value('luci');
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_log', form.Value, 'ban_logopts_src', _('SRC Log Options'), _('Set special SRC log options, e.g. to set a limit rate.'));
		o.nocreate = false;
		o.unspecified = true;
		o.value('-m limit --limit 2/sec', _('-m limit --limit 2/sec (default)'));
		o.value('-m limit --limit 10/sec');
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('adv_log', form.Value, 'ban_logopts_dst', _('DST Log Options'), _('Set special DST log options, e.g. to set a limit rate.'));
		o.nocreate = false;
		o.unspecified = true;
		o.value('-m limit --limit 2/sec', _('-m limit --limit 2/sec (default)'));
		o.value('-m limit --limit 10/sec');
		o.optional = true;
		o.rmempty = true;

		/*
			advanced email settings tab
		*/
		o = s.taboption('adv_email', form.Value, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
		o.placeholder = 'no-reply@banIP';
		o.rmempty = true;

		o = s.taboption('adv_email', form.Value, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
		o.placeholder = 'banIP notification';
		o.rmempty = true;

		o = s.taboption('adv_email', form.Value, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
		o.placeholder = 'ban_notify';
		o.datatype = 'uciname';
		o.rmempty = true;

		o = s.taboption('adv_email', form.MultiValue, 'ban_mailactions', _('E-Mail Actions'), _('Limit E-Mail trigger to certain banIP actions.'));
		o.value('start');
		o.value('reload');
		o.value('restart');
		o.value('refresh');
		o.rmempty = true;

		/*
			blocklist sources tab
		*/
		o = s.taboption('sources', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>List of supported and fully pre-configured banIP sources.</b></em>';

		o = s.taboption('sources', form.MultiValue, 'ban_sources', _('Sources (Info)'));
		for (var i = 0; i < sources.length; i++) {
			if (sources[i].match(/^\s+\+/)) {
				source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
				info = sources[i].slice(35,70).trim();
				o.value(source, source + ' (' + info + ')');
			}
		}
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('sources', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>Country selection</b></em>';

		/*
			prepare country data
		*/
		var code, country, countries = [];
		if (result[3]) {
			countries = result[3].trim().split('\n');
		}

		o = s.taboption('sources', form.DynamicList, 'ban_countries', _('Countries'));
		for (var i = 0; i < countries.length; i++) {
			code = countries[i].match(/^(\w+);/)[1].trim();
			country = countries[i].match(/^\w+;(.*$)/)[1].trim();
			o.value(code, country);
		}
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('sources', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>ASN selection</b></em>';

		o = s.taboption('sources', form.DynamicList, 'ban_asns', _('ASNs'));
		o.datatype = 'uinteger';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('sources', form.DummyValue, '_sub');
		o.rawhtml = true;
		o.default = '<em><b>Local Sources</b></em>';

		o = s.taboption('sources', form.MultiValue, 'ban_localsources', _('Local Sources'), _('Limit the selection to certain local sources.'));
		o.value('maclist');
		o.value('whitelist');
		o.value('blacklist');
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('sources', form.DynamicList, 'ban_extrasources', _('Extra Sources'), _('Add additional, non-banIP related IPSets e.g. for reporting and queries.'));
		o.datatype = 'uciname';
		o.optional = true;
		o.rmempty = true;

		o = s.taboption('sources', form.Flag, 'ban_autoblacklist', _('Auto Blacklist'), _('Automatically transfers suspicious IPs from the log to the banIP blacklist during runtime.'));
		o.rmempty = false;

		o = s.taboption('sources', form.Flag, 'ban_autowhitelist', _('Auto Whitelist'), _('Automatically transfers uplink IPs to the banIP whitelist during runtime.'));
		o.rmempty = false;

		return m.render();
	},
	handleReset: null
});