2008-12-07 19:17:26 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2009-02-22 17:54:19 +01:00
|
|
|
# Shorewall Packet Filtering Firewall Control Program - V4.4
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
|
|
|
|
#
|
2010-01-01 21:58:27 +01:00
|
|
|
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 - Tom Eastep (teastep@shorewall.net)
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# This file should be placed in /sbin/shorewall.
|
|
|
|
#
|
|
|
|
# Shorewall documentation is available at http://www.shorewall.net
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2009-09-20 15:10:23 +02:00
|
|
|
# For a list of supported commands, type 'shorewall help'
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
2009-09-20 15:10:23 +02:00
|
|
|
#####################################################################################################
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# Set the configuration variables from shorewall.conf
|
|
|
|
#
|
|
|
|
# $1 = Yes: read the params file
|
|
|
|
# $2 = Yes: check for STARTUP_ENABLED
|
|
|
|
# $3 = Yes: Check for LOGFILE
|
2010-06-07 18:16:56 +02:00
|
|
|
#
|
2008-12-07 19:17:26 +01:00
|
|
|
get_config() {
|
2009-04-18 20:48:28 +02:00
|
|
|
local prog
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
ensure_config_path
|
|
|
|
|
|
|
|
if [ "$1" = Yes ]; then
|
|
|
|
params=$(find_file params)
|
|
|
|
|
|
|
|
if [ -f $params ]; then
|
|
|
|
. $params
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
config=$(find_file shorewall.conf)
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2008-12-07 19:17:26 +01: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
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2010-02-22 17:05:23 +01:00
|
|
|
if [ -z "$g_export" -a "$(id -u)" = 0 ]; then
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# This block is avoided for compile for export and when the user isn't root
|
|
|
|
#
|
|
|
|
if [ "$3" = Yes ]; then
|
|
|
|
[ -z "$LOGFILE" ] && LOGFILE=/var/log/messages
|
|
|
|
|
|
|
|
if [ -n "$(syslog_circular_buffer)" ]; then
|
2010-02-24 02:00:26 +01:00
|
|
|
g_logread="logread | tac"
|
2009-12-04 01:16:13 +01:00
|
|
|
elif [ -r $LOGFILE ]; then
|
2010-02-24 02:00:26 +01:00
|
|
|
g_logread="tac $LOGFILE"
|
2008-12-07 19:17:26 +01:00
|
|
|
else
|
|
|
|
echo "LOGFILE ($LOGFILE) does not exist!" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$IPTABLES" ]; then
|
|
|
|
if [ ! -x "$IPTABLES" ]; then
|
|
|
|
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
|
|
|
|
|
2009-04-18 20:48:28 +02:00
|
|
|
if [ -n "$IP" ]; then
|
|
|
|
case "$IP" in
|
|
|
|
*/*)
|
|
|
|
if [ ! -x "$IP" ] ; then
|
|
|
|
echo " ERROR: The program specified in IP ($IP) does not exist or is not executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prog="$(mywhich $IP 2> /dev/null)"
|
|
|
|
if [ -z "$prog" ] ; then
|
|
|
|
echo " ERROR: Can't find $IP executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
IP=$prog
|
|
|
|
;;
|
|
|
|
esac
|
2010-06-07 18:16:56 +02:00
|
|
|
else
|
2009-04-18 20:48:28 +02:00
|
|
|
IP='ip'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$IPSET" ]; then
|
|
|
|
case "$IPSET" in
|
|
|
|
*/*)
|
|
|
|
if [ ! -x "$IPSET" ] ; then
|
|
|
|
echo " ERROR: The program specified in IPSET ($IPSET) does not exist or is not executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prog="$(mywhich $IPSET 2> /dev/null)"
|
|
|
|
if [ -z "$prog" ] ; then
|
|
|
|
echo " ERROR: Can't find $IPSET executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
IPSET=$prog
|
|
|
|
;;
|
|
|
|
esac
|
2010-06-07 18:16:56 +02:00
|
|
|
else
|
2009-04-18 20:48:28 +02:00
|
|
|
IPSET='ipset'
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$TC" ]; then
|
|
|
|
case "$TC" in
|
|
|
|
*/*)
|
|
|
|
if [ ! -x "$TC" ] ; then
|
|
|
|
echo " ERROR: The program specified in TC ($TC) does not exist or is not executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prog="$(mywhich $TC 2> /dev/null)"
|
|
|
|
if [ -z "$prog" ] ; then
|
|
|
|
echo " ERROR: Can't find $TC executable" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
TC=$prog
|
|
|
|
;;
|
|
|
|
esac
|
2010-06-07 18:16:56 +02:00
|
|
|
else
|
2009-04-18 20:48:28 +02:00
|
|
|
TC='tc'
|
|
|
|
fi
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# Compile by non-root needs no restore file
|
|
|
|
#
|
|
|
|
[ -n "$RESTOREFILE" ] || RESTOREFILE=restore
|
|
|
|
|
|
|
|
validate_restorefile RESTOREFILE
|
|
|
|
|
|
|
|
if [ "$2" = Yes ]; then
|
|
|
|
case $STARTUP_ENABLED in
|
|
|
|
No|no|NO)
|
|
|
|
echo " ERROR: Shorewall startup is disabled. To enable startup, set STARTUP_ENABLED=Yes in ${CONFDIR}/shorewall.conf" >&2
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
Yes|yes|YES)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$STARTUP_ENABLED" ]; then
|
2009-09-25 19:36:45 +02:00
|
|
|
echo " ERROR: Invalid Value for STARTUP_ENABLED: $STARTUP_ENABLED" >&2
|
2008-12-07 19:17:26 +01:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2009-02-22 17:54:19 +01:00
|
|
|
case ${SHOREWALL_COMPILER:=perl} in
|
|
|
|
perl|Perl)
|
|
|
|
;;
|
|
|
|
shell|Shell)
|
2009-08-09 17:19:24 +02:00
|
|
|
echo " WARNING: SHOREWALL_COMPILER=shell ignored. Shorewall-shell support has been removed in this release" >&2
|
2009-02-22 17:54:19 +01:00
|
|
|
;;
|
|
|
|
*)
|
2009-04-07 05:22:02 +02:00
|
|
|
echo " ERROR: Invalid value ($SHOREWALL_COMPILER) for SHOREWALL_COMPILER" >&2
|
2009-02-22 17:54:19 +01:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
case ${TC_ENABLED:=Internal} in
|
|
|
|
No|NO|no)
|
|
|
|
TC_ENABLED=
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-06-07 18:16:56 +02:00
|
|
|
[ -z "$LOGFORMAT" ] && LOGFORMAT='Shorewall:%s.%s'
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2009-08-07 22:33:07 +02:00
|
|
|
[ -n "$LOGFORMAT" ] && LOGFORMAT="${LOGFORMAT%%%*}"
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
if [ -n "$STARTUP_LOG" ]; then
|
|
|
|
if [ -n "$LOG_VERBOSITY" ]; then
|
|
|
|
case $LOG_VERBOSITY in
|
|
|
|
-1)
|
|
|
|
;;
|
|
|
|
0|1|2)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " ERROR: Invalid LOG_VERBOSITY ($LOG_VERBOSITY)" >&2
|
|
|
|
exit 2;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
LOG_VERBOSITY=2;
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
LOG_VERBOSITY=-1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
STARTUP_LOG=
|
|
|
|
LOG_VERBOSITY=-1
|
2010-06-07 18:16:56 +02:00
|
|
|
fi
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
if [ -n "$SHOREWALL_SHELL" ]; then
|
|
|
|
if [ ! -x "$SHOREWALL_SHELL" ]; then
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $VERBOSITY in
|
|
|
|
-1|0|1|2)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$VERBOSITY" ]; then
|
|
|
|
echo " ERROR: Invalid VERBOSITY setting ($VERBOSITY)" >&2
|
|
|
|
exit 2
|
|
|
|
else
|
|
|
|
VERBOSITY=2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-03-01 02:58:01 +01:00
|
|
|
[ -n "$g_use_verbosity" ] && VERBOSITY=$g_use_verbosity || VERBOSITY=$(($g_verbose_offset + $VERBOSITY))
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-03-01 02:58:01 +01:00
|
|
|
if [ $VERBOSITY -lt -1 ]; then
|
|
|
|
VERBOSITY=-1
|
|
|
|
elif [ $VERBOSITY -gt 2 ]; then
|
|
|
|
VERBOSITY=2
|
2008-12-07 19:17:26 +01:00
|
|
|
fi
|
|
|
|
|
2010-03-02 20:59:38 +01:00
|
|
|
g_hostname=$(hostname 2> /dev/null)
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
[ -n "$RSH_COMMAND" ] || RSH_COMMAND='ssh ${root}@${system} ${command}'
|
|
|
|
[ -n "$RCP_COMMAND" ] || RCP_COMMAND='scp ${files} ${root}@${system}:${destination}'
|
|
|
|
|
|
|
|
case $MANGLE_ENABLED in
|
|
|
|
Yes|yes)
|
|
|
|
;;
|
|
|
|
No|no)
|
|
|
|
MANGLE_ENABLED=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$MANGLE_ENABLED" ]; then
|
|
|
|
echo " ERROR: Invalid MANGLE_ENABLED setting ($MANGLE_ENABLED)" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2009-02-21 18:21:51 +01:00
|
|
|
|
2009-03-31 19:31:23 +02:00
|
|
|
case $AUTOMAKE in
|
|
|
|
Yes|yes)
|
|
|
|
;;
|
|
|
|
No|no)
|
|
|
|
AUTOMAKE=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$AUTOMAKE" ]; then
|
|
|
|
echo " ERROR: Invalid AUTOMAKE setting ($AUTOMAKE)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2010-01-21 19:30:54 +01:00
|
|
|
|
|
|
|
case $LOAD_HELPERS_ONLY in
|
|
|
|
Yes|yes)
|
|
|
|
;;
|
|
|
|
No|no)
|
|
|
|
LOAD_HELPERS_ONLY=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$LOAD_HELPERS_ONLY" ]; then
|
|
|
|
echo " ERROR: Invalid LOAD_HELPERS_ONLY setting ($LOAD_HELPERS_ONLY)" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2008-12-07 19:17:26 +01:00
|
|
|
}
|
|
|
|
|
2010-04-07 22:28:07 +02:00
|
|
|
#
|
|
|
|
# Fatal error
|
|
|
|
#
|
|
|
|
startup_error() {
|
|
|
|
echo " ERROR: $@" >&2
|
|
|
|
kill $$
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
2009-02-22 17:54:19 +01:00
|
|
|
# Run the compiler
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
compiler() {
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
if [ $(id -u) -ne 0 ]; then
|
|
|
|
if [ -z "$SHOREWALL_DIR" -o "$SHOREWALL_DIR" = /etc/shorewall ]; then
|
|
|
|
startup_error "Ordinary users may not compile the /etc/shorewall configuration"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# We've now set SHOREWALL_DIR so recalculate CONFIG_PATH
|
|
|
|
#
|
|
|
|
ensure_config_path
|
|
|
|
|
|
|
|
case $COMMAND in
|
|
|
|
*start|try|refresh)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
STARTUP_LOG=
|
|
|
|
LOG_VERBOSITY=-1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-02-22 17:54:19 +01:00
|
|
|
debugflags="-w"
|
2010-02-22 17:05:23 +01:00
|
|
|
[ -n "$g_debug" ] && debugflags='-wd'
|
|
|
|
[ -n "$g_profile" ] && debugflags='-wd:DProf'
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2009-02-22 17:54:19 +01:00
|
|
|
# Perl compiler only takes the output file as a argument
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2009-02-22 17:54:19 +01:00
|
|
|
[ "$1" = debug -o "$1" = trace ] && shift;
|
|
|
|
[ "$1" = nolock ] && shift;
|
2010-06-07 18:16:56 +02:00
|
|
|
shift
|
2009-02-22 17:54:19 +01:00
|
|
|
|
2010-03-01 02:58:01 +01:00
|
|
|
options="--verbose=$VERBOSITY"
|
2009-02-22 17:54:19 +01:00
|
|
|
[ -n "$STARTUP_LOG" ] && options="$options --log=$STARTUP_LOG"
|
|
|
|
[ -n "$LOG_VERBOSITY" ] && options="$options --log_verbosity=$LOG_VERBOSITY";
|
2010-02-22 17:05:23 +01:00
|
|
|
[ -n "$g_export" ] && options="$options --export"
|
2009-02-22 17:54:19 +01:00
|
|
|
[ -n "$SHOREWALL_DIR" ] && options="$options --directory=$SHOREWALL_DIR"
|
2010-03-03 18:50:07 +01:00
|
|
|
[ -n "$g_timestamp" ] && options="$options --timestamp"
|
2010-02-22 17:05:23 +01:00
|
|
|
[ -n "$g_test" ] && options="$options --test"
|
2010-02-27 02:05:35 +01:00
|
|
|
[ -n "$g_preview" ] && options="$options --preview"
|
2010-02-23 01:43:38 +01:00
|
|
|
[ "$g_debugging" = trace ] && options="$options --debug"
|
2010-02-22 17:05:23 +01:00
|
|
|
[ -n "$g_refreshchains" ] && options="$options --refresh=$g_refreshchains"
|
2009-02-22 17:54:19 +01:00
|
|
|
#
|
|
|
|
# Run the appropriate params file
|
|
|
|
#
|
2010-06-07 18:16:56 +02:00
|
|
|
set -a;
|
2009-02-22 17:54:19 +01:00
|
|
|
run_user_exit params
|
|
|
|
set +a
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-07-05 22:11:52 +02:00
|
|
|
if [ -n "$PERL" ]; then
|
|
|
|
if [ ! -x "$PERL" ]; then
|
|
|
|
echo " WARNING: The program specified in the PERL option does not exist or is not executable; falling back to /usr/bin/perl" >&2
|
|
|
|
PERL=/usr/bin/perl
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
PERL=/usr/bin/perl
|
|
|
|
fi
|
|
|
|
|
|
|
|
$PERL $debugflags /usr/share/shorewall/compiler.pl $options $@
|
2010-03-03 01:03:44 +01:00
|
|
|
}
|
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# Start Command Executor
|
|
|
|
#
|
|
|
|
start_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
2009-03-31 20:54:00 +02:00
|
|
|
local restorefile
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
do_it() {
|
|
|
|
local rc
|
|
|
|
rc=0
|
|
|
|
|
2009-03-31 19:31:23 +02:00
|
|
|
if [ -n "$AUTOMAKE" ]; then
|
2008-12-07 19:17:26 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2010-03-03 01:03:44 +01:00
|
|
|
run_it ${VARDIR}/firewall $g_debugging start
|
2008-12-07 19:17:26 +01:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
2009-03-31 19:31:23 +02:00
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if compiler $g_debugging $nolock compile ${VARDIR}/.start; then
|
2009-03-31 19:31:23 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2010-03-03 01:03:44 +01:00
|
|
|
run_it ${VARDIR}/.start $g_debugging start
|
2009-03-31 19:31:23 +02:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
rc=$?
|
|
|
|
logger -p kern.err "ERROR:Shorewall start failed"
|
|
|
|
fi
|
2008-12-07 19:17:26 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit $rc
|
|
|
|
}
|
|
|
|
|
|
|
|
if shorewall_is_started; then
|
|
|
|
error_message "Shorewall is already running"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$STARTUP_ENABLED" ] || fatal_error "Startup is disabled"
|
|
|
|
|
|
|
|
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=
|
|
|
|
;;
|
|
|
|
d*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_debug=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
f*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_fast=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#f}
|
|
|
|
;;
|
|
|
|
p*)
|
|
|
|
[ -n "$(which conntrack)" ] || fatal_error "The '-p' option requires the conntrack utility which does not appear to be installed on this system"
|
2010-03-03 18:50:07 +01:00
|
|
|
g_purge=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option%p}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
2010-02-22 17:05:23 +01:00
|
|
|
[ -n "$SHOREWALL_DIR" -o -n "$g_fast" ] && usage 2
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2009-04-02 16:24:23 +02:00
|
|
|
AUTOMAKE=
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-02-22 17:05:23 +01:00
|
|
|
if [ -n "${g_fast}${AUTOMAKE}" ]; then
|
2008-12-07 19:17:26 +01:00
|
|
|
if qt mywhich make; then
|
2009-03-31 20:54:00 +02:00
|
|
|
restorefile=$RESTOREFILE
|
|
|
|
|
2010-02-22 17:05:23 +01:00
|
|
|
if [ -z "$g_fast" ]; then
|
2009-03-31 19:31:23 +02:00
|
|
|
#
|
2009-05-11 16:04:08 +02:00
|
|
|
# Automake -- use the last compiled script
|
2009-03-31 19:31:23 +02:00
|
|
|
#
|
|
|
|
RESTOREFILE=firewall
|
|
|
|
fi
|
|
|
|
|
2010-03-03 01:03:44 +01:00
|
|
|
export RESTOREFILE
|
|
|
|
|
2010-08-14 16:32:53 +02:00
|
|
|
if ! make -qf ${CONFDIR}/Makefile; then
|
2010-03-03 01:03:44 +01:00
|
|
|
g_fast=
|
2009-03-31 19:31:23 +02:00
|
|
|
AUTOMAKE=
|
|
|
|
fi
|
2009-03-31 20:54:00 +02:00
|
|
|
|
|
|
|
RESTOREFILE=$restorefile
|
2009-03-31 19:31:23 +02:00
|
|
|
else
|
2010-02-22 17:05:23 +01:00
|
|
|
g_fast=
|
2009-03-31 19:31:23 +02:00
|
|
|
AUTOMAKE=
|
2008-12-07 19:17:26 +01:00
|
|
|
fi
|
|
|
|
|
2010-02-22 17:05:23 +01:00
|
|
|
if [ -n "$g_fast" ]; then
|
2010-02-26 17:35:50 +01:00
|
|
|
g_restorepath=${VARDIR}/$RESTOREFILE
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-02-26 17:35:50 +01:00
|
|
|
if [ -x $g_restorepath ]; then
|
2008-12-07 19:17:26 +01:00
|
|
|
echo Restoring Shorewall...
|
2010-03-03 01:03:44 +01:00
|
|
|
run_it $g_restorepath restore
|
2008-12-07 19:17:26 +01:00
|
|
|
date > ${VARDIR}/restarted
|
2010-02-26 17:35:50 +01:00
|
|
|
progress_message3 Shorewall restored from $g_restorepath
|
2008-12-07 19:17:26 +01:00
|
|
|
else
|
|
|
|
do_it
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
do_it
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
do_it
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Compile Command Executor
|
|
|
|
#
|
|
|
|
compile_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 ]; do
|
2009-04-02 03:12:34 +02:00
|
|
|
[ $# -eq 0 ] && break
|
2008-12-07 19:17:26 +01:00
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
shift
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
[ -z "$option" ] && usage 1
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
e*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_export=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
p*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_profile=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#p}
|
|
|
|
;;
|
|
|
|
t*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_test=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#t}
|
2010-06-07 18:16:56 +02:00
|
|
|
;;
|
2008-12-07 19:17:26 +01:00
|
|
|
d*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_debug=Yes;
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
file=
|
|
|
|
|
|
|
|
case $# in
|
2009-04-02 03:12:34 +02:00
|
|
|
0)
|
|
|
|
file=${VARDIR}/firewall
|
|
|
|
;;
|
2008-12-07 19:17:26 +01:00
|
|
|
1)
|
|
|
|
file=$1
|
|
|
|
[ -d $file ] && echo " ERROR: $file is a directory" >&2 && exit 2;
|
|
|
|
;;
|
|
|
|
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
|
|
|
|
|
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
|
|
|
file=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-08-03 23:49:51 +02:00
|
|
|
[ "x$file" = x- ] || progress_message3 "Compiling..."
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
compiler $g_debugging compile $file
|
2008-12-07 19:17:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Check Command Executor
|
|
|
|
#
|
|
|
|
check_command() {
|
|
|
|
local finished
|
|
|
|
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=
|
|
|
|
;;
|
|
|
|
e*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_export=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
p*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_profile=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#p}
|
|
|
|
;;
|
|
|
|
d*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_debug=Yes;
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#d}
|
|
|
|
;;
|
2010-01-13 00:32:50 +01:00
|
|
|
r*)
|
2010-02-27 02:05:35 +01:00
|
|
|
g_preview=Yes;
|
2010-01-13 00:32:50 +01:00
|
|
|
option=${option#r}
|
|
|
|
;;
|
2008-12-07 19:17:26 +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
|
|
|
|
|
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
progress_message3 "Checking..."
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
compiler $g_debugging $nolock check
|
2008-12-07 19:17:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Restart Command Executor
|
|
|
|
#
|
|
|
|
restart_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local rc
|
|
|
|
rc=0
|
2009-03-31 20:54:00 +02:00
|
|
|
local restorefile
|
2008-12-07 19:17:26 +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=
|
|
|
|
;;
|
|
|
|
d*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_debug=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
f*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_fast=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#f}
|
|
|
|
;;
|
|
|
|
n*)
|
2010-03-03 18:50:07 +01:00
|
|
|
g_noroutes=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
p*)
|
|
|
|
[ -n "$(which conntrack)" ] || fatal_error "The '-p' option requires the conntrack utility which does not appear to be installed on this system"
|
2010-03-03 18:50:07 +01:00
|
|
|
g_purge=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option%p}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
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
|
|
|
|
|
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
2010-02-22 17:05:23 +01:00
|
|
|
[ -n "$g_fast" ] && fatal_error "Directory may not be specified with the -f option"
|
2009-04-02 16:24:23 +02:00
|
|
|
AUTOMAKE=
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$STARTUP_ENABLED" ] || fatal_error "Startup is disabled"
|
|
|
|
|
2010-02-22 17:05:23 +01:00
|
|
|
if [ -z "$g_fast" -a -n "$AUTOMAKE" ]; then
|
2009-03-31 20:54:00 +02:00
|
|
|
if qt mywhich make; then
|
|
|
|
#
|
|
|
|
# RESTOREFILE is exported by get_config()
|
|
|
|
#
|
|
|
|
restorefile=$RESTOREFILE
|
|
|
|
RESTOREFILE=firewall
|
2010-02-22 17:05:23 +01:00
|
|
|
make -qf ${CONFDIR}/Makefile && g_fast=Yes
|
2009-03-31 20:54:00 +02:00
|
|
|
RESTOREFILE=$restorefile
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-06-07 18:16:56 +02:00
|
|
|
if [ -z "$g_fast" ]; then
|
2009-03-31 20:54:00 +02:00
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if compiler $g_debugging $nolock compile ${VARDIR}/.restart; then
|
2009-03-31 20:54:00 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2010-03-03 01:03:44 +01:00
|
|
|
run_it ${VARDIR}/.restart $g_debugging restart
|
2009-03-31 20:54:00 +02:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
rc=$?
|
|
|
|
logger -p kern.err "ERROR:Shorewall restart failed"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
[ -x ${VARDIR}/firewall ] || fatal_error "No ${VARDIR}/firewall file found"
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
2010-03-03 01:03:44 +01:00
|
|
|
run_it ${VARDIR}/firewall $g_debugging restart
|
2009-03-31 20:54:00 +02:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
fi
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2009-03-31 20:54:00 +02:00
|
|
|
return $rc
|
2008-12-07 19:17:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Refresh Command Executor
|
|
|
|
#
|
|
|
|
refresh_command() {
|
|
|
|
local finished
|
|
|
|
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
|
|
|
|
|
|
|
|
if [ $# -gt 0 ]; then
|
2010-02-22 17:05:23 +01:00
|
|
|
g_refreshchains=$1
|
2008-12-07 19:17:26 +01:00
|
|
|
shift
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
2010-02-22 17:05:23 +01:00
|
|
|
g_refreshchains="$g_refreshchains,$1"
|
2008-12-07 19:17:26 +01:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
shorewall_is_started || fatal_error "Shorewall is not running"
|
|
|
|
|
|
|
|
[ -n "$STARTUP_ENABLED" ] || fatal_error "Startup is disabled"
|
|
|
|
|
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if compiler $g_debugging $nolock compile ${VARDIR}/.refresh; then
|
2008-12-07 19:17:26 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2010-03-03 01:03:44 +01:00
|
|
|
run_it ${VARDIR}/.refresh $g_debugging refresh
|
2008-12-07 19:17:26 +01:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
rc=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Safe-start/safe-restart Command Executor
|
|
|
|
#
|
|
|
|
safe_commands() {
|
|
|
|
local finished
|
|
|
|
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*)
|
2010-03-03 18:50:07 +01:00
|
|
|
g_noroutes=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$STARTUP_ENABLED" ] || fatal_error "Startup is disabled"
|
|
|
|
|
|
|
|
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"
|
|
|
|
exit 0
|
|
|
|
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
|
|
|
|
|
|
|
|
progress_message3 "Compiling..."
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if ! compiler $g_debugging nolock compile ${VARDIR}/.$command; then
|
2008-12-07 19:17:26 +01:00
|
|
|
status=$?
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $command in
|
|
|
|
start)
|
2010-03-03 01:03:44 +01:00
|
|
|
RESTOREFILE=NONE
|
2008-12-07 19:17:26 +01:00
|
|
|
progress_message3 "Starting..."
|
|
|
|
;;
|
|
|
|
restart)
|
2010-03-03 01:03:44 +01:00
|
|
|
RESTOREFILE=.safe
|
2010-02-26 17:35:50 +01:00
|
|
|
g_restorepath=${VARDIR}/.safe
|
2008-12-07 19:17:26 +01:00
|
|
|
save_config
|
|
|
|
progress_message3 "Restarting..."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if ${VARDIR}/.$command $g_debugging $command; then
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
echo -n "Do you want to accept the new firewall configuration? [y/n] "
|
|
|
|
|
|
|
|
if read_yesno_with_timeout; then
|
|
|
|
echo "New configuration has been accepted"
|
|
|
|
else
|
|
|
|
if [ "$command" = "restart" ]; then
|
|
|
|
${VARDIR}/.safe restore
|
|
|
|
else
|
|
|
|
${VARDIR}/.$command clear
|
|
|
|
fi
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
|
|
|
|
echo "New configuration has been rejected and the old one restored"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# 'try' Command Executor
|
|
|
|
#
|
|
|
|
try_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local timeout
|
|
|
|
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
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
SHOREWALL_DIR=$(resolve_file $1)
|
|
|
|
}
|
|
|
|
|
|
|
|
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*)
|
2010-03-03 18:50:07 +01:00
|
|
|
g_noroutes=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
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
|
2010-06-07 18:16:56 +02:00
|
|
|
case $timeout in
|
2008-12-07 19:17:26 +01:00
|
|
|
*[!0-9]*)
|
|
|
|
echo " ERROR: Invalid timeout ($timeout)" >&2;
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$STARTUP_ENABLED" ] || fatal_error "Startup is disabled"
|
|
|
|
|
|
|
|
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..."
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if ! compiler $g_debugging $nolock compile ${VARDIR}/.$command; then
|
2008-12-07 19:17:26 +01:00
|
|
|
status=$?
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $command in
|
|
|
|
start)
|
2010-03-03 01:03:44 +01:00
|
|
|
RESTOREFILE=NONE
|
2008-12-07 19:17:26 +01:00
|
|
|
progress_message3 "Starting..."
|
|
|
|
;;
|
|
|
|
restart)
|
2010-03-03 01:03:44 +01:00
|
|
|
RESTOREFILE=.try
|
2010-02-26 17:35:50 +01:00
|
|
|
g_restorepath=${VARDIR}/.try
|
2008-12-07 19:17:26 +01:00
|
|
|
save_config
|
|
|
|
progress_message3 "Restarting..."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
if ${VARDIR}/.$command $command && [ -n "$timeout" ]; then
|
|
|
|
sleep $timeout
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
if [ "$command" = "restart" ]; then
|
|
|
|
${VARDIR}/.try restore
|
|
|
|
else
|
|
|
|
${VARDIR}/.$command clear
|
2010-06-07 18:16:56 +02:00
|
|
|
fi
|
2008-12-07 19:17:26 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
rsh_command() {
|
|
|
|
command="$*"
|
|
|
|
|
|
|
|
eval $RSH_COMMAND
|
|
|
|
}
|
|
|
|
|
|
|
|
rcp_command() {
|
|
|
|
files="$1"
|
|
|
|
destination=$2
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
eval $RCP_COMMAND
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# [Re]load command executor
|
|
|
|
#
|
|
|
|
reload_command() # $* = original arguments less the command.
|
|
|
|
{
|
|
|
|
local verbose
|
|
|
|
verbose=$(make_verbose)
|
|
|
|
local file
|
|
|
|
file=
|
|
|
|
local capabilities
|
|
|
|
capabilities=
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local saveit
|
|
|
|
saveit=
|
|
|
|
local result
|
|
|
|
local directory
|
|
|
|
local system
|
|
|
|
local getcaps
|
|
|
|
getcaps=
|
|
|
|
local root
|
|
|
|
root=root
|
|
|
|
|
2010-02-27 02:05:35 +01:00
|
|
|
litedir=/var/lib/shorewall-lite
|
2008-12-07 19:17:26 +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=
|
|
|
|
;;
|
|
|
|
s*)
|
|
|
|
saveit=Yes
|
|
|
|
option=${option#s}
|
|
|
|
;;
|
|
|
|
c*)
|
|
|
|
getcaps=Yes
|
|
|
|
option=${option#c}
|
|
|
|
;;
|
|
|
|
r)
|
|
|
|
[ $# -gt 1 ] || fatal_error "Missing Root User name"
|
|
|
|
root=$2
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
directory="."
|
|
|
|
system=$1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
directory=$1
|
|
|
|
system=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-03-03 02:16:11 +01:00
|
|
|
temp=$(rsh_command /sbin/shorewall-lite show config 2> /dev/null | grep ^LITEDIR | sed 's/LITEDIR is //')
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-03-03 02:16:11 +01:00
|
|
|
[ -n "$temp" ] && litedir="$temp"
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
if [ -z "$getcaps" ]; then
|
|
|
|
SHOREWALL_DIR=$(resolve_file $directory)
|
|
|
|
ensure_config_path
|
|
|
|
capabilities=$(find_file capabilities)
|
|
|
|
[ -f $capabilities ] || getcaps=Yes
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$getcaps" ]; then
|
|
|
|
if [ -f $directory/shorewall.conf ]; then
|
|
|
|
. $directory/shorewall.conf
|
|
|
|
ensure_config_path
|
|
|
|
fi
|
|
|
|
|
2009-12-07 23:44:46 +01:00
|
|
|
[ -n "$DONT_LOAD" ] && DONT_LOAD="$(echo $DONT_LOAD | tr ',' ' ')"
|
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
progress_message "Getting Capabilities on system $system..."
|
2009-12-07 23:44:46 +01:00
|
|
|
if ! rsh_command "MODULESDIR=$MODULESDIR MODULE_SUFFIX=\"$MODULE_SUFFIX\" IPTABLES=$IPTABLES DONT_LOAD=\"$DONT_LOAD\" /usr/share/shorewall-lite/shorecap" > $directory/capabilities; then
|
2008-12-07 19:17:26 +01:00
|
|
|
fatal_error "ERROR: Capturing capabilities on system $system failed"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
file=$(resolve_file $directory/firewall)
|
|
|
|
|
2010-03-03 18:50:07 +01:00
|
|
|
[ -n "$g_timestamp" ] && timestamp='-t' || timestamp=
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if shorewall $g_debugging $verbose $timestamp compile -e $directory $directory/firewall && \
|
2010-02-27 02:05:35 +01:00
|
|
|
progress_message3 "Copying $file and ${file}.conf to ${system}:${litedir}..." && \
|
|
|
|
rcp_command "$directory/firewall $directory/firewall.conf" ${litedir}
|
2008-12-07 19:17:26 +01:00
|
|
|
then
|
|
|
|
save=$(find_file save);
|
|
|
|
|
|
|
|
[ -f $save ] && progress_message3 "Copying $save to ${system}:/etc/shorewall-lite/" && rcp_command $save /etc/shorewall-lite/
|
|
|
|
|
|
|
|
progress_message3 "Copy complete"
|
|
|
|
if [ $COMMAND = reload ]; then
|
2010-02-23 01:43:38 +01:00
|
|
|
rsh_command "/sbin/shorewall-lite $g_debugging $verbose $timestamp restart" && \
|
2008-12-07 19:17:26 +01:00
|
|
|
progress_message3 "System $system reloaded" || saveit=
|
|
|
|
else
|
2010-02-23 01:43:38 +01:00
|
|
|
rsh_command "/sbin/shorewall-lite $g_debugging $verbose $timestamp start" && \
|
2008-12-07 19:17:26 +01:00
|
|
|
progress_message3 "System $system loaded" || saveit=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$saveit" ]; then
|
2010-02-23 01:43:38 +01:00
|
|
|
rsh_command "/sbin/shorewall-lite $g_debugging $verbose $timestamp save" && \
|
2008-12-07 19:17:26 +01:00
|
|
|
progress_message3 "Configuration on system $system saved"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Export command executor
|
|
|
|
#
|
|
|
|
export_command() # $* = original arguments less the command.
|
|
|
|
{
|
|
|
|
local verbose
|
2010-06-07 18:16:56 +02:00
|
|
|
verbose=$(make_verbose)
|
2008-12-07 19:17:26 +01:00
|
|
|
local file
|
2010-06-07 18:16:56 +02:00
|
|
|
file=
|
2008-12-07 19:17:26 +01:00
|
|
|
local finished
|
2010-06-07 18:16:56 +02:00
|
|
|
finished=0
|
|
|
|
local directory
|
2008-12-07 19:17:26 +01:00
|
|
|
local 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=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_error "Unrecognized option \"$option\""
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
directory="."
|
|
|
|
target=$1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
directory=$1
|
|
|
|
target=$2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_error "ERROR: Invalid command syntax (\"man shorewall\" for help)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $target in
|
|
|
|
*:*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
target=$target:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
file=$(resolve_file $directory/firewall)
|
|
|
|
|
2010-02-23 01:43:38 +01:00
|
|
|
if shorewall $g_debugging $verbose compile -e $directory $directory/firewall && \
|
2008-12-07 19:17:26 +01:00
|
|
|
echo "Copying $file and ${file}.conf to ${target#*@}..." && \
|
|
|
|
scp $directory/firewall $directory/firewall.conf $target
|
|
|
|
then
|
|
|
|
save=$(find_file save);
|
|
|
|
|
|
|
|
[ -f $save ] && progress_message3 "Copying $save to ${target#*}..." && rcp_command $save $target
|
|
|
|
|
|
|
|
progress_message3 "Copy complete"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
|
|
|
usage() # $1 = exit status
|
|
|
|
{
|
|
|
|
echo "Usage: $(basename $0) [debug|trace] [nolock] [ -q ] [ -v[-1|{0-2}] ] [ -t ] <command>"
|
|
|
|
echo "where <command> is one of:"
|
2009-03-06 18:00:38 +01:00
|
|
|
echo " add <interface>[:<host-list>] ... <zone>"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " allow <address> ..."
|
2010-01-13 00:32:50 +01:00
|
|
|
echo " check [ -e ] [ -r ] [ <directory> ]"
|
2010-05-14 01:39:01 +02:00
|
|
|
echo " clear"
|
2009-04-02 03:12:34 +02:00
|
|
|
echo " compile [ -e ] [ -d ] [ <directory name> ] [ <path name> ]"
|
2009-03-06 18:00:38 +01:00
|
|
|
echo " delete <interface>[:<host-list>] ... <zone>"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " drop <address> ..."
|
|
|
|
echo " dump [ -x ]"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " export [ <directory1> ] [<user>@]<system>[:<directory2>]"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " forget [ <file name> ]"
|
|
|
|
echo " help"
|
|
|
|
echo " hits [ -t ]"
|
|
|
|
echo " ipcalc { <address>/<vlsm> | <address> <netmask> }"
|
|
|
|
echo " ipdecimal { <address> | <integer> }"
|
|
|
|
echo " iprange <address>-<address>"
|
2009-06-17 21:03:05 +02:00
|
|
|
echo " iptrace <iptables match expression>"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " load [ -s ] [ -c ] [ -r <root user> ] [ <directory> ] <system>"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " logdrop <address> ..."
|
|
|
|
echo " logreject <address> ..."
|
|
|
|
echo " logwatch [<refresh interval>]"
|
2009-06-17 21:03:05 +02:00
|
|
|
echo " noiptrace <iptables match expression>"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " refresh [ <chain>... ]"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " reject <address> ..."
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " reload [ -s ] [ -c ] [ -r <root user> ] [ <directory> ] <system>"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " reset [ <chain> ... ]"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " restart [ -n ] [ -p ] [ -f ] [ <directory> ]"
|
2008-12-07 19:17:26 +01: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 actions"
|
|
|
|
echo " show [ -f ] capabilities"
|
|
|
|
echo " show classifiers"
|
|
|
|
echo " show config"
|
|
|
|
echo " show connections"
|
|
|
|
echo " show dynamic <zone>"
|
2009-12-27 20:56:38 +01:00
|
|
|
echo " show filters"
|
2009-03-06 21:43:46 +01:00
|
|
|
echo " show ip"
|
2010-04-19 22:02:21 +02:00
|
|
|
echo " show [ -m ] log [<regex>]"
|
2010-01-12 22:12:01 +01:00
|
|
|
echo " show macro <macro>"
|
2009-03-06 21:43:46 +01:00
|
|
|
echo " show macros"
|
|
|
|
echo " show [ -x ] mangle|nat|raw|routing"
|
2009-11-15 18:24:56 +01:00
|
|
|
echo " show policies"
|
2010-01-18 01:18:44 +01:00
|
|
|
echo " show tc [ device ]"
|
2009-03-06 21:43:46 +01:00
|
|
|
echo " show vardir"
|
|
|
|
echo " show zones"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " start [ -f ] [ -n ] [ -p ] [ <directory> ]"
|
2010-05-14 01:39:01 +02:00
|
|
|
echo " stop"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " status"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " try <directory> [ <timeout> ]"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo " version [ -a ]"
|
2009-02-22 17:54:19 +01:00
|
|
|
echo " safe-start [ <directory> ]"
|
|
|
|
echo " safe-restart [ <directory> ]"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Execution begins here
|
|
|
|
#
|
2010-02-23 01:43:38 +01:00
|
|
|
g_debugging=
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "x$1" = "xdebug" -o "x$1" = "xtrace" ]; then
|
2010-02-23 01:43:38 +01:00
|
|
|
g_debugging=$1
|
2008-12-07 19:17:26 +01:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
nolock=
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "nolock" ]; then
|
|
|
|
nolock=nolock
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHOREWALL_DIR=
|
2010-03-03 18:50:07 +01:00
|
|
|
g_noroutes=
|
|
|
|
g_purge=
|
2010-02-22 17:05:23 +01:00
|
|
|
|
|
|
|
g_ipt_options="-nv"
|
|
|
|
g_fast=
|
|
|
|
g_verbose_offset=0
|
|
|
|
g_use_verbosity=
|
|
|
|
g_debug=
|
|
|
|
g_export=
|
|
|
|
g_refreshchains=
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 ]; do
|
|
|
|
[ $# -eq 0 ] && usage 1
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
SHOREWALL_DIR=$(resolve_file $2)
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
e*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_export=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
x*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_ipt_options="-xnv"
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#x}
|
|
|
|
;;
|
|
|
|
q*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_verbose_offset=$(($g_verbose_offset - 1 ))
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#q}
|
|
|
|
;;
|
|
|
|
f*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_fast=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#f}
|
|
|
|
;;
|
|
|
|
v*)
|
|
|
|
option=${option#v}
|
2010-06-07 18:16:56 +02:00
|
|
|
case $option in
|
2008-12-07 19:17:26 +01:00
|
|
|
-1*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_use_verbosity=-1
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#-1}
|
|
|
|
;;
|
|
|
|
0*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_use_verbosity=0
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#0}
|
|
|
|
;;
|
|
|
|
1*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_use_verbosity=1
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#1}
|
|
|
|
;;
|
|
|
|
2*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_use_verbosity=2
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#2}
|
|
|
|
;;
|
|
|
|
*)
|
2010-02-22 17:05:23 +01:00
|
|
|
g_verbose_offset=$(($g_verbose_offset + 1 ))
|
|
|
|
g_use_verbosity=
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
n*)
|
2010-03-03 18:50:07 +01:00
|
|
|
g_noroutes=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
t*)
|
2010-03-03 18:50:07 +01:00
|
|
|
g_timestamp=Yes
|
2008-12-07 19:17:26 +01:00
|
|
|
option=${option#t}
|
|
|
|
;;
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
version_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local all
|
|
|
|
all=
|
2010-05-29 17:59:45 +02:00
|
|
|
local product
|
2008-12-07 19:17:26 +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=
|
|
|
|
;;
|
|
|
|
a*)
|
|
|
|
all=Yes
|
|
|
|
option=${option#a}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ $# -gt 0 ] && usage 1
|
|
|
|
|
2010-05-31 16:32:17 +02:00
|
|
|
echo $SHOREWALL_VERSION
|
2010-06-07 18:16:56 +02:00
|
|
|
|
2010-05-29 17:59:45 +02:00
|
|
|
if [ -n "$all" ]; then
|
2010-05-31 16:32:17 +02:00
|
|
|
for product in shorewall6 shorewall-lite shorewall6-lite shorewall-init; do
|
2010-05-29 17:59:45 +02:00
|
|
|
if [ -f /usr/share/$product/version ]; then
|
2010-05-31 16:32:17 +02:00
|
|
|
echo "$product: $(cat /usr/share/$product/version)"
|
2010-05-29 17:59:45 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2008-12-07 19:17:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
|
|
|
|
MUTEX_TIMEOUT=
|
|
|
|
|
|
|
|
SHAREDIR=/usr/share/shorewall
|
|
|
|
CONFDIR=/etc/shorewall
|
2010-03-02 21:34:36 +01:00
|
|
|
g_product="Shorewall"
|
2010-03-03 18:50:07 +01:00
|
|
|
g_recovering=
|
|
|
|
g_timestamp=
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
[ -f ${CONFDIR}/vardir ] && . ${CONFDIR}/vardir
|
|
|
|
|
|
|
|
[ -n "${VARDIR:=/var/lib/shorewall}" ]
|
|
|
|
|
2009-03-01 20:46:30 +01:00
|
|
|
if [ ! -f ${VARDIR}/firewall ]; then
|
2010-06-07 18:16:56 +02:00
|
|
|
[ -f ${VARDIR}/.restore ] && cp -f ${VARDIR}/.restore ${VARDIR}/firewall
|
2009-03-01 20:46:30 +01:00
|
|
|
fi
|
|
|
|
|
2010-02-23 16:52:35 +01:00
|
|
|
g_firewall=${VARDIR}/firewall
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-03-05 15:51:13 +01:00
|
|
|
for library in base cli; do
|
|
|
|
. ${SHAREDIR}/lib.$library
|
2008-12-07 19:17:26 +01:00
|
|
|
done
|
|
|
|
|
2010-02-23 16:52:35 +01:00
|
|
|
version_file=$SHAREDIR/version
|
|
|
|
if [ -f $version_file ]; then
|
2010-03-02 17:02:10 +01:00
|
|
|
SHOREWALL_VERSION=$(cat $version_file)
|
2008-12-07 19:17:26 +01:00
|
|
|
else
|
|
|
|
echo " ERROR: Shorewall is not properly installed" >&2
|
2010-02-23 16:52:35 +01:00
|
|
|
echo " The file $version_file does not exist" >&2
|
2008-12-07 19:17:26 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-03-02 20:59:38 +01:00
|
|
|
banner="Shorewall-$SHOREWALL_VERSION Status at $g_hostname -"
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
case $(echo -e) in
|
|
|
|
-e*)
|
2010-02-23 16:52:35 +01:00
|
|
|
g_ring_bell="echo \a"
|
|
|
|
g_echo_e="echo"
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
*)
|
2010-02-23 16:52:35 +01:00
|
|
|
g_ring_bell="echo -e \a"
|
|
|
|
g_echo_e="echo -e"
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $(echo -n "Testing") in
|
|
|
|
-n*)
|
2010-02-23 16:52:35 +01:00
|
|
|
g_echo_n=
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
*)
|
2010-02-23 16:52:35 +01:00
|
|
|
g_echo_n=-n
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
COMMAND=$1
|
|
|
|
|
|
|
|
case "$COMMAND" in
|
|
|
|
start)
|
|
|
|
get_config Yes Yes
|
|
|
|
shift
|
|
|
|
start_command $@
|
|
|
|
;;
|
2010-05-20 23:09:40 +02:00
|
|
|
stop|clear)
|
2009-02-21 18:21:51 +01:00
|
|
|
get_config
|
2008-12-07 19:17:26 +01:00
|
|
|
[ $# -ne 1 ] && usage 1
|
2010-02-23 16:52:35 +01:00
|
|
|
[ -x $g_firewall ] || fatal_error "Shorewall has never been started"
|
2010-07-23 22:24:07 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
run_it $g_firewall $g_debugging $COMMAND
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
reset)
|
|
|
|
get_config
|
|
|
|
shift
|
2010-07-23 22:24:07 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2010-02-23 16:52:35 +01:00
|
|
|
[ -x $g_firewall ] || fatal_error "Shorewall has never been started"
|
2010-07-23 22:24:07 +02:00
|
|
|
run_it $g_firewall $g_debugging reset $@
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
2008-12-07 19:17:26 +01:00
|
|
|
;;
|
|
|
|
compile)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
compile_command $@
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
get_config Yes Yes
|
|
|
|
shift
|
|
|
|
restart_command $@
|
|
|
|
;;
|
|
|
|
refresh)
|
|
|
|
get_config Yes Yes
|
|
|
|
shift
|
|
|
|
refresh_command $@
|
|
|
|
;;
|
|
|
|
check)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
check_command $@
|
|
|
|
;;
|
2009-03-06 21:43:46 +01:00
|
|
|
show|list)
|
2008-12-07 19:17:26 +01:00
|
|
|
get_config Yes No Yes
|
|
|
|
shift
|
|
|
|
show_command $@
|
|
|
|
;;
|
|
|
|
load|reload)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
reload_command $@
|
|
|
|
;;
|
|
|
|
export)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
export_command $@
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
[ $# -eq 1 ] || usage 1
|
2009-07-21 21:32:25 +02:00
|
|
|
[ "$(id -u)" != 0 ] && fatal_error "ERROR: The status command may only be run by root"
|
2008-12-07 19:17:26 +01:00
|
|
|
get_config
|
2010-03-02 20:59:38 +01:00
|
|
|
echo "Shorewall-$SHOREWALL_VERSION Status at $g_hostname - $(date)"
|
2008-12-07 19:17:26 +01:00
|
|
|
echo
|
|
|
|
if shorewall_is_started ; then
|
|
|
|
echo "Shorewall is running"
|
|
|
|
status=0
|
|
|
|
else
|
|
|
|
echo "Shorewall is stopped"
|
|
|
|
status=4
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f ${VARDIR}/state ]; then
|
|
|
|
state="$(cat ${VARDIR}/state)"
|
|
|
|
case $state in
|
2010-05-15 21:46:47 +02:00
|
|
|
Stopped*|Closed*|Clear*)
|
2008-12-07 19:17:26 +01:00
|
|
|
status=3
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
state=Unknown
|
|
|
|
fi
|
|
|
|
echo "State:$state"
|
|
|
|
echo
|
|
|
|
exit $status
|
|
|
|
;;
|
|
|
|
dump)
|
|
|
|
get_config Yes No Yes
|
|
|
|
shift
|
|
|
|
dump_command $@
|
|
|
|
;;
|
|
|
|
hits)
|
|
|
|
get_config Yes No Yes
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
shift
|
|
|
|
hits_command $@
|
|
|
|
;;
|
|
|
|
version)
|
|
|
|
shift
|
|
|
|
version_command $@
|
|
|
|
;;
|
|
|
|
try)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
try_command $@
|
|
|
|
;;
|
|
|
|
logwatch)
|
|
|
|
get_config Yes Yes Yes
|
2010-03-02 20:59:38 +01:00
|
|
|
banner="Shorewall-$SHOREWALL_VERSION Logwatch at $g_hostname -"
|
2008-12-07 19:17:26 +01:00
|
|
|
logwatch_command $@
|
|
|
|
;;
|
|
|
|
drop)
|
|
|
|
get_config
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
2010-01-18 01:18:44 +01:00
|
|
|
if ! chain_exists dynamic; then
|
2010-03-02 21:34:36 +01:00
|
|
|
echo "Dynamic blacklisting is not supported in the current $g_product configuration"
|
2010-01-18 01:18:44 +01:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
block DROP Dropped $*
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
fatal_error "Shorewall is not started"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
logdrop)
|
|
|
|
get_config
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
2010-01-18 01:18:44 +01:00
|
|
|
if ! chain_exists dynamic; then
|
2010-03-02 21:34:36 +01:00
|
|
|
echo "Dynamic blacklisting is not supported in the current $g_product configuration"
|
2010-01-18 01:18:44 +01:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2008-12-07 19:17:26 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
block logdrop Dropped $*
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
fatal_error "Shorewall is not started"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
reject|logreject)
|
|
|
|
get_config
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
block $COMMAND Rejected $*
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
fatal_error "Shorewall is not started"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
allow)
|
|
|
|
get_config
|
|
|
|
allow_command $@
|
|
|
|
;;
|
2009-03-06 18:00:38 +01:00
|
|
|
add)
|
|
|
|
get_config
|
|
|
|
shift
|
|
|
|
add_command $@
|
|
|
|
;;
|
|
|
|
delete)
|
|
|
|
get_config
|
|
|
|
shift
|
2009-04-18 20:48:28 +02:00
|
|
|
delete_command $@
|
2009-03-06 21:25:59 +01:00
|
|
|
;;
|
2008-12-07 19:17:26 +01:00
|
|
|
save)
|
|
|
|
get_config
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-02-26 17:35:50 +01:00
|
|
|
g_restorepath=${VARDIR}/$RESTOREFILE
|
2008-12-07 19:17:26 +01:00
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
save_config
|
|
|
|
|
|
|
|
result=$?
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
|
|
|
|
exit $result
|
|
|
|
;;
|
|
|
|
forget)
|
|
|
|
get_config
|
|
|
|
case $# in
|
|
|
|
1)
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
RESTOREFILE="$2"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-02-26 17:35:50 +01:00
|
|
|
g_restorepath=${VARDIR}/$RESTOREFILE
|
2008-12-07 19:17:26 +01:00
|
|
|
|
2010-02-26 17:35:50 +01:00
|
|
|
if [ -x $g_restorepath ]; then
|
|
|
|
rm -f $g_restorepath
|
|
|
|
rm -f ${g_restorepath}-iptables
|
2010-06-07 22:07:33 +02:00
|
|
|
rm -f ${g_restorepath}-ipsets
|
2010-02-26 17:35:50 +01:00
|
|
|
echo " $g_restorepath removed"
|
|
|
|
elif [ -f $g_restorepath ]; then
|
|
|
|
echo " $g_restorepath exists and is not a saved Shorewall configuration"
|
2008-12-07 19:17:26 +01:00
|
|
|
fi
|
|
|
|
rm -f ${VARDIR}/save
|
|
|
|
;;
|
|
|
|
ipcalc)
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
if [ $# -eq 2 ]; then
|
|
|
|
address=${2%/*}
|
|
|
|
vlsm=${2#*/}
|
|
|
|
elif [ $# -eq 3 ]; then
|
|
|
|
address=$2
|
|
|
|
vlsm=$(ip_vlsm $3)
|
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
valid_address $address || fatal_error "Invalid IP address: $address"
|
|
|
|
[ -z "$vlsm" ] && exit 2
|
|
|
|
[ "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)
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
case $2 in
|
|
|
|
*.*.*.*-*.*.*.*)
|
|
|
|
for address in ${2%-*} ${2#*-}; do
|
|
|
|
valid_address $address || fatal_error "Invalid IP address: $address"
|
|
|
|
done
|
|
|
|
|
|
|
|
ip_range $2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
ipdecimal)
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
[ $# -eq 2 ] || usage 1
|
|
|
|
case $2 in
|
|
|
|
*.*.*.*)
|
|
|
|
valid_address $2 || fatal_error "Invalid IP address: $2"
|
|
|
|
echo " $(decodeaddr $2)"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " $(encodeaddr $2)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
restore)
|
|
|
|
get_config
|
|
|
|
shift
|
|
|
|
restore_command $@
|
|
|
|
;;
|
|
|
|
call)
|
|
|
|
get_config
|
2010-02-23 01:43:38 +01:00
|
|
|
[ -n "$g_debugging" ] && set -x
|
2008-12-07 19:17:26 +01:00
|
|
|
#
|
|
|
|
# Undocumented way to call functions in ${SHAREDIR}/functions directly
|
|
|
|
#
|
|
|
|
shift
|
|
|
|
$@
|
|
|
|
;;
|
|
|
|
help)
|
|
|
|
shift
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
safe-restart|safe-start)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
safe_commands $@
|
|
|
|
;;
|
2009-06-17 21:03:05 +02:00
|
|
|
iptrace)
|
|
|
|
get_config
|
|
|
|
shift
|
|
|
|
if shorewall_is_started ; then
|
|
|
|
$IPTABLES -t raw -A PREROUTING $@ -j TRACE
|
|
|
|
$IPTABLES -t raw -A OUTPUT $@ -j TRACE
|
|
|
|
else
|
|
|
|
fatal_error "Shorewall is not started"
|
|
|
|
fi
|
2010-06-07 18:16:56 +02:00
|
|
|
;;
|
2009-06-17 21:03:05 +02:00
|
|
|
noiptrace)
|
|
|
|
get_config
|
|
|
|
shift
|
|
|
|
if shorewall_is_started ; then
|
|
|
|
$IPTABLES -t raw -D PREROUTING $@ -j TRACE
|
|
|
|
$IPTABLES -t raw -D OUTPUT $@ -j TRACE
|
|
|
|
else
|
|
|
|
fatal_error "Shorewall is not started"
|
|
|
|
fi
|
2010-06-07 18:16:56 +02:00
|
|
|
;;
|
2008-12-07 19:17:26 +01:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|