luci-app-banip: sync with banIP 0.7.0
[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 async function handleAction(ev) {
14 if (ev === 'timer') {
15 L.ui.showModal(_('Refresh Timer'), [
16 E('p', _('To keep your banIP lists up-to-date, you should setup an automatic update job for these lists.')),
17 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
18 E('h5', _('Existing job(s)')),
19 E('textarea', {
20 'id': 'cronView',
21 'style': 'width: 100% !important; padding: 5px; font-family: monospace',
22 'readonly': 'readonly',
23 'wrap': 'off',
24 'rows': 5
25 })
26 ]),
27 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
28 E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em' }, [
29 E('h5', _('Set a new banIP job')),
30 E('select', { 'class': 'cbi-input-select', 'id': 'timerA' }, [
31 E('option', { 'value': 'start' }, 'Start'),
32 E('option', { 'value': 'reload' }, 'Reload'),
33 E('option', { 'value': 'restart' }, 'Restart'),
34 E('option', { 'value': 'refresh' }, 'Refresh'),
35 E('option', { 'value': 'suspend' }, 'Suspend'),
36 E('option', { 'value': 'resume' }, 'Resume'),
37 E('option', { 'value': 'report gen' }, 'Report'),
38 E('option', { 'value': 'report mail' }, 'Report & Mail')
39 ]),
40 '\xa0\xa0\xa0',
41 _('banIP action')
42 ]),
43 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
44 E('input', { 'class': 'cbi-input-text', 'id': 'timerH', 'maxlength': '2' }, [
45 ]),
46 '\xa0\xa0\xa0',
47 _('The hours portition (req., range: 0-23)')
48 ]),
49 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
50 E('input', { 'class': 'cbi-input-text', 'id': 'timerM', 'maxlength': '2' }),
51 '\xa0\xa0\xa0',
52 _('The minutes portion (opt., range: 0-59)')
53 ]),
54 E('label', { 'class': 'cbi-input-text', 'style': 'padding-top:.5em' }, [
55 E('input', { 'class': 'cbi-input-text', 'id': 'timerD', 'maxlength': '13' }),
56 '\xa0\xa0\xa0',
57 _('The day of the week (opt., values: 1-7 possibly sep. by , or -)')
58 ])
59 ]),
60 E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
61 E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em' }, [
62 E('h5', _('Remove an existing job')),
63 E('input', { 'class': 'cbi-input-text', 'id': 'lineno', 'maxlength': '2' }, [
64 ]),
65 '\xa0\xa0\xa0',
66 _('Line number to remove')
67 ])
68 ]),
69 E('div', { 'class': 'right' }, [
70 E('button', {
71 'class': 'btn',
72 'click': L.hideModal
73 }, _('Cancel')),
74 ' ',
75 E('button', {
76 'class': 'btn cbi-button-action',
77 'click': ui.createHandlerFn(this, function(ev) {
78 var lineno = document.getElementById('lineno').value;
79 var action = document.getElementById('timerA').value;
80 var hours = document.getElementById('timerH').value;
81 var minutes = document.getElementById('timerM').value || '0';
82 var days = document.getElementById('timerD').value || '*';
83 if (hours) {
84 L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['timer', 'add', action, hours, minutes, days]))
85 .then(function(res) {
86 if (res) {
87 ui.addNotification(null, E('p', _('The Refresh Timer could not been updated.')), 'error');
88 } else {
89 ui.addNotification(null, E('p', _('The Refresh Timer has been updated.')), 'info');
90 }
91 });
92 } else if (lineno) {
93 L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['timer', 'remove', lineno]))
94 .then(function(res) {
95 if (res) {
96 ui.addNotification(null, E('p', _('The Refresh Timer could not been updated.')), 'error');
97 } else {
98 ui.addNotification(null, E('p', _('The Refresh Timer has been updated.')), 'info');
99 }
100 });
101 } else {
102 document.getElementById('timerH').focus();
103 return
104 }
105 L.hideModal();
106 })
107 }, _('Save'))
108 ])
109 ]);
110 L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['timer', 'list']))
111 .then(function(res) {
112 document.getElementById('cronView').value = res.trim();
113 });
114 document.getElementById('timerH').focus();
115 return
116 }
117
118 if (document.getElementById('status') && document.getElementById('btn_suspend')) {
119 if (document.getElementById('status').textContent.substr(0,6) === 'paused') {
120 ev = 'resume';
121 }
122 }
123
124 poll.start();
125 fs.exec_direct('/etc/init.d/banip', [ev])
126 var running = 1;
127 while (running === 1) {
128 await new Promise(r => setTimeout(r, 1000));
129 L.resolveDefault(fs.read_direct('/var/run/banip.pid')).then(function(res) {
130 if (!res) {
131 running = 0;
132 if (document.getElementById('status') && document.getElementById('btn_suspend')) {
133 if (document.getElementById('status').textContent.substr(0,7) === 'enabled') {
134 document.querySelector('#btn_suspend').textContent = 'Suspend';
135 }
136 }
137 }
138 })
139 }
140 poll.stop();
141 }
142
143 return view.extend({
144 load: function() {
145 return Promise.all([
146 L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['list']), {}),
147 L.resolveDefault(fs.exec_direct('/usr/sbin/iptables', ['-L']), null),
148 L.resolveDefault(fs.exec_direct('/usr/sbin/ip6tables', ['-L']), null),
149 L.resolveDefault(fs.read_direct('/etc/banip/banip.countries'), ''),
150 uci.load('banip')
151 ]);
152 },
153
154 render: function(result) {
155 var m, s, o;
156
157 m = new form.Map('banip', 'banIP', _('Configuration of the banIP package to block ip adresses/subnets via IPSet. \
158 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>'));
159
160 /*
161 poll runtime information
162 */
163 var rt_res, inf_stat, inf_ipsets, inf_sources, inf_srcarr, inf_devices, inf_devarr, inf_ifaces, inf_ifarr, inf_logterms, inf_logtarr
164 var inf_subnets, inf_subnarr, inf_misc, inf_flags, inf_run
165
166 pollData: poll.add(function() {
167 return L.resolveDefault(fs.read_direct('/tmp/ban_runtime.json'), 'null').then(function(res) {
168 rt_res = JSON.parse(res);
169 inf_stat = document.getElementById('status');
170 if (inf_stat && rt_res) {
171 inf_stat.textContent = (rt_res.status || '-') + ' / ' + (rt_res.version || '-');
172 if (rt_res.status === "running") {
173 if (!inf_stat.classList.contains("spinning")) {
174 inf_stat.classList.add("spinning");
175 }
176 } else {
177 if (inf_stat.classList.contains("spinning")) {
178 inf_stat.classList.remove("spinning");
179 poll.stop();
180 }
181 }
182 if (inf_stat.textContent.substr(0,6) === 'paused' && document.getElementById('btn_suspend')) {
183 document.querySelector('#btn_suspend').textContent = 'Resume';
184 }
185 } else if (inf_stat) {
186 inf_stat.textContent = '-';
187 if (inf_stat.classList.contains("spinning")) {
188 inf_stat.classList.remove("spinning");
189 }
190 }
191 inf_ipsets = document.getElementById('ipsets');
192 if (inf_ipsets && rt_res) {
193 inf_ipsets.textContent = rt_res.ipset_info || '-';
194 }
195 inf_sources = document.getElementById('sources');
196 inf_srcarr = [];
197 if (inf_sources && rt_res) {
198 for (var i = 0; i < rt_res.active_sources.length; i++) {
199 if (i < rt_res.active_sources.length-1) {
200 inf_srcarr += rt_res.active_sources[i].source + ', ';
201 } else {
202 inf_srcarr += rt_res.active_sources[i].source
203 }
204 }
205 inf_sources.textContent = inf_srcarr || '-';
206 }
207 inf_devices = document.getElementById('devices');
208 inf_devarr = [];
209 if (inf_devices && rt_res) {
210 for (var i = 0; i < rt_res.active_devs.length; i++) {
211 if (i < rt_res.active_devs.length-1) {
212 inf_devarr += rt_res.active_devs[i].dev + ', ';
213 } else {
214 inf_devarr += rt_res.active_devs[i].dev
215 }
216 }
217 inf_devices.textContent = inf_devarr || '-';
218 }
219 inf_ifaces = document.getElementById('ifaces');
220 inf_ifarr = [];
221 if (inf_ifaces && rt_res) {
222 for (var i = 0; i < rt_res.active_ifaces.length; i++) {
223 if (i < rt_res.active_ifaces.length-1) {
224 inf_ifarr += rt_res.active_ifaces[i].iface + ', ';
225 } else {
226 inf_ifarr += rt_res.active_ifaces[i].iface
227 }
228 }
229 inf_ifaces.textContent = inf_ifarr || '-';
230 }
231 inf_logterms = document.getElementById('logterms');
232 inf_logtarr = [];
233 if (inf_logterms && rt_res) {
234 for (var i = 0; i < rt_res.active_logterms.length; i++) {
235 if (i < rt_res.active_logterms.length-1) {
236 inf_logtarr += rt_res.active_logterms[i].term + ', ';
237 } else {
238 inf_logtarr += rt_res.active_logterms[i].term
239 }
240 }
241 inf_logterms.textContent = inf_logtarr || '-';
242 }
243 inf_subnets = document.getElementById('subnets');
244 inf_subnarr = [];
245 if (inf_subnets && rt_res) {
246 for (var i = 0; i < rt_res.active_subnets.length; i++) {
247 if (i < rt_res.active_subnets.length-1) {
248 inf_subnarr += rt_res.active_subnets[i].subnet + ', ';
249 } else {
250 inf_subnarr += rt_res.active_subnets[i].subnet
251 }
252 }
253 inf_subnets.textContent = inf_subnarr || '-';
254 }
255 inf_misc = document.getElementById('infos');
256 if (inf_misc && rt_res) {
257 inf_misc.textContent = rt_res.run_infos || '-';
258 }
259 inf_flags = document.getElementById('flags');
260 if (inf_flags && rt_res) {
261 inf_flags.textContent = rt_res.run_flags || '-';
262 }
263 inf_run = document.getElementById('run');
264 if (inf_run && rt_res) {
265 inf_run.textContent = rt_res.last_run || '-';
266 }
267 });
268 }, 1);
269
270 /*
271 runtime information and buttons
272 */
273 s = m.section(form.NamedSection, 'global');
274 s.render = L.bind(function(view, section_id) {
275 return E('div', { 'class': 'cbi-section' }, [
276 E('h3', _('Information')),
277 E('div', { 'class': 'cbi-value' }, [
278 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Status / Version')),
279 E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'color:#37c' },'\xa0')
280 ]),
281 E('div', { 'class': 'cbi-value' }, [
282 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('IPSet Information')),
283 E('div', { 'class': 'cbi-value-field', 'id': 'ipsets', 'style': 'color:#37c' },'-')
284 ]),
285 E('div', { 'class': 'cbi-value' }, [
286 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Sources')),
287 E('div', { 'class': 'cbi-value-field', 'id': 'sources', 'style': 'color:#37c' },'-')
288 ]),
289 E('div', { 'class': 'cbi-value' }, [
290 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Devices')),
291 E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'color:#37c' },'-')
292 ]),
293 E('div', { 'class': 'cbi-value' }, [
294 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Interfaces')),
295 E('div', { 'class': 'cbi-value-field', 'id': 'ifaces', 'style': 'color:#37c' },'-')
296 ]),
297 E('div', { 'class': 'cbi-value' }, [
298 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Logterms')),
299 E('div', { 'class': 'cbi-value-field', 'id': 'logterms', 'style': 'color:#37c' },'-')
300 ]),
301 E('div', { 'class': 'cbi-value' }, [
302 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Active Subnets')),
303 E('div', { 'class': 'cbi-value-field', 'id': 'subnets', 'style': 'color:#37c' },'-')
304 ]),
305 E('div', { 'class': 'cbi-value' }, [
306 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Run Information')),
307 E('div', { 'class': 'cbi-value-field', 'id': 'infos', 'style': 'color:#37c' },'-')
308 ]),
309 E('div', { 'class': 'cbi-value' }, [
310 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Run Flags')),
311 E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'color:#37c' },'-')
312 ]),
313 E('div', { 'class': 'cbi-value' }, [
314 E('label', { 'class': 'cbi-value-title', 'style': 'padding-top:0rem' }, _('Last Run')),
315 E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'color:#37c' },'-')
316 ]),
317 E('div', { class: 'right' }, [
318 E('button', {
319 'class': 'cbi-button cbi-button-apply',
320 'click': ui.createHandlerFn(this, function() {
321 return handleAction('timer');
322 })
323 }, [ _('Refresh Timer...') ]),
324 '\xa0\xa0\xa0',
325 E('button', {
326 'class': 'cbi-button cbi-button-apply',
327 'id': 'btn_suspend',
328 'click': ui.createHandlerFn(this, function() {
329 return handleAction('suspend');
330 })
331 }, [ _('Suspend') ]),
332 '\xa0\xa0\xa0',
333 E('button', {
334 'class': 'cbi-button cbi-button-positive',
335 'click': ui.createHandlerFn(this, function() {
336 return handleAction('refresh');
337 })
338 }, [ _('Refresh') ]),
339 '\xa0\xa0\xa0',
340 E('button', {
341 'class': 'cbi-button cbi-button-negative',
342 'click': ui.createHandlerFn(this, function() {
343 return handleAction('restart');
344 })
345 }, [ _('Restart') ])
346 ])
347 ]);
348 }, o, this);
349 this.pollData;
350
351 /*
352 tabbed config section
353 */
354 s = m.section(form.NamedSection, 'global', 'banip', _('Settings'));
355 s.addremove = false;
356 s.tab('general', _('General Settings'));
357 s.tab('additional', _('Additional Settings'));
358 s.tab('adv_chain', _('Advanced Chain Settings'));
359 s.tab('adv_log', _('Advanced Log Settings'));
360 s.tab('adv_email', _('Advanced E-Mail Settings'));
361 s.tab('sources', _('Blocklist Sources'));
362
363 /*
364 general settings tab
365 */
366 o = s.taboption('general', form.Flag, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
367 o.rmempty = false;
368
369 o = s.taboption('general', widgets.NetworkSelect, 'ban_trigger', _('Startup Trigger Interface'), _('List of available network interfaces to trigger the banIP start.'));
370 o.unspecified = true;
371 o.nocreate = true;
372 o.rmempty = true;
373
374 o = s.taboption('general', form.Flag, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network interfaces, devices, subnets and protocols automatically.'));
375 o.rmempty = false;
376
377 o = s.taboption('general', widgets.NetworkSelect, 'ban_ifaces', _('Network Interfaces'), _('Select the relevant network interfaces manually.'));
378 o.depends('ban_autodetect', '0');
379 o.unspecified = true;
380 o.multiple = true;
381 o.nocreate = true;
382 o.optional = true;
383 o.rmempty = false;
384
385 o = s.taboption('general', form.Flag, 'ban_proto4_enabled', _('IPv4 Support'), _('Enables IPv4 support in banIP.'));
386 o.depends('ban_autodetect', '0');
387 o.optional = true;
388 o.rmempty = false;
389
390 o = s.taboption('general', form.Flag, 'ban_proto6_enabled', _('IPv6 Support'), _('Enables IPv6 support in banIP.'));
391 o.depends('ban_autodetect', '0');
392 o.optional = true;
393 o.rmempty = false;
394
395 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.'));
396 o.rmempty = false;
397
398 o = s.taboption('general', form.Flag, 'ban_logsrc_enabled', _('Enable SRC logging'), _('Log suspicious incoming packets - usually dropped.'));
399 o.rmempty = false;
400
401 o = s.taboption('general', form.Flag, 'ban_logdst_enabled', _('Enable DST logging'), _('Log suspicious outgoing packets - usually rejected. \
402 Logging such packets may cause an increase in latency due to it requiring additional system resources.'));
403 o.rmempty = false;
404
405 o = s.taboption('general', form.Flag, 'ban_mail_enabled', _('E-Mail Notification'), _('Send banIP related notification e-mails. \
406 This needs the installation and setup of the additional \'msmtp\' package.'));
407 o.rmempty = false;
408
409 o = s.taboption('general', form.Value, 'ban_mailreceiver', _('E-Mail Receiver Address'), _('Receiver address for banIP notification e-mails.'));
410 o.depends('ban_mail_enabled', '1');
411 o.placeholder = 'name@example.com';
412 o.rmempty = true;
413
414 /*
415 additional settings tab
416 */
417 o = s.taboption('additional', form.Flag, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of any processing errors.'));
418 o.rmempty = false;
419
420 o = s.taboption('additional', form.ListValue, 'ban_nice', _('Service Priority'), _('The selected priority will be used for banIP background processing. \
421 This change requires a full banIP service restart to take effect.'));
422 o.value('-20', _('Highest Priority'));
423 o.value('-10', _('High Priority'));
424 o.value('0', _('Normal Priority (default)'));
425 o.value('10', _('Less Priority'));
426 o.value('19', _('Least Priority'));
427 o.optional = true;
428 o.rmempty = true;
429
430 o = s.taboption('additional', form.Value, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds before banIP processing begins.'));
431 o.placeholder = '5';
432 o.datatype = 'range(1,120)';
433 o.rmempty = true;
434
435 o = s.taboption('additional', form.ListValue, 'ban_maxqueue', _('Download Queue'), _('Size of the download queue for download processing in parallel.'));
436 o.value('1');
437 o.value('2');
438 o.value('4');
439 o.value('8');
440 o.value('16');
441 o.value('32');
442 o.optional = true;
443 o.rmempty = false;
444
445 o = s.taboption('additional', form.Value, 'ban_tmpbase', _('Base Temp Directory'), _('Base Temp Directory used for all banIP related runtime operations.'));
446 o.placeholder = '/tmp';
447 o.rmempty = true;
448
449 o = s.taboption('additional', form.Value, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed source list backups.'));
450 o.placeholder = '/tmp/banIP-Backup';
451 o.rmempty = true;
452
453 o = s.taboption('additional', form.Value, 'ban_reportdir', _('Report Directory'), _('Target directory for IPSet related report files.'));
454 o.placeholder = '/tmp/banIP-Report';
455 o.rmempty = true;
456
457 o = s.taboption('additional', form.ListValue, 'ban_fetchutil', _('Download Utility'), _('List of supported and fully pre-configured download utilities.'));
458 o.value('uclient-fetch');
459 o.value('wget');
460 o.value('curl');
461 o.value('aria2c');
462 o.optional = true;
463 o.rmempty = true;
464
465 o = s.taboption('additional', form.Value, 'ban_fetchparm', _('Download Parameters'), _('Special config options for the selected download utility.'))
466 o.rmempty = true;
467
468 /*
469 advanced chain settings tab
470 */
471 o = s.taboption('adv_chain', form.DummyValue, '_sub');
472 o.rawhtml = true;
473 o.default = '<em><b>Changes on this tab needs a full banIP service restart to take effect.</b></em>';
474
475 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.'));
476 o.value('src+dst');
477 o.value('src');
478 o.value('dst');
479 o.rmempty = false;
480
481 o = s.taboption('adv_chain', form.ListValue, 'ban_target_src', _('SRC Target'), _('Set the firewall target for all SRC related rules.'));
482 o.value('DROP');
483 o.value('REJECT');
484 o.rmempty = false;
485
486 o = s.taboption('adv_chain', form.ListValue, 'ban_target_dst', _('DST Target'), _('Set the firewall target for all DST related rules.'));
487 o.value('REJECT');
488 o.value('DROP');
489 o.rmempty = false;
490
491 o = s.taboption('adv_chain', form.DummyValue, '_sub');
492 o.rawhtml = true;
493 o.default = '<em><b>Individual IPSet Types</b></em>';
494
495 /*
496 prepare source data
497 */
498 var info, source, sources = [];
499 if (result[0]) {
500 sources = result[0].trim().split('\n');
501 }
502
503 o = s.taboption('adv_chain', form.MultiValue, 'ban_settype_src', _('SRC IPSet Type'), _('Set individual SRC type per IPset to block only incoming packets.'));
504 for (var i = 0; i < sources.length; i++) {
505 if (sources[i].match(/^\s+\+/)) {
506 source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
507 o.value(source);
508 }
509 }
510 o.optional = true;
511 o.rmempty = true;
512
513 o = s.taboption('adv_chain', form.MultiValue, 'ban_settype_dst', _('DST IPSet Type'), _('Set individual DST type per IPset to block only outgoing packets.'));
514 for (var i = 0; i < sources.length; i++) {
515 if (sources[i].match(/^\s+\+/)) {
516 source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
517 o.value(source);
518 }
519 }
520 o.optional = true;
521 o.rmempty = true;
522
523 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.'));
524 for (var i = 0; i < sources.length; i++) {
525 if (sources[i].match(/^\s+\+/)) {
526 source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
527 o.value(source);
528 }
529 }
530 o.optional = true;
531 o.rmempty = true;
532
533 o = s.taboption('adv_chain', form.DummyValue, '_sub');
534 o.rawhtml = true;
535 o.default = '<em><b>IPv4 Chains</b></em>';
536
537 /*
538 prepare iptables data
539 */
540 var chain, result_v4=[], result_v6=[];
541 if (result[1]) {
542 result_v4 = result[1].trim().split('\n');
543 } else if (result[2]) {
544 result_v4 = result[2].trim().split('\n');
545 }
546
547 if (result[2]) {
548 result_v6 = result[2].trim().split('\n');
549 } else if (result[1]) {
550 result_v6 = result[1].trim().split('\n');
551 }
552
553 o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_inputchains_4', _('LAN Input'), _('Default chain used by banIP is \'input_lan_rule\''));
554 for (var i = 0; i < result_v4.length; i++) {
555 if (result_v4[i].match(/^Chain input[\w_]+\s+/)) {
556 chain = result_v4[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
557 o.value(chain);
558 }
559 }
560 o.datatype = 'uciname';
561 o.optional = true;
562 o.rmempty = true;
563
564 o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_forwardchains_4', _('LAN Forward'), _('Default chain used by banIP is \'forwarding_lan_rule\''));
565 for (var i = 0; i < result_v4.length; i++) {
566 if (result_v4[i].match(/^Chain forwarding[\w_]+\s+/)) {
567 chain = result_v4[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
568 o.value(chain);
569 }
570 }
571 o.datatype = 'uciname';
572 o.optional = true;
573 o.rmempty = true;
574
575 o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_inputchains_4', _('WAN Input'), _('Default chain used by banIP is \'input_wan_rule\''));
576 for (var i = 0; i < result_v4.length; i++) {
577 if (result_v4[i].match(/^Chain input[\w_]+\s+/)) {
578 chain = result_v4[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
579 o.value(chain);
580 }
581 }
582 o.datatype = 'uciname';
583 o.optional = true;
584 o.rmempty = true;
585
586 o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_forwardchains_4', _('WAN Forward'), _('Default chain used by banIP is \'forwarding_wan_rule\''));
587 for (var i = 0; i < result_v4.length; i++) {
588 if (result_v4[i].match(/^Chain forwarding[\w_]+\s+/)) {
589 chain = result_v4[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
590 o.value(chain);
591 }
592 }
593 o.datatype = 'uciname';
594 o.optional = true;
595 o.rmempty = true;
596
597 o = s.taboption('adv_chain', form.DummyValue, '_sub');
598 o.rawhtml = true;
599 o.default = '<em><b>IPv6 Chains</b></em>';
600
601 o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_inputchains_6', _('LAN Input'), _('Default chain used by banIP is \'input_lan_rule\''));
602 for (var i = 0; i < result_v6.length; i++) {
603 if (result_v6[i].match(/^Chain input[\w_]+\s+/)) {
604 chain = result_v6[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
605 o.value(chain);
606 }
607 }
608 o.datatype = 'uciname';
609 o.optional = true;
610 o.rmempty = true;
611
612 o = s.taboption('adv_chain', form.DynamicList, 'ban_lan_forwardchains_6', _('LAN Forward'), _('Default chain used by banIP is \'forwarding_lan_rule\''));
613 for (var i = 0; i < result_v6.length; i++) {
614 if (result_v6[i].match(/^Chain forwarding[\w_]+\s+/)) {
615 chain = result_v6[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
616 o.value(chain);
617 }
618 }
619 o.datatype = 'uciname';
620 o.optional = true;
621 o.rmempty = true;
622
623 o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_inputchains_6', _('WAN Input'), _('Default chain used by banIP is \'input_wan_rule\''));
624 for (var i = 0; i < result_v6.length; i++) {
625 if (result_v6[i].match(/^Chain input[\w_]+\s+/)) {
626 chain = result_v6[i].match(/\s+(input[\w_]+)\s+/)[1].trim();
627 o.value(chain);
628 }
629 }
630 o.datatype = 'uciname';
631 o.optional = true;
632 o.rmempty = true;
633
634 o = s.taboption('adv_chain', form.DynamicList, 'ban_wan_forwardchains_6', _('WAN Forward'), _('Default chain used by banIP is \'forwarding_wan_rule\''));
635 for (var i = 0; i < result_v6.length; i++) {
636 if (result_v6[i].match(/^Chain forwarding[\w_]+\s+/)) {
637 chain = result_v6[i].match(/\s+(forwarding[\w_]+)\s+/)[1].trim();
638 o.value(chain);
639 }
640 }
641 o.datatype = 'uciname';
642 o.optional = true;
643 o.rmempty = true;
644
645 /*
646 advanced log settings tab
647 */
648 o = s.taboption('adv_log', form.DummyValue, '_sub');
649 o.rawhtml = true;
650 o.default = '<em><b>Changes on this tab needs a full banIP service restart to take effect.</b></em>';
651
652 o = s.taboption('adv_log', form.ListValue, 'ban_loglimit', _('Log Limit'), _('Parse only the last stated number of log entries for suspicious events.'));
653 o.value('50');
654 o.value('100');
655 o.value('250');
656 o.value('500');
657 o.rmempty = false;
658
659 o = s.taboption('adv_log', form.MultiValue, 'ban_logterms', _('Log Terms'), _('Limit the log monitor to certain log terms.'));
660 o.value('dropbear');
661 o.value('sshd');
662 o.value('luci');
663 o.optional = true;
664 o.rmempty = true;
665
666 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.'));
667 o.nocreate = false;
668 o.unspecified = true;
669 o.value('-m limit --limit 2/sec', _('-m limit --limit 2/sec (default)'));
670 o.value('-m limit --limit 10/sec');
671 o.optional = true;
672 o.rmempty = true;
673
674 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.'));
675 o.nocreate = false;
676 o.unspecified = true;
677 o.value('-m limit --limit 2/sec', _('-m limit --limit 2/sec (default)'));
678 o.value('-m limit --limit 10/sec');
679 o.optional = true;
680 o.rmempty = true;
681
682 /*
683 advanced email settings tab
684 */
685 o = s.taboption('adv_email', form.Value, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
686 o.placeholder = 'no-reply@banIP';
687 o.rmempty = true;
688
689 o = s.taboption('adv_email', form.Value, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
690 o.placeholder = 'banIP notification';
691 o.rmempty = true;
692
693 o = s.taboption('adv_email', form.Value, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
694 o.placeholder = 'ban_notify';
695 o.datatype = 'uciname';
696 o.rmempty = true;
697
698 o = s.taboption('adv_email', form.MultiValue, 'ban_mailactions', _('E-Mail Actions'), _('Limit E-Mail trigger to certain banIP actions.'));
699 o.value('start');
700 o.value('reload');
701 o.value('restart');
702 o.value('refresh');
703 o.rmempty = true;
704
705 /*
706 blocklist sources tab
707 */
708 o = s.taboption('sources', form.DummyValue, '_sub');
709 o.rawhtml = true;
710 o.default = '<em><b>List of supported and fully pre-configured banIP sources.</b></em>';
711
712 o = s.taboption('sources', form.MultiValue, 'ban_sources', _('Sources (Info)'));
713 for (var i = 0; i < sources.length; i++) {
714 if (sources[i].match(/^\s+\+/)) {
715 source = sources[i].match(/^\s+\+\s(\w+)\s/)[1].trim();
716 info = sources[i].slice(35,70).trim();
717 o.value(source, source + ' (' + info + ')');
718 }
719 }
720 o.optional = true;
721 o.rmempty = true;
722
723 o = s.taboption('sources', form.DummyValue, '_sub');
724 o.rawhtml = true;
725 o.default = '<em><b>Country selection</b></em>';
726
727 /*
728 prepare country data
729 */
730 var code, country, countries = [];
731 if (result[3]) {
732 countries = result[3].trim().split('\n');
733 }
734
735 o = s.taboption('sources', form.DynamicList, 'ban_countries', _('Countries'));
736 for (var i = 0; i < countries.length; i++) {
737 code = countries[i].match(/^(\w+);/)[1].trim();
738 country = countries[i].match(/^\w+;(.*$)/)[1].trim();
739 o.value(code, country);
740 }
741 o.optional = true;
742 o.rmempty = true;
743
744 o = s.taboption('sources', form.DummyValue, '_sub');
745 o.rawhtml = true;
746 o.default = '<em><b>ASN selection</b></em>';
747
748 o = s.taboption('sources', form.DynamicList, 'ban_asns', _('ASNs'));
749 o.datatype = 'uinteger';
750 o.optional = true;
751 o.rmempty = true;
752
753 o = s.taboption('sources', form.DummyValue, '_sub');
754 o.rawhtml = true;
755 o.default = '<em><b>Local Sources</b></em>';
756
757 o = s.taboption('sources', form.Flag, 'ban_autoblacklist', _('Auto Blacklist'), _('Automatically transfers suspicious IPs from the log to the banIP blacklist during runtime.'));
758 o.rmempty = false;
759
760 o = s.taboption('sources', form.Flag, 'ban_autowhitelist', _('Auto Whitelist'), _('Automatically transfers uplink IPs to the banIP whitelist during runtime.'));
761 o.rmempty = false;
762
763 return m.render();
764 },
765 handleReset: null
766 });