summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-full/luasrc/controller
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-11-07 23:31:19 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-11-07 23:31:19 +0000
commitcb3caa6e3087380291a7fee8ca05d35d89744f27 (patch)
treebb3823948d5af39fb1a81043355eaceeed0fa982 /modules/admin-full/luasrc/controller
parente910619bbd67fe259ae5c709bbc78b7fd256fe84 (diff)
modules/admin-full: live status, validation for dhcp leases
Diffstat (limited to 'modules/admin-full/luasrc/controller')
-rw-r--r--modules/admin-full/luasrc/controller/admin/network.lua43
1 files changed, 43 insertions, 0 deletions
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