From bd80daad97e932ecc5b9c8e45ad71baedd937736 Mon Sep 17 00:00:00 2001 From: bol-van Date: Sat, 12 Oct 2024 12:26:09 +0300 Subject: [PATCH] ipset: add missing ZAPRET_RW enabled scripts --- ipset/create_ipset.sh | 13 ++++++------ ipset/def.sh | 46 ++++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/ipset/create_ipset.sh b/ipset/create_ipset.sh index f5eaaa5..a88137d 100755 --- a/ipset/create_ipset.sh +++ b/ipset/create_ipset.sh @@ -4,12 +4,12 @@ # $1=no-update - do not update ipset, only create if its absent # $1=clear - clear ipset -IPSET_DIR="$(dirname "$0")" -IPSET_DIR="$(cd "$IPSET_DIR"; pwd)" +EXEDIR="$(dirname "$0")" +EXEDIR="$(cd "$EXEDIR"; pwd)" -. "$IPSET_DIR/def.sh" -. "$IPSET_DIR/../common/fwtype.sh" -. "$IPSET_DIR/../common/nft.sh" +. "$EXEDIR/def.sh" +. "$ZAPRET_BASE/common/fwtype.sh" +. "$ZAPRET_BASE/common/nft.sh" IPSET_CMD="$TMPDIR/ipset_cmd.txt" IPSET_SAVERAM_CHUNK_SIZE=20000 @@ -119,13 +119,12 @@ nfset_get_script_multi() local set=$1 nonempty N=1 f shift - # first we need to make sure at least one element exists or nft will fail while : do eval f=\$$N [ -n "$f" ] || break - nonempty=$(zzexist "$f" && zzcat "$f" | head -n 1) + nonempty=$(zzexist "$f" && zzcat "$f" 2>/dev/null | head -n 1) [ -n "$nonempty" ] && break N=$(($N+1)) done diff --git a/ipset/def.sh b/ipset/def.sh index 4be9e8d..174cc35 100644 --- a/ipset/def.sh +++ b/ipset/def.sh @@ -1,10 +1,12 @@ -[ -n "$IPSET_DIR" ] || { - IPSET_DIR="$(dirname "$0")" - IPSET_DIR="$(cd "$IPSET_DIR"; pwd)" -} +EXEDIR="$(dirname "$0")" +EXEDIR="$(cd "$EXEDIR"; pwd)" +ZAPRET_BASE=${ZAPRET_BASE:-"$(cd "$EXEDIR/.."; pwd)"} +ZAPRET_RW=${ZAPRET_RW:-"$ZAPRET_BASE"} +ZAPRET_CONFIG=${ZAPRET_CONFIG:-"$ZAPRET_RW/config"} +IPSET_RW_DIR="$ZAPRET_RW/ipset" -. "$IPSET_DIR/../config" -. "$IPSET_DIR/../common/base.sh" +. "$ZAPRET_CONFIG" +. "$ZAPRET_BASE/common/base.sh" [ -z "$TMPDIR" ] && TMPDIR=/tmp [ -z "$GZIP_LISTS" ] && GZIP_LISTS=1 @@ -21,27 +23,27 @@ ZIPSET=zapret ZIPSET6=zapret6 ZIPSET_EXCLUDE=nozapret ZIPSET_EXCLUDE6=nozapret6 -ZIPLIST="$IPSET_DIR/zapret-ip.txt" -ZIPLIST6="$IPSET_DIR/zapret-ip6.txt" -ZIPLIST_EXCLUDE="$IPSET_DIR/zapret-ip-exclude.txt" -ZIPLIST_EXCLUDE6="$IPSET_DIR/zapret-ip-exclude6.txt" -ZIPLIST_USER="$IPSET_DIR/zapret-ip-user.txt" -ZIPLIST_USER6="$IPSET_DIR/zapret-ip-user6.txt" -ZUSERLIST="$IPSET_DIR/zapret-hosts-user.txt" -ZHOSTLIST="$IPSET_DIR/zapret-hosts.txt" +ZIPLIST="$IPSET_RW_DIR/zapret-ip.txt" +ZIPLIST6="$IPSET_RW_DIR/zapret-ip6.txt" +ZIPLIST_EXCLUDE="$IPSET_RW_DIR/zapret-ip-exclude.txt" +ZIPLIST_EXCLUDE6="$IPSET_RW_DIR/zapret-ip-exclude6.txt" +ZIPLIST_USER="$IPSET_RW_DIR/zapret-ip-user.txt" +ZIPLIST_USER6="$IPSET_RW_DIR/zapret-ip-user6.txt" +ZUSERLIST="$IPSET_RW_DIR/zapret-hosts-user.txt" +ZHOSTLIST="$IPSET_RW_DIR/zapret-hosts.txt" ZIPSET_IPBAN=ipban ZIPSET_IPBAN6=ipban6 -ZIPLIST_IPBAN="$IPSET_DIR/zapret-ip-ipban.txt" -ZIPLIST_IPBAN6="$IPSET_DIR/zapret-ip-ipban6.txt" -ZIPLIST_USER_IPBAN="$IPSET_DIR/zapret-ip-user-ipban.txt" -ZIPLIST_USER_IPBAN6="$IPSET_DIR/zapret-ip-user-ipban6.txt" -ZUSERLIST_IPBAN="$IPSET_DIR/zapret-hosts-user-ipban.txt" -ZUSERLIST_EXCLUDE="$IPSET_DIR/zapret-hosts-user-exclude.txt" +ZIPLIST_IPBAN="$IPSET_RW_DIR/zapret-ip-ipban.txt" +ZIPLIST_IPBAN6="$IPSET_RW_DIR/zapret-ip-ipban6.txt" +ZIPLIST_USER_IPBAN="$IPSET_RW_DIR/zapret-ip-user-ipban.txt" +ZIPLIST_USER_IPBAN6="$IPSET_RW_DIR/zapret-ip-user-ipban6.txt" +ZUSERLIST_IPBAN="$IPSET_RW_DIR/zapret-hosts-user-ipban.txt" +ZUSERLIST_EXCLUDE="$IPSET_RW_DIR/zapret-hosts-user-exclude.txt" -[ -n "$IP2NET" ] || IP2NET="$IPSET_DIR/../ip2net/ip2net" -[ -n "$MDIG" ] || MDIG="$IPSET_DIR/../mdig/mdig" +[ -n "$IP2NET" ] || IP2NET="$ZAPRET_BASE/ip2net/ip2net" +[ -n "$MDIG" ] || MDIG="$ZAPRET_BASE/mdig/mdig" [ -z "$MDIG_THREADS" ] && MDIG_THREADS=30