1 module("luci.controller.splash.splash", package.seeall)
2 luci.i18n.loadc("splash")
5 entry({"admin", "services", "splash"}, cbi("splash/splash"), _("Client-Splash"), 90).i18n = "freifunk"
6 entry({"admin", "services", "splash", "splashtext" }, form("splash/splashtext"), _("Splashtext"), 10)
11 e.target = call("action_dispatch")
14 node("splash", "activate").target = call("action_activate")
15 node("splash", "splash").target = template("splash_splash/splash")
17 entry({"admin", "status", "splash"}, call("action_status_admin"), _("Client-Splash")).i18n = "freifunk"
20 function action_dispatch()
21 local uci = luci.model.uci.cursor_state()
22 local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR")) or ""
25 uci:foreach("luci_splash", "lease", function(s)
26 if s.mac and s.mac:lower() == mac then access = true end
28 uci:foreach("luci_splash", "whitelist", function(s)
29 if s.mac and s.mac:lower() == mac then access = true end
32 if #mac > 0 and access then
33 luci.http.redirect(luci.dispatcher.build_url())
35 luci.http.redirect(luci.dispatcher.build_url("splash", "splash"))
39 function action_activate()
40 local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
41 local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
42 if mac and luci.http.formvalue("accept") then
43 os.execute("luci-splash lease "..mac.." >/dev/null 2>&1")
44 luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
46 luci.http.redirect(luci.dispatcher.build_url())
50 function action_status_admin()
51 local uci = luci.model.uci.cursor_state()
52 local macs = luci.http.formvaluetable("save")
61 for key, _ in pairs(macs) do
62 local policy = luci.http.formvalue("policy.%s" % key)
63 local mac = luci.http.protocol.urldecode(key)
65 if policy == "whitelist" or policy == "blacklist" then
66 changes[policy][#changes[policy]+1] = mac
67 elseif policy == "normal" then
68 changes["lease"][#changes["lease"]+1] = mac
69 elseif policy == "kicked" then
70 changes["remove"][#changes["remove"]+1] = mac
74 if #changes.whitelist > 0 then
75 os.execute("luci-splash whitelist %s >/dev/null"
76 % table.concat(changes.whitelist))
79 if #changes.blacklist > 0 then
80 os.execute("luci-splash blacklist %s >/dev/null"
81 % table.concat(changes.blacklist))
84 if #changes.lease > 0 then
85 os.execute("luci-splash lease %s >/dev/null"
86 % table.concat(changes.lease))
89 if #changes.remove > 0 then
90 os.execute("luci-splash remove %s >/dev/null"
91 % table.concat(changes.remove))
94 luci.template.render("admin_status/splash", { is_admin = true })