1 module("luci.controller.splash.splash", package.seeall)
3 local uci = luci.model.uci.cursor()
4 local util = require "luci.util"
7 entry({"admin", "services", "splash"}, cbi("splash/splash"), _("Client-Splash"), 90)
8 entry({"admin", "services", "splash", "splashtext" }, form("splash/splashtext"), _("Splashtext"), 10)
13 e.target = call("action_dispatch")
15 node("splash", "activate").target = call("action_activate")
16 node("splash", "splash").target = template("splash_splash/splash")
17 node("splash", "blocked").target = template("splash/blocked")
19 entry({"admin", "status", "splash"}, call("action_status_admin"), _("Client-Splash"))
21 local page = node("splash", "publicstatus")
22 page.target = call("action_status_public")
26 function action_dispatch()
27 local uci = luci.model.uci.cursor_state()
28 local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR")) or ""
31 uci:foreach("luci_splash", "lease", function(s)
32 if s.mac and s.mac:lower() == mac then access = true end
34 uci:foreach("luci_splash", "whitelist", function(s)
35 if s.mac and s.mac:lower() == mac then access = true end
38 if #mac > 0 and access then
39 luci.http.redirect(luci.dispatcher.build_url())
41 luci.http.redirect(luci.dispatcher.build_url("splash", "splash"))
47 uci:foreach("luci_splash", "blacklist",
48 function(s) leased_macs[s.mac:lower()] = true
53 function action_activate()
54 local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
55 local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
56 local blacklisted = false
57 if mac and luci.http.formvalue("accept") then
58 uci:foreach("luci_splash", "blacklist",
59 function(s) if s.mac:lower() == mac or s.mac == mac then blacklisted = true end
62 luci.http.redirect(luci.dispatcher.build_url("splash" ,"blocked"))
64 os.execute("luci-splash lease "..mac.." >/dev/null 2>&1")
65 luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
68 luci.http.redirect(luci.dispatcher.build_url())
72 function action_status_admin()
73 local uci = luci.model.uci.cursor_state()
74 local macs = luci.http.formvaluetable("save")
83 for key, _ in pairs(macs) do
84 local policy = luci.http.formvalue("policy.%s" % key)
85 local mac = luci.http.protocol.urldecode(key)
87 if policy == "whitelist" or policy == "blacklist" then
88 changes[policy][#changes[policy]+1] = mac
89 elseif policy == "normal" then
90 changes["lease"][#changes["lease"]+1] = mac
91 elseif policy == "kicked" then
92 changes["remove"][#changes["remove"]+1] = mac
96 if #changes.whitelist > 0 then
97 os.execute("luci-splash whitelist %s >/dev/null"
98 % table.concat(changes.whitelist))
101 if #changes.blacklist > 0 then
102 os.execute("luci-splash blacklist %s >/dev/null"
103 % table.concat(changes.blacklist))
106 if #changes.lease > 0 then
107 os.execute("luci-splash lease %s >/dev/null"
108 % table.concat(changes.lease))
111 if #changes.remove > 0 then
112 os.execute("luci-splash remove %s >/dev/null"
113 % table.concat(changes.remove))
116 luci.template.render("admin_status/splash", { is_admin = true })
119 function action_status_public()
120 luci.template.render("admin_status/splash", { is_admin = false })