fix path iptables for refill_blacklist

This commit is contained in:
Valentin CZERYBA 2023-03-04 10:47:04 +01:00
parent c1197dec5c
commit 3c1f18d417

View File

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
IPTABLES=/usr/sbin/iptables
BLACKLIST=/etc/sentinel/blacklist BLACKLIST=/etc/sentinel/blacklist
chain_count=$(iptables -L BLACKLIST -n | wc -l) chain_count=$(${IPTABLES} -L BLACKLIST -n | wc -l)
if [ ${chain_count} -eq 0 ]; then if [ ${chain_count} -eq 0 ]; then
iptables -N BLACKLIST ${IPTABLES} -N BLACKLIST
iptables -I INPUT 1 -p tcp -m tcp --dport 80 -j BLACKLIST ${IPTABLES} -I INPUT 1 -p tcp -m tcp --dport 80 -j BLACKLIST
iptables -I INPUT 1 -p tcp -m tcp --dport 443 -j BLACKLIST ${IPTABLES} -I INPUT 1 -p tcp -m tcp --dport 443 -j BLACKLIST
fi fi
if [ ! -f ${BLACKLIST} ]; then if [ ! -f ${BLACKLIST} ]; then
@ -13,7 +14,7 @@ if [ ! -f ${BLACKLIST} ]; then
fi fi
if [ ${chain_count} -gt 2 ]; then if [ ${chain_count} -gt 2 ]; then
chain_count=$(echo ${chain_count}-2 |bc) chain_count=$(echo ${chain_count}-2 |bc)
iptables_ip=($(iptables -nvL BLACKLIST | tail -n ${chain_count} | awk '{print $8}')) iptables_ip=($(${IPTABLES} -nvL BLACKLIST | tail -n ${chain_count} | awk '{print $8}'))
for i in $(cat ${BLACKLIST}) for i in $(cat ${BLACKLIST})
do do
block_ip=1 block_ip=1
@ -24,13 +25,13 @@ if [ ${chain_count} -gt 2 ]; then
fi fi
done done
if [ ${block_ip} -eq 1 ]; then if [ ${block_ip} -eq 1 ]; then
iptables -A BLACKLIST -s ${i} -j DROP ${IPTABLES} -A BLACKLIST -s ${i} -j DROP
fi fi
done done
else else
for i in $(cat ${BLACKLIST}) for i in $(cat ${BLACKLIST})
do do
iptables -A BLACKLIST -s ${i} -j DROP ${IPTABLES} -A BLACKLIST -s ${i} -j DROP
done done
fi fi