mirror of
https://gitlab.com/shorewall/code.git
synced 2025-02-18 18:51:00 +01:00
Implement the 'up' and 'down' script commands
Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
parent
ff388ca5c4
commit
a3589dc6e9
@ -865,6 +865,11 @@ sub compiler {
|
|||||||
#
|
#
|
||||||
compile_stop_firewall( $test, $export );
|
compile_stop_firewall( $test, $export );
|
||||||
#
|
#
|
||||||
|
# U P D O W N
|
||||||
|
# (Writes the updown() function to the compiled script)
|
||||||
|
#
|
||||||
|
compile_updown;
|
||||||
|
#
|
||||||
# Copy the footer to the script
|
# Copy the footer to the script
|
||||||
#
|
#
|
||||||
unless ( $test ) {
|
unless ( $test ) {
|
||||||
|
@ -70,6 +70,7 @@ our @EXPORT = qw( NOTHING
|
|||||||
get_interface_option
|
get_interface_option
|
||||||
set_interface_option
|
set_interface_option
|
||||||
verify_required_interfaces
|
verify_required_interfaces
|
||||||
|
compile_updown
|
||||||
validate_hosts_file
|
validate_hosts_file
|
||||||
find_hosts_by_option
|
find_hosts_by_option
|
||||||
all_ipsets
|
all_ipsets
|
||||||
@ -816,6 +817,8 @@ sub process_interface( $$ ) {
|
|||||||
|
|
||||||
my $hostoptionsref = {};
|
my $hostoptionsref = {};
|
||||||
|
|
||||||
|
$options{ignore} = 1, $options = '-' if $options eq 'ignore';
|
||||||
|
|
||||||
if ( $options ne '-' ) {
|
if ( $options ne '-' ) {
|
||||||
|
|
||||||
my %hostoptions = ( dynamic => 0 );
|
my %hostoptions = ( dynamic => 0 );
|
||||||
@ -1225,6 +1228,91 @@ sub verify_required_interfaces() {
|
|||||||
$returnvalue;
|
$returnvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Emit the updown() function
|
||||||
|
#
|
||||||
|
sub compile_updown() {
|
||||||
|
emit( '',
|
||||||
|
'#',
|
||||||
|
'# Handle the "up" and "down" commands',
|
||||||
|
'#',
|
||||||
|
'updown() # $1 = interface',
|
||||||
|
'{',
|
||||||
|
);
|
||||||
|
|
||||||
|
push_indent;
|
||||||
|
|
||||||
|
emit( 'case $1 in' );
|
||||||
|
|
||||||
|
push_indent;
|
||||||
|
|
||||||
|
my $ignore = find_interfaces_by_option 'ignore';
|
||||||
|
my $required = find_interfaces_by_option 'required';
|
||||||
|
|
||||||
|
if ( @$ignore ) {
|
||||||
|
my $interfaces = join '|', map $interfaces{$_}->{physical}, @$ignore;
|
||||||
|
|
||||||
|
$interfaces =~ s/\+/*/;
|
||||||
|
|
||||||
|
emit( "$interfaces)",
|
||||||
|
' exit 0',
|
||||||
|
' ;;'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( @$required ) {
|
||||||
|
my $interfaces = join '|', map $interfaces{$_}->{physical}, @$required;
|
||||||
|
|
||||||
|
$interfaces =~ s/\+/*/;
|
||||||
|
|
||||||
|
emit( "$interfaces)",
|
||||||
|
' if [ "$COMMAND" = up ]; then',
|
||||||
|
' if shorewall_is_started; then',
|
||||||
|
' COMMAND=restart',
|
||||||
|
' else',
|
||||||
|
' COMMAND=start',
|
||||||
|
' fi',
|
||||||
|
'',
|
||||||
|
' detect_configuration',
|
||||||
|
' define_firewall',
|
||||||
|
' else',
|
||||||
|
' COMMAND=close',
|
||||||
|
' detect_configuration',
|
||||||
|
' stop_firewall',
|
||||||
|
' fi',
|
||||||
|
' ;;'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit( "*)",
|
||||||
|
' if [ "$COMMAND" = up ]; then',
|
||||||
|
' if shorewall_is_started; then',
|
||||||
|
' COMMAND=restart',
|
||||||
|
' else',
|
||||||
|
' COMMAND=start',
|
||||||
|
' fi',
|
||||||
|
'',
|
||||||
|
' detect_configuration',
|
||||||
|
' define_firewall',
|
||||||
|
' elif shorewall_is_started; then',
|
||||||
|
' COMMAND=restart',
|
||||||
|
' detect_configuration',
|
||||||
|
' define_firewall',
|
||||||
|
' fi',
|
||||||
|
' ;;'
|
||||||
|
);
|
||||||
|
|
||||||
|
pop_indent;
|
||||||
|
|
||||||
|
emit( 'esac' );
|
||||||
|
|
||||||
|
pop_indent;
|
||||||
|
|
||||||
|
emit( '}',
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Process a record in the hosts file
|
# Process a record in the hosts file
|
||||||
#
|
#
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# Give Usage Information
|
# Give Usage Information
|
||||||
#
|
#
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 [ options ] [ start|stop|close|clear|reset|refresh|restart|status|version ]"
|
echo "Usage: $0 [ options ] [ start|stop|close|clear|down|reset|refresh|restart|status|up|version ]"
|
||||||
echo
|
echo
|
||||||
echo "Options are:"
|
echo "Options are:"
|
||||||
echo
|
echo
|
||||||
@ -285,7 +285,7 @@ case "$COMMAND" in
|
|||||||
if [ -f ${VARDIR}/state ]; then
|
if [ -f ${VARDIR}/state ]; then
|
||||||
state="$(cat ${VARDIR}/state)"
|
state="$(cat ${VARDIR}/state)"
|
||||||
case $state in
|
case $state in
|
||||||
Stopped*|Clear*)
|
Stopped*|Closed*|lClear*)
|
||||||
status=3
|
status=3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -295,6 +295,13 @@ case "$COMMAND" in
|
|||||||
echo "State:$state"
|
echo "State:$state"
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
|
up|down)
|
||||||
|
[ $# -eq 1 ] && exit 0
|
||||||
|
shift
|
||||||
|
[ $# -ne 1 ] && usage 2
|
||||||
|
updown $@
|
||||||
|
status=0;
|
||||||
|
;;
|
||||||
version)
|
version)
|
||||||
[ $# -ne 1 ] && usage 2
|
[ $# -ne 1 ] && usage 2
|
||||||
echo $SHOREWALL_VERSION
|
echo $SHOREWALL_VERSION
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# Give Usage Information
|
# Give Usage Information
|
||||||
#
|
#
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: $0 [ options ] [ start|stop|close|clear|reset|refresh|restart|status|version ]"
|
echo "Usage: $0 [ options ] [ start|stop|close|clear|down|reset|refresh|restart|status|up|version ]"
|
||||||
echo
|
echo
|
||||||
echo "Options are:"
|
echo "Options are:"
|
||||||
echo
|
echo
|
||||||
@ -286,7 +286,7 @@ else
|
|||||||
if [ -f ${VARDIR}/state ]; then
|
if [ -f ${VARDIR}/state ]; then
|
||||||
state="$(cat ${VARDIR}/state)"
|
state="$(cat ${VARDIR}/state)"
|
||||||
case $state in
|
case $state in
|
||||||
Stopped*|Clear*)
|
Stopped*|Closed*|Clear*)
|
||||||
status=3
|
status=3
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -296,6 +296,13 @@ else
|
|||||||
echo "State:$state"
|
echo "State:$state"
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
|
up|down)
|
||||||
|
[ $# -eq 1 ] && exit 0
|
||||||
|
shift
|
||||||
|
[ $# -ne 1 ] && usage 2
|
||||||
|
updown $1
|
||||||
|
status=0
|
||||||
|
;;
|
||||||
version)
|
version)
|
||||||
[ $# -ne 1 ] && usage 2
|
[ $# -ne 1 ] && usage 2
|
||||||
echo $SHOREWALL_VERSION
|
echo $SHOREWALL_VERSION
|
||||||
|
Loading…
Reference in New Issue
Block a user