evobackup/lib/bkctld-firewall

38 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#
# Update firewall rules of <jailname> or all
# Usage: firewall <jailname>|all
#
2020-04-01 11:23:35 +02:00
# shellcheck source=./config
2020-04-02 00:31:57 +02:00
LIBDIR="$(dirname $0)" && . "${LIBDIR}/includes"
2020-04-02 01:07:12 +02:00
jail_name="${1:-}"
if [ ! -n "${jail_name}" ]; then
"${LIBDIR}/bkctld-help" && exit 1
fi
2020-04-02 01:07:12 +02:00
jail_path=$(jail_path "${jail_name}")
test -d "${jail_path}" || error "${jail_name}: jail is missing."
iptables_input_accept() {
jail_name="${1}"
port="${2}"
ip="${3}"
echo "/sbin/iptables -A INPUT -p tcp --sport 1024: --dport ${port} -s ${ip} -j ACCEPT #${jail_name}"
}
if [ -n "${FIREWALL_RULES}" ]; then
2020-04-02 01:07:12 +02:00
[ -f "${FIREWALL_RULES}" ] && sed -i "/#${jail_name}$/d" "${FIREWALL_RULES}"
if [ -d "${jail_path}" ]; then
port=$("${LIBDIR}/bkctld-port" "${jail_name}")
for ip in $("${LIBDIR}/bkctld-ip" "${jail_name}"); do
iptables_input_accept "${jail_name}" "${port}" "${ip}" >> "${FIREWALL_RULES}"
done
[ -f /etc/init.d/minifirewall ] && /etc/init.d/minifirewall restart >/dev/null
fi
2020-04-02 01:07:12 +02:00
notice "${jail_name}: firewall rules have been updated."
fi