summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-splash/luasrc/controller/splash
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-01-22 22:07:50 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-22 22:07:50 +0100
commit1d461b6e7ee664d6a356eb20861f3b957a558329 (patch)
treed039dc957d8b2a09b9839d03ea158b704bd6812c /applications/luci-app-splash/luasrc/controller/splash
parentfac02283137f6ff59363695bb07a3f9cec58e577 (diff)
luci-app-splash: convert ip4mac() to luci.ip.neighbors()
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'applications/luci-app-splash/luasrc/controller/splash')
-rw-r--r--applications/luci-app-splash/luasrc/controller/splash/splash.lua23
1 files changed, 13 insertions, 10 deletions
diff --git a/applications/luci-app-splash/luasrc/controller/splash/splash.lua b/applications/luci-app-splash/luasrc/controller/splash/splash.lua
index a41015ea1a..4add43559f 100644
--- a/applications/luci-app-splash/luasrc/controller/splash/splash.lua
+++ b/applications/luci-app-splash/luasrc/controller/splash/splash.lua
@@ -23,23 +23,26 @@ function index()
page.leaf = true
end
-function action_dispatch()
- local uci = luci.model.uci.cursor_state()
+function ip_to_mac(ip)
local ipc = require "luci.ip"
-
local i, n
- local mac = ""
- local access = false
for i, n in ipairs(ipc.neighbors()) do
- if n.mac and n.dest and n.dest:equal(luci.http.getenv("REMOTE_ADDR")) then
- mac = n.mac
+ if n.mac and n.dest and n.dest:equal(ip) then
+ return n.mac
end
end
+end
+
+function action_dispatch()
+ local uci = luci.model.uci.cursor_state()
+ local mac = ip_to_mac(luci.http.getenv("REMOTE_ADDR")) or ""
+ local access = false
uci:foreach("luci_splash", "lease", function(s)
if s.mac and s.mac:lower() == mac then access = true end
end)
+
uci:foreach("luci_splash", "whitelist", function(s)
if s.mac and s.mac:lower() == mac then access = true end
end)
@@ -60,13 +63,13 @@ function blacklist()
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 ipc = require "luci.ip"
+ local mac = ip_to_mac(luci.http.getenv("REMOTE_ADDR") or "127.0.0.1") or ""
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",
- function(s) if s.mac:lower() == mac or s.mac == mac then blacklisted = true end
+ function(s) if s.mac and s.mac:lower() == mac then blacklisted = true end
end)
if blacklisted then
luci.http.redirect(luci.dispatcher.build_url("splash" ,"blocked"))