From 5402f8eea16e9651cecf6a238c73a477c2832c9a Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Tue, 29 Apr 2025 21:55:30 +0200 Subject: [PATCH] banIP: update 1.5.6-2 * add an uci-defaults script for housekeeping and option migration from former versions * small fixes and improvements Signed-off-by: Dirk Brenken --- net/banip/Makefile | 5 ++++- net/banip/files/95-banip-housekeeping | 31 +++++++++++++++++++++++++++ net/banip/files/banip-functions.sh | 14 ++++++------ 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100755 net/banip/files/95-banip-housekeeping diff --git a/net/banip/Makefile b/net/banip/Makefile index 757f68901e..8f9c6bc578 100644 --- a/net/banip/Makefile +++ b/net/banip/Makefile @@ -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 @@ -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 index 0000000000..55b2439e69 --- /dev/null +++ b/net/banip/files/95-banip-housekeeping @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright (c) 2015-2025 Dirk Brenken (dev@brenken.org) +# 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 diff --git a/net/banip/files/banip-functions.sh b/net/banip/files/banip-functions.sh index 7e9b110b6c..24394623af 100644 --- a/net/banip/files/banip-functions.sh +++ b/net/banip/files/banip-functions.sh @@ -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 -- 2.30.2