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.
|
---|
11 | # XXX: For effiently reasons this should be combined with the nagios check_inet check
|
---|
12 | #
|
---|
13 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
14 | #
|
---|
15 |
|
---|
16 | TAG=`basename $0`
|
---|
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 |
|
---|
36 | service lvrouted onestatus > /dev/null && LVROUTED_STATUS="running" || LVROUTED_STATUS="stopped"
|
---|
37 | service tinyproxy onestatus > /dev/null && TINYPROXY_STATUS="running" || TINYPROXY_STATUS="stopped"
|
---|
38 |
|
---|
39 | check_http() {
|
---|
40 | fetch -o /dev/null -q $* 2>/dev/null
|
---|
41 | }
|
---|
42 |
|
---|
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
|
---|
48 |
|
---|
49 | # Log Network Status
|
---|
50 | cat <<EOF > /tmp/network.status
|
---|
51 | internet=$INET_STATUS
|
---|
52 | proxy=$PROXY_STATUS
|
---|
53 | EOF
|
---|
54 |
|
---|
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
|
---|
62 | fi
|
---|
63 |
|
---|
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
|
---|
70 | fi
|
---|