1 module("luci.controller.splash.splash", package.seeall)
4 entry({"admin", "services", "splash"}, cbi("splash/splash"), _("Client-Splash"), 90).i18n = "freifunk"
5 entry({"admin", "services", "splash", "splashtext" }, form("splash/splashtext"), _("Splashtext"), 10)
10 e.target = call("action_dispatch")
13 node("splash", "activate").target = call("action_activate")
14 node("splash", "splash").target = template("splash_splash/splash")
16 entry({"admin", "status", "splash"}, call("action_status_admin"), _("Client-Splash")).i18n = "freifunk"
19 function action_dispatch()
20 local uci = luci.model.uci.cursor_state()
21 local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR")) or ""
24 uci:foreach("luci_splash", "lease", function(s)
25 if s.mac and s.mac:lower() == mac then access = true end
27 uci:foreach("luci_splash", "whitelist", function(s)
28 if s.mac and s.mac:lower() == mac then access = true end
31 if #mac > 0 and access then
32 luci.http.redirect(luci.dispatcher.build_url())
34 luci.http.redirect(luci.dispatcher.build_url("splash", "splash"))
38 function action_activate()
39 local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
40 local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
41 if mac and luci.http.formvalue("accept") then
42 os.execute("luci-splash lease "..mac.." >/dev/null 2>&1")
43 luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
45 luci.http.redirect(luci.dispatcher.build_url())
49 function action_status_admin()
50 local uci = luci.model.uci.cursor_state()
51 local macs = luci.http.formvaluetable("save")
60 for key, _ in pairs(macs) do
61 local policy = luci.http.formvalue("policy.%s" % key)
62 local mac = luci.http.protocol.urldecode(key)
64 if policy == "whitelist" or policy == "blacklist" then
65 changes[policy][#changes[policy]+1] = mac
66 elseif policy == "normal" then
67 changes["lease"][#changes["lease"]+1] = mac
68 elseif policy == "kicked" then
69 changes["remove"][#changes["remove"]+1] = mac
73 if #changes.whitelist > 0 then
74 os.execute("luci-splash whitelist %s >/dev/null"
75 % table.concat(changes.whitelist))
78 if #changes.blacklist > 0 then
79 os.execute("luci-splash blacklist %s >/dev/null"
80 % table.concat(changes.blacklist))
83 if #changes.lease > 0 then
84 os.execute("luci-splash lease %s >/dev/null"
85 % table.concat(changes.lease))
88 if #changes.remove > 0 then
89 os.execute("luci-splash remove %s >/dev/null"
90 % table.concat(changes.remove))
93 luci.template.render("admin_status/splash", { is_admin = true })