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