[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 | #
|
---|
| 13 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
| 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
|
---|
| 23 | load_rc_config "lvrouted"
|
---|
| 24 | load_rc_config "tinyproxy"
|
---|
| 25 | : ${lvouted_enable="NO"}
|
---|
| 26 | : ${tinyproxy_enable="NO"}
|
---|
| 27 | : ${service_ileiden="NO"}
|
---|
| 28 | : ${service_proxy="NO"}
|
---|
| 29 |
|
---|
| 30 | control_lvrouted="yes"
|
---|
| 31 | control_tinyproxy="yes"
|
---|
| 32 | (( checkyesno service_ileiden || checkyesno service_proxy ) && checkyesno lvouted_enable ) || control_lvrouted="no"
|
---|
| 33 | (( checkyesno service_ileiden || checkyesno service_proxy ) && checkyesno tinyproxy_enable ) || control_tinyproxy="no"
|
---|
| 34 |
|
---|
| 35 |
|
---|
[10136] | 36 | service lvrouted onestatus > /dev/null && LVROUTED_STATUS="running" || LVROUTED_STATUS="stopped"
|
---|
[10483] | 37 | service tinyproxy onestatus > /dev/null && TINYPROXY_STATUS="running" || TINYPROXY_STATUS="stopped"
|
---|
[10136] | 38 |
|
---|
[10481] | 39 | check_http() {
|
---|
| 40 | fetch -o /dev/null -q $* 2>/dev/null
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[10483] | 43 | # Get connection stats for internet
|
---|
| 44 | INET_STATUS=up && check_http http://proxy-test.wirelessleiden.nl || check_http http://ams-ix.net || INET_STATUS=down
|
---|
| 45 | # Connections statistics for proxy
|
---|
| 46 | export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
|
---|
| 47 | PROXY_STATUS=up && check_http http://tinyproxy.stats || check_http http://ams-ix.net || PROXY_STATUS=down
|
---|
[10136] | 48 |
|
---|
[10483] | 49 | # Log Network Status
|
---|
| 50 | cat <<EOF > /tmp/network.status
|
---|
| 51 | internet=$INET_STATUS
|
---|
[10485] | 52 | proxy=$PROXY_STATUS
|
---|
[10483] | 53 | EOF
|
---|
[10136] | 54 |
|
---|
[10483] | 55 | # Control connections
|
---|
| 56 | if checkyesno control_lvrouted; then
|
---|
| 57 | if [ $LVROUTED_STATUS = "stopped" ] && [ $INET_STATUS = "up" ]; then
|
---|
| 58 | service lvrouted start | logit
|
---|
| 59 | elif [ $LVROUTED_STATUS = "running" ] && [ $INET_STATUS = "down" ]; then
|
---|
| 60 | service lvrouted stop | logit
|
---|
| 61 | fi
|
---|
[10136] | 62 | fi
|
---|
[10481] | 63 |
|
---|
[10483] | 64 | if checkyesno control_tinyproxy; then
|
---|
| 65 | if [ $TINYPROXY_STATUS_STATUS = "stopped" ] && [ $INET_STATUS = "up" ]; then
|
---|
| 66 | service tinyproxy start | logit
|
---|
| 67 | elif [ $TINYPROXY_STATUS = "running" ] && [ $INET_STATUS = "down" ]; then
|
---|
| 68 | service tinyproxy stop | logit
|
---|
| 69 | fi
|
---|
[10481] | 70 | fi
|
---|