check_smb_idle does finally work

This commit is contained in:
lars 2005-09-15 22:19:22 +00:00
parent 415e779adf
commit 936bb4880c

View file

@ -33,18 +33,16 @@ filter_ipt_rules()
}
function count_traffic()
function check_for_traffic()
{
local sum=0
local traffic_yes=0
# fallback if no rules were found
echo "$sum"
# extract the number of packets and calculate the sum
filter_ipt_rules | sed 's/ */ /g' | cut -d " " -f 3 | while read a
do sum=$((sum+a))
echo "$sum"
done | tail -1
# sorry for the echo-tail-voodoo - i did not know it better :)
do [ "$a" -gt 0 ] && echo "$a"
done | grep -q "" && traffic_yes=1
iptables -Z INPUT
[ "$traffic_yes" = "1" ]
}
@ -60,15 +58,20 @@ MAX_IDLE_COUNTER=$("$CB_SCRIPT" get_config timeout)
# config test
[ -z "`filter_ipt_rules`" ] && echo "[`basename $0`]: Could not find a matching iptables rule!" >>"$LOG_FILE" && exit 1
# init idle_counter file, if it does not exist
[ ! -e "$IDLE_COUNTER_FILE" ] && echo "0" >"$IDLE_COUNTER_FILE"
# read current idle counter
if [ -e "$IDLE_COUNTER_FILE" ]
then current_count=$(<$IDLE_COUNTER_FILE)
else current_count=0
fi
# return true if it was idle
if [ "$(count_traffic)" -eq 0 ]
then echo "$(( $(<$IDLE_COUNTER_FILE) +1))"
else echo 0
# update counter
if check_for_traffic
then echo 0
else echo $((current_count + 1))
fi >"$IDLE_COUNTER_FILE"
# unmount crypto partition, if the threshold was reached
[ "$(<$IDLE_COUNTER_FILE)" -ge "$MAX_IDLE_COUNTER" ] && \
"$CB_SCRIPT" crypto-umount >>"$LOG_FILE" 2>&1
if [ "$(<$IDLE_COUNTER_FILE)" -ge "$MAX_IDLE_COUNTER" ]
then "$CB_SCRIPT" crypto-down >>"$LOG_FILE" 2>&1
echo "0" >"$IDLE_COUNTER_FILE"
fi