* luci-splash: Fixes
[project/luci.git] / contrib / package / luci-splash / src / luci-splash / htdocs / cgi-bin / index.cgi
1 #!/usr/bin/haserl --shell=luac
2 dofile("/usr/lib/luci-splash/splash.lua")
3
4 local srv
5 local ip = ffluci.http.remote_addr()
6 for k, v in pairs(uci:show("network").network) do
7 if v[".type"] == "interface" then
8 local p = ffluci.sys.net.mask4prefix(v.netmask)
9 if ffluci.sys.net.belongs(ip, v.ipaddr, p) then
10 srv = v.ipaddr
11 end
12 end
13 end
14
15 if not srv then
16 ffluci.http.textheader()
17 return print("Unable to detect network settings!")
18 end
19
20 local action = "splash"
21
22 local mac = ip4mac(ip)
23 if not mac then
24 action = "unknown"
25 end
26
27 if iswhitelisted(mac) or haslease(mac) then
28 action = "allowed"
29 end
30
31 ffluci.http.redirect("http://" .. srv .. "/cgi-bin/luci-splash/" .. action)