1 module("luci.controller.splash.splash", package.seeall)
4 entry({"admin", "services", "splash"}, cbi("splash/splash"), "Client-Splash")
6 node("splash").target = call("action_dispatch")
7 node("splash", "activate").target = call("action_activate")
8 node("splash", "splash").target = template("splash_splash/splash")
10 entry({"admin", "status", "splash"}, call("action_status_admin"), "Client-Splash")
13 function action_dispatch()
14 local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR")) or ""
15 local status = luci.util.execl("luci-splash status "..mac)[1]
16 if #mac > 0 and ( status == "whitelisted" or status == "lease" ) then
17 luci.http.redirect(luci.dispatcher.build_url())
19 luci.http.redirect(luci.dispatcher.build_url("splash", "splash"))
23 function action_activate()
24 local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
25 local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
26 if mac and luci.http.formvalue("accept") then
27 os.execute("luci-splash add "..mac.." >/dev/null 2>&1")
28 luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
30 luci.http.redirect(luci.dispatcher.build_url())
34 function action_status_admin()
35 local uci = luci.model.uci.cursor_state()
36 local macs = luci.http.formvaluetable("save")
38 local function delete_mac(what, mac)
39 uci:delete_all("luci_splash", what,
41 return ( s.mac and s.mac:lower() == mac )
45 local function leases(mac)
48 uci:foreach("luci_splash", "lease", function(s)
49 if s.start and s.mac and s.mac:lower() ~= mac then
57 uci:revert("luci_splash")
62 local function commit(leases, no_commit)
64 uci:save("luci_splash")
65 uci:commit("luci_splash")
68 for _, l in ipairs(leases) do
69 uci:section("luci_splash", "lease", nil, l)
72 uci:save("luci_splash")
73 os.execute("/etc/init.d/luci_splash restart")
76 for key, _ in pairs(macs) do
77 local policy = luci.http.formvalue("policy.%s" % key)
78 local mac = luci.http.protocol.urldecode(key)
79 local lslist = leases(policy ~= "kick" and mac)
81 delete_mac("blacklist", mac)
82 delete_mac("whitelist", mac)
84 if policy == "whitelist" or policy == "blacklist" then
85 uci:section("luci_splash", policy, nil, { mac = mac })
86 elseif policy == "normal" then
87 lslist[#lslist+1] = { mac = mac, start = os.time() }
88 elseif policy == "kick" then
89 for _, l in ipairs(lslist) do
90 if l.mac:lower() == mac then l.kicked="1" end
97 luci.template.render("admin_status/splash", { is_admin = true })