############################################################################### # Code imported from /usr/share/shorewall/prog.footer6 ############################################################################### # # 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" # if [ $# -gt 1 ]; then if [ "x$1" = "xtrace" ]; then set -x shift elif [ "x$1" = "xdebug" ]; then DEBUG=Yes shift fi fi # # Map VERBOSE to VERBOSITY for compatibility with old Shorewall6-lite installations # [ -z "$VERBOSITY" ] && [ -n "$VERBOSE" ] && VERBOSITY=$VERBOSE initialize if [ -n "$STARTUP_LOG" ]; then touch $STARTUP_LOG chmod 0600 $STARTUP_LOG if [ ${SHOREWALL_INIT_SCRIPT:-0} -eq 1 ]; then # # We're being run by a startup script that isn't redirecting STDOUT # Redirect it to the log # exec 2>>$STARTUP_LOG fi fi 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*) VERBOSITY=$(($VERBOSITY + 1 )) option=${option#v} ;; q*) VERBOSITY=$(($VERBOSITY - 1 )) option=${option#q} ;; n*) NOROUTES=Yes option=${option#n} ;; t*) TIMESTAMP=Yes option=${option#t} ;; p*) PURGE=Yes option=${option#p} ;; r*) RECOVERING=Yes option=${option#r} ;; V*) option=${option#V} if [ -z "$option" -a $# -gt 0 ]; then shift option=$1 fi if [ -n "$option" ]; then case $option in -1|0|1|2) VERBOSITY=$option option= ;; *) startup_error "Invalid -V option value ($option)" ;; esac else startup_error "Missing -V option value" fi ;; R*) option=${option#R} if [ -z "$option" -a $# -gt 0 ]; then shift option=$1 fi if [ -n "$option" ]; then case $option in */*) startup_error "-R must specify a simple file name: $option" ;; .safe|.try|NONE) ;; .*) error_message "ERROR: Reserved File Name: $RESTOREFILE" exit 2 ;; esac else startup_error "Missing -R option value" fi RESTOREFILE=$option option= ;; esac done shift ;; *) finished=1 ;; esac done COMMAND="$1" kernel=$(printf "%2d%02d%02d" $(uname -r 2> /dev/null | sed -e 's/-.*//' -e 's/^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/\1 \2 \3/g')) if [ $kernel -lt 20624 ]; then error_message "ERROR: $g_product requires Linux kernel 2.6.24 or later" status=2 else case "$COMMAND" in start) [ $# -ne 1 ] && usage 2 if shorewall6_is_started; then error_message "$g_product is already Running" status=0 else progress_message3 "Starting $g_product...." detect_configuration define_firewall status=$? [ -n "$SUBSYSLOCK" -a $status -eq 0 ] && touch $SUBSYSLOCK progress_message3 "done." fi ;; stop) [ $# -ne 1 ] && usage 2 progress_message3 "Stopping $g_product...." detect_configuration stop_firewall status=0 [ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK progress_message3 "done." ;; reset) if ! shorewall6_is_started ; then error_message "$g_product is not running" status=2 elif [ $# -eq 1 ]; then $IP6TABLES -Z $IP6TABLES -t mangle -Z date > ${VARDIR}/restarted status=0 progress_message3 "$g_product Counters Reset" else shift status=0 for chain in $@; do if chain_exists $chain; then if qt $IP6TABLES -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 shorewall6_is_started; then progress_message3 "Restarting $g_product...." else error_message "$g_product is not running" progress_message3 "Starting $g_product...." fi detect_configuration 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 shorewall6_is_started; then progress_message3 "Refreshing $g_product...." detect_configuration define_firewall status=$? progress_message3 "done." else echo "$g_product is not running" >&2 status=2 fi ;; restore) [ $# -ne 1 ] && usage 2 detect_configuration define_firewall status=$? if [ -n "$SUBSYSLOCK" ]; then [ $status -eq 0 ] && touch $SUBSYSLOCK || rm -f $SUBSYSLOCK fi ;; clear) [ $# -ne 1 ] && usage 2 progress_message3 "Clearing $g_product...." clear_firewall status=0 [ -n "$SUBSYSLOCK" ] && rm -f $SUBSYSLOCK progress_message3 "done." ;; status) [ $# -ne 1 ] && usage 2 echo "$g_product-$SHOREWALL_VERSION Status at $(hostname) - $(date)" echo if shorewall6_is_started; then echo "$g_product is running" status=0 else echo "$g_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 echo $SHOREWALL_VERSION status=0 ;; help) [ $# -ne 1 ] && usage 2 usage 0 ;; *) usage 2 ;; esac fi exit $status