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
16 local uci = require "luci.model.uci".cursor()
17 local sys = require "luci.sys"
18 local wa = require "luci.tools.webadmin"
19 local fs = require "nixio.fs"
21 m = Map("dhcp", "DHCP")
23 s = m:section(TypedSection, "dhcp", "DHCP-Server")
28 s:depends("interface", "lan")
30 enable = s:option(ListValue, "ignore", translate("enable"), "")
31 enable:value(0, translate("enable"))
32 enable:value(1, translate("disable"))
34 start = s:option(Value, "start", translate("m_n_d_firstaddress"))
36 start:depends("ignore", "0")
39 limit = s:option(Value, "limit", translate("m_n_d_numleases"), "")
40 limit:depends("ignore", "0")
42 function limit.cfgvalue(self, section)
43 local value = Value.cfgvalue(self, section)
46 return tonumber(value) + 1
50 function limit.write(self, section, value)
51 value = tonumber(value) - 1
52 return Value.write(self, section, value)
57 time = s:option(Value, "leasetime")
58 time:depends("ignore", "0")
63 m2 = Map("luci_ethers", translate("dhcp_leases"))
65 local leasefn, leasefp, leases
66 uci:foreach("dhcp", "dnsmasq",
68 leasefn = section.leasefile
71 local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn)
74 for lease in leasefp do
75 table.insert(leases, luci.util.split(lease, " "))
80 v = m2:section(Table, leases, translate("dhcp_leases_active"))
81 ip = v:option(DummyValue, 3, translate("ipaddress"))
83 mac = v:option(DummyValue, 2, translate("macaddress"))
85 ltime = v:option(DummyValue, 1, translate("dhcp_timeremain"))
86 function ltime.cfgvalue(self, ...)
87 local value = DummyValue.cfgvalue(self, ...)
88 return wa.date_format(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 sys.net.arptable(function(entry)
100 ip:value(entry["IP address"])
103 entry["HW address"] .. " (" .. entry["IP address"] .. ")"