Fixed multiple firewall enviroments usage

This commit is contained in:
2020-12-15 09:19:22 +01:00
parent 6c85b6de9d
commit 2cefb52334

View File

@@ -18,40 +18,24 @@ fi
############################### ###############################
COUNT=1
COUNT_SOURCE_IP=$(set |grep SOURCE_IP |wc -l) COUNT_SOURCE_IP=$(set |grep SOURCE_IP |wc -l)
COUNT_TARGET_IP=$(set |grep TARGET_IP |wc -l) COUNT_TARGET_IP=$(set |grep TARGET_IP |wc -l)
COUNT_TARGET_PORT=$(set |grep TARGET_PORT |wc -l) COUNT_TARGET_PORT=$(set |grep TARGET_PORT |wc -l)
if [[ $COUNT_SOURCE_IP -ge $COUNT_TARGET_IP ]] ; then
if [[ $COUNT_SOURCE_IP -ge $COUNT_TARGET_PORT ]] ; then
COUNT=$COUNT_SOURCE_IP
else
if [[ $COUNT_TARGET_IP -ge $COUNT_TARGET_PORT ]] ; then
COUNT=$COUNT_TARGET_IP
else
COUNT=$COUNT_TARGET_PORT
fi
fi
else # not ge
if [[ $COUNT_TARGET_IP -ge $COUNT_TARGET_PORT ]] ; then
COUNT=$COUNT_TARGET_IP
else
COUNT=$COUNT_TARGET_PORT
fi
fi
for i in $(seq 1 $COUNT) ; do
for source_ip_index in $(seq 1 $COUNT_SOURCE_IP) ; do
if set |grep SOURCE_IP_ ; then if set |grep SOURCE_IP_ ; then
SOURCE_IP=$(eval "echo \${"SOURCE_IP_$i"}") SOURCE_IP=$(eval "echo \${"SOURCE_IP_$source_ip_index"}")
fi fi
for target_ip_index in $(seq 1 $COUNT_TARGET_IP) ; do
if set |grep TARGET_IP_ ; then if set |grep TARGET_IP_ ; then
TARGET_IP=$(eval "echo \${"TARGET_IP_$i"}") TARGET_IP=$(eval "echo \${"TARGET_IP_$target_ip_index"}")
fi fi
for target_port_index in $(seq 1 $COUNT_TARGET_PORT) ; do
if set |grep TARGET_PORT_ ; then if set |grep TARGET_PORT_ ; then
TARGET_PORT=$(eval "echo \${"TARGET_PORT_$i"}") TARGET_PORT=$(eval "echo \${"TARGET_PORT_$target_port_index"}")
fi fi
# DELETE UNECESSARY LINES FROM PREVIOUS RULES # DELETE UNECESSARY LINES FROM PREVIOUS RULES
@@ -64,7 +48,7 @@ for i in $(seq 1 $COUNT) ; do
done done
fi fi
# CREATE PORT FORWARD RULES
/sbin/iptables-legacy -I $CHAIN -s $SOURCE_IP -d $TARGET_IP -p $PROTOCOL --dport $TARGET_PORT -m comment --comment "$COMMENT" -j ACCEPT /sbin/iptables-legacy -I $CHAIN -s $SOURCE_IP -d $TARGET_IP -p $PROTOCOL --dport $TARGET_PORT -m comment --comment "$COMMENT" -j ACCEPT
done
done
done done