diff options
author | Dirk Brenken <dev@brenken.org> | 2024-07-26 22:29:39 +0200 |
---|---|---|
committer | Dirk Brenken <dev@brenken.org> | 2024-07-26 22:38:06 +0200 |
commit | 7154efa1bedabdc6a35c07665909da9a5669e842 (patch) | |
tree | 778ebe822a97f224360bcd2d870dd981766cfa58 /applications/luci-app-banip/htdocs/luci-static/resources/view/banip | |
parent | f71e9cbd42db24c7743589804dacfdf5513ca883 (diff) |
luci-app-banip: optimized external file loading
* optimize loading of external config/feed files
Signed-off-by: Dirk Brenken <dev@brenken.org>
Diffstat (limited to 'applications/luci-app-banip/htdocs/luci-static/resources/view/banip')
-rw-r--r-- | applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js | 108 |
1 files changed, 61 insertions, 47 deletions
diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js index 93a80f41ce..b1dbbe0d7e 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js @@ -255,6 +255,11 @@ return view.extend({ /* general settings tab */ + o = s.taboption('general', form.DummyValue, '_sub'); + o.rawhtml = true; + o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>' + + '<hr style="width: 200px; height: 1px;" />'; + o = s.taboption('general', form.Flag, 'ban_enabled', _('Enabled'), _('Enable the banIP service.')); o.rmempty = false; @@ -339,7 +344,8 @@ return view.extend({ */ o = s.taboption('advanced', form.DummyValue, '_sub'); o.rawhtml = true; - o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'; + o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>' + + '<hr style="width: 200px; height: 1px;" />'; o = s.taboption('advanced', form.ListValue, 'ban_nicelimit', _('Nice Level'), _('The selected priority will be used for banIP background processing.')); o.value('-20', _('Highest Priority')); @@ -408,7 +414,8 @@ return view.extend({ */ o = s.taboption('adv_chain', form.DummyValue, '_sub'); o.rawhtml = true; - o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'; + o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>' + + '<hr style="width: 200px; height: 1px;" />'; 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.')); o.value('10'); @@ -485,7 +492,8 @@ return view.extend({ */ o = s.taboption('adv_set', form.DummyValue, '_sub'); o.rawhtml = true; - o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'; + o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>' + + '<hr style="width: 200px; height: 1px;" />'; o = s.taboption('adv_set', form.ListValue, 'ban_nftpolicy', _('Set Policy'), _('Set the nft policy for banIP-related Sets.')); o.value('memory', _('memory')); @@ -513,22 +521,23 @@ return view.extend({ o.rmempty = true; let feed, feeds, descr; - if (result[0]) { - try { - feeds = JSON.parse(result[0]); - } catch (e) { - feeds = ""; - ui.addNotification(null, E('p', _('Unable to parse the custom feed file!')), 'error'); + if (result && Object.keys(result).length) { + if (result[0]) { + try { + feeds = JSON.parse(result[0]); + } catch (e) { + ui.addNotification(null, E('p', _('Unable to parse the custom feed file!')), 'error'); + } } - } else if (result[1]) { - try { - feeds = JSON.parse(result[1]); - } catch (e) { - feeds = ""; - ui.addNotification(null, E('p', _('Unable to parse the default feed file!')), 'error'); + if (result[1] && (!feeds || (feeds && !Object.keys(feeds).length))) { + try { + feeds = JSON.parse(result[1]); + } catch (e) { + ui.addNotification(null, E('p', _('Unable to parse the default feed file!')), 'error'); + } } } - if (feeds) { + if (feeds && Object.keys(feeds).length) { o = s.taboption('adv_set', form.MultiValue, 'ban_blockinput', _('WAN-Input Chain'), _('Limit certain feeds to the WAN-Input chain.')); o.value('allowlist', _('local allowlist')); o.value('blocklist', _('local blocklist')); @@ -565,7 +574,8 @@ return view.extend({ */ o = s.taboption('adv_log', form.DummyValue, '_sub'); o.rawhtml = true; - o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>'; + o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service restart to take effect.') + '</em>' + + '<hr style="width: 200px; height: 1px;" />'; o = s.taboption('adv_log', form.ListValue, 'ban_nftloglevel', _('NFT Log Level'), _('Set the syslog level for NFT logging.')); o.value('emerg', _('emerg')); @@ -645,7 +655,8 @@ return view.extend({ */ o = s.taboption('adv_email', form.DummyValue, '_sub'); o.rawhtml = true; - 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>'; + 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>' + + '<hr style="width: 200px; height: 1px;" />'; o = s.taboption('adv_email', form.Flag, 'ban_mailnotification', _('E-Mail Notification'), _('Receive E-Mail notifications with every banIP run.')); o.rmempty = true; @@ -672,9 +683,11 @@ return view.extend({ */ o = s.taboption('feeds', form.DummyValue, '_sub'); o.rawhtml = true; - o.default = '<em style="color:#37c;font-weight:bold;">' + _('External Blocklist Feeds') + '</em>'; + o.default = '<em style="color:#37c;font-weight:bold;">' + _('Changes on this tab needs a banIP service reload to take effect.') + '</em>' + + '<hr style="width: 200px; height: 1px;" />' + + '<em style="color:#37c;font-weight:bold;">' + _('External Blocklist Feeds') + '</em>'; - if (feeds) { + if (feeds && Object.keys(feeds).length) { o = s.taboption('feeds', form.MultiValue, 'ban_feed', _('Blocklist Feed')); for (let i = 0; i < Object.keys(feeds).length; i++) { feed = Object.keys(feeds)[i].trim(); @@ -686,26 +699,27 @@ return view.extend({ } let err, ccode, rir, country, countries = []; - if (result[2]) { + if (result && Object.keys(result[2]).length) { countries = result[2].trim().split('\n'); - - o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries') + ' (<abbr title="Regional Internet Registries">RIR</abbr>)'); - for (let i = 0; i < countries.length; i++) { - try { - ccode = countries[i].match(/^(\w+)\t/)[1].trim(); - rir = countries[i].match(/^\w+\t(\w+)\t/)[1].trim(); - country = countries[i].match(/^\w+\t\w+\t(.*$)/)[1].trim(); - o.value(ccode, country + ' (' + rir + ')'); - } catch (e) { - countries[i] = ""; - if (!err) { - ui.addNotification(null, E('p', _('Unable to parse the countries file!')), 'error'); + if (countries && countries.length) { + o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries') + ' (<abbr title="Regional Internet Registries">RIR</abbr>)'); + for (let i = 0; i < countries.length; i++) { + try { + ccode = countries[i].match(/^(\w+)\t/)[1].trim(); + rir = countries[i].match(/^\w+\t(\w+)\t/)[1].trim(); + country = countries[i].match(/^\w+\t\w+\t(.*$)/)[1].trim(); + o.value(ccode, country + ' (' + rir + ')'); + } catch (e) { + countries[i] = ""; + if (!err) { + ui.addNotification(null, E('p', _('Unable to parse the countries file!')), 'error'); + } + err = e; } - err = e; } + o.optional = true; + o.rmempty = true; } - o.optional = true; - o.rmempty = true; } o = s.taboption('feeds', form.MultiValue, 'ban_region', _('Regional Internet Registry')); @@ -726,8 +740,8 @@ return view.extend({ o.rawhtml = true; o.default = '<hr style="width: 200px; height: 1px;" /><em style="color:#37c;font-weight:bold;">' + _('External Allowlist Feeds') + '</em>'; - o = s.taboption('feeds', form.DynamicList, 'ban_allowurl', _('Allowlist Feed URLs')); - if (countries) { + if (countries && countries.length) { + o = s.taboption('feeds', form.DynamicList, 'ban_allowurl', _('Allowlist Feed URLs')); for (let i = 0; i < countries.length; i++) { try { ccode = countries[i].match(/^(\w+)\t/)[1].trim(); @@ -739,17 +753,17 @@ return view.extend({ countries[i] = ""; } } - } - o.optional = true; - o.rmempty = true; - o.validate = function (section_id, value) { - if (!value) { + o.optional = true; + o.rmempty = true; + o.validate = function (section_id, value) { + if (!value) { + return true; + } + if (!value.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) { + return _('Protocol/URL format not supported'); + } return true; } - if (!value.match(/^(http:\/\/|https:\/\/)[A-Za-z0-9\/\.\-_\?\&\+=:~#]+$/)) { - return _('Protocol/URL format not supported'); - } - return true; } o = s.taboption('feeds', form.DummyValue, '_feeds'); |