luci-app-splash: convert ip4mac() to luci.ip.neighbors()
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
fac0228313
commit
1d461b6e7e
1 changed files with 13 additions and 10 deletions
|
@ -23,23 +23,26 @@ function index()
|
||||||
page.leaf = true
|
page.leaf = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_dispatch()
|
function ip_to_mac(ip)
|
||||||
local uci = luci.model.uci.cursor_state()
|
|
||||||
local ipc = require "luci.ip"
|
local ipc = require "luci.ip"
|
||||||
|
|
||||||
local i, n
|
local i, n
|
||||||
local mac = ""
|
|
||||||
local access = false
|
|
||||||
|
|
||||||
for i, n in ipairs(ipc.neighbors()) do
|
for i, n in ipairs(ipc.neighbors()) do
|
||||||
if n.mac and n.dest and n.dest:equal(luci.http.getenv("REMOTE_ADDR")) then
|
if n.mac and n.dest and n.dest:equal(ip) then
|
||||||
mac = n.mac
|
return n.mac
|
||||||
end
|
end
|
||||||
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)
|
uci:foreach("luci_splash", "lease", function(s)
|
||||||
if s.mac and s.mac:lower() == mac then access = true end
|
if s.mac and s.mac:lower() == mac then access = true end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
uci:foreach("luci_splash", "whitelist", function(s)
|
uci:foreach("luci_splash", "whitelist", function(s)
|
||||||
if s.mac and s.mac:lower() == mac then access = true end
|
if s.mac and s.mac:lower() == mac then access = true end
|
||||||
end)
|
end)
|
||||||
|
@ -60,13 +63,13 @@ function blacklist()
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_activate()
|
function action_activate()
|
||||||
local ip = luci.http.getenv("REMOTE_ADDR") or "127.0.0.1"
|
local ipc = require "luci.ip"
|
||||||
local mac = luci.sys.net.ip4mac(ip:match("^[\[::ffff:]*(%d+.%d+%.%d+%.%d+)\]*$"))
|
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 uci_state = require "luci.model.uci".cursor_state()
|
||||||
local blacklisted = false
|
local blacklisted = false
|
||||||
if mac and luci.http.formvalue("accept") then
|
if mac and luci.http.formvalue("accept") then
|
||||||
uci:foreach("luci_splash", "blacklist",
|
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)
|
end)
|
||||||
if blacklisted then
|
if blacklisted then
|
||||||
luci.http.redirect(luci.dispatcher.build_url("splash" ,"blocked"))
|
luci.http.redirect(luci.dispatcher.build_url("splash" ,"blocked"))
|
||||||
|
|
Loading…
Reference in a new issue