Merge pull request #268 from tobiastom/feature/persistent-rdr

Make RDR rules persistent between bastille restarts.
This commit is contained in:
Christer Edwards
2020-10-19 09:08:52 -06:00
committed by GitHub
2 changed files with 23 additions and 0 deletions

View File

@@ -86,6 +86,13 @@ for _jail in ${JAILS}; do
done < "${bastille_jailsdir}/${_jail}/rctl.conf" done < "${bastille_jailsdir}/${_jail}/rctl.conf"
fi fi
## add rdr rules
if [ -s "${bastille_jailsdir}/${_jail}/rdr.conf" ]; then
while read _rules; do
bastille rdr "${_jail}" ${_rules}
done < "${bastille_jailsdir}/${_jail}/rdr.conf"
fi
## add ip4.addr to firewall table:jails ## add ip4.addr to firewall table:jails
if [ -n "${bastille_network_loopback}" ]; then if [ -n "${bastille_network_loopback}" ]; then
if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then if grep -qw "interface.*=.*${bastille_network_loopback}" "${bastille_jailsdir}/${_jail}/jail.conf"; then

View File

@@ -35,6 +35,20 @@ bastille_usage() {
error_exit "Usage: bastille template TARGET project/template" error_exit "Usage: bastille template TARGET project/template"
} }
post_command_hook() {
_jail=$1
_cmd=$2
_args=$3
case $_cmd in
rdr)
if ! grep -qs "${_args}" "${bastille_jailsdir}/${_jail}/rdr.conf"; then
echo "${_args}" >> "${bastille_jailsdir}/${_jail}/rdr.conf"
fi
echo -e ${_args}
esac
}
# Handle special-case commands first. # Handle special-case commands first.
case "$1" in case "$1" in
help|-h|--help) help|-h|--help)
@@ -140,6 +154,8 @@ for _jail in ${JAILS}; do
unset IFS unset IFS
error_exit "Failed to execute command: ${_cmd}" error_exit "Failed to execute command: ${_cmd}"
fi fi
post_command_hook "${_jail}" "${_cmd}" "${_args}"
done done
set +f set +f
unset IFS unset IFS