* applications/luci-splash: Rewrote luci-splash using an own daemon implementation
[project/luci.git] / applications / luci-splash / luasrc / controller / splash / splash.lua
index 617e0f8..6512ee5 100644 (file)
@@ -1,16 +1,23 @@
 module("luci.controller.splash.splash", package.seeall)
 
 function index()
-       local page = node("admin", "services", "splash")
-       page.target = cbi("splash/splash")
-       page.title  = "Client-Splash"
+       entry({"admin", "services", "splash"}, cbi("splash/splash"), "Client-Splash")
 
+       node("splash").target = call("action_dispatch")
        node("splash", "splash", "activate").target = call("action_activate")
-       node("splash", "splash", "allowed").target  = call("action_allowed")
-       node("splash", "splash", "unknown").target  = call("action_unknown")
        node("splash", "splash", "splash").target   = template("splash_splash/splash")
 end
 
+function action_dispatch()
+       local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR"))
+       local status = luci.sys.execl("luci-splash status "..mac)[1]
+       if status == "whitelisted" or status == "lease" then
+               luci.http.redirect(luci.dispatcher.build_url())
+       else
+               luci.http.redirect(luci.dispatcher.build_url("splash", "splash", "splash"))
+       end
+end
+
 function action_activate()
        local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR"))
        if mac and luci.http.formvalue("accept") then
@@ -19,12 +26,4 @@ function action_activate()
        else
                luci.http.redirect(luci.dispatcher.build_url())
        end
-end
-
-function action_allowed()
-       luci.http.redirect(luci.dispatcher.build_url())
-end
-
-function action_unknown()
-       luci.http.redirect(luci.dispatcher.build_url())
 end
\ No newline at end of file