diff --git a/Shorewall-lite/shorewall-lite b/Shorewall-lite/shorewall-lite index 8202d9d77..600db46ad 100755 --- a/Shorewall-lite/shorewall-lite +++ b/Shorewall-lite/shorewall-lite @@ -634,57 +634,7 @@ case "$COMMAND" in hits) [ -n "$debugging" ] && set -x [ $# -eq 1 ] || usage 1 - clear_term - echo "Shorewall Lite $version Hits at $HOSTNAME - $(date)" - echo - - timeout=30 - - if [ $(grep -c "$LOGFORMAT" $LOGFILE ) -gt 0 ] ; then - echo " HITS IP DATE" - echo " ---- --------------- ------" - grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn | \ - while read count address month day; do - printf '%7d %-15s %3s %2d\n' $count $address $month $day - done - - echo "" - - echo " HITS IP PORT" - echo " ---- --------------- -----" - grep "$LOGFORMAT" $LOGFILE | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/ - t - s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn | \ - while read count address port; do - printf '%7d %-15s %d\n' $count $address $port - done - - echo "" - - echo " HITS DATE" - echo " ---- ------" - grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn | \ - while read count month day; do - printf '%7d %3s %2d\n' $count $month $day - done - - echo "" - - echo " HITS PORT SERVICE(S)" - echo " ---- ----- ----------" - grep "$LOGFORMAT.*DPT" $LOGFILE | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | \ - while read count port ; do - # List all services defined for the given port - srv=$(grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | cut -f 1 -d' ' | sort -u) - srv=$(echo $srv | sed 's/ /,/g') - - if [ -n "$srv" ] ; then - printf '%7d %5d %s\n' $count $port $srv - else - printf '%7d %5d\n' $count $port - fi - done - fi + hits_command ;; version) echo $version Lite diff --git a/Shorewall/lib.cli b/Shorewall/lib.cli index dd607eaae..03390bda6 100644 --- a/Shorewall/lib.cli +++ b/Shorewall/lib.cli @@ -824,3 +824,57 @@ block() # $1 = command, $2 = Finished, $3 = Original Command $4 - $n addresses shift done } + +hits_command() { + clear_term + echo "Shorewall-$version Hits at $HOSTNAME - $(date)" + echo + + timeout=30 + + if [ $(grep -c 'IN=.* OUT=' $LOGFILE ) -gt 0 ] ; then + echo " HITS IP DATE" + echo " ---- --------------- ------" + grep 'IN=.* OUT=' $LOGFILE | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn | \ + while read count address month day; do + printf '%7d %-15s %3s %2d\n' $count $address $month $day + done + + echo "" + + echo " HITS IP PORT" + echo " ---- --------------- -----" + grep 'IN=.* OUT=' $LOGFILE | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/ + t + s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn | \ + while read count address port; do + printf '%7d %-15s %d\n' $count $address $port + done + + echo "" + + echo " HITS DATE" + echo " ---- ------" + grep 'IN=.* OUT=' $LOGFILE | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn | \ + while read count month day; do + printf '%7d %3s %2d\n' $count $month $day + done + + echo "" + + echo " HITS PORT SERVICE(S)" + echo " ---- ----- ----------" + grep 'IN=.* OUT=.*DPT' $LOGFILE | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | \ + while read count port ; do + # List all services defined for the given port + srv=$(grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | cut -f 1 -d' ' | sort -u) + srv=$(echo $srv | sed 's/ /,/g') + + if [ -n "$srv" ] ; then + printf '%7d %5d %s\n' $count $port $srv + else + printf '%7d %5d\n' $count $port + fi + done + fi +} diff --git a/Shorewall/shorewall b/Shorewall/shorewall index b02306419..918da3ce5 100755 --- a/Shorewall/shorewall +++ b/Shorewall/shorewall @@ -1176,57 +1176,7 @@ case "$COMMAND" in hits) [ -n "$debugging" ] && set -x [ $# -eq 1 ] || usage 1 - clear_term - echo "Shorewall-$version Hits at $HOSTNAME - $(date)" - echo - - timeout=30 - - if [ $(grep -c "$LOGFORMAT" $LOGFILE ) -gt 0 ] ; then - echo " HITS IP DATE" - echo " ---- --------------- ------" - grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn | \ - while read count address month day; do - printf '%7d %-15s %3s %2d\n' $count $address $month $day - done - - echo "" - - echo " HITS IP PORT" - echo " ---- --------------- -----" - grep "$LOGFORMAT" $LOGFILE | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/ - t - s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn | \ - while read count address port; do - printf '%7d %-15s %d\n' $count $address $port - done - - echo "" - - echo " HITS DATE" - echo " ---- ------" - grep "$LOGFORMAT" $LOGFILE | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn | \ - while read count month day; do - printf '%7d %3s %2d\n' $count $month $day - done - - echo "" - - echo " HITS PORT SERVICE(S)" - echo " ---- ----- ----------" - grep "$LOGFORMAT.*DPT" $LOGFILE | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | \ - while read count port ; do - # List all services defined for the given port - srv=$(grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | cut -f 1 -d' ' | sort -u) - srv=$(echo $srv | sed 's/ /,/g') - - if [ -n "$srv" ] ; then - printf '%7d %5d %s\n' $count $port $srv - else - printf '%7d %5d\n' $count $port - fi - done - fi + hits_command ;; version) echo $version