luci-app-banip: sync with update 1.5.6-3
authorDirk Brenken <[email protected]>
Sat, 31 May 2025 20:14:41 +0000 (22:14 +0200)
committerDirk Brenken <[email protected]>
Sat, 31 May 2025 20:15:50 +0000 (22:15 +0200)
* fixed #7772
* map improvements
* add a json reporting cache

Signed-off-by: Dirk Brenken <[email protected]>
(cherry picked from commit 242768d42c3f444383ca1734a79a41013ff30b03)

applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js
applications/luci-app-banip/htdocs/luci-static/resources/view/banip/map.html
applications/luci-app-banip/htdocs/luci-static/resources/view/banip/setreport.js
applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json

index 4fe01adf4a145186948e11efce657616c4f2d950..4ac74f4710bb6b206f43df405b8a10a74ab88cdc 100644 (file)
@@ -123,11 +123,19 @@ function handleEdit(ev) {
        const nodeKeys = document.querySelectorAll('[id^="widget.cbid.json"][id$="name"]');
        for (let i = 0; i < nodeKeys.length; i++) {
                let subElements = {};
-               let elements = document.querySelectorAll('[id^="widget.cbid.json.' + nodeKeys[i].id.split('.')[3] + '\."]');
+               const elements = document.querySelectorAll('[id^="widget.cbid.json.' + nodeKeys[i].id.split('.')[3] + '\."], \
+                       [id^="cbid.json.' + nodeKeys[i].id.split('.')[3] + '\.rule_4"], \
+                       [id^="cbid.json.' + nodeKeys[i].id.split('.')[3] + '\.rule_6"]');
                for (const element of elements) {
-                       let key = element.id.split('.')[4];
-                       let value = element.value || "";
-                       if (value === "") {
+                       let key;
+                       const value = element.value || "";
+                       const parts = element.id.split('.');
+                       if (parts.length === 5) {
+                               key = element.id.split('.')[4];
+                       } else if (parts.length === 4) {
+                               key = element.id.split('.')[3];
+                       }
+                       if (!key || value === "") {
                                continue;
                        }
                        switch (key) {
@@ -170,11 +178,11 @@ return view.extend({
        load: function () {
                return L.resolveDefault(fs.stat('/etc/banip/banip.custom.feeds'), "")
                        .then(function (stat) {
-                       if (!stat) {
-                               return fs.write('/etc/banip/banip.custom.feeds', "");
-                       }
-                       return L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds', 'json'), "");
-               })
+                               if (!stat) {
+                                       return fs.write('/etc/banip/banip.custom.feeds', "");
+                               }
+                               return L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds', 'json'), "");
+                       })
        },
 
        render: function (data) {
@@ -221,7 +229,7 @@ return view.extend({
                                return true;
                        }
 
-                       o = s.option(form.ListValue, 'rule_4', _('Rulev4'));
+                       o = s.option(form.Value, 'rule_4', _('Rulev4'));
                        o.value('/^127\\./{next}/^(([1-9][0-9]{0,2}\\.){1}([0-9]{1,3}\\.){2}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])(\\/(1?[0-9]|2?[0-9]|3?[0-2]))?)[[:space:]]/{printf \"%s,\\n\",$1}', _('<IPv4><SPACE>'));
                        o.value('/^127\\./{next}/^(([1-9][0-9]{0,2}\\.){1}([0-9]{1,3}\\.){2}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])(\\/(1?[0-9]|2?[0-9]|3?[0-2]))?)$/{printf \"%s,\\n\",$1}', _('<IPv4><END>'));
                        o.value('/^127\\./{next}/^(([1-9][0-9]{0,2}\\.){1}([0-9]{1,3}\\.){2}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])(\\/(1?[0-9]|2?[0-9]|3?[0-2]))?)[[:space:]]/{printf \"%s/%s,\\n\",$1,$3}', _('<IPv4><SPACE>, concatinated'));
@@ -246,7 +254,7 @@ return view.extend({
                                return true;
                        }
 
-                       o = s.option(form.ListValue, 'rule_6', _('Rulev6'));
+                       o = s.option(form.Value, 'rule_6', _('Rulev6'));
                        o.value('/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)[[:space:]]/{printf \"%s,\\n\",$1}', _('<IPv6><SPACE>'));
                        o.value('/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)$/{printf \"%s,\\n\",$1}', _('<IPv6><END>'));
                        o.value('BEGIN{FS=\",\"}/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)/{printf \"%s,\\n\",$1}', _('<IPv6>, csv'));
index b7528aced964b6ba3fa8f2f52a855dcd0cc9dcfd..a125325aefb96756b0ff4c0e0a6145854bae1094 100644 (file)
        <script>
                'use strict';
 
+               /* intialize map */
+               let map = L.map('map', {
+                       zoom: 4,
+                       minZoom: 2,
+                       maxZoom: 18,
+                       center: [50, 10]
+                       }).setView([50, 10]);
+                       L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png', {
+                               attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
+               }).addTo(map);
+
                /* get mapData */
                const mapData = sessionStorage.getItem('mapData');
                if (mapData) {
@@ -56,8 +67,7 @@
                                }
                        });
 
-                       /* intialize map and map tiles */
-                       let map;
+                       /* render markers for local IPs, reset focus and zoom level */
                        homeCoordinates.forEach(function (coordObj) {
                                let latHome = coordObj.lat;
                                let lonHome = coordObj.lon;
                                let cityHome = coordObj.city.slice(0, 33);
                                let ccHome = coordObj.cc;
 
-                               if (typeof map === "undefined") {
-                                       map = L.map('map', {
-                                               zoom: 6,
-                                               minZoom: 2,
-                                               maxZoom: 18,
-                                               center: [latHome, lonHome]
-                                       }).setView([latHome, lonHome]);
-                                       L.tileLayer('https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png', {
-                                               attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
-                                       }).addTo(map);
-                               }
+                               map.setView([latHome, lonHome], 6);
 
-                               /* render markers for local IPs */
                                let circle = L.circleMarker([latHome, lonHome]).addTo(map);
                                circle.setStyle({ color: '#378242', opacity: 1.0, fillColor: '#378242', fillOpacity: 0.5, radius: 6 });
                                circle.bindPopup("<b><center>local IP</center></b>" +
index 8e9f3eaaebf7707e46a281cb66ec6c6f896d9fa1..a7c9c5d33d3792771f894fff06529db8fe212ca6 100644 (file)
@@ -9,7 +9,7 @@
 */
 function handleAction(report, ev) {
        if (ev === 'search') {
-               L.ui.showModal(_('IP Search'), [
+               ui.showModal(_('IP Search'), [
                        E('p', _('Search the banIP-related Sets for a specific IP.')),
                        E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
                                E('label', { 'style': 'padding-top:.5em', 'id': 'run' }, [
@@ -36,7 +36,7 @@ function handleAction(report, ev) {
                        E('div', { 'class': 'right' }, [
                                E('button', {
                                        'class': 'btn cbi-button',
-                                       'click': L.hideModal
+                                       'click': ui.hideModal
                                }, _('Cancel')),
                                ' ',
                                E('button', {
@@ -82,7 +82,7 @@ function handleAction(report, ev) {
                .forEach(key => {
                        selectOption.push(E('option', { 'value': content.nftables[key].set.name }, content.nftables[key].set.name));
                })
-               L.ui.showModal(_('Set Content'), [
+               ui.showModal(_('Set Content'), [
                        E('p', _('List the elements of a specific banIP-related Set.')),
                        E('div', { 'class': 'left', 'style': 'display:flex; flex-direction:column' }, [
                                E('label', { 'class': 'cbi-input-select', 'style': 'padding-top:.5em', 'id': 'run' }, [
@@ -106,7 +106,7 @@ function handleAction(report, ev) {
                        E('div', { 'class': 'right' }, [
                                E('button', {
                                        'class': 'btn cbi-button',
-                                       'click': L.hideModal
+                                       'click': ui.hideModal
                                }, _('Cancel')),
                                ' ',
                                E('button', {
@@ -129,7 +129,7 @@ function handleAction(report, ev) {
                document.getElementById('set').focus();
        }
        if (ev === 'map') {
-               let md = L.ui.showModal(null, [
+               let md = ui.showModal(null, [
                        E('div', { id: 'mapModal',
                                                style: 'position: relative;' }, [
                                E('iframe', {
@@ -141,10 +141,11 @@ function handleAction(report, ev) {
                        E('div', { 'class': 'right' }, [
                                E('button', {
                                        'class': 'btn cbi-button',
-                                       'click': function() {
-                                               L.hideModal();
+                                       'click': ui.createHandlerFn(this, function (ev) {
+                                               ui.hideModal();
                                                sessionStorage.clear();
-                                       }
+                                               location.reload();
+                                       })
                                }, _('Cancel')),
                                ' ',
                                E('button', {
@@ -171,20 +172,16 @@ return view.extend({
        },
 
        render: function (report) {
-               let content, rowSets, tblSets, notMsg, errMsg;
+               let content=[], rowSets, tblSets, notMsg, errMsg;
 
-               if (report[0]) {
+               if (report) {
                        try {
                                content = JSON.parse(report[0]);
                        } catch (e) {
-                               content = "";
-                               if (!errMsg) {
-                                       errMsg = true;
-                                       ui.addNotification(null, E('p', _('Unable to parse the report file!')), 'error');
-                               }
+                               content[0] = "";
                        }
                } else {
-                       content = "";
+                       content[0] = "";
                }
                rowSets = [];
                tblSets = E('table', { 'class': 'table', 'id': 'sets' }, [
@@ -198,7 +195,7 @@ return view.extend({
                        ])
                ]);
 
-               if (content[0] && content[0].sets) {
+               if (content[0].sets) {
                        let cnt1, cnt2;
 
                        Object.keys(content[0].sets).sort().forEach(function (key) {
@@ -311,9 +308,17 @@ return view.extend({
                                E('button', {
                                        'class': 'btn cbi-button cbi-button-positive important',
                                        'style': 'float:none',
-                                       'click': ui.createHandlerFn(this, function () {
-                                               location.reload();
-                                       })
+                                       'click': function () {
+                                               document.querySelectorAll('.cbi-page-actions button').forEach(function(btn) {
+                                                       btn.disabled = true;
+                                               })
+                                               this.blur();
+                                               this.classList.add('spinning');
+                                               L.resolveDefault(fs.exec_direct('/etc/init.d/banip', ['report', 'gen']))
+                                                       .then(function () {
+                                                               location.reload();
+                                                       })
+                                       }
                                }, [_('Refresh')]),
                        ])
                ]);
index 56bbcc3758ec3bc404eed253e43c2476e65b8e48..57332394d79814a38ba1d0e456d62df6fa7547f1 100644 (file)
@@ -57,6 +57,9 @@
                                "/etc/init.d/banip report json": [
                                        "exec"
                                ],
+                               "/etc/init.d/banip report gen": [
+                                       "exec"
+                               ],
                                "/etc/init.d/banip search [A-Za-z0-9:.]*": [
                                        "exec"
                                ],