From 1f978052637ef9b7e040e44ee4ce1322d4da6ccb Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Fri, 26 Apr 2024 13:42:54 +0200 Subject: [PATCH] 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 (cherry picked from commit f8eb80bac75df3b69ec0713524c8bb1169d7d3b9) --- .../resources/view/banip/overview.js | 27 ++++++++++++------- 1 file 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; -- 2.30.2