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 uci = luci.model.uci.cursor_state()
15 local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR")) or ""
18 uci:foreach("luci_splash", "lease", function(s)
19 if s.mac and s.mac:lower() == mac then access = true end
21 uci:foreach("luci_splash", "whitelist", function(s)
22 if s.mac and s.mac:lower() == mac then access = true end
25 if #mac > 0 and access then
26 luci.http.redirect(luci.dispatcher.build_url())
28 luci.http.redirect(luci.dispatcher.build_url("splash", "splash"))
32 function action_activate()
33 local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
34 local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
35 if mac and luci.http.formvalue("accept") then
36 os.execute("luci-splash lease "..mac.." >/dev/null 2>&1")
37 luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
39 luci.http.redirect(luci.dispatcher.build_url())
43 function action_status_admin()
44 local uci = luci.model.uci.cursor_state()
45 local macs = luci.http.formvaluetable("save")
54 for key, _ in pairs(macs) do
55 local policy = luci.http.formvalue("policy.%s" % key)
56 local mac = luci.http.protocol.urldecode(key)
58 if policy == "whitelist" or policy == "blacklist" then
59 changes[policy][#changes[policy]+1] = mac
60 elseif policy == "normal" then
61 changes["lease"][#changes["lease"]+1] = mac
62 elseif policy == "kicked" then
63 changes["remove"][#changes["remove"]+1] = mac
67 if #changes.whitelist > 0 then
68 os.execute("luci-splash whitelist %s >/dev/null"
69 % table.concat(changes.whitelist))
72 if #changes.blacklist > 0 then
73 os.execute("luci-splash blacklist %s >/dev/null"
74 % table.concat(changes.blacklist))
77 if #changes.lease > 0 then
78 os.execute("luci-splash lease %s >/dev/null"
79 % table.concat(changes.lease))
82 if #changes.remove > 0 then
83 os.execute("luci-splash remove %s >/dev/null"
84 % table.concat(changes.remove))
87 luci.template.render("admin_status/splash", { is_admin = true })