<%# Copyright 2008-2009 Steven Barth Copyright 2008-2015 Jo-Philipp Wich Licensed to the public under the Apache License 2.0. -%> <%- local fs = require "nixio.fs" local path = luci.dispatcher.context.requestpath local utl = require "luci.util" local mUtl = require "luci.moreUtils" local master = mUtl.identify_pseudo_maestre(path[3] or "") local method local uci if master == true then method = "dhcp" uci = "uci" else method = path[3].."/dhcp" uci = path[3].."/uci" end local ipv4leases = utl.ubus(method, "ipv4leases") local ipv6leases = utl.ubus(method, "ipv6leases") local leases4 = {} if ipv4leases and ipv4leases.device then for k , v in pairs (ipv4leases.device) do for z, t in pairs (v) do if z == "leases" then for r, n in pairs (t) do if n and n.valid ~= "nil" then n.valid=n.valid*-1 hours = string.format("%02.f", math.floor(n.valid/3600)); mins = string.format("%02.f", math.floor(n.valid/60 - (hours*60))); secs = string.format("%02.f", math.floor(n.valid - hours*3600 - mins *60)); n.valid=hours..":"..mins..":"..secs if tonumber(hours) > 100 then n.valid = "static" end end table.insert(leases4, n) end end end end end local leases6 = {} if ipv6leases and ipv6leases.device then for k , v in pairs (ipv6leases.device) do for z, t in pairs (v) do if z == "leases" then for r, n in pairs (t) do if n and n.valid ~= "nil" then n.valid=n.valid*-1 hours = string.format("%02.f", math.floor(n.valid/3600)); mins = string.format("%02.f", math.floor(n.valid/60 - (hours*60))); secs = string.format("%02.f", math.floor(n.valid - hours*3600 - mins *60)); n.valid=hours..":"..mins..":"..secs if tonumber(hours) > 100 then n.valid = "static" end end table.insert(leases6, n) end end end end end local staticleases = utl.ubus(uci, "get", {config = "dhcp", type= "host"}) local static = {} if staticleases and staticleases.values then static = staticleases.values end cl = path[1] local all_leases = {} all_leases.leases4 = leases4 all_leases.leases6 = leases6 all_leases.static = static if luci.http.formvalue("status") == "1" then luci.http.prepare_content("application/json") luci.http.write_json(all_leases) return end -%> <%+header%>
">

<%:DHCP%> - <%=path[3]%>

<%:Active DHCP Leases%> <%if #leases4 > 0 then %> <%for k , v in pairs (leases4) do%> <%end%> <%else%> <%end%>
<%:Hostname%> <%:IPv4-Address%> <%:MAC-Address%> <%:Leasetime remaining%>
<%=v.hostname%> <%=v.ip%> <%=v.mac:gsub("..", ":%0"):sub(2)%> <%=v.valid%>

<%:Collecting data...%>
<%:Static leases%>
<%if static then %> <%for k , v in pairs (static) do %> <%if v.ip then %> <% local valid if v and v.valid then v.valid=v.valid*-1 hours = string.format("%02.f", math.floor(v.valid/3600)); mins = string.format("%02.f", math.floor(v.valid/60 - (hours*60))); secs = string.format("%02.f", math.floor(v.valid - hours*3600 - mins *60)); valid=hours..":"..mins..":"..secs end %> <%end%> <%end%> <%for k , v in pairs (static) do %> <%if not v.ip then %> <% local valid if v and v.valid then v.valid=v.valid*-1 hours = string.format("%02.f", math.floor(v.valid/3600)); mins = string.format("%02.f", math.floor(v.valid/60 - (hours*60))); secs = string.format("%02.f", math.floor(v.valid - hours*3600 - mins *60)); valid=hours..":"..mins..":"..secs end %> <%end%> <%end%> <%end%>
<%:Hostname%> <%:MAC-Address%> <%:IPv4-Address%>
" onclick = "actions('save')"/> " onclick = "actions('save')"/> " onclick = "action('save')" />
<%+footer%>