2011-08-22 18:05:40 +02:00
|
|
|
#! /bin/bash
|
|
|
|
#
|
|
|
|
# chkconfig: - 09 91
|
|
|
|
# description: Initialize the shorewall firewall at boot time
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: shorewall-init
|
|
|
|
# Required-Start: $local_fs
|
|
|
|
# Required-Stop: $local_fs
|
|
|
|
# Default-Start:
|
|
|
|
# Default-Stop: 0 1 2 3 4 5 6
|
|
|
|
# Short-Description: Initialize the shorewall firewall at boot time
|
|
|
|
# Description: Place the firewall in a safe state at boot time
|
|
|
|
# prior to bringing up the network.
|
|
|
|
### END INIT INFO
|
2012-03-26 16:20:31 +02:00
|
|
|
#determine where the files were installed
|
2012-09-01 19:52:59 +02:00
|
|
|
|
|
|
|
. /usr/share/shorewall/shorewallrc
|
2012-03-26 16:20:31 +02:00
|
|
|
|
2011-08-22 18:05:40 +02:00
|
|
|
prog="shorewall-init"
|
|
|
|
logger="logger -i -t $prog"
|
|
|
|
lockfile="/var/lock/subsys/shorewall-init"
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
|
|
|
# Get startup options (override default)
|
|
|
|
OPTIONS=
|
|
|
|
|
|
|
|
# check if shorewall-init is configured or not
|
|
|
|
if [ -f "/etc/sysconfig/shorewall-init" ]; then
|
|
|
|
. /etc/sysconfig/shorewall-init
|
|
|
|
else
|
|
|
|
echo "/etc/sysconfig/shorewall-init not found"
|
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
|
2012-09-02 22:43:43 +02:00
|
|
|
# set the STATEDIR variable
|
|
|
|
setstatedir() {
|
|
|
|
local statedir
|
2012-09-05 16:37:12 +02:00
|
|
|
if [ -f ${CONFDIR}/${PRODUCT}/vardir ]; then
|
|
|
|
statedir=$( . /${CONFDIR}/${PRODUCT}/vardir && echo $VARDIR )
|
2012-09-02 22:43:43 +02:00
|
|
|
fi
|
2012-09-05 16:37:12 +02:00
|
|
|
|
2014-11-24 08:43:32 +01:00
|
|
|
[ -n "$statedir" ] && STATEDIR=${statedir} || STATEDIR=${VARLIB}/${PRODUCT}
|
2013-05-11 05:21:00 +02:00
|
|
|
|
2016-12-01 00:04:40 +01:00
|
|
|
if [ $PRODUCT = shorewall ]; then
|
|
|
|
${SBINDIR}/shorewall compile
|
|
|
|
elif [ $PRODUCT = shorewall6 ]; then
|
|
|
|
${SBINDIR}/shorewall -6 compile
|
2013-05-12 01:38:09 +02:00
|
|
|
else
|
|
|
|
return 0
|
2012-09-02 22:43:43 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-08-22 18:05:40 +02:00
|
|
|
# Initialize the firewall
|
|
|
|
start () {
|
2012-09-02 19:23:11 +02:00
|
|
|
local PRODUCT
|
2013-08-24 18:37:56 +02:00
|
|
|
local STATEDIR
|
2011-08-22 18:05:40 +02:00
|
|
|
|
|
|
|
if [ -z "$PRODUCTS" ]; then
|
|
|
|
echo "No firewalls configured for shorewall-init"
|
|
|
|
failure
|
|
|
|
return 6 #Not configured
|
|
|
|
fi
|
|
|
|
|
2016-12-28 20:09:08 +01:00
|
|
|
printf "Initializing \"Shorewall-based firewalls\": "
|
2013-05-12 01:38:09 +02:00
|
|
|
|
2017-09-18 18:28:43 +02:00
|
|
|
if [ -n "$SAVE_IPSETS" -a -f "$SAVE_IPSETS" ]; then
|
|
|
|
ipset -R < "$SAVE_IPSETS"
|
|
|
|
fi
|
|
|
|
|
2012-09-02 19:23:11 +02:00
|
|
|
for PRODUCT in $PRODUCTS; do
|
2012-09-02 22:43:43 +02:00
|
|
|
setstatedir
|
2013-05-12 01:38:09 +02:00
|
|
|
retval=$?
|
|
|
|
|
2013-05-13 20:23:53 +02:00
|
|
|
if [ $retval -eq 0 ]; then
|
2013-05-12 01:38:09 +02:00
|
|
|
if [ -x "${STATEDIR}/firewall" ]; then
|
2013-09-09 16:33:08 +02:00
|
|
|
${STATEDIR}/firewall ${OPTIONS} stop 2>&1 | $logger
|
2013-05-12 01:38:09 +02:00
|
|
|
retval=${PIPESTATUS[0]}
|
|
|
|
[ $retval -ne 0 ] && break
|
|
|
|
else
|
|
|
|
retval=6 #Product not configured
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
break
|
2011-08-22 18:05:40 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2013-05-06 18:36:00 +02:00
|
|
|
if [ $retval -eq 0 ]; then
|
2011-08-22 18:05:40 +02:00
|
|
|
touch $lockfile
|
|
|
|
success
|
|
|
|
else
|
|
|
|
failure
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clear the firewall
|
|
|
|
stop () {
|
2012-09-02 19:23:11 +02:00
|
|
|
local PRODUCT
|
2013-08-24 18:37:56 +02:00
|
|
|
local STATEDIR
|
2011-08-22 18:05:40 +02:00
|
|
|
|
2016-12-28 20:09:08 +01:00
|
|
|
printf "Clearing \"Shorewall-based firewalls\": "
|
2013-05-12 01:38:09 +02:00
|
|
|
|
2012-09-02 19:23:11 +02:00
|
|
|
for PRODUCT in $PRODUCTS; do
|
2012-09-02 22:43:43 +02:00
|
|
|
setstatedir
|
2013-05-12 01:38:09 +02:00
|
|
|
retval=$?
|
|
|
|
|
|
|
|
if [ $retval -eq 0 ]; then
|
|
|
|
if [ -x "${STATEDIR}/firewall" ]; then
|
2013-09-09 16:33:08 +02:00
|
|
|
${STATEDIR}/firewall ${OPTIONS} clear 2>&1 | $logger
|
2013-05-12 01:38:09 +02:00
|
|
|
retval=${PIPESTATUS[0]}
|
|
|
|
[ $retval -ne 0 ] && break
|
|
|
|
else
|
|
|
|
retval=6 #Product not configured
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
break
|
2011-08-22 18:05:40 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2013-05-06 18:36:00 +02:00
|
|
|
if [ $retval -eq 0 ]; then
|
2017-09-18 18:28:43 +02:00
|
|
|
if [ -n "$SAVE_IPSETS" ]; then
|
|
|
|
mkdir -p $(dirname "$SAVE_IPSETS")
|
|
|
|
if ipset -S > "${SAVE_IPSETS}.tmp"; then
|
|
|
|
grep -qE -- '^(-N|create )' "${SAVE_IPSETS}.tmp" && mv -f "${SAVE_IPSETS}.tmp" "$SAVE_IPSETS" || rm -f "${SAVE_IPSETS}.tmp"
|
|
|
|
else
|
|
|
|
rm -f "${SAVE_IPSETS}.tmp"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-08-22 18:05:40 +02:00
|
|
|
rm -f $lockfile
|
|
|
|
success
|
|
|
|
else
|
|
|
|
failure
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
return $retval
|
|
|
|
}
|
|
|
|
|
|
|
|
status_q() {
|
|
|
|
status > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
status_q && exit 0
|
|
|
|
$1
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
status_q || exit 0
|
|
|
|
$1
|
|
|
|
;;
|
2012-09-17 19:23:18 +02:00
|
|
|
restart|reload|force-reload|condrestart|try-restart)
|
2011-08-22 18:05:40 +02:00
|
|
|
echo "Not implemented"
|
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status $prog
|
|
|
|
;;
|
|
|
|
*)
|
2013-05-13 20:23:53 +02:00
|
|
|
echo "Usage: $0 {start|stop|status}"
|
2011-08-22 18:05:40 +02:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|