2006-06-03 17:16:21 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2007-12-01 18:45:43 +01:00
|
|
|
# Shorewall Lite Packet Filtering Firewall Control Program - V4.1
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2007-09-08 18:09:51 +02:00
|
|
|
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# (c) 2006 - Tom Eastep (teastep@shorewall.net)
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-06-12 19:48:20 +02:00
|
|
|
# This file should be placed in /sbin/shorewall-lite.
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# Shorewall documentation is available at http://shorewall.net
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of Version 2 of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2007-09-08 18:09:51 +02:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# If an error occurs while starting or restarting the firewall, the
|
|
|
|
# firewall is automatically stopped.
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# Commands are:
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite dump Dumps all Shorewall-related information
|
2006-06-03 17:16:21 +02:00
|
|
|
# for problem analysis
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite start Starts the firewall
|
|
|
|
# shorewall-lite restart Restarts the firewall
|
|
|
|
# shorewall-lite stop Stops the firewall
|
|
|
|
# shorewall-lite status Displays firewall status
|
|
|
|
# shorewall-lite reset Resets iptables packet and
|
2006-06-03 17:16:21 +02:00
|
|
|
# byte counts
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite clear Open the floodgates by
|
2006-06-03 17:16:21 +02:00
|
|
|
# removing all iptables rules
|
|
|
|
# and setting the three permanent
|
|
|
|
# chain policies to ACCEPT
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite show <chain> [ <chain> ... ] Display the rules in each <chain> listed
|
|
|
|
# shorewall-lite show log Print the last 20 log messages
|
|
|
|
# shorewall-lite show connections Show the kernel's connection
|
2006-06-03 17:16:21 +02:00
|
|
|
# tracking table
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite show nat Display the rules in the nat table
|
|
|
|
# shorewall-lite show {mangle|tos} Display the rules in the mangle table
|
|
|
|
# shorewall-lite show tc Display traffic control info
|
|
|
|
# shorewall-lite show classifiers Display classifiers
|
|
|
|
# shorewall-lite show capabilities Display iptables/kernel capabilities
|
2007-11-16 00:24:54 +01:00
|
|
|
# shorewall-lite show vardir Display VARDIR setting
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite version Display the installed version id
|
|
|
|
# shorewall-lite logwatch [ refresh-interval ] Monitor the local log for Shorewall
|
2006-06-03 17:16:21 +02:00
|
|
|
# messages.
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite drop <address> ... Temporarily drop all packets from the
|
2006-06-03 17:16:21 +02:00
|
|
|
# listed address(es)
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite reject <address> ... Temporarily reject all packets from the
|
2006-06-03 17:16:21 +02:00
|
|
|
# listed address(es)
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite allow <address> ... Reenable address(es) previously
|
2006-06-03 17:16:21 +02:00
|
|
|
# disabled with "drop" or "reject"
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite save [ <file> ] Save the list of "rejected" and
|
2006-06-03 17:16:21 +02:00
|
|
|
# "dropped" addresses so that it will
|
|
|
|
# be automatically reinstated the
|
|
|
|
# next time that Shorewall starts.
|
|
|
|
# Save the current state so that 'shorewall
|
|
|
|
# restore' can be used.
|
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite forget [ <file> ] Discard the data saved by 'shorewall save'
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite restore [ <file> ] Restore the state of the firewall from
|
2006-06-03 17:16:21 +02:00
|
|
|
# previously saved information.
|
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite ipaddr { <address>/<cidr> | <address> <netmask> }
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Displays information about the network
|
|
|
|
# defined by the argument[s]
|
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite iprange <address>-<address> Decomposes a range of IP addresses into
|
2006-06-03 17:16:21 +02:00
|
|
|
# a list of network/host addresses.
|
|
|
|
#
|
2006-07-21 18:37:00 +02:00
|
|
|
# shorewall-lite ipdecimal { <address> | <integer> }
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Displays the decimal equivalent of an IP
|
|
|
|
# address and vice versa.
|
|
|
|
|
|
|
|
#
|
2007-01-04 00:26:13 +01:00
|
|
|
# Set the configuration variables from shorewall-lite.conf
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
get_config() {
|
|
|
|
|
2006-08-09 18:18:32 +02:00
|
|
|
[ -n "$PATH" ] || PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
[ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
|
|
|
|
|
2006-12-06 00:11:20 +01:00
|
|
|
if ( ps ax 2> /dev/null | grep -v grep | qt grep 'syslogd.*-C' ) ; then
|
2007-09-10 17:52:57 +02:00
|
|
|
LOGREAD="logread | tac"
|
2006-12-05 22:26:37 +01:00
|
|
|
elif [ -f $LOGFILE ]; then
|
2007-09-10 17:52:57 +02:00
|
|
|
LOGREAD="tac $LOGFILE"
|
2006-12-05 22:26:37 +01:00
|
|
|
else
|
2006-06-03 17:16:21 +02:00
|
|
|
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
|
|
|
|
#
|
2006-12-05 22:26:37 +01:00
|
|
|
if ( tail -n5 /dev/null > /dev/null 2> /dev/null ) ; then
|
2006-06-03 17:16:21 +02:00
|
|
|
realtail="Yes"
|
|
|
|
else
|
|
|
|
realtail=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$FW" ] || FW=fw
|
|
|
|
|
|
|
|
[ -n "LOGFORMAT" ] && LOGFORMAT="${LOGFORMAT%%%*}"
|
|
|
|
|
|
|
|
[ -n "$LOGFORMAT" ] || LOGFORMAT="Shorewall:"
|
|
|
|
|
2006-06-08 23:49:34 +02:00
|
|
|
export LOGFORMAT
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
if [ -n "$IPTABLES" ]; then
|
2006-09-05 16:29:47 +02:00
|
|
|
if [ ! -x "$IPTABLES" ]; then
|
2006-06-03 17:16:21 +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-08 23:49:34 +02:00
|
|
|
export IPTABLES
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
if [ -n "$SHOREWALL_SHELL" ]; then
|
2006-09-05 16:29:47 +02:00
|
|
|
if [ ! -x "$SHOREWALL_SHELL" ]; then
|
2007-12-15 00:13:36 +01:00
|
|
|
echo " WARNING: The program specified in SHOREWALL_SHELL does not exist or is not executable; falling back to /bin/sh" >&2
|
|
|
|
SHOREWALL_SHELL=/bin/sh
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$RESTOREFILE" ] || RESTOREFILE=restore
|
|
|
|
|
|
|
|
validate_restorefile RESTOREFILE
|
|
|
|
|
|
|
|
export RESTOREFILE
|
|
|
|
|
|
|
|
[ -n "${VERBOSITY:=2}" ]
|
|
|
|
|
2007-11-23 22:49:06 +01:00
|
|
|
[ -n "$USE_VERBOSITY" ] && VERBOSE=$USE_VERBOSITY || VERBOSE=$(($VERBOSE_OFFSET + $VERBOSITY))
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
export VERBOSE
|
|
|
|
|
2006-12-02 18:11:33 +01:00
|
|
|
[ -n "${HOSTNAME:=$(hostname)}" ]
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
}
|
|
|
|
|
2006-08-09 18:18:32 +02:00
|
|
|
#
|
|
|
|
# Verify that we have a compiled firewall script
|
|
|
|
#
|
|
|
|
verify_firewall_script() {
|
|
|
|
if [ ! -f $FIREWALL ]; then
|
|
|
|
echo " ERROR: Shorewall Lite is not properly installed" >&2
|
|
|
|
if [ -L $FIREWALL ]; then
|
|
|
|
echo " $FIREWALL is a symbolic link to a" >&2
|
|
|
|
echo " non-existant file" >&2
|
|
|
|
else
|
|
|
|
echo " The file $FIREWALL does not exist" >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
# Start Command Executor
|
|
|
|
#
|
|
|
|
start_command() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local finished
|
|
|
|
finished=0
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
do_it() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local rc
|
|
|
|
rc=0
|
2006-06-03 17:16:21 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
2006-06-17 17:28:51 +02:00
|
|
|
if [ -x ${LITEDIR}/firewall ]; then
|
|
|
|
${LITEDIR}/firewall $debugging start
|
2006-09-29 17:45:03 +02:00
|
|
|
rc=$?
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
2006-06-17 17:28:51 +02:00
|
|
|
error_message "${LITEDIR}/firewall is missing or is not executable"
|
2006-12-12 18:49:52 +01:00
|
|
|
logger -p kern.err "ERROR:Shorewall Lite start failed"
|
2006-09-29 17:45:03 +02:00
|
|
|
rc=2
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-09-29 17:45:03 +02:00
|
|
|
exit $rc
|
2006-06-03 17:16:21 +02:00
|
|
|
}
|
|
|
|
|
2006-08-09 18:18:32 +02:00
|
|
|
verify_firewall_script
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
if shorewall_is_started; then
|
|
|
|
error_message "Shorewall is already running"
|
2006-11-11 17:20:59 +01:00
|
|
|
exit 0
|
2006-06-03 17:16:21 +02:00
|
|
|
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=
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
FAST=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
2008-04-28 19:32:31 +02:00
|
|
|
p*)
|
|
|
|
[ -n "$(which conntrack)" ] || fatal_error "The '-p' option requires the conntrack utility which does not appear to be installed on this system"
|
|
|
|
PURGE=Yes
|
|
|
|
option=${option%p}
|
|
|
|
;;
|
2006-06-03 17:16:21 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
export NOROUTES
|
|
|
|
|
|
|
|
if [ -n "$FAST" ]; then
|
|
|
|
if qt mywhich make; then
|
|
|
|
#
|
|
|
|
# RESTOREFILE is exported by get_config()
|
|
|
|
#
|
2006-06-09 18:36:12 +02:00
|
|
|
make -qf ${CONFDIR}/Makefile || FAST=
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$FAST" ]; then
|
|
|
|
|
2006-06-09 18:36:12 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2006-06-03 17:16:21 +02: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:42:51 +02:00
|
|
|
$SHOREWALL_SHELL ${RESTOREPATH}-ipsets
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
2006-06-14 18:32:13 +02:00
|
|
|
echo Restoring Shorewall Lite...
|
2006-06-03 17:16:21 +02:00
|
|
|
$SHOREWALL_SHELL $RESTOREPATH restore
|
2006-06-09 18:36:12 +02:00
|
|
|
date > ${VARDIR}/restarted
|
2006-06-14 18:32:13 +02:00
|
|
|
progress_message3 Shorewall Lite restored from $RESTOREPATH
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
|
|
|
do_it
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
do_it
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
do_it
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Restart Command Executor
|
|
|
|
#
|
|
|
|
restart_command() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local rc
|
|
|
|
rc=0
|
2006-06-03 17:16:21 +02:00
|
|
|
|
2006-08-09 18:18:32 +02:00
|
|
|
verify_firewall_script
|
|
|
|
|
2006-06-03 17:16:21 +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=
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
2008-04-28 19:32:31 +02:00
|
|
|
p*)
|
|
|
|
[ -n "$(which conntrack)" ] || fatal_error "The '-p' option requires the conntrack utility which does not appear to be installed on this system"
|
|
|
|
PURGE=Yes
|
|
|
|
option=${option%p}
|
|
|
|
;;
|
2006-06-03 17:16:21 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
export NOROUTES
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
2006-06-17 17:28:51 +02:00
|
|
|
if [ -x ${LITEDIR}/firewall ]; then
|
|
|
|
$SHOREWALL_SHELL ${LITEDIR}/firewall $debugging restart
|
2006-09-29 17:45:03 +02:00
|
|
|
rc=$?
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
2006-06-17 17:28:51 +02:00
|
|
|
error_message "${LITEDIR}/firewall is missing or is not executable"
|
2006-12-12 18:49:52 +01:00
|
|
|
logger -p kern.err "ERROR:Shorewall Lite restart failed"
|
2006-09-29 17:45:03 +02:00
|
|
|
rc=2
|
2006-06-03 17:16:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-09-29 17:45:03 +02:00
|
|
|
return $rc
|
2006-06-03 17:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
2007-11-23 22:58:32 +01:00
|
|
|
echo "Usage: $(basename $0) [debug|trace] [nolock] [ -q ] [ -v[-1|{0-2}] ] [ -t ] <command>"
|
2006-06-03 17:16:21 +02:00
|
|
|
echo "where <command> is one of:"
|
|
|
|
echo " allow <address> ..."
|
|
|
|
echo " clear"
|
|
|
|
echo " drop <address> ..."
|
|
|
|
echo " dump [ -x ]"
|
|
|
|
echo " forget [ <file name> ]"
|
2006-11-21 23:52:07 +01:00
|
|
|
echo " help"
|
2007-11-16 00:24:54 +01:00
|
|
|
echo " hits [ -t ]"
|
2006-06-03 17:16:21 +02:00
|
|
|
echo " ipcalc { <address>/<vlsm> | <address> <netmask> }"
|
|
|
|
echo " ipdecimal { <address> | <integer> }"
|
|
|
|
echo " iprange <address>-<address>"
|
|
|
|
echo " logdrop <address> ..."
|
|
|
|
echo " logreject <address> ..."
|
|
|
|
echo " logwatch [<refresh interval>]"
|
|
|
|
echo " reject <address> ..."
|
2008-12-17 18:40:44 +01:00
|
|
|
echo " reset [ <chain> ... ]"
|
2008-04-28 19:32:31 +02:00
|
|
|
echo " restart [ -n ] [ -p ]"
|
2006-06-03 17:16:21 +02:00
|
|
|
echo " restore [ -n ] [ <file name> ]"
|
|
|
|
echo " save [ <file name> ]"
|
2009-03-06 21:43:46 +01:00
|
|
|
echo " show [ -x ] [ -t {filter|mangle|nat} ] [ {chain [<chain> [ <chain> ... ]"
|
|
|
|
echo " show [ -f ] capabilities"
|
|
|
|
echo " show classifiers"
|
|
|
|
echo " show config"
|
|
|
|
echo " show connections"
|
|
|
|
echo " show dynamic <zone>"
|
|
|
|
echo " show filter"
|
|
|
|
echo " show ip"
|
|
|
|
echo " show [ -m ] log"
|
|
|
|
echo " show [ -x ] mangle|nat|raw"
|
|
|
|
echo " show routing"
|
|
|
|
echo " show tc"
|
|
|
|
echo " show vardir"
|
|
|
|
echo " show zones"
|
|
|
|
echo " start [ -n ] [ -p ]"
|
2006-06-03 17:16:21 +02:00
|
|
|
echo " stop"
|
|
|
|
echo " status"
|
|
|
|
echo " version"
|
|
|
|
echo
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Execution begins here
|
|
|
|
#
|
|
|
|
debugging=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "debug" -o "$1" = "trace" ]; then
|
2007-10-19 21:43:14 +02:00
|
|
|
debugging=$1
|
2006-06-03 17:16:21 +02:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
nolock=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "nolock" ]; then
|
|
|
|
nolock=nolock
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
IPT_OPTIONS="-nv"
|
|
|
|
FAST=
|
|
|
|
VERBOSE_OFFSET=0
|
2007-11-23 22:49:06 +01:00
|
|
|
USE_VERBOSITY=
|
2006-06-03 17:16:21 +02:00
|
|
|
NOROUTES=
|
|
|
|
EXPORT=
|
|
|
|
export TIMESTAMP=
|
|
|
|
noroutes=
|
|
|
|
|
|
|
|
finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 ]; do
|
|
|
|
[ $# -eq 0 ] && usage 1
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
[ -z "$option" ] && usage 1
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
x*)
|
|
|
|
IPT_OPTIONS="-xnv"
|
|
|
|
option=${option#x}
|
|
|
|
;;
|
|
|
|
q*)
|
|
|
|
VERBOSE_OFFSET=$(($VERBOSE_OFFSET - 1 ))
|
|
|
|
option=${option#q}
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
FAST=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
|
|
|
v*)
|
|
|
|
option=${option#v}
|
2007-11-23 22:49:06 +01:00
|
|
|
case $option in
|
|
|
|
-1*)
|
|
|
|
USE_VERBOSITY=-1
|
|
|
|
option=${option#-1}
|
|
|
|
;;
|
|
|
|
0*)
|
|
|
|
USE_VERBOSITY=0
|
|
|
|
option=${option#0}
|
|
|
|
;;
|
|
|
|
1*)
|
|
|
|
USE_VERBOSITY=1
|
|
|
|
option=${option#1}
|
|
|
|
;;
|
|
|
|
2*)
|
|
|
|
USE_VERBOSITY=2
|
|
|
|
option=${option#2}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
VERBOSE_OFFSET=$(($VERBOSE_OFFSET + 1 ))
|
|
|
|
USE_VERBOSITY=
|
|
|
|
;;
|
|
|
|
esac
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
t*)
|
|
|
|
TIMESTAMP=Yes
|
|
|
|
option=${option#t}
|
|
|
|
;;
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
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-lite
|
|
|
|
CONFDIR=/etc/shorewall-lite
|
2006-06-14 18:32:13 +02:00
|
|
|
export PRODUCT="Shorewall Lite"
|
2006-06-11 17:07:34 +02:00
|
|
|
|
2007-07-08 21:10:11 +02:00
|
|
|
[ -f ${CONFDIR}/vardir ] && . ${CONFDIR}/vardir ]
|
|
|
|
|
|
|
|
[ -n "${VARDIR:=/var/lib/shorewall-lite}" ]
|
|
|
|
|
2007-07-08 22:07:55 +02:00
|
|
|
[ -d $VARDIR ] || mkdir -p $VARDIR || fatal_error "Unable to create $VARDIR"
|
|
|
|
|
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
|
2006-06-03 17:16:21 +02:00
|
|
|
|
2006-10-28 16:46:43 +02:00
|
|
|
for library in $LIBRARIES; do
|
|
|
|
if [ -f $library ]; then
|
|
|
|
. $library
|
|
|
|
else
|
2006-11-21 22:50:56 +01:00
|
|
|
echo "Installation error: $library does not exist!" >&2
|
2006-10-28 16:46:43 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
ensure_config_path
|
|
|
|
|
2007-01-04 00:26:13 +01:00
|
|
|
config=$(find_file shorewall-lite.conf)
|
2007-01-02 22:25:35 +01:00
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
if [ -f $config ]; then
|
|
|
|
if [ -r $config ]; then
|
|
|
|
. $config
|
|
|
|
else
|
|
|
|
echo "Cannot read $config! (Hint: Are you root?)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$config does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
ensure_config_path
|
|
|
|
export CONFIG_PATH
|
|
|
|
|
2007-07-08 21:10:11 +02:00
|
|
|
LITEDIR=${VARDIR}
|
|
|
|
|
|
|
|
[ -f ${LITEDIR}/firewall.conf ] && . ${LITEDIR}/firewall.conf
|
2006-06-19 17:54:30 +02:00
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
get_config
|
|
|
|
|
2006-06-17 17:28:51 +02:00
|
|
|
FIREWALL=$LITEDIR/firewall
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
if [ -f $VERSION_FILE ]; then
|
|
|
|
version=$(cat $VERSION_FILE)
|
|
|
|
else
|
2006-06-12 18:48:07 +02:00
|
|
|
echo " ERROR: Shorewall Lite is not properly installed" >&2
|
|
|
|
echo " The file $VERSION_FILE does not exist" >&2
|
2006-06-03 17:16:21 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2006-06-12 18:11:32 +02:00
|
|
|
banner="Shorewall Lite $version Status at $HOSTNAME -"
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
case $(echo -e) in
|
|
|
|
-e*)
|
|
|
|
RING_BELL="echo \a"
|
2007-12-01 18:14:08 +01:00
|
|
|
ECHO_E="echo"
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
RING_BELL="echo -e \a"
|
2007-12-01 18:14:08 +01:00
|
|
|
ECHO_E="echo -e"
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $(echo -n "Testing") in
|
|
|
|
-n*)
|
|
|
|
ECHO_N=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ECHO_N=-n
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
COMMAND=$1
|
|
|
|
|
|
|
|
case "$COMMAND" in
|
|
|
|
start)
|
|
|
|
shift
|
|
|
|
start_command $@
|
|
|
|
;;
|
2008-12-17 18:40:44 +01:00
|
|
|
stop|clear)
|
2006-06-03 17:16:21 +02:00
|
|
|
[ $# -ne 1 ] && usage 1
|
2006-08-09 18:18:32 +02:00
|
|
|
verify_firewall_script
|
2006-06-03 17:16:21 +02:00
|
|
|
export NOROUTES
|
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $COMMAND
|
|
|
|
;;
|
2008-12-17 18:40:44 +01:00
|
|
|
reset)
|
|
|
|
verify_firewall_script
|
|
|
|
exec $SHOREWALL_SHELL $FIREWALL $debugging $nolock $@
|
|
|
|
;;
|
2006-06-03 17:16:21 +02:00
|
|
|
restart)
|
|
|
|
shift
|
2008-12-17 18:40:44 +01:00
|
|
|
restart_command
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
show|list)
|
|
|
|
shift
|
|
|
|
show_command $@
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
[ $# -eq 1 ] || usage 1
|
2006-06-12 18:11:32 +02:00
|
|
|
echo "Shorewall Lite $version Status at $HOSTNAME - $(date)"
|
2006-06-03 17:16:21 +02:00
|
|
|
echo
|
|
|
|
if shorewall_is_started ; then
|
2006-06-12 18:15:44 +02:00
|
|
|
echo "Shorewall Lite is running"
|
2006-06-03 17:16:21 +02:00
|
|
|
status=0
|
|
|
|
else
|
2006-06-12 18:15:44 +02:00
|
|
|
echo "Shorewall Lite is stopped"
|
2006-06-03 17:16:21 +02:00
|
|
|
status=4
|
|
|
|
fi
|
|
|
|
|
2006-06-09 18:36:12 +02:00
|
|
|
if [ -f ${VARDIR}/state ]; then
|
|
|
|
state="$(cat ${VARDIR}/state)"
|
2006-06-03 17:16:21 +02:00
|
|
|
case $state in
|
|
|
|
Stopped*|Clear*)
|
|
|
|
status=3
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
state=Unknown
|
|
|
|
fi
|
|
|
|
echo "State:$state"
|
|
|
|
echo
|
|
|
|
exit $status
|
|
|
|
;;
|
|
|
|
dump)
|
|
|
|
shift
|
|
|
|
dump_command $@
|
|
|
|
;;
|
|
|
|
hits)
|
|
|
|
[ -n "$debugging" ] && set -x
|
2007-11-16 00:24:54 +01:00
|
|
|
shift
|
|
|
|
hits_command $@
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
version)
|
2006-06-09 02:45:44 +02:00
|
|
|
echo $version Lite
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
logwatch)
|
2006-11-29 02:11:29 +01:00
|
|
|
logwatch_command $@
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
drop)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
2007-06-16 17:24:17 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2006-10-28 00:00:48 +02:00
|
|
|
block DROP Dropped $*
|
2007-06-16 17:24:17 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
2006-10-28 00:00:48 +02:00
|
|
|
error_message "ERROR: Shorewall Lite is not started"
|
2006-06-03 17:16:21 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
logdrop)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
2007-06-16 17:24:17 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2006-10-28 00:00:48 +02:00
|
|
|
block logdrop Dropped $*
|
2007-06-16 17:24:17 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
2006-10-28 00:00:48 +02:00
|
|
|
error_message "ERROR: Shorewall Lite is not started"
|
2006-06-03 17:16:21 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
reject|logreject)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
2007-06-16 17:24:17 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2006-10-28 00:00:48 +02:00
|
|
|
block $COMMAND Rejected $*
|
2007-06-16 17:24:17 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-06-03 17:16:21 +02:00
|
|
|
else
|
2006-10-28 00:00:48 +02:00
|
|
|
error_message "ERROR: Shorewall Lite is not started"
|
2006-06-03 17:16:21 +02:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
allow)
|
2006-11-29 01:53:39 +01:00
|
|
|
allow_command $@
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
2009-03-06 21:43:46 +01:00
|
|
|
add)
|
|
|
|
get_config
|
|
|
|
shift
|
|
|
|
add_command $@
|
|
|
|
;;
|
|
|
|
delete)
|
|
|
|
get_config
|
|
|
|
shift
|
|
|
|
add_command $@
|
|
|
|
;;
|
2006-06-03 17:16:21 +02:00
|
|
|
save)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-06-09 18:36:12 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
[ "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
save_config
|
|
|
|
|
|
|
|
[ "$nolock" ] || mutex_off
|
|
|
|
;;
|
|
|
|
forget)
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
2006-06-09 18:36:12 +02:00
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
2006-06-03 17:16:21 +02:00
|
|
|
|
|
|
|
if [ -x $RESTOREPATH ]; then
|
|
|
|
|
|
|
|
if [ -x ${RESTOREPATH}-ipsets ]; then
|
|
|
|
rm -f ${RESTOREPATH}-ipsets
|
|
|
|
echo " ${RESTOREPATH}-ipsets removed"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f $RESTOREPATH
|
|
|
|
rm -f ${RESTOREPATH}-iptables
|
|
|
|
echo " $RESTOREPATH removed"
|
|
|
|
elif [ -f $RESTOREPATH ]; then
|
|
|
|
echo " $RESTOREPATH exists and is not a saved Shorewall configuration"
|
|
|
|
fi
|
2006-06-09 18:36:12 +02:00
|
|
|
rm -f ${VARDIR}/save
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
ipcalc)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
address=${2%/*}
|
|
|
|
vlsm=${2#*/}
|
|
|
|
elif [ $# -eq 3 ]; then
|
|
|
|
address=$2
|
|
|
|
vlsm=$(ip_vlsm $3)
|
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
|
2006-12-21 22:10:18 +01:00
|
|
|
valid_address $address || fatal_error "Invalid IP address: $address"
|
2006-12-21 22:10:54 +01:00
|
|
|
[ -z "$vlsm" ] && exit 2
|
2006-06-03 17:16:21 +02:00
|
|
|
[ "x$address" = "x$vlsm" ] && usage 2
|
|
|
|
[ $vlsm -gt 32 ] && echo "Invalid VLSM: /$vlsm" >&2 && exit 2
|
|
|
|
|
|
|
|
address=$address/$vlsm
|
|
|
|
|
|
|
|
echo " CIDR=$address"
|
|
|
|
temp=$(ip_netmask $address); echo " NETMASK=$(encodeaddr $temp)"
|
|
|
|
temp=$(ip_network $address); echo " NETWORK=$temp"
|
|
|
|
temp=$(broadcastaddress $address); echo " BROADCAST=$temp"
|
|
|
|
;;
|
|
|
|
|
|
|
|
iprange)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
case $2 in
|
|
|
|
*.*.*.*-*.*.*.*)
|
2006-12-21 22:10:18 +01:00
|
|
|
for address in ${2%-*} ${2#*-}; do
|
|
|
|
valid_address $address || fatal_error "Invalid IP address: $address"
|
|
|
|
done
|
|
|
|
|
2006-06-03 17:16:21 +02:00
|
|
|
ip_range $2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
ipdecimal)
|
|
|
|
[ -n "$debugging" ] && set -x
|
2007-05-17 00:47:22 +02:00
|
|
|
[ $# -eq 2 ] || usage 1
|
2006-06-03 17:16:21 +02:00
|
|
|
case $2 in
|
|
|
|
*.*.*.*)
|
2006-12-21 22:10:18 +01:00
|
|
|
valid_address $2 || fatal_error "Invalid IP address: $2"
|
2006-06-03 17:16:21 +02:00
|
|
|
echo " $(decodeaddr $2)"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " $(encodeaddr $2)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
restore)
|
|
|
|
shift
|
2007-04-15 06:08:32 +02:00
|
|
|
STARTUP_ENABLED=Yes
|
2006-06-03 17:16:21 +02:00
|
|
|
restore_command $@
|
|
|
|
;;
|
|
|
|
call)
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
#
|
2006-06-09 18:36:12 +02:00
|
|
|
# Undocumented way to call functions in ${SHAREDIR}/functions directly
|
2006-06-03 17:16:21 +02:00
|
|
|
#
|
|
|
|
shift
|
|
|
|
$@
|
|
|
|
;;
|
|
|
|
help)
|
|
|
|
shift
|
2006-11-21 23:52:07 +01:00
|
|
|
usage
|
2006-06-03 17:16:21 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|