applications, modules: remove i18n handling from controller modules as it moved to...
[project/luci.git] / applications / luci-splash / luasrc / controller / splash / splash.lua
1 module("luci.controller.splash.splash", package.seeall)
2
3 function index()
4 entry({"admin", "services", "splash"}, cbi("splash/splash"), _("Client-Splash"), 90).i18n = "freifunk"
5 entry({"admin", "services", "splash", "splashtext" }, form("splash/splashtext"), _("Splashtext"), 10)
6
7 local e
8
9 e = node("splash")
10 e.target = call("action_dispatch")
11 e.i18n = "freifunk"
12
13 node("splash", "activate").target = call("action_activate")
14 node("splash", "splash").target = template("splash_splash/splash")
15
16 entry({"admin", "status", "splash"}, call("action_status_admin"), _("Client-Splash")).i18n = "freifunk"
17 end
18
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 ""
22 local access = false
23
24 uci:foreach("luci_splash", "lease", function(s)
25 if s.mac and s.mac:lower() == mac then access = true end
26 end)
27 uci:foreach("luci_splash", "whitelist", function(s)
28 if s.mac and s.mac:lower() == mac then access = true end
29 end)
30
31 if #mac > 0 and access then
32 luci.http.redirect(luci.dispatcher.build_url())
33 else
34 luci.http.redirect(luci.dispatcher.build_url("splash", "splash"))
35 end
36 end
37
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"))
44 else
45 luci.http.redirect(luci.dispatcher.build_url())
46 end
47 end
48
49 function action_status_admin()
50 local uci = luci.model.uci.cursor_state()
51 local macs = luci.http.formvaluetable("save")
52
53 local changes = {
54 whitelist = { },
55 blacklist = { },
56 lease = { },
57 remove = { }
58 }
59
60 for key, _ in pairs(macs) do
61 local policy = luci.http.formvalue("policy.%s" % key)
62 local mac = luci.http.protocol.urldecode(key)
63
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
70 end
71 end
72
73 if #changes.whitelist > 0 then
74 os.execute("luci-splash whitelist %s >/dev/null"
75 % table.concat(changes.whitelist))
76 end
77
78 if #changes.blacklist > 0 then
79 os.execute("luci-splash blacklist %s >/dev/null"
80 % table.concat(changes.blacklist))
81 end
82
83 if #changes.lease > 0 then
84 os.execute("luci-splash lease %s >/dev/null"
85 % table.concat(changes.lease))
86 end
87
88 if #changes.remove > 0 then
89 os.execute("luci-splash remove %s >/dev/null"
90 % table.concat(changes.remove))
91 end
92
93 luci.template.render("admin_status/splash", { is_admin = true })
94 end