2002-05-01 01:13:15 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2005-08-31 17:27:22 +02:00
|
|
|
# Shorewall Packet Filtering Firewall Control Program - V3.0
|
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
|
|
|
#
|
2005-07-09 07:45:05 +02:00
|
|
|
# (c) 1999,2000,2001,2002,2003,2004,2005 - 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
|
|
|
#
|
2002-07-06 00:24:40 +02:00
|
|
|
# Shorewall documentation is available at http://shorewall.sourceforge.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
|
|
|
#
|
2002-10-01 22:54:42 +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
|
|
|
|
# shorewall monitor [ refresh-interval ] Repeatedly Displays firewall status
|
|
|
|
# plus the last 20 "interesting"
|
|
|
|
# packets
|
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.
|
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
|
2003-02-27 23:28:06 +01:00
|
|
|
# shorewall check Verify the more heavily-used
|
|
|
|
# configuration files.
|
2002-07-06 00:24:40 +02: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
|
2002-05-01 01:13:15 +02:00
|
|
|
# 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
|
|
|
#
|
2003-07-05 19:14:21 +02:00
|
|
|
# shorewall ipaddr [ <address>/<cidr> | <address> <netmask> ]
|
|
|
|
#
|
|
|
|
# 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-07-09 07:55:29 +02:00
|
|
|
# shorewall safe-start 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
|
|
|
|
#
|
2005-08-02 18:46:30 +02:00
|
|
|
# shorewall safe-restart Restarts the firewall and prompt for a
|
|
|
|
# confirmation to accept or reject the new
|
2005-07-09 07:55:29 +02:00
|
|
|
# configuration
|
|
|
|
#
|
2003-07-06 15:24:23 +02:00
|
|
|
# Fatal Error
|
|
|
|
#
|
|
|
|
fatal_error() # $@ = Message
|
|
|
|
{
|
|
|
|
echo " $@" >&2
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
# Display a chain if it exists
|
|
|
|
#
|
2003-02-25 17:21:41 +01:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
showfirstchain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
awk \
|
2002-07-06 00:24:40 +02:00
|
|
|
'BEGIN {prnt=0; rslt=1; }; \
|
|
|
|
/^$/ { next; };\
|
|
|
|
/^Chain/ {if ( prnt == 1 ) { rslt=0; exit 0; }; };\
|
2002-05-01 01:13:15 +02:00
|
|
|
/Chain '$1'/ { prnt=1; }; \
|
2002-07-06 00:24:40 +02:00
|
|
|
{ if (prnt == 1) print; };\
|
2005-07-09 06:45:32 +02:00
|
|
|
END { exit rslt; }' $TMPFILE
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
showchain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
if [ "$firstchain" = "Yes" ]; then
|
2002-05-30 14:55:47 +02:00
|
|
|
if showfirstchain $1; then
|
|
|
|
firstchain=
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
|
|
|
awk \
|
2002-07-06 00:24:40 +02:00
|
|
|
'BEGIN {prnt=0;};\
|
|
|
|
/^$|^ pkts/ { next; };\
|
|
|
|
/^Chain/ {if ( prnt == 1 ) exit; };\
|
|
|
|
/Chain '$1'/ { prnt=1; };\
|
2005-07-09 06:45:32 +02:00
|
|
|
{ if (prnt == 1) print; }' $TMPFILE
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
#
|
2005-07-09 07:55:29 +02:00
|
|
|
# The 'awk' hack that compensates for bugs in iptables-save (or rather in the extension modules).
|
2005-07-09 07:45:05 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
iptablesbug()
|
|
|
|
{
|
2005-07-27 22:30:16 +02:00
|
|
|
if qt mywhich awk ; then
|
2005-07-09 07:45:05 +02:00
|
|
|
awk 'BEGIN {sline=""; };\
|
|
|
|
/^-j/ { print sline $0; next };\
|
|
|
|
/-m policy.*-j/ { print $0; next };\
|
|
|
|
/-m policy/ { sline=$0; next };\
|
2005-07-09 07:55:29 +02:00
|
|
|
/--mask ff/ { sub( /--mask ff/, "--mask 0xff" ) };\
|
2005-07-09 07:45:05 +02:00
|
|
|
{print ; sline="" }'
|
|
|
|
else
|
2005-07-26 01:08:09 +02:00
|
|
|
echo " WARNING: You don't have 'awk' on this system so the output of the save command may be unusable" >&2
|
2005-07-09 07:45:05 +02:00
|
|
|
cat
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
#
|
|
|
|
# Validate the value of RESTOREFILE
|
|
|
|
#
|
|
|
|
validate_restorefile() # $* = label
|
|
|
|
{
|
|
|
|
case $RESTOREFILE in
|
|
|
|
*/*)
|
|
|
|
echo " ERROR: $@ must specify a simple file name: $RESTOREFILE" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
2005-08-02 18:46:30 +02:00
|
|
|
esac
|
2005-07-09 06:45:32 +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() {
|
|
|
|
|
|
|
|
[ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
|
|
|
|
|
|
|
|
if [ ! -f $LOGFILE ]; then
|
|
|
|
echo "LOGFILE ($LOGFILE) does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# See if we have a real version of "tail" -- use separate redirection so
|
|
|
|
# that ash (aka /bin/sh on LRP) doesn't crap
|
|
|
|
#
|
|
|
|
if ( tail -n5 $LOGFILE > /dev/null 2> /dev/null ) ; then
|
2002-07-06 00:24:40 +02:00
|
|
|
realtail="Yes"
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2002-07-06 00:24:40 +02:00
|
|
|
realtail=""
|
2002-05-01 01:13:15 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$FW" ] || FW=fw
|
2003-04-25 18:22:18 +02:00
|
|
|
|
2003-05-21 23:36:05 +02:00
|
|
|
[ -n "LOGFORMAT" ] && LOGFORMAT="${LOGFORMAT%%%*}"
|
|
|
|
|
|
|
|
[ -n "$LOGFORMAT" ] || LOGFORMAT="Shorewall:"
|
2003-06-28 17:22:22 +02:00
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
if [ -n "$IPTABLES" ]; then
|
|
|
|
if [ ! -e "$IPTABLES" ]; then
|
|
|
|
echo " ERROR: The program specified in IPTABLES does not exist or is not executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
else
|
2005-07-27 22:30:16 +02:00
|
|
|
IPTABLES=$(mywhich iptables 2> /dev/null)
|
2005-07-09 07:45:05 +02:00
|
|
|
if [ -z "$IPTABLES" ] ; then
|
|
|
|
echo " ERROR: Can't find iptables executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2003-06-28 17:22:22 +02:00
|
|
|
if [ -n "$SHOREWALL_SHELL" ]; then
|
|
|
|
if [ ! -e "$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
|
|
|
|
|
|
|
[ -n "$RESTOREFILE" ] || RESTOREFILE=restore
|
|
|
|
|
|
|
|
validate_restorefile RESTOREFILE
|
|
|
|
|
|
|
|
export RESTOREFILE
|
|
|
|
|
2005-07-15 22:50:01 +02:00
|
|
|
case $STARTUP_ENABLED in
|
|
|
|
[Nn][Oo])
|
|
|
|
echo " WARNING: Shorewall startup is disabled. To enable startup, set STARTUP_ENABLED=Yes in /etc/shorewall/shorewall.conf" >&2
|
|
|
|
;;
|
|
|
|
esac
|
2005-07-26 01:08:09 +02:00
|
|
|
|
2005-12-01 20:18:15 +01:00
|
|
|
case ${TC_ENABLED:=Internal} in
|
2005-12-01 19:24:19 +01:00
|
|
|
[Nn][Oo])
|
|
|
|
TC_ENABLED=
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
#
|
|
|
|
# Clear descriptor 1 if it is a terminal
|
|
|
|
#
|
|
|
|
clear_term() {
|
|
|
|
[ -t 1 ] && clear
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Delay $timeout seconds -- if we're running on a recent bash2 then allow
|
|
|
|
# <enter> to terminate the delay
|
|
|
|
#
|
2003-02-23 15:10:37 +01:00
|
|
|
timed_read ()
|
2002-05-01 01:13:15 +02:00
|
|
|
{
|
|
|
|
read -t $timeout foo 2> /dev/null
|
|
|
|
|
|
|
|
test $? -eq 2 && sleep $timeout
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Display the last $1 packets logged
|
|
|
|
#
|
2003-02-23 15:10:37 +01:00
|
|
|
packet_log() # $1 = number of messages
|
2002-05-01 01:13:15 +02:00
|
|
|
{
|
|
|
|
local options
|
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
[ -n "$realtail" ] && options="-n$1"
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
if [ -n "$VERBOSE" ]; then
|
|
|
|
grep "${LOGFORMAT}" $LOGFILE | \
|
|
|
|
sed s/" kernel:"// | \
|
|
|
|
sed s/" $host $LOGFORMAT"/" "/ | \
|
|
|
|
tail $options
|
|
|
|
else
|
|
|
|
grep "${LOGFORMAT}" $LOGFILE | \
|
|
|
|
sed s/" kernel:"// | \
|
|
|
|
sed s/" $host $LOGFORMAT"/" "/ | \
|
|
|
|
sed 's/MAC=.* SRC=/SRC=/' | \
|
|
|
|
tail $options
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Show traffic control information
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
show_tc() {
|
|
|
|
|
|
|
|
show_one_tc() {
|
2002-07-06 00:24:40 +02:00
|
|
|
local device=${1%@*}
|
2005-07-09 06:45:32 +02:00
|
|
|
qdisc=$(tc qdisc list dev $device)
|
2002-05-01 01:13:15 +02:00
|
|
|
|
|
|
|
if [ -n "$qdisc" ]; then
|
|
|
|
echo Device $device:
|
|
|
|
tc -s -d qdisc show dev $device
|
|
|
|
tc -s -d class show dev $device
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ip link list | \
|
|
|
|
while read inx interface details; do
|
|
|
|
case $inx in
|
|
|
|
[0-9]*)
|
|
|
|
show_one_tc ${interface%:}
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-12-10 21:42:19 +01:00
|
|
|
#
|
|
|
|
# Show classifier information
|
|
|
|
#
|
|
|
|
show_classifiers() {
|
|
|
|
|
|
|
|
show_one_classifier() {
|
|
|
|
local device=${1%@*}
|
2005-07-09 06:45:32 +02:00
|
|
|
qdisc=$(tc qdisc list dev $device)
|
2002-12-10 21:42:19 +01:00
|
|
|
|
|
|
|
if [ -n "$qdisc" ]; then
|
|
|
|
echo Device $device:
|
|
|
|
tc -s filter ls dev $device
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
ip link list | \
|
|
|
|
while read inx interface details; do
|
|
|
|
case $inx in
|
|
|
|
[0-9]*)
|
|
|
|
show_one_classifier ${interface%:}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Watch the Firewall Log
|
|
|
|
#
|
2002-06-02 19:05:51 +02:00
|
|
|
logwatch() # $1 = timeout -- if negative, prompt each time that
|
2002-07-06 00:24:40 +02:00
|
|
|
# an 'interesting' packet count changes
|
2002-06-02 19:05:51 +02:00
|
|
|
{
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
host=$(echo $HOSTNAME | sed 's/\..*$//')
|
2005-07-09 07:45:05 +02:00
|
|
|
oldrejects=$($IPTABLES -L -v -n | grep 'LOG')
|
2003-02-23 15:10:37 +01:00
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
if [ $1 -lt 0 ]; then
|
|
|
|
timeout=$((- $1))
|
|
|
|
pause="Yes"
|
|
|
|
else
|
|
|
|
pause="No"
|
|
|
|
timeout=$1
|
|
|
|
fi
|
|
|
|
|
2005-07-27 22:30:16 +02:00
|
|
|
qt mywhich awk && haveawk=Yes || haveawk=
|
2002-06-02 19:05:51 +02:00
|
|
|
|
|
|
|
while true; do
|
2005-07-09 07:45:05 +02:00
|
|
|
clear_term
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "$banner $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-06-02 19:05:51 +02:00
|
|
|
|
2002-11-11 00:15:53 +01:00
|
|
|
echo "Dropped/Rejected Packet Log"
|
|
|
|
echo
|
2002-06-02 19:05:51 +02:00
|
|
|
|
2002-09-18 01:53:46 +02:00
|
|
|
show_reset
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
rejects=$($IPTABLES -L -v -n | grep 'LOG')
|
2002-06-02 19:05:51 +02:00
|
|
|
|
|
|
|
if [ "$rejects" != "$oldrejects" ]; then
|
|
|
|
oldrejects="$rejects"
|
2002-11-11 00:15:53 +01:00
|
|
|
|
2002-11-11 17:46:50 +01:00
|
|
|
$RING_BELL
|
2002-11-11 00:15:53 +01:00
|
|
|
|
2002-06-02 19:05:51 +02:00
|
|
|
packet_log 40
|
|
|
|
|
|
|
|
if [ "$pause" = "Yes" ]; then
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-11-11 17:46:50 +01:00
|
|
|
echo $ECHO_N 'Enter any character to continue: '
|
2002-06-02 19:05:51 +02:00
|
|
|
read foo
|
|
|
|
else
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
packet_log 40
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
#
|
|
|
|
# Save currently running configuration
|
|
|
|
#
|
|
|
|
save_config() {
|
|
|
|
[ "$nolock" ] || mutex_on
|
|
|
|
|
2005-07-29 21:06:37 +02:00
|
|
|
if shorewall_is_started ; then
|
2005-07-09 07:55:29 +02:00
|
|
|
[ -d /var/lib/shorewall ] || mkdir -p /var/lib/shorewall
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
if [ -f $RESTOREPATH -a ! -x $RESTOREPATH ]; then
|
|
|
|
echo " ERROR: $RESTOREPATH exists and is not a saved Shorewall configuration"
|
|
|
|
else
|
|
|
|
case $RESTOREFILE in
|
|
|
|
save|restore-base)
|
|
|
|
echo " ERROR: Reserved file name: $RESTOREFILE"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if $IPTABLES -L dynamic -n > /var/lib/shorewall/save; then
|
|
|
|
echo " Dynamic Rules Saved"
|
|
|
|
if [ -f /var/lib/shorewall/restore-base ]; then
|
|
|
|
cp -f /var/lib/shorewall/restore-base /var/lib/shorewall/restore-$$
|
|
|
|
if iptables-save | iptablesbug >> /var/lib/shorewall/restore-$$ ; then
|
|
|
|
echo __EOF__ >> /var/lib/shorewall/restore-$$
|
|
|
|
[ -f /var/lib/shorewall/restore-tail ] && \
|
|
|
|
cat /var/lib/shorewall/restore-tail >> /var/lib/shorewall/restore-$$
|
2005-08-02 18:46:30 +02:00
|
|
|
mv -f /var/lib/shorewall/restore-$$ $RESTOREPATH
|
2005-07-09 07:55:29 +02:00
|
|
|
chmod +x $RESTOREPATH
|
|
|
|
echo " Currently-running Configuration Saved to $RESTOREPATH"
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
rm -f ${RESTOREPATH}-ipsets
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
case ${SAVE_IPSETS:-No} in
|
|
|
|
[Yy][Ee][Ss])
|
|
|
|
RESTOREPATH=${RESTOREPATH}-ipsets
|
|
|
|
|
|
|
|
f=/var/lib/shorewall/restore-$$
|
|
|
|
|
|
|
|
echo "#!/bin/sh" > $f
|
|
|
|
echo "#This ipset restore file generated $(date) by Shorewall $version" >> $f
|
|
|
|
echo >> $f
|
|
|
|
echo ". /usr/share/shorewall/functions" >> $f
|
|
|
|
echo >> $f
|
|
|
|
grep '^MODULE' /var/lib/shorewall/restore-base >> $f
|
|
|
|
echo "reload_kernel_modules << __EOF__" >> $f
|
|
|
|
grep 'loadmodule ip_set' /var/lib/shorewall/restore-base >> $f
|
|
|
|
echo "__EOF__" >> $f
|
|
|
|
echo >> $f
|
|
|
|
echo "ipset -U :all: :all:" >> $f
|
|
|
|
echo "ipset -F" >> $f
|
|
|
|
echo "ipset -X" >> $f
|
|
|
|
echo "ipset -R << __EOF__" >> $f
|
|
|
|
ipset -S >> $f
|
|
|
|
echo "__EOF__" >> $f
|
2005-08-02 18:46:30 +02:00
|
|
|
mv -f $f $RESTOREPATH
|
2005-07-09 07:55:29 +02:00
|
|
|
chmod +x $RESTOREPATH
|
|
|
|
echo " Current Ipset Contents Saved to $RESTOREPATH"
|
|
|
|
;;
|
|
|
|
[Nn][Oo])
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " WARNING: Invalid value ($SAVE_IPSETS) for SAVE_IPSETS. Ipset contents not saved"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
rm -f /var/lib/shorewall/restore-$$
|
|
|
|
echo " ERROR: Currently-running Configuration Not Saved"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo " ERROR: /var/lib/shorewall/restore-base does not exist"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Error Saving the Dynamic Rules"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Shorewall isn't started"
|
|
|
|
fi
|
2005-08-02 18:46:30 +02:00
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
[ "$nolock" ] || mutex_off
|
|
|
|
}
|
2003-07-27 20:17:39 +02:00
|
|
|
#
|
|
|
|
# Help information
|
|
|
|
#
|
|
|
|
help()
|
|
|
|
{
|
|
|
|
[ -x $HELP ] && { export version; exec $HELP $*; }
|
|
|
|
echo "Help subsystem is not installed at $HELP"
|
|
|
|
}
|
2005-08-02 18:46:30 +02:00
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
2005-09-15 01:01:13 +02:00
|
|
|
echo "Usage: $(basename $0) [debug|trace] [nolock] [ -x ] [ -q ] [ -f ] [ -v ] [ -n ] <command>"
|
2002-05-01 01:13:15 +02:00
|
|
|
echo "where <command> is one of:"
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " add <interface>[:{<bridge-port>[:<host>]|<host>}[,...]] ... <zone>"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " allow <address> ..."
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " check [ <directory> ]"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " clear"
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " delete <interface>[:{<bridge-port>[:<host>]|<host>}[,...]] ... <zone>"
|
2003-08-24 03:24:23 +02:00
|
|
|
echo " drop <address> ..."
|
2005-07-28 16:37:56 +02:00
|
|
|
echo " dump"
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " forget [ <file name> ]"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " help [ <command > | host | address ]"
|
|
|
|
echo " hits"
|
|
|
|
echo " ipcalc [ <address>/<vlsm> | <address> <netmask> ]"
|
|
|
|
echo " iprange <address>-<address>"
|
|
|
|
echo " logwatch [<refresh interval>]"
|
|
|
|
echo " refresh"
|
2003-08-24 03:24:23 +02:00
|
|
|
echo " reject <address> ..."
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " reset"
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " restart [ <directory> ]"
|
2005-07-09 06:45:32 +02:00
|
|
|
echo " restore [ <file name> ]"
|
|
|
|
echo " save [ <file name> ]"
|
2005-11-28 00:09:36 +01:00
|
|
|
echo " show [<chain> [ <chain> ... ]|actions|capabilities|classifiers|connections|log|macros|mangle|nat|tc|zones]"
|
2005-07-09 07:45:05 +02:00
|
|
|
echo " start [ <directory> ]"
|
2002-05-01 01:13:15 +02:00
|
|
|
echo " stop"
|
|
|
|
echo " status"
|
|
|
|
echo " try <directory> [ <timeout> ]"
|
2003-07-27 20:17:39 +02:00
|
|
|
echo " version"
|
2005-07-09 07:55:29 +02:00
|
|
|
echo " safe-start"
|
|
|
|
echo " safe-restart"
|
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
|
|
|
#
|
|
|
|
# Display the time that the counters were last reset
|
|
|
|
#
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset() {
|
2005-07-26 01:08:09 +02:00
|
|
|
[ -f /var/lib/shorewall/restarted ] && \
|
|
|
|
echo "Counters reset $(cat /var/lib/shorewall/restarted)" && \
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
}
|
2005-07-09 07:55:29 +02:00
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
#
|
|
|
|
# Display's the passed file name followed by "=" and the file's contents.
|
|
|
|
#
|
2005-08-02 18:46:30 +02:00
|
|
|
show_proc() # $1 = name of a file
|
2005-07-09 07:45:05 +02:00
|
|
|
{
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -f $1 ] && echo " $1 = $(cat $1)"
|
|
|
|
}
|
|
|
|
|
2005-08-02 18:46:30 +02:00
|
|
|
read_yesno_with_timeout() {
|
2005-07-09 07:55:29 +02:00
|
|
|
read -t 60 yn 2> /dev/null
|
|
|
|
if [ $? -eq 2 ]
|
|
|
|
then
|
|
|
|
# read doesn't support timeout
|
|
|
|
test -x /bin/bash || return 2 # bash is not installed so the feature is not available
|
|
|
|
/bin/bash -c 'read -t 60 yn ; if [ "$yn" == "y" ] ; then exit 0 ; else exit 1 ; fi' # invoke bash and use its version of read
|
|
|
|
return $?
|
|
|
|
else
|
|
|
|
# read supports timeout
|
|
|
|
case "$yn" in
|
|
|
|
y|Y)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2005-08-08 20:05:22 +02:00
|
|
|
#
|
|
|
|
# Print a heading with leading and trailing black lines
|
|
|
|
#
|
|
|
|
heading() {
|
|
|
|
echo
|
|
|
|
echo "$@"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2002-10-23 18:48:40 +02:00
|
|
|
#
|
|
|
|
# Execution begins here
|
|
|
|
#
|
2002-05-01 01:13:15 +02:00
|
|
|
debugging=
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
if [ $# -gt 0 ] && [ "$1" = "debug" -o "$1" = "trace" ]; then
|
2002-05-01 01:13:15 +02:00
|
|
|
debugging=debug
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
nolock=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "nolock" ]; then
|
|
|
|
nolock=nolock
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHOREWALL_DIR=
|
2005-07-09 06:45:32 +02:00
|
|
|
QUIET=
|
|
|
|
IPT_OPTIONS="-nv"
|
|
|
|
FAST=
|
2005-07-09 07:45:05 +02:00
|
|
|
VERBOSE=
|
2005-09-15 01:01:13 +02:00
|
|
|
NOROUTES=
|
2005-09-15 03:07:12 +02:00
|
|
|
noroutes=
|
2005-07-09 06:45:32 +02:00
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
done=0
|
|
|
|
|
|
|
|
while [ $done -eq 0 ]; do
|
|
|
|
[ $# -eq 0 ] && usage 1
|
2005-07-09 06:45:32 +02:00
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -z "$option" ] && usage 1
|
2005-09-30 18:54:24 +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
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
SHOREWALL_DIR=$2
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
x*)
|
|
|
|
IPT_OPTIONS="-xnv"
|
|
|
|
option=${option#x}
|
|
|
|
;;
|
|
|
|
q*)
|
|
|
|
QUIET=Yes
|
|
|
|
option=${option#q}
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
FAST=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
2005-07-09 07:45:05 +02:00
|
|
|
v*)
|
|
|
|
VERBOSE=Yes
|
|
|
|
option=${option#v}
|
|
|
|
;;
|
2005-09-15 01:01:13 +02:00
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
2005-09-30 18:54:24 +02:00
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
done=1
|
|
|
|
;;
|
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
|
|
|
|
|
2002-06-15 19:27:41 +02:00
|
|
|
[ -n "$SHOREWALL_DIR" ] && export SHOREWALL_DIR
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$QUIET" ] && export QUIET
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
|
|
|
MUTEX_TIMEOUT=
|
|
|
|
|
2003-03-08 19:01:32 +01:00
|
|
|
SHARED_DIR=/usr/share/shorewall
|
2003-01-07 00:01:23 +01:00
|
|
|
FIREWALL=$SHARED_DIR/firewall
|
|
|
|
FUNCTIONS=$SHARED_DIR/functions
|
|
|
|
VERSION_FILE=$SHARED_DIR/version
|
2003-07-27 20:17:39 +02:00
|
|
|
HELP=$SHARED_DIR/help
|
2003-01-07 00:01:23 +01:00
|
|
|
|
|
|
|
if [ -f $FUNCTIONS ]; then
|
|
|
|
. $FUNCTIONS
|
|
|
|
else
|
|
|
|
echo "$FUNCTIONS does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
2002-05-01 01:13:15 +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
|
|
|
|
|
|
|
|
export CONFIG_PATH
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
get_config
|
|
|
|
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ ! -f $FIREWALL ]; then
|
2002-05-01 01:13:15 +02:00
|
|
|
echo "ERROR: Shorewall is not properly installed"
|
2003-01-07 00:01:23 +01:00
|
|
|
if [ -L $FIREWALL ]; then
|
|
|
|
echo " $FIREWALL is a symbolic link to a"
|
2002-07-06 00:24:40 +02:00
|
|
|
echo " non-existant file"
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2003-01-07 00:01:23 +01:00
|
|
|
echo " The file $FIREWALL does not exist"
|
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
|
2005-07-09 06:45:32 +02:00
|
|
|
version=$(cat $VERSION_FILE)
|
2002-05-01 01:13:15 +02:00
|
|
|
else
|
2002-06-15 19:27:41 +02:00
|
|
|
echo "ERROR: Shorewall is not properly installed"
|
2003-01-07 00:01:23 +01:00
|
|
|
echo " The file $VERSION_FILE does not exist"
|
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
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
case "$1" in
|
2005-07-09 06:45:32 +02:00
|
|
|
start)
|
2005-07-09 07:45:05 +02:00
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
[ -n "$SHOREWALL_DIR" -o -n "$FAST" ] && usage 2
|
|
|
|
|
|
|
|
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
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
SHOREWALL_DIR=$2
|
|
|
|
export SHOREWALL_DIR
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
2005-09-15 01:01:13 +02:00
|
|
|
|
|
|
|
export NOROUTES
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
if [ -n "$FAST" ]; then
|
2005-07-27 22:30:16 +02:00
|
|
|
if qt mywhich make; then
|
2005-07-26 01:08:09 +02:00
|
|
|
make -qf /etc/shorewall/Makefile || FAST=
|
|
|
|
fi
|
2005-07-09 07:55:29 +02:00
|
|
|
|
2005-07-26 01:08:09 +02:00
|
|
|
if [ -n "$FAST" ]; then
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-26 01:08:09 +02:00
|
|
|
RESTOREPATH=/var/lib/shorewall/$RESTOREFILE
|
|
|
|
|
|
|
|
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
|
|
|
|
${RESTOREPATH}-ipsets
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo Restoring Shorewall...
|
|
|
|
$RESTOREPATH
|
|
|
|
date > /var/lib/shorewall/restarted
|
|
|
|
echo Shorewall restored from $RESTOREPATH
|
|
|
|
else
|
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock start
|
|
|
|
fi
|
2005-07-09 06:45:32 +02:00
|
|
|
else
|
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock start
|
|
|
|
fi
|
2005-07-26 01:08:09 +02:00
|
|
|
else
|
2005-07-09 06:45:32 +02:00
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock start
|
|
|
|
fi
|
|
|
|
;;
|
2005-07-09 07:45:05 +02:00
|
|
|
stop|reset|clear|refresh)
|
2002-05-01 01:13:15 +02:00
|
|
|
[ $# -ne 1 ] && usage 1
|
2005-09-15 01:01:13 +02:00
|
|
|
export NOROUTES
|
2005-07-09 07:45:05 +02:00
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $1
|
|
|
|
;;
|
|
|
|
check|restart)
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
[ -n "$SHOREWALL_DIR" ] && usage 2
|
|
|
|
|
|
|
|
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
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
SHOREWALL_DIR=$2
|
|
|
|
export SHOREWALL_DIR
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
2005-09-15 01:01:13 +02:00
|
|
|
|
|
|
|
export NOROUTES
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2003-06-28 17:22:22 +02:00
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $1
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-10-01 22:54:42 +02:00
|
|
|
add|delete)
|
2005-07-09 07:45:05 +02:00
|
|
|
[ $# -lt 3 ] && usage 1
|
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $@
|
2002-10-01 22:54:42 +02:00
|
|
|
;;
|
2003-01-23 02:13:36 +01:00
|
|
|
show|list)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-05-01 01:13:15 +02:00
|
|
|
case "$2" in
|
|
|
|
connections)
|
2003-08-15 02:59:06 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "Shorewall-$version Connections at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
cat /proc/net/ip_conntrack
|
|
|
|
;;
|
|
|
|
nat)
|
2003-08-15 02:59:06 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-11-28 00:21:16 +01:00
|
|
|
echo "Shorewall-$version NAT Table at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -t nat -L $IPT_OPTIONS
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
tos|mangle)
|
2003-08-15 02:59:06 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-11-28 00:21:16 +01:00
|
|
|
echo "Shorewall-$version Mangle Table at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -t mangle -L $IPT_OPTIONS
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
log)
|
2003-08-15 02:59:06 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "Shorewall-$version Log at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-09-18 01:53:46 +02:00
|
|
|
show_reset
|
2005-07-09 06:45:32 +02:00
|
|
|
host=$(echo $HOSTNAME | sed 's/\..*$//')
|
2002-06-02 19:05:51 +02:00
|
|
|
packet_log 20
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
tc)
|
2003-08-15 02:59:06 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "Shorewall-$version Traffic Control at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-05-01 01:13:15 +02:00
|
|
|
show_tc
|
|
|
|
;;
|
2002-12-10 21:42:19 +01:00
|
|
|
classifiers)
|
2003-08-15 02:59:06 +02:00
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "Shorewall-$version Clasifiers at $HOSTNAME - $(date)"
|
2002-12-10 21:42:19 +01:00
|
|
|
echo
|
|
|
|
show_classifiers
|
|
|
|
;;
|
2005-07-09 07:45:05 +02:00
|
|
|
zones)
|
|
|
|
[ $# -gt 2 ] && usage 1
|
2005-07-26 01:08:09 +02:00
|
|
|
if [ -f /var/lib/shorewall/zones ]; then
|
2005-07-09 07:45:05 +02:00
|
|
|
echo "Shorewall-$version Zones at $HOSTNAME - $(date)"
|
|
|
|
echo
|
2005-10-04 16:54:56 +02:00
|
|
|
while read zone type hosts; do
|
|
|
|
echo "$zone ($type)"
|
2005-07-09 07:45:05 +02:00
|
|
|
for host in $hosts; do
|
|
|
|
echo " $host"
|
|
|
|
done
|
2005-07-26 01:08:09 +02:00
|
|
|
done < /var/lib/shorewall/zones
|
2005-07-09 07:45:05 +02:00
|
|
|
echo
|
|
|
|
else
|
2005-07-26 01:08:09 +02:00
|
|
|
echo " ERROR: /var/lib/shorewall/zones does not exist" >&2
|
2005-07-09 07:45:05 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
capabilities)
|
2005-09-30 18:54:24 +02:00
|
|
|
determine_capabilities
|
|
|
|
report_capabilities
|
2005-07-09 07:45:05 +02:00
|
|
|
;;
|
2005-07-24 18:27:21 +02:00
|
|
|
actions)
|
|
|
|
echo "allowBcast #Silently Allow Broadcast/multicast"
|
|
|
|
echo "dropBcast #Silently Drop Broadcast/multicast"
|
|
|
|
echo "dropNotSyn #Silently Drop Non-syn TCP packets"
|
|
|
|
echo "rejNotSyn #Silently Reject Non-syn TCP packets"
|
|
|
|
echo "dropInvalid #Silently Drop packets that are in the INVALID conntrack state"
|
|
|
|
echo "allowInvalid #Accept packets that are in the INVALID conntrack state."
|
|
|
|
echo "allowoutUPnP #Allow traffic from local command 'upnpd'"
|
|
|
|
echo "allowinUPnP #Allow UPnP inbound (to firewall) traffic"
|
|
|
|
echo "forwardUPnP #Allow traffic that upnpd has redirected from"
|
|
|
|
cat /usr/share/shorewall/actions.std /etc/shorewall/actions | grep -Ev '^\#|^$'
|
|
|
|
;;
|
2005-11-27 21:59:47 +01:00
|
|
|
macros)
|
|
|
|
for macro in /usr/share/shorewall/macro.*; do
|
|
|
|
foo=`grep 'This macro' $macro | head -n 1`
|
|
|
|
if [ -n "$foo" ]; then
|
|
|
|
macro=${macro#*.}
|
|
|
|
foo=${foo%.*}
|
2005-11-27 22:11:14 +01:00
|
|
|
echo " $macro ${foo#\#}"
|
2005-11-27 21:59:47 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
2002-07-06 00:24:40 +02:00
|
|
|
*)
|
2003-08-15 02:59:06 +02:00
|
|
|
shift
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "Shorewall-$version $([ $# -gt 1 ] && echo Chains || echo Chain) $* at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2003-08-15 17:54:13 +02:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
for chain in $*; do
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -L $chain $IPT_OPTIONS
|
2003-08-15 17:54:13 +02:00
|
|
|
done
|
|
|
|
else
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -L $IPT_OPTIONS
|
2003-08-15 17:54:13 +02:00
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-07-06 00:24:40 +02:00
|
|
|
esac
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
status)
|
2005-07-28 16:37:56 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2005-07-30 23:59:12 +02:00
|
|
|
echo "Shorewall-$version Status at $HOSTNAME - $(date)"
|
|
|
|
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
|
|
|
|
|
|
|
|
if [ -f /var/lib/shorewall/state ]; then
|
2005-07-30 23:59:12 +02:00
|
|
|
state="$(cat /var/lib/shorewall/state)"
|
|
|
|
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)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2005-07-09 07:45:05 +02:00
|
|
|
clear_term
|
2005-07-28 16:37:56 +02:00
|
|
|
echo "Shorewall-$version Dump at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
2002-07-23 00:31:07 +02:00
|
|
|
show_reset
|
2005-07-09 06:45:32 +02:00
|
|
|
host=$(echo $HOSTNAME | sed 's/\..*$//')
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -L $IPT_OPTIONS
|
2002-05-01 01:13:15 +02:00
|
|
|
echo
|
2002-06-10 18:53:18 +02:00
|
|
|
packet_log 20
|
2005-08-08 20:05:22 +02:00
|
|
|
|
|
|
|
heading "NAT Table"
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -t nat -L $IPT_OPTIONS
|
2005-08-08 20:05:22 +02:00
|
|
|
|
|
|
|
heading "Mangle Table"
|
2005-07-09 07:45:05 +02:00
|
|
|
$IPTABLES -t mangle -L $IPT_OPTIONS
|
2002-05-01 01:13:15 +02:00
|
|
|
echo
|
|
|
|
cat /proc/net/ip_conntrack
|
2005-08-08 20:05:22 +02:00
|
|
|
|
|
|
|
heading "IP Configuration"
|
2005-07-09 06:45:32 +02:00
|
|
|
ip addr ls
|
2005-08-08 20:05:22 +02:00
|
|
|
|
|
|
|
heading "IP Stats"
|
2005-07-09 07:45:05 +02:00
|
|
|
ip -stat link ls
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-27 22:30:16 +02:00
|
|
|
if qt mywhich brctl; then
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "Bridges"
|
2005-07-09 06:45:32 +02:00
|
|
|
brctl show
|
|
|
|
fi
|
|
|
|
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "/proc"
|
|
|
|
show_proc /proc/version
|
2005-07-09 06:45:32 +02:00
|
|
|
show_proc /proc/sys/net/ipv4/ip_forward
|
2005-07-09 07:45:05 +02:00
|
|
|
show_proc /proc/sys/net/ipv4/icmp_echo_ignore_all
|
2005-07-09 06:45:32 +02:00
|
|
|
|
|
|
|
for directory in /proc/sys/net/ipv4/conf/*; do
|
2005-07-26 01:08:09 +02:00
|
|
|
for file in proxy_arp arp_filter arp_ignore rp_filter log_martians; do
|
2005-07-09 06:45:32 +02:00
|
|
|
show_proc $directory/$file
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2005-07-09 07:45:05 +02:00
|
|
|
if [ -n "$(ip rule ls)" ]; then
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "Routing Rules"
|
2005-07-09 07:45:05 +02:00
|
|
|
ip rule ls
|
|
|
|
ip rule ls | while read rule; do
|
2005-07-09 07:55:29 +02:00
|
|
|
echo ${rule##* }
|
2005-08-02 18:46:30 +02:00
|
|
|
done | sort -u | while read table; do
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "Table $table:"
|
2005-07-09 07:45:05 +02:00
|
|
|
ip route ls table $table
|
|
|
|
done
|
|
|
|
else
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "Routing Table"
|
2005-07-09 07:45:05 +02:00
|
|
|
ip route ls
|
|
|
|
fi
|
|
|
|
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "ARP"
|
2005-07-09 07:45:05 +02:00
|
|
|
arp -na
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-27 22:30:16 +02:00
|
|
|
if qt mywhich lsmod; then
|
2005-08-08 20:05:22 +02:00
|
|
|
heading "Modules"
|
2005-08-03 22:24:55 +02:00
|
|
|
lsmod | grep -E '^ip_|^ipt_|^iptable_'
|
2005-07-09 07:45:05 +02:00
|
|
|
fi
|
2005-09-30 18:54:24 +02:00
|
|
|
|
|
|
|
determine_capabilities
|
|
|
|
echo
|
|
|
|
report_capabilities
|
2005-12-01 19:24:19 +01:00
|
|
|
|
|
|
|
if [ -n "$TC_ENABLED" ]; then
|
|
|
|
echo
|
|
|
|
echo "Traffic Control"
|
|
|
|
echo
|
|
|
|
show_tc
|
|
|
|
echo "Traffic Filters"
|
|
|
|
echo
|
|
|
|
show_classifiers
|
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
|
|
|
hits)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] || usage 1
|
2005-07-09 07:45:05 +02:00
|
|
|
clear_term
|
2005-07-09 06:45:32 +02:00
|
|
|
echo "Shorewall-$version Hits at $HOSTNAME - $(date)"
|
2002-11-11 00:15:53 +01:00
|
|
|
echo
|
|
|
|
|
2002-05-01 01:13:15 +02:00
|
|
|
timeout=30
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
if [ $(grep -c "$LOGFORMAT" $LOGFILE ) -gt 0 ] ; then
|
2002-07-06 00:24:40 +02:00
|
|
|
echo " HITS IP DATE"
|
|
|
|
echo " ---- --------------- ------"
|
2003-05-21 23:36:05 +02:00
|
|
|
grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn
|
2002-07-06 00:24:40 +02:00
|
|
|
echo ""
|
2002-05-01 01:13:15 +02:00
|
|
|
|
2002-07-06 00:24:40 +02:00
|
|
|
echo " HITS IP PORT"
|
|
|
|
echo " ---- --------------- -----"
|
2003-05-21 23:36:05 +02:00
|
|
|
grep "$LOGFORMAT" $LOGFILE | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/
|
2002-06-30 00:41:30 +02:00
|
|
|
t
|
|
|
|
s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn
|
2002-07-06 00:24:40 +02:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo " HITS DATE"
|
|
|
|
echo " ---- ------"
|
2003-05-21 23:36:05 +02:00
|
|
|
grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn
|
2002-07-06 00:24:40 +02:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo " HITS PORT SERVICE(S)"
|
2003-02-23 15:10:37 +01:00
|
|
|
echo " ---- ----- ----------"
|
2003-06-01 05:14:20 +02:00
|
|
|
grep "$LOGFORMAT.*DPT" $LOGFILE | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | \
|
2002-07-06 00:24:40 +02:00
|
|
|
while read count port ; do
|
|
|
|
# List all services defined for the given port
|
2005-07-09 06:45:32 +02:00
|
|
|
srv=$(grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | sort -u)
|
|
|
|
srv=$(echo $srv | sed 's/ /,/g')
|
2002-07-06 00:24:40 +02:00
|
|
|
|
|
|
|
if [ -n "$srv" ] ; then
|
|
|
|
printf '%7d %5d %s\n' $count $port $srv
|
|
|
|
else
|
|
|
|
printf '%7d %5d\n' $count $port
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
2002-05-01 01:13:15 +02:00
|
|
|
version)
|
|
|
|
echo $version
|
|
|
|
;;
|
|
|
|
try)
|
2005-07-26 01:08:09 +02:00
|
|
|
[ -n "$SHOREWALL_DIR" ] && startup_error "ERROR: -c option may not be used with \"try\""
|
2002-05-01 01:13:15 +02:00
|
|
|
[ $# -lt 2 -o $# -gt 3 ] && usage 1
|
2005-08-15 20:30:59 +02:00
|
|
|
[ -n "$QUIET" ] && QUIET=-q
|
2005-09-15 03:07:12 +02:00
|
|
|
[ -n "$NOROUTES" ] && NOROUTES=-n
|
2005-08-15 20:30:59 +02:00
|
|
|
if ! $0 $debugging $QUIET -c $2 restart; then
|
2005-07-09 07:45:05 +02:00
|
|
|
if ! $IPTABLES -L shorewall > /dev/null 2> /dev/null; then
|
2005-09-15 03:07:12 +02:00
|
|
|
$0 $QUIET $NOROUTES start
|
2002-06-04 17:08:50 +02:00
|
|
|
fi
|
2005-07-09 07:45:05 +02:00
|
|
|
elif ! $IPTABLES -L shorewall > /dev/null 2> /dev/null; then
|
2005-09-15 03:07:12 +02:00
|
|
|
$0 $QUIET $NOROUTES start
|
2002-05-01 01:13:15 +02:00
|
|
|
elif [ $# -eq 3 ]; then
|
|
|
|
sleep $3
|
2005-09-15 03:07:12 +02:00
|
|
|
$0 $QUIET $NOROUTES restart
|
2002-07-06 00:24:40 +02:00
|
|
|
fi
|
2002-05-01 01:13:15 +02:00
|
|
|
;;
|
2002-06-02 19:05:51 +02:00
|
|
|
logwatch)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-06-02 19:05:51 +02:00
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
logwatch $2
|
|
|
|
elif [ $# -eq 1 ]; then
|
|
|
|
logwatch 30
|
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
2002-07-06 00:24:40 +02:00
|
|
|
;;
|
2002-06-04 22:17:46 +02:00
|
|
|
drop)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-06-04 17:08:50 +02:00
|
|
|
mutex_on
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
2005-07-09 07:45:05 +02:00
|
|
|
qt $IPTABLES -D dynamic -s $1 -j reject
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j DROP
|
|
|
|
$IPTABLES -A dynamic -s $1 -j DROP || break 1
|
2002-06-04 22:17:46 +02:00
|
|
|
echo "$1 Dropped"
|
2002-06-04 17:08:50 +02:00
|
|
|
done
|
|
|
|
mutex_off
|
|
|
|
;;
|
2002-06-04 22:17:46 +02:00
|
|
|
reject)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-06-04 22:17:46 +02:00
|
|
|
mutex_on
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
2005-07-09 07:45:05 +02:00
|
|
|
qt $IPTABLES -D dynamic -s $1 -j reject
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j DROP
|
|
|
|
$IPTABLES -A dynamic -s $1 -j reject || break 1
|
2003-08-24 03:24:23 +02:00
|
|
|
echo "$1 Rejected"
|
2002-06-04 22:17:46 +02:00
|
|
|
done
|
|
|
|
mutex_off
|
|
|
|
;;
|
|
|
|
allow)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2002-07-06 00:24:40 +02:00
|
|
|
[ $# -eq 1 ] && usage 1
|
2002-06-04 22:17:46 +02:00
|
|
|
mutex_on
|
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
2005-07-09 07:45:05 +02:00
|
|
|
if qt $IPTABLES -D dynamic -s $1 -j reject || qt $IPTABLES -D dynamic -s $1 -j DROP; then
|
2003-08-24 03:24:23 +02:00
|
|
|
echo "$1 Allowed"
|
|
|
|
else
|
|
|
|
echo "$1 Not Dropped or Rejected"
|
|
|
|
fi
|
2002-06-04 22:17:46 +02:00
|
|
|
done
|
|
|
|
mutex_off
|
|
|
|
;;
|
|
|
|
save)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
RESTOREPATH=/var/lib/shorewall/$RESTOREFILE
|
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
save_config
|
2003-08-24 03:24:23 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
RESTOREPATH=/var/lib/shorewall/$RESTOREFILE
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
2005-08-03 22:24:55 +02:00
|
|
|
rm -f /var/lib/shorewall/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
|
|
|
|
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-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2003-07-06 15:24:23 +02:00
|
|
|
case $2 in
|
|
|
|
*.*.*.*-*.*.*.*)
|
|
|
|
ip_range $2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2005-07-09 06:45:32 +02:00
|
|
|
restore)
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
RESTOREPATH=/var/lib/shorewall/$RESTOREFILE
|
|
|
|
|
2005-09-15 01:01:13 +02:00
|
|
|
export NOROUTES
|
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
2005-08-02 18:46:30 +02:00
|
|
|
if [ -x $RESTOREPATH ]; then
|
2005-07-09 07:55:29 +02:00
|
|
|
if [ -x ${RESTOREPATH}-ipsets ] ; then
|
|
|
|
echo Restoring Ipsets...
|
|
|
|
iptables -F
|
|
|
|
iptables -X
|
|
|
|
${RESTOREPATH}-ipsets
|
|
|
|
fi
|
|
|
|
|
2005-07-09 06:45:32 +02:00
|
|
|
echo Restoring Shorewall...
|
|
|
|
$RESTOREPATH && echo "Shorewall restored from /var/lib/shorewall/$RESTOREFILE"
|
2005-07-09 07:55:29 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
2005-07-09 06:45:32 +02:00
|
|
|
else
|
|
|
|
echo "File /var/lib/shorewall/$RESTOREFILE: file not found"
|
2005-07-09 07:55:29 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
2005-07-09 06:45:32 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
2005-08-02 18:46:30 +02:00
|
|
|
call)
|
2005-07-09 06:45:32 +02:00
|
|
|
[ -n "$debugging" ] && set -x
|
2003-07-05 19:55:43 +02:00
|
|
|
#
|
|
|
|
# Undocumented way to call functions in /usr/share/shorewall/functions directly
|
|
|
|
#
|
|
|
|
shift;
|
|
|
|
$@
|
|
|
|
;;
|
2003-07-27 20:17:39 +02:00
|
|
|
help)
|
|
|
|
shift
|
|
|
|
[ $# -ne 1 ] && usage 1
|
|
|
|
help $@
|
|
|
|
;;
|
2005-07-09 07:55:29 +02:00
|
|
|
safe-restart|safe-start)
|
2005-08-02 18:46:30 +02:00
|
|
|
# test is the shell supports timed read
|
2005-07-09 07:55:29 +02:00
|
|
|
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
|
|
|
|
|
2005-11-29 20:39:43 +01:00
|
|
|
[ -n "$QUIET" ] && QUIET=-q
|
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
mutex_on
|
|
|
|
|
2005-07-29 21:06:37 +02:00
|
|
|
if shorewall_is_started
|
2005-07-09 07:55:29 +02:00
|
|
|
then
|
|
|
|
running=0
|
|
|
|
else
|
|
|
|
running=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "safe-start" -a $running -eq 0 ]
|
|
|
|
then
|
|
|
|
# the command is safe-start but the firewall is already running
|
2005-11-29 20:39:43 +01:00
|
|
|
$0 $debugging nolock $QUIET start
|
2005-07-09 07:55:29 +02:00
|
|
|
ret=$?
|
2005-09-15 03:07:12 +02:00
|
|
|
mutex_off
|
2005-07-09 07:55:29 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
if [ "$1" = "safe-start" -o $running -ne 0 ]
|
|
|
|
then
|
|
|
|
# the command is safe-start or shorewall is not started yet
|
|
|
|
command="start"
|
|
|
|
else
|
2005-09-17 05:22:17 +02:00
|
|
|
# the command is safe-restart and the firewall is already running
|
2005-07-09 07:55:29 +02:00
|
|
|
command="restart"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$command" = "restart" ]
|
|
|
|
then
|
|
|
|
# save previous configuration
|
2005-11-29 20:39:43 +01:00
|
|
|
$0 $debugging nolock save "safe-start-restart"
|
2005-07-09 07:55:29 +02:00
|
|
|
fi
|
|
|
|
|
2005-11-29 20:39:43 +01:00
|
|
|
$0 $debugging nolock $QUIET $command
|
2005-07-09 07:55:29 +02:00
|
|
|
|
|
|
|
echo -n "Do you want to accept the new firewall configuration? [y/n] "
|
|
|
|
read_yesno_with_timeout
|
|
|
|
if [ $? -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "New configuration has been accepted"
|
|
|
|
if [ "$command" = "restart" ]
|
|
|
|
then
|
|
|
|
# removed previous configuration
|
|
|
|
rm /var/lib/shorewall/safe-start-restart
|
|
|
|
fi
|
2005-09-30 18:54:24 +02:00
|
|
|
else
|
2005-07-09 07:55:29 +02:00
|
|
|
if [ "$command" = "restart" ]
|
|
|
|
then
|
2005-11-29 20:39:43 +01:00
|
|
|
$0 $debugging nolock restore "safe-start-restart"
|
2005-07-09 07:55:29 +02:00
|
|
|
rm /var/lib/shorewall/safe-start-restart
|
2005-09-30 18:54:24 +02:00
|
|
|
else
|
2005-11-29 20:39:43 +01:00
|
|
|
$0 $debugging nolock clear
|
2005-07-09 07:55:29 +02:00
|
|
|
fi
|
2005-09-30 18:54:24 +02:00
|
|
|
|
2005-07-09 07:55:29 +02:00
|
|
|
mutex_off
|
|
|
|
echo "New configuration has been rejected and the old one restored"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
mutex_off
|
|
|
|
[ $? -eq 0 ] && [ -n "$SUBSYSLOCK" ] && touch $SUBSYSLOCK
|
|
|
|
;;
|
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
|