9 'require tools.widgets as widgets';
14 function handleAction(ev
) {
15 if (ev
=== 'restart' || ev
=== 'reload') {
16 let map
= document
.querySelector('.cbi-map');
17 dom
.callClassMethod(map
, 'save')
18 .then(L
.bind(ui
.changes
.apply
, ui
.changes
))
20 return fs
.exec_direct('/etc/init.d/banip', [ev
]);
23 return fs
.exec_direct('/etc/init.d/banip', [ev
]);
30 L
.resolveDefault(fs
.read_direct('/etc/banip/banip.custom.feeds'), ''),
31 L
.resolveDefault(fs
.read_direct('/etc/banip/banip.feeds'), ''),
32 L
.resolveDefault(fs
.read_direct('/etc/banip/banip.countries'), ''),
37 render: function (result
) {
40 m
= new form
.Map('banip', 'banIP', _('Configuration of the banIP package to ban incoming and outgoing IPs via named nftables Sets. \
41 For further information please check the <a style="color:#37c;font-weight:bold;" href="https://github.com/openwrt/packages/blob/master/net/banip/files/README.md" target="_blank" rel="noreferrer noopener" >online documentation</a>'));
44 poll runtime information
46 let buttons
, rtRes
, infStat
, infVer
, infElements
, infFeeds
, infDevices
, infUplink
, infSystem
, nftInfos
, runInfos
, infFlags
, last_run
48 pollData
: poll
.add(function () {
49 return L
.resolveDefault(fs
.stat('/var/run/banip.lock')).then(function (stat
) {
50 buttons
= document
.querySelectorAll('.cbi-button');
51 infStat
= document
.getElementById('status');
53 for (let i
= 0; i
< buttons
.length
; i
++) {
54 buttons
[i
].setAttribute('disabled', 'true');
56 if (infStat
&& !infStat
.classList
.contains('spinning')) {
57 infStat
.classList
.add('spinning');
60 for (let i
= 0; i
< buttons
.length
; i
++) {
61 buttons
[i
].removeAttribute('disabled');
63 if (infStat
&& infStat
.classList
.contains('spinning')) {
64 infStat
.classList
.remove('spinning');
67 L
.resolveDefault(fs
.exec_direct('/etc/init.d/banip', ['status'])).then(function (result
) {
69 rtRes
= result
.trim().split('\n');
71 for (let i
= 0; i
< rtRes
.length
; i
++) {
72 if (rtRes
[i
].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)) {
73 rtRes
.status
= rtRes
[i
].match(/^\s+\+\sstatus\s+\:\s+(.*)$/)[1];
74 } else if (rtRes
[i
].match(/^\s+\+\sversion\s+\:\s+(.*)$/)) {
75 rtRes
.version
= rtRes
[i
].match(/^\s+\+\sversion\s+\:\s+(.*)$/)[1];
76 } else if (rtRes
[i
].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)) {
77 rtRes
.elementCount
= rtRes
[i
].match(/^\s+\+\selement_count\s+\:\s+(.*)$/)[1];
78 } else if (rtRes
[i
].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)) {
79 rtRes
.activeFeeds
= rtRes
[i
].match(/^\s+\+\sactive_feeds\s+\:\s+(.*)$/)[1];
80 } else if (rtRes
[i
].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)) {
81 rtRes
.activeDevices
= rtRes
[i
].match(/^\s+\+\sactive_devices\s+\:\s+(.*)$/)[1];
82 } else if (rtRes
[i
].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)) {
83 rtRes
.activeUplink
= rtRes
[i
].match(/^\s+\+\sactive_uplink\s+\:\s+(.*)$/)[1];
84 } else if (rtRes
[i
].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)) {
85 rtRes
.nftInfo
= rtRes
[i
].match(/^\s+\+\snft_info\s+\:\s+(.*)$/)[1];
86 } else if (rtRes
[i
].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)) {
87 rtRes
.runInfo
= rtRes
[i
].match(/^\s+\+\srun_info\s+\:\s+(.*)$/)[1];
88 } else if (rtRes
[i
].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)) {
89 rtRes
.runFlags
= rtRes
[i
].match(/^\s+\+\srun_flags\s+\:\s+(.*)$/)[1];
90 } else if (rtRes
[i
].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)) {
91 rtRes
.lastRun
= rtRes
[i
].match(/^\s+\+\slast_run\s+\:\s+(.*)$/)[1];
92 } else if (rtRes
[i
].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)) {
93 rtRes
.systemInfo
= rtRes
[i
].match(/^\s+\+\ssystem_info\s+\:\s+(.*)$/)[1];
98 infStat
= document
.getElementById('status');
100 infStat
.textContent
= rtRes
.status
|| '-';
102 infVer
= document
.getElementById('version');
104 infVer
.textContent
= rtRes
.version
|| '-';
106 infElements
= document
.getElementById('elements');
108 infElements
.textContent
= rtRes
.elementCount
|| '-';
110 infFeeds
= document
.getElementById('feeds');
112 infFeeds
.textContent
= rtRes
.activeFeeds
|| '-';
114 infDevices
= document
.getElementById('devices');
116 infDevices
.textContent
= rtRes
.activeDevices
|| '-';
118 infUplink
= document
.getElementById('uplink');
120 infUplink
.textContent
= rtRes
.activeUplink
|| '-';
122 nftInfos
= document
.getElementById('nft');
124 nftInfos
.textContent
= rtRes
.nftInfo
|| '-';
126 runInfos
= document
.getElementById('run');
128 runInfos
.textContent
= rtRes
.runInfo
|| '-';
130 infFlags
= document
.getElementById('flags');
132 infFlags
.textContent
= rtRes
.runFlags
|| '-';
134 last_run
= document
.getElementById('last');
136 last_run
.textContent
= rtRes
.lastRun
|| '-';
138 infSystem
= document
.getElementById('system');
140 infSystem
.textContent
= rtRes
.systemInfo
|| '-';
144 infStat
= document
.getElementById('status');
146 infStat
.textContent
= '-';
148 if (infStat
.classList
.contains('spinning')) {
149 infStat
.classList
.remove('spinning');
158 runtime information and buttons
160 s
= m
.section(form
.NamedSection
, 'global');
161 s
.render
= L
.bind(function (view
, section_id
) {
162 return E('div', { 'class': 'cbi-section' }, [
163 E('h3', _('Information')),
164 E('div', { 'class': 'cbi-value' }, [
165 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Status')),
166 E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '\xa0')
168 E('div', { 'class': 'cbi-value' }, [
169 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Version')),
170 E('div', { 'class': 'cbi-value-field', 'id': 'version', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
172 E('div', { 'class': 'cbi-value' }, [
173 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Element Count')),
174 E('div', { 'class': 'cbi-value-field', 'id': 'elements', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
176 E('div', { 'class': 'cbi-value' }, [
177 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Active Feeds')),
178 E('div', { 'class': 'cbi-value-field', 'id': 'feeds', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
180 E('div', { 'class': 'cbi-value' }, [
181 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Active Devices')),
182 E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
184 E('div', { 'class': 'cbi-value' }, [
185 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Active Uplink')),
186 E('div', { 'class': 'cbi-value-field', 'id': 'uplink', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
188 E('div', { 'class': 'cbi-value' }, [
189 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('NFT Information')),
190 E('div', { 'class': 'cbi-value-field', 'id': 'nft', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
192 E('div', { 'class': 'cbi-value' }, [
193 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Run Information')),
194 E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
196 E('div', { 'class': 'cbi-value' }, [
197 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Run Flags')),
198 E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
200 E('div', { 'class': 'cbi-value' }, [
201 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('Last Run')),
202 E('div', { 'class': 'cbi-value-field', 'id': 'last', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
204 E('div', { 'class': 'cbi-value' }, [
205 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;font-weight:bold;padding-top:0rem;' }, _('System Information')),
206 E('div', { 'class': 'cbi-value-field', 'id': 'system', 'style': 'margin-bottom:-5px;color:#37c;font-weight:bold;' }, '-')
208 E('div', { class: 'right' }, [
210 'class': 'btn cbi-button cbi-button-action',
211 'click': ui
.createHandlerFn(this, function () {
212 return handleAction('lookup');
214 }, [_('Domain Lookup')]),
217 'class': 'btn cbi-button cbi-button-negative',
218 'click': ui
.createHandlerFn(this, function () {
219 return handleAction('stop');
224 'class': 'btn cbi-button cbi-button-positive',
225 'click': ui
.createHandlerFn(this, function () {
226 return handleAction('reload');
231 'class': 'btn cbi-button cbi-button-positive',
232 'click': ui
.createHandlerFn(this, function () {
233 return handleAction('restart');
243 tabbed config section
245 s
= m
.section(form
.NamedSection
, 'global', 'banip', _('Settings'));
247 s
.tab('general', _('General Settings'));
248 s
.tab('advanced', _('Advanced Settings'));
249 s
.tab('adv_chain', _('Table/Chain Settings'));
250 s
.tab('adv_set', _('Feed/Set Settings'));
251 s
.tab('adv_log', _('Log Settings'));
252 s
.tab('adv_email', _('E-Mail Settings'));
253 s
.tab('feeds', _('Feed Selection'));
258 o
= s
.taboption('general', form
.DummyValue
, '_sub');
260 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
261 + '<hr style="width: 200px; height: 1px;" />';
263 o
= s
.taboption('general', form
.Flag
, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
266 o
= s
.taboption('general', form
.Flag
, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of processing errors.'));
269 o
= s
.taboption('general', form
.Flag
, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network devices, interfaces, subnets, protocols and utilities automatically.'));
272 o
= s
.taboption('general', form
.Flag
, 'ban_protov4', _('IPv4 Support'), _('Enables IPv4 support.'));
273 o
.depends('ban_autodetect', '0');
277 o
= s
.taboption('general', form
.Flag
, 'ban_protov6', _('IPv6 Support'), _('Enables IPv6 support.'));
278 o
.depends('ban_autodetect', '0');
282 o
= s
.taboption('general', widgets
.DeviceSelect
, 'ban_dev', _('Network Devices'), _('Select the WAN network device(s).'));
283 o
.depends('ban_autodetect', '0');
289 o
= s
.taboption('general', widgets
.NetworkSelect
, 'ban_ifv4', _('IPv4 Network Interfaces'), _('Select the logical WAN IPv4 network interface(s).'));
290 o
.depends('ban_autodetect', '0');
296 o
= s
.taboption('general', widgets
.NetworkSelect
, 'ban_ifv6', _('IPv6 Network Interfaces'), _('Select the logical WAN IPv6 network interface(s).'));
297 o
.depends('ban_autodetect', '0');
303 o
= s
.taboption('general', form
.ListValue
, 'ban_fetchcmd', _('Download Utility'), _('Select one of the pre-configured download utilities.'));
304 o
.depends('ban_autodetect', '0');
305 o
.value('uclient-fetch');
312 o
= s
.taboption('general', form
.Value
, 'ban_fetchparm', _('Download Parameters'), _('Override the pre-configured download options for the selected download utility.'))
313 o
.depends('ban_autodetect', '0');
317 o
= s
.taboption('general', widgets
.NetworkSelect
, 'ban_trigger', _('Reload Trigger Interface'), _('List of available reload trigger interface(s).'));
322 o
= s
.taboption('general', form
.Value
, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds during interface reload and boot.'));
323 o
.placeholder
= '10';
324 o
.datatype
= 'range(1,300)';
327 o
= s
.taboption('general', form
.ListValue
, 'ban_fetchretry', _('Download Retries'), _('Number of download attempts in case of an error (not supported by uclient-fetch).'));
334 o
.placeholder
= _('-- default --');
339 o
= s
.taboption('general', form
.Flag
, 'ban_fetchinsecure', _('Download Insecure'), _('Don\'t check SSL server certificates during download.'));
343 additional settings tab
345 o
= s
.taboption('advanced', form
.DummyValue
, '_sub');
347 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
348 + '<hr style="width: 200px; height: 1px;" />';
350 o
= s
.taboption('advanced', form
.ListValue
, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.'));
351 o
.value('-20', _('Highest Priority'));
352 o
.value('-10', _('High Priority'));
353 o
.value('0', _('Normal Priority'));
354 o
.value('10', _('Less Priority'));
355 o
.value('19', _('Least Priority'));
357 o
.placeholder
= _('-- default --');
362 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.'));
368 o
.placeholder
= _('-- default --');
373 o
= s
.taboption('advanced', form
.ListValue
, 'ban_cores', _('CPU Cores'), _('Limit the cpu cores used by banIP to save RAM.'));
382 o
= s
.taboption('advanced', form
.ListValue
, 'ban_splitsize', _('Set Split Size'), _('Split external Set loading after every n members to save RAM.'));
392 o
= s
.taboption('advanced', form
.Value
, 'ban_basedir', _('Base Directory'), _('Base working directory while banIP processing.'));
393 o
.placeholder
= '/tmp';
396 o
= s
.taboption('advanced', form
.Value
, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed feed backups.'));
397 o
.placeholder
= '/tmp/banIP-backup';
400 o
= s
.taboption('advanced', form
.Value
, 'ban_reportdir', _('Report Directory'), _('Target directory for banIP-related report files.'));
401 o
.placeholder
= '/tmp/banIP-report';
404 o
= s
.taboption('advanced', form
.Flag
, 'ban_deduplicate', _('Deduplicate IPs'), _('Deduplicate IP addresses across all active Sets and tidy up the local blocklist.'));
408 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.'));
413 advanced chain settings tab
415 o
= s
.taboption('adv_chain', form
.DummyValue
, '_sub');
417 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
418 + '<hr style="width: 200px; height: 1px;" />';
420 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_nftpriority', _('Chain Priority'), _('Set the nft chain priority within the banIP table, lower values means higher priority.'));
427 o
.placeholder
= _('-- default --');
432 o
= s
.taboption('adv_chain', form
.Value
, 'ban_allowflag', _('Allow Protocol/Ports'), _('Always allow a protocol \(tcp/udp\) with certain ports or port ranges in WAN-Input and WAN-Forward chain.'));
433 o
.placeholder
= 'tcp 80 443-445';
436 o
= s
.taboption('adv_chain', widgets
.DeviceSelect
, 'ban_vlanallow', _('Allow VLAN Forwards'), _('Always allow certain VLAN forwards.'));
442 o
= s
.taboption('adv_chain', widgets
.DeviceSelect
, 'ban_vlanblock', _('Block VLAN Forwards'), _('Always block certain VLAN forwards.'));
448 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_icmplimit', _('ICMP-Threshold'), _('ICMP-Threshold in packets per second to prevent WAN-DoS attacks. To disable this safeguard set it to \'0\'.'));
457 o
.placeholder
= _('-- default --');
462 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_synlimit', _('SYN-Threshold'), _('SYN-Threshold in packets per second to prevent WAN-DoS attacks. To disable this safeguard set it to \'0\'.'));
471 o
.placeholder
= _('-- default --');
476 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_udplimit', _('UDP-Threshold'), _('UDP-Threshold in packets per second to prevent WAN-DoS attacks. To disable this safeguard set it to \'0\'.'));
485 o
.placeholder
= _('-- default --');
491 advanced Set settings tab
493 o
= s
.taboption('adv_set', form
.DummyValue
, '_sub');
495 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
496 + '<hr style="width: 200px; height: 1px;" />';
498 o
= s
.taboption('adv_set', form
.ListValue
, 'ban_nftpolicy', _('Set Policy'), _('Set the nft policy for banIP-related Sets.'));
499 o
.value('memory', _('memory'));
500 o
.value('performance', _('performance'));
501 o
.default = 'memory';
502 o
.placeholder
= _('-- default --');
507 o
= s
.taboption('adv_set', form
.ListValue
, 'ban_blocktype', _('Block Type'), _('Drop packets silently or actively reject the traffic on WAN-Input and WAN-Forward chains.'));
508 o
.value('drop', _('drop'));
509 o
.value('reject', _('reject'));
511 o
.placeholder
= _('-- default --');
516 o
= s
.taboption('adv_set', form
.ListValue
, 'ban_blockpolicy', _('Default Block Policy'), _('By default each feed is active in all supported chains. Limit the default block policy to a certain chain.'));
517 o
.value('input', _('WAN-Input Chain'));
518 o
.value('forwardwan', _('WAN-Forward Chain'));
519 o
.value('forwardlan', _('LAN-Forward Chain'));
523 let feed
, feeds
, descr
;
524 if (result
&& Object
.keys(result
).length
) {
527 feeds
= JSON
.parse(result
[0]);
529 ui
.addNotification(null, E('p', _('Unable to parse the custom feed file!')), 'error');
532 if (result
[1] && (!feeds
|| (feeds
&& !Object
.keys(feeds
).length
))) {
534 feeds
= JSON
.parse(result
[1]);
536 ui
.addNotification(null, E('p', _('Unable to parse the default feed file!')), 'error');
540 if (feeds
&& Object
.keys(feeds
).length
) {
541 o
= s
.taboption('adv_set', form
.MultiValue
, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.'));
542 o
.value('allowlist', _('local allowlist'));
543 o
.value('blocklist', _('local blocklist'));
544 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
545 feed
= Object
.keys(feeds
)[i
].trim();
551 o
= s
.taboption('adv_set', form
.MultiValue
, 'ban_blockforwardwan', _('WAN-Forward Chain'), _('Limit certain feeds to the WAN-Forward chain.'));
552 o
.value('allowlist', _('local allowlist'));
553 o
.value('blocklist', _('local blocklist'));
554 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
555 feed
= Object
.keys(feeds
)[i
].trim();
561 o
= s
.taboption('adv_set', form
.MultiValue
, 'ban_blockforwardlan', _('LAN-Forward Chain'), _('Limit certain feeds to the LAN-Forward chain.'));
562 o
.value('allowlist', _('local allowlist'));
563 o
.value('blocklist', _('local blocklist'));
564 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
565 feed
= Object
.keys(feeds
)[i
].trim();
573 advanced log settings tab
575 o
= s
.taboption('adv_log', form
.DummyValue
, '_sub');
577 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'
578 + '<hr style="width: 200px; height: 1px;" />';
580 o
= s
.taboption('adv_log', form
.ListValue
, 'ban_nftloglevel', _('NFT Log Level'), _('Set the syslog level for NFT logging.'));
581 o
.value('emerg', _('emerg'));
582 o
.value('alert', _('alert'));
583 o
.value('crit', _('crit'));
584 o
.value('err', _('err'));
585 o
.value('warn', _('warn'));
586 o
.value('notice', _('notice'));
587 o
.value('info', _('info'));
588 o
.value('debug', _('debug'));
590 o
.placeholder
= _('-- default --');
595 o
= s
.taboption('adv_log', form
.Flag
, 'ban_logprerouting', _('Log Prerouting'), _('Log suspicious Prerouting packets.'));
598 o
= s
.taboption('adv_log', form
.Flag
, 'ban_loginput', _('Log WAN-Input'), _('Log suspicious incoming WAN packets.'));
601 o
= s
.taboption('adv_log', form
.Flag
, 'ban_logforwardwan', _('Log WAN-Forward'), _('Log suspicious forwarded WAN packets.'));
604 o
= s
.taboption('adv_log', form
.Flag
, 'ban_logforwardlan', _('Log LAN-Forward'), _('Log suspicious forwarded LAN packets.'));
607 o
= s
.taboption('adv_log', form
.Value
, 'ban_logreadfile', _('Logfile Location'), _('Location for parsing the log file, e.g. via syslog-ng, to deactivate the standard parsing via logread.'));
608 o
.placeholder
= '/var/log/messages';
611 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\'.'));
619 o
.placeholder
= _('-- default --');
624 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.'));
626 o
.datatype
= 'range(1,10)';
629 o
= s
.taboption('adv_log', form
.DynamicList
, 'ban_logterm', _('Log Terms'), _('The default regular expressions are filtering suspicious ssh, LuCI, nginx and asterisk traffic.'));
633 o
= s
.taboption('adv_log', form
.Flag
, 'ban_remotelog', _('Enable Remote Logging'), _('Enable the cgi interface to receive remote logging events.'));
638 o
= s
.taboption('adv_log', form
.Value
, 'ban_remotetoken', _('Remote Token'), _('Token to communicate with the cgi interface.'));
639 o
.depends('ban_remotelog', '1');
640 o
.datatype
= 'and(minlength(3),maxlength(20))';
641 o
.validate = function (section_id
, value
) {
643 return _('Empty field not allowed');
645 if (!value
.match(/^[A-Za-z0-9\.\:]+$/)) {
646 return _('Invalid characters');
654 advanced email settings tab
656 o
= s
.taboption('adv_email', form
.DummyValue
, '_sub');
658 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('To enable email notifications, set up the \'msmtp\' package and specify a vaild E-Mail receiver address.') + '</em>'
659 + '<hr style="width: 200px; height: 1px;" />';
661 o
= s
.taboption('adv_email', form
.Flag
, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.'));
664 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.'));
665 o
.placeholder
= 'name@example.com';
668 o
= s
.taboption('adv_email', form
.Value
, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
669 o
.placeholder
= 'no-reply@banIP';
672 o
= s
.taboption('adv_email', form
.Value
, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
673 o
.placeholder
= 'banIP notification';
676 o
= s
.taboption('adv_email', form
.Value
, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
677 o
.placeholder
= 'ban_notify';
678 o
.datatype
= 'uciname';
684 o
= s
.taboption('feeds', form
.DummyValue
, '_sub');
686 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service reload to take effect.') + '</em>'
687 + '<hr style="width: 200px; height: 1px;" />'
688 + '<em style="color:#37c;font-weight:bold;">' + _('External Blocklist Feeds') + '</em>';
690 if (feeds
&& Object
.keys(feeds
).length
) {
691 o
= s
.taboption('feeds', form
.MultiValue
, 'ban_feed', _('Blocklist Feed'));
692 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
693 feed
= Object
.keys(feeds
)[i
].trim();
694 descr
= feeds
[feed
].descr
.trim() || '-';
695 o
.value(feed
, feed
+ ' (' + descr
+ ')');
701 let err
, ccode
, rir
, country
, countries
= [];
702 if (result
&& Object
.keys(result
[2]).length
) {
703 countries
= result
[2].trim().split('\n');
704 if (countries
&& countries
.length
) {
705 o
= s
.taboption('feeds', form
.MultiValue
, 'ban_country', _('Countries') + ' (<abbr title="Regional Internet Registries">RIR</abbr>)');
706 for (let i
= 0; i
< countries
.length
; i
++) {
708 ccode
= countries
[i
].match(/^(\w+)\t/)[1].trim();
709 rir
= countries
[i
].match(/^\w+\t(\w+)\t/)[1].trim();
710 country
= countries
[i
].match(/^\w+\t\w+\t(.*$)/)[1].trim();
711 o
.value(ccode
, country
+ ' (' + rir
+ ')');
715 ui
.addNotification(null, E('p', _('Unable to parse the countries file!')), 'error');
725 o
= s
.taboption('feeds', form
.MultiValue
, 'ban_region', _('Regional Internet Registry'));
726 o
.value('AFRINIC', _('AFRINIC - serving Africa and the Indian Ocean region'));
727 o
.value('APNIC', _('APNIC - serving the Asia Pacific region'));
728 o
.value('ARIN', _('ARIN - serving Canada and the United States'));
729 o
.value('LACNIC', _('LACNIC - serving the Latin American and Caribbean region'));
730 o
.value('RIPE', _('RIPE - serving Europe, Middle East and Central Asia'));
734 o
= s
.taboption('feeds', form
.DynamicList
, 'ban_asn', _('ASNs'));
735 o
.datatype
= 'uinteger';
739 o
= s
.taboption('feeds', form
.DummyValue
, '_feeds');
741 o
.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('External Allowlist Feeds') + '</em>';
743 if (countries
&& countries
.length
) {
744 o
= s
.taboption('feeds', form
.DynamicList
, 'ban_allowurl', _('Allowlist Feed URLs'));
745 for (let i
= 0; i
< countries
.length
; i
++) {
747 ccode
= countries
[i
].match(/^(\w+)\t/)[1].trim();
748 rir
= countries
[i
].match(/^\w+\t(\w+)\t/)[1].trim();
749 country
= countries
[i
].match(/^\w+\t\w+\t(.*$)/)[1].trim();
750 o
.value('https://www.ipdeny.com/ipblocks/data/aggregated/' + ccode
+ '-aggregated.zone', country
+ ' IPv4 (' + rir
+ ')');
751 o
.value('https://www.ipdeny.com/ipv6/ipaddresses/aggregated/' + ccode
+ '-aggregated.zone', country
+ ' IPv6 (' + rir
+ ')');
758 o
.validate = function (section_id
, value
) {
762 if (!value
.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) {
763 return _('Protocol/URL format not supported');
769 o
= s
.taboption('feeds', form
.DummyValue
, '_feeds');
771 o
.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('Local Feed Settings') + '</em>';
773 o
= s
.taboption('feeds', form
.Flag
, 'ban_autoallowlist', _('Auto Allowlist'), _('Automatically add resolved domains and uplink IPs to the local banIP allowlist.'));
777 o
= s
.taboption('feeds', form
.ListValue
, 'ban_autoallowuplink', _('Auto Allow Uplink'), _('Limit the uplink autoallow function.'));
778 o
.depends('ban_autoallowlist', '1');
779 o
.value('disable', _('Disable'));
780 o
.value('subnet', _('Subnet'));
781 o
.value('ip', _('IP'));
782 o
.default = 'subnet';
783 o
.placeholder
= _('-- default --');
788 o
= s
.taboption('feeds', form
.Flag
, 'ban_autoblocklist', _('Auto Blocklist'), _('Automatically add resolved domains and suspicious IPs to the local banIP blocklist.'));
792 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.'));
797 o
= s
.taboption('feeds', form
.ListValue
, 'ban_nftexpiry', _('Blocklist Set Expiry'), _('Expiry time for auto added blocklist Set members.'));
807 o
= s
.taboption('feeds', form
.Flag
, 'ban_allowlistonly', _('Allowlist Only'), _('Restrict the internet access from/to a small number of secure IPs.'));
812 handleSaveApply
: null,