summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDirk Brenken <dev@brenken.org>2024-04-26 13:42:54 +0200
committerDirk Brenken <dev@brenken.org>2024-04-26 13:42:54 +0200
commitf8eb80bac75df3b69ec0713524c8bb1169d7d3b9 (patch)
treece2030020c4385ca21f9eec005dd4a0b89ad5b24
parent443f7d67c6908f9e8ead5f72c8de9f1c41b2ad60 (diff)
luci-app-banip: handle load errors of the countries file
* properly handle/skip possible read errors in try/catch blocks Signed-off-by: Dirk Brenken <dev@brenken.org>
-rw-r--r--applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js27
1 files changed, 18 insertions, 9 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 c8c571f735..bb5804a90e 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
@@ -643,10 +643,15 @@ return view.extend({
o = s.taboption('feeds', form.MultiValue, 'ban_country', _('Countries (RIR)'));
for (let i = 0; i < countries.length; i++) {
- 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 + ')');
+ 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] = "";
+ ui.addNotification(null, E('p', _('Unable to parse the countries file: %s').format(e.message)), 'error');
+ }
}
o.optional = true;
o.rmempty = true;
@@ -673,11 +678,15 @@ return view.extend({
o = s.taboption('feeds', form.DynamicList, 'ban_allowurl', _('Allowlist Feed URLs'));
if (countries) {
for (let i = 0; i < countries.length; i++) {
- 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('https://www.ipdeny.com/ipblocks/data/aggregated/' + ccode + '-aggregated.zone', country + ' IPv4 (' + rir + ')');
- o.value('https://www.ipdeny.com/ipv6/ipaddresses/aggregated/' + ccode + '-aggregated.zone', country + ' IPv6 (' + rir + ')');
+ 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('https://www.ipdeny.com/ipblocks/data/aggregated/' + ccode + '-aggregated.zone', country + ' IPv4 (' + rir + ')');
+ o.value('https://www.ipdeny.com/ipv6/ipaddresses/aggregated/' + ccode + '-aggregated.zone', country + ' IPv6 (' + rir + ')');
+ } catch (e) {
+ countries[i] = "";
+ }
}
}
o.optional = true;