X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-splash%2Fluasrc%2Fview%2Fadmin_status%2Fsplash.htm;h=37f67776aadd2acd90f406ce125a4b6cf769fa69;hp=3415c205d53da61f70590fc427527801ba382cc7;hb=d01ddb29281bd3737aad63635eeb5aa54df6dce1;hpb=c1278f967e90352506900d243888cd3ac9caee9f diff --git a/applications/luci-app-splash/luasrc/view/admin_status/splash.htm b/applications/luci-app-splash/luasrc/view/admin_status/splash.htm index 3415c205d..37f67776a 100644 --- a/applications/luci-app-splash/luasrc/view/admin_status/splash.htm +++ b/applications/luci-app-splash/luasrc/view/admin_status/splash.htm @@ -6,6 +6,8 @@ <%- local utl = require "luci.util" +local sys = require "luci.sys" +local ipc = require "luci.ip" local ipt = require "luci.sys.iptparser".IptParser() local uci = require "luci.model.uci".cursor_state() local wat = require "luci.tools.webadmin" @@ -14,21 +16,15 @@ local fs = require "nixio.fs" local clients = { } local leasetime = tonumber(uci:get("luci_splash", "general", "leasetime") or 1) * 60 * 60 -local leasefile = "/tmp/dhcp.leases" - -uci:foreach("dhcp", "dnsmasq", - function(s) - if s.leasefile then leasefile = s.leasefile end - end) - uci:foreach("luci_splash_leases", "lease", function(s) - if s.start and s.mac then - clients[s.mac:lower()] = { + local m = ipc.checkmac(s.mac) + if m and s.start then + clients[m] = { start = tonumber(s.start), limit = ( tonumber(s.start) + leasetime ), - mac = s.mac:upper(), + mac = m, ipaddr = s.ipaddr, policy = "normal", packets = 0, @@ -39,11 +35,12 @@ uci:foreach("luci_splash_leases", "lease", for _, r in ipairs(ipt:find({table="nat", chain="luci_splash_leases"})) do if r.options and #r.options >= 2 and r.options[1] == "MAC" then - if not clients[r.options[2]:lower()] then - clients[r.options[2]:lower()] = { + local m = ipc.checkmac(r.options[2]) + if m and not clients[m] then + clients[m] = { start = 0, limit = 0, - mac = r.options[2]:upper(), + mac = m, policy = ( r.target == "RETURN" ) and "whitelist" or "blacklist", packets = 0, bytes = 0 @@ -60,7 +57,7 @@ for mac, client in pairs(clients) do if client.ipaddr then local rin = ipt:find({table="mangle", chain="luci_splash_mark_in", destination=client.ipaddr}) - local rout = ipt:find({table="mangle", chain="luci_splash_mark_out", options={"MAC", client.mac:upper()}}) + local rout = ipt:find({table="mangle", chain="luci_splash_mark_out", options={"MAC", client.mac}}) if rin and #rin > 0 then client.bytes_in = rin[1].bytes @@ -76,39 +73,27 @@ end uci:foreach("luci_splash", "whitelist", function(s) - if s.mac and clients[s.mac:lower()] then - clients[s.mac:lower()].policy="whitelist" + local m = ipc.checkmac(s.mac) + if m and clients[m] then + clients[m].policy="whitelist" end end) uci:foreach("luci_splash", "blacklist", function(s) - if s.mac and clients[s.mac:lower()] then - clients[s.mac:lower()].policy=(s.kicked and "kicked" or "blacklist") + local m = ipc.checkmac(s.mac) + if m and clients[m] then + clients[m].policy=(s.kicked and "kicked" or "blacklist") end end) -if fs.access(leasefile) then - for l in io.lines(leasefile) do - local time, mac, ip, name = l:match("^(%d+) (%S+) (%S+) (%S+)") - if time and mac and ip then - local c = clients[mac:lower()] - if c then - c.ip = ip - c.hostname = ( name ~= "*" ) and name or nil - end - end +sys.net.host_hints(function(mac, v4, v6, name) + local c = mac and clients[mac] + if c then + c.ip = c.ip or v4 + c.hostname = c.hostname or name end -end - -for i, n in ipairs(ipc.neighbors({ family = 4 })) do - if n.mac and n.dest then - local c = clients[n.mac] - if c and not c.ip then - c.ip = n.dest:string() - end - end -end +end) local function showmac(mac) if not is_admin then @@ -176,7 +161,7 @@ end splash.hostname, splash.ip, splash.mac, splash.timeleft, splash.trafficin, splash.trafficout); <% if is_admin then %> - s += String.format('', splash.mac); if (splash.policy == 'whitelist') { s += '' } else { @@ -196,7 +181,7 @@ end s += String.format( '' + '', - splash.mac.toLowerCase()); + splash.mac); <% else %> s += String.format('%s', splash.policy); <% end %>