summaryrefslogtreecommitdiffstats
path: root/nodogsplash/files/nodogsplash.init
blob: b4657923181b810abefceb45b887a41b148e8960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/sh /etc/rc.common
#
# description: Startup/shutdown script for nodogsplash captive portal
#
# P. Kube 2007
#
# (Based on wifidog startup script
# Date    : 2004-08-25
# Version : 1.0
# Comment by that author: Could be better, but it's working as expected)
#


IPT=/usr/sbin/iptables
WD_DIR=/usr/bin
NDS_CONF=/etc/nodogsplash/nodogsplash.conf
OPTIONS=""
START=65
STOP=65
# -s -d 5 runs in background, with level 5 (not so verbose) messages to syslog
# -f -d 7 runs in foreground, with level 7 (verbose) debug messages to terminal
# N.B.: -f will fail if starting at boot from rcS
#OPTIONS="-s -d 5"

start() {
   	echo "Starting nodogsplash ... "
	if $WD_DIR/ndsctl status 2> /dev/null; then
		echo "FAILED:  nodogsplash already running"
    	else
		if test_module && $WD_DIR/nodogsplash $OPTIONS; then
			echo "OK: nodogsplash started"
		else
			echo "FAILED:  nodogsplash exited with non 0 status"
		fi
    	fi
}

stop() {
	echo "Stopping nodogsplash ... "
	if $WD_DIR/ndsctl status 2> /dev/null; then
		if $WD_DIR/ndsctl stop; then
			echo "OK: nodogsplash stopped"
		else
			echo "FAILED:  ndsctl stop exited with non 0 status"
		fi
	else
		echo "FAILED:  nodogsplash was not running"
    	fi
}

status() {
	$WD_DIR/ndsctl status
}

test_module() {

    ### Test ipt_mark with iptables
    test_ipt_mark () {
	($IPT -A FORWARD -m mark --mark 2 -j ACCEPT 2>&1) > /dev/null
	IPTABLES_OK=$?
	if [ "$IPTABLES_OK" -eq 0 ]; then
	    ($IPT -D FORWARD -m mark --mark 2 -j ACCEPT 2>&1) > /dev/null
	    return 0
	else
	    return 1
	fi
    }
    ### Test ipt_mac with iptables
    test_ipt_mac () {
	($IPT -A INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1) > /dev/null
	IPTABLES_OK=$?
	if [ "$IPTABLES_OK" -eq 0 ]; then
	    ($IPT -D INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1) > /dev/null
	    return 0
	else
	    return 1
	fi
    }

    ### Test ipt_IMQ with iptables
    test_ipt_IMQ () {
	($IPT -t mangle -A PREROUTING -j IMQ --todev 0 2>&1) > /dev/null
	IPTABLES_OK=$?
	if [ "$IPTABLES_OK" -eq 0 ]; then
	    ($IPT -t mangle -D PREROUTING -j IMQ --todev 0 2>&1) > /dev/null
	    return 0
	else
	    return 1
	fi
    }

    ### Test imq with ip
    test_imq () {
	(ip link set imq0 up 2>&1) > /dev/null
	IMQ0_OK=$?
	(ip link set imq1 up 2>&1) > /dev/null
	IMQ1_OK=$?
	if [ "$IMQ0_OK" -eq 0 -a "$IMQ1_OK" -eq 0 ]; then
	    (ip link set imq0 down 2>&1) > /dev/null
	    (ip link set imq1 down 2>&1) > /dev/null
	    return 0
	else
	    return 1
	fi
    }

    ### Test sch_htb with tc; requires imq0
    test_sch_htb () {
	(tc qdisc del dev imq0 root 2>&1) > /dev/null
	(tc qdisc add dev imq0 root htb 2>&1) > /dev/null
	TC_OK=$?
	if [ "$TC_OK" -eq 0 ]; then
	    (tc qdisc del dev imq0 root 2>&1) > /dev/null
	    return 0
	else
	    return 1
	fi
    }

    
    ### Find a module on disk
    module_exists () {
      EXIST=$(find /lib/modules/`uname -r` -name $1.*o 2> /dev/null)
      if [ -n "$EXIST" ]; then
        return 0
      else
        return 1
      fi
    }

    ### Test if a module is in memory
    module_in_memory () {
      MODULE=$(lsmod | grep $1 | awk '{print $1}')
      if [ "$MODULE" = "$1" ]; then
        return 0
      else
        return 1
      fi
    }

    ### Test functionality of a module; load if necessary
    do_module_tests () {
	echo "  Testing module $1 $2"
	"test_$1"
	if [ $? -ne 0 ]; then
	    echo "   Module $1 $2 needed"
	    echo "   Scanning disk for $1 module"
	    module_exists $1
	    if [ $? -ne 0 ]; then 
		echo "   $1 module missing: please install it"
		exit 1
	    else
		echo "   $1 exists, trying to load"
		insmod $1 $2 > /dev/null
		if [ $? -ne 0 ]; then
		    echo "   Error: insmod $1 $2 failed"
		    exit 1
		else
		    echo "   $1 $2 loaded successfully"
		fi
	    fi
	else
	    echo "   $1 is working"
	fi 
		
    }

    echo " Testing required modules"

    do_module_tests "ipt_mac"
    do_module_tests "ipt_mark"

    # test for imq modules, only if TrafficControl is enabled in conf
    if ( grep -q -E '^[[:space:]]*TrafficControl[[:space:]]+(yes|true|1)' "$NDS_CONF" ) ; then
        do_module_tests "imq" "numdevs=2"
        do_module_tests "ipt_IMQ"
        do_module_tests "sch_htb"
    fi
}