From c9512dfaf8cacfda7b4b4eee1c5f9d2020bf74cb Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Thu, 25 Jun 2020 09:23:53 -0700 Subject: [PATCH] Make 'show actions' more robust - Show all lines, including continuation and compiler directives - Show both actions and actions.std entries - The actions file need not reside in /etc/shorewall[6] but may be in any directory on the CONFIG_PATH Signed-off-by: Tom Eastep --- Shorewall-core/lib.cli | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Shorewall-core/lib.cli b/Shorewall-core/lib.cli index 348ea5879..ea8b52700 100644 --- a/Shorewall-core/lib.cli +++ b/Shorewall-core/lib.cli @@ -937,11 +937,28 @@ show_events() { fi } +sort_actions() { + local sep #separates sort keys from the action[.std] record + sep="##" + + awk -v sep="$sep" \ + 'BEGIN { action = ""; ifrec = ""; nr = 0; };\ + /^#/ { next; };\ + /^\?(if|IF|If)/ { ifrec = $0; nr = NR; next; };\ + /^( |\t|\?)/ { if ( action != "" ) print action, NR, sep $0; next; };\ + { action = $1; };\ + nr != 0 { print action , nr, sep ifrec; nr = 0; };\ + { print action , NR, sep $0; }' | sort -k 1,2 | sed "s/^.*${sep}//" +} + show_actions() { - if [ -f ${g_confdir}/actions ]; then - cat ${g_sharedir}/actions.std ${g_confdir}/actions | grep -Ev '^[#?[:space:]]|^$' + local actions + actions=$(find_file actions) + + if [ -f ${actions} ]; then + cat ${actions} ${g_sharedir}/actions.std | sort_actions else - grep -Ev '^[#?[:space:]]|^$' ${g_sharedir}/actions.std + sort_actions < ${g_sharedir}/actions.std fi } @@ -1108,10 +1125,6 @@ show_blacklists() { show_bl; } -show_actions_sorted() { - show_actions | sort -u -k 1,1 -} - show_macros() { for directory in $(split $CONFIG_PATH); do temp= @@ -1543,7 +1556,7 @@ show_command() { ;; actions) [ $# -gt 1 ] && too_many_arguments $2 - eval show_actions_sorted $g_pager + eval show_actions $g_pager return ;; macro)