summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-splash/luasrc
diff options
context:
space:
mode:
authorManuel Munz <freifunk@somakoma.de>2013-08-18 20:41:30 +0000
committerManuel Munz <freifunk@somakoma.de>2013-08-18 20:41:30 +0000
commit47612c60f3436b5bdff26fbc8d869a0f1eca7ed2 (patch)
tree3888a30ef08c8fc76cb4150ad8c0d42bd490a828 /applications/luci-splash/luasrc
parent15088f5dd4f53cb25e71a871dd4ed25440ec7eb5 (diff)
applications/luci-splash: Per default redirect to the page the user requested after he accepted the splash. This can be overwritten with redirect_url in the general section in luci_splash config, #595
Diffstat (limited to 'applications/luci-splash/luasrc')
-rw-r--r--applications/luci-splash/luasrc/controller/splash/splash.lua32
1 files changed, 31 insertions, 1 deletions
diff --git a/applications/luci-splash/luasrc/controller/splash/splash.lua b/applications/luci-splash/luasrc/controller/splash/splash.lua
index 73584580d8..97d0400822 100644
--- a/applications/luci-splash/luasrc/controller/splash/splash.lua
+++ b/applications/luci-splash/luasrc/controller/splash/splash.lua
@@ -53,6 +53,7 @@ end
function action_activate()
local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
+ local uci_state = require "luci.model.uci".cursor_state()
local blacklisted = false
if mac and luci.http.formvalue("accept") then
uci:foreach("luci_splash", "blacklist",
@@ -61,8 +62,16 @@ function action_activate()
if blacklisted then
luci.http.redirect(luci.dispatcher.build_url("splash" ,"blocked"))
else
+ local redirect_url = uci:get("luci_splash", "general", "redirect_url")
+ if not redirect_url then
+ redirect_url = uci_state:get("luci_splash_locations", mac:gsub(':', ''):lower(), "location")
+ end
+ if not redirect_url then
+ redirect_url = luci.model.uci.cursor():get("freifunk", "community", "homepage") or 'http://www.freifunk.net'
+ end
+ remove_redirect(mac:gsub(':', ''):lower())
os.execute("luci-splash lease "..mac.." >/dev/null 2>&1")
- luci.http.redirect(luci.model.uci.cursor():get("freifunk", "community", "homepage"))
+ luci.http.redirect(redirect_url)
end
else
luci.http.redirect(luci.dispatcher.build_url())
@@ -119,3 +128,24 @@ end
function action_status_public()
luci.template.render("admin_status/splash", { is_admin = false })
end
+
+function remove_redirect(mac)
+ local mac = mac:lower()
+ mac = mac:gsub(":", "")
+ local uci = require "luci.model.uci".cursor_state()
+ local redirects = uci:get_all("luci_splash_locations")
+ --uci:load("luci_splash_locations")
+ uci:revert("luci_splash_locations")
+ -- For all redirects
+ for k, v in pairs(redirects) do
+ if v[".type"] == "redirect" then
+ if v[".name"] ~= mac then
+ -- Rewrite state
+ uci:section("luci_splash_locations", "redirect", v[".name"], {
+ location = v.location
+ })
+ end
+ end
+ end
+ uci:save("luci_splash_redirects")
+end