banIP: update 1.5.6-2
authorDirk Brenken <[email protected]>
Tue, 29 Apr 2025 19:55:30 +0000 (21:55 +0200)
committerDirk Brenken <[email protected]>
Tue, 29 Apr 2025 19:55:55 +0000 (21:55 +0200)
* add an uci-defaults script for housekeeping and option migration from former versions
* small fixes and improvements

Signed-off-by: Dirk Brenken <[email protected]>
net/banip/Makefile
net/banip/files/95-banip-housekeeping [new file with mode: 0755]
net/banip/files/banip-functions.sh

index 757f68901e5105f4a813855f4a6b4fca386e90f9..8f9c6bc5785d22429cd20c0bda29a716e87cd7f8 100644 (file)
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=banip
 PKG_VERSION:=1.5.6
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 PKG_LICENSE:=GPL-3.0-or-later
 PKG_MAINTAINER:=Dirk Brenken <[email protected]>
 
@@ -66,6 +66,9 @@ define Package/banip/install
 
        $(INSTALL_DIR) $(1)/www/cgi-bin
        $(INSTALL_BIN) ./files/banip.cgi $(1)/www/cgi-bin/banip
+
+       $(INSTALL_DIR) $(1)/etc/uci-defaults
+       $(INSTALL_BIN) ./files/95-banip-housekeeping $(1)/etc/uci-defaults
 endef
 
 $(eval $(call BuildPackage,banip))
diff --git a/net/banip/files/95-banip-housekeeping b/net/banip/files/95-banip-housekeeping
new file mode 100755 (executable)
index 0000000..55b2439
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Copyright (c) 2015-2025 Dirk Brenken ([email protected])
+# This is free software, licensed under the GNU General Public License v3.
+
+# (s)hellcheck exceptions
+# shellcheck disable=all
+
+export LC_ALL=C
+export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
+
+config="banip"
+old_options="ban_loginput ban_logforwardwan ban_logforwardlan ban_blockinput ban_blockforwardwan ban_blockforwardlan"
+
+for option in ${old_options}; do
+       if uci -q get ${config}.global.${option} >/dev/null 2>&1; then
+               old_values="$(uci -q get "${config}.global.${option}")"
+               for value in ${old_values}; do
+                       case "${option}" in
+                               "ban_loginput" | "ban_logforwardwan")
+                                       uci -q set "${config}".global.ban_loginbound="${value}"
+                               ;;
+                               "ban_logforwardlan")
+                                       uci -q set "${config}".global.ban_logoutbound="${value}"
+                               ;;
+                       esac
+               done
+               uci -q delete "${config}.global.${option}"
+       fi
+done
+[ -n "$(uci -q changes "${config}")" ] && uci -q commit "${config}"
+exit 0
index 7e9b110b6c08b67506fee15fcb7109fb0e33e947..24394623af248468adac330254f5fa953cd1d67f 100644 (file)
@@ -546,17 +546,17 @@ f_etag() {
                if [ -z "${etag_id}" ]; then
                        etag_id="$(printf "%s" "${http_head}" | "${ban_awkcmd}" 'tolower($0)~/^[[:space:]]*last-modified: /{gsub(/[Ll]ast-[Mm]odified:|[[:space:]]|,|:/,"");printf "%s\n",$1}')"
                fi
-               etag_cnt="$("${ban_grepcmd}" -c "^${feed}" "${ban_backupdir}/banIP.etag")"
+               etag_cnt="$("${ban_grepcmd}" -c "^${feed} " "${ban_backupdir}/banIP.etag")"
                if [ "${http_code}" = "200" ] && [ "${etag_cnt}" = "${feed_cnt}" ] && [ -n "${etag_id}" ] &&
-                       "${ban_grepcmd}" -q "^${feed}${feed_suffix}[[:space:]]\+${etag_id}\$" "${ban_backupdir}/banIP.etag"; then
+                       "${ban_grepcmd}" -q "^${feed} ${feed_suffix}[[:space:]]\+${etag_id}\$" "${ban_backupdir}/banIP.etag"; then
                        out_rc="0"
                elif [ -n "${etag_id}" ]; then
                        if [ "${feed_cnt}" -lt "${etag_cnt}" ]; then
-                               "${ban_sedcmd}" -i "/^${feed}/d" "${ban_backupdir}/banIP.etag"
+                               "${ban_sedcmd}" -i "/^${feed} /d" "${ban_backupdir}/banIP.etag"
                        else
-                               "${ban_sedcmd}" -i "/^${feed}${feed_suffix}/d" "${ban_backupdir}/banIP.etag"
+                               "${ban_sedcmd}" -i "/^${feed} ${feed_suffix//\//\\/}/d" "${ban_backupdir}/banIP.etag"
                        fi
-                       printf "%-50s%s\n" "${feed}${feed_suffix}" "${etag_id}" >>"${ban_backupdir}/banIP.etag"
+                       printf "%-50s%s\n" "${feed} ${feed_suffix}" "${etag_id}" >>"${ban_backupdir}/banIP.etag"
                        out_rc="2"
                fi
        fi
@@ -1162,7 +1162,7 @@ f_down() {
                        if [ "${feed_rc}" = "0" ]; then
                                for split_file in "${tmp_file}".*; do
                                        if [ -s "${split_file}" ]; then
-                                               "${ban_sedcmd}" -i "1 i #!${ban_nftcmd} -f\nadd element inet banIP "${feed}" { " "${split_file}"
+                                               "${ban_sedcmd}" -i "1 i #!${ban_nftcmd} -f\nadd element inet banIP ${feed} { " "${split_file}"
                                                printf "%s\n" "}" >>"${split_file}"
                                                # load split file to nftset
                                                #
@@ -1371,7 +1371,7 @@ f_getstatus() {
                        else
                                json_get_var value "${key}" >/dev/null 2>&1
                                if [ "${key}" = "status" ]; then
-                                       [ "${value}" = "active" ] && value="${value} ($(f_actual))" || value="${value}"
+                                       [ "${value}" = "active" ] && value="${value} ($(f_actual))"
                                fi
                        fi
                        if [ "${key}" != "wan_interfaces" ] && [ "${key}" != "vlan_allow" ] && [ "${key}" != "vlan_block" ]; then