X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fadmin-full%2Fluasrc%2Fcontroller%2Fadmin%2Fnetwork.lua;h=df4529d3413b2a7969400c1cab9e120ca4a164ea;hp=896b4be06a99020ceee6560d6d533d151fbf4428;hb=614f878fb494eb7ba111e51ee8c99e736ae64397;hpb=a3e66af2a3e2e291ba3f737ac11365c5acc5d9c9 diff --git a/modules/admin-full/luasrc/controller/admin/network.lua b/modules/admin-full/luasrc/controller/admin/network.lua index 896b4be06..df4529d34 100644 --- a/modules/admin-full/luasrc/controller/admin/network.lua +++ b/modules/admin-full/luasrc/controller/admin/network.lua @@ -87,6 +87,9 @@ function index() page.target = cbi("admin_network/dhcpleases") page.title = i18n("DHCP Leases") page.order = 30 + + page = entry({"admin", "network", "dhcplease_status"}, call("lease_status"), nil) + page.leaf = true end page = node("admin", "network", "hosts") @@ -156,45 +159,12 @@ end function wifi_delete(network) local ntm = require "luci.model.network".init() - ntm:del_network(network) + ntm:del_wifinet(network) ntm:save("wireless") luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless")) end -function jsondump(x) - if x == nil then - luci.http.write("null") - elseif type(x) == "table" then - local k, v - if type(next(x)) == "number" then - luci.http.write("[ ") - for k, v in ipairs(x) do - jsondump(v) - if next(x, k) then - luci.http.write(", ") - end - end - luci.http.write(" ]") - else - luci.http.write("{ ") - for k, v in pairs(x) do - luci.http.write("%q: " % k) - jsondump(v) - if next(x, k) then - luci.http.write(", ") - end - end - luci.http.write(" }") - end - elseif type(x) == "number" or type(x) == "boolean" then - luci.http.write(tostring(x)) - elseif type(x) == "string" then - luci.http.write("%q" % tostring(x)) - end -end - - function iface_status() local path = luci.dispatcher.context.requestpath local x = luci.model.uci.cursor_state() @@ -245,7 +215,7 @@ function iface_status() if #rv > 0 then luci.http.prepare_content("application/json") - jsondump(rv) + luci.http.write_json(rv) return end @@ -261,7 +231,7 @@ function wifi_status() local iw = luci.sys.wifi.getiwinfo(dev) if iw then local f - local j = { } + local j = { id = dev } for _, f in ipairs({ "channel", "frequency", "txpower", "bitrate", "signal", "noise", "quality", "quality_max", "mode", "ssid", "bssid", "country", @@ -276,9 +246,49 @@ function wifi_status() if #rv > 0 then luci.http.prepare_content("application/json") - jsondump(rv) + luci.http.write_json(rv) return end luci.http.status(404, "No such device") end + +function lease_status() + local rv = { } + local leasefile = "/var/dhcp.leases" + + local uci = require "luci.model.uci".cursor() + local nfs = require "nixio.fs" + + uci:foreach("dhcp", "dnsmasq", + function(s) + if s.leasefile and nfs.access(s.leasefile) then + leasefile = s.leasefile + return false + end + end) + + local fd = io.open(leasefile, "r") + if fd then + while true do + local ln = fd:read("*l") + if not ln then + break + else + local ts, mac, ip, name = ln:match("^(%d+) (%S+) (%S+) (%S+)") + if ts and mac and ip and name then + rv[#rv+1] = { + expires = os.difftime(tonumber(ts) or 0, os.time()), + macaddr = mac, + ipaddr = ip, + hostname = (name ~= "*") and name + } + end + end + end + fd:close() + end + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) +end