9 'require tools.widgets as widgets';
14 function handleAction(ev
) {
15 if (ev
=== 'restart') {
16 let map
= document
.querySelector('.cbi-map');
17 return 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;float:left;font-weight:bold;padding-top:0rem;' }, _('Status')),
166 E('div', { 'class': 'cbi-value-field spinning', 'id': 'status', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '\xa0')
168 E('div', { 'class': 'cbi-value' }, [
169 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Version')),
170 E('div', { 'class': 'cbi-value-field', 'id': 'version', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
172 E('div', { 'class': 'cbi-value' }, [
173 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Element Count')),
174 E('div', { 'class': 'cbi-value-field', 'id': 'elements', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
176 E('div', { 'class': 'cbi-value' }, [
177 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Active Feeds')),
178 E('div', { 'class': 'cbi-value-field', 'id': 'feeds', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
180 E('div', { 'class': 'cbi-value' }, [
181 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Active Devices')),
182 E('div', { 'class': 'cbi-value-field', 'id': 'devices', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
184 E('div', { 'class': 'cbi-value' }, [
185 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Active Uplink')),
186 E('div', { 'class': 'cbi-value-field', 'id': 'uplink', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
188 E('div', { 'class': 'cbi-value' }, [
189 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('NFT Information')),
190 E('div', { 'class': 'cbi-value-field', 'id': 'nft', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
192 E('div', { 'class': 'cbi-value' }, [
193 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Run Information')),
194 E('div', { 'class': 'cbi-value-field', 'id': 'run', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
196 E('div', { 'class': 'cbi-value' }, [
197 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Run Flags')),
198 E('div', { 'class': 'cbi-value-field', 'id': 'flags', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
200 E('div', { 'class': 'cbi-value' }, [
201 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('Last Run')),
202 E('div', { 'class': 'cbi-value-field', 'id': 'last', 'style': 'margin-bottom:-5px;float:left;color:#37c;font-weight:bold;' }, '-')
204 E('div', { 'class': 'cbi-value' }, [
205 E('label', { 'class': 'cbi-value-title', 'style': 'margin-bottom:-5px;float:left;font-weight:bold;padding-top:0rem;' }, _('System Information')),
206 E('div', { 'class': 'cbi-value-field', 'id': 'system', 'style': 'margin-bottom:-5px;float:left;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');
235 }, [_('Apply & Restart')])
242 tabbed config section
244 s
= m
.section(form
.NamedSection
, 'global', 'banip', _('Settings'));
246 s
.tab('general', _('General Settings'));
247 s
.tab('advanced', _('Advanced Settings'));
248 s
.tab('adv_chain', _('Table/Chain Settings'));
249 s
.tab('adv_set', _('Feed/Set Settings'));
250 s
.tab('adv_log', _('Log Settings'));
251 s
.tab('adv_email', _('E-Mail Settings'));
252 s
.tab('feeds', _('Feed Selection'));
257 o
= s
.taboption('general', form
.Flag
, 'ban_enabled', _('Enabled'), _('Enable the banIP service.'));
260 o
= s
.taboption('general', form
.Flag
, 'ban_debug', _('Verbose Debug Logging'), _('Enable verbose debug logging in case of processing errors.'));
263 o
= s
.taboption('general', form
.Flag
, 'ban_autodetect', _('Auto Detection'), _('Detect relevant network devices, interfaces, subnets, protocols and utilities automatically.'));
266 o
= s
.taboption('general', form
.Flag
, 'ban_protov4', _('IPv4 Support'), _('Enables IPv4 support.'));
267 o
.depends('ban_autodetect', '0');
271 o
= s
.taboption('general', form
.Flag
, 'ban_protov6', _('IPv6 Support'), _('Enables IPv6 support.'));
272 o
.depends('ban_autodetect', '0');
276 o
= s
.taboption('general', widgets
.DeviceSelect
, 'ban_dev', _('Network Devices'), _('Select the WAN network device(s).'));
277 o
.depends('ban_autodetect', '0');
283 o
= s
.taboption('general', widgets
.NetworkSelect
, 'ban_ifv4', _('IPv4 Network Interfaces'), _('Select the logical WAN IPv4 network interface(s).'));
284 o
.depends('ban_autodetect', '0');
290 o
= s
.taboption('general', widgets
.NetworkSelect
, 'ban_ifv6', _('IPv6 Network Interfaces'), _('Select the logical WAN IPv6 network interface(s).'));
291 o
.depends('ban_autodetect', '0');
297 o
= s
.taboption('general', form
.ListValue
, 'ban_fetchcmd', _('Download Utility'), _('Select one of the pre-configured download utilities.'));
298 o
.depends('ban_autodetect', '0');
299 o
.value('uclient-fetch');
306 o
= s
.taboption('general', form
.Value
, 'ban_fetchparm', _('Download Parameters'), _('Override the pre-configured download options for the selected download utility.'))
307 o
.depends('ban_autodetect', '0');
311 o
= s
.taboption('general', widgets
.NetworkSelect
, 'ban_trigger', _('Reload Trigger Interface'), _('List of available reload trigger interface(s).'));
316 o
= s
.taboption('general', form
.Value
, 'ban_triggerdelay', _('Trigger Delay'), _('Additional trigger delay in seconds during interface reload and boot.'));
317 o
.placeholder
= '10';
318 o
.datatype
= 'range(1,300)';
321 o
= s
.taboption('general', form
.ListValue
, 'ban_fetchretry', _('Download Retries'), _('Number of download attempts in case of an error (not supported by uclient-fetch).'));
331 o
= s
.taboption('general', form
.Flag
, 'ban_fetchinsecure', _('Download Insecure'), _('Don\'t check SSL server certificates during download.'));
335 additional settings tab
337 o
= s
.taboption('advanced', form
.DummyValue
, '_sub');
339 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
341 o
= s
.taboption('advanced', form
.ListValue
, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.'));
342 o
.value('-20', _('Highest Priority'));
343 o
.value('-10', _('High Priority'));
344 o
.value('0', _('Normal Priority'));
345 o
.value('10', _('Less Priority'));
346 o
.value('19', _('Least Priority'));
351 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.'));
352 o
.value('512', '512');
353 o
.value('1024', '1024');
354 o
.value('2048', '2048');
355 o
.value('4096', '4096');
360 o
= s
.taboption('advanced', form
.ListValue
, 'ban_cores', _('CPU Cores'), _('Limit the cpu cores used by banIP to save RAM.'));
369 o
= s
.taboption('advanced', form
.ListValue
, 'ban_splitsize', _('Set Split Size'), _('Split external Set loading after every n members to save RAM.'));
379 o
= s
.taboption('advanced', form
.Value
, 'ban_basedir', _('Base Directory'), _('Base working directory while banIP processing.'));
380 o
.placeholder
= '/tmp';
383 o
= s
.taboption('advanced', form
.Value
, 'ban_backupdir', _('Backup Directory'), _('Target directory for compressed feed backups.'));
384 o
.placeholder
= '/tmp/banIP-backup';
387 o
= s
.taboption('advanced', form
.Value
, 'ban_reportdir', _('Report Directory'), _('Target directory for banIP-related report files.'));
388 o
.placeholder
= '/tmp/banIP-report';
391 o
= s
.taboption('advanced', form
.Flag
, 'ban_deduplicate', _('Deduplicate IPs'), _('Deduplicate IP addresses across all active Sets and tidy up the local blocklist.'));
395 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.'));
400 advanced chain settings tab
402 o
= s
.taboption('adv_chain', form
.DummyValue
, '_sub');
404 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
406 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.'));
408 o
.value('-100', '-100');
409 o
.value('-150', '-150');
410 o
.value('-200', '-200');
415 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.'));
416 o
.placeholder
= 'tcp 80 443-445';
419 o
= s
.taboption('adv_chain', widgets
.DeviceSelect
, 'ban_vlanallow', _('Allow VLAN Forwards'), _('Always allow certain VLAN forwards.'));
425 o
= s
.taboption('adv_chain', widgets
.DeviceSelect
, 'ban_vlanblock', _('Block VLAN Forwards'), _('Always block certain VLAN forwards.'));
431 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_icmplimit', _('ICMP-Treshold'), _('ICMP-Treshold in packets per second to prevent WAN-DDoS attacks.'));
435 o
.value('100', '100');
436 o
.value('250', '250');
437 o
.value('500', '500');
442 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_synlimit', _('SYN-Treshold'), _('SYN-Treshold in packets per second to prevent WAN-DDoS attacks.'));
446 o
.value('100', '100');
447 o
.value('250', '250');
448 o
.value('500', '500');
453 o
= s
.taboption('adv_chain', form
.ListValue
, 'ban_udplimit', _('UDP-Treshold'), _('UDP-Treshold in packets per second to prevent WAN-DDoS attacks.'));
457 o
.value('100', '100');
458 o
.value('250', '250');
459 o
.value('500', '500');
465 advanced Set settings tab
467 o
= s
.taboption('adv_set', form
.DummyValue
, '_sub');
469 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
471 o
= s
.taboption('adv_set', form
.ListValue
, 'ban_nftpolicy', _('Set Policy'), _('Set the nft policy for banIP-related Sets.'));
472 o
.value('memory', _('memory'));
473 o
.value('performance', _('performance'));
474 o
.default = 'memory';
478 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.'));
479 o
.value('drop', _('drop'));
480 o
.value('reject', _('reject'));
485 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.'));
486 o
.value('input', _('WAN-Input Chain'));
487 o
.value('forwardwan', _('WAN-Forward Chain'));
488 o
.value('forwardlan', _('LAN-Forward Chain'));
492 let feed
, feeds
, descr
;
495 feeds
= JSON
.parse(result
[0]);
498 ui
.addNotification(null, E('p', _('Unable to parse the custom feed file: %s').format(e
.message
)), 'error');
500 } else if (result
[1]) {
502 feeds
= JSON
.parse(result
[1]);
505 ui
.addNotification(null, E('p', _('Unable to parse the default feed file: %s').format(e
.message
)), 'error');
509 o
= s
.taboption('adv_set', form
.MultiValue
, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.'));
510 o
.value('allowlist', _('local allowlist'));
511 o
.value('blocklist', _('local blocklist'));
512 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
513 feed
= Object
.keys(feeds
)[i
].trim();
519 o
= s
.taboption('adv_set', form
.MultiValue
, 'ban_blockforwardwan', _('WAN-Forward Chain'), _('Limit certain feeds to the WAN-Forward chain.'));
520 o
.value('allowlist', _('local allowlist'));
521 o
.value('blocklist', _('local blocklist'));
522 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
523 feed
= Object
.keys(feeds
)[i
].trim();
529 o
= s
.taboption('adv_set', form
.MultiValue
, 'ban_blockforwardlan', _('LAN-Forward Chain'), _('Limit certain feeds to the LAN-Forward chain.'));
530 o
.value('allowlist', _('local allowlist'));
531 o
.value('blocklist', _('local blocklist'));
532 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
533 feed
= Object
.keys(feeds
)[i
].trim();
541 advanced log settings tab
543 o
= s
.taboption('adv_log', form
.DummyValue
, '_sub');
545 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>';
547 o
= s
.taboption('adv_log', form
.ListValue
, 'ban_nftloglevel', _('NFT Log Level'), _('Set the syslog level for NFT logging.'));
548 o
.value('emerg', _('emerg'));
549 o
.value('alert', _('alert'));
550 o
.value('crit', _('crit'));
551 o
.value('err', _('err'));
552 o
.value('warn', _('warn'));
553 o
.value('notice', _('notice'));
554 o
.value('info', _('info'));
555 o
.value('debug', _('debug'));
560 o
= s
.taboption('adv_log', form
.Flag
, 'ban_logprerouting', _('Log Prerouting'), _('Log suspicious Prerouting packets.'));
563 o
= s
.taboption('adv_log', form
.Flag
, 'ban_loginput', _('Log WAN-Input'), _('Log suspicious incoming WAN packets.'));
566 o
= s
.taboption('adv_log', form
.Flag
, 'ban_logforwardwan', _('Log WAN-Forward'), _('Log suspicious forwarded WAN packets.'));
569 o
= s
.taboption('adv_log', form
.Flag
, 'ban_logforwardlan', _('Log LAN-Forward'), _('Log suspicious forwarded LAN packets.'));
572 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.'));
573 o
.placeholder
= '/var/log/messages';
576 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\'.'));
577 o
.value('0', _('Disable'));
579 o
.value('100', '100');
580 o
.value('250', '250');
581 o
.value('500', '500');
582 o
.value('1000', '1000');
587 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.'));
589 o
.datatype
= 'range(1,10)';
592 o
= s
.taboption('adv_log', form
.DynamicList
, 'ban_logterm', _('Log Terms'), _('The default regular expressions are filtering suspicious ssh, LuCI, nginx and asterisk traffic.'));
596 o
= s
.taboption('adv_log', form
.Flag
, 'ban_remotelog', _('Enable Remote Logging'), _('Enable the cgi interface to receive remote logging events.'));
601 o
= s
.taboption('adv_log', form
.Value
, 'ban_remotetoken', _('Remote Token'), _('Token to communicate with the cgi interface.'));
602 o
.depends('ban_remotelog', '1');
603 o
.datatype
= 'and(minlength(3),maxlength(20))';
604 o
.validate = function (section_id
, value
) {
606 return _('Empty field not allowed');
608 if (!value
.match(/^[A-Za-z0-9\.\:]+$/)) {
609 return _('Invalid characters');
617 advanced email settings tab
619 o
= s
.taboption('adv_email', form
.DummyValue
, '_sub');
621 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>';
623 o
= s
.taboption('adv_email', form
.Flag
, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.'));
626 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.'));
627 o
.placeholder
= 'name@example.com';
630 o
= s
.taboption('adv_email', form
.Value
, 'ban_mailsender', _('E-Mail Sender Address'), _('Sender address for banIP notification E-Mails.'));
631 o
.placeholder
= 'no-reply@banIP';
634 o
= s
.taboption('adv_email', form
.Value
, 'ban_mailtopic', _('E-Mail Topic'), _('Topic for banIP notification E-Mails.'));
635 o
.placeholder
= 'banIP notification';
638 o
= s
.taboption('adv_email', form
.Value
, 'ban_mailprofile', _('E-Mail Profile'), _('Profile used by \'msmtp\' for banIP notification E-Mails.'));
639 o
.placeholder
= 'ban_notify';
640 o
.datatype
= 'uciname';
646 o
= s
.taboption('feeds', form
.DummyValue
, '_sub');
648 o
.default = '<em style="color:#37c;font-weight:bold;">' + _('External Blocklist Feeds') + '</em>';
651 o
= s
.taboption('feeds', form
.MultiValue
, 'ban_feed', _('Blocklist Feed'));
652 for (let i
= 0; i
< Object
.keys(feeds
).length
; i
++) {
653 feed
= Object
.keys(feeds
)[i
].trim();
654 descr
= feeds
[feed
].descr
.trim() || '-';
655 o
.value(feed
, feed
+ ' (' + descr
+ ')');
661 let ccode
, rir
, country
, countries
= [];
663 countries
= result
[2].trim().split('\n');
665 o
= s
.taboption('feeds', form
.MultiValue
, 'ban_country', _('Countries (RIR)'));
666 for (let i
= 0; i
< countries
.length
; i
++) {
668 ccode
= countries
[i
].match(/^(\w+)\t/)[1].trim();
669 rir
= countries
[i
].match(/^\w+\t(\w+)\t/)[1].trim();
670 country
= countries
[i
].match(/^\w+\t\w+\t(.*$)/)[1].trim();
671 o
.value(ccode
, country
+ ' (' + rir
+ ')');
674 ui
.addNotification(null, E('p', _('Unable to parse the countries file: %s').format(e
.message
)), 'error');
681 o
= s
.taboption('feeds', form
.MultiValue
, 'ban_region', _('Regional Internet Registry'));
682 o
.value('AFRINIC', _('AFRINIC - serving Africa and the Indian Ocean region'));
683 o
.value('APNIC', _('APNIC - serving the Asia Pacific region'));
684 o
.value('ARIN', _('ARIN - serving Canada and the United States'));
685 o
.value('LACNIC', _('LACNIC - serving the Latin American and Caribbean region'));
686 o
.value('RIPE', _('RIPE - serving Europe, Middle East and Central Asia'));
690 o
= s
.taboption('feeds', form
.DynamicList
, 'ban_asn', _('ASNs'));
691 o
.datatype
= 'uinteger';
695 o
= s
.taboption('feeds', form
.DummyValue
, '_feeds');
697 o
.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('External Allowlist Feeds') + '</em>';
699 o
= s
.taboption('feeds', form
.DynamicList
, 'ban_allowurl', _('Allowlist Feed URLs'));
701 for (let i
= 0; i
< countries
.length
; i
++) {
703 ccode
= countries
[i
].match(/^(\w+)\t/)[1].trim();
704 rir
= countries
[i
].match(/^\w+\t(\w+)\t/)[1].trim();
705 country
= countries
[i
].match(/^\w+\t\w+\t(.*$)/)[1].trim();
706 o
.value('https://www.ipdeny.com/ipblocks/data/aggregated/' + ccode
+ '-aggregated.zone', country
+ ' IPv4 (' + rir
+ ')');
707 o
.value('https://www.ipdeny.com/ipv6/ipaddresses/aggregated/' + ccode
+ '-aggregated.zone', country
+ ' IPv6 (' + rir
+ ')');
715 o
.validate = function (section_id
, value
) {
719 if (!value
.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) {
720 return _('Protocol/URL format not supported');
725 o
= s
.taboption('feeds', form
.DummyValue
, '_feeds');
727 o
.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('Local Feed Settings') + '</em>';
729 o
= s
.taboption('feeds', form
.Flag
, 'ban_autoallowlist', _('Auto Allowlist'), _('Automatically add resolved domains and uplink IPs to the local banIP allowlist.'));
733 o
= s
.taboption('feeds', form
.ListValue
, 'ban_autoallowuplink', _('Auto Allow Uplink'), _('Limit the uplink autoallow function.'));
734 o
.depends('ban_autoallowlist', '1');
735 o
.value('disable', _('Disable'));
736 o
.value('subnet', _('Subnet'));
737 o
.value('ip', _('IP'));
738 o
.default = 'subnet';
742 o
= s
.taboption('feeds', form
.Flag
, 'ban_autoblocklist', _('Auto Blocklist'), _('Automatically add resolved domains and suspicious IPs to the local banIP blocklist.'));
746 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.'));
751 o
= s
.taboption('feeds', form
.ListValue
, 'ban_nftexpiry', _('Blocklist Set Expiry'), _('Expiry time for auto added blocklist Set members.'));
761 o
= s
.taboption('feeds', form
.Flag
, 'ban_allowlistonly', _('Allowlist Only'), _('Restrict the internet access from/to a small number of secure IPs.'));