2006-12-10 04:01:24 +01:00
|
|
|
#!/bin/sh
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2006-12-18 22:57:44 +01:00
|
|
|
# Shorewall Packet Filtering Firewall Control Program - V3.4
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2003-02-23 15:10:37 +01:00
|
|
|
# This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2007-01-12 23:06:29 +01:00
|
|
|
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007 - Tom Eastep (teastep@shorewall.net)
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# This file should be placed in /sbin/shorewall.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2006-11-11 18:21:04 +01:00
|
|
|
# Shorewall documentation is available at http://www.shorewall.net
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2003-02-23 15:10:37 +01:00
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
2002-07-06 00:24:40 +02:00
|
|
|
# as published by the Free Software Foundation.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02: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.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +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., 675 Mass Ave, Cambridge, MA 02139, USA
|
2003-02-23 15:10:37 +01:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# If an error occurs while starting or restarting the firewall, the
|
|
|
|
# firewall is automatically stopped.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# The firewall uses configuration files in /etc/shorewall/ - skeleton
|
|
|
|
# files is included with the firewall.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# Commands are:
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2006-08-27 19:27:48 +02:00
|
|
|
# shorewall add <iface>[:<host>] zone Adds a host or subnet to a zone
|
|
|
|
# shorewall delete <iface>[:<host>] zone Deletes a host or subnet from a zone
|
2005-07-28 16:37:56 +02:00
|
|
|
# shorewall dump Dumps all Shorewall-related information
|
|
|
|
# for problem analysis
|
2005-07-09 07:45:05 +02:00
|
|
|
# shorewall start Starts the firewall
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall restart Restarts the firewall
|
|
|
|
# shorewall stop Stops the firewall
|
2003-02-23 15:10:37 +01:00
|
|
|
# shorewall status Displays firewall status
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall reset Resets iptables packet and
|
|
|
|
# byte counts
|
|
|
|
# shorewall clear Open the floodgates by
|
|
|
|
# removing all iptables rules
|
|
|
|
# and setting the three permanent
|
|
|
|
# chain policies to ACCEPT
|
2002-05-01 01:13:15 +02:00
|
|
|
# shorewall refresh Rebuild the common chain to
|
|
|
|
# compensate for a change of
|
|
|
|
# broadcast address on any "detect"
|
|
|
|
# interface.
|
2006-06-17 19:17:45 +02:00
|
|
|
# shorewall [re]load [ <directory> ] <system>
|
|
|
|
# Compile a script and install it on a
|
|
|
|
# remote Shorewall Lite system.
|
2003-08-15 02:59:06 +02:00
|
|
|
# shorewall show <chain> [ <chain> ... ] Display the rules in each <chain> listed
|
2005-07-24 18:27:21 +02:00
|
|
|
# shorewall show actions Displays the available actions
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall show log Print the last 20 log messages
|
|
|
|
# shorewall show connections Show the kernel's connection
|
|
|
|
# tracking table
|
|
|
|
# shorewall show nat Display the rules in the nat table
|
|
|
|
# shorewall show {mangle|tos} Display the rules in the mangle table
|
|
|
|
# shorewall show tc Display traffic control info
|
2002-12-10 21:42:19 +01:00
|
|
|
# shorewall show classifiers Display classifiers
|
2005-07-09 07:45:05 +02:00
|
|
|
# shorewall show capabilities Display iptables/kernel capabilities
|
2002-05-01 01:13:15 +02:00
|
|
|
# shorewall version Display the installed version id
|
2006-08-17 19:46:25 +02:00
|
|
|
# shorewall check [ -e ] [ <directory> ] Dry-run compilation.
|
2006-12-03 19:18:21 +01:00
|
|
|
# shorewall try <directory> [ <timeout> ] Try a new configuration and if
|
|
|
|
# it doesn't work, revert to the
|
|
|
|
# standard one. If a timeout is supplied
|
|
|
|
# the command reverts back to the
|
|
|
|
# standard configuration after that many
|
|
|
|
# seconds have elapsed after successfully
|
|
|
|
# starting the new configuration.
|
2002-06-04 17:08:50 +02:00
|
|
|
# shorewall logwatch [ refresh-interval ] Monitor the local log for Shorewall
|
|
|
|
# messages.
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall drop <address> ... Temporarily drop all packets from the
|
2002-06-04 22:17:46 +02:00
|
|
|
# listed address(es)
|
2002-07-06 00:24:40 +02:00
|
|
|
# shorewall reject <address> ... Temporarily reject all packets from the
|
2002-06-04 22:17:46 +02:00
|
|
|
# listed address(es)
|
2003-02-23 15:10:37 +01:00
|
|
|
# shorewall allow <address> ... Reenable address(es) previously
|
2002-06-04 22:58:53 +02:00
|
|
|
# disabled with "drop" or "reject"
|
2005-07-09 06:45:32 +02:00
|
|
|
# shorewall save [ <file> ] Save the list of "rejected" and
|
2002-06-04 22:58:53 +02:00
|
|
|
# "dropped" addresses so that it will
|
|
|
|
# be automatically reinstated the
|
2002-06-11 22:14:58 +02:00
|
|
|
# next time that Shorewall starts.
|
2005-07-09 06:45:32 +02:00
|
|
|
# Save the current state so that 'shorewall
|
|
|
|
# restore' can be used.
|
|
|
|
#
|
|
|
|
# shorewall forget [ <file> ] Discard the data saved by 'shorewall save'
|
|
|
|
#
|
|
|
|
# shorewall restore [ <file> ] Restore the state of the firewall from
|
|
|
|
# previously saved information.
|
2002-05-01 01:13:15 +02:00
|
|
|
#
|
2005-12-03 00:58:57 +01:00
|
|
|
# shorewall ipaddr { <address>/<cidr> | <address> <netmask> }
|
2003-07-05 19:14:21 +02:00
|
|
|
#
|
|
|
|
# Displays information about the network
|
|
|
|
# defined by the argument[s]
|
2003-07-06 15:24:23 +02:00
|
|
|
#
|
|
|
|
# shorewall iprange <address>-<address> Decomposes a range of IP addresses into
|
|
|
|
# a list of network/host addresses.
|
|
|
|
#
|
2005-12-03 00:58:57 +01:00
|
|
|
# shorewall ipdecimal { <address> | <integer> }
|
|
|
|
#
|
|
|
|
# Displays the decimal equivalent of an IP
|
|
|
|
# address and vice versa.
|
|
|
|
#
|
2006-12-03 19:18:21 +01:00
|
|
|
# shorewall safe-start [ <directory> ] Starts the firewall and promtp for a c
|
2005-08-02 18:46:30 +02:00
|
|
|
# confirmation to accept or reject the new
|
2005-07-09 07:55:29 +02:00
|
|
|
# configuration
|
|
|
|
#
|
2006-12-03 19:18:21 +01:00
|
|
|
# shorewall safe-restart [ <directory> ] Restarts the firewall and prompt for a
|
2005-08-02 18:46:30 +02:00
|
|
|
# confirmation to accept or reject the new
|
2005-07-09 07:55:29 +02:00
|
|
|
# configuration
|
|
|
|
#
|
2006-06-16 23:43:55 +02:00
|
|
|
# shorewall compile [ -e ] [ <directory> ] <filename>
|
2006-02-03 16:10:46 +01:00
|
|
|
# Compile a firewall program file.
|
2006-10-28 16:46:43 +02:00
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Set the configuration variables from shorewall.conf
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
get_config() {
|
|
|
|
|
2006-12-11 19:42:53 +01:00
|
|
|
if [ -z "$EXPORT" -a "$(id -u)" = 0 ]; then
|
2006-06-17 00:40:36 +02:00
|
|
|
#
|
|
|
|
# This block is avoided for compile for export and when the user isn't root
|
|
|
|
#
|
2006-06-17 00:19:18 +02:00
|
|
|
export CONFIG_PATH
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-16 23:43:55 +02:00
|
|
|
[ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2006-12-06 17:37:29 +01:00
|
|
|
if [ -n "$(syslog_circular_buffer)" ]; then
|
2006-12-05 22:24:49 +01:00
|
|
|
LOGREAD="logread"
|
|
|
|
elif [ -f $LOGFILE ]; then
|
|
|
|
LOGREAD="cat $LOGFILE"
|
|
|
|
else
|
2006-06-16 23:43:55 +02:00
|
|
|
echo "LOGFILE ($LOGFILE) does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-16 23:43:55 +02:00
|
|
|
if [ -n "$IPTABLES" ]; then
|
2006-09-05 16:29:47 +02:00
|
|
|
if [ ! -x "$IPTABLES" ]; then
|
2006-06-16 23:43:55 +02:00
|
|
|
echo " ERROR: The program specified in IPTABLES does not exist or is not executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
IPTABLES=$(mywhich iptables 2> /dev/null)
|
|
|
|
if [ -z "$IPTABLES" ] ; then
|
|
|
|
echo " ERROR: Can't find iptables executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-16 23:43:55 +02:00
|
|
|
export IPTABLES
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-16 23:43:55 +02:00
|
|
|
#
|
|
|
|
# See if we have a real version of "tail" -- use separate redirection so
|
|
|
|
# that ash (aka /bin/sh on LRP) doesn't crap
|
|
|
|
#
|
2006-12-05 22:24:49 +01:00
|
|
|
if ( tail -n5 /dev/null > /dev/null 2> /dev/null ) ; then
|
2006-06-16 23:43:55 +02:00
|
|
|
realtail="Yes"
|
|
|
|
else
|
|
|
|
realtail=""
|
|
|
|
fi
|
2006-06-17 00:40:36 +02:00
|
|
|
#
|
|
|
|
# Compile by non-root needs no restore file
|
|
|
|
#
|
2006-06-16 23:43:55 +02:00
|
|
|
[ -n "$RESTOREFILE" ] || RESTOREFILE=restore
|
|
|
|
|
|
|
|
validate_restorefile RESTOREFILE
|
|
|
|
|
|
|
|
export RESTOREFILE
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-16 23:43:55 +02:00
|
|
|
case $STARTUP_ENABLED in
|
|
|
|
No|no|NO)
|
|
|
|
echo " WARNING: Shorewall startup is disabled. To enable startup, set STARTUP_ENABLED=Yes in ${CONFDIR}/shorewall.conf" >&2
|
|
|
|
STARTUP_ENABLED=
|
|
|
|
;;
|
|
|
|
Yes|yes|YES)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$STARTUP_ENABLED" ]; then
|
|
|
|
echo " ERROR: Invalid Value for STARTUP_ENABLE: $STARTUP_ENABLED" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-16 23:43:55 +02:00
|
|
|
case ${TC_ENABLED:=Internal} in
|
|
|
|
No|NO|no)
|
|
|
|
TC_ENABLED=
|
|
|
|
;;
|
|
|
|
esac
|
2006-06-08 23:49:34 +02:00
|
|
|
|
2006-06-17 00:40:36 +02:00
|
|
|
[ -n "LOGFORMAT" ] && LOGFORMAT="${LOGFORMAT%%%*}"
|
2006-06-17 19:17:45 +02:00
|
|
|
|
2006-06-17 00:40:36 +02:00
|
|
|
[ -n "$LOGFORMAT" ] || LOGFORMAT="Shorewall:"
|
|
|
|
|
|
|
|
export LOGFORMAT
|
2006-06-16 23:43:55 +02:00
|
|
|
|
2006-06-17 00:40:36 +02:00
|
|
|
fi
|
2006-06-08 23:49:34 +02:00
|
|
|
|
2003-06-28 17:22:22 +02:00
|
|
|
if [ -n "$SHOREWALL_SHELL" ]; then
|
2006-09-05 16:29:47 +02:00
|
|
|
if [ ! -x "$SHOREWALL_SHELL" ]; then
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " ERROR: The program specified in SHOREWALL_SHELL does not exist or is not executable" >&2
|
2003-06-28 17:22:22 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-01-24 18:44:19 +01:00
|
|
|
[ -n "${VERBOSITY:=2}" ]
|
|
|
|
|
2006-03-24 00:26:41 +01:00
|
|
|
VERBOSE=$(($VERBOSE_OFFSET + $VERBOSITY))
|
2006-01-24 18:44:19 +01:00
|
|
|
|
|
|
|
export VERBOSE
|
2006-01-24 16:41:38 +01:00
|
|
|
|
2006-11-30 22:28:31 +01:00
|
|
|
[ -n "${HOSTNAME:=$(hostname)}" ]
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
2006-01-22 03:35:15 +01:00
|
|
|
#
|
|
|
|
# Start Command Executor
|
|
|
|
#
|
2006-01-19 01:20:23 +01:00
|
|
|
start_command() {
|
2006-07-17 01:06:18 +02:00
|
|
|
local finished=0
|
2006-01-19 01:20:23 +01:00
|
|
|
|
2006-01-24 00:30:58 +01:00
|
|
|
do_it() {
|
2006-09-27 22:11:52 +02:00
|
|
|
local rc=0
|
|
|
|
|
2006-01-24 00:30:58 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2006-07-17 01:06:18 +02:00
|
|
|
if $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging $nolock compile ${VARDIR}/.start; then
|
|
|
|
${VARDIR}/.start $debugging start
|
2006-09-27 22:11:52 +02:00
|
|
|
rc=$?
|
|
|
|
else
|
2006-12-12 18:49:52 +01:00
|
|
|
logger -p kern.err "ERROR:Shorewall start failed"
|
2006-09-27 22:11:52 +02:00
|
|
|
rc=$?
|
2006-01-24 00:30:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-09-27 22:11:52 +02:00
|
|
|
exit $rc
|
2006-01-24 00:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if shorewall_is_started; then
|
|
|
|
error_message "Shorewall is already running"
|
2006-11-11 17:20:59 +01:00
|
|
|
exit 0
|
2006-01-24 00:30:58 +01:00
|
|
|
fi
|
|
|
|
|
2006-02-04 04:45:03 +01:00
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
|
|
|
error_message "ERROR: Startup is disabled"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2006-01-19 01:20:23 +01:00
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
FAST=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
[ -n "$SHOREWALL_DIR" -o -n "$FAST" ] && usage 2
|
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
|
|
|
echo "$1 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $1 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2006-12-10 05:12:28 +01:00
|
|
|
export SHOREWALL_DIR
|
2006-01-19 01:20:23 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
export NOROUTES
|
|
|
|
|
|
|
|
if [ -n "$FAST" ]; then
|
|
|
|
if qt mywhich make; then
|
2006-03-12 01:19:33 +01:00
|
|
|
#
|
|
|
|
# RESTOREFILE is exported by get_config()
|
|
|
|
#
|
2006-06-09 18:35:55 +02:00
|
|
|
make -qf ${CONFDIR}/Makefile || FAST=
|
2006-01-19 01:20:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$FAST" ]; then
|
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2006-01-19 01:20:23 +01:00
|
|
|
|
|
|
|
if [ -x $RESTOREPATH ]; then
|
|
|
|
if [ -x ${RESTOREPATH}-ipsets ]; then
|
|
|
|
echo Restoring Ipsets...
|
|
|
|
#
|
|
|
|
# We must purge iptables to be sure that there are no
|
|
|
|
# references to ipsets
|
|
|
|
#
|
|
|
|
iptables -F
|
|
|
|
iptables -X
|
2006-06-09 17:40:31 +02:00
|
|
|
$SHOREWALL_SHELL ${RESTOREPATH}-ipsets
|
2006-01-19 01:20:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo Restoring Shorewall...
|
2006-06-09 17:40:31 +02:00
|
|
|
$SHOREWALL_SHELL $RESTOREPATH restore
|
2006-06-09 18:35:55 +02:00
|
|
|
date > ${VARDIR}/restarted
|
2006-05-10 22:11:37 +02:00
|
|
|
progress_message3 Shorewall restored from $RESTOREPATH
|
2006-01-19 01:20:23 +01:00
|
|
|
else
|
2006-01-24 00:30:58 +01:00
|
|
|
do_it
|
2006-01-19 01:20:23 +01:00
|
|
|
fi
|
|
|
|
else
|
2006-01-24 00:30:58 +01:00
|
|
|
do_it
|
2006-01-19 01:20:23 +01:00
|
|
|
fi
|
|
|
|
else
|
2006-01-24 00:30:58 +01:00
|
|
|
do_it
|
2006-01-19 01:20:23 +01:00
|
|
|
fi
|
|
|
|
}
|
2006-09-07 22:48:40 +02:00
|
|
|
|
2006-01-22 03:35:15 +01:00
|
|
|
#
|
|
|
|
# Compile Command Executor
|
|
|
|
#
|
2006-01-19 01:20:23 +01:00
|
|
|
compile_command() {
|
2006-07-17 01:06:18 +02:00
|
|
|
local finished=0
|
2006-01-19 01:20:23 +01:00
|
|
|
|
|
|
|
while [ $finished -eq 0 ]; do
|
|
|
|
[ $# -eq 0 ] && usage 1
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
2006-02-03 18:08:37 +01:00
|
|
|
shift
|
2006-01-19 01:20:23 +01:00
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
[ -z "$option" ] && usage 1
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
e*)
|
|
|
|
EXPORT=Yes
|
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
file=
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
file=$1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && usage 2
|
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
|
|
|
echo "$1 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $1 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2006-12-10 05:12:28 +01:00
|
|
|
export SHOREWALL_DIR
|
2006-01-19 01:20:23 +01:00
|
|
|
file=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
export EXPORT
|
|
|
|
|
2006-02-03 22:39:00 +01:00
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2006-07-17 01:06:18 +02:00
|
|
|
exec $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging compile $file
|
2006-01-19 01:20:23 +01:00
|
|
|
}
|
2006-09-07 22:48:40 +02:00
|
|
|
|
2006-01-22 03:35:15 +01:00
|
|
|
#
|
2006-01-24 00:30:58 +01:00
|
|
|
# Check Command Executor
|
2006-01-22 03:35:15 +01:00
|
|
|
#
|
2006-01-24 00:30:58 +01:00
|
|
|
check_command() {
|
2006-07-17 01:06:18 +02:00
|
|
|
local finished=0
|
2006-01-19 01:20:23 +01:00
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
2006-02-03 16:27:54 +01:00
|
|
|
e*)
|
|
|
|
EXPORT=Yes
|
|
|
|
option=${option#e}
|
2006-01-23 02:41:24 +01:00
|
|
|
;;
|
2006-01-19 01:20:23 +01:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && usage 2
|
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
|
|
|
echo "$1 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $1 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2006-12-10 05:12:28 +01:00
|
|
|
export SHOREWALL_DIR
|
2006-01-19 01:20:23 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-02-10 19:45:05 +01:00
|
|
|
export EXPORT
|
2006-01-19 01:20:23 +01:00
|
|
|
|
2006-02-03 22:39:00 +01:00
|
|
|
progress_message3 "Checking..."
|
|
|
|
|
2006-07-17 01:06:18 +02:00
|
|
|
exec $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging $nolock check
|
2006-01-19 01:20:23 +01:00
|
|
|
}
|
2006-01-24 00:30:58 +01:00
|
|
|
|
2006-01-22 03:35:15 +01:00
|
|
|
#
|
2006-01-24 00:30:58 +01:00
|
|
|
# Restart Command Executor
|
2006-01-22 03:35:15 +01:00
|
|
|
#
|
2006-01-24 00:30:58 +01:00
|
|
|
restart_command() {
|
2006-09-27 22:11:52 +02:00
|
|
|
local finished=0 rc=0
|
2006-01-19 01:20:23 +01:00
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && usage 2
|
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
|
|
|
echo "$1 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $1 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2006-12-10 05:12:28 +01:00
|
|
|
export SHOREWALL_DIR
|
2006-01-19 01:20:23 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-02-04 04:45:03 +01:00
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
|
|
|
error_message "ERROR: Startup is disabled"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2006-01-19 01:20:23 +01:00
|
|
|
export NOROUTES
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
2006-01-23 21:44:31 +01:00
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2006-07-17 01:06:18 +02:00
|
|
|
if $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging $nolock compile ${VARDIR}/.restart; then
|
2006-06-09 18:35:55 +02:00
|
|
|
$SHOREWALL_SHELL ${VARDIR}/.restart $debugging restart
|
2006-09-27 22:11:52 +02:00
|
|
|
rc=$?
|
|
|
|
else
|
2006-12-12 18:49:52 +01:00
|
|
|
logger -p kern.err "ERROR:Shorewall restart failed"
|
2006-09-27 22:11:52 +02:00
|
|
|
rc=$?
|
2006-01-19 01:20:23 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-09-27 22:11:52 +02:00
|
|
|
return $rc
|
2006-01-19 01:20:23 +01:00
|
|
|
}
|
2006-01-24 00:30:58 +01:00
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
#
|
|
|
|
# Refresh Command Executor
|
|
|
|
#
|
|
|
|
refresh_command() {
|
|
|
|
local finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if ! shorewall_is_started ; then
|
|
|
|
error_message "ERROR: Shorewall is not running"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
|
|
|
error_message "ERROR: Startup is disabled"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
export NOROUTES
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
|
|
|
if $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging $nolock compile ${VARDIR}/.refresh; then
|
|
|
|
$SHOREWALL_SHELL ${VARDIR}/.refresh $debugging refresh
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
}
|
|
|
|
|
2006-01-24 16:24:20 +01:00
|
|
|
#
|
|
|
|
# Safe-start/safe-restart Command Executor
|
|
|
|
#
|
|
|
|
safe_commands() {
|
|
|
|
local finished=0
|
|
|
|
|
|
|
|
# test is the shell supports timed read
|
|
|
|
read -t 0 junk 2> /dev/null
|
|
|
|
if [ $? -eq 2 -a ! -x /bin/bash ];then
|
|
|
|
echo "Your shell does not support a feature required to execute this command".
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2006-12-03 19:18:21 +01:00
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && usage 2
|
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
|
|
|
echo "$1 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $1 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2006-12-10 05:12:28 +01:00
|
|
|
export SHOREWALL_DIR
|
2006-12-03 19:18:21 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
2006-01-24 16:24:20 +01:00
|
|
|
|
2006-02-04 04:45:03 +01:00
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
|
|
|
error_message "ERROR: Startup is disabled"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2006-01-24 16:24:20 +01:00
|
|
|
mutex_on
|
|
|
|
|
|
|
|
if shorewall_is_started; then
|
|
|
|
running=Yes
|
|
|
|
else
|
|
|
|
running=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$COMMAND" = "safe-start" -a -n "$running" ]; then
|
|
|
|
# the command is safe-start but the firewall is already running
|
|
|
|
error_message "Shorewall is already started"
|
|
|
|
mutex_off
|
2006-12-03 19:18:21 +01:00
|
|
|
exit 0
|
2006-01-24 16:24:20 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$COMMAND" = "safe-start" -o -z "$running" ]; then
|
|
|
|
# the command is safe-start or shorewall is not started yet
|
|
|
|
command="start"
|
|
|
|
else
|
|
|
|
# the command is safe-restart and the firewall is already running
|
|
|
|
command="restart"
|
|
|
|
fi
|
|
|
|
|
2006-02-03 22:39:00 +01:00
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
if ! $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging nolock compile ${VARDIR}/.$command; then
|
2006-01-24 16:24:20 +01:00
|
|
|
status=$?
|
|
|
|
mutex_off
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
2006-02-03 22:39:00 +01:00
|
|
|
case $command in
|
|
|
|
start)
|
2006-12-03 19:18:21 +01:00
|
|
|
export RESTOREFILE=NONE
|
2006-02-03 22:39:00 +01:00
|
|
|
progress_message3 "Starting..."
|
|
|
|
;;
|
|
|
|
restart)
|
2006-12-03 19:18:21 +01:00
|
|
|
export RESTOREFILE=.safe
|
|
|
|
RESTOREPATH=${VARDIR}/.safe
|
|
|
|
save_config
|
2006-02-03 22:39:00 +01:00
|
|
|
progress_message3 "Restarting..."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-12-03 19:18:21 +01:00
|
|
|
if ${VARDIR}/.$command $command; then
|
2006-01-24 16:24:20 +01:00
|
|
|
|
2006-12-03 19:18:21 +01:00
|
|
|
echo -n "Do you want to accept the new firewall configuration? [y/n] "
|
2006-01-24 16:24:20 +01:00
|
|
|
|
2006-12-03 19:18:21 +01:00
|
|
|
if read_yesno_with_timeout; then
|
|
|
|
echo "New configuration has been accepted"
|
2006-01-24 16:24:20 +01:00
|
|
|
else
|
2006-12-03 19:18:21 +01:00
|
|
|
if [ "$command" = "restart" ]; then
|
|
|
|
${VARDIR}/.safe restore
|
|
|
|
else
|
|
|
|
${VARDIR}/.$command clear
|
|
|
|
fi
|
|
|
|
|
|
|
|
mutex_off
|
|
|
|
echo "New configuration has been rejected and the old one restored"
|
|
|
|
exit 2
|
2006-01-24 16:24:20 +01:00
|
|
|
fi
|
|
|
|
|
2006-12-03 19:18:21 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
mutex_off
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# 'try' Command Executor
|
|
|
|
#
|
|
|
|
try_command() {
|
|
|
|
local finished=0 timeout=
|
|
|
|
|
|
|
|
handle_directory() {
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && usage 2
|
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
|
|
|
echo "$1 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $1 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2006-12-10 05:12:28 +01:00
|
|
|
export SHOREWALL_DIR
|
2006-12-03 19:18:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
handle_directory $1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
handle_directory $1
|
|
|
|
timeout=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
|
|
|
error_message "ERROR: Startup is disabled"
|
2006-01-24 16:24:20 +01:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2006-12-03 19:18:21 +01:00
|
|
|
mutex_on
|
|
|
|
|
|
|
|
if shorewall_is_started; then
|
|
|
|
running=Yes
|
|
|
|
else
|
|
|
|
running=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$running" ]; then
|
|
|
|
# shorewall is not started yet
|
|
|
|
command="start"
|
|
|
|
else
|
|
|
|
# the firewall is already running
|
|
|
|
command="restart"
|
|
|
|
fi
|
|
|
|
|
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
|
|
|
if ! $SHOREWALL_SHELL ${SHAREDIR}/compiler $debugging nolock compile ${VARDIR}/.$command; then
|
|
|
|
status=$?
|
|
|
|
mutex_off
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $command in
|
|
|
|
start)
|
|
|
|
export RESTOREFILE=NONE
|
|
|
|
progress_message3 "Starting..."
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
export RESTOREFILE=.try
|
|
|
|
RESTOREPATH=${VARDIR}/.try
|
|
|
|
save_config
|
|
|
|
progress_message3 "Restarting..."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if ${VARDIR}/.$command $command && [ -n "$timeout" ]; then
|
|
|
|
sleep $timeout
|
|
|
|
|
|
|
|
if [ "$command" = "restart" ]; then
|
|
|
|
${VARDIR}/.try restore
|
|
|
|
else
|
|
|
|
${VARDIR}/.$command clear
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-01-24 16:24:20 +01:00
|
|
|
mutex_off
|
2006-12-03 19:18:21 +01:00
|
|
|
|
|
|
|
return 0
|
2006-01-24 16:24:20 +01:00
|
|
|
}
|
|
|
|
|
2003-07-27 20:17:39 +02:00
|
|
|
#
|
2006-06-17 19:17:45 +02:00
|
|
|
# [Re]load command executor
|
2006-06-14 19:25:37 +02:00
|
|
|
#
|
2006-08-09 01:03:06 +02:00
|
|
|
reload_command() # $* = original arguments less the command.
|
2006-06-14 19:25:37 +02:00
|
|
|
{
|
2006-12-11 19:42:53 +01:00
|
|
|
local verbose=$(make_verbose) file= capabilities= finished=0 saveit= result directory system getcaps= root=root
|
2006-06-17 01:04:12 +02:00
|
|
|
|
2006-11-09 19:30:36 +01:00
|
|
|
[ -n "$LITEDIR" ] || fatal_error "ERROR: LITEDIR not defined in ${SHAREDIR}/configpath"
|
2006-06-19 17:54:30 +02:00
|
|
|
|
2006-08-09 01:03:06 +02:00
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
s*)
|
|
|
|
saveit=Yes
|
|
|
|
option=${option#s}
|
|
|
|
;;
|
2006-11-09 16:57:58 +01:00
|
|
|
c*)
|
|
|
|
getcaps=Yes
|
|
|
|
option=${option#c}
|
|
|
|
;;
|
2006-12-11 19:42:53 +01:00
|
|
|
r)
|
|
|
|
[ $# -gt 1 ] || fatal_error "Missing Root User name"
|
|
|
|
root=$2
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
2006-08-09 01:03:06 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
directory="."
|
|
|
|
system=$1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
directory=$1
|
|
|
|
system=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-11-09 19:30:36 +01:00
|
|
|
if [ -z "$getcaps" ]; then
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $directory)
|
2006-11-09 19:30:36 +01:00
|
|
|
capabilities=$(find_file capabilities)
|
|
|
|
[ -f $capabilities ] || getcaps=Yes
|
|
|
|
fi
|
2006-08-09 01:03:06 +02:00
|
|
|
|
2006-11-09 19:30:36 +01:00
|
|
|
if [ -n "$getcaps" ]; then
|
2006-11-09 16:57:58 +01:00
|
|
|
progress_message "Getting Capabilities on system $system..."
|
2006-12-11 19:42:53 +01:00
|
|
|
if ! ssh ${root}@${system} "/sbin/shorewall-lite show -f capabilities > ${LITEDIR}/capabilities" || \
|
|
|
|
! scp ${root}@$system:${LITEDIR}/capabilities $directory; then
|
2006-11-09 19:30:36 +01:00
|
|
|
fatal_error "ERROR: Capturing capabilities on system $system failed"
|
2006-11-09 16:57:58 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2006-11-09 17:11:32 +01:00
|
|
|
file=$(resolve_file $directory/firewall)
|
|
|
|
|
2006-08-09 01:03:06 +02:00
|
|
|
if shorewall $debugging $verbose compile -e $directory $directory/firewall && \
|
2006-11-09 16:57:58 +01:00
|
|
|
progress_message "Copying $file and ${file}.conf to ${system}:${LITEDIR}..." && \
|
2006-12-11 19:42:53 +01:00
|
|
|
scp $directory/firewall $directory/firewall.conf ${root}@${system}:${LITEDIR}
|
2006-06-17 19:17:45 +02:00
|
|
|
then
|
|
|
|
echo "Copy complete"
|
|
|
|
if [ $COMMAND = reload ]; then
|
2006-12-11 19:42:53 +01:00
|
|
|
ssh ${root}@${system} "/sbin/shorewall-lite $debugging $verbose restart" && \
|
2006-08-09 01:03:06 +02:00
|
|
|
progress_message3 "System $system reloaded" || saveit=
|
2006-06-17 19:17:45 +02:00
|
|
|
else
|
2006-12-11 19:42:53 +01:00
|
|
|
ssh ${root}@${system} "/sbin/shorewall-lite $debugging $verbose restart" && \
|
2006-08-09 01:03:06 +02:00
|
|
|
progress_message3 "System $system reloaded" || saveit=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$saveit" ]; then
|
2006-12-11 19:42:53 +01:00
|
|
|
ssh ${root}@${system} "/sbin/shorewall-lite $debugging $verbose save" && \
|
2006-08-09 01:03:06 +02:00
|
|
|
progress_message3 "Configuration on system $system saved"
|
2006-06-17 19:17:45 +02:00
|
|
|
fi
|
|
|
|
fi
|
2006-06-14 19:25:37 +02:00
|
|
|
}
|
2006-08-13 17:34:52 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Export command executor
|
|
|
|
#
|
|
|
|
export_command() # $* = original arguments less the command.
|
|
|
|
{
|
|
|
|
local verbose=$(make_verbose) file= finished=0 directory target
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
2006-11-09 19:30:36 +01:00
|
|
|
fatal_error "Unrecognized option \"$option\""
|
2006-08-13 17:34:52 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
directory="."
|
|
|
|
target=$1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
directory=$1
|
|
|
|
target=$2
|
|
|
|
;;
|
|
|
|
*)
|
2006-11-21 23:52:07 +01:00
|
|
|
fatal_error "ERROR: Invalid command syntax (\"man shorewall\" for help)"
|
2006-08-13 17:34:52 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $target in
|
|
|
|
*:*)
|
|
|
|
;;
|
|
|
|
*)
|
2006-12-02 18:11:33 +01:00
|
|
|
target=$target:
|
2006-08-13 17:34:52 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
file=$(resolve_file $directory/firewall)
|
|
|
|
|
|
|
|
if shorewall $debugging $verbose compile -e $directory $directory/firewall && \
|
|
|
|
echo "Copying $file and ${file}.conf to ${target#*@}..." && \
|
|
|
|
scp $directory/firewall $directory/firewall.conf $target
|
|
|
|
then
|
|
|
|
progress_message3 "Copy complete"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
2006-02-15 16:20:17 +01:00
|
|
|
echo "Usage: $(basename $0) [debug|trace] [nolock] [ -q ] [ -v ] [ -t ] <command>"
|
2002-05-01 01:13:15 +02:00
|
|
|
echo "where <command> is one of:"
|
2006-08-27 19:27:48 +02:00
|
|
|
echo " add <interface>[:<host-list>] ... <zone>"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " allow <address> ..."
|
2006-02-10 19:45:05 +01:00
|
|
|
echo " check [ -e ] [ <directory> ]"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " clear"
|
2006-06-03 19:05:43 +02:00
|
|
|
echo " compile [ -e ] [ <directory name> ] <path name>"
|
2006-08-27 19:27:48 +02:00
|
|
|
echo " delete <interface>[:<host-list>] ... <zone>"
|
2003-08-24 03:24:23 +02:00
|
|
|
echo " drop <address> ..."
|
2006-02-03 16:27:54 +01:00
|
|
|
echo " dump [ -x ]"
|
2006-12-02 18:11:33 +01:00
|
|
|
echo " export [ <directory1> ] [<user>@]<system>[:<directory2>]"
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " forget [ <file name> ]"
|
2006-11-21 23:52:07 +01:00
|
|
|
echo " help"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " hits"
|
2005-12-03 00:58:57 +01:00
|
|
|
echo " ipcalc { <address>/<vlsm> | <address> <netmask> }"
|
|
|
|
echo " ipdecimal { <address> | <integer> }"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " iprange <address>-<address>"
|
2006-12-11 19:42:53 +01:00
|
|
|
echo " load [ -s ] [ -c ] [ -r <root user> ] [ <directory> ] <system>"
|
2006-03-23 17:37:45 +01:00
|
|
|
echo " logdrop <address> ..."
|
|
|
|
echo " logreject <address> ..."
|
2006-01-25 23:33:50 +01:00
|
|
|
echo " logwatch [<refresh interval>]"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " refresh"
|
2003-08-24 03:24:23 +02:00
|
|
|
echo " reject <address> ..."
|
2006-12-11 19:42:53 +01:00
|
|
|
echo " reload [ -s ] [ -c ] [ -r <root user> ] [ <directory> ] <system>"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " reset"
|
2006-02-03 16:27:54 +01:00
|
|
|
echo " restart [ -n ] [ <directory> ]"
|
|
|
|
echo " restore [ -n ] [ <file name> ]"
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " save [ <file name> ]"
|
2006-11-21 23:52:07 +01:00
|
|
|
echo " show [ -x ] [ -m ] [-f] [ -t {filter|mangle|nat} ] [<chain> [ <chain> ... ]|actions|capabilities|classifiers|config|connections|ip|log|macros|mangle|nat|routing|tc|zones]"
|
2006-02-03 16:27:54 +01:00
|
|
|
echo " start [ -f ] [ -n ] [ <directory> ]"
|
2002-05-01 01:13:15 +02:00
|
|
|
echo " stop"
|
|
|
|
echo " status"
|
2006-12-03 19:18:21 +01:00
|
|
|
echo " try <directory> [ <timeout> ]"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " version"
|
2006-12-03 19:18:21 +01:00
|
|
|
echo " safe-start [ <directory> ]"
|
|
|
|
echo " safe-restart [ <directory> ]"
|
2005-08-02 18:46:30 +02:00
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2006-10-31 20:01:23 +01:00
|
|
|
# Execution begins here
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
debugging=
|
|
|
|
|
2006-08-27 19:27:48 +02:00
|
|
|
if [ $# -gt 0 ] && [ "x$1" = "xdebug" -o "x$1" = "xtrace" ]; then
|
|
|
|
debugging=debug
|
|
|
|
shift
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
nolock=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "nolock" ]; then
|
|
|
|
nolock=nolock
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHOREWALL_DIR=
|
2005-07-09 06:45:32 +02:00
|
|
|
IPT_OPTIONS="-nv"
|
|
|
|
FAST=
|
2006-03-24 00:26:41 +01:00
|
|
|
VERBOSE_OFFSET=0
|
2005-09-15 01:01:13 +02:00
|
|
|
NOROUTES=
|
2006-01-13 00:26:37 +01:00
|
|
|
EXPORT=
|
2006-02-15 16:20:17 +01:00
|
|
|
export TIMESTAMP=
|
2005-09-15 03:07:12 +02:00
|
|
|
noroutes=
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-01-17 18:00:54 +01:00
|
|
|
finished=0
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2006-01-17 18:00:54 +01:00
|
|
|
while [ $finished -eq 0 ]; do
|
2002-05-01 01:13:15 +02:00
|
|
|
[ $# -eq 0 ] && usage 1
|
2005-07-09 06:45:32 +02:00
|
|
|
option=$1
|
|
|
|
case $option in
|
2006-01-17 18:08:41 +01:00
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
-*)
|
|
|
|
option=${option#-}
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
c)
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
|
|
|
|
if [ ! -d $2 ]; then
|
|
|
|
if [ -e $2 ]; then
|
|
|
|
echo "$2 is not a directory" >&2 && exit 2
|
|
|
|
else
|
|
|
|
echo "Directory $2 does not exist" >&2 && exit 2
|
|
|
|
fi
|
|
|
|
fi
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2006-12-10 21:21:02 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $2)
|
2005-07-09 06:45:32 +02:00
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
2006-01-13 00:26:37 +01:00
|
|
|
e*)
|
|
|
|
EXPORT=Yes
|
|
|
|
option=${option#e}
|
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
x*)
|
|
|
|
IPT_OPTIONS="-xnv"
|
|
|
|
option=${option#x}
|
|
|
|
;;
|
|
|
|
q*)
|
2006-03-24 00:26:41 +01:00
|
|
|
VERBOSE_OFFSET=$(($VERBOSE_OFFSET - 1 ))
|
2005-07-09 06:45:32 +02:00
|
|
|
option=${option#q}
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
FAST=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
2005-07-09 07:45:05 +02:00
|
|
|
v*)
|
2006-03-24 00:26:41 +01:00
|
|
|
VERBOSE_OFFSET=$(($VERBOSE_OFFSET + 1 ))
|
2006-01-24 17:10:41 +01:00
|
|
|
option=${option#v}
|
2005-07-09 07:45:05 +02:00
|
|
|
;;
|
2005-09-15 01:01:13 +02:00
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
2005-09-30 18:54:24 +02:00
|
|
|
;;
|
2006-02-15 16:20:17 +01:00
|
|
|
t*)
|
|
|
|
TIMESTAMP=Yes
|
|
|
|
option=${option#t}
|
|
|
|
;;
|
2006-01-17 18:00:54 +01:00
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2006-01-17 18:00:54 +01:00
|
|
|
finished=1
|
2005-07-09 06:45:32 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2002-06-04 17:08:50 +02:00
|
|
|
if [ $# -eq 0 ]; then
|
2002-05-01 01:13:15 +02:00
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
|
2006-12-10 05:12:28 +01:00
|
|
|
[ -n "$SHOREWALL_DIR" ] && export SHOREWALL_DIR
|
2003-01-07 00:01:23 +01:00
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
|
|
|
MUTEX_TIMEOUT=
|
|
|
|
|
2006-06-11 17:07:34 +02:00
|
|
|
SHAREDIR=/usr/share/shorewall
|
|
|
|
VARDIR=/var/lib/shorewall
|
|
|
|
CONFDIR=/etc/shorewall
|
2006-06-14 18:32:13 +02:00
|
|
|
export PRODUCT="Shorewall"
|
2006-06-11 17:07:34 +02:00
|
|
|
|
|
|
|
FIREWALL=$SHAREDIR/firewall
|
2006-10-28 16:46:43 +02:00
|
|
|
LIBRARIES="$SHAREDIR/lib.base $SHAREDIR/lib.cli"
|
2006-06-11 17:07:34 +02:00
|
|
|
VERSION_FILE=$SHAREDIR/version
|
|
|
|
HELP=$SHAREDIR/help
|
2003-01-07 00:01:23 +01:00
|
|
|
|
2006-10-28 16:46:43 +02:00
|
|
|
for library in $LIBRARIES; do
|
|
|
|
if [ -f $library ]; then
|
|
|
|
. $library
|
|
|
|
else
|
|
|
|
echo "$library does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done
|
2006-10-28 00:42:05 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
ensure_config_path
|
|
|
|
|
|
|
|
config=$(find_file shorewall.conf)
|
2003-03-08 19:01:32 +01:00
|
|
|
|
|
|
|
if [ -f $config ]; then
|
2005-07-09 06:45:32 +02:00
|
|
|
if [ -r $config ]; then
|
|
|
|
. $config
|
|
|
|
else
|
|
|
|
echo "Cannot read $config! (Hint: Are you root?)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2003-03-08 19:01:32 +01:00
|
|
|
else
|
|
|
|
echo "$config does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
ensure_config_path
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
get_config
|
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ ! -f $FIREWALL ]; then
|
2006-06-12 18:48:07 +02:00
|
|
|
echo " ERROR: Shorewall is not properly installed" >&2
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ -L $FIREWALL ]; then
|
2006-06-12 18:48:07 +02:00
|
|
|
echo " $FIREWALL is a symbolic link to a" >&2
|
|
|
|
echo " non-existant file" >&2
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2006-06-12 18:48:07 +02:00
|
|
|
echo " The file $FIREWALL does not exist" >&2
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ -f $VERSION_FILE ]; then
|
2006-07-17 01:06:18 +02:00
|
|
|
version=$(cat $VERSION_FILE)
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2006-06-12 18:48:07 +02:00
|
|
|
echo " ERROR: Shorewall is not properly installed" >&2
|
|
|
|
echo " The file $VERSION_FILE does not exist" >&2
|
2002-05-01 01:13:15 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
banner="Shorewall-$version Status at $HOSTNAME -"
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
case $(echo -e) in
|
2002-11-11 17:46:50 +01:00
|
|
|
-e*)
|
2003-01-06 20:54:50 +01:00
|
|
|
RING_BELL="echo \a"
|
2002-11-11 17:46:50 +01:00
|
|
|
;;
|
|
|
|
*)
|
2003-01-06 20:54:50 +01:00
|
|
|
RING_BELL="echo -e \a"
|
2002-11-11 17:46:50 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
case $(echo -n "Testing") in
|
2002-11-11 17:46:50 +01:00
|
|
|
-n*)
|
|
|
|
ECHO_N=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ECHO_N=-n
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-01-18 21:17:58 +01:00
|
|
|
COMMAND=$1
|
|
|
|
|
|
|
|
case "$COMMAND" in
|
2005-07-09 06:45:32 +02:00
|
|
|
start)
|
2006-01-18 21:17:58 +01:00
|
|
|
shift
|
2006-01-19 01:20:23 +01:00
|
|
|
start_command $@
|
2005-07-09 06:45:32 +02:00
|
|
|
;;
|
2006-08-27 19:27:48 +02:00
|
|
|
stop|reset|clear)
|
2002-05-01 01:13:15 +02:00
|
|
|
[ $# -ne 1 ] && usage 1
|
2005-09-15 01:01:13 +02:00
|
|
|
export NOROUTES
|
2006-01-18 21:17:58 +01:00
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $COMMAND
|
2005-07-09 07:45:05 +02:00
|
|
|
;;
|
2006-02-03 16:10:46 +01:00
|
|
|
compile)
|
2006-01-15 17:35:09 +01:00
|
|
|
shift
|
2006-01-19 01:20:23 +01:00
|
|
|
compile_command $@
|
2006-01-07 02:08:23 +01:00
|
|
|
;;
|
2006-01-18 21:17:58 +01:00
|
|
|
restart)
|
|
|
|
shift
|
2006-01-19 01:20:23 +01:00
|
|
|
restart_command $@
|
2006-01-18 21:17:58 +01:00
|
|
|
;;
|
2006-08-27 19:27:48 +02:00
|
|
|
refresh)
|
|
|
|
shift
|
|
|
|
refresh_command $@
|
|
|
|
;;
|
2006-01-18 21:17:58 +01:00
|
|
|
check)
|
2006-01-19 01:20:23 +01:00
|
|
|
shift
|
|
|
|
check_command $@
|
2006-01-07 07:04:16 +01:00
|
|
|
;;
|
2006-08-27 19:27:48 +02:00
|
|
|
add|delete)
|
|
|
|
[ $# -lt 3 ] && usage 1
|
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $@
|
|
|
|
;;
|
2003-01-23 02:13:36 +01:00
|
|
|
show|list)
|
2006-01-19 01:20:23 +01:00
|
|
|
shift
|
|
|
|
show_command $@
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2006-06-17 19:17:45 +02:00
|
|
|
load|reload)
|
2006-06-14 19:25:37 +02:00
|
|
|
shift
|
2006-08-09 01:03:06 +02:00
|
|
|
reload_command $@
|
2006-06-14 19:25:37 +02:00
|
|
|
;;
|
2006-08-13 17:34:52 +02:00
|
|
|
export)
|
|
|
|
shift
|
|
|
|
export_command $@
|
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
status)
|
2005-07-28 16:37:56 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2006-07-17 01:06:18 +02:00
|
|
|
echo "Shorewall-$version Status at $HOSTNAME - $(date)"
|
2005-07-30 23:59:12 +02:00
|
|
|
echo
|
2005-07-29 21:06:37 +02:00
|
|
|
if shorewall_is_started ; then
|
2005-07-29 20:32:50 +02:00
|
|
|
echo "Shorewall is running"
|
2005-07-30 23:59:12 +02:00
|
|
|
status=0
|
|
|
|
else
|
|
|
|
echo "Shorewall is stopped"
|
|
|
|
status=4
|
2005-07-29 20:32:50 +02:00
|
|
|
fi
|
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
if [ -f ${VARDIR}/state ]; then
|
|
|
|
state="$(cat ${VARDIR}/state)"
|
2006-01-17 18:34:34 +01:00
|
|
|
case $state in
|
2005-07-29 20:32:50 +02:00
|
|
|
Stopped*|Clear*)
|
|
|
|
status=3
|
|
|
|
;;
|
|
|
|
esac
|
2005-07-28 16:37:56 +02:00
|
|
|
else
|
2005-07-29 20:32:50 +02:00
|
|
|
state=Unknown
|
2005-07-28 16:37:56 +02:00
|
|
|
fi
|
2005-07-30 23:59:12 +02:00
|
|
|
echo "State:$state"
|
2005-07-29 20:32:50 +02:00
|
|
|
echo
|
2005-08-02 18:46:30 +02:00
|
|
|
exit $status
|
2005-07-28 16:37:56 +02:00
|
|
|
;;
|
|
|
|
dump)
|
2006-01-19 01:20:23 +01:00
|
|
|
shift
|
|
|
|
dump_command $@
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
hits)
|
2005-12-03 00:58:57 +01:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2006-11-05 20:47:59 +01:00
|
|
|
hits_command
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
version)
|
2006-07-17 01:06:18 +02:00
|
|
|
echo $version
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2006-12-03 19:18:21 +01:00
|
|
|
try)
|
|
|
|
shift
|
|
|
|
try_command $@
|
|
|
|
;;
|
2002-06-02 19:05:51 +02:00
|
|
|
logwatch)
|
2006-11-29 02:11:29 +01:00
|
|
|
logwatch_command $@
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-06-04 22:17:46 +02:00
|
|
|
drop)
|
2005-12-03 00:58:57 +01:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2006-02-04 18:14:46 +01:00
|
|
|
if shorewall_is_started ; then
|
|
|
|
mutex_on
|
2006-10-28 00:00:48 +02:00
|
|
|
block DROP Dropped $*
|
2006-02-04 18:14:46 +01:00
|
|
|
mutex_off
|
|
|
|
else
|
|
|
|
error_message "ERROR: Shorewall is not started"
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-06-04 17:08:50 +02:00
|
|
|
;;
|
2006-03-23 17:37:45 +01:00
|
|
|
logdrop)
|
2005-12-03 00:58:57 +01:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2006-02-04 18:14:46 +01:00
|
|
|
if shorewall_is_started ; then
|
|
|
|
mutex_on
|
2006-10-28 00:00:48 +02:00
|
|
|
block logdrop Dropped $*
|
2006-03-23 17:37:45 +01:00
|
|
|
mutex_off
|
|
|
|
else
|
|
|
|
error_message "ERROR: Shorewall is not started"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
reject|logreject)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
|
|
|
mutex_on
|
2006-10-28 00:00:48 +02:00
|
|
|
block $COMMAND Rejected $*
|
2006-02-04 18:14:46 +01:00
|
|
|
mutex_off
|
|
|
|
else
|
|
|
|
error_message "ERROR: Shorewall is not started"
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-06-04 22:17:46 +02:00
|
|
|
;;
|
|
|
|
allow)
|
2006-11-29 01:53:39 +01:00
|
|
|
allow_command $@
|
2002-06-04 22:17:46 +02:00
|
|
|
;;
|
|
|
|
save)
|
2005-12-03 00:58:57 +01:00
|
|
|
[ -n "$debugging" ] && set -x
|
2005-07-09 06:45:32 +02:00
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2006-12-03 19:18:21 +01:00
|
|
|
mutex_off
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2006-01-24 16:24:20 +01:00
|
|
|
[ "$nolock" ] || mutex_on
|
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
save_config
|
2003-08-24 03:24:23 +02:00
|
|
|
|
2006-01-24 16:24:20 +01:00
|
|
|
[ "$nolock" ] || mutex_off
|
2002-06-04 22:17:46 +02:00
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
forget)
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
2006-06-09 18:35:55 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2005-07-09 06:45:32 +02:00
|
|
|
|
|
|
|
if [ -x $RESTOREPATH ]; then
|
2005-07-09 07:55:29 +02:00
|
|
|
|
|
|
|
if [ -x ${RESTOREPATH}-ipsets ]; then
|
|
|
|
rm -f ${RESTOREPATH}-ipsets
|
|
|
|
echo " ${RESTOREPATH}-ipsets removed"
|
|
|
|
fi
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
rm -f $RESTOREPATH
|
2006-01-25 18:33:38 +01:00
|
|
|
rm -f ${RESTOREPATH}-iptables
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " $RESTOREPATH removed"
|
|
|
|
elif [ -f $RESTOREPATH ]; then
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " $RESTOREPATH exists and is not a saved Shorewall configuration"
|
2005-07-09 06:45:32 +02:00
|
|
|
fi
|
2006-06-09 18:35:55 +02:00
|
|
|
rm -f ${VARDIR}/save
|
2005-07-09 06:45:32 +02:00
|
|
|
;;
|
2003-07-05 19:14:21 +02:00
|
|
|
ipcalc)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2003-07-05 19:14:21 +02:00
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
address=${2%/*}
|
2003-07-05 19:23:53 +02:00
|
|
|
vlsm=${2#*/}
|
2003-07-05 19:14:21 +02:00
|
|
|
elif [ $# -eq 3 ]; then
|
|
|
|
address=$2
|
2005-07-09 06:45:32 +02:00
|
|
|
vlsm=$(ip_vlsm $3)
|
2003-07-05 19:14:21 +02:00
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2006-12-21 03:29:32 +01:00
|
|
|
valid_address $address || fatal_error "Invalid IP address: $address"
|
2003-07-05 19:23:53 +02:00
|
|
|
[ -z "$vlsm" ] && exit 2
|
|
|
|
[ "x$address" = "x$vlsm" ] && usage 2
|
2003-07-05 19:41:28 +02:00
|
|
|
[ $vlsm -gt 32 ] && echo "Invalid VLSM: /$vlsm" >&2 && exit 2
|
2003-07-05 19:14:21 +02:00
|
|
|
|
2003-07-05 19:23:53 +02:00
|
|
|
address=$address/$vlsm
|
2003-07-05 19:14:21 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " CIDR=$address"
|
|
|
|
temp=$(ip_netmask $address); echo " NETMASK=$(encodeaddr $temp)"
|
|
|
|
temp=$(ip_network $address); echo " NETWORK=$temp"
|
|
|
|
temp=$(broadcastaddress $address); echo " BROADCAST=$temp"
|
2003-07-05 19:14:21 +02:00
|
|
|
;;
|
|
|
|
|
2003-07-06 15:24:23 +02:00
|
|
|
iprange)
|
2005-12-03 00:58:57 +01:00
|
|
|
[ -n "$debugging" ] && set -x
|
2003-07-06 15:24:23 +02:00
|
|
|
case $2 in
|
|
|
|
*.*.*.*-*.*.*.*)
|
2006-12-21 03:29:32 +01:00
|
|
|
for address in ${2%-*} ${2#*-}; do
|
|
|
|
valid_address $address || fatal_error "Invalid IP address: $address"
|
|
|
|
done
|
|
|
|
|
2003-07-06 15:24:23 +02:00
|
|
|
ip_range $2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2005-12-03 00:58:57 +01:00
|
|
|
ipdecimal)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
case $2 in
|
|
|
|
*.*.*.*)
|
2006-12-21 03:29:32 +01:00
|
|
|
valid_address $2 || fatal_error "Invalid IP address: $2"
|
2005-12-03 00:58:57 +01:00
|
|
|
echo " $(decodeaddr $2)"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " $(encodeaddr $2)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
restore)
|
2006-01-18 21:17:58 +01:00
|
|
|
shift
|
2006-12-21 03:29:32 +01:00
|
|
|
restore_command $@
|
2005-07-09 06:45:32 +02:00
|
|
|
;;
|
2005-08-02 18:46:30 +02:00
|
|
|
call)
|
2005-12-03 00:58:57 +01:00
|
|
|
[ -n "$debugging" ] && set -x
|
2003-07-05 19:55:43 +02:00
|
|
|
#
|
2006-06-09 18:35:55 +02:00
|
|
|
# Undocumented way to call functions in ${SHAREDIR}/functions directly
|
2003-07-05 19:55:43 +02:00
|
|
|
#
|
2006-01-05 00:34:07 +01:00
|
|
|
shift
|
2003-07-05 19:55:43 +02:00
|
|
|
$@
|
|
|
|
;;
|
2003-07-27 20:17:39 +02:00
|
|
|
help)
|
|
|
|
shift
|
2006-11-21 23:52:07 +01:00
|
|
|
usage
|
2003-07-27 20:17:39 +02:00
|
|
|
;;
|
2005-07-09 07:55:29 +02:00
|
|
|
safe-restart|safe-start)
|
2006-01-24 16:24:20 +01:00
|
|
|
shift
|
|
|
|
safe_commands $@
|
2005-07-09 07:55:29 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
2003-07-05 19:14:21 +02:00
|
|
|
|
2003-02-23 15:10:37 +01:00
|
|
|
esac
|