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=a6324f427d7026928350cec68945fdbcfac82501;hp=9492e11d770ce8a1fd0463b495c9db69497f6466;hb=cb3caa6e3087380291a7fee8ca05d35d89744f27;hpb=e910619bbd67fe259ae5c709bbc78b7fd256fe84 diff --git a/modules/admin-full/luasrc/controller/admin/network.lua b/modules/admin-full/luasrc/controller/admin/network.lua index 9492e11d7..a6324f427 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") @@ -249,3 +252,43 @@ function wifi_status() 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