[packages] nodogsplash: fix use of deprecated iptables syntax
[feed/routing.git] / 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 OPTIONS=""
17 START=65
18 STOP=65
19 # -s -d 5 runs in background, with level 5 (not so verbose) messages to syslog
20 # -f -d 7 runs in foreground, with level 7 (verbose) debug messages to terminal
21 # N.B.: -f will fail if starting at boot from rcS
22 #OPTIONS="-s -d 5"
23
24 start() {
25 echo "Starting nodogsplash ... "
26 if $WD_DIR/ndsctl status 2> /dev/null; then
27 echo "FAILED: nodogsplash already running"
28 else
29 if test_module && $WD_DIR/nodogsplash $OPTIONS; then
30 echo "OK: nodogsplash started"
31 else
32 echo "FAILED: nodogsplash exited with non 0 status"
33 fi
34 fi
35 }
36
37 stop() {
38 echo "Stopping nodogsplash ... "
39 if $WD_DIR/ndsctl status 2> /dev/null; then
40 if $WD_DIR/ndsctl stop; then
41 echo "OK: nodogsplash stopped"
42 else
43 echo "FAILED: ndsctl stop exited with non 0 status"
44 fi
45 else
46 echo "FAILED: nodogsplash was not running"
47 fi
48 }
49
50 status() {
51 $WD_DIR/ndsctl status
52 }
53
54 test_module() {
55
56 ### Test ipt_mark with iptables
57 test_ipt_mark () {
58 ($IPT -A FORWARD -m mark --mark 2 -j ACCEPT 2>&1) > /dev/null
59 IPTABLES_OK=$?
60 if [ "$IPTABLES_OK" -eq 0 ]; then
61 ($IPT -D FORWARD -m mark --mark 2 -j ACCEPT 2>&1) > /dev/null
62 return 0
63 else
64 return 1
65 fi
66 }
67 ### Test ipt_mac with iptables
68 test_ipt_mac () {
69 ($IPT -A INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1) > /dev/null
70 IPTABLES_OK=$?
71 if [ "$IPTABLES_OK" -eq 0 ]; then
72 ($IPT -D INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1) > /dev/null
73 return 0
74 else
75 return 1
76 fi
77 }
78
79 ### Test ipt_IMQ with iptables
80 test_ipt_IMQ () {
81 ($IPT -t mangle -A PREROUTING -j IMQ --todev 0 2>&1) > /dev/null
82 IPTABLES_OK=$?
83 if [ "$IPTABLES_OK" -eq 0 ]; then
84 ($IPT -t mangle -D PREROUTING -j IMQ --todev 0 2>&1) > /dev/null
85 return 0
86 else
87 return 1
88 fi
89 }
90
91 ### Test imq with ip
92 test_imq () {
93 (ip link set imq0 up 2>&1) > /dev/null
94 IMQ0_OK=$?
95 (ip link set imq1 up 2>&1) > /dev/null
96 IMQ1_OK=$?
97 if [ "$IMQ0_OK" -eq 0 -a "$IMQ1_OK" -eq 0 ]; then
98 (ip link set imq0 down 2>&1) > /dev/null
99 (ip link set imq1 down 2>&1) > /dev/null
100 return 0
101 else
102 return 1
103 fi
104 }
105
106 ### Test sch_htb with tc; requires imq0
107 test_sch_htb () {
108 (tc qdisc del dev imq0 root 2>&1) > /dev/null
109 (tc qdisc add dev imq0 root htb 2>&1) > /dev/null
110 TC_OK=$?
111 if [ "$TC_OK" -eq 0 ]; then
112 (tc qdisc del dev imq0 root 2>&1) > /dev/null
113 return 0
114 else
115 return 1
116 fi
117 }
118
119
120 ### Find a module on disk
121 module_exists () {
122 EXIST=$(find /lib/modules/`uname -r` -name $1.*o 2> /dev/null)
123 if [ -n "$EXIST" ]; then
124 return 0
125 else
126 return 1
127 fi
128 }
129
130 ### Test if a module is in memory
131 module_in_memory () {
132 MODULE=$(lsmod | grep $1 | awk '{print $1}')
133 if [ "$MODULE" = "$1" ]; then
134 return 0
135 else
136 return 1
137 fi
138 }
139
140 ### Test functionality of a module; load if necessary
141 do_module_tests () {
142 echo " Testing module $1 $2"
143 "test_$1"
144 if [ $? -ne 0 ]; then
145 echo " Module $1 $2 needed"
146 echo " Scanning disk for $1 module"
147 module_exists $1
148 if [ $? -ne 0 ]; then
149 echo " $1 module missing: please install it"
150 exit 1
151 else
152 echo " $1 exists, trying to load"
153 insmod $1 $2 > /dev/null
154 if [ $? -ne 0 ]; then
155 echo " Error: insmod $1 $2 failed"
156 exit 1
157 else
158 echo " $1 $2 loaded successfully"
159 fi
160 fi
161 else
162 echo " $1 is working"
163 fi
164
165 }
166
167 echo " Testing required modules"
168
169 do_module_tests "ipt_mac"
170 do_module_tests "ipt_mark"
171 # if not using traffic control,
172 # you can comment out the following 3 lines:
173 do_module_tests "imq" "numdevs=2"
174 do_module_tests "ipt_IMQ"
175 do_module_tests "sch_htb"
176 }