[10136] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # Internet Connection Wrapper From Cron
|
---|
| 4 | #
|
---|
| 5 | # a) Disable lvrouted if the internet is down.
|
---|
| 6 | # b) Re-enable lvrouted if the internet is back up.
|
---|
| 7 | #
|
---|
| 8 | # XXX: Do we need build an fail-save for flapping states?
|
---|
| 9 | # XXX: Do we need to manage state, like DHCP here?
|
---|
| 10 | # XXX: Check if page output is actually the output expected and not some weird captive portal somewhere.
|
---|
[10481] | 11 | # XXX: For effiently reasons this should be combined with the nagios check_inet check
|
---|
[10136] | 12 | #
|
---|
[10829] | 13 | # Rick van der Zwet <rick@wirelessleiden.nl>
|
---|
[10136] | 14 | #
|
---|
| 15 |
|
---|
| 16 | TAG=`basename $0`
|
---|
[10483] | 17 | logit() {
|
---|
| 18 | logger -t "$TAG" $*
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | # Check if we need to check inet at all
|
---|
| 22 | . /etc/rc.subr
|
---|
[10829] | 23 |
|
---|
[10483] | 24 | load_rc_config "lvrouted"
|
---|
| 25 | load_rc_config "tinyproxy"
|
---|
[10829] | 26 |
|
---|
[10483] | 27 | : ${lvouted_enable="NO"}
|
---|
| 28 | : ${tinyproxy_enable="NO"}
|
---|
| 29 | : ${service_ileiden="NO"}
|
---|
| 30 | : ${service_proxy="NO"}
|
---|
| 31 |
|
---|
[10829] | 32 | control_lvrouted=false
|
---|
| 33 | control_tinyproxy=false
|
---|
| 34 | checkyesno service_proxy_ileiden && checkyesno lvouted_enable control_lvrouted=true
|
---|
| 35 | checkyesno service_proxy_normal && checkyesno tinyproxy_enable || control_tinyproxy=false
|
---|
[10483] | 36 |
|
---|
| 37 |
|
---|
[10829] | 38 | # Get current state of the daemons
|
---|
| 39 | lvouted_status="stopped"
|
---|
| 40 | tinyproxy_status="stopped"
|
---|
| 41 | service lvrouted onestatus > /dev/null && lvouted_status="running"
|
---|
| 42 | service tinyproxy onestatus > /dev/null && tinyproxy_status="running"
|
---|
[10136] | 43 |
|
---|
[10481] | 44 | check_http() {
|
---|
| 45 | fetch -o /dev/null -q $* 2>/dev/null
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[10829] | 48 | # Get connection stats for internet direct and via proxy
|
---|
| 49 | inet_status=up
|
---|
| 50 | proxy_status=up
|
---|
[12894] | 51 | check_http http://www.nu.nl || check_http http://ams-ix.net || inet_status=down
|
---|
[10483] | 52 | export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
|
---|
[12894] | 53 | check_http http://tinyproxy.stats || check_http http://www.nu.net || proxy_status=down
|
---|
[10136] | 54 |
|
---|
[10483] | 55 | # Log Network Status
|
---|
| 56 | cat <<EOF > /tmp/network.status
|
---|
[10829] | 57 | internet=$inet_status
|
---|
| 58 | proxy=$proxy_status
|
---|
[10483] | 59 | EOF
|
---|
[10136] | 60 |
|
---|
[10483] | 61 | # Control connections
|
---|
[10829] | 62 | if $control_lvrouted; then
|
---|
| 63 | if [ $lvrouted_status = "stopped" ] && [ $inet_status = "up" ]; then
|
---|
[10483] | 64 | service lvrouted start | logit
|
---|
[10829] | 65 | elif [ $lvrouted_status = "running" ] && [ $inet_status = "down" ]; then
|
---|
[10483] | 66 | service lvrouted stop | logit
|
---|
| 67 | fi
|
---|
[10136] | 68 | fi
|
---|
[10481] | 69 |
|
---|
[10829] | 70 | if $control_tinyproxy; then
|
---|
| 71 | if [ $tinyproxy_status = "stopped" ] && [ $inet_status = "up" ]; then
|
---|
[10483] | 72 | service tinyproxy start | logit
|
---|
[10829] | 73 | elif [ $tinyproxy_status = "running" ] && [ $inet_status = "down" ]; then
|
---|
[10483] | 74 | service tinyproxy stop | logit
|
---|
| 75 | fi
|
---|
[10481] | 76 | fi
|
---|