Page the output of verbose commands

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2016-03-01 15:12:54 -08:00
parent 68cce5ff73
commit a95de8d092
2 changed files with 143 additions and 101 deletions

View File

@ -266,7 +266,7 @@ search_log() # $1 = IP address to search for
# #
# Show traffic control information # Show traffic control information
# #
show_tc() { show_tc1() {
show_one_tc() { show_one_tc() {
local device local device
@ -292,6 +292,19 @@ show_tc() {
} }
show_tc() {
echo "$g_product $SHOREWALL_VERSION Traffic Control at $g_hostname - $(date)"
echo
shift
if [ -z "$1" ]; then
$g_tool -t mangle -L -n -v | $output_filter
echo
fi
show_tc1 $1
}
# #
# Show classifier information # Show classifier information
# #
@ -928,6 +941,66 @@ show_actions() {
grep -Ev '^\#|^$' ${g_sharedir}/actions.std grep -Ev '^\#|^$' ${g_sharedir}/actions.std
fi fi
} }
show_chain() {
echo "$g_product $SHOREWALL_VERSION $([ $# -gt 1 ] && echo "Chains " || [ $# -gt 0 ] && echo "Chain " || echo $table Table)$* at $g_hostname - $(date)"
echo
show_reset
if [ $# -gt 0 ]; then
for chain in $*; do
$g_tool -t $table -L $chain $g_ipt_options | $output_filter
echo
done
else
$g_tool -t $table -L $g_ipt_options | $output_filter
fi
}
show_chains() {
echo "$g_product $SHOREWALL_VERSION $([ $# -gt 1 ] && echo "Chains " || echo "Chain ")$* at $g_hostname - $(date)"
echo
show_reset
for chain in $*; do
$g_tool -t $table -L $chain $g_ipt_options | $output_filter
echo
done
}
show_table() {
echo "$g_product $SHOREWALL_VERSION $table Table at $g_hostname - $(date)"
echo
show_reset
$g_tool -t $table -L $g_ipt_options | $output_filter
}
show_nat() {
echo "$g_product $SHOREWALL_VERSION NAT Table at $g_hostname - $(date)"
echo
show_reset
$g_tool -t nat -L $g_ipt_options | $output_filter
}
show_macros() {
for directory in $(split $CONFIG_PATH); do
temp=
for macro in ${directory}/macro.*; do
case $macro in
*\*)
;;
*)
if [ -z "$temp" ]; then
echo
echo "Macros in $directory:"
echo
temp=Yes
fi
show_macro
;;
esac
done
done
}
# #
# Show Command Executor # Show Command Executor
# #
@ -1084,31 +1157,28 @@ show_command() {
;; ;;
nat) nat)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION NAT Table at $g_hostname - $(date)" eval show_nat $g_pager
echo
show_reset
$g_tool -t nat -L $g_ipt_options | $output_filter
;; ;;
raw) raw)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION RAW Table at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION RAW Table at $g_hostname - $(date)"
echo echo
show_reset show_reset
$g_tool -t raw -L $g_ipt_options | $output_filter $g_tool -t raw -L $g_ipt_options | $output_filter } $g_pager
;; ;;
rawpost) rawpost)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION RAWPOST Table at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION RAWPOST Table at $g_hostname - $(date)"
echo echo
show_reset show_reset
$g_tool -t rawpost -L $g_ipt_options | $output_filter $g_tool -t rawpost -L $g_ipt_options | $output_filter } $g_pager
;; ;;
tos|mangle) tos|mangle)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION Mangle Table at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION Mangle Table at $g_hostname - $(date)"
echo echo
show_reset show_reset
$g_tool -t mangle -L $g_ipt_options | $output_filter $g_tool -t mangle -L $g_ipt_options | $output_filter } $g_pager
;; ;;
log) log)
[ $# -gt 2 ] && usage 1 [ $# -gt 2 ] && usage 1
@ -1128,22 +1198,13 @@ show_command() {
;; ;;
tc) tc)
[ $# -gt 2 ] && usage 1 [ $# -gt 2 ] && usage 1
echo "$g_product $SHOREWALL_VERSION Traffic Control at $g_hostname - $(date)" eval show_tc $g_pager
echo
shift
if [ -z "$1" ]; then
$g_tool -t mangle -L -n -v | $output_filter
echo
fi
show_tc $1
;; ;;
classifiers|filters) classifiers|filters)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION Classifiers at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION Classifiers at $g_hostname - $(date)"
echo echo
show_classifiers show_classifiers } $g_pager
;; ;;
zones) zones)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
@ -1173,22 +1234,22 @@ show_command() {
determine_capabilities determine_capabilities
VERBOSITY=2 VERBOSITY=2
if [ -n "$g_filemode" ]; then if [ -n "$g_filemode" ]; then
report_capabilities1 eval report_capabilities1 $g_pager
else else
report_capabilities eval report_capabilities $g_pager
fi fi
;; ;;
ip) ip)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION IP at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION IP at $g_hostname - $(date)"
echo echo
ip -$g_family addr list ip -$g_family addr list } $g_pager
;; ;;
routing) routing)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION Routing at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION Routing at $g_hostname - $(date)"
echo echo
show_routing show_routing } $g_pager
;; ;;
config) config)
. ${g_sharedir}/configpath . ${g_sharedir}/configpath
@ -1210,33 +1271,23 @@ show_command() {
;; ;;
chain) chain)
shift shift
echo "$g_product $SHOREWALL_VERSION $([ $# -gt 1 ] && echo "Chains " || [ $# -gt 0 ] && echo "Chain " || echo $table Table)$* at $g_hostname - $(date)" eval show_chain $@ $g_pager
echo
show_reset
if [ $# -gt 0 ]; then
for chain in $*; do
$g_tool -t $table -L $chain $g_ipt_options | $output_filter
echo
done
else
$g_tool -t $table -L $g_ipt_options | $output_filter
fi
;; ;;
vardir) vardir)
echo $VARDIR; echo $VARDIR;
;; ;;
policies) policies)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION Policies at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION Policies at $g_hostname - $(date)"
echo echo
[ -f ${VARDIR}/policies ] && cat ${VARDIR}/policies; [ -f ${VARDIR}/policies ] && cat ${VARDIR}/policies } $g_pager
;; ;;
ipa) ipa)
[ $g_family -eq 4 ] || usage 1 [ $g_family -eq 4 ] || usage 1
echo "$g_product $SHOREWALL_VERSION per-IP Accounting at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION per-IP Accounting at $g_hostname - $(date)"
echo echo
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
perip_accounting perip_accounting } $g_pager
;; ;;
marks) marks)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
@ -1246,17 +1297,17 @@ show_command() {
;; ;;
nfacct) nfacct)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION NF Accounting at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION NF Accounting at $g_hostname - $(date)"
echo echo
show_nfacct show_nfacct } $g_pager
;; ;;
arptables) arptables)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
resolve_arptables resolve_arptables
if [ -n "$arptables" -a -x $arptables ]; then if [ -n "$arptables" -a -x $arptables ]; then
echo "$g_product $SHOREWALL_VERSION arptables at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION arptables at $g_hostname - $(date)"
echo echo
$arptables -L -n -v $arptables -L -n -v } $g_pager
else else
error_message "Cannot locate the arptables executable" error_message "Cannot locate the arptables executable"
fi fi
@ -1270,9 +1321,9 @@ show_command() {
;; ;;
events) events)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
echo "$g_product $SHOREWALL_VERSION events at $g_hostname - $(date)" eval { echo "$g_product $SHOREWALL_VERSION events at $g_hostname - $(date)"
echo echo
show_events show_events } $g_pager
;; ;;
bl|blacklists) bl|blacklists)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
@ -1298,7 +1349,7 @@ show_command() {
case $1 in case $1 in
actions) actions)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
show_actions | sort eval show_actions | sort $pager
return return
;; ;;
macro) macro)
@ -1315,25 +1366,7 @@ show_command() {
;; ;;
macros) macros)
[ $# -gt 1 ] && usage 1 [ $# -gt 1 ] && usage 1
eval show_macros $g_pager
for directory in $(split $CONFIG_PATH); do
temp=
for macro in ${directory}/macro.*; do
case $macro in
*\*)
;;
*)
if [ -z "$temp" ]; then
echo
echo "Macros in $directory:"
echo
temp=Yes
fi
show_macro
;;
esac
done
done
return return
;; ;;
esac esac
@ -1355,18 +1388,9 @@ show_command() {
fi fi
done done
echo "$g_product $SHOREWALL_VERSION $([ $# -gt 1 ] && echo "Chains " || echo "Chain ")$* at $g_hostname - $(date)" eval show_chains $@ $g_pager
echo
show_reset
for chain in $*; do
$g_tool -t $table -L $chain $g_ipt_options | $output_filter
echo
done
else else
echo "$g_product $SHOREWALL_VERSION $table Table at $g_hostname - $(date)" eval show_table $g_pager
echo
show_reset
$g_tool -t $table -L $g_ipt_options | $output_filter
fi fi
;; ;;
esac esac
@ -1417,12 +1441,16 @@ dump_filter() {
;; ;;
esac esac
$command $filter eval $command $filter $g_pager
else else
cat - cat -
fi fi
} }
dump_filter_wrapper() {
eval dump_filter $g_pager
}
# #
# Dump Command Executor # Dump Command Executor
# #
@ -1633,14 +1661,14 @@ do_dump_command() {
if [ -n "$TC_ENABLED" ]; then if [ -n "$TC_ENABLED" ]; then
heading "Traffic Control" heading "Traffic Control"
show_tc show_tc1
heading "TC Filters" heading "TC Filters"
show_classifiers show_classifiers
fi fi
} }
dump_command() { dump_command() {
do_dump_command $@ | dump_filter do_dump_command $@ | dump_filter_wrapper
} }
# #
@ -4040,6 +4068,7 @@ shorewall_cli() {
g_counters= g_counters=
g_loopback= g_loopback=
g_compiled= g_compiled=
g_pager=
VERBOSE= VERBOSE=
VERBOSITY=1 VERBOSITY=1
@ -4194,6 +4223,19 @@ shorewall_cli() {
;; ;;
esac esac
if [ -t 1 ]; then
#
# Output is to a terminal -- use a pager on commands with verbose output
#
if qt mywhich less; then
g_pager='| less'
elif qt mywhich more; then
g_pager='| more'
else
g_pager=''
fi
fi
COMMAND=$1 COMMAND=$1
case "$COMMAND" in case "$COMMAND" in

View File

@ -6438,7 +6438,7 @@ sub generate_aux_config() {
if ( -f $fn ) { if ( -f $fn ) {
emit( '', emit( '',
'dump_filter() {' ); 'dump_filter1() {' );
push_indent; push_indent;
append_file( $fn,1 ) or emit 'cat -'; append_file( $fn,1 ) or emit 'cat -';
pop_indent; pop_indent;