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 wa = require "luci.tools.webadmin"
18 local fs = require "nixio.fs"
20 m2 = Map("dhcp", translate("DHCP Leases"),
21 translate("Static leases are used to assign fixed IP addresses and symbolic hostnames to " ..
22 "DHCP clients. They are also required for non-dynamic interface configurations where " ..
23 "only hosts with a corresponding lease are served."))
25 local leasefn, leasefp, leases
26 uci:foreach("dhcp", "dnsmasq",
28 leasefn = section.leasefile
31 local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn)
34 for lease in leasefp do
35 table.insert(leases, luci.util.split(lease, " "))
40 v = m2:section(Table, leases, translate("Active Leases"))
41 ip = v:option(DummyValue, 3, translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
43 mac = v:option(DummyValue, 2, translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
45 ltime = v:option(DummyValue, 1, translate("Leasetime remaining"))
46 function ltime.cfgvalue(self, ...)
47 local value = DummyValue.cfgvalue(self, ...)
48 return wa.date_format(os.difftime(tonumber(value), os.time()))
52 s = m2:section(TypedSection, "host", translate("Static Leases"),
53 translate("Use the <em>Add</em> Button to add a new lease entry. The <em>MAC-Address</em> " ..
54 "indentifies the host, the <em>IPv4-Address</em> specifies to the fixed address to " ..
55 "use and the <em>Hostname</em> is assigned as symbolic name to the requesting host."))
59 s.template = "cbi/tblsection"
61 name = s:option(Value, "name", translate("Hostname"))
62 mac = s:option(Value, "mac", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
63 ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
64 sys.net.arptable(function(entry)
65 ip:value(entry["IP address"])
68 entry["HW address"] .. " (" .. entry["IP address"] .. ")"