#
# Shorewall 1.1 -- /etc/shorewall/functions

#
# Suppress all output for a command
#    
qt()  
{ 
    "$@" >/dev/null 2>&1
}
#
# Poor Man's grep -- Some LRP systems have a grep that simply searches for
#                    strings rather than regular expressions. When we are
#                    really looking for regular expressions, we use this one
#
mygrep () 
{
    local pat
    pat="$1"
    shift
    sed "\'$pat'P" -n "$@"
}
#
# Replace commas with spaces and echo the result
#
separate_list()
{
    echo $1 | sed 's/,/ /g'
}
#
# Replace leading "!" with "! " in the passed argument and echo result
#
handle_bang()
{
    echo $1 | sed 's/^!/! /'
}
#
# Find the zones
#
find_zones() 
{
    while read zone display comments; do
	[ -n "$zone" ] && case "$zone" in
	    \#*)
		;;
            *)
		echo $zone
		;;
        esac
    done < /etc/shorewall/zones
}

find_display() # $1 = zone
{
    mygrep ^$1 /etc/shorewall/zones | while read z display comments; do
	[ "x$1" = "x$z" ] && echo $display
    done
}

determine_zones() 
{
    if [ -f /etc/shorewall/zones ]; then
	zones=`find_zones`
	zones=`echo $zones` # Remove extra trash
	zonepattern="^$zones"

	while [ "$zonepattern" != "${zonepattern% *}" ]; do
	    zonepattern="`echo "$zonepattern" | sed 's/ /\\\|^/'`"
	done

	for zone in $zones; do
	    dsply=`find_display $zone`
	    eval ${zone}_display=\$dsply
        done
    else
	zones="net local dmz gw"
	zonepattern="^net\|^local\|^dmz\|^gw"
	net_display=Net
	local_display=Local
	dmz_display=DMZ
	gw_display=Gateway
    fi
}
