* luci-splash: Fixes
[project/luci.git] / contrib / package / luci-splash / src / luci-splash / htdocs / cgi-bin / index.cgi
diff --git a/contrib/package/luci-splash/src/luci-splash/htdocs/cgi-bin/index.cgi b/contrib/package/luci-splash/src/luci-splash/htdocs/cgi-bin/index.cgi
new file mode 100644 (file)
index 0000000..88f67c2
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/haserl --shell=luac
+dofile("/usr/lib/luci-splash/splash.lua")
+
+local srv
+local ip = ffluci.http.remote_addr()
+for k, v in pairs(uci:show("network").network) do
+       if v[".type"] == "interface" then
+               local p = ffluci.sys.net.mask4prefix(v.netmask)
+               if ffluci.sys.net.belongs(ip, v.ipaddr, p) then
+                       srv = v.ipaddr
+               end
+       end
+end
+
+if not srv then
+       ffluci.http.textheader()
+       return print("Unable to detect network settings!")
+end
+
+local action = "splash"
+
+local mac = ip4mac(ip)
+if not mac then
+       action = "unknown"
+end
+
+if iswhitelisted(mac) or haslease(mac) then
+       action = "allowed"
+end
+
+ffluci.http.redirect("http://" .. srv .. "/cgi-bin/luci-splash/" .. action)
\ No newline at end of file