2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
15 local uci = require "luci.model.uci".cursor()
16 local sys = require "luci.sys"
17 local fs = require "nixio.fs"
20 local function date_format(secs)
21 local suff = {"min", "h", "d"}
26 secs = math.floor(secs)
28 mins = math.floor(secs / 60)
33 hour = math.floor(mins / 60)
38 days = math.floor(hour / 24)
43 return string.format("%.0fd %02.0fh %02.0fmin %02.0fs", days, hour, mins, secs)
45 return string.format("%02.0fh %02.0fmin %02.0fs", hour, mins, secs)
49 m2 = Map("dhcp", "Manage Address Assignment")
51 local leasefn, leasefp, leases
52 uci:foreach("dhcp", "dnsmasq",
54 leasefn = section.leasefile
57 local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn)
60 for lease in leasefp do
61 table.insert(leases, luci.util.split(lease, " "))
66 v = m2:section(Table, leases, translate("Active Leases"))
67 ip = v:option(DummyValue, 3, translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
69 mac = v:option(DummyValue, 2, translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
71 ltime = v:option(DummyValue, 1, translate("Leasetime remaining"))
72 function ltime.cfgvalue(self, ...)
73 local value = DummyValue.cfgvalue(self, ...)
74 return date_format(os.difftime(tonumber(value), os.time()))
78 s = m2:section(TypedSection, "host", "Static Assignment",
79 "You can assign fixed addresses and DNS names to devices in you local network to make reaching them more easy.")
82 s.template = "cbi/tblsection"
84 hn = s:option(Value, "name", translate("Hostname"))
85 mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
86 ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
87 sys.net.arptable(function(entry)
88 ip:value(entry["IP address"])
91 entry["HW address"] .. " (" .. entry["IP address"] .. ")"