2011-12-06 21:54:51 +01:00
|
|
|
#
|
2015-07-28 19:59:11 +02:00
|
|
|
# Shorewall 5.0 -- /usr/share/shorewall/lib.cli-std.
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
2015-07-28 19:59:11 +02:00
|
|
|
# (c) 1999-2015 - Tom Eastep (teastep@shorewall.net)
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
# Complete documentation is available at http://shorewall.net
|
|
|
|
#
|
2014-01-04 18:48:27 +01:00
|
|
|
# This program is part of Shorewall.
|
|
|
|
#
|
2011-12-06 21:54:51 +01:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2014-01-04 18:48:27 +01:00
|
|
|
# it under the terms of the GNU General Public License as published by the
|
|
|
|
# Free Software Foundation, either version 2 of the license or, at your
|
|
|
|
# option, any later version.
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-01-04 18:48:27 +01:00
|
|
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
# This library contains the command processing code common to /sbin/shorewall and /sbin/shorewall6.
|
|
|
|
#
|
2011-12-07 22:04:20 +01:00
|
|
|
####################################################################################################
|
|
|
|
# Set the configuration variables from the .conf file
|
|
|
|
#
|
|
|
|
# $1 = Yes: read the params file
|
|
|
|
# $2 = Yes: check for STARTUP_ENABLED
|
|
|
|
# $3 = Yes: Check for LOGFILE
|
|
|
|
#
|
2011-12-06 21:54:51 +01:00
|
|
|
get_config() {
|
|
|
|
local prog
|
2015-10-30 16:47:16 +01:00
|
|
|
local lib
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
ensure_config_path
|
|
|
|
|
|
|
|
if [ "$1" = Yes ]; then
|
2013-02-11 15:36:32 +01:00
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
params=$(find_file params)
|
|
|
|
else
|
|
|
|
params="$g_shorewalldir/params"
|
|
|
|
fi
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ -f $params ]; then
|
|
|
|
. $params
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-02-13 21:45:28 +01:00
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
2016-11-21 19:00:55 +01:00
|
|
|
config=$(find_file ${PRODUCT}.conf)
|
2013-02-13 16:45:24 +01:00
|
|
|
else
|
2016-11-21 19:00:55 +01:00
|
|
|
[ -n "$g_shorewalldir" ] || fatal_error "Ordinary users may not $COMMAND the $CONFDIR/$PRODUCT configuration"
|
|
|
|
config="$g_shorewalldir/$PRODUCT.conf"
|
2013-02-13 16:45:24 +01:00
|
|
|
fi
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ -f $config ]; then
|
|
|
|
if [ -r $config ]; then
|
|
|
|
. $config
|
|
|
|
else
|
2013-02-14 15:52:43 +01:00
|
|
|
fatal_error "Cannot read $config! (Hint: Are you root?)"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
else
|
2013-02-14 15:52:43 +01:00
|
|
|
fatal_error "$config does not exist!"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
ensure_config_path
|
|
|
|
|
|
|
|
if [ -z "$g_export" -a "$(id -u)" = 0 ]; then
|
|
|
|
#
|
|
|
|
# This block is avoided for compile for export and when the user isn't root
|
|
|
|
#
|
|
|
|
if [ "$3" = Yes ]; then
|
2015-10-31 16:08:17 +01:00
|
|
|
setup_logread
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $g_family -eq 4 ]; then
|
|
|
|
if [ -n "$IPTABLES" ]; then
|
|
|
|
if [ ! -x "$IPTABLES" ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "The program specified in IPTABLES does not exist or is not executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
IPTABLES=$(mywhich iptables 2> /dev/null)
|
|
|
|
if [ -z "$IPTABLES" ] ; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Can't find iptables executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
2012-04-24 23:52:57 +02:00
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
g_tool=$IPTABLES
|
|
|
|
else
|
|
|
|
if [ -n "$IP6TABLES" ]; then
|
|
|
|
if [ ! -x "$IP6TABLES" ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "The program specified in IP6TABLES does not exist or is not executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
IP6TABLES=$(mywhich ip6tables 2> /dev/null)
|
|
|
|
if [ -z "$IP6TABLES" ] ; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Can't find ip6tables executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
g_tool=$IP6TABLES
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$IPSET" ]; then
|
|
|
|
case "$IPSET" in
|
|
|
|
*/*)
|
|
|
|
if [ ! -x "$IPSET" ] ; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "The program specified in IPSET ($IPSET) does not exist or is not executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
;;
|
2012-11-09 17:54:54 +01:00
|
|
|
ipset)
|
|
|
|
#
|
|
|
|
# Old config files had this as default
|
|
|
|
#
|
|
|
|
IPSET=''
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
|
|
|
prog="$(mywhich $IPSET 2> /dev/null)"
|
|
|
|
if [ -z "$prog" ] ; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Can't find $IPSET executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
IPSET=$prog
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
2012-11-09 17:54:54 +01:00
|
|
|
IPSET=''
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$TC" ]; then
|
|
|
|
case "$TC" in
|
|
|
|
*/*)
|
|
|
|
if [ ! -x "$TC" ] ; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "The program specified in TC ($TC) does not exist or is not executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prog="$(mywhich $TC 2> /dev/null)"
|
|
|
|
if [ -z "$prog" ] ; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Can't find $TC executable"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
TC=$prog
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
TC='tc'
|
|
|
|
fi
|
|
|
|
#
|
|
|
|
# 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)
|
2016-11-21 19:00:55 +01:00
|
|
|
not_configured_error "$g_product startup is disabled. To enable startup, set STARTUP_ENABLED=Yes in ${g_confdir}/${PRODUCT}.conf"
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
Yes|yes|YES)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$STARTUP_ENABLED" ]; then
|
2015-06-09 19:29:45 +02:00
|
|
|
not_configured_error "Invalid Value for STARTUP_ENABLED: $STARTUP_ENABLED"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
case ${SHOREWALL_COMPILER:=perl} in
|
|
|
|
perl|Perl)
|
|
|
|
;;
|
|
|
|
shell|Shell)
|
|
|
|
echo " WARNING: SHOREWALL_COMPILER=shell ignored. Shorewall-shell support has been removed in this release" >&2
|
|
|
|
;;
|
|
|
|
*)
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Invalid value ($SHOREWALL_COMPILER) for SHOREWALL_COMPILER"
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case ${TC_ENABLED:=Internal} in
|
|
|
|
No|NO|no)
|
|
|
|
TC_ENABLED=
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -z "$LOGFORMAT" ] && LOGFORMAT='Shorewall:%s.%s'
|
|
|
|
|
|
|
|
[ -n "$LOGFORMAT" ] && LOGFORMAT="${LOGFORMAT%%%*}"
|
|
|
|
|
|
|
|
if [ -n "$STARTUP_LOG" ]; then
|
|
|
|
if [ -n "$LOG_VERBOSITY" ]; then
|
|
|
|
case $LOG_VERBOSITY in
|
|
|
|
-1)
|
|
|
|
;;
|
|
|
|
0|1|2)
|
|
|
|
;;
|
|
|
|
*)
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Invalid LOG_VERBOSITY ($LOG_VERBOSITY)"
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
LOG_VERBOSITY=2;
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
LOG_VERBOSITY=-1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
STARTUP_LOG=
|
|
|
|
LOG_VERBOSITY=-1
|
|
|
|
fi
|
|
|
|
|
2012-03-18 20:28:26 +01:00
|
|
|
if [ -n "$SHOREWALL_SHELL" -a -z "$g_export" ]; then
|
2011-12-06 21:54:51 +01:00
|
|
|
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
|
|
|
|
|
2015-01-02 18:28:50 +01:00
|
|
|
if [ -n "$IP" ]; then
|
|
|
|
case "$IP" in
|
|
|
|
*/*)
|
|
|
|
if [ ! -x "$IP" ] ; then
|
|
|
|
fatal_error "The program specified in IP ($IP) does not exist or is not executable"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prog="$(mywhich $IP 2> /dev/null)"
|
|
|
|
if [ -z "$prog" ] ; then
|
|
|
|
fatal_error "Can't find $IP executable"
|
|
|
|
fi
|
|
|
|
IP=$prog
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
IP='ip'
|
|
|
|
fi
|
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
case $VERBOSITY in
|
|
|
|
-1|0|1|2)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$VERBOSITY" ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Invalid VERBOSITY setting ($VERBOSITY)"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
|
|
|
VERBOSITY=2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$g_use_verbosity" ] && VERBOSITY=$g_use_verbosity || VERBOSITY=$(($g_verbose_offset + $VERBOSITY))
|
|
|
|
|
|
|
|
if [ $VERBOSITY -lt -1 ]; then
|
|
|
|
VERBOSITY=-1
|
|
|
|
elif [ $VERBOSITY -gt 2 ]; then
|
|
|
|
VERBOSITY=2
|
|
|
|
fi
|
|
|
|
|
|
|
|
g_hostname=$(hostname 2> /dev/null)
|
|
|
|
|
|
|
|
[ -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
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Invalid MANGLE_ENABLED setting ($MANGLE_ENABLED)"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $AUTOMAKE in
|
|
|
|
Yes|yes)
|
|
|
|
;;
|
|
|
|
No|no)
|
|
|
|
AUTOMAKE=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$AUTOMAKE" ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Invalid AUTOMAKE setting ($AUTOMAKE)"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $LOAD_HELPERS_ONLY in
|
|
|
|
Yes|yes)
|
|
|
|
;;
|
|
|
|
No|no)
|
|
|
|
LOAD_HELPERS_ONLY=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$LOAD_HELPERS_ONLY" ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Invalid LOAD_HELPERS_ONLY setting ($LOAD_HELPERS_ONLY)"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-06-01 21:59:25 +02:00
|
|
|
if [ -n "$WORKAROUNDS" ]; then
|
|
|
|
case $WORKAROUNDS in
|
|
|
|
[Yy]es)
|
|
|
|
;;
|
|
|
|
[Nn]o)
|
|
|
|
WORKAROUNDS=''
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_error "Invalid setting ($WORKAROUNDS) for WORKAROUNDS"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
2015-01-02 17:49:38 +01:00
|
|
|
g_loopback=$(find_loopback_interfaces)
|
2015-10-30 16:47:16 +01:00
|
|
|
|
2016-09-21 19:20:48 +02:00
|
|
|
[ -n "$PAGER" ] || PAGER=$DEFAULT_PAGER
|
|
|
|
|
2016-11-17 19:58:10 +01:00
|
|
|
if [ -z "$g_nopager" ]; then
|
|
|
|
if [ -n "$PAGER" -a -t 1 ]; then
|
|
|
|
case $PAGER in
|
|
|
|
/*)
|
|
|
|
g_pager="$PAGER"
|
|
|
|
[ -f "$g_pager" ] || fatal_error "PAGER $PAGER does not exist"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
g_pager=$(mywhich $PAGER 2> /dev/null)
|
|
|
|
[ -n "$g_pager" ] || fatal_error "PAGER $PAGER not found"
|
|
|
|
;;
|
|
|
|
esac
|
2016-03-02 17:32:49 +01:00
|
|
|
|
2016-11-17 19:58:10 +01:00
|
|
|
[ -x "$g_pager" ] || fatal_error "PAGER $g_pager is not executable"
|
2016-03-02 17:58:26 +01:00
|
|
|
|
2016-11-17 19:58:10 +01:00
|
|
|
g_pager="| $g_pager"
|
|
|
|
fi
|
2016-03-02 17:32:49 +01:00
|
|
|
fi
|
|
|
|
|
2016-04-11 01:07:56 +02:00
|
|
|
if [ -n "$DYNAMIC_BLACKLIST" ]; then
|
2016-10-04 18:09:45 +02:00
|
|
|
setup_dbl
|
2016-04-11 01:07:56 +02:00
|
|
|
fi
|
|
|
|
|
2015-10-30 16:47:16 +01:00
|
|
|
lib=$(find_file lib.cli-user)
|
|
|
|
|
|
|
|
[ -f $lib ] && . $lib
|
2011-12-06 21:54:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Determine if there are config files newer than the passed object
|
|
|
|
#
|
|
|
|
uptodate() {
|
|
|
|
[ -x $1 ] || return 1
|
|
|
|
|
|
|
|
local dir
|
|
|
|
local ifs
|
|
|
|
|
|
|
|
ifs="$IFS"
|
|
|
|
IFS=':'
|
|
|
|
|
2013-05-07 18:36:02 +02:00
|
|
|
for dir in $g_shorewalldir $CONFIG_PATH; do
|
2011-12-06 21:54:51 +01:00
|
|
|
if [ -n "$(find ${dir} -newer $1)" ]; then
|
|
|
|
IFS="$ifs"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
IFS="$ifs"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
#
|
|
|
|
# Run the postcompile user exit
|
|
|
|
#
|
|
|
|
run_postcompile() { # $1 is the compiled script
|
|
|
|
local script
|
|
|
|
|
|
|
|
script=$(find_file postcompile)
|
|
|
|
|
|
|
|
if [ -f $script ]; then
|
|
|
|
. $script $1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
# Run the compiler
|
|
|
|
#
|
|
|
|
compiler() {
|
|
|
|
local pc
|
2012-04-02 16:46:38 +02:00
|
|
|
local shorewallrc
|
2012-09-04 00:07:50 +02:00
|
|
|
local shorewallrc1
|
2015-06-27 00:18:07 +02:00
|
|
|
local options
|
2012-04-02 16:46:38 +02:00
|
|
|
|
2012-10-01 15:51:36 +02:00
|
|
|
pc=${LIBEXECDIR}/shorewall/compiler.pl
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ $(id -u) -ne 0 ]; then
|
2016-11-21 19:00:55 +01:00
|
|
|
if [ -z "$g_shorewalldir" -o "$g_shorewalldir" = $CONFDIR/$PRODUCT ]; then
|
|
|
|
startup_error "Ordinary users may not $COMMAND the $CONFDIR/$PRODUCT configuration"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
#
|
2011-12-20 17:19:57 +01:00
|
|
|
# We've now set g_shorewalldir so recalculate CONFIG_PATH
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
2013-02-23 01:15:41 +01:00
|
|
|
[ -n "$g_haveconfig" ] || ensure_config_path
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
2011-12-20 17:19:57 +01:00
|
|
|
# Get the config from $g_shorewalldir
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
2012-09-01 17:21:45 +02:00
|
|
|
get_config Yes
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
case $COMMAND in
|
2016-04-18 23:16:13 +02:00
|
|
|
*start|try|refresh|reload|restart|safe-*)
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
STARTUP_LOG=
|
|
|
|
LOG_VERBOSITY=-1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
debugflags="-w"
|
|
|
|
[ -n "$g_debug" ] && debugflags='-wd'
|
2015-08-19 23:05:15 +02:00
|
|
|
[ -n "$g_profile" ] && debugflags='-wd:NYTProf'
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
# Perl compiler only takes the output file as a argument
|
|
|
|
|
2015-06-26 20:35:11 +02:00
|
|
|
[ "$1" = debug -o "$1" = trace ] && shift;
|
2011-12-06 21:54:51 +01:00
|
|
|
[ "$1" = nolock ] && shift;
|
|
|
|
shift
|
|
|
|
|
2012-09-04 00:07:50 +02:00
|
|
|
shorewallrc=${g_basedir}/shorewallrc
|
2013-02-13 21:45:28 +01:00
|
|
|
|
2012-04-02 16:46:38 +02:00
|
|
|
if [ -n "$g_export" ]; then
|
2012-09-04 00:07:50 +02:00
|
|
|
shorewallrc1=$(find_file shorewallrc)
|
|
|
|
[ -f "$shorewallrc1" ] || fatal_error "Compiling for export requires a shorewallrc file"
|
2012-04-02 16:46:38 +02:00
|
|
|
fi
|
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
if [ -n "$g_conditional" ] && uptodate "$g_file"; then
|
2013-05-09 04:01:39 +02:00
|
|
|
echo "$g_file is up to date -- no compilation required"
|
2015-06-26 23:32:43 +02:00
|
|
|
g_compiled="$g_file"
|
2013-05-09 04:01:39 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2012-09-04 00:07:50 +02:00
|
|
|
options="--verbose=$VERBOSITY --family=$g_family --config_path=$CONFIG_PATH --shorewallrc=${shorewallrc}"
|
2017-01-22 04:47:50 +01:00
|
|
|
|
|
|
|
[ -n "$shorewallrc1" ] && options="$options --shorewallrc1=${shorewallrc1}"
|
|
|
|
[ -n "$STARTUP_LOG" ] && options="$options --log=$STARTUP_LOG"
|
|
|
|
[ -n "$LOG_VERBOSITY" ] && options="$options --log_verbosity=$LOG_VERBOSITY";
|
|
|
|
[ -n "$g_export" ] && options="$options --export"
|
|
|
|
[ -n "$g_shorewalldir" ] && options="$options --directory=$g_shorewalldir"
|
|
|
|
[ -n "$g_timestamp" ] && options="$options --timestamp"
|
|
|
|
[ -n "$g_test" ] && options="$options --test"
|
|
|
|
[ -n "$g_preview" ] && options="$options --preview"
|
2011-12-06 21:54:51 +01:00
|
|
|
[ "$g_debugging" = trace ] && options="$options --debug"
|
2017-01-22 04:47:50 +01:00
|
|
|
[ -n "$g_refreshchains" ] && options="$options --refresh=$g_refreshchains"
|
|
|
|
[ -n "$g_confess" ] && options="$options --confess"
|
|
|
|
[ -n "$g_update" ] && options="$options --update"
|
|
|
|
[ -n "$g_annotate" ] && options="$options --annotate"
|
|
|
|
[ -n "$g_inline" ] && options="$options --inline"
|
2011-12-06 21:54:51 +01: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
|
|
|
|
|
2015-07-08 21:53:42 +02:00
|
|
|
case "$g_doing" in
|
|
|
|
Compiling|Checking)
|
2016-05-06 00:41:46 +02:00
|
|
|
progress_message3 "$g_doing using Shorewall $SHOREWALL_VERSION..."
|
2015-07-08 21:53:42 +02:00
|
|
|
;;
|
|
|
|
Updating)
|
|
|
|
progress_message3 "Updating $g_product configuration to $SHOREWALL_VERSION..."
|
|
|
|
;;
|
|
|
|
*)
|
2016-05-06 00:41:46 +02:00
|
|
|
[ -n "$g_doing" ] && progress_message3 "$g_doing using Shorewall $SHOREWALL_VERSION..."
|
2015-07-08 21:53:42 +02:00
|
|
|
;;
|
|
|
|
esac
|
2016-03-11 22:26:23 +01:00
|
|
|
#
|
|
|
|
# Only use the pager if 'trace' or -r was specified and -d was not
|
|
|
|
#
|
|
|
|
[ "$g_debugging" != trace -a -z "$g_preview" ] || [ -n "$g_debug" ] && g_pager=
|
2015-06-22 19:56:17 +02:00
|
|
|
|
2012-10-01 15:59:39 +02:00
|
|
|
if [ ${PERLLIBDIR} = ${LIBEXECDIR}/shorewall ]; then
|
2016-03-11 22:26:23 +01:00
|
|
|
eval $PERL $debugflags $pc $options $@ $g_pager
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2016-03-11 22:26:23 +01:00
|
|
|
eval PERL5LIB=${PERLLIBDIR} $PERL $debugflags $pc $options $@ $g_pager
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
2012-09-02 17:28:02 +02:00
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
status=$?
|
2012-09-02 17:28:02 +02:00
|
|
|
|
2015-07-08 21:53:42 +02:00
|
|
|
if [ $status -eq 0 -a $COMMAND != check -a $COMMAND != update ]; then
|
2015-06-26 23:32:43 +02:00
|
|
|
g_compiled="$g_file"
|
|
|
|
run_postcompile "$g_compiled"
|
2015-06-23 01:41:21 +02:00
|
|
|
return
|
2012-09-02 17:28:02 +02:00
|
|
|
fi
|
2015-06-23 01:41:21 +02:00
|
|
|
|
|
|
|
return $status
|
2012-09-02 17:28:02 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
# Start Command Executor
|
|
|
|
#
|
|
|
|
start_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local rc
|
|
|
|
rc=0
|
|
|
|
|
|
|
|
do_it() {
|
|
|
|
if [ -n "$AUTOMAKE" ]; then
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
run_it ${VARDIR}/firewall $g_debugging start
|
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
2015-06-23 01:41:21 +02:00
|
|
|
g_file="${VARDIR}/.start"
|
|
|
|
if compiler $g_debugging $nolock compile "$g_file"; then
|
2011-12-06 21:54:51 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
run_it ${VARDIR}/.start $g_debugging start
|
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
rc=$?
|
2016-04-15 23:29:51 +02:00
|
|
|
mylogger kern.err "ERROR:$g_product start failed"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit $rc
|
|
|
|
}
|
|
|
|
|
|
|
|
if product_is_started; then
|
|
|
|
error_message "Shorewall is already running"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2015-06-09 19:29:45 +02:00
|
|
|
[ -n "$STARTUP_ENABLED" ] || not_configured_error "Startup is disabled"
|
2011-12-06 21:54:51 +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*)
|
|
|
|
g_debug=Yes
|
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
g_fast=Yes
|
|
|
|
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"
|
|
|
|
g_purge=Yes
|
|
|
|
option=${option%p}
|
|
|
|
;;
|
|
|
|
c*)
|
|
|
|
AUTOMAKE=
|
|
|
|
option=${option#c}
|
2012-04-24 23:52:57 +02:00
|
|
|
;;
|
2012-04-11 23:28:44 +02:00
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2014-11-01 17:37:57 +01:00
|
|
|
C*)
|
|
|
|
g_counters=Yes
|
|
|
|
option=${option#C}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" ] && fatal_error "A directory has already been specified: $1"
|
|
|
|
[ -n "$g_fast" ] && fatal_error "Directory may not be specified with the -f option"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2011-12-06 21:54:51 +01:00
|
|
|
AUTOMAKE=
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $2
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -n "${g_fast}${AUTOMAKE}" ]; then
|
2016-04-14 18:43:21 +02:00
|
|
|
if ! uptodate ${VARDIR}/firewall; then
|
2011-12-06 21:54:51 +01:00
|
|
|
g_fast=
|
|
|
|
AUTOMAKE=
|
|
|
|
fi
|
|
|
|
fi
|
2015-08-01 20:11:35 +02:00
|
|
|
|
|
|
|
do_it
|
2011-12-06 21:54:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Compile Command Executor
|
|
|
|
#
|
|
|
|
compile_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 ]; do
|
|
|
|
[ $# -eq 0 ] && break
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
shift
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
e*)
|
|
|
|
g_export=Yes
|
2012-09-03 20:33:58 +02:00
|
|
|
g_shorewalldir='.'
|
2011-12-06 21:54:51 +01:00
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
p*)
|
|
|
|
g_profile=Yes
|
|
|
|
option=${option#p}
|
|
|
|
;;
|
|
|
|
t*)
|
|
|
|
g_test=Yes
|
|
|
|
option=${option#t}
|
|
|
|
;;
|
|
|
|
d*)
|
|
|
|
g_debug=Yes;
|
|
|
|
option=${option#d}
|
|
|
|
;;
|
2013-05-07 18:36:02 +02:00
|
|
|
c*)
|
2013-05-09 04:01:39 +02:00
|
|
|
g_conditional=Yes;
|
2013-05-07 18:36:02 +02:00
|
|
|
option=${option#c}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2013-05-09 04:01:39 +02:00
|
|
|
g_file=
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
2013-05-09 04:01:39 +02:00
|
|
|
[ -n "$g_export" ] && g_file=firewall || g_file=${VARDIR}/firewall
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
1)
|
2013-05-09 04:01:39 +02:00
|
|
|
g_file=$1
|
2015-06-23 01:41:21 +02:00
|
|
|
[ -d "$g_file" ] && fatal_error "$g_file is a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
2)
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" -a -z "$g_export" ] && fatal_error "A directory has already been specified: $1"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2013-05-09 04:01:39 +02:00
|
|
|
g_file=$2
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $3
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-07-03 17:16:27 +02:00
|
|
|
[ "x$g_file" = x- ] && g_doing=''
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
compiler $g_debugging compile "$g_file"
|
2011-12-06 21:54:51 +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*)
|
|
|
|
g_export=Yes
|
2012-09-03 20:33:58 +02:00
|
|
|
g_shorewalldir='.'
|
2011-12-06 21:54:51 +01:00
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
p*)
|
|
|
|
g_profile=Yes
|
|
|
|
option=${option#p}
|
|
|
|
;;
|
|
|
|
d*)
|
|
|
|
g_debug=Yes;
|
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
r*)
|
|
|
|
g_preview=Yes
|
|
|
|
option=${option#r}
|
|
|
|
;;
|
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" -a -z "$g_export" ] && fatal_error "A directory has already been specified: $1"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $2
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-07-02 23:23:27 +02:00
|
|
|
g_doing="Checking"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
compiler $g_debugging $nolock check
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Update Command Executor
|
|
|
|
#
|
|
|
|
update_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
|
|
|
|
g_update=Yes
|
|
|
|
|
|
|
|
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*)
|
|
|
|
g_export=Yes
|
|
|
|
option=${option#e}
|
|
|
|
;;
|
|
|
|
p*)
|
|
|
|
g_profile=Yes
|
|
|
|
option=${option#p}
|
|
|
|
;;
|
|
|
|
d*)
|
|
|
|
g_debug=Yes;
|
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
r*)
|
|
|
|
g_preview=Yes
|
|
|
|
option=${option#r}
|
|
|
|
;;
|
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
a*)
|
|
|
|
g_annotate=Yes
|
|
|
|
option=${option#a}
|
|
|
|
;;
|
2014-02-15 18:36:13 +01:00
|
|
|
A*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#A}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" ] && fatal_error "A directory has already been specified: $1"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $2
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-07-08 21:53:42 +02:00
|
|
|
g_doing="Updating"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
compiler $g_debugging $nolock check
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2015-07-26 18:59:49 +02:00
|
|
|
# Reload/Restart Command Executor
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
restart_command() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local rc
|
|
|
|
rc=0
|
|
|
|
local restorefile
|
|
|
|
|
|
|
|
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*)
|
|
|
|
g_debug=Yes
|
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
g_fast=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
|
|
|
c*)
|
|
|
|
AUTOMAKE=
|
|
|
|
option=${option#c}
|
2012-04-24 23:52:57 +02:00
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
n*)
|
|
|
|
g_noroutes=Yes
|
|
|
|
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"
|
|
|
|
g_purge=Yes
|
|
|
|
option=${option%p}
|
|
|
|
;;
|
2012-04-11 23:28:44 +02:00
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2014-11-01 17:37:57 +01:00
|
|
|
C*)
|
|
|
|
g_counters=Yes
|
|
|
|
option=${option#C}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" ] && fatal_error "A directory has already been specified: $1"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2011-12-06 21:54:51 +01:00
|
|
|
[ -n "$g_fast" ] && fatal_error "Directory may not be specified with the -f option"
|
|
|
|
AUTOMAKE=
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $2
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-06-09 19:29:45 +02:00
|
|
|
[ -n "$STARTUP_ENABLED" ] || not_configured_error "Startup is disabled"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ -z "$g_fast" -a -n "$AUTOMAKE" ]; then
|
|
|
|
uptodate ${VARDIR}/firewall && g_fast=Yes
|
|
|
|
fi
|
|
|
|
|
2015-07-26 18:59:49 +02:00
|
|
|
g_file="${VARDIR}/.${COMMAND}"
|
2015-06-23 01:41:21 +02:00
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
if [ -z "$g_fast" ]; then
|
2015-06-23 01:41:21 +02:00
|
|
|
if compiler $g_debugging $nolock compile "$g_file"; then
|
2011-12-06 21:54:51 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2015-07-26 18:59:49 +02:00
|
|
|
run_it ${VARDIR}/.${COMMAND} $g_debugging ${COMMAND}
|
2011-12-06 21:54:51 +01:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
rc=$?
|
2016-04-15 23:29:51 +02:00
|
|
|
mylogger kern.err "ERROR:$g_product ${COMMAND} failed"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
[ -x ${VARDIR}/firewall ] || fatal_error "No ${VARDIR}/firewall file found"
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
2015-07-26 18:59:49 +02:00
|
|
|
run_it ${VARDIR}/firewall $g_debugging $COMMAND
|
2011-12-06 21:54:51 +01:00
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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=
|
|
|
|
;;
|
2012-05-02 22:48:18 +02:00
|
|
|
d*)
|
|
|
|
g_debug=Yes
|
|
|
|
option=${option#d}
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
g_noroutes=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2012-05-02 22:48:18 +02:00
|
|
|
D)
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
g_shorewalldir="$2"
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "The -D option requires a directory name"
|
2012-05-02 22:48:18 +02:00
|
|
|
fi
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
g_refreshchains=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
g_refreshchains="$g_refreshchains,$1"
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
else
|
|
|
|
g_refreshchains=:refresh:
|
|
|
|
fi
|
|
|
|
|
|
|
|
product_is_started || fatal_error "$g_product is not running"
|
|
|
|
|
2015-06-09 19:29:45 +02:00
|
|
|
[ -n "$STARTUP_ENABLED" ] || not_configured_error "Startup is disabled"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
g_file="${VARDIR}/.refresh"
|
|
|
|
|
|
|
|
if compiler $g_debugging $nolock compile "$g_file"; then
|
2011-12-06 21:54:51 +01:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
run_it ${VARDIR}/.refresh $g_debugging refresh
|
|
|
|
rc=$?
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
rc=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $rc
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2015-07-26 18:59:49 +02:00
|
|
|
# Safe-start/safe-reload/safe-restart Command Executor
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
|
|
|
safe_commands() {
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local command
|
2011-12-31 18:40:36 +01:00
|
|
|
local timeout
|
|
|
|
timeout=60
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
# 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*)
|
|
|
|
g_noroutes=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
2011-12-31 18:40:36 +01:00
|
|
|
t)
|
|
|
|
[ $# -eq 1 ] && fatal_error "The -t option requires a timeout value"
|
|
|
|
echo $2 | egrep -q '[[:digit:]]+[smh]' || fatal_error "The timeout value must be numeric, optionally followed by a suffix (s, m or h)"
|
|
|
|
timeout=$2
|
|
|
|
option=
|
|
|
|
shift;
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" ] && fatal_error "A directory has already been specified: $1"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $2
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-06-09 19:29:45 +02:00
|
|
|
[ -n "$STARTUP_ENABLED" ] || not_configured_error "Startup is disabled"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if product_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[6] is not started yet
|
|
|
|
command="start"
|
|
|
|
else
|
2015-07-26 18:59:49 +02:00
|
|
|
# the command is safe-reload or safe-restart and the firewall is already running
|
|
|
|
command="${COMMAND#safe-}"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
g_file="${VARDIR}/.$command"
|
|
|
|
|
|
|
|
if ! compiler $g_debugging nolock compile "$g_file"; then
|
2011-12-06 21:54:51 +01:00
|
|
|
status=$?
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $command in
|
|
|
|
start)
|
|
|
|
RESTOREFILE=NONE
|
|
|
|
progress_message3 "Starting..."
|
|
|
|
;;
|
2015-07-26 18:59:49 +02:00
|
|
|
reload)
|
|
|
|
RESTOREFILE=.safe
|
|
|
|
g_restorepath=${VARDIR}/.safe
|
|
|
|
save_config
|
|
|
|
progress_message3 "Reloading..."
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
restart)
|
|
|
|
RESTOREFILE=.safe
|
|
|
|
g_restorepath=${VARDIR}/.safe
|
|
|
|
save_config
|
|
|
|
progress_message3 "Restarting..."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
if run_it ${VARDIR}/.$command $g_debugging $command; then
|
|
|
|
|
2016-12-28 20:09:08 +01:00
|
|
|
printf "Do you want to accept the new firewall configuration? [y/n] "
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2011-12-31 18:40:36 +01:00
|
|
|
if read_yesno_with_timeout $timeout ; then
|
2011-12-06 21:54:51 +01:00
|
|
|
echo "New configuration has been accepted"
|
|
|
|
else
|
2015-07-26 18:59:49 +02:00
|
|
|
if [ "$command" = "restart" -o "$command" = "reload" ]; then
|
2016-12-28 01:29:01 +01:00
|
|
|
run_it ${VARDIR}/.safe -r restore
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
|
|
|
run_it ${VARDIR}/.$command clear
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -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() {
|
2016-04-27 19:13:24 +02:00
|
|
|
[ -n "$g_shorewalldir" ] && fatal_error "A directory has already been specified: $1"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if [ ! -d $1 ]; then
|
|
|
|
if [ -e $1 ]; then
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "$1 is not a directory"
|
2011-12-06 21:54:51 +01:00
|
|
|
else
|
2013-02-16 16:32:47 +01:00
|
|
|
fatal_error "Directory $1 does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-12-20 17:19:57 +01:00
|
|
|
g_shorewalldir=$(resolve_file $1)
|
2011-12-06 21:54:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
g_noroutes=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
2016-04-27 19:13:24 +02:00
|
|
|
missing_argument
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
1)
|
|
|
|
handle_directory $1
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
handle_directory $1
|
2011-12-31 18:40:36 +01:00
|
|
|
echo $2 | egrep -q '[[:digit:]]+[smh]' || fatal_error "The timeout value must be numeric, optionally followed by a suffix (s, m or h)"
|
2011-12-06 21:54:51 +01:00
|
|
|
timeout=$2
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $3
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-06-09 19:29:45 +02:00
|
|
|
[ -n "$STARTUP_ENABLED" ] || not_configured_error "Startup is disabled"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
|
|
|
if product_is_started; then
|
|
|
|
running=Yes
|
|
|
|
else
|
|
|
|
running=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$running" ]; then
|
|
|
|
# shorewall[6] is not started yet
|
|
|
|
command="start"
|
|
|
|
else
|
|
|
|
# the firewall is already running
|
2015-07-26 18:59:49 +02:00
|
|
|
command="reload"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
g_file="${VARDIR}/.$command"
|
|
|
|
|
|
|
|
if ! compiler $g_debugging $nolock compile "$g_file"; then
|
2011-12-06 21:54:51 +01:00
|
|
|
status=$?
|
|
|
|
exit $status
|
|
|
|
fi
|
|
|
|
|
2012-09-02 17:28:02 +02:00
|
|
|
run_postcompile ${VARDIR}/.restart
|
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
case $command in
|
|
|
|
start)
|
|
|
|
RESTOREFILE=NONE
|
|
|
|
progress_message3 "Starting..."
|
|
|
|
;;
|
2015-07-26 18:59:49 +02:00
|
|
|
reload)
|
2011-12-06 21:54:51 +01:00
|
|
|
RESTOREFILE=.try
|
|
|
|
g_restorepath=${VARDIR}/.try
|
|
|
|
save_config
|
2015-07-26 18:59:49 +02:00
|
|
|
progress_message3 "Reloading..."
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
2012-11-23 20:46:14 +01:00
|
|
|
if run_it ${VARDIR}/.$command $g_debugging $command && [ -n "$timeout" ]; then
|
2011-12-06 21:54:51 +01:00
|
|
|
sleep $timeout
|
|
|
|
|
2015-07-26 18:59:49 +02:00
|
|
|
if [ "$command" = "reload" ]; then
|
2011-12-06 21:54:51 +01:00
|
|
|
run_it ${VARDIR}/.try restore
|
|
|
|
else
|
|
|
|
run_it ${VARDIR}/.$command clear
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
rsh_command() {
|
|
|
|
command="$*"
|
|
|
|
|
|
|
|
eval $RSH_COMMAND
|
|
|
|
}
|
|
|
|
|
|
|
|
rcp_command() {
|
|
|
|
files="$1"
|
|
|
|
destination=$2
|
|
|
|
|
|
|
|
eval $RCP_COMMAND
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2015-07-26 18:59:49 +02:00
|
|
|
# Remote-{start|reload|restart} command executor
|
2011-12-06 21:54:51 +01:00
|
|
|
#
|
2015-07-26 18:59:49 +02:00
|
|
|
remote_reload_command() # $* = original arguments less the command.
|
2011-12-06 21:54:51 +01:00
|
|
|
{
|
|
|
|
local verbose
|
|
|
|
verbose=$(make_verbose)
|
|
|
|
local file
|
|
|
|
file=
|
|
|
|
local capabilities
|
|
|
|
capabilities=
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local saveit
|
|
|
|
saveit=
|
|
|
|
local result
|
|
|
|
local system
|
|
|
|
local getcaps
|
|
|
|
getcaps=
|
|
|
|
local root
|
|
|
|
root=root
|
|
|
|
local libexec
|
2013-02-14 19:21:26 +01:00
|
|
|
libexec=${LIBEXECDIR}
|
2012-04-04 18:24:48 +02:00
|
|
|
local confdir
|
2013-02-14 19:21:26 +01:00
|
|
|
confdir=${CONFDIR}
|
2012-04-04 20:47:45 +02:00
|
|
|
local sbindir
|
2013-02-14 19:21:26 +01:00
|
|
|
sbindir=${SBINDIR}
|
2013-02-15 15:46:14 +01:00
|
|
|
local sharedir
|
|
|
|
sharedir=${SHAREDIR}
|
2013-09-19 06:05:35 +02:00
|
|
|
local litedir
|
2015-11-01 16:53:31 +01:00
|
|
|
local exitstatus
|
2016-11-21 19:00:55 +01:00
|
|
|
local program
|
2011-12-06 21:54:51 +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
|
|
|
|
;;
|
2016-10-06 00:03:54 +02:00
|
|
|
D)
|
|
|
|
[ $# -gt 1 ] || fatal_error "Missing directory name"
|
|
|
|
g_shorewalldir=$2
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
2012-04-11 23:28:44 +02:00
|
|
|
T*)
|
|
|
|
g_confess=Yes
|
|
|
|
option=${option#T}
|
|
|
|
;;
|
2013-12-15 20:23:20 +01:00
|
|
|
i*)
|
|
|
|
g_inline=Yes
|
|
|
|
option=${option#i}
|
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
option_error $option
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
2016-04-27 19:13:24 +02:00
|
|
|
0)
|
2016-10-06 00:03:54 +02:00
|
|
|
[ -n "$g_shorewalldir" ] || g_shorewalldir='.'
|
2016-04-27 19:13:24 +02:00
|
|
|
;;
|
2011-12-06 21:54:51 +01:00
|
|
|
1)
|
2013-02-22 22:37:31 +01:00
|
|
|
g_shorewalldir="."
|
2011-12-06 21:54:51 +01:00
|
|
|
system=$1
|
|
|
|
;;
|
|
|
|
2)
|
2013-02-22 22:37:31 +01:00
|
|
|
g_shorewalldir=$1
|
2011-12-06 21:54:51 +01:00
|
|
|
system=$2
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
too_many_arguments $3
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-02-22 22:37:31 +01:00
|
|
|
if [ -f $g_shorewalldir/shorewallrc ]; then
|
|
|
|
. $g_shorewalldir/shorewallrc
|
2013-02-14 19:21:26 +01:00
|
|
|
sbindir="$SBINDIR"
|
|
|
|
confdir="$CONFDIR"
|
|
|
|
libexec="$LIBEXECDIR"
|
2016-11-21 19:00:55 +01:00
|
|
|
litedir="${VARDIR}-lite"
|
2013-02-15 15:46:14 +01:00
|
|
|
. $sharedir/shorewall/shorewallrc
|
2013-02-14 19:21:26 +01:00
|
|
|
else
|
2016-11-21 19:00:55 +01:00
|
|
|
error_message " WARNING: $g_shorewalldir/shorewallrc does not exist; using settings from $g_basedir/shorewalrc" >&2
|
|
|
|
sbindir="$SBINDIR"
|
|
|
|
confdir="$CONFDIR"
|
|
|
|
libexec="$LIBEXECDIR"
|
|
|
|
litedir="${VARDIR}-lite"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
2016-11-21 19:00:55 +01:00
|
|
|
if [ -f $g_shorewalldir/${PRODUCT}.conf ]; then
|
2013-02-22 22:37:31 +01:00
|
|
|
if [ -f $g_shorewalldir/params ]; then
|
|
|
|
. $g_shorewalldir/params
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
ensure_config_path
|
2013-02-23 01:15:41 +01:00
|
|
|
|
|
|
|
get_config No
|
|
|
|
|
|
|
|
g_haveconfig=Yes
|
2016-10-06 00:03:54 +02:00
|
|
|
|
|
|
|
if [ -z "$system" ]; then
|
|
|
|
system=$FIREWALL
|
|
|
|
[ -n "$system" ] || fatal_error "No system name given and the FIREWALL option is not set"
|
|
|
|
fi
|
2013-02-14 19:21:26 +01:00
|
|
|
else
|
2016-11-21 19:00:55 +01:00
|
|
|
fatal_error "$g_shorewalldir/$PRODUCT.conf does not exist"
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
|
|
|
|
2013-02-23 01:15:41 +01:00
|
|
|
if [ -z "$getcaps" ]; then
|
|
|
|
capabilities=$(find_file capabilities)
|
|
|
|
[ -f $capabilities ] || getcaps=Yes
|
|
|
|
fi
|
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
if [ -n "$getcaps" ]; then
|
|
|
|
[ -n "$DONT_LOAD" ] && DONT_LOAD="$(echo $DONT_LOAD | tr ',' ' ')"
|
|
|
|
|
|
|
|
progress_message "Getting Capabilities on system $system..."
|
|
|
|
if [ $g_family -eq 4 ]; then
|
2013-02-22 22:37:31 +01:00
|
|
|
if ! rsh_command "MODULESDIR=$MODULESDIR MODULE_SUFFIX=\"$MODULE_SUFFIX\" IPTABLES=$IPTABLES DONT_LOAD=\"$DONT_LOAD\" $libexec/shorewall-lite/shorecap" > $g_shorewalldir/capabilities; then
|
2011-12-06 21:54:51 +01:00
|
|
|
fatal_error "Capturing capabilities on system $system failed"
|
|
|
|
fi
|
2013-02-22 22:37:31 +01:00
|
|
|
elif ! rsh_command "MODULESDIR=$MODULESDIR MODULE_SUFFIX=\"$MODULE_SUFFIX\" IP6TABLES=$IP6TABLES DONT_LOAD=\"$DONT_LOAD\" $libexec/shorewall6-lite/shorecap" > $g_shorewalldir/capabilities; then
|
2011-12-06 21:54:51 +01:00
|
|
|
fatal_error "Capturing capabilities on system $system failed"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-02-22 22:37:31 +01:00
|
|
|
file=$(resolve_file $g_shorewalldir/firewall)
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2013-02-23 01:15:41 +01:00
|
|
|
g_export=Yes
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2017-01-05 02:12:20 +01:00
|
|
|
program=$sbindir/${PRODUCT}-lite
|
2016-11-21 19:00:55 +01:00
|
|
|
#
|
|
|
|
# Handle nonstandard remote VARDIR
|
|
|
|
#
|
|
|
|
temp=$(rsh_command $program show config 2> /dev/null | grep ^LITEDIR | sed 's/LITEDIR is //')
|
|
|
|
|
2013-09-19 06:05:35 +02:00
|
|
|
[ -n "$temp" ] && litedir="$temp"
|
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
g_file="$g_shorewalldir/firewall"
|
|
|
|
|
2015-11-01 16:53:31 +01:00
|
|
|
exitstatus=0
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2015-11-01 16:53:31 +01:00
|
|
|
if compiler $g_debugging compiler "$g_file"; then
|
|
|
|
progress_message3 "Copying $file and ${file}.conf to ${system}:${litedir}..."
|
|
|
|
if rcp_command "$g_shorewalldir/firewall $g_shorewalldir/firewall.conf" ${litedir}; then
|
|
|
|
save=$(find_file save);
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2015-11-01 16:53:31 +01:00
|
|
|
if [ -f $save ]; then
|
2016-11-21 19:00:55 +01:00
|
|
|
progress_message3 "Copying $save to ${system}:${confdir}/${PRODUCT}-lite/"
|
|
|
|
rcp_command $save ${confdir}/$PRODUCT/
|
2015-11-01 16:53:31 +01:00
|
|
|
exitstatus=$?
|
|
|
|
fi
|
2012-04-07 18:34:32 +02:00
|
|
|
|
2015-11-01 16:53:31 +01:00
|
|
|
if [ $exitstatus -eq 0 ]; then
|
|
|
|
progress_message3 "Copy complete"
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2015-11-01 16:53:31 +01:00
|
|
|
if [ $COMMAND = remote-reload ]; then
|
2016-11-21 19:00:55 +01:00
|
|
|
if rsh_command "$program $g_debugging $verbose $timestamp reload"; then
|
2015-11-01 16:53:31 +01:00
|
|
|
progress_message3 "System $system reloaded"
|
|
|
|
else
|
|
|
|
exitstatus=$?
|
|
|
|
savit=
|
|
|
|
fi
|
|
|
|
elif [ $COMMAND = remote-restart ]; then
|
2016-11-21 19:00:55 +01:00
|
|
|
if rsh_command "$program $g_debugging $verbose $timestamp restart"; then
|
2015-11-01 16:53:31 +01:00
|
|
|
progress_message3 "System $system restarted"
|
|
|
|
else
|
|
|
|
exitstatus=$?
|
|
|
|
saveit=
|
|
|
|
fi
|
2016-11-21 19:00:55 +01:00
|
|
|
elif rsh_command "$program $g_debugging $verbose $timestamp start"; then
|
2015-11-01 16:53:31 +01:00
|
|
|
progress_message3 "System $system started"
|
|
|
|
else
|
|
|
|
exitstatus=$?
|
|
|
|
saveit=
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$saveit" ]; then
|
2016-11-21 19:00:55 +01:00
|
|
|
if rsh_command "$program $g_debugging $verbose $timestamp save"; then
|
2015-11-01 16:53:31 +01:00
|
|
|
progress_message3 "Configuration on system $system saved"
|
|
|
|
else
|
|
|
|
exitstatus=$?
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
exitstatus=$?
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
2015-11-01 16:53:31 +01:00
|
|
|
else
|
|
|
|
exitstatus=$?
|
2011-12-06 21:54:51 +01:00
|
|
|
fi
|
2015-11-01 16:53:31 +01:00
|
|
|
|
|
|
|
return $exitstatus
|
2011-12-06 21:54:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Export command executor
|
|
|
|
#
|
|
|
|
export_command() # $* = original arguments less the command.
|
|
|
|
{
|
|
|
|
local verbose
|
|
|
|
verbose=$(make_verbose)
|
|
|
|
local file
|
|
|
|
file=
|
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
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)
|
2013-02-22 22:37:31 +01:00
|
|
|
g_shorewalldir="."
|
2011-12-06 21:54:51 +01:00
|
|
|
target=$1
|
|
|
|
;;
|
|
|
|
2)
|
2013-02-22 22:37:31 +01:00
|
|
|
g_shorewalldir=$1
|
2011-12-06 21:54:51 +01:00
|
|
|
target=$2
|
|
|
|
;;
|
|
|
|
*)
|
2016-11-21 19:00:55 +01:00
|
|
|
fatal_error "Invalid command syntax (\"man shorewall\" for help)"
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $target in
|
|
|
|
*:*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
target=$target:
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2013-02-22 22:37:31 +01:00
|
|
|
file=$(resolve_file $g_shorewalldir/firewall)
|
2011-12-06 21:54:51 +01:00
|
|
|
|
2013-02-23 01:15:41 +01:00
|
|
|
g_export=Yes
|
|
|
|
|
2015-06-23 01:41:21 +02:00
|
|
|
g_file="$g_shorewalldir/firewall"
|
|
|
|
|
|
|
|
if compiler $g_debugging compile "$g_file" && \
|
2011-12-06 21:54:51 +01:00
|
|
|
echo "Copying $file and ${file}.conf to ${target#*@}..." && \
|
2013-02-22 22:37:31 +01:00
|
|
|
scp $g_shorewalldir/firewall $g_shorewalldir/firewall.conf $target
|
2011-12-06 21:54:51 +01:00
|
|
|
then
|
|
|
|
save=$(find_file save);
|
|
|
|
|
|
|
|
[ -f $save ] && progress_message3 "Copying $save to ${target#*}..." && rcp_command $save $target
|
|
|
|
|
|
|
|
progress_message3 "Copy complete"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-07-29 19:30:07 +02:00
|
|
|
run_command() {
|
|
|
|
if [ -x ${VARDIR}/firewall ] ; then
|
|
|
|
uptodate ${VARDIR}/firewall || echo " WARNING: ${VARDIR}/firewall is not up to date" >&2
|
|
|
|
run_it ${VARDIR}/firewall $g_debugging $@
|
|
|
|
else
|
|
|
|
fatal_error "${VARDIR}/firewall does not exist or is not executable"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-12-06 21:54:51 +01:00
|
|
|
compiler_command() {
|
|
|
|
|
|
|
|
case $COMMAND in
|
2013-08-06 16:05:47 +02:00
|
|
|
compile|co)
|
2011-12-06 21:54:51 +01:00
|
|
|
shift
|
2011-12-09 07:00:48 +01:00
|
|
|
compile_command $@
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
refresh)
|
|
|
|
get_config Yes Yes
|
|
|
|
shift
|
|
|
|
refresh_command $@
|
|
|
|
;;
|
2013-08-06 16:05:47 +02:00
|
|
|
check|ck)
|
2011-12-06 21:54:51 +01:00
|
|
|
shift
|
|
|
|
check_command $@
|
|
|
|
;;
|
|
|
|
update)
|
|
|
|
shift
|
|
|
|
update_command $@
|
|
|
|
;;
|
2015-10-27 04:06:10 +01:00
|
|
|
remote-start|remote-reload|remote-restart)
|
2011-12-06 21:54:51 +01:00
|
|
|
shift
|
2015-07-26 18:59:49 +02:00
|
|
|
remote_reload_command $@
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
export)
|
|
|
|
shift
|
|
|
|
export_command $@
|
|
|
|
;;
|
|
|
|
try)
|
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
try_command $@
|
|
|
|
;;
|
2015-07-26 18:59:49 +02:00
|
|
|
safe-reload|safe-restart|safe-start)
|
2011-12-06 21:54:51 +01:00
|
|
|
get_config Yes
|
|
|
|
shift
|
|
|
|
safe_commands $@
|
|
|
|
;;
|
|
|
|
*)
|
2016-04-27 19:13:24 +02:00
|
|
|
fatal_error "Invalid command: $COMMAND"
|
2011-12-06 21:54:51 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|