Merge branch 'master' into bmx6_testing
[feed/routing.git] / nodogsplash / files / nodogsplash.init
1 #!/bin/sh /etc/rc.common
2 #
3 # description: Startup/shutdown script for nodogsplash captive portal
4 #
5 # P. Kube 2007
6 #
7 # (Based on wifidog startup script
8 # Date : 2004-08-25
9 # Version : 1.0
10 # Comment by that author: Could be better, but it's working as expected)
11 #
12
13
14 IPT=/usr/sbin/iptables
15 WD_DIR=/usr/bin
16 NDS_CONF=/etc/nodogsplash/nodogsplash.conf
17 OPTIONS=""
18 START=65
19 STOP=65
20 # -s -d 5 runs in background, with level 5 (not so verbose) messages to syslog
21 # -f -d 7 runs in foreground, with level 7 (verbose) debug messages to terminal
22 # N.B.: -f will fail if starting at boot from rcS
23 #OPTIONS="-s -d 5"
24
25 start() {
26 echo "Starting nodogsplash ... "
27 if $WD_DIR/ndsctl status 2> /dev/null; then
28 echo "FAILED: nodogsplash already running"
29 else
30 if test_module && $WD_DIR/nodogsplash $OPTIONS; then
31 echo "OK: nodogsplash started"
32 else
33 echo "FAILED: nodogsplash exited with non 0 status"
34 fi
35 fi
36 }
37
38 stop() {
39 echo "Stopping nodogsplash ... "
40 if $WD_DIR/ndsctl status 2> /dev/null; then
41 if $WD_DIR/ndsctl stop; then
42 echo "OK: nodogsplash stopped"
43 else
44 echo "FAILED: ndsctl stop exited with non 0 status"
45 fi
46 else
47 echo "FAILED: nodogsplash was not running"
48 fi
49 }
50
51 status() {
52 $WD_DIR/ndsctl status
53 }
54
55 test_module() {
56
57 ### Test ipt_mark with iptables
58 test_ipt_mark () {
59 ($IPT -A FORWARD -m mark --mark 2 -j ACCEPT 2>&1) > /dev/null
60 IPTABLES_OK=$?
61 if [ "$IPTABLES_OK" -eq 0 ]; then
62 ($IPT -D FORWARD -m mark --mark 2 -j ACCEPT 2>&1) > /dev/null
63 return 0
64 else
65 return 1
66 fi
67 }
68 ### Test ipt_mac with iptables
69 test_ipt_mac () {
70 ($IPT -A INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1) > /dev/null
71 IPTABLES_OK=$?
72 if [ "$IPTABLES_OK" -eq 0 ]; then
73 ($IPT -D INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1) > /dev/null
74 return 0
75 else
76 return 1
77 fi
78 }
79
80 ### Test ipt_IMQ with iptables
81 test_ipt_IMQ () {
82 ($IPT -t mangle -A PREROUTING -j IMQ --todev 0 2>&1) > /dev/null
83 IPTABLES_OK=$?
84 if [ "$IPTABLES_OK" -eq 0 ]; then
85 ($IPT -t mangle -D PREROUTING -j IMQ --todev 0 2>&1) > /dev/null
86 return 0
87 else
88 return 1
89 fi
90 }
91
92 ### Test imq with ip
93 test_imq () {
94 (ip link set imq0 up 2>&1) > /dev/null
95 IMQ0_OK=$?
96 (ip link set imq1 up 2>&1) > /dev/null
97 IMQ1_OK=$?
98 if [ "$IMQ0_OK" -eq 0 -a "$IMQ1_OK" -eq 0 ]; then
99 (ip link set imq0 down 2>&1) > /dev/null
100 (ip link set imq1 down 2>&1) > /dev/null
101 return 0
102 else
103 return 1
104 fi
105 }
106
107 ### Test sch_htb with tc; requires imq0
108 test_sch_htb () {
109 (tc qdisc del dev imq0 root 2>&1) > /dev/null
110 (tc qdisc add dev imq0 root htb 2>&1) > /dev/null
111 TC_OK=$?
112 if [ "$TC_OK" -eq 0 ]; then
113 (tc qdisc del dev imq0 root 2>&1) > /dev/null
114 return 0
115 else
116 return 1
117 fi
118 }
119
120
121 ### Find a module on disk
122 module_exists () {
123 EXIST=$(find /lib/modules/`uname -r` -name $1.*o 2> /dev/null)
124 if [ -n "$EXIST" ]; then
125 return 0
126 else
127 return 1
128 fi
129 }
130
131 ### Test if a module is in memory
132 module_in_memory () {
133 MODULE=$(lsmod | grep $1 | awk '{print $1}')
134 if [ "$MODULE" = "$1" ]; then
135 return 0
136 else
137 return 1
138 fi
139 }
140
141 ### Test functionality of a module; load if necessary
142 do_module_tests () {
143 echo " Testing module $1 $2"
144 "test_$1"
145 if [ $? -ne 0 ]; then
146 echo " Module $1 $2 needed"
147 echo " Scanning disk for $1 module"
148 module_exists $1
149 if [ $? -ne 0 ]; then
150 echo " $1 module missing: please install it"
151 exit 1
152 else
153 echo " $1 exists, trying to load"
154 insmod $1 $2 > /dev/null
155 if [ $? -ne 0 ]; then
156 echo " Error: insmod $1 $2 failed"
157 exit 1
158 else
159 echo " $1 $2 loaded successfully"
160 fi
161 fi
162 else
163 echo " $1 is working"
164 fi
165
166 }
167
168 echo " Testing required modules"
169
170 do_module_tests "ipt_mac"
171 do_module_tests "ipt_mark"
172
173 # test for imq modules, only if TrafficControl is enabled in conf
174 if ( grep -q -E '^[[:space:]]*TrafficControl[[:space:]]+(yes|true|1)' "$NDS_CONF" ) ; then
175 do_module_tests "imq" "numdevs=2"
176 do_module_tests "ipt_IMQ"
177 do_module_tests "sch_htb"
178 fi
179 }