2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 require("luci.model.uci")
17 require("luci.tools.webadmin")
19 m = Map("dhcp", "DHCP")
21 s = m:section(TypedSection, "dhcp", "DHCP-Server")
26 s:depends("interface", "lan")
28 enable = s:option(ListValue, "ignore", translate("enable"), "")
29 enable:value(0, translate("enable"))
30 enable:value(1, translate("disable"))
32 start = s:option(Value, "start", translate("m_n_d_firstaddress"))
34 start:depends("ignore", "0")
37 limit = s:option(Value, "limit", translate("m_n_d_numleases"), "")
38 limit:depends("ignore", "0")
40 function limit.cfgvalue(self, section)
41 local value = Value.cfgvalue(self, section)
44 return tonumber(value) + 1
48 function limit.write(self, section, value)
49 value = tonumber(value) - 1
50 return Value.write(self, section, value)
55 time = s:option(Value, "leasetime")
56 time:depends("ignore", "0")
61 m2 = Map("luci_ethers", translate("dhcp_leases"))
63 local leasefn, leasefp, leases
64 luci.model.uci.cursor():foreach("dhcp", "dnsmasq",
66 leasefn = section.leasefile
69 local leasefp = leasefn and luci.fs.access(leasefn) and io.lines(leasefn)
72 for lease in leasefp do
73 table.insert(leases, luci.util.split(lease, " "))
78 v = m2:section(Table, leases, translate("dhcp_leases_active"))
79 ip = v:option(DummyValue, 3, translate("ipaddress"))
81 mac = v:option(DummyValue, 2, translate("macaddress"))
83 ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
84 function ltime.cfgvalue(self, ...)
85 local value = DummyValue.cfgvalue(self, ...)
86 return luci.tools.webadmin.date_format(
87 os.difftime(tonumber(value), os.time())
92 s = m2:section(TypedSection, "static_lease", translate("luci_ethers"))
95 s.template = "cbi/tblsection"
97 mac = s:option(Value, "macaddr", translate("macaddress"))
98 ip = s:option(Value, "ipaddr", translate("ipaddress"))
99 for i, dataset in ipairs(luci.sys.net.arptable()) do
100 ip:value(dataset["IP address"])
101 mac:value(dataset["HW address"],
102 dataset["HW address"] .. " (" .. dataset["IP address"] .. ")")