2010-05-17 00:35:22 +02:00
|
|
|
#! /bin/bash
|
2018-06-23 17:29:01 +02:00
|
|
|
# The Shoreline Firewall (Shorewall) Packet Filtering Firewall - V5.2
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
2014-01-04 18:48:27 +01:00
|
|
|
# (c) 2010,2012-2014 - Tom Eastep (teastep@shorewall.net)
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
|
|
|
# On most distributions, this file should be called /etc/init.d/shorewall.
|
|
|
|
#
|
2014-01-04 18:48:27 +01:00
|
|
|
# This program is part of Shorewall.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by the
|
|
|
|
# Free Software Foundation, either version 2 of the license or, at your
|
|
|
|
# option, any later version.
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
2014-01-04 18:48:27 +01:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
2014-01-04 18:48:27 +01:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2010-05-17 00:35:22 +02:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# chkconfig: - 09 91
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: shorewall-init
|
2010-05-21 21:46:22 +02:00
|
|
|
# Required-start: $local_fs
|
|
|
|
# Required-stop: $local_fs
|
2010-05-21 21:37:22 +02:00
|
|
|
# Default-Start: 2 3 5
|
2011-06-19 19:10:59 +02:00
|
|
|
# Default-Stop: 6
|
2010-05-17 00:35:22 +02:00
|
|
|
# Short-Description: Initialize the firewall at boot time
|
|
|
|
# Description: Place the firewall in a safe state at boot time
|
|
|
|
# prior to bringing up the network.
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
if [ "$(id -u)" != "0" ]
|
|
|
|
then
|
|
|
|
echo "You must be root to start, stop or restart \"Shorewall \"."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check if shorewall-init is configured or not
|
|
|
|
if [ -f "/etc/sysconfig/shorewall-init" ]
|
|
|
|
then
|
|
|
|
. /etc/sysconfig/shorewall-init
|
|
|
|
if [ -z "$PRODUCTS" ]
|
|
|
|
then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-03-31 01:21:37 +02:00
|
|
|
#
|
|
|
|
# The installer may alter this
|
|
|
|
#
|
|
|
|
. /usr/share/shorewall/shorewallrc
|
2012-03-24 21:05:39 +01:00
|
|
|
|
2012-09-05 16:37:12 +02:00
|
|
|
# Locate the current PRODUCT's statedir
|
|
|
|
setstatedir() {
|
|
|
|
local statedir
|
|
|
|
if [ -f ${CONFDIR}/${PRODUCT}/vardir ]; then
|
|
|
|
statedir=$( . /${CONFDIR}/${PRODUCT}/vardir && echo $VARDIR )
|
|
|
|
fi
|
|
|
|
|
2014-11-24 08:43:32 +01:00
|
|
|
[ -n "$statedir" ] && STATEDIR=${statedir} || STATEDIR=${VARLIB}/${PRODUCT}
|
2012-09-05 16:37:12 +02:00
|
|
|
|
2017-12-18 19:25:56 +01:00
|
|
|
if [ -x ${STATEDIR}/firewall ]; then
|
|
|
|
return 0
|
|
|
|
elif [ $PRODUCT = shorewall -o $PRODUCT = shorewall6 ]; then
|
2015-05-07 21:31:46 +02:00
|
|
|
${SBINDIR}/$PRODUCT ${OPTIONS} compile $STATEDIR/firewall
|
|
|
|
else
|
2017-12-18 19:25:56 +01:00
|
|
|
return 1
|
2012-09-05 16:37:12 +02:00
|
|
|
fi
|
|
|
|
}
|
2012-09-02 19:23:11 +02:00
|
|
|
|
2010-05-17 00:35:22 +02:00
|
|
|
# Initialize the firewall
|
|
|
|
shorewall_start () {
|
2010-07-23 18:26:47 +02:00
|
|
|
local PRODUCT
|
2012-09-02 22:43:43 +02:00
|
|
|
local STATEDIR
|
2010-05-17 00:35:22 +02:00
|
|
|
|
2016-12-28 20:09:08 +01:00
|
|
|
printf "Initializing \"Shorewall-based firewalls\": "
|
2010-07-23 18:26:47 +02:00
|
|
|
for PRODUCT in $PRODUCTS; do
|
2015-05-07 21:31:46 +02:00
|
|
|
if setstatedir; then
|
2017-12-18 19:25:56 +01:00
|
|
|
if ! ${SBIN}/$PRODUCT status > /dev/null 2>&1; then
|
|
|
|
${STATEDIR}/firewall ${OPTIONS} stop
|
2010-07-23 18:26:47 +02:00
|
|
|
fi
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-06-19 19:10:59 +02:00
|
|
|
if [ -n "$SAVE_IPSETS" -a -f "$SAVE_IPSETS" ]; then
|
|
|
|
ipset -R < "$SAVE_IPSETS"
|
|
|
|
fi
|
|
|
|
|
2010-05-17 00:35:22 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clear the firewall
|
|
|
|
shorewall_stop () {
|
2010-07-23 18:26:47 +02:00
|
|
|
local PRODUCT
|
2013-08-24 18:37:56 +02:00
|
|
|
local STATEDIR
|
2010-05-17 00:35:22 +02:00
|
|
|
|
2016-12-28 20:09:08 +01:00
|
|
|
printf "Clearing \"Shorewall-based firewalls\": "
|
2010-07-23 18:26:47 +02:00
|
|
|
for PRODUCT in $PRODUCTS; do
|
2015-05-07 21:31:46 +02:00
|
|
|
if setstatedir; then
|
2017-12-18 19:25:56 +01:00
|
|
|
${STATEDIR}/firewall ${OPTIONS} clear
|
2010-05-17 00:35:22 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-06-19 19:10:59 +02:00
|
|
|
if [ -n "$SAVE_IPSETS" ]; then
|
|
|
|
mkdir -p $(dirname "$SAVE_IPSETS")
|
|
|
|
if ipset -S > "${SAVE_IPSETS}.tmp"; then
|
2017-09-18 18:28:43 +02:00
|
|
|
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"
|
2011-06-19 19:10:59 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-05-17 00:35:22 +02:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
shorewall_start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
shorewall_stop
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: /etc/init.d/shorewall-init {start|stop}"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|