more env var

This commit is contained in:
2024-12-18 22:31:50 +01:00
parent ca70371683
commit 9cc63a9c22
2 changed files with 14 additions and 17 deletions

View File

@@ -2,54 +2,50 @@
#
# Script to add /remove IPs to iptables
[[ -z "${IPTABLES_COMMENT}" ]] && commment="-m comment --comment \"$4\"" || comment=""
[[ -n "${IPTABLES_COMMENT}" ]] && commment="-m comment --comment \"$4\"" || comment=""
: ${IPTABLES_CHAIN:=INPUT}
function iptableAdd () {
if [[ -z "${IPTABLES_INSERT}" ]]; then
iptables $comment -A INPUT -s $1 -j DROP
iptables $comment -A DOCKER-USER -s $1 -j DROP
iptables $comment -A $IPTABLES_CHAIN -s "$1" -j DROP
else
iptables $comment -I INPUT $IPTABLES_INSERT -s $1 -j DROP
iptables $comment -I DOCKER-USER $IPTABLES_INSERT -s $1 -j DROP
iptables $comment -I $IPTABLES_CHAIN "$IPTABLES_INSERT" -s "$1" -j DROP
fi
}
function iptableDel () {
iptables $comment -D INPUT -s $1 -j DROP
iptables $comment -D DOCKER-USER -s $1 -j DROP
iptables $comment -D $IPTABLES_CHAIN -s "$1" -j DROP
}
function ip6tableAdd () {
if [[ -z "${IPTABLES_INSERT}" ]]; then
ip6tables $comment -A INPUT -s $1 -j DROP
ip6tables $comment -A DOCKER-USER -s $1 -j DROP
ip6tables $comment -A $IPTABLES_CHAIN -s "$1" -j DROP
else
ip6tables $comment -I INPUT $IPTABLES_INSERT -s $1 -j DROP
ip6tables $comment -I DOCKER-USER $IPTABLES_INSERT -s $1 -j DROP
ip6tables $comment -I $IPTABLES_CHAIN "$IPTABLES_INSERT" -s "$1" -j DROP
fi
}
function ip6tableDel () {
ip6tables $comment -D INPUT -s $1 -j DROP
ip6tables $comment -D DOCKER-USER -s $1 -j DROP
ip6tables $comment -D $IPTABLES_CHAIN -s "$1" -j DROP
}
#determine action
if [ "$1" = "add" ]; then #add
if [[ "$2" =~ .*[.].* ]]; then #ipv4
echo "add $2 for $3 with $4"
iptableAdd $2
iptableAdd "$2"
elif [[ "$2" =~ .*[:].* ]]; then #ipv6
echo "IPV6 : add $2 for $3 with $4"
ip6tableAdd $2
ip6tableAdd "$2"
fi
elif [ "$1" = "del" ]; then #del
if [[ "$2" =~ .*[.].* ]]; then #ipv4
echo "del $2 for $3 with $4"
iptableDel $2
iptableDel "$2"
elif [[ "$2" =~ .*[:].* ]]; then #ipv6
echo "IPV6 : add $2 for $3 with $4"
ip6tableDel $2
ip6tableDel "$2"
fi
else
echo "unknon action"