From ca0198b167dcfa8682fa866c2cd7a22b604e0586 Mon Sep 17 00:00:00 2001 From: lars Date: Wed, 18 May 2005 17:53:05 +0000 Subject: [PATCH] traffic counter interface added --- web-splash/CHANGELOG | 4 ++++ web-splash/ipkg/control | 2 +- web-splash/splash-functions.inc | 27 ++++++++++++++++++--------- web-splash/web-splash.sh | 11 ++++++++++- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/web-splash/CHANGELOG b/web-splash/CHANGELOG index f3b9da0..0bbc0e7 100644 --- a/web-splash/CHANGELOG +++ b/web-splash/CHANGELOG @@ -1,3 +1,7 @@ +Version 0.2.1 + * traffic counter added + --- 18. May 02005 - Lars Kruse --- + Version 0.2 * counter for returned packets added * enhanced installation and removal diff --git a/web-splash/ipkg/control b/web-splash/ipkg/control index df229c2..7391e07 100644 --- a/web-splash/ipkg/control +++ b/web-splash/ipkg/control @@ -1,6 +1,6 @@ Package: web-splash Priority: optional -Version: 0.2 +Version: 0.2.1 Architecture: mipsel Maintainer: Lars Kruse Section: net diff --git a/web-splash/splash-functions.inc b/web-splash/splash-functions.inc index 77881c0..e6a4d1a 100644 --- a/web-splash/splash-functions.inc +++ b/web-splash/splash-functions.inc @@ -77,15 +77,14 @@ init_chains() } -get_IPs() -# prints out all active forwards line by line -# every line consists of: "Number of Packets" and "IP" +get_IP_list() +# prints out all active forwarding IPs { - iptables -t nat -L "$CHAIN_FORWARD_CHECK" -vnx | sed "1,2d; s/ */ /g" | cut -d " " -f 2,9 + $IPT -t nat -L "$CHAIN_FORWARD_CHECK" -vnx | sed "1,2d; s/ */ /g" | cut -d " " -f 9 # get all active forward chains # remove the first two lines # remove multiple spaces - # take only the number of packets and the IP + # take only the IP } @@ -103,12 +102,22 @@ unregister_IP() } -refresh_IP_list() +update_IP_list() +# remove inactive IPs from the forwarding list { - local NUM local IP - get_IPs | while read NUM IP - do [ "$NUM" = "0" ] && unregister_IP "$IP" + get_IPs | while read IP + do [ `get_IP_traffic $IP` -gt 0 ] && unregister_IP "$IP" done } +get_IP_traffic() +{ + local IP="$1" + local out_traffic="`$IPT -t nat -L \"$CHAIN_FORWARD_CHECK\" -vnx | sed '1,2d; s/ */ /g' | cut -d ' ' -f 3,9 | grep \" $IP$\" | cut -d ' ' -f 1`" + local in_traffic="`$IPT -L \"$CHAIN_RETURN\" -vnx | sed '1,2d; s/ */ /g' | cut -d ' ' -f 3,9 | grep \" $IP$\" | cut -d ' ' -f 1`" + if [ -n "$in_traffic" -a -n "$out_traffic" ] + then echo $((in_traffic+out_traffic)) + else echo 0 + fi +} diff --git a/web-splash/web-splash.sh b/web-splash/web-splash.sh index 6812810..4120e10 100755 --- a/web-splash/web-splash.sh +++ b/web-splash/web-splash.sh @@ -33,7 +33,16 @@ case "$ACTION" in register_IP "$2" ;; update ) - refresh_IP_list + update_IP_list + ;; + traffic ) + if [ $# -eq 1 ] + then get_IP_list | while read IP + do echo "$IP `get_IP_traffic $IP`" + done + else IP="$2" + echo "$IP `get_IP_traffic $IP`" + fi ;; * ) echo "Syntax: $0 {start|stop|restart}"