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")
23 s:depends("interface", "lan")
25 enable = s:option(ListValue, "ignore", translate("enable"), "")
26 enable:value(0, translate("enable"))
27 enable:value(1, translate("disable"))
29 start = s:option(Value, "start", translate("m_n_d_firstaddress"))
31 start:depends("ignore", "0")
34 limit = s:option(Value, "limit", translate("m_n_d_numleases"), "")
35 limit:depends("ignore", "0")
37 function limit.cfgvalue(self, section)
38 local value = Value.cfgvalue(self, section)
41 return tonumber(value) + 1
45 function limit.write(self, section, value)
46 value = tonumber(value) - 1
47 return Value.write(self, section, value)
52 time = s:option(Value, "leasetime")
53 time:depends("ignore", "0")
58 m2 = Map("luci_ethers", translate("dhcp_leases"))
60 local leasefn, leasefp, leases
61 luci.model.uci.foreach("dhcp", "dnsmasq",
63 leasefn = section.leasefile
66 local leasefp = leasefn and luci.fs.access(leasefn) and io.lines(leasefn)
69 for lease in leasefp do
70 table.insert(leases, luci.util.split(lease, " "))
75 v = m2:section(Table, leases, translate("dhcp_leases_active"))
76 ip = v:option(DummyValue, 3, translate("ipaddress"))
78 mac = v:option(DummyValue, 2, translate("macaddress"))
80 ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
81 function ltime.cfgvalue(self, ...)
82 local value = DummyValue.cfgvalue(self, ...)
83 return luci.tools.webadmin.date_format(
84 os.difftime(tonumber(value), os.time())
89 s = m2:section(TypedSection, "static_lease", translate("luci_ethers"))
92 s.template = "cbi/tblsection"
94 mac = s:option(Value, "macaddr", translate("macaddress"))
95 ip = s:option(Value, "ipaddr", translate("ipaddress"))
96 for i, dataset in ipairs(luci.sys.net.arptable()) do
97 ip:value(dataset["IP address"])
98 mac:value(dataset["HW address"],
99 dataset["HW address"] .. " (" .. dataset["IP address"] .. ")")