networkdisconnect 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler Dec. 2010, License: GPL v3 /usr/share/doc/legal
  3. #called from pupdial.
  4. #got code out of rc.shutdown.
  5. #shutdown network interfaces, except for ppp
  6. #100814 log the cumulative bytes transmitted on network...
  7. # (see also /etc/rc.d/rc.sysinit and network_tray)
  8. ACTIVE_INTERFACE=""
  9. [ -f /tmp/sns_interface_success ] && ACTIVE_INTERFACE="`cat /tmp/sns_interface_success`" #SNS
  10. [ ! "$ACTIVE_INTERFACE" ] && ACTIVE_INTERFACE="`ifconfig | grep '^[a-z]' | grep -v '^lo' | grep -v '^ppp' | grep 'Link encap:Ethernet' | cut -f 1 -d ' ' | head -n 1`"
  11. if [ "$ACTIVE_INTERFACE" ];then
  12. if [ -d /sys/class/net/${ACTIVE_INTERFACE}/statistics ];then
  13. RX_BYTES="`cat /sys/class/net/${ACTIVE_INTERFACE}/statistics/rx_bytes`"
  14. TX_BYTES="`cat /sys/class/net/${ACTIVE_INTERFACE}/statistics/tx_bytes`"
  15. echo -n "$RX_BYTES" > /var/local/sns/rx_bytes_session
  16. echo -n "$TX_BYTES" > /var/local/sns/tx_bytes_session
  17. RX_BYTES_MONTH=`cat /var/local/sns/rx_bytes_month`
  18. RX_BYTES_MONTH=`expr $RX_BYTES_MONTH + $RX_BYTES`
  19. echo -n "$RX_BYTES_MONTH" > /var/local/sns/rx_bytes_month
  20. TX_BYTES_MONTH=`cat /var/local/sns/tx_bytes_month`
  21. TX_BYTES_MONTH=`expr $TX_BYTES_MONTH + $TX_BYTES`
  22. echo -n "$TX_BYTES_MONTH" > /var/local/sns/tx_bytes_month
  23. fi
  24. fi
  25. [ "`pidof wpa_supplicant`" != "" ] && wpa_cli terminate #100309 kills any running wpa_supplicant.
  26. if [ "`grep 'net-setup.sh' /usr/local/bin/defaultconnect`" = "" ];then #see connectwizard and connectwizard_2nd.
  27. for ONENETIF in `ifconfig | grep -E '^wifi[0-9]|^wlan[0-9]|^eth[0-9]' | cut -f 1 -d ' ' | tr '\n' ' '`
  28. do
  29. ifconfig $ONENETIF down 2> /dev/null
  30. [ "`iwconfig | grep "^${ONENETIF}" | grep "ESSID"`" != "" ] && iwconfig $ONENETIF essid off #100309
  31. dhcpcd --release $ONENETIF 2>/dev/null #100309
  32. done
  33. else
  34. /etc/rc.d/rc.network stop
  35. fi
  36. ###END###