ad1a8b1071e068352c330af04e8e00599e57d86e
[project/luci.git] / applications / luci-splash / root / etc / init.d / luci_splash
1 #!/bin/sh /etc/rc.common
2 START=70
3
4 iface_add() {
5         local cfg="$1"
6         
7         config_get zone "$cfg" zone
8         [ -n "$zone" ] || return 0
9         
10         config_get gw "$cfg" gateway
11         [ -n "$gw" ] || return 0
12         
13         iptables -t nat -A zone_${zone}_prerouting -j luci_splash_portal
14         
15         for i in $gw
16         do
17                 iptables -t nat -A luci_splash_portal -d "$i" -p tcp -m multiport --dports 22,80,443 -j RETURN
18         done
19 }
20
21 blacklist_add() {
22         local cfg="$1"
23         
24         config_get mac "$cfg" mac
25         [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j DROP
26 }
27
28 whitelist_add() {
29         local cfg="$1"
30         
31         config_get mac "$cfg" mac
32         [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j RETURN
33 }
34
35 start() {
36         ### Read chains from config
37         include /lib/network
38         scan_interfaces
39         config_load luci_splash
40         
41         ### Create subchains
42         iptables -t nat -N luci_splash
43         iptables -t nat -N luci_splash_portal
44         iptables -t nat -N luci_splash_leases
45         
46         ### Build the main and portal rule
47         config_foreach blacklist_add blacklist
48         config_foreach whitelist_add whitelist
49         config_foreach iface_add iface
50         
51         ### Build the portal rule
52         iptables -t nat -A luci_splash_portal -p udp --dport 53 -j RETURN
53         iptables -t nat -A luci_splash_portal -j luci_splash_leases
54         
55         ### Build the leases rule
56         iptables -t nat -A luci_splash_leases -p tcp --dport 80 -j REDIRECT --to-ports 8082
57         iptables -t nat -A luci_splash_leases -j DROP
58         
59         ### Start the splash httpd
60         start-stop-daemon -S -b -q -x /usr/bin/luci-splashd
61 }
62
63 stop() {        
64         ### Clear subchains
65         iptables -t nat -F luci_splash_leases
66         iptables -t nat -F luci_splash_portal
67         iptables -t nat -F luci_splash  
68         
69         ### Delete subchains
70         iptables -t nat -X luci_splash_leases
71         iptables -t nat -X luci_splash_portal
72         iptables -t nat -X luci_splash
73 }
74