2009-03-02 04:25:16 +01:00
|
|
|
###############################################################################
|
|
|
|
# Code imported from /usr/share/shorewall/prog.footer
|
|
|
|
###############################################################################
|
2009-02-22 18:30:14 +01:00
|
|
|
#
|
|
|
|
# Give Usage Information
|
|
|
|
#
|
|
|
|
usage() {
|
|
|
|
echo "Usage: $0 [ -q ] [ -v ] [ -n ] [ start|stop|clear|reset|refresh|restart|status|version ]"
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
# E X E C U T I O N B E G I N S H E R E #
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Start trace if first arg is "debug" or "trace"
|
|
|
|
#
|
2009-08-20 23:32:15 +02:00
|
|
|
if [ $# -gt 1 ]; then
|
2009-02-22 18:30:14 +01:00
|
|
|
if [ "x$1" = "xtrace" ]; then
|
|
|
|
set -x
|
|
|
|
shift
|
|
|
|
elif [ "x$1" = "xdebug" ]; then
|
|
|
|
DEBUG=Yes
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
fi
|
2010-03-01 17:32:59 +01:00
|
|
|
#
|
|
|
|
# Map VERBOSE to VERBOSITY for compatibility with old Shorewall-lite installations
|
|
|
|
#
|
2010-03-01 15:57:04 +01:00
|
|
|
[ -z "$VERBOSITY" ] && [ -n "$VERBOSE" ] && VERBOSITY=$VERBOSE
|
2010-03-01 02:58:01 +01:00
|
|
|
|
2009-02-22 18:30:14 +01:00
|
|
|
initialize
|
|
|
|
|
2009-06-05 22:49:23 +02:00
|
|
|
if [ -n "$STARTUP_LOG" ]; then
|
2009-11-03 18:34:21 +01:00
|
|
|
touch $STARTUP_LOG
|
|
|
|
chmod 0600 $STARTUP_LOG
|
2009-06-07 17:07:56 +02:00
|
|
|
if [ ${SHOREWALL_INIT_SCRIPT:-0} -eq 1 ]; then
|
2009-06-05 22:49:23 +02:00
|
|
|
#
|
|
|
|
# We're being run by a startup script that isn't redirecting STDOUT
|
|
|
|
# Redirect it to the log
|
|
|
|
#
|
2009-06-07 17:07:56 +02:00
|
|
|
exec 2>>$STARTUP_LOG
|
2009-06-05 22:49:23 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2009-02-22 18:30:14 +01:00
|
|
|
finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
[ -z "$option" ] && usage 1
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
v*)
|
2010-03-01 02:58:01 +01:00
|
|
|
VERBOSITY=$(($VERBOSITY + 1 ))
|
2009-02-22 18:30:14 +01:00
|
|
|
option=${option#v}
|
|
|
|
;;
|
|
|
|
q*)
|
2010-03-01 02:58:01 +01:00
|
|
|
VERBOSITY=$(($VERBOSITY - 1 ))
|
2009-02-22 18:30:14 +01:00
|
|
|
option=${option#q}
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
2010-03-01 00:25:25 +01:00
|
|
|
t*)
|
|
|
|
TIMESTAMP=Yes
|
|
|
|
option=${option#t}
|
|
|
|
;;
|
|
|
|
r*)
|
|
|
|
RECOVERING=Yes
|
|
|
|
option=${option#r}
|
|
|
|
;;
|
|
|
|
V*)
|
|
|
|
option=${option#V}
|
2010-03-01 01:42:50 +01:00
|
|
|
|
|
|
|
if [ -z "$option" -a $# -gt 0 ]; then
|
|
|
|
shift
|
|
|
|
option=$1
|
|
|
|
fi
|
|
|
|
|
2010-03-01 00:25:25 +01:00
|
|
|
if [ -n "$option" ]; then
|
|
|
|
case $option in
|
|
|
|
-1|0|1|2)
|
2010-03-01 02:58:01 +01:00
|
|
|
VERBOSITY=$option
|
2010-03-01 00:25:25 +01:00
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
2010-03-01 01:42:50 +01:00
|
|
|
startup_error "Invalid -V option value ($option)"
|
2010-03-01 00:25:25 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
2010-03-01 01:42:50 +01:00
|
|
|
startup_error "Missing -V option value"
|
2010-03-01 00:25:25 +01:00
|
|
|
fi
|
|
|
|
;;
|
2009-02-22 18:30:14 +01:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
COMMAND="$1"
|
|
|
|
|
|
|
|
case "$COMMAND" in
|
|
|
|
start)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
|
|
|
if shorewall_is_started; then
|
|
|
|
error_message "$PRODUCT is already Running"
|
|
|
|
status=0
|
|
|
|
else
|
|
|
|
progress_message3 "Starting $PRODUCT...."
|
2009-10-15 22:06:04 +02:00
|
|
|
detect_configuration
|
2009-02-22 18:30:14 +01:00
|
|
|
define_firewall
|
|
|
|
status=$?
|
|
|
|
[ -n "$SUBSYSLOCK" -a $status -eq 0 ] && touch $SUBSYSLOCK
|
|
|
|
progress_message3 "done."
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
|
|
|
progress_message3 "Stopping $PRODUCT...."
|
2009-10-15 22:06:04 +02:00
|
|
|
detect_configuration
|
2009-02-22 18:30:14 +01:00
|
|
|
stop_firewall
|
|
|
|
status=0
|
|
|
|
[ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK
|
|
|
|
progress_message3 "done."
|
|
|
|
;;
|
|
|
|
reset)
|
|
|
|
if ! shorewall_is_started ; then
|
|
|
|
error_message "$PRODUCT is not running"
|
|
|
|
status=2
|
|
|
|
elif [ $# -eq 1 ]; then
|
|
|
|
$IPTABLES -Z
|
|
|
|
$IPTABLES -t nat -Z
|
|
|
|
$IPTABLES -t mangle -Z
|
|
|
|
date > ${VARDIR}/restarted
|
|
|
|
status=0
|
|
|
|
progress_message3 "$PRODUCT Counters Reset"
|
|
|
|
else
|
|
|
|
shift
|
|
|
|
status=0
|
|
|
|
for chain in $@; do
|
|
|
|
if chain_exists $chain; then
|
|
|
|
if qt $IPTABLES -Z $chain; then
|
|
|
|
progress_message3 "Filter $chain Counters Reset"
|
|
|
|
else
|
|
|
|
error_message "ERROR: Reset of chain $chain failed"
|
|
|
|
status=2
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
error_message "WARNING: Filter Chain $chain does not exist"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
|
|
|
if shorewall_is_started; then
|
|
|
|
progress_message3 "Restarting $PRODUCT...."
|
|
|
|
else
|
|
|
|
error_message "$PRODUCT is not running"
|
|
|
|
progress_message3 "Starting $PRODUCT...."
|
|
|
|
fi
|
|
|
|
|
2009-10-15 22:06:04 +02:00
|
|
|
detect_configuration
|
2009-02-22 18:30:14 +01:00
|
|
|
define_firewall
|
|
|
|
status=$?
|
|
|
|
if [ -n "$SUBSYSLOCK" ]; then
|
|
|
|
[ $status -eq 0 ] && touch $SUBSYSLOCK || rm -f $SUBSYSLOCK
|
|
|
|
fi
|
|
|
|
progress_message3 "done."
|
|
|
|
;;
|
|
|
|
refresh)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
|
|
|
if shorewall_is_started; then
|
|
|
|
progress_message3 "Refreshing $PRODUCT...."
|
2009-10-15 22:06:04 +02:00
|
|
|
detect_configuration
|
2009-02-22 18:30:14 +01:00
|
|
|
define_firewall
|
|
|
|
status=$?
|
|
|
|
progress_message3 "done."
|
|
|
|
else
|
|
|
|
echo "$PRODUCT is not running" >&2
|
|
|
|
status=2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
restore)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
2009-10-15 22:06:04 +02:00
|
|
|
detect_configuration
|
2009-02-22 18:30:14 +01:00
|
|
|
define_firewall
|
|
|
|
status=$?
|
|
|
|
if [ -n "$SUBSYSLOCK" ]; then
|
|
|
|
[ $status -eq 0 ] && touch $SUBSYSLOCK || rm -f $SUBSYSLOCK
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
clear)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
|
|
|
progress_message3 "Clearing $PRODUCT...."
|
|
|
|
clear_firewall
|
|
|
|
status=0
|
|
|
|
[ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK
|
|
|
|
progress_message3 "done."
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
2010-03-02 20:45:35 +01:00
|
|
|
echo "$PRODUCT-$SHORWEALL_VERSION Status at $(hostname) - $(date)"
|
2009-02-22 18:30:14 +01:00
|
|
|
echo
|
|
|
|
if shorewall_is_started; then
|
|
|
|
echo "$PRODUCT is running"
|
|
|
|
status=0
|
|
|
|
else
|
|
|
|
echo "$PRODUCT is stopped"
|
|
|
|
status=4
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f ${VARDIR}/state ]; then
|
|
|
|
state="$(cat ${VARDIR}/state)"
|
|
|
|
case $state in
|
|
|
|
Stopped*|Clear*)
|
|
|
|
status=3
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
state=Unknown
|
|
|
|
fi
|
|
|
|
echo "State:$state"
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
version)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
2010-03-02 17:02:10 +01:00
|
|
|
echo $SHOREWALL_VERSION
|
2009-02-22 18:30:14 +01:00
|
|
|
status=0
|
|
|
|
;;
|
|
|
|
help)
|
|
|
|
[ $# -ne 1 ] && usage 2
|
|
|
|
usage 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $status
|