| 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 net "$cfg" network |
|---|
| 11 | [ -n "$net" ] || return 0 |
|---|
| 12 | |
|---|
| 13 | config_get ipaddr "$net" ipaddr |
|---|
| 14 | [ -n "$ipaddr" ] || return 0 |
|---|
| 15 | |
|---|
| 16 | config_get netmask "$net" netmask |
|---|
| 17 | [ -n "$netmask" ] || return 0 |
|---|
| 18 | |
|---|
| 19 | eval "$(ipcalc.sh $ipaddr $netmask)" |
|---|
| 20 | |
|---|
| 21 | iptables -t nat -A zone_${zone}_prerouting -s "$NETWORK/$PREFIX" -p ! tcp -j luci_splash_portal |
|---|
| 22 | iptables -t nat -A zone_${zone}_prerouting -s "$NETWORK/$PREFIX" -d ! "$ipaddr" -j luci_splash_portal |
|---|
| 23 | iptables -t nat -A zone_${zone}_prerouting -s "$NETWORK/$PREFIX" -d "$ipaddr" -p tcp -m multiport ! --dport 22,80,443 -j luci_splash_portal |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | blacklist_add() { |
|---|
| 27 | local cfg="$1" |
|---|
| 28 | |
|---|
| 29 | config_get mac "$cfg" mac |
|---|
| 30 | [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j DROP |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | whitelist_add() { |
|---|
| 34 | local cfg="$1" |
|---|
| 35 | |
|---|
| 36 | config_get mac "$cfg" mac |
|---|
| 37 | [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j RETURN |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | start() { |
|---|
| 41 | ### Read chains from config |
|---|
| 42 | include /lib/network |
|---|
| 43 | scan_interfaces |
|---|
| 44 | config_load luci_splash |
|---|
| 45 | |
|---|
| 46 | ### Create subchains |
|---|
| 47 | iptables -t nat -N luci_splash |
|---|
| 48 | iptables -t nat -N luci_splash_portal |
|---|
| 49 | iptables -t nat -N luci_splash_leases |
|---|
| 50 | |
|---|
| 51 | ### Build the main and portal rule |
|---|
| 52 | config_foreach blacklist_add blacklist |
|---|
| 53 | config_foreach whitelist_add whitelist |
|---|
| 54 | config_foreach iface_add iface |
|---|
| 55 | |
|---|
| 56 | ### Build the portal rule |
|---|
| 57 | iptables -t nat -A luci_splash_portal -p udp --dport 53 -j RETURN |
|---|
| 58 | iptables -t nat -A luci_splash_portal -j luci_splash_leases |
|---|
| 59 | |
|---|
| 60 | ### Build the leases rule |
|---|
| 61 | iptables -t nat -A luci_splash_leases -p tcp --dport 80 -j REDIRECT --to-ports 8082 |
|---|
| 62 | iptables -t nat -A luci_splash_leases -j DROP |
|---|
| 63 | |
|---|
| 64 | ### Add crontab entry |
|---|
| 65 | grep luci-splash /var/spool/cron/crontabs/root >/dev/null 2>&1 || { |
|---|
| 66 | echo '*/5 * * * * /usr/sbin/luci-splash sync' >> /var/spool/cron/crontabs/root |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | ### Start the splash httpd |
|---|
| 70 | start-stop-daemon -S -b -q -x /usr/bin/luci-splashd |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | stop() { |
|---|
| 74 | ### Clear subchains |
|---|
| 75 | iptables -t nat -F luci_splash_leases |
|---|
| 76 | iptables -t nat -F luci_splash_portal |
|---|
| 77 | iptables -t nat -F luci_splash |
|---|
| 78 | |
|---|
| 79 | ### Delete subchains |
|---|
| 80 | iptables -t nat -X luci_splash_leases |
|---|
| 81 | iptables -t nat -X luci_splash_portal |
|---|
| 82 | iptables -t nat -X luci_splash |
|---|
| 83 | |
|---|
| 84 | ### Stop the splash httpd |
|---|
| 85 | start-stop-daemon -K -q -x /usr/bin/luci-splashd |
|---|
| 86 | } |
|---|
| 87 | |
|---|