applications/luci-splash: Updated to work with new UCI firewall
[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 "$zone" ] || return 0
12         
13         iptables -t nat -A zone_$zone_prerouting -j luci_splash_portal
14         iptables -t nat -A luci_splash_portal -d "$gw" -p tcp -m multiport --dports 22,80,443 -j RETURN
15 }
16
17 blacklist_add() {
18         local cfg="$1"
19         
20         config_get mac "$cfg" mac
21         [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j DROP
22 }
23
24 whitelist_add() {
25         local cfg="$1"
26         
27         config_get mac "$cfg" mac
28         [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j RETURN
29 }
30
31 start() {
32         ### Read chains from config
33         include /lib/network
34         scan_interfaces
35         config_load luci_splash
36         
37         ### Create subchains
38         iptables -t nat -N luci_splash
39         iptables -t nat -N luci_splash_portal
40         iptables -t nat -N luci_splash_leases
41         
42         ### Build the main and portal rule
43         config_foreach blacklist_add blacklist
44         config_foreach whitelist_add whitelist
45         config_foreach iface_add iface
46         
47         ### Build the portal rule
48         iptables -t nat -A luci_splash_portal -p udp --dport 53 -j RETURN
49         iptables -t nat -A luci_splash_portal -j luci_splash_leases
50         
51         ### Build the leases rule
52         iptables -t nat -A luci_splash_leases -p tcp --dport 80 -j REDIRECT --to-ports 8082
53         iptables -t nat -A luci_splash_leases -j DROP
54         
55         ### Start the splash httpd
56         start-stop-daemon -S -b -q -x /usr/bin/luci-splashd
57 }
58
59 stop() {        
60         ### Clear subchains
61         iptables -t nat -F luci_splash_leases
62         iptables -t nat -F luci_splash_portal
63         iptables -t nat -F luci_splash  
64         
65         ### Delete subchains
66         iptables -t nat -X luci_splash_leases
67         iptables -t nat -X luci_splash_portal
68         iptables -t nat -X luci_splash
69 }
70